Skip to content
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

Added GitHub Action to Close second issue Automatically #1014

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .github/workflows/close-duplicate-issue.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Close Duplicate Issue

on:
issues:
types: [opened]

jobs:
close_duplicate_issue:
runs-on: ubuntu-latest

steps:
- name: Check for duplicate issues
uses: actions/github-script@v6
with:
script: |
const issueAuthor = context.payload.issue.user.login;
const { data: issues } = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open'
});

// Check if the author has another open issue
const authorHasOtherOpenIssues = issues.some(issue =>
issue.user.login === issueAuthor && issue.number !== context.payload.issue.number
);

if (authorHasOtherOpenIssues) {
// Close the current issue
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.issue.number,
state: 'closed'
});

// Leave a comment explaining why the issue is closed
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.issue.number,
body: `This issue is being closed automatically because you already have an open issue. Please resolve or close the existing issue before opening a new one.`
});
}