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.

5
  • Does this answer your question? git-python get commit feed from a repository Commented Sep 14, 2022 at 12:25
  • 1
    github.com/PyGithub/PyGithub/issues/2261 Commented Sep 14, 2022 at 12:32
  • @AlexisG The question is about PyGithub accessing a remote repository hosted at GitHub. No local repo, no GitPython. Commented Sep 14, 2022 at 12:35
  • github.com/PyGithub/PyGithub/issues/2261 this works for me Thanks :) Commented Sep 14, 2022 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. Commented Sep 16, 2022 at 15:26

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Using "branch.commit.commit.message" i am getting all commit message but I want the lastest commit message

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.