diff options
author | John Molakvoæ <skjnldsv@users.noreply.github.com> | 2025-06-07 07:42:46 +0200 |
---|---|---|
committer | skjnldsv <skjnldsv@protonmail.com> | 2025-06-07 09:05:03 +0200 |
commit | 377eebaece323f346576cc95b3ece3987820a4e3 (patch) | |
tree | 8acde6e8aff5d699652459836729221463161d3b | |
parent | a921fcb05ed9840c4a468d344d1fa75211de0afb (diff) | |
download | nextcloud-server-skjnldsv-patch-1.tar.gz nextcloud-server-skjnldsv-patch-1.zip |
chore(workflows): add auto stable PR title updateskjnldsv-patch-1
Signed-off-by: John Molakvoæ <skjnldsv@users.noreply.github.com>
-rw-r--r-- | .github/workflows/update-stable-titles.yml | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/.github/workflows/update-stable-titles.yml b/.github/workflows/update-stable-titles.yml new file mode 100644 index 00000000000..b39bab88b6e --- /dev/null +++ b/.github/workflows/update-stable-titles.yml @@ -0,0 +1,69 @@ +# SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors +# SPDX-License-Identifier: MIT +name: Update PRs titles on stable branches + +on: + pull_request: + types: [opened, edited] + branches: + - "stable*" + +concurrency: + group: stable-pr-title-${{ github.event.pull_request.number }} + cancel-in-progress: true + +jobs: + update-pr-title: + runs-on: ubuntu-latest-low + permissions: + pull-requests: write + contents: read + + steps: + - name: Wait for potential title edits + run: sleep 15 + + - name: Get PR details and update title + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const { data: pr } = await github.rest.pulls.get({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: context.issue.number, + }); + + const baseBranch = pr.base.ref; + const currentTitle = pr.title; + + // Check if this is a stable branch + // Should not happen as we only trigger on stable* branches 🤷♀️ + if (!baseBranch.startsWith('stable')) { + console.log(`Not a stable branch: ${baseBranch}`); + return; + } + + const prefix = `[${baseBranch}]`; + + // Check if title already has the correct prefix and no other stable tags + const correctTagRegex = new RegExp(`^\\[${baseBranch}\\]\\s*`); + const hasOtherStableTags = /\[stable[\d.]*\]/.test(currentTitle.replace(correctTagRegex, '')); + + if (correctTagRegex.test(currentTitle) && !hasOtherStableTags) { + console.log(`Title already has correct prefix only: ${currentTitle}`); + return; + } + + // Remove all stable tags and add the correct one + const cleanTitle = currentTitle.replace(/\[stable[\d.]*\]\s*/g, '').trim(); + const newTitle = `${prefix} ${cleanTitle}`; + + console.log(`Updating title from: "${currentTitle}" to: "${newTitle}"`); + + await github.rest.pulls.update({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: context.issue.number, + title: newTitle, + }); |