Skip to content

Commit 540c4dc

Browse files
committed
Merge PR ceph#57183 into main
* refs/pull/57183/head: script/ptl-tool: add switch to update existing qa ticket Reviewed-by: Yuri Weinstein <[email protected]>
2 parents 10acaf6 + 0554785 commit 540c4dc

File tree

1 file changed

+36
-12
lines changed

1 file changed

+36
-12
lines changed

src/script/ptl-tool.py

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ def build_branch(args):
327327

328328
G = git.Repo(args.git)
329329

330-
if args.create_qa:
330+
if args.create_qa or args.update_qa:
331331
log.info("connecting to %s", REDMINE_ENDPOINT)
332332
R = Redmine(REDMINE_ENDPOINT, username=REDMINE_USER, key=REDMINE_API_KEY)
333333
log.debug("connected")
@@ -452,7 +452,7 @@ def build_branch(args):
452452
tag = git.refs.tag.Tag.create(G, tag_name)
453453
log.info("Created tag %s" % tag)
454454

455-
if args.create_qa:
455+
if args.create_qa or args.update_qa:
456456
if not created_branch:
457457
log.error("branch already exists!")
458458
sys.exit(1)
@@ -490,17 +490,36 @@ def build_branch(args):
490490
"subject": branch,
491491
"watcher_user_ids": user['id'],
492492
}
493-
log.debug("creating issue with kwargs: %s", issue_kwargs)
494-
issue = R.issue.create(**issue_kwargs)
495-
log.info("created redmine qa issue: %s", issue.url)
496493

494+
if args.update_qa:
495+
issue = R.issue.get(args.update_qa)
496+
if issue.project.id != project.id:
497+
log.error(f"issue {issue.url} project {issue.project} does not match {project}")
498+
sys.exit(1)
499+
if issue.tracker.id != tracker.id:
500+
log.error(f"issue {issue.url} tracker {issue.tracker} does not match {tracker}")
501+
sys.exit(1)
497502

498-
for pr in prs:
499-
log.debug(f"Posting QA Run in comment for ={pr}")
500-
endpoint = f"https://api.github.com/repos/{BASE_PROJECT}/{BASE_REPO}/issues/{pr}/comments"
501-
body = f"This PR is under test in [{issue.url}]({issue.url})."
502-
r = session.post(endpoint, auth=gitauth(), data=json.dumps({'body':body}))
503-
log.debug(f"= {r}")
503+
log.debug("updating issue with kwargs: %s", issue_kwargs)
504+
notes = f"""
505+
Updating branch to {branch}.
506+
"""
507+
if R.issue.update(issue.id, **issue_kwargs):
508+
log.info("updated redmine qa issue: %s", issue.url)
509+
else:
510+
log.error(f"failed to update {issue}")
511+
sys.exit(1)
512+
elif args.create_qa:
513+
log.debug("creating issue with kwargs: %s", issue_kwargs)
514+
issue = R.issue.create(**issue_kwargs)
515+
log.info("created redmine qa issue: %s", issue.url)
516+
517+
for pr in prs:
518+
log.debug(f"Posting QA Run in comment for ={pr}")
519+
endpoint = f"https://api.github.com/repos/{BASE_PROJECT}/{BASE_REPO}/issues/{pr}/comments"
520+
body = f"This PR is under test in [{issue.url}]({issue.url})."
521+
r = session.post(endpoint, auth=gitauth(), data=json.dumps({'body':body}))
522+
log.debug(f"= {r}")
504523

505524
def main():
506525
parser = argparse.ArgumentParser(description="Ceph PTL tool")
@@ -528,13 +547,18 @@ def main():
528547
parser.add_argument('--qa-release', dest='qa_release', action='store', help='QA release for tracker')
529548
parser.add_argument('--qa-tags', dest='qa_tags', action='store', help='QA tags for tracker')
530549
parser.add_argument('--stop-at-built', dest='stop_at_built', action='store_true', help='stop execution when branch is built')
550+
parser.add_argument('--update-qa', dest='update_qa', action='store', help='update QA run ticket')
531551
parser.add_argument('prs', metavar="PR", type=int, nargs='*', help='Pull Requests to merge')
532552
args = parser.parse_args(argv)
533553

554+
if args.create_qa and args.update_qa:
555+
log.error("--create-qa and --update-qa are mutually exclusive switches")
556+
sys.exit(1)
557+
534558
if args.debug:
535559
log.setLevel(logging.DEBUG)
536560

537-
if args.create_qa and Redmine is None:
561+
if (args.create_qa or args.update_qa) and Redmine is None:
538562
log.error("redmine library is not available so cannot create qa tracker ticket")
539563
sys.exit(1)
540564

0 commit comments

Comments
 (0)