简体   繁体   中英

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)

But the print(branch.commit) print the commit SHA ie, Commit(sha="026493bb65bc12c99f66c159eda050471d6757ff") instead of commit message.
Could you please help me to print the last commit message of a specific branch.

As you can read in the documentation for PyGitHub , GitCommit objects contain .message attribute with the data you need. Commit objects contain corresponding GitCommit object in .commit attribute. Thus you can access the data you need with branch.commit.commit.message

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM