我在浏览git命令时,找不到一个可以接收MR id并给出merge request object之类的命令,我可以从这里获取目标分支。有没有这样的git命令?我也使用GitPython,所以如果包中有任何API,也可以工作。
pgky5nke1#
如果你使用GitLab,你可以使用requests库。例如:
import requests # API endpoint and access token gitlab_url = 'https://gitlab.example.com/api/v4' access_token = '<your-access-token>' # MR ID and project ID mr_id = 123 project_id = 456 # get MR info response = requests.get(f'{gitlab_url}/projects/{project_id}/merge_requests/{mr_id}', headers={'Private-Token': access_token}) # Extract target branch target_branch = response.json()['target_branch'] print(f'The target branch for MR {mr_id} is {target_branch}')
如果你使用GitHub,你可以使用github库。示例:
from github import Github # token and repository info access_token = '<your-access-token>' repo_name = '<owner>/<repo>' pr_id = 123 g = Github(access_token) # repository object repo = g.get_repo(repo_name) # pull request object pr = repo.get_pull(pr_id) # target branch name target_branch = pr.base.ref print(f'The target branch for PR {pr_id} is {target_branch}')
1条答案
按热度按时间pgky5nke1#
如果你使用GitLab,你可以使用requests库。例如:
如果你使用GitHub,你可以使用github库。示例: