计算Bitbucket上用户的平均贡献量。
代码示例:
import requests
import json
url = "https://api.bitbucket.org/2.0/repositories/{username}/{repo_slug}/commits"
# 替换成你的Bitbucket用户名和仓库slug
username = "your_username"
repo_slug = "your_repo_slug"
response = requests.get(url.format(username=username, repo_slug=repo_slug))
data = json.loads(response.text)
# 计算总贡献量和提交数
total = 0
count = 0
for commit in data["values"]:
total += commit["author"]["raw"]
count += 1
# 计算平均贡献量
if count > 0:
average = total / count
print("平均贡献量:", average)
else:
print("没有提交记录")
解释:这段Python代码通过Bitbucket API获取仓库提交记录,并计算出所有提交的贡献量总和和提交数。然后通过总贡献量除以提交数计算出平均贡献量。