0
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 i.e, Commit(sha="026493bb65bc12c99f66c159eda050471d6757ff") instead of commit message.
Could you please help me to print the last commit message of a specific branch.

torek
  • 448,244
  • 59
  • 642
  • 775
  • Does this answer your question? [git-python get commit feed from a repository](https://stackoverflow.com/questions/6806266/git-python-get-commit-feed-from-a-repository) – AlexisG Sep 14 '22 at 12:25
  • 1
    https://github.com/PyGithub/PyGithub/issues/2261 – matszwecja Sep 14 '22 at 12:32
  • @AlexisG The question is about PyGithub accessing a remote repository hosted at GitHub. No local repo, no GitPython. – phd Sep 14 '22 at 12:35
  • github.com/PyGithub/PyGithub/issues/2261 this works for me Thanks :) – Deepak Rohilla Sep 14 '22 at 12:40
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Sep 16 '22 at 15:26

1 Answers1

0

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

matszwecja
  • 6,357
  • 2
  • 10
  • 17