Skip to content

Commit

Permalink
ref(notifications): improve github check messages for PR status (#72)
Browse files Browse the repository at this point in the history
CHANGES
- add message when PR is good to merge
- reduce some duplicated logic in mergeability for set_status

BEFORE
<img width="315" alt="Screen Shot 2019-07-17 at 7 22 52 PM" src="https://user-images.githubusercontent.com/1929960/61418371-4d944900-a8c8-11e9-80ca-b610b89bda10.png">
AFTER
<img width="307" alt="Screen Shot 2019-07-17 at 7 21 24 PM" src="https://user-images.githubusercontent.com/1929960/61418372-4d944900-a8c8-11e9-9fb3-336b838df0a4.png">
  • Loading branch information
chdsbd authored and kodiakhq[bot] committed Jul 17, 2019
1 parent e7fbb66 commit dc370f1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
9 changes: 9 additions & 0 deletions kodiak/evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,23 @@ class MissingAppID(BaseException):
another instance of kodiak.
"""

def __str__(self) -> str:
return "missing Github app id"


class BranchMerged(BaseException):
"""branch has already been merged"""

def __str__(self) -> str:
return str(self.__doc__)


class MergeConflict(BaseException):
"""Merge conflict in the PR."""

def __str__(self) -> str:
return "merge conflict"


def review_status(reviews: typing.List[PRReview]) -> PRReviewState:
"""
Expand Down
33 changes: 16 additions & 17 deletions kodiak/pull_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,24 @@ async def mergeability(
valid_merge_methods=self.event.valid_merge_methods,
)
self.log.info("okay")
await self.set_status(summary="⛴ ready to merge")
return MergeabilityResponse.OK, self.event
except MissingAppID:
return MergeabilityResponse.NOT_MERGEABLE, self.event
except NotQueueable as e:
await self.set_status(summary="🛑 cannot merge", detail=str(e))
return MergeabilityResponse.NOT_MERGEABLE, self.event
except MergeConflict:
await self.set_status(summary="🛑 cannot merge", detail="merge conflict")
if self.event.config.merge.notify_on_conflict:
except (NotQueueable, MissingAppID, MergeConflict, BranchMerged) as e:
if (
isinstance(e, MergeConflict)
and self.event.config.merge.notify_on_conflict
):
await self.notify_pr_creator()

if (
isinstance(e, BranchMerged)
and self.event.config.merge.delete_branch_on_merge
):
await self.client.delete_branch(
branch=self.event.pull_request.headRefName
)

await self.set_status(summary="🛑 cannot merge", detail=str(e))
return MergeabilityResponse.NOT_MERGEABLE, self.event
except MissingGithubMergeabilityState:
self.log.info("missing mergeability state, need refresh")
Expand All @@ -170,15 +178,6 @@ async def mergeability(
except NeedsBranchUpdate:
await self.set_status(summary="⏭ need update")
return MergeabilityResponse.NEEDS_UPDATE, self.event
except BranchMerged:
await self.set_status(
summary="🛑 cannot merge", detail="branch merged already"
)
if self.event.config.merge.delete_branch_on_merge:
await self.client.delete_branch(
branch=self.event.pull_request.headRefName
)
return MergeabilityResponse.NOT_MERGEABLE, self.event

async def update(self) -> None:
self.log.info("update")
Expand Down

0 comments on commit dc370f1

Please sign in to comment.