sigmavirus24 / github3.py

Hi, I'm a library for interacting with GItHub's REST API in a convenient and ergonomic way. I work on Python 3.6+.
https://github3.readthedocs.io
BSD 3-Clause "New" or "Revised" License
1.21k stars 404 forks source link

Get approval status of the pr #1133

Closed thatdevin closed 1 year ago

thatdevin commented 1 year ago

Hi there, I currently use the cool package and I am wondering how f there is an API that I could use to get the approval status of a specific PR?

BR, Yue

offbyone commented 1 year ago

Yep:

repo = g.repository(owner, repo)
pr = repo.pull_request(PR_NUMBER_AS_STRING)
states = [r.state for r in pr.reviews()]

That gets the review statuses.

pr.mergeable and pr.mergeable_state tell you if the PR is able to merge.

Checks are the other approving concept and you can get at those using the commits on the PR:

most_recent_commit = list(pr.commits())[-1]
runs = list(most_recent_commit.check_runs())
statuses = [r.status for r in runs]