1

Im managing a jenkins pipeline for automation tests, and I need to start different suite of tests depending on whether the PR is approved or not. Is there a way to get this info from console or any API?

nm1234
  • 11
  • 1
  • If you are using webhooks to trigger the Pipeline this information would be available to you. – ycr Oct 17 '22 at 13:33

1 Answers1

0

Gitea offers a bunch of REST APIs and it is enabled by default, you can simply check it on https://gitea.your.host/api/swagger.

Here is the sample for checking PR's status via Gitea's API:

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()}")

Note that to make API requests to your Gitea instance, you'll need to generate a personal access token with the appropriate scope "repo".

Corey
  • 1,217
  • 3
  • 22
  • 39