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

87 lines
2.1 KiB
Python
Raw Normal View History

2019-11-22 15:03:21 +01:00
#!/usr/bin/env python3
2019-11-30 13:49:44 +01:00
import os
2019-11-22 15:03:21 +01:00
import requests
2019-11-30 13:49:44 +01:00
PROJECT = os.getenv("PUSHEE_PROJECT")
TOKEN = os.getenv("GITLAB_FI_TOKEN")
2019-11-22 15:03:21 +01:00
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}
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