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

Update Issue-Handler.yaml #1198

Merged
merged 3 commits into from
Dec 16, 2023
Merged
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
38 changes: 28 additions & 10 deletions .github/workflows/Issue-Handler.yaml
Original file line number Diff line number Diff line change
@@ -1,53 +1,71 @@
# Name of the GitHub Action
name: Check and Close Issues

# Trigger the action on issue events, specifically when an issue is opened
on:
issues:
types: [opened]

# Job definitions
jobs:
handle-issues:
# Run this job only for issues
if: github.event_name == 'issues'
# Specify the runner environment
runs-on: ubuntu-latest
steps:
# Step 1: Check out the repository code
- name: Check out code
uses: actions/checkout@v2
uses: actions/checkout@v4

# Step 2: Set up Node.js environment (version 16)
- name: Set up Node.js
uses: actions/setup-node@v2
uses: actions/setup-node@v4
with:
node-version: 16

# Step 3: Custom script to check and close issues
- name: Check and close issues
id: close-issues
uses: actions/github-script@v3
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
// Define keywords and labels for issue filtering
const keywordsToCheck = ['instagram', 'facebook', 'twitter'];
const requiredLabels = ['bug', 'enhancement'];
const referenceIssueNumber = 733;
const actionClosedLabel = 'action-closed'; // Unique label to track action-closed issues

// Function to process each issue
async function processIssue(issue) {
const issueBody = issue.body.toLowerCase();
const issueLabels = issue.labels.map(label => label.name);
const wasClosedByAction = issueLabels.includes(actionClosedLabel);

const shouldCloseIssue = keywordsToCheck.some(keyword => issueBody.includes(keyword)) &&
// Determine if the issue should be closed
const shouldCloseIssue = !wasClosedByAction &&
keywordsToCheck.some(keyword => issueBody.includes(keyword)) &&
requiredLabels.some(label => issueLabels.includes(label));

// Close the issue if it meets the criteria
if (shouldCloseIssue) {
await github.issues.update({
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
state: 'closed'
});

await github.issues.addLabels({
// Add labels and comment to the closed issue
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
labels: ['wontfix']
labels: ['wontfix', actionClosedLabel]
});

await github.issues.createComment({
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
Expand All @@ -61,8 +79,8 @@ jobs:
await processIssue(context.payload.issue);
}

// Process all existing open issues
const issues = await github.issues.listForRepo({
// Fetch and process all open issues in the repo
const issues = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open'
Expand Down