Free, open-source file converter. Convert 263 formats offline by drag & drop — images, PDF, Word, Excel, PowerPoint, HWP/HWPX, video, audio, e-books and archives. No upload, no Office needed.
C# audio-converteravaloniabatch-conversionconvertercsharpdocument-converterdocx-to-pdfdotnetdrag-and-dropfile-conversionfile-converterheic-converterhwphwpximage-converterlinuxmacospdf-convertervideo-converterwindows
ci: flag duplicate issues and requests already added but not released
adnan-bhaldarf3bb3640299c
diff --git a/.github/workflows/flag-duplicate-issue.yml b/.github/workflows/flag-duplicate-issue.ymlindex 743aad5a..a9d5f5d0 100644--- a/.github/workflows/flag-duplicate-issue.yml+++ b/.github/workflows/flag-duplicate-issue.yml@@ -1,17 +1,22 @@-# Flags a new issue that may duplicate an open one: a comment links the original and mentions the owner (or the-# collaborators listed in MENTION below), who decide. The issue gets the `duplicate` label but is not closed.+# Flags a new issue that asks for something already requested or already added: a comment links the original issue+# and mentions the owner (or the collaborators listed in MENTION below), who decide. The issue gets the `duplicate`+# label but is not closed.# Trigger: an issue is opened. The `issues` event never fires for pull requests (those use `pull_request`), so this# workflow only ever runs for issues.-# What counts as a duplicate, compared with the other open issues:+# What counts as the same request, compared with the other issues:# - Format requests (the "File extension" field of .github/ISSUE_TEMPLATE/format_request.yml): the same file# extension. ".NCM" and "ncm" are the same, and a list such as ".mp3, .wav" must match the other list exactly. The# format it should convert to is not compared.# - Any other issue, or a format request without a usable extension: the same title, ignoring case, punctuation and# spacing. Titles whose text is short or only the template tag (for example "[Bug]:") are never compared, so empty-# or generic titles are never closed.-# When several open issues match, the oldest one is the original. The workflow then comments on the new issue with a-# link to it, adds the `duplicate` label (created when missing) and asks the owner to check, so a person decides-# whether to close it.+# or generic titles are never flagged.+# There are two cases, each with its own comment. When both exist, the first one is used:+# 1. Already added, not released yet: the matching issue was closed as completed after the latest published release+# (or there is no release yet), so its change is merged and will be in the next release. The comment says so.+# Issues closed as "not planned", and issues closed before the latest release, are ignored.+# 2. Duplicate request: the matching issue is still open and nothing was added yet. The comment asks the owner to+# review it.+# When several issues match in a case, the oldest one is the original.name: Flag duplicate issueon:@@ -34,7 +39,7 @@ jobs:# example '@owner @collaborator1 @collaborator2'.MENTION: "@${{ github.repository_owner }}"steps:- - name: Find an open issue that asks for the same thing+ - name: Find an issue that asks for the same thingid: findenv:# Passed as environment variables, never written into the script, so the text can't run as code.@@ -75,45 +80,80 @@ jobs:print('Title is too short or generic: not checking for duplicates')sys.exit(0)+ # When the latest published release was made (drafts and pre-releases don't count). None: no release yet.+ latest = subprocess.run(+ ['gh', 'api', f"repos/{os.environ['GH_REPO']}/releases/latest", '--jq', '.published_at'],+ capture_output=True, text=True)+ released_at = latest.stdout.strip() if latest.returncode == 0 and latest.stdout.strip() else None+listing = subprocess.run(- ['gh', 'issue', 'list', '--state', 'open', '--limit', '1000', '--json', 'number,title,body'],+ ['gh', 'issue', 'list', '--state', 'all', '--limit', '1000',+ '--json', 'number,title,body,state,stateReason,closedAt'],check=True, capture_output=True, text=True).stdout- matches = []+ unreleased, duplicates = [], []for issue in json.loads(listing):if issue['number'] >= me:continueif mine is not None:- if extensions(issue.get('body')) == mine:- matches.append(issue['number'])- elif norm(issue['title']) == key:- matches.append(issue['number'])- if not matches:+ same = extensions(issue.get('body')) == mine+ else:+ same = norm(issue['title']) == key+ if not same:+ continue+ if issue['state'] == 'OPEN':+ duplicates.append(issue['number'])+ elif issue.get('stateReason') == 'COMPLETED' and (released_at is None or issue['closedAt'] > released_at):+ unreleased.append(issue['number'])++ if unreleased:+ kind, original = 'release', min(unreleased)+ elif duplicates:+ kind, original = 'duplicate', min(duplicates)+ else:print('No duplicate found')sys.exit(0)- original = min(matches)- if mine is not None:- reason = 'it asks for the same file extension (' + ', '.join('.' + e for e in sorted(mine)) + ')'- else:- reason = 'it has the same title'- print(f'Duplicate of #{original}: {reason}')+ ext = ', '.join('.' + e for e in sorted(mine)) if mine is not None else ''+ print(f'{kind} #{original} ({ext or "same title"})')with open(os.environ['GITHUB_OUTPUT'], 'a') as out:out.write(f'original={original}\n')- out.write(f'reason={reason}\n')+ out.write(f'kind={kind}\n')+ out.write(f'ext={ext}\n')PY- name: Comment with a link to the original and add the labelif: ${{ steps.find.outputs.original != '' }}env:ORIGINAL: ${{ steps.find.outputs.original }}- REASON: ${{ steps.find.outputs.reason }}+ KIND: ${{ steps.find.outputs.kind }}+ EXT: ${{ steps.find.outputs.ext }}AUTHOR: ${{ github.event.issue.user.login }}run: |- body=$(printf '%s\n\n%s\n\n%s\n\n%s\n' \- "Hi @$AUTHOR, thank you for opening this issue." \- "This issue may be a duplicate of #$ORIGINAL, because $REASON." \- "$MENTION, when you have a moment, could you please review it and confirm whether it is a duplicate? If it is, it can be closed in favor of #$ORIGINAL." \- "@$AUTHOR, if you believe this is not a duplicate, please add a comment describing what is different so that it can be reviewed again.")+ if [ "$KIND" = release ]; then+ # Case 1: the format (or fix) is already merged and only waits for the next release.+ if [ -n "$EXT" ]; then+ what="The format you asked for ($EXT) has already been added in #$ORIGINAL, but it is not released yet."+ else+ what="This request has already been addressed in #$ORIGINAL (same title), but the change is not released yet."+ fi+ body=$(printf '%s\n\n%s\n\n%s\n\n%s\n' \+ "Hi @$AUTHOR, thank you for your request." \+ "$what It will be available in the next release." \+ "$MENTION, when you have a moment, could you please confirm this and close this issue in favor of #$ORIGINAL?" \+ "@$AUTHOR, if you meant something different, please add a comment describing what is different so that it can be reviewed again.")+ else+ # Case 2: the same request is still open and nothing was added yet.+ if [ -n "$EXT" ]; then+ reason="it asks for the same file extension ($EXT)"+ else+ reason="it has the same title"+ fi+ body=$(printf '%s\n\n%s\n\n%s\n\n%s\n' \+ "Hi @$AUTHOR, thank you for opening this issue." \+ "This issue may be a duplicate of #$ORIGINAL, because $reason." \+ "$MENTION, when you have a moment, could you please review it and confirm whether it is a duplicate? If it is, it can be closed in favor of #$ORIGINAL." \+ "@$AUTHOR, if you believe this is not a duplicate, please add a comment describing what is different so that it can be reviewed again.")+ figh issue comment "$ISSUE" --body "$body"gh label create duplicate --description "This issue already exists" --color cfd3d7 2>/dev/null || truegh issue edit "$ISSUE" --add-label duplicate