Skip to content

High performance self-hosted photo and video management solution.

feat: close likely duplicates (#20556)

bo0tzzc8f9a72d3e59
diff --git a/.github/workflows/close-duplicates.yml b/.github/workflows/close-duplicates.yml
new file mode 100644
index 0000000000..5ef56a6daf
--- /dev/null
+++ b/.github/workflows/close-duplicates.yml
@@ -0,0 +1,96 @@
+on:
+ issues:
+ types: [opened]
+ discussion:
+ types: [created]
+
+name: Close likely duplicates
+permissions: {}
+
+jobs:
+ get_body:
+ runs-on: ubuntu-latest
+ env:
+ EVENT: ${{ toJSON(github.event) }}
+ outputs:
+ body: ${{ steps.get_body.outputs.body }}
+ steps:
+ - id: get_body
+ run: |
+ BODY=$(echo """$EVENT""" | jq -r '.issue // .discussion | .body' | base64 -w 0)
+ echo "body=$BODY" >> $GITHUB_OUTPUT
+
+ get_checkbox_json:
+ runs-on: ubuntu-latest
+ needs: get_body
+ container:
+ image: yshavit/mdq:0.7.2
+ outputs:
+ json: ${{ steps.get_checkbox.outputs.json }}
+ steps:
+ - id: get_checkbox
+ env:
+ BODY: ${{ needs.get_body.outputs.body }}
+ run: |
+ JSON=$(echo "$BODY" | base64 -d | /mdq --output json '# I have searched | - [?] Yes')
+ echo "json=$JSON" >> $GITHUB_OUTPUT
+
+ close_and_comment:
+ runs-on: ubuntu-latest
+ needs: get_checkbox_json
+ if: ${{ !fromJSON(needs.get_checkbox_json.outputs.json).items[0].list[0].checked }}
+ permissions:
+ issues: write
+ discussions: write
+ steps:
+ - name: Close issue
+ if: ${{ github.event_name == 'issues' }}
+ env:
+ GH_TOKEN: ${{ github.token }}
+ NODE_ID: ${{ github.event.issue.node_id }}
+ run: |
+ gh api graphql \
+ -f issueId="$NODE_ID" \
+ -f body="This issue has automatically been closed as it is likely a duplicate. We get a lot of duplicate threads each day, which is why we ask you in the template to confirm that you searched for duplicates before opening one." \
+ -f query='
+ mutation CommentAndCloseIssue($issueId: ID!, $body: String!) {
+ addComment(input: {
+ subjectId: $issueId,
+ body: $body
+ }) {
+ __typename
+ }
+
+ closeIssue(input: {
+ issueId: $issueId,
+ stateReason: DUPLICATE
+ }) {
+ __typename
+ }
+ }'
+
+ - name: Close discussion
+ if: ${{ github.event_name == 'discussion' && github.event.discussion.category.name == 'Feature Request' }}
+ env:
+ GH_TOKEN: ${{ github.token }}
+ NODE_ID: ${{ github.event.discussion.node_id }}
+ run: |
+ gh api graphql \
+ -f discussionId="$NODE_ID" \
+ -f body="This discussion has automatically been closed as it is likely a duplicate. We get a lot of duplicate threads each day, which is why we ask you in the template to confirm that you searched for duplicates before opening one." \
+ -f query='
+ mutation CommentAndCloseDiscussion($discussionId: ID!, $body: String!) {
+ addDiscussionComment(input: {
+ discussionId: $discussionId,
+ body: $body
+ }) {
+ __typename
+ }
+
+ closeDiscussion(input: {
+ discussionId: $discussionId,
+ reason: DUPLICATE
+ }) {
+ __typename
+ }
+ }'