add ability to automatically close the issue

This commit is contained in:
Emilien Devos 2023-06-03 11:34:53 +02:00
parent 34fe38ec33
commit 9b0c29f521
4 changed files with 26 additions and 25 deletions

View File

@ -18,18 +18,9 @@ jobs:
run: yarn install run: yarn install
- name: 📦 Build - name: 📦 Build
run: yarn build run: NODE_OPTIONS=--openssl-legacy-provider 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
- name: 📦 Release - name: 📦 Release
uses: wow-actions/release-github-action@v1 uses: wow-actions/release-github-action@v2
with: env:
GITHUB_TOKEN: ${{ env.bot_token }} GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }}
GIT_COMMITTER_NAME: wow-actions-bot
GIT_COMMITTER_EMAIL: wow-actions-bot@users.noreply.github.com

View File

@ -1,25 +1,23 @@
<h1 align="center">Potential Duplicates</h1> <h1 align="center">Potential Duplicates</h1>
<p align="center"> <p align="center">
<a href="https://github.com/wow-actions/potential-duplicates/actions/workflows/release.yml"><img alt="build" src="https://img.shields.io/github/actions/workflow/status/wow-actions/potential-duplicates/release.yml?branch=master&logo=github&style=flat-square" ></a> <a href="https://github.com/iv-org/close-potential-duplicates/actions/workflows/release.yml"><img alt="build" src="https://img.shields.io/github/actions/workflow/status/iv-org/close-potential-duplicates/release.yml?branch=master&logo=github&style=flat-square" ></a>
<a href="/wow-actions/potential-duplicates/blob/master/LICENSE"><img alt="MIT License" src="https://img.shields.io/github/license/wow-actions/potential-duplicates?style=flat-square"></a> <a href="/iv-org/close-potential-duplicates/blob/master/LICENSE"><img alt="MIT License" src="https://img.shields.io/github/license/iv-org/close-potential-duplicates?style=flat-square"></a>
<a href="https://www.typescriptlang.org" rel="nofollow"><img alt="Language" src="https://img.shields.io/badge/language-TypeScript-blue.svg?style=flat-square"></a> <a href="https://www.typescriptlang.org" rel="nofollow"><img alt="Language" src="https://img.shields.io/badge/language-TypeScript-blue.svg?style=flat-square"></a>
<a href="https://github.com/wow-actions/potential-duplicates/pulls"><img alt="PRs Welcome" src="https://img.shields.io/badge/PRs-Welcome-brightgreen.svg?style=flat-square" ></a> <a href="https://github.com/iv-org/close-potential-duplicates/pulls"><img alt="PRs Welcome" src="https://img.shields.io/badge/PRs-Welcome-brightgreen.svg?style=flat-square" ></a>
<a href="https://github.com/marketplace/actions/potential-duplicates" rel="nofollow"><img alt="website" src="https://img.shields.io/static/v1?label=&labelColor=505050&message=Marketplace&color=0076D6&style=flat-square&logo=google-chrome&logoColor=0076D6" ></a> <a href="https://github.com/marketplace/actions/close-potential-duplicates" rel="nofollow"><img alt="website" src="https://img.shields.io/static/v1?label=&labelColor=505050&message=Marketplace&color=0076D6&style=flat-square&logo=google-chrome&logoColor=0076D6" ></a>
<a href="https://lgtm.com/projects/g/wow-actions/potential-duplicates/context:javascript" rel="nofollow"><img alt="Language grade: JavaScript" src="https://img.shields.io/lgtm/grade/javascript/g/wow-actions/potential-duplicates.svg?logo=lgtm&style=flat-square" ></a> <a href="https://lgtm.com/projects/g/iv-org/close-potential-duplicates/context:javascript" rel="nofollow"><img alt="Language grade: JavaScript" src="https://img.shields.io/lgtm/grade/javascript/g/iv-org/close-potential-duplicates.svg?logo=lgtm&style=flat-square" ></a>
</p> </p>
<p align="center"> <p align="center">
<strong> <strong>
Search for potential issue duplicates using <a href="https://en.wikipedia.org/wiki/Damerau%E2%80%93Levenshtein_distance">DamerauLevenshtein</a> algorithm Search for potential issue duplicates using <a href="https://en.wikipedia.org/wiki/Damerau%E2%80%93Levenshtein_distance">DamerauLevenshtein</a> algorithm and close it.
</strong> </strong>
</p> </p>
## Usage ## Usage
Create `.github/workflows/potential-duplicates.yml` in the default branch: Create `.github/workflows/close-potential-duplicates.yml` in the default branch:
```yaml ```yaml
name: Potential Duplicates name: Potential Duplicates
@ -30,7 +28,7 @@ jobs:
run: run:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: wow-actions/potential-duplicates@v1 - uses: iv-org/close-potential-duplicates@v1
with: with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Issue title filter work with anymatch https://www.npmjs.com/package/anymatch. # 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. # Reactions to be add to comment when potential duplicates are detected.
# Available reactions: "-1", "+1", "confused", "laugh", "heart", "hooray", "rocket", "eyes" # Available reactions: "-1", "+1", "confused", "laugh", "heart", "hooray", "rocket", "eyes"
reactions: 'eyes, confused' reactions: 'eyes, confused'
# Close or not the issue: false or true
close: 'false'
# Comment to post when potential duplicates are detected. # Comment to post when potential duplicates are detected.
comment: > comment: >
Potential duplicates: {{#issues}} 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` | | `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 <br> Available reactions: "-1", "+1", "confused", "laugh", "heart", "hooray", "rocket", "eyes" | | | `reactions` | Reactions to be add to comment when potential duplicates are detected <br> Available reactions: "-1", "+1", "confused", "laugh", "heart", "hooray", "rocket", "eyes" | |
| `comment` | Comment to post when potential duplicates are detected | 👇 | | `comment` | Comment to post when potential duplicates are detected | 👇 |
| `close` | Close or not the issue when found to be duplicate. | false |
Available reactions: Available reactions:

View File

@ -1,7 +1,7 @@
{ {
"name": "potential-duplicates", "name": "potential-duplicates",
"description": "Search for potential issue duplicates using DamerauLevenshtein algorithm.", "description": "Search for potential issue duplicates using DamerauLevenshtein algorithm.",
"version": "1.1.0", "version": "1.0.0",
"main": "dist/index.js", "main": "dist/index.js",
"files": [ "files": [
"dist", "dist",
@ -33,7 +33,7 @@
"email": "bubkoo.wy@gmail.com" "email": "bubkoo.wy@gmail.com"
}, },
"contributors": [], "contributors": [],
"repository": "https://github.com/wow-actions/potential-duplicates", "repository": "https://github.com/iv-org/close-potential-duplicates",
"dependencies": { "dependencies": {
"@actions/core": "^1.2.6", "@actions/core": "^1.2.6",
"@actions/github": "^5.0.0", "@actions/github": "^5.0.0",

View File

@ -67,6 +67,7 @@ export namespace Action {
const comment = core.getInput('comment') const comment = core.getInput('comment')
const reactions = core.getInput('reactions') const reactions = core.getInput('reactions')
const close = core.getInput('close') as 'false' | 'true'
if (comment) { if (comment) {
const body = mustache.render(comment, { const body = mustache.render(comment, {
issues: duplicates, issues: duplicates,
@ -82,6 +83,14 @@ export namespace Action {
await Reaction.add(octokit, data.id, reactions) await Reaction.add(octokit, data.id, reactions)
} }
} }
if (close === 'true') {
octokit.rest.issues.update({
...context.repo,
issue_number: payload.number,
state: 'closed',
})
}
} }
} }
} }