From 90e32d8c16cd92a4fa290db30f74d0502db23453 Mon Sep 17 00:00:00 2001 From: "Peter Fichtner (pfichtner)" Date: Thu, 5 Feb 2026 20:53:28 +0100 Subject: [PATCH 1/5] initial version --- .github/workflows/close-solution-pr.yml | 42 +++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 .github/workflows/close-solution-pr.yml diff --git a/.github/workflows/close-solution-pr.yml b/.github/workflows/close-solution-pr.yml new file mode 100644 index 00000000..cf5ff91f --- /dev/null +++ b/.github/workflows/close-solution-pr.yml @@ -0,0 +1,42 @@ +name: Close solution PRs + +on: + pull_request: + types: [labeled] + +jobs: + close: + if: github.event.label.name == 'solution' + runs-on: ubuntu-slim + steps: + - name: Comment on PR + uses: actions/github-script@v7 + with: + script: | + github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + body: ` +👋 Thanks for working on the Gilded Rose kata! + +This repository intentionally contains badly written code for learning purposes. + +We don't accept refactored solutions as pull requests. +Please keep your solution in your fork. + +If you intended to contribute documentation, tests, or a new language version, feel free to reopen and explain 🙂 +` + }) + + - name: Close PR + uses: actions/github-script@v7 + with: + script: | + github.rest.pulls.update({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: context.issue.number, + state: 'closed' + }) + From 1070625668a86f6455d702db10416f32bb18999c Mon Sep 17 00:00:00 2001 From: "Peter Fichtner (pfichtner)" Date: Thu, 5 Feb 2026 20:54:10 +0100 Subject: [PATCH 2/5] =?UTF-8?q?GitHub-Action:=20Try=20to=20detect=20?= =?UTF-8?q?=E2=80=9Caccidental=20solution=20PRs=E2=80=9D=20and=20tag=20the?= =?UTF-8?q?m=20(only)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/pr-validation.yml | 64 ++++++++++++++++++++--------- 1 file changed, 44 insertions(+), 20 deletions(-) diff --git a/.github/workflows/pr-validation.yml b/.github/workflows/pr-validation.yml index e4ce66de..30f2ab5a 100644 --- a/.github/workflows/pr-validation.yml +++ b/.github/workflows/pr-validation.yml @@ -9,31 +9,55 @@ jobs: # we could check owner and name if: github.repository == 'emilybache/GildedRose-Refactoring-Kata' # but checking owner is enough/better/more stable # Only run from the base repository - if: github.repository_owner == 'emilybache' - runs-on: ubuntu-latest + if: github.repository_owner == 'emilybache' || env.FORK_TESTING == 'true' + runs-on: ubuntu-slim permissions: issues: write pull-requests: write steps: - - name: Comment if checkmark is missing - if: ${{ !contains(github.event.pull_request.body, '[X] I acknowledge') }} - uses: actions/github-script@v6 + - name: Determine if PR is a solution + id: check + uses: actions/github-script@v7 with: script: | - github.rest.issues.createComment({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - body: "Please don't submit a Pull Request containing a Kata solution to the original repo from Emily Bache. If you are instead trying to add an improvement, please resubmit this PR and check the `[X]` box in the PR template." - }) - - name: Close PR if checkmark is missing - if: ${{ !contains(github.event.pull_request.body, '[X] I acknowledge') }} - uses: actions/github-script@v6 + - uses: actions/checkout@v3 + + - name: Check PR template via diff + id: check + uses: actions/github-script@v7 with: script: | - github.rest.pulls.update({ - pull_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - state: 'closed' - }) + const fs = require('fs'); + const path = require('path'); + const diff = require('diff'); + + const prBody = context.payload.pull_request.body || ""; + + // Read the PR template + const templatePath = path.join(process.env.GITHUB_WORKSPACE, ".github/pull_request_template.md"); + const template = fs.readFileSync(templatePath, "utf8"); + + // Transform unchecked boxes to checked boxes + const transformedTemplate = template.replace(/- \[ \]/g, '- [x]'); + + const normalize = text => text.replace(/\r\n/g, '\n').trim(); + const bodyNormalized = normalize(prBody); + const templateNormalized = normalize(transformedTemplate); + + // Compute line diff + const changes = diff.diffLines(templateNormalized, bodyNormalized); + + // Filter out lines that are identical + const diffLines = changes.filter(c => c.added || c.removed).map(c => c.value.trim()).filter(Boolean); + + // Check if diff is empty or only contains the last line of the template + const lastLine = normalize(transformedTemplate.split('\n').slice(-1)[0]); + const isSuspect = diffLines.length === 0 || (diffLines.length === 1 && diffLines[0] === lastLine); + + return { is_suspect: isSuspect }; + + - name: Add solution label + if: steps.check.outputs.is_suspect == 'true' + uses: actions-ecosystem/action-add-labels@v1 + with: + labels: solution From 44b4fd43378b9d11f197ff5a3acdcdab9afcb940 Mon Sep 17 00:00:00 2001 From: Peter Fichtner <1958485+pfichtner@users.noreply.github.com> Date: Thu, 5 Feb 2026 21:02:33 +0100 Subject: [PATCH 3/5] Update close-solution-pr.yml: Single line for body --- .github/workflows/close-solution-pr.yml | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/.github/workflows/close-solution-pr.yml b/.github/workflows/close-solution-pr.yml index cf5ff91f..0ea48f07 100644 --- a/.github/workflows/close-solution-pr.yml +++ b/.github/workflows/close-solution-pr.yml @@ -17,16 +17,7 @@ jobs: owner: context.repo.owner, repo: context.repo.repo, issue_number: context.issue.number, - body: ` -👋 Thanks for working on the Gilded Rose kata! - -This repository intentionally contains badly written code for learning purposes. - -We don't accept refactored solutions as pull requests. -Please keep your solution in your fork. - -If you intended to contribute documentation, tests, or a new language version, feel free to reopen and explain 🙂 -` + body: "👋 Thanks for working on the Gilded Rose kata!\n\nThis repository intentionally contains badly written code for learning purposes.\n\nWe don't accept refactored solutions as pull requests.\nPlease keep your solution in your fork.\n\nIf you intended to contribute documentation, tests, or a new language version, feel free to reopen and explain 🙂" }) - name: Close PR From 7081069861959486ca017e5b549fa72ef012704f Mon Sep 17 00:00:00 2001 From: "Peter Fichtner (pfichtner)" Date: Thu, 5 Feb 2026 21:08:46 +0100 Subject: [PATCH 4/5] GitHub-action: fixed guard clause --- .github/workflows/pr-validation.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-validation.yml b/.github/workflows/pr-validation.yml index 30f2ab5a..de83f025 100644 --- a/.github/workflows/pr-validation.yml +++ b/.github/workflows/pr-validation.yml @@ -9,7 +9,7 @@ jobs: # we could check owner and name if: github.repository == 'emilybache/GildedRose-Refactoring-Kata' # but checking owner is enough/better/more stable # Only run from the base repository - if: github.repository_owner == 'emilybache' || env.FORK_TESTING == 'true' + if: ${{ github.repository_owner == 'emilybache' || env.FORK_TESTING == 'true' }} runs-on: ubuntu-slim permissions: issues: write From 5a11c5ce48f61b5466ef160592311d701f598eec Mon Sep 17 00:00:00 2001 From: "Peter Fichtner (pfichtner)" Date: Thu, 5 Feb 2026 21:22:53 +0100 Subject: [PATCH 5/5] Github-Action: Moved gurad clause from job to step level --- .github/workflows/pr-validation.yml | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/.github/workflows/pr-validation.yml b/.github/workflows/pr-validation.yml index de83f025..6a54d5a9 100644 --- a/.github/workflows/pr-validation.yml +++ b/.github/workflows/pr-validation.yml @@ -5,19 +5,23 @@ on: jobs: task-check: - # github.event.repository.name only contains 'GildedRose-Refactoring-Kata' (no owner)! - # we could check owner and name if: github.repository == 'emilybache/GildedRose-Refactoring-Kata' - # but checking owner is enough/better/more stable - # Only run from the base repository - if: ${{ github.repository_owner == 'emilybache' || env.FORK_TESTING == 'true' }} - runs-on: ubuntu-slim + runs-on: ubuntu-latest permissions: issues: write pull-requests: write steps: - - name: Determine if PR is a solution - id: check - uses: actions/github-script@v7 + # github.event.repository.name only contains 'GildedRose-Refactoring-Kata' (no owner)! + # we could check owner and name if: github.repository == 'emilybache/GildedRose-Refactoring-Kata' + # but checking owner is enough/better/more stable + # Only run from the base repository + - name: Skip if not main repo or fork testing + if: ${{ github.repository_owner != 'emilybache' && env.PR_TESTING != 'true' }} + run: | + echo "Skipping workflow on fork without PR_TESTING" + exit 0 + - name: Comment if checkmark is missing + if: ${{ !contains(github.event.pull_request.body, '[X] I acknowledge') }} + uses: actions/github-script@v6 with: script: | - uses: actions/checkout@v3