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

Rewrite of Issue-Handler.yaml #1021

Merged
merged 7 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
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
73 changes: 73 additions & 0 deletions .github/workflows/Issue-Handler.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Check and Close Issues

on:
issues:
types: [opened]

jobs:
handle-issues:
if: github.event_name == 'issues'
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v2

- name: Check and close issues
id: close-issues
uses: actions/github-script@v3
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const keywordsToCheck = ['instagram', 'facebook', 'twitter'];
const requiredLabels = ['bug', 'enhancement'];
const referenceIssueNumber = 733;

async function processIssue(issue) {
const issueBody = issue.body.toLowerCase();
const issueLabels = issue.labels.map(label => label.name);

const shouldCloseIssue = keywordsToCheck.some(keyword => issueBody.includes(keyword)) &&
requiredLabels.some(label => issueLabels.includes(label));

if (shouldCloseIssue) {
await github.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
state: 'closed'
});

await github.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
labels: ['wontfix']
});

await github.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
body: `This issue has been closed and labeled as wontfix. Please see issue #${referenceIssueNumber} for more details.`
});
}
}

// Process newly opened issues
if (context.payload.action === 'opened') {
await processIssue(context.payload.issue);
}

// Process all existing open issues
const issues = await github.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open'
});

for (const issue of issues.data) {
await processIssue(issue);
}
144 changes: 0 additions & 144 deletions .github/workflows/MetaIssueHandler.yaml

This file was deleted.