-
Notifications
You must be signed in to change notification settings - Fork 103
feat(workflow): add workflow to unassign inactive issue assignees #341
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
Harxhit
wants to merge
6
commits into
Dev-Card:main
Choose a base branch
from
Harxhit:unassign-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.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b9171f0
fix: Fixed linting issues
Harxhit 9e54f51
Merge remote-tracking branch 'upstream/main'
Harxhit 34573be
feat(workflow): add workflow to unassign inactive issue assignees
Harxhit 9992f0f
fix: Changed the description
Harxhit 92c0fb7
fix: Clean description
Harxhit 307ac8e
fix: Removed the emote
Harxhit 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,104 @@ | ||
| name: Unassign Issues Without Linked PR | ||
|
|
||
| on: | ||
| schedule: | ||
| - cron: '0 9 */5 * *' # Runs every 5 days at 9:00 AM UTC | ||
| workflow_dispatch: # Also allows manual triggering | ||
|
|
||
| jobs: | ||
| unassign-issues: | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| issues: write | ||
|
|
||
| steps: | ||
| - name: Unassign issues with no linked PR and notify | ||
| uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 #v9.0.0 | ||
| with: | ||
| github-token: ${{ secrets.GITHUB_TOKEN }} | ||
| script: | | ||
| const owner = context.repo.owner; | ||
| const repo = context.repo.repo; | ||
|
|
||
| // Fetch all open issues (excluding PRs) | ||
| let page = 1; | ||
| let issues = []; | ||
|
|
||
| while (true) { | ||
| const { data } = await github.rest.issues.listForRepo({ | ||
| owner, | ||
| repo, | ||
| state: 'open', | ||
| per_page: 100, | ||
| page, | ||
| }); | ||
|
|
||
| // Filter out pull requests | ||
| const onlyIssues = data.filter(i => !i.pull_request); | ||
| issues = issues.concat(onlyIssues); | ||
|
|
||
| if (data.length < 100) break; | ||
| page++; | ||
| } | ||
|
|
||
| console.log(`Found ${issues.length} open issue(s) to check.`); | ||
|
|
||
| for (const issue of issues) { | ||
| const issueNumber = issue.number; | ||
|
|
||
| // Skip issues with no assignees | ||
| if (!issue.assignees || issue.assignees.length === 0) { | ||
| console.log(`Issue #${issueNumber} has no assignees — skipping.`); | ||
| continue; | ||
| } | ||
|
|
||
| // Search for PRs that reference this issue | ||
| const query = `repo:${owner}/${repo} is:pr is:open linked:issue`; | ||
| let linkedPRFound = false; | ||
|
|
||
| try { | ||
| // Check timeline for cross-referenced PRs | ||
| const timeline = await github.rest.issues.listEventsForTimeline({ | ||
| owner, | ||
| repo, | ||
| issue_number: issueNumber, | ||
| per_page: 100, | ||
| }); | ||
|
|
||
| linkedPRFound = timeline.data.some(event => | ||
| event.event === 'cross-referenced' && | ||
| event.source?.issue?.pull_request && | ||
| event.source?.issue?.state === 'open' | ||
| ); | ||
| } catch (err) { | ||
| console.log(`Could not fetch timeline for issue #${issueNumber}: ${err.message}`); | ||
| } | ||
|
|
||
| if (!linkedPRFound) { | ||
| console.log(`Issue #${issueNumber} has no linked PR — unassigning and notifying.`); | ||
|
|
||
| // Get current assignees before removing | ||
| const assigneeLogins = issue.assignees.map(a => a.login); | ||
|
|
||
| // Unassign all current assignees | ||
| await github.rest.issues.removeAssignees({ | ||
| owner, | ||
| repo, | ||
| issue_number: issueNumber, | ||
| assignees: assigneeLogins, | ||
| }); | ||
|
|
||
| // Post a comment tagging the specified users | ||
| const assigneesMention = assigneeLogins.map(u => `@${u}`).join(', '); | ||
| await github.rest.issues.createComment({ | ||
| owner, | ||
| repo, | ||
| issue_number: issueNumber, | ||
| body: `Hey @ShantKhatri(Project Admin) and @Harxhit(Maintainer),\n\nThis issue (previously assigned to ${assigneesMention}) has been **automatically unassigned** because no linked pull request was found after the scheduled check.\n\nIf work is in progress, please open a PR and link it to this issue to keep the assignment.`, | ||
| }); | ||
|
|
||
| console.log(`Unassigned and commented on issue #${issueNumber}.`); | ||
| } else { | ||
| console.log(`Issue #${issueNumber} has a linked PR — leaving as-is.`); | ||
| } | ||
| } | ||
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.
Hey @Harxhit , can we move this script to separate file? That's better practice.