git 如何在gerrit REST API中获取项目的所有未合并提交?

egdjgwm8  于 2023-04-19  发布在  Git
关注(0)|答案(1)|浏览(214)

嗨,我试图使用Gerrit REST API和python从特定的仓库中获取所有未被管理的提交(它们是活动的)。有人能帮助我如何做到这一点吗?示例项目:TEST/Python/calcapp感谢帮助!

igetnqfo

igetnqfo1#

import requests

GERRIT_URL = 'https://your-gerrit-instance-url.com'
PROJECT = 'TEST/Python/calcapp'
QUERY = 'status:open'  # Query for unmerged commits

def get_unmerged_commits(url, project, query):
    endpoint = f"{url}/changes/?q=project:{project}+{query}&o=ALL_REVISIONS&o=ALL_FILES"
    response = requests.get(endpoint, auth=('your_username', 'your_password'))

    if response.status_code == 200:
        unmerged_commits = response.json()
        return unmerged_commits
    else:
        print(f"Error: {response.status_code}")
        return None

unmerged_commits = get_unmerged_commits(GERRIT_URL, PROJECT, QUERY)

if unmerged_commits:
    for commit in unmerged_commits:
        print(f"Change ID: {commit['change_id']}")
        print(f"Subject: {commit['subject']}")
        print(f"Owner: {commit['owner']['name']} ({commit['owner']['email']})")
        print("-" * 40)

相关问题