|
10 | 10 | steps:
|
11 | 11 | - uses: actions/checkout@v4.2.2
|
12 | 12 |
|
13 |
| - - name: Update PR labels |
| 13 | + - name: Update PR labels and title |
14 | 14 | uses: actions/github-script@v7.0.1
|
15 | 15 | with:
|
16 | 16 | script: |
|
|
27 | 27 | 'Documentation update': 'Documentation',
|
28 | 28 | 'Chore': 'Chore'
|
29 | 29 | };
|
| 30 | +
|
| 31 | + const titlePrefixMappings = { |
| 32 | + 'Bug': 'fix', |
| 33 | + 'Feature': 'feat', |
| 34 | + 'UI/UX': 'ui', |
| 35 | + 'Data Processing': 'data', |
| 36 | + 'Optimisation': 'perf', |
| 37 | + 'Security': 'security', |
| 38 | + 'Documentation': 'docs', |
| 39 | + 'Chore': 'chore' |
| 40 | + }; |
| 41 | +
|
| 42 | + const validPrefixes = Object.values(titlePrefixMappings); |
30 | 43 |
|
31 | 44 | // Determine which labels should be present
|
32 | 45 | for (const [text, label] of Object.entries(labelMappings)) {
|
|
72 | 85 | labels: labelsToAdd
|
73 | 86 | });
|
74 | 87 | }
|
| 88 | + |
| 89 | + // Update PR title with prefix |
| 90 | + const selectedLabel = [...shouldHaveLabels][0]; |
| 91 | + if (selectedLabel) { |
| 92 | + const prefix = titlePrefixMappings[selectedLabel].toLowerCase(); |
| 93 | + let currentTitle = context.payload.pull_request.title; |
| 94 | + |
| 95 | + // Check if current title has any prefix (including non-standard ones) |
| 96 | + const prefixMatch = currentTitle.match(/^([a-zA-Z]+):\s*(.*)/); |
| 97 | + |
| 98 | + if (prefixMatch) { |
| 99 | + const titleContent = prefixMatch[2]; |
| 100 | + // Only update if current prefix is not the correct one |
| 101 | + const currentPrefix = prefixMatch[1].toLowerCase(); |
| 102 | + if (!validPrefixes.includes(currentPrefix) || currentPrefix !== prefix) { |
| 103 | + const newTitle = `${prefix}: ${titleContent}`; |
| 104 | + |
| 105 | + await github.rest.pulls.update({ |
| 106 | + owner: context.repo.owner, |
| 107 | + repo: context.repo.repo, |
| 108 | + pull_number: context.payload.pull_request.number, |
| 109 | + title: newTitle |
| 110 | + }); |
| 111 | + } |
| 112 | + } else { |
| 113 | + // No prefix exists, add new one |
| 114 | + const newTitle = `${prefix}: ${currentTitle}`; |
| 115 | + |
| 116 | + await github.rest.pulls.update({ |
| 117 | + owner: context.repo.owner, |
| 118 | + repo: context.repo.repo, |
| 119 | + pull_number: context.payload.pull_request.number, |
| 120 | + title: newTitle |
| 121 | + }); |
| 122 | + } |
| 123 | + } |
0 commit comments