Skip to content

Commit 0d1c3fb

Browse files
authored
chore: added automatic title prefix (#144)
1 parent 8106570 commit 0d1c3fb

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

.github/workflows/pr_labeller.yml .github/workflows/pr-title-labeler.yml

+50-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
steps:
1111
- uses: actions/checkout@v4.2.2
1212

13-
- name: Update PR labels
13+
- name: Update PR labels and title
1414
uses: actions/github-script@v7.0.1
1515
with:
1616
script: |
@@ -27,6 +27,19 @@ jobs:
2727
'Documentation update': 'Documentation',
2828
'Chore': 'Chore'
2929
};
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);
3043
3144
// Determine which labels should be present
3245
for (const [text, label] of Object.entries(labelMappings)) {
@@ -72,3 +85,39 @@ jobs:
7285
labels: labelsToAdd
7386
});
7487
}
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+
}

src/resources/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- Fixed key index errors in mobile dropdown and header
1010
- Enhanced the changelog checker to check for bot PRs including removal of changelog labels for bot PRs
1111
- Added CodeRabbit config with auto review for bot PRs
12+
- Enhanced automatic PR labeler to also do automatic PR title prefixing
1213

1314
---
1415

0 commit comments

Comments
 (0)