Skip to content

Commit

Permalink
Merge pull request #87 from sopel-irc/86-issue-open-closed
Browse files Browse the repository at this point in the history
github: include issue/PR state in `issue_info()`
  • Loading branch information
dgw authored Jun 2, 2021
2 parents 5fe16e4 + 344b75c commit 4120bfc
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions sopel_modules/github/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,35 @@ def issue_info(bot, trigger, match=None):
else:
body = formatting.fmt_short_comment_body(body)

type_ = 'issue'
state = data['state']
if 'pull_request' in data:
type_ = 'PR'

if type_ == 'PR' and state == 'closed':
# annoying consequence of "all PRs are issues, but not all issues are PRs"
# merge status is only included if the object is fetched via `pulls` endpoint
try:
pr_raw = fetch_api_endpoint(bot, data['pull_request']['url'])
except HTTPError:
# just use the "issue" state, fine
pass

pr_data = json.loads(pr_raw)
if pr_data.get("merged"):
state = "merged"

response = [
bold('[GitHub]'),
' [',
repo,
' #',
num,
'] ',
state,
' ',
type_,
' by ',
data['user']['login'],
': '
]
Expand Down

0 comments on commit 4120bfc

Please sign in to comment.