Bitbucket使用Jira的API来匹配多个Jira问题。以下是使用Bitbucket API和Jira API的示例代码:
import requests
import re
BITBUCKET_API_URL = 'https://api.bitbucket.org/2.0/repositories/{owner}/{repo}/commits/{commit_id}/comments'
JIRA_API_URL = 'https://jira.example.com/rest/api/latest/issue/{issue_key}'
def find_jira_issues(commit_id, owner, repo):
# Get the commit message using the Bitbucket API
comments_response = requests.get(BITBUCKET_API_URL.format(owner=owner, repo=repo, commit_id=commit_id))
comments_data = comments_response.json()
commit_message = comments_data['values'][0]['content']['raw']
# Use regular expressions to match Jira issue keys
pattern = r'[A-Z]{2,}-\d+'
issue_keys = re.findall(pattern, commit_message)
jira_issues = {}
# Use the Jira API to get information about the Jira issues
for key in issue_keys:
jira_response = requests.get(JIRA_API_URL.format(issue_key=key))
jira_data = jira_response.json()
jira_issue = {
'title': jira_data['fields']['summary'],
'url': JIRA_API_URL.format(issue_key=key)
}
jira_issues[key] = jira_issue
return jira_issues
jira_issues = find_jira_issues('abc123', 'myusername', 'myrepository')
for issue_key, issue in jira_issues.items():
print('{}: {}'.format(issue_key, issue['title']))
print(issue['url'])
此脚本使用Bitbucket API获取给定提交的注释,使用正则表达式匹配多个Jira问题,并使用Jira API检索每个Jira问题的标题和URL。最后,它将Jira问题的键、标题和URL作为字典返回。