jenkins Gitea:Pull Request approval status

pxq42qpu  于 2023-08-03  发布在  Jenkins
关注(0)|答案(1)|浏览(100)

我正在管理一个用于自动化测试的Jenkins管道,我需要根据PR是否被批准来启动不同的测试套件。有没有办法从控制台或任何API获取此信息?

lymgl2op

lymgl2op1#

Gitea提供了一堆REST API,默认情况下是启用的,你可以简单地在https://gitea.your.host/api/swagger上检查它。
下面是通过Gitea的API查看PR状态的示例:

import requests

gitea_url = "http://gitea.your.host/api/v1"
repository_owner = "repo_owner"
repository_name = "repo_name"
access_token = "your_access_token"

# pr number you want to check
pull_request_number = 4

headers = {"Authorization": f"token {access_token}"}

response = requests.get(
    f"{gitea_url}/repos/{repository_owner}/{repository_name}/pulls/{pull_request_number}", headers=headers
)

if response.status_code == 200:
    pull_request_data = response.json()
    pull_request_state = pull_request_data["state"]
    print(f"Pull request #{pull_request_number} state: {pull_request_state}")
else:
    print(f"Error getting pull request: {response.status_code} - {response.json()}")

字符串
请注意,要向Gitea示例发出API请求,您需要生成一个具有适当范围“repo”的个人访问令牌。

相关问题