2019-11-22 15:03:21 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
|
|
|
|
import requests
|
|
|
|
|
|
|
|
|
|
|
|
from constants import PROJECT, 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):
|
2019-11-23 16:51:30 +01:00
|
|
|
params = {"assignee_ids[]": assignee_ids}
|
2019-11-22 15:03:21 +01:00
|
|
|
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)
|
2019-11-22 20:12:37 +01:00
|
|
|
|
|
|
|
|
2019-11-23 13:46:37 +01:00
|
|
|
def get_comments(iid, page=1):
|
|
|
|
params = {"sort": "asc", "page": page}
|
2019-11-22 20:12:37 +01:00
|
|
|
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:
|
2019-11-23 13:46:37 +01:00
|
|
|
comments = req.json()
|
|
|
|
if 'rel="next"' in req.headers["Link"]:
|
|
|
|
comments.extend(get_comments(iid, page + 1))
|
|
|
|
return comments
|
|
|
|
|