[英]Count of commits in azure devops git repo using Python
I am trying to count no of commits in a repo in Azure devops using python. I am referring this https://github.com/microsoft/azure-devops-python-api .我正在尝试使用 python 计算 Azure devops 中 repo 中的提交数。我指的是这个https://github.com/microsoft/azure-devops-python-api 。 Can anybody help me in how to count no of commits in azure devops using python.
任何人都可以帮助我如何使用 python 计算 azure devops 中的提交数。
Try this Rest API , it will return the count.试试这个Rest API ,它会返回计数。
GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/commits?api-version=6.0
So the code in Python will be:所以 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'])
I also tried the method in Python get_commits
.我还尝试了 Python
get_commits
中的方法。 But it will return the commit objects without count.但它会返回没有计数的提交对象。
git_client = connection.clients.get_git_client()
commits = git_client.get_commits("repo_id", None)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.