-
-
Notifications
You must be signed in to change notification settings - Fork 847
Reopen Issues Without Linked PR #8438
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
Merged
t-will-gillis
merged 4 commits into
hackforla:gh-pages
from
myronchen-git:check-closed-issue-for-linked-pr-8139
Feb 5, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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,47 @@ | ||
| name: Check Closed Issue for Linked PR | ||
|
|
||
| on: | ||
| issues: | ||
| types: [closed] | ||
|
|
||
| jobs: | ||
| check-for-linked-issue: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Check Out Repository | ||
| uses: actions/checkout@v6 | ||
|
|
||
| - name: Check Issue Labels And Linked PRs | ||
| uses: actions/github-script@v8 | ||
| id: check-issue-labels-and-linked-prs | ||
| with: | ||
| script: | | ||
| const script = require( | ||
| './github-actions' | ||
| + '/check-closed-issue-for-linked-pr' | ||
| + '/check-for-linked-issue' | ||
| + '/check-issue-labels-and-linked-prs.js' | ||
| ); | ||
| const isValidClose = await script({github, context}); | ||
| core.setOutput('isValidClose', isValidClose); | ||
|
|
||
| # Sleep to allow other GitHub Actions to change project status. | ||
| - name: Sleep | ||
| id: sleep | ||
| shell: bash | ||
| run: sleep 30s | ||
|
|
||
| - name: Reopen Issue | ||
| if: steps.check-issue-labels-and-linked-prs.outputs.isValidClose == 'false' | ||
| uses: actions/github-script@v8 | ||
| id: reopen-issue | ||
| with: | ||
| github-token: ${{ secrets.HACKFORLA_GRAPHQL_TOKEN }} | ||
| script: | | ||
| const script = require( | ||
| './github-actions' | ||
| + '/check-closed-issue-for-linked-pr' | ||
| + '/check-for-linked-issue' | ||
| + '/reopen-issue.js' | ||
| ); | ||
| await script({github, context}); | ||
94 changes: 94 additions & 0 deletions
94
...ck-closed-issue-for-linked-pr/check-for-linked-issue/check-issue-labels-and-linked-prs.js
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,94 @@ | ||
| const retrieveLabelDirectory = require('../../utils/retrieve-label-directory'); | ||
|
|
||
| // Use labelKeys to retrieve current labelNames from directory | ||
| const [ | ||
| nonPrContribution | ||
| ] = [ | ||
| 'NEW-nonPrContribution' | ||
| ].map(retrieveLabelDirectory); | ||
|
|
||
| // ================================================== | ||
|
|
||
| /** | ||
| * Checks whether a closed issue has a linked PR or one of the labels to excuse | ||
| * this GitHub Actions workflow. | ||
| * | ||
| * @param {{github: object, context: object}} actionsGithubScriptArgs - GitHub | ||
| * objects from actions/github-script | ||
| * @returns {boolean} False if the issue does not have a linked PR, a "non-PR | ||
| * contribution" label, or an "Ignore..." label. | ||
| */ | ||
| async function hasLinkedPrOrExcusableLabel({ github, context }) { | ||
| const repoOwner = context.repo.owner; | ||
| const repoName = context.repo.repo; | ||
| const issueNumber = context.payload.issue.number; | ||
|
|
||
| const labels = context.payload.issue.labels.map((label) => label.name); | ||
|
|
||
| const consoleMessageAllowClose = | ||
| `Issue #${issueNumber} is allowed to be closed.`; | ||
|
|
||
| // -------------------------------------------------- | ||
|
|
||
| // Check if the issue has the labels that will avoid re-opening it. | ||
| if ( | ||
| labels.some( | ||
| (label) => | ||
| label === nonPrContribution || label.toLowerCase().includes('ignore') | ||
| ) | ||
| ) { | ||
| console.info(consoleMessageAllowClose); | ||
| return true; | ||
| } | ||
|
|
||
| console.info( | ||
| `Issue #${issueNumber} does not have ` + | ||
| `the necessary labels to excuse reopening it.` | ||
| ); | ||
|
|
||
| // Use GitHub's GraphQL's closedByPullRequestsReferences to more reliably | ||
| // determine if there is a linked PR. | ||
| const query = `query($owner: String!, $repo: String!, $issue: Int!) { | ||
| repository(owner: $owner, name: $repo) { | ||
| issue(number: $issue) { | ||
| closedByPullRequestsReferences(includeClosedPrs: true, first: 1) { | ||
| totalCount | ||
| } | ||
| } | ||
| } | ||
| }`; | ||
|
|
||
| const variables = { | ||
| owner: repoOwner, | ||
| repo: repoName, | ||
| issue: issueNumber, | ||
| }; | ||
|
|
||
| // Determine if there is a linked PR. | ||
| try { | ||
| const response = await github.graphql(query, variables); | ||
|
|
||
| const numLinkedPrs = | ||
| response.repository.issue.closedByPullRequestsReferences.totalCount; | ||
|
|
||
| console.debug(`Number of linked PRs found: ${numLinkedPrs}.`); | ||
|
|
||
| if (numLinkedPrs > 0) { | ||
| console.info(consoleMessageAllowClose); | ||
| return true; | ||
| } | ||
| } catch (err) { | ||
| throw new Error( | ||
| `Can not find issue #${issueNumber} or its PR count; error = ${err}` | ||
| ); | ||
| } | ||
| console.info(`Issue #${issueNumber} does not have a linked PR.`); | ||
|
|
||
| // If the issue does not have a linked PR or any of the excusable labels. | ||
| console.info(`Issue #${issueNumber} is not allowed to be closed.`); | ||
| return false; | ||
| } | ||
|
|
||
| // ================================================== | ||
|
|
||
| module.exports = hasLinkedPrOrExcusableLabel; |
80 changes: 80 additions & 0 deletions
80
github-actions/check-closed-issue-for-linked-pr/check-for-linked-issue/reopen-issue.js
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,80 @@ | ||
| const queryIssueInfo = require('../../utils/query-issue-info'); | ||
| const mutateIssueStatus = require('../../utils/mutate-issue-status'); | ||
| const postComment = require('../../utils/post-issue-comment'); | ||
|
|
||
| const statusFieldIds = require('../../utils/_data/status-field-ids'); | ||
| const labelDirectory = require('../../utils/_data/label-directory.json'); | ||
|
|
||
| // ================================================== | ||
|
|
||
| /** | ||
| * Reopens an issue that does not have a linked PR or excusable labels. Adds a | ||
| * "ready for product" label, sets the project status to Questions / In Review", | ||
| * and posts a comment to the issue. | ||
| * | ||
| * @param {{github: object, context: object}} actionsGithubScriptArgs - | ||
| * GitHub objects from actions/github-script | ||
| */ | ||
| async function reopenIssue({ github, context }) { | ||
| const repoOwner = context.repo.owner; | ||
| const repoName = context.repo.repo; | ||
| const issueNumber = context.payload.issue.number; | ||
|
|
||
| const labelsToAdd = [labelDirectory.readyForPM[0]]; | ||
|
|
||
| const newStatusFieldId = statusFieldIds('Questions_In_Review'); | ||
|
|
||
| const comment = | ||
| 'This issue was reopened because ' + | ||
| `it did not have any of the following: | ||
| - A linked PR, | ||
| - An \`Ignore\` label | ||
| - A \`non-PR contribution\` label`; | ||
|
|
||
| // -------------------------------------------------- | ||
|
|
||
| // Add the "ready for product" label. | ||
| try { | ||
| await github.rest.issues.addLabels({ | ||
| owner: repoOwner, | ||
| repo: repoName, | ||
| issue_number: issueNumber, | ||
| labels: labelsToAdd, | ||
| }); | ||
| } catch (err) { | ||
| throw new Error( | ||
| `Unable to add "ready for product" label to issue #${issueNumber}; ` + | ||
| `error = ${err}` | ||
| ); | ||
| } | ||
| console.info(`Added "ready for product" label to issue #${issueNumber}.`); | ||
|
|
||
| // Change the project status of the issue to "Questions / In Review". | ||
| const issueInfo = await queryIssueInfo(github, context, issueNumber); | ||
| await mutateIssueStatus(github, context, issueInfo.id, newStatusFieldId); | ||
| console.info( | ||
| `Changed project status to ` + | ||
| `"Questions / In Review" in issue #${issueNumber}.` | ||
| ); | ||
|
|
||
| // Post comment to the issue. | ||
| await postComment(issueNumber, comment, github, context); | ||
| console.info(`Posted comment to issue #${issueNumber}.`); | ||
|
|
||
| // Re-opening the issue. | ||
| try { | ||
| await github.rest.issues.update({ | ||
| owner: repoOwner, | ||
| repo: repoName, | ||
| issue_number: issueNumber, | ||
| state: 'open', | ||
| }); | ||
| } catch (err) { | ||
| throw new Error(`Unable to reopen issue #${issueNumber}; error = ${err}`); | ||
| } | ||
| console.info(`Reopened issue #${issueNumber}.`); | ||
| } | ||
|
|
||
| // ================================================== | ||
|
|
||
| module.exports = reopenIssue; |
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.
Uh oh!
There was an error while loading. Please reload this page.