Bitbucket文件更改日志

时间:2018-11-02 08:26:40

标签: bitbucket-server bitbucket-api

是否可以在指定文件路径的特定分支上获取文件更改日志/提交列表或最新提交? 我尝试使用/ commits /?path = {filepath}&until = {branch -name}。然后提取json的第一个元素以获取最新提交。 但是有些数据与位桶中的数据不同。

1 个答案:

答案 0 :(得分:0)

以下是获取特定文件的最新提交的摘要:

#!/usr/bin/python

import os
import tempfile
import sys
import urllib2
import json
import base64
import logging
import re
import pprint
import requests
import subprocess

projectKey= "FW"
repoKey = "fw"
branch = "master"
pathToVersionProperties = "core/CruiseControl/CI_version.properties"
localVersionProperties = "CI_version.properties"
bitbucketBaseUrl = "https://bitbucket.company.com/rest/api/latest"
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)s %(message)s')

    def getLatestCommit():
        restEndpoint = "{}/projects/{}/repos/{}/commits?path={}".format(bitbucketBaseUrl, projectKey, repoKey, pathToVersionProperties)
        logging.info("REST endpoint : {}".format(restEndpoint))

         request = urllib2.Request(restEndpoint)
         request.add_header("Authorization", "Bearer %s" % os.environ["PAT"])
         result = json.loads(urllib2.urlopen(request).read())
         latestCommit = result["values"][0]["displayId"]
         if(len(latestCommit) > 0):
              logging.info("Latest commit: {}".format(latestCommit))
         else:
             logging.error("Commit hash is empty, failed to retrieve latest commit")
             sys.exit(1)
    return latestCommit

 latestCommit = getLatestCommit()

您可以使用pip install stashy安装stashy。