-
-
Notifications
You must be signed in to change notification settings - Fork 0
ci: Add workflow to close resolved reproduction PRs #30
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
Open
dingsdax
wants to merge
4
commits into
main
Choose a base branch
from
add-close-resolved-repros-workflow
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+103
−0
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0e6f294
ci: Add workflow to close resolved reproduction PRs
dingsdax 7d91368
fix(ci): Move label after close to prevent stuck PRs
dingsdax 6155b82
fix(ci): Only close repro PRs when upstream is completed
dingsdax 1f6b02e
fix(ci): Wrap close/comment/label in try-catch
dingsdax File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,103 @@ | ||
| name: Close resolved repros | ||
|
|
||
| on: | ||
| schedule: | ||
| - cron: "0 9 * * *" # daily at 9am UTC | ||
| workflow_dispatch: | ||
| inputs: | ||
| dry_run: | ||
| description: "Log which PRs would be closed without taking action" | ||
| type: boolean | ||
| default: false | ||
|
|
||
| permissions: | ||
| issues: write | ||
| pull-requests: write | ||
|
|
||
| jobs: | ||
| close-resolved: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Close PRs whose upstream issue is resolved | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| const owner = context.repo.owner; | ||
| const repo = context.repo.repo; | ||
| const label = 'resolved-upstream'; | ||
| const dryRun = context.payload.inputs?.dry_run === 'true'; | ||
|
|
||
| // Fetch all open PRs (paginated) | ||
| const prs = await github.paginate(github.rest.pulls.list, { | ||
| owner, | ||
| repo, | ||
| state: 'open', | ||
| per_page: 100, | ||
| }); | ||
|
|
||
| // Match titles like "Reproduction for sentry-ruby#2842" | ||
| const titleRe = /^Reproduction for (sentry-[\w-]+#\d+)/; | ||
|
|
||
| for (const pr of prs) { | ||
| const match = pr.title.match(titleRe); | ||
| if (!match) continue; | ||
|
|
||
| // Skip if already labelled (already processed on a previous run) | ||
| if (pr.labels.some(l => l.name === label)) continue; | ||
|
|
||
| const [upstreamRepo, issueNumber] = match[1].split('#'); | ||
|
|
||
| let issue; | ||
| try { | ||
| issue = await github.rest.issues.get({ | ||
| owner: 'getsentry', | ||
| repo: upstreamRepo, | ||
| issue_number: Number(issueNumber), | ||
| }); | ||
| } catch (err) { | ||
| core.warning( | ||
| `PR #${pr.number}: could not fetch getsentry/${upstreamRepo}#${issueNumber} — ${err.message}` | ||
| ); | ||
| continue; | ||
| } | ||
|
|
||
| if (issue.data.state !== 'closed' || issue.data.state_reason !== 'completed') continue; | ||
|
|
||
| core.info(`PR #${pr.number}: upstream getsentry/${upstreamRepo}#${issueNumber} is resolved`); | ||
|
|
||
| if (dryRun) { | ||
| core.info(` [dry run] would label and close PR #${pr.number}`); | ||
| continue; | ||
| } | ||
|
|
||
| try { | ||
| // Close first — if this fails, the PR stays open and unlabelled | ||
| // so the next run retries cleanly with no duplicate comments | ||
| await github.rest.pulls.update({ | ||
| owner, | ||
| repo, | ||
| pull_number: pr.number, | ||
| state: 'closed', | ||
| }); | ||
|
|
||
| await github.rest.issues.createComment({ | ||
| owner, | ||
| repo, | ||
| issue_number: pr.number, | ||
| body: [ | ||
| `Upstream issue [getsentry/${upstreamRepo}#${issueNumber}](https://github.com/getsentry/${upstreamRepo}/issues/${issueNumber}) has been closed.`, | ||
| '', | ||
| 'Closing this reproduction PR. Re-open if the issue resurfaces!', | ||
| ].join('\n'), | ||
| }); | ||
|
|
||
| await github.rest.issues.addLabels({ | ||
| owner, | ||
| repo, | ||
| issue_number: pr.number, | ||
| labels: [label], | ||
| }); | ||
| } catch (err) { | ||
| core.warning(`PR #${pr.number}: failed to close — ${err.message}`); | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Partial failure leaves PR closed without label permanently
Low Severity
The close, comment, and label API calls are wrapped in a single
try/catch. Ifpulls.update(close) succeeds butcreateCommentoraddLabelsthrows, the PR ends up closed without theresolved-upstreamlabel. Since subsequent runs only fetch open PRs viastate: 'open', this PR will never be retried, and the label — described as key for distinguishing these from manually closed PRs — is permanently lost. Separatetry/catchblocks for the comment and label calls after the close would allow those operations to be attempted independently.Additional Locations (1)
.github/workflows/close-resolved-repros.yml#L33-L34