【问题标题】:Count of commits in azure devops git repo using Python使用 Python 在 azure devops git repo 中的提交计数
【发布时间】:2021-08-20 16:19:36
【问题描述】:

我正在尝试使用 python 计算 Azure devops 中的 repo 中的提交次数。我指的是https://github.com/microsoft/azure-devops-python-api。任何人都可以帮助我如何使用 python 计算 azure devops 中的提交次数。

【问题讨论】:

  • 到目前为止你尝试了什么?
  • for branch in git_repo_branch: pprint.pprint(branch.name) git_repo_commit=git_client.get_commits(repo.name,search_criteria=) 我在这里,所以我尝试使用搜索条件,但如何使用搜索标准。

标签: python azure-devops


【解决方案1】:

试试这个Rest API,它会返回计数。

GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/commits?api-version=6.0

所以 Python 中的代码将是:

import requests
import base64
import json

pat = 'YOUR PAT'
authorization = str(base64.b64encode(bytes(':'+pat, 'ascii')), 'ascii')
headers = {
    'Accept': 'application/json',
    'Authorization': 'Basic '+authorization
}
response = requests.get(
    url="https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/commits?api-version=6.0", headers=headers)

data = json.loads(response.content)
print(data['count'])

我也尝试了 Python get_commits 中的方法。但它会返回不计其数的提交对象。

git_client = connection.clients.get_git_client()
commits = git_client.get_commits("repo_id", None)

【讨论】:

  • 我尝试通过 rest api 并且我能够获得存储库的提交计数,你能告诉什么“授权 = str(base64.b64encode(bytes(':'+pat,'ascii ')), 'ascii')" 这行代码是干什么的?
  • 习惯于authenticate with PAT。个人访问令牌 (PAT) 用作在 Azure DevOps 中进行身份验证的备用密码。您可以使用 OAuth 2.0 来代替。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-12-08
  • 2022-10-21
  • 2020-08-10
  • 1970-01-01
  • 1970-01-01
  • 2022-11-15
  • 1970-01-01
相关资源
最近更新 更多