Skip to content

Commit

Permalink
fixed github MR approval status
Browse files Browse the repository at this point in the history
  • Loading branch information
ye11ow committed Sep 14, 2021
1 parent c99db49 commit a010a08
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
3 changes: 2 additions & 1 deletion noti.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,10 @@ def failed_pipeline_jobs(self):

return self._failed_pipeline_jobs

# As long as the state is not BLOCKED, we should consider the MR is approved.
@property
def approved(self):
return self._pr.mergeable
return self._pr.mergeable and self._pr.mergeable_state != 'blocked'

@property
def reviews(self):
Expand Down
7 changes: 6 additions & 1 deletion tests/unit/fixtures/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ def html_url(self):

class DummyPR:

def __init__(self, comments=[]):
def __init__(self, comments=[], mergeable_state='clean'):
self._head = MagicMock()
self._head.ref = '_branch_'
self._head.sha = '_sha_'
self._comments = comments
self._mergeable_state = mergeable_state

def get_comments(self):
return self._comments
Expand All @@ -51,6 +52,10 @@ def head(self):
def mergeable(self):
return True

@property
def mergeable_state(self):
return self._mergeable_state

class DummyBuild:

def __init__(self, state='success'):
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/test_github_pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ def test_failed_pipeline_jobs(self, default_pr):
def test_approved(self, default_pr):
assert default_pr.approved

def test_not_approved(self):
pr = GithubPR(MagicMock(), mock.DummyPR(mergeable_state='blocked'))
assert not pr.approved

def test_url(self, default_pr):
assert default_pr.url == '_url_'

Expand Down

0 comments on commit a010a08

Please sign in to comment.