-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes to allow MergeBot to post to the Commit Status API #19
Conversation
Signed-off-by: Jason Kuster <[email protected]>
Signed-off-by: Jason Kuster <[email protected]>
mergebot_backend/github_helper.py
Outdated
COMMIT_STATE_PENDING = 'pending' | ||
COMMIT_STATE_SUCCESS = 'success' | ||
COMMIT_STATE_ERROR = 'error' | ||
COMMIT_STATE_FAILURE = 'failure' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's difference between error and failure? Probably some documents here or other place?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error is a problem that happened on MergeBot's side -- something that should be retried. Failure indicates something went wrong that wasn't MergeBot's fault -- bad rebase, tests failed, merge conflict, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a comment here to clarify.
@@ -155,14 +169,46 @@ def post_info(self, content, logger): | |||
""" | |||
self.post_pr_comment('Info: {}'.format(content), logger) | |||
|
|||
def post_commit_status(self, state, url, description, context, logger): | |||
""" Posts a commit status update to this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please correct me if I'm wrong, it looks like a function that posts/updates merge status to the particular PR. If that's true, how about something like post/update_merge_status
? since commit
makes me think of a specific commit in a PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is actually attached to a particular commit, and is using the "Commit Status API" from GitHub.
https://developer.github.com/v3/repos/statuses/
Statuses need to be attached to specific commits since they are what represent the HEAD of a particular pull request. GitHub doesn't have any other way to do this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it.
@@ -289,6 +319,17 @@ def merge_git_pr(self, pr): | |||
_set_up(tmp_dir) | |||
self.execute_merge_lifecycle(pr, tmp_dir, pr_logger) | |||
except AssertionError as exc: | |||
pr.post_commit_status( | |||
state=github_helper.COMMIT_STATE_FAILURE, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why "failure" not "error"?
Also i'm thinking if someone that first use mergebot, how can they tell difference between failure and error status? Do I miss anything that contains more instructions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like the description tell the difference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AssertionErrors indicate something has gone preventably wrong in the PR (as mentioned in the above comment) and thus FAILURE is the appropriate level.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it.
mergebot_backend/merge.py
Outdated
state=github_helper.COMMIT_STATE_ERROR, | ||
url=MERGEBOT_ITEM_URL.format( | ||
name=self.config.name, number=pr.get_num()), | ||
description='MergeBot shutdown; resubmit when mergebot is back up.', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we provide a url for health check? or some instructions? If I'm new to mergebot and got this message, I'll have no idea when mergebot is back up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll update the URL to the top-level MergeBot page which indicates whether MergeBot is back up, but all of the URLs on these point to the MergeBot frontend.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated URL.
# In the case of shutdown, we still post back to the pull request | ||
# because otherwise if mergebot is stopped and restarted we will try | ||
# this pull request again. If mergebot is modified to work with webhooks | ||
# this can be removed. | ||
pr.post_info('MergeBot shutting down; please resubmit when MergeBot is ' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need to post similar content comparing to line 286? I guess it's another comment just right next to the above one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what you mean by this -- in this section we're both updating the commit status (line ~286), and posting a comment on the PR indicating the same message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I previously thought the status commit is the place where people commenting on a PR. I think it's good now 👍
state=github_helper.COMMIT_STATE_PENDING, | ||
url=MERGEBOT_ITEM_URL.format( | ||
name=self.config.name, number=pr_num), | ||
description='Started Work', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
start merging or start running jenkins build?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This indicates that MergeBot has begun work on this PR. I could add additional commit status updates which show when the status changes in intermediary ways, if that's something you think would be useful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's clear enough. I have better understanding after saw the real case :)
Signed-off-by: Jason Kuster <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. Just one more question.
@@ -155,14 +169,46 @@ def post_info(self, content, logger): | |||
""" | |||
self.post_pr_comment('Info: {}'.format(content), logger) | |||
|
|||
def post_commit_status(self, state, url, description, context, logger): | |||
""" Posts a commit status update to this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it.
state=github_helper.COMMIT_STATE_PENDING, | ||
url=MERGEBOT_ITEM_URL.format( | ||
name=self.config.name, number=pr_num), | ||
description='Started Work', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's clear enough. I have better understanding after saw the real case :)
# In the case of shutdown, we still post back to the pull request | ||
# because otherwise if mergebot is stopped and restarted we will try | ||
# this pull request again. If mergebot is modified to work with webhooks | ||
# this can be removed. | ||
pr.post_info('MergeBot shutting down; please resubmit when MergeBot is ' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I previously thought the status commit is the place where people commenting on a PR. I think it's good now 👍
@@ -289,6 +319,17 @@ def merge_git_pr(self, pr): | |||
_set_up(tmp_dir) | |||
self.execute_merge_lifecycle(pr, tmp_dir, pr_logger) | |||
except AssertionError as exc: | |||
pr.post_commit_status( | |||
state=github_helper.COMMIT_STATE_FAILURE, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it.
pr.post_commit_status( | ||
state=github_helper.COMMIT_STATE_ERROR, | ||
url=job_url, | ||
description='Timed out waiting for job start.', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sometimes Jenkins doesn't have enough executors so job will be queued. Is it possible that job is queued and timed out on mergebot side?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this will still find queued jobs, but I'll investigate that and get back to you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't appear to find queued jobs. I've bumped the timeout to 10 minutes to compensate -- if jobs are waiting longer than 10 minutes we probably need new executors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There will be resource waste if timeout here since Jenkins will run the queued job anyway. Another issue is created and we can address it in another PR.
LGTM |
No description provided.