From 9b0c29f5211458192c72bdc4b59a91c4d718f681 Mon Sep 17 00:00:00 2001 From: Emilien Devos Date: Sat, 3 Jun 2023 11:34:53 +0200 Subject: [PATCH] add ability to automatically close the issue --- .github/workflows/release.yml | 17 ++++------------- README.md | 21 +++++++++++---------- package.json | 4 ++-- src/action.ts | 9 +++++++++ 4 files changed, 26 insertions(+), 25 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3175e0b..0efb252 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,18 +18,9 @@ jobs: run: yarn install - name: 📦 Build - run: yarn build - - - name: 🔑 Generate Token - uses: wow-actions/use-app-token@v1 - with: - app_id: ${{ secrets.APP_ID }} - private_key: ${{ secrets.PRIVATE_KEY }} - env_name: bot_token + run: NODE_OPTIONS=--openssl-legacy-provider yarn build - name: 📦 Release - uses: wow-actions/release-github-action@v1 - with: - GITHUB_TOKEN: ${{ env.bot_token }} - GIT_COMMITTER_NAME: wow-actions-bot - GIT_COMMITTER_EMAIL: wow-actions-bot@users.noreply.github.com + uses: wow-actions/release-github-action@v2 + env: + GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }} diff --git a/README.md b/README.md index 3637473..cc8183f 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,23 @@

Potential Duplicates

-

- build - MIT License + build + MIT License Language - PRs Welcome - website - Language grade: JavaScript + PRs Welcome + website + Language grade: JavaScript

-

- Search for potential issue duplicates using Damerau–Levenshtein algorithm + Search for potential issue duplicates using Damerau–Levenshtein algorithm and close it.

## Usage -Create `.github/workflows/potential-duplicates.yml` in the default branch: +Create `.github/workflows/close-potential-duplicates.yml` in the default branch: ```yaml name: Potential Duplicates @@ -30,7 +28,7 @@ jobs: run: runs-on: ubuntu-latest steps: - - uses: wow-actions/potential-duplicates@v1 + - uses: iv-org/close-potential-duplicates@v1 with: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Issue title filter work with anymatch https://www.npmjs.com/package/anymatch. @@ -48,6 +46,8 @@ jobs: # Reactions to be add to comment when potential duplicates are detected. # Available reactions: "-1", "+1", "confused", "laugh", "heart", "hooray", "rocket", "eyes" reactions: 'eyes, confused' + # Close or not the issue: false or true + close: 'false' # Comment to post when potential duplicates are detected. comment: > Potential duplicates: {{#issues}} @@ -71,6 +71,7 @@ Various inputs are defined to let you configure the action: | `threshold` | If similarity is higher than this threshold(`[0,1]`), issue will be marked as duplicate | `0.6` | | `reactions` | Reactions to be add to comment when potential duplicates are detected
Available reactions: "-1", "+1", "confused", "laugh", "heart", "hooray", "rocket", "eyes" | | | `comment` | Comment to post when potential duplicates are detected | 👇 | +| `close` | Close or not the issue when found to be duplicate. | false | Available reactions: diff --git a/package.json b/package.json index 31135a0..075a599 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "potential-duplicates", "description": "Search for potential issue duplicates using Damerau–Levenshtein algorithm.", - "version": "1.1.0", + "version": "1.0.0", "main": "dist/index.js", "files": [ "dist", @@ -33,7 +33,7 @@ "email": "bubkoo.wy@gmail.com" }, "contributors": [], - "repository": "https://github.com/wow-actions/potential-duplicates", + "repository": "https://github.com/iv-org/close-potential-duplicates", "dependencies": { "@actions/core": "^1.2.6", "@actions/github": "^5.0.0", diff --git a/src/action.ts b/src/action.ts index 8ef5cba..676851e 100644 --- a/src/action.ts +++ b/src/action.ts @@ -67,6 +67,7 @@ export namespace Action { const comment = core.getInput('comment') const reactions = core.getInput('reactions') + const close = core.getInput('close') as 'false' | 'true' if (comment) { const body = mustache.render(comment, { issues: duplicates, @@ -82,6 +83,14 @@ export namespace Action { await Reaction.add(octokit, data.id, reactions) } } + + if (close === 'true') { + octokit.rest.issues.update({ + ...context.repo, + issue_number: payload.number, + state: 'closed', + }) + } } } }