Skip to content

Commit 58c562e

Browse files
authored
Merge pull request #2874 from nextcloud/skjnldsv-patch-1
2 parents cd130ef + c063e5c commit 58c562e

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
2+
# SPDX-License-Identifier: MIT
3+
name: Update PRs titles on stable branches
4+
5+
on:
6+
pull_request:
7+
types: [opened, edited]
8+
branches:
9+
- "stable*"
10+
11+
concurrency:
12+
group: stable-pr-title-${{ github.event.pull_request.number }}
13+
cancel-in-progress: true
14+
15+
jobs:
16+
update-pr-title:
17+
runs-on: ubuntu-latest-low
18+
permissions:
19+
pull-requests: write
20+
contents: read
21+
22+
steps:
23+
- name: Wait for potential title edits
24+
run: sleep 15
25+
26+
- name: Get PR details and update title
27+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
28+
with:
29+
github-token: ${{ secrets.GITHUB_TOKEN }}
30+
script: |
31+
const { data: pr } = await github.rest.pulls.get({
32+
owner: context.repo.owner,
33+
repo: context.repo.repo,
34+
pull_number: context.issue.number,
35+
});
36+
37+
const baseBranch = pr.base.ref;
38+
const currentTitle = pr.title;
39+
40+
// Check if this is a stable branch
41+
// Should not happen as we only trigger on stable* branches 🤷‍♀️
42+
if (!baseBranch.startsWith('stable')) {
43+
console.log(`Not a stable branch: ${baseBranch}`);
44+
return;
45+
}
46+
47+
const prefix = `[${baseBranch}]`;
48+
49+
// Check if title already has the correct prefix and no other stable tags
50+
const correctTagRegex = new RegExp(`^\\[${baseBranch}\\]\\s*`);
51+
const hasOtherStableTags = /\[stable[\d.]*\]/.test(currentTitle.replace(correctTagRegex, ''));
52+
53+
if (correctTagRegex.test(currentTitle) && !hasOtherStableTags) {
54+
console.log(`Title already has correct prefix only: ${currentTitle}`);
55+
return;
56+
}
57+
58+
// Remove all stable tags and add the correct one
59+
const cleanTitle = currentTitle.replace(/\[stable[\d.]*\]\s*/g, '').trim();
60+
const newTitle = `${prefix} ${cleanTitle}`;
61+
62+
console.log(`Updating title from: "${currentTitle}" to: "${newTitle}"`);
63+
64+
await github.rest.pulls.update({
65+
owner: context.repo.owner,
66+
repo: context.repo.repo,
67+
pull_number: context.issue.number,
68+
title: newTitle,
69+
});

0 commit comments

Comments
 (0)