PyGithub
PyGithub copied to clipboard
How can you retrieve the description of a pull request associated with a commit?
I've tried the following;
commit = org.get_repo("my-repo").get_commit(sha="c2144da718afdbc343115e995f585d6d58c7ec6bd")
print(commit.author)
print(commit.committer)
print(commit.last_modified)
Which returns the details of the commit, however, can not find how to fetch the commit message. I thought it might be;
print(commit.get_comments())
But that doesn't retrieve the commit message.
Does anyone know if it's possible?
thanks in advance!
@atulkpatel you can try this
print(commit.commit.message)
Ref: https://pygithub.readthedocs.io/en/latest/github_objects/GitCommit.html#github.GitCommit.GitCommit
Is there a way we can fetch commit description as well. commit.commit.message gives commit title but looking if there's a way to get description as well.
Are you sure the commit your are looking at has a multi-line message? The first line is used as the title, all lines are the message.
Here is an example:
import github
gh = github.Github()
repo = gh.get_repo("PyGithub/PyGithub")
commit = repo.get_commit("e47c153bad20306add8585d36b89e71610ce01df")
print(commit.commit.message)
Provides the multi-line commit message: e47c153bad20306add8585d36b89e71610ce01df
Add missing branch protection fields (#2873)
Co-authored-by: jodelasur <[email protected]>
Co-authored-by: Terence Ho <[email protected]>
Co-authored-by: harry-unlikelyai <[email protected]>
Sorry, I meant PR description. To elaborate my use case, I am looking for the Jira Issue ID in the PR associated with a commit sha. My team follows this process of adding the Jira ID in the PR description (and not in the commit message), so I was wondering if there is way to get the PR number from commit sha using PyGithub
Try Commit.get_pulls
to get associated pull requests, then PullRequest.body
:
import github
gh = github.Github()
repo = gh.get_repo("PyGithub/PyGithub")
commit = repo.get_commit("e47c153bad20306add8585d36b89e71610ce01df")
for pull in commit.get_pulls():
print(pull.body)
Great, that woirks! thank you!