-
Notifications
You must be signed in to change notification settings - Fork 20
cherry-picked PR #14
base: master
Are you sure you want to change the base?
cherry-picked PR #14
Changes from all commits
d112a7e
ecae9f0
513c1d2
f84722b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| #!/usr/bin/env python3 | ||
| # | ||
| # Copyright 2019 Espressif Systems (Shanghai) PTE LTD | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
| from github import Github | ||
| import os | ||
| import re | ||
|
|
||
| def handle_push_event(event): | ||
| issue_numbers = [] | ||
| for commit in event['commits']: | ||
| commit_message = commit['message'] | ||
| issue_numbers += parse_commit_message(commit_message) | ||
|
|
||
| github = Github(os.environ['GITHUB_TOKEN']) | ||
| repo = github.get_repo(os.environ['GITHUB_REPOSITORY']) | ||
| for issue in issue_numbers: | ||
| gh_issue = repo.get_issue(int(issue)) | ||
| if gh_issue.pull_request: | ||
| update_pull_request(gh_issue.as_pull_request()) | ||
|
|
||
| def update_pull_request(pull_request): | ||
| print("Updating %s" % pull_request) | ||
| original_title = pull_request.title | ||
| # Check if original title already starts with [Merged] keyword. If yes, skip updating pull request. | ||
| if original_title.startswith('[Merged]'): | ||
| print('Pull request title suggests it was already merged. Skipping...') | ||
| return | ||
| # Prepend [Merged] to the pull request title | ||
| new_title = '[Merged] ' + original_title | ||
| pull_request.edit(title=new_title) | ||
| # Thank contributor for opening pull request. Let them know we didn't throw it away | ||
| pull_request.create_issue_comment('The pull request has been cherry-picked, the commit is linked above.\ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sometimes we actually do "close" a PR by doing something different to what the author originally intended, and with a totally different commit. We try to avoid this, but it's necessary sometimes. Ideally this action would check if the commit author is the same as the author of any of the commits in the PR branch, and only continue if it is. However this is probably a rare enough occasion that you can consider it a "nice to have". :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for suggestion. I have noted this feature request and will implement it in the future. |
||
| Thank you for your contribution!') | ||
|
|
||
|
|
||
| def parse_commit_message(commit_message): | ||
| # First regex matches numbers that come after Fix, fix, Fixed, fixed, Fixes, fixes keyword followed by any | ||
| # combination of spaces and colons, followed by exactly one hashtag. The same applies for Close and Resolve | ||
| # keywords and their combinations. Note: fixing, closing and resolving don't work. Only first number is picked. | ||
| # To match multiple numbers you have to add fix or close or resolve keyword for each of them. | ||
| # | ||
| # Second regex matches pull request numbers from pull reques url. | ||
| # | ||
| # Example: | ||
| # | ||
| # fixed: #1 #2 #3 | ||
| # resolved ::: ::: :: #4 | ||
| # closes: ##5 | ||
| # fix: # 6 | ||
| # asdfresolves #7 | ||
| # closeasdf: #8 | ||
| # closes #9 <any sting in between> fixed #10 | ||
| # fixing #11 | ||
igrr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # https://github.com/espressif/esp-idf/pull/12\ | ||
| # https://github.com/espressif/esp-idf/pull/ 13\ | ||
| # https://github.com/espressif/esp-idf/pull/#14\ | ||
| # https://github.com/ESPRESSIF/esp-idf/pull/15 | ||
| # | ||
| # Above example matches: [1, 4, 9, 10, 12, 15] | ||
|
|
||
| # | ||
| reference_pattern = re.compile(r'(?:closes?|closed|fixes|fix|fixed|resolves?|resolved)(?:\s|:)+#(\d+)', re.IGNORECASE) | ||
| url_pattern = re.compile(r'(?:https://github.com/espressif/esp-idf/pull/)(\d+)', re.IGNORECASE) | ||
| matches = [] | ||
| matches += reference_pattern.findall(commit_message) | ||
| matches += url_pattern.findall(commit_message) | ||
| return matches | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ | |
| import json | ||
| from sync_pr import sync_remain_prs | ||
| from sync_issue import * | ||
| from push_event import handle_push_event | ||
|
|
||
|
|
||
| class _JIRA(JIRA): | ||
|
|
@@ -52,6 +53,11 @@ def main(): | |
| with open(os.environ['GITHUB_EVENT_PATH'], 'r') as f: | ||
| event = json.load(f) | ||
| print(json.dumps(event, indent=4)) | ||
|
|
||
| # Check if it's a push event | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggest this would be easier to test and maintain as a standalone action. There isn't any conceptual relationship between this functionality and JIRA, and the script doesn't use any functions from the jira sync code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I plan to refactor the github-actions so it is standalone action. Unfortunately this requires much more effort than I anticipated initially and I suggest we address that in new pull request. |
||
| if os.environ['GITHUB_EVENT_NAME'] == 'push': | ||
| handle_push_event(event) | ||
| return | ||
|
|
||
| event_name = os.environ['GITHUB_EVENT_NAME'] # The name of the webhook event that triggered the workflow. | ||
| action = event["action"] | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.