This repository has been archived on 2023-07-17. You can view files and clone it, but cannot push or open issues or pull requests.
pushee/gitlab.py
2019-12-01 13:23:03 +01:00

86 lines
2.1 KiB
Python

#!/usr/bin/env python3
import os
import requests
PROJECT = os.getenv("PUSHEE_PROJECT")
TOKEN = os.getenv("GITLAB_FI_TOKEN")
def post_mr(
source_branch,
target_branch,
title,
description,
labels,
remove_source_branch,
assignee_ids,
):
params = {
"source_branch": source_branch,
"target_branch": target_branch,
"title": title,
"description": description,
"labels": labels,
"remove_source_branch": remove_source_branch,
"assignee_ids": assignee_ids,
}
headers = {"Private-Token": TOKEN}
with requests.post(
f"https://gitlab.fi.muni.cz/api/v4/projects/{PROJECT}/merge_requests",
params=params,
headers=headers,
) as req:
print(req.status_code)
def get_mrs_for_branch(branch):
params = {"source_branch": branch}
headers = {"Private-Token": TOKEN}
with requests.get(
f"https://gitlab.fi.muni.cz/api/v4/projects/{PROJECT}/merge_requests",
params=params,
headers=headers,
) as req:
return req.json()
def merge_mr(iid):
headers = {"Private-Token": TOKEN}
with requests.put(
f"https://gitlab.fi.muni.cz/api/v4/projects/{PROJECT}/merge_requests/{iid}/merge",
headers=headers,
) as req:
print(req.status_code)
def set_assignees(iid, assignee_ids):
params = {"assignee_ids[]": assignee_ids}
headers = {"Private-Token": TOKEN}
with requests.put(
f"https://gitlab.fi.muni.cz/api/v4/projects/{PROJECT}/merge_requests/{iid}",
params=params,
headers=headers,
) as req:
print(req.status_code)
def get_comments(iid, page=1):
params = {"sort": "asc", "page": page}
headers = {"Private-Token": TOKEN}
with requests.get(
f"https://gitlab.fi.muni.cz/api/v4/projects/{PROJECT}/merge_requests/{iid}/notes",
params=params,
headers=headers,
) as req:
comments = req.json()
if 'rel="next"' in req.headers["Link"]:
comments.extend(get_comments(iid, page + 1))
return comments