forked from longhorn/bot
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Jack Yu <[email protected]>
- Loading branch information
Showing
7 changed files
with
146 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import re | ||
|
||
from flask import render_template | ||
|
||
from harvester_github_bot.label_action.create_gui_issue import CreateGUIIssue | ||
from harvester_github_bot.label_action.create_backport import CreateBackport | ||
from harvester_github_bot.action import Action | ||
from harvester_github_bot import app, gtihub_project_manager, repo, repo_test, \ | ||
ZENHUB_PIPELINE, GITHUB_OWNER, GITHUB_REPOSITORY, ZENHUB_PIPELINE, GITHUB_REPOSITORY_TEST | ||
|
||
template_re = re.compile('---\n.*?---\n', re.DOTALL) | ||
|
||
|
||
class ActionProject(Action): | ||
def __init__(self): | ||
self.__event_type_key = "projects_v2_item" | ||
|
||
def isMatched(self, actionRequest): | ||
if actionRequest.event_type not in [self.__event_type_key]: | ||
return False | ||
if actionRequest.action not in ['edited']: | ||
return False | ||
return True | ||
|
||
def action(self, request): | ||
if request[self.__event_type_key]["content_type"] != "Issue": | ||
return | ||
|
||
project_node_id = request[self.__event_type_key]['project_node_id'] | ||
if gtihub_project_manager.project()["id"] != project_node_id: | ||
app.logger.error("project is not matched") | ||
return | ||
|
||
target_column = request['changes']['field_value']['to'] | ||
if target_column["name"] not in ZENHUB_PIPELINE.split(","): | ||
app.logger.debug('target_column is {}, ignoring'.format(target_column["name"])) | ||
return | ||
|
||
issue_node_id = request[self.__event_type_key]['content_node_id'] | ||
issue = gtihub_project_manager.get_global_issue(issue_node_id) | ||
|
||
if issue["number"] is None: | ||
app.logger.error("issue number is None") | ||
return | ||
|
||
it = IssueTransfer(issue["number"]) | ||
it.create_comment_if_not_exist() | ||
it.create_e2e_issue() | ||
|
||
|
||
class IssueTransfer: | ||
def __init__( | ||
self, | ||
issue_number | ||
): | ||
self.__comments = None | ||
self.__issue = repo.get_issue(issue_number) | ||
|
||
def create_comment_if_not_exist(self): | ||
self.__comments = self.__issue.get_comments() | ||
found = False | ||
for comment in self.__comments: | ||
if comment.body.strip().startswith('## Pre Ready-For-Testing Checklist'): | ||
app.logger.debug('pre-merged checklist already exists, not creating a new one') | ||
found = True | ||
break | ||
if not found: | ||
app.logger.debug('pre-merge checklist does not exist, creating a new one') | ||
self.__issue.create_comment(render_template('pre-merge.md')) | ||
|
||
def create_e2e_issue(self): | ||
require_e2e = True | ||
labels = self.__issue.get_labels() | ||
for label in labels: | ||
if label.name == 'not-require/test-plan': | ||
require_e2e = False | ||
break | ||
if require_e2e: | ||
found = False | ||
for comment in self.__comments: | ||
if comment.body.startswith('Automation e2e test issue:'): | ||
app.logger.debug('Automation e2e test issue already exists, not creating a new one') | ||
found = True | ||
break | ||
if not found: | ||
app.logger.debug('Automation e2e test issue does not exist, creating a new one') | ||
|
||
issue_link = '{}/{}#{}'.format(GITHUB_OWNER, GITHUB_REPOSITORY, self.__issue.number) | ||
issue_test_title = '[e2e] {}'.format(self.__issue.title) | ||
issue_test_template_content = repo_test.get_contents( | ||
".github/ISSUE_TEMPLATE/test.md").decoded_content.decode() | ||
issue_test_body = template_re.sub("\n", issue_test_template_content, count=1) | ||
issue_test_body += '\nrelated issue: {}'.format(issue_link) | ||
issue_test = repo_test.create_issue(title=issue_test_title, body=issue_test_body) | ||
|
||
issue_test_link = '{}/{}#{}'.format(GITHUB_OWNER, GITHUB_REPOSITORY_TEST, issue_test.number) | ||
|
||
# link test issue in Harvester issue | ||
self.__issue.create_comment('Automation e2e test issue: {}'.format(issue_test_link)) | ||
else: | ||
app.logger.debug('label require/automation-e2e does not exists, not creating test issue') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters