简体   繁体   English

azure 中的提交计数 devops git repo 使用 Python

[英]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.

相关问题 在 Azure DevOps Git 存储库中使用来自 Azure Pipelines 的 Python 包版本标记 Git 存储库 - Tag Git repo with Python Package version from Azure Pipelines in Azure DevOps Git repo 如何使用 Python 与 Azure devops Repo-Branches 交互 - How to interact with Azure devops Repo-Branches using Python 将 Python 代码从 Azure Devops 存储库移动到 Windows Azure VM - Move python code from Azure Devops repo to windows Azure VM Invalid Json error when Uploading/pushing a file to Azure Devops Repo using Pushes Create Api with Python - Invalid Json error when Uploading/pushing a file to Azure Devops Repo using Pushes Create Api with Python 使用推送将文件上传/推送到 Azure Devops Repo 时如何找到 oldobjectid - How to find oldobjectid when Uploading/pushing a file to Azure Devops Repo using Pushes Create Api with Python 如何使用 azure devops 管道编辑 azure repo 中的 py 文件? - how to edit py file in azure repo using azure devops pipline? 使用存储在私有 Git 存储库中的 python package 存储库用于 Z3A580F142203677F1F0BC308ZF 应用程序? - Using a python package stored in private Git Repo for Azure Functions and Container Apps? Bitbucket git push提交而不克隆存储库 - Bitbucket git push commits without cloning the repo Azure DevOps 添加评论使用 Python API - Azure DevOps add a comment using the Python API 如何使用python克隆git repo? - How to clone a git repo using python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM