From 46dd5ecddda040f265462943b663c269fcb1c762 Mon Sep 17 00:00:00 2001 From: embeddedt <42941056+embeddedt@users.noreply.github.com> Date: Wed, 22 Apr 2026 19:36:59 -0400 Subject: [PATCH] Comment on issues when fix is released Fixes #649 --- .github/workflows/gradle.yml | 53 ++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 5b621513..037848bf 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -11,6 +11,8 @@ on: jobs: build: runs-on: ubuntu-22.04 + permissions: + issues: write concurrency: group: release-${{ github.ref }} cancel-in-progress: true @@ -52,6 +54,57 @@ jobs: env: CURSEFORGE_TOKEN: ${{ secrets.CURSEFORGE_TOKEN }} MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }} + - name: Capture mod version + if: steps.check_branch.outputs.is_release == 'true' + run: echo "MOD_VERSION=$(./gradlew properties -q | grep '^version:' | awk '{print $2}')" >> $GITHUB_ENV + - name: Comment on fixed issues + if: steps.check_branch.outputs.is_release == 'true' + uses: actions/github-script@v7 + with: + script: | + const { execSync } = require('child_process'); + + const branch = context.ref.replace('refs/heads/', ''); + const { data: runs } = await github.rest.actions.listWorkflowRuns({ + owner: context.repo.owner, + repo: context.repo.repo, + workflow_id: 'gradle.yml', + branch, + status: 'success', + per_page: 1 + }); + + const logArgs = runs.workflow_runs.length > 0 + ? `${runs.workflow_runs[0].head_sha}..${context.sha}` + : `-1 ${context.sha}`; + const log = execSync(`git log ${logArgs} --format=%s%n%b`, { encoding: 'utf8' }); + + const issueNumbers = new Set(); + const pattern = /(?:fix(?:es|ed)?|close[sd]?|resolve[sd]?)\s+#(\d+)/gi; + let match; + while ((match = pattern.exec(log)) !== null) { + issueNumbers.add(parseInt(match[1])); + } + + if (issueNumbers.size === 0) { + console.log('No fixed issues found in commits'); + return; + } + + const version = process.env.MOD_VERSION; + for (const issueNumber of issueNumbers) { + try { + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: issueNumber, + body: `The fix for this issue has been released in ModernFix ${version}` + }); + console.log(`Commented on issue #${issueNumber}`); + } catch (e) { + console.log(`Could not comment on #${issueNumber}: ${e.message}`); + } + } - name: Upload Artifacts to GitHub uses: actions/upload-artifact@v4 with: