Skip to content

Commit

Permalink
Merge pull request #130 from marusinm/github-merged-prs
Browse files Browse the repository at this point in the history
allow usage of PRStatus.merged for Github get_pr_list(status)
  • Loading branch information
lachmanfrantisek authored Jul 23, 2019
2 parents 8f31ca9 + 871e9b3 commit fed150b
Show file tree
Hide file tree
Showing 6 changed files with 26,219 additions and 5,520 deletions.
15 changes: 13 additions & 2 deletions ogr/services/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,17 @@ def add_issue_labels(self, issue_id, labels) -> None:

def get_pr_list(self, status: PRStatus = PRStatus.open) -> List[PullRequest]:
prs = self.github_repo.get_pulls(
state=status.name, sort="updated", direction="desc"
# Github API has no status 'merged', just 'closed'/'opened'/'all'
state=status.name if status != PRStatus.merged else "closed",
sort="updated",
direction="desc",
)

if status == PRStatus.merged:
prs = list(prs) # Github PaginatedList into list()
for pr in prs:
if not pr.is_merged(): # parse merged PRs
prs.remove(pr)
try:
return [self._pr_from_github_object(pr) for pr in prs]
except UnknownObjectException:
Expand Down Expand Up @@ -584,7 +593,9 @@ def _pr_from_github_object(github_pr: GithubPullRequest) -> PullRequest:
return PullRequest(
title=github_pr.title,
id=github_pr.number,
status=PRStatus[github_pr.state],
status=PRStatus.merged
if github_pr.is_merged()
else PRStatus[github_pr.state],
url=github_pr.html_url,
description=github_pr.body,
author=github_pr.user.name,
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

16 changes: 14 additions & 2 deletions tests/integration/test_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,18 @@ def test_pr_list(self):
pr_list_closed = self.colin_project.get_pr_list(status=PRStatus.closed)
assert pr_list_closed
assert len(pr_list_closed) >= 140
closed_pr_numbers = []
for closed_pr in pr_list_closed:
closed_pr_numbers.append(closed_pr.id)
assert 23 in closed_pr_numbers

pr_list_merged = self.colin_project.get_pr_list(status=PRStatus.merged)
assert pr_list_merged
assert len(pr_list_merged) >= 1
closed_pr_numbers = []
for closed_pr in pr_list_merged:
closed_pr_numbers.append(closed_pr.id)
assert 23 not in closed_pr_numbers

pr_list = self.colin_project.get_pr_list()
assert pr_list
Expand All @@ -224,8 +236,8 @@ def test_pr_list(self):
def test_pr_info(self):
pr_info = self.colin_project.get_pr_info(pr_id=1)
assert pr_info
assert pr_info.title.startswith("Add basic structure")
assert pr_info.status == PRStatus.closed
assert pr_info.title.startswith("new")
assert pr_info.status == PRStatus.merged

def test_update_pr_info(self):
self.colin_project.update_pr_info(
Expand Down

0 comments on commit fed150b

Please sign in to comment.