From 9a3aad85abef1b9329dfbc9a4d68b3a4dd6fa19e Mon Sep 17 00:00:00 2001 From: Endkind Date: Sun, 15 Jun 2025 23:19:55 +0200 Subject: [PATCH] =?UTF-8?q?F=C3=BCge=20Workflow=20zum=20Kopieren=20von=20L?= =?UTF-8?q?abels=20von=20verkn=C3=BCpften=20Issues=20zu=20PRs=20hinzu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/copy-issue-labels.yml | 52 +++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 .github/workflows/copy-issue-labels.yml diff --git a/.github/workflows/copy-issue-labels.yml b/.github/workflows/copy-issue-labels.yml new file mode 100644 index 0000000..f9624fb --- /dev/null +++ b/.github/workflows/copy-issue-labels.yml @@ -0,0 +1,52 @@ +# .github/workflows/copy-issue-labels.yml +name: Copy issue labels to PR + +on: + pull_request: + types: [opened, reopened, synchronize] + +permissions: + contents: read + issues: read + pull-requests: write + +jobs: + copy-issue-labels: + runs-on: ubuntu-latest + steps: + - name: Copy labels from linked issue + uses: actions/github-script@v7 + with: + script: | + const prNumber = context.payload.pull_request.number; + const body = context.payload.pull_request.body || ''; + + const match = body.match(/(?:Fixes|Closes|Resolves):?\s+#(\d+)/i); + if (!match) { + core.info('No issue reference found in PR body.'); + return; + } + + const issueNumber = parseInt(match[1], 10); + core.info(`Found linked issue #${issueNumber}`); + + const issue = await github.rest.issues.get({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: issueNumber + }); + + const labels = issue.data.labels.map(label => label.name); + if (labels.length === 0) { + core.info('No labels found on linked issue.'); + return; + } + + await github.rest.issues.addLabels({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber, + labels + }); + + core.info(`Copied labels to PR: ${labels.join(', ')}`);