[英]python script to print the last commit message from specific git branch
from github import Github
import sys
import requests
import subprocess
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
# github connection
gc = Github(login_or_token = '3d09afd6df8d92bd', password = None, b
base_url = "https://eos2git.com/api/v3", timeout = 60, verify=False, retry=5)
# enter github repo
repo_gh = gc.get_repo('Devops/emporium')
# get the branches of the given repo
branches = repo_gh.get_branches()
for branch in branches:
if branch.name == "dev/anjali-raghu/DSE-401":
# print the last commit message of a branch
print(branch.commit)
但是 print(branch.commit) 打印提交 SHA 即 Commit(sha="026493bb65bc12c99f66c159eda050471d6757ff") 而不是提交消息。
您能幫我打印特定分支的最后提交消息嗎?
正如您在 PyGitHub 的文檔中所讀到的,GitCommit 對象包含帶有您需要的數據的.message
屬性。 Commit
對象在.commit
屬性中包含相應的 GitCommit object。 因此,您可以使用branch.commit.commit.message
訪問所需的數據
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.