This repository has been archived by the owner on Nov 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move linked issues adjacent to their linked PRs
- Loading branch information
1 parent
52b8b6d
commit 0af3222
Showing
3 changed files
with
74 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/usr/bin/python3 | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
|
||
import enarxbot | ||
import re | ||
|
||
github = enarxbot.connect() | ||
|
||
# Get the Enarx org. | ||
org = github.get_organization('enarx') | ||
|
||
# Get the Sprint board. | ||
sprint = {p.name: p for p in org.get_projects(state='open')}['Sprint'] | ||
|
||
# Cache the Sprint board to avoid redundant network requests. | ||
sprint_cached = enarxbot.cache_boards([sprint]) | ||
|
||
for issue in github.search_issues(f"org:enarx is:pr is:public is:open linked:issue -is:draft project:enarx/{sprint.number}"): | ||
# Some attributes change when converting to PR; get them beforehand. | ||
repo = issue.repository | ||
(pr_project, pr_column, pr_card) = sprint_cached[issue.id] | ||
|
||
# Convert to a PR. | ||
pr = issue.as_pull_request() | ||
|
||
# Get a list of related issues to the PR. | ||
related = {repo.get_issue(i) for i in enarxbot.get_related_issues(pr)} | ||
|
||
# Move every related issue adjacent to the PR in the sprint board. | ||
for issue in related: | ||
try: | ||
(issue_project, issue_column, issue_card) = sprint_cached[issue.id] | ||
except: | ||
# If an exception, the issue isn't in the board. Add it directly. | ||
print(f"Adding issue {repo.name}#{issue.number} adjacent to PR {repo.name}#{pr.number}") | ||
issue_card = enarxbot.create_card(pr_column, issue.id, "Issue") | ||
issue_card.move(f"after:{pr_card.id}", pr_column) | ||
continue | ||
|
||
# Only move if the issue is in a different column to the PR. | ||
if issue_column != pr_column: | ||
print(f"Moving issue {repo.name}#{issue.number} adjacent to PR {repo.name}#{pr.number}") | ||
issue_card.move(f"after:{pr_card.id}", pr_column) |
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