Skip to content

Commit 342bdae

Browse files
committed
fix: resolve pr review comments
Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
1 parent 20742ca commit 342bdae

1 file changed

Lines changed: 48 additions & 46 deletions

File tree

.github/workflows/pr-title-jira-key-lint.yml

Lines changed: 48 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -26,57 +26,63 @@ jobs:
2626
2727
console.log(`PR Title: ${prTitle}`);
2828
29-
const existingComment = await (async () => {
30-
const perPage = 100;
31-
for (let page = 1; ; page += 1) {
32-
const { data: comments } = await github.rest.issues.listComments({
33-
owner,
34-
repo,
35-
issue_number: prNumber,
36-
per_page: perPage,
37-
page,
38-
});
29+
const matchingComments = [];
30+
const perPage = 100;
31+
for (let page = 1; ; page += 1) {
32+
const { data: comments } = await github.rest.issues.listComments({
33+
owner,
34+
repo,
35+
issue_number: prNumber,
36+
per_page: perPage,
37+
page,
38+
});
3939
40-
const found = comments.find(
41-
(c) => c.user?.type === 'Bot' && c.body?.includes(COMMENT_MARKER),
42-
);
43-
if (found) return found;
44-
if (comments.length < perPage) return null;
40+
for (const c of comments) {
41+
if (c.user?.type === 'Bot' && c.body?.includes(COMMENT_MARKER)) {
42+
matchingComments.push(c);
43+
}
4544
}
46-
})();
45+
if (comments.length < perPage) break;
46+
}
4747
4848
if (!jiraKeyRegex.test(prTitle)) {
49-
const warningMessage = `${COMMENT_MARKER}
50-
⚠️ **Jira Issue Key Missing**
51-
52-
Your PR title doesn't contain a Jira issue key. Consider adding it for better traceability.
53-
54-
**Example:**
55-
- \`feat: add user authentication (CM-123)\`
56-
- \`feat: add user authentication (IN-123)\`
57-
58-
**Projects:**
59-
- CM: Community Data Platform
60-
- IN: Insights
49+
const warningMessage = [
50+
COMMENT_MARKER,
51+
'⚠️ **Jira Issue Key Missing**',
52+
'',
53+
"Your PR title doesn't contain a Jira issue key. Consider adding it for better traceability.",
54+
'',
55+
'**Example:**',
56+
'- `feat: add user authentication (CM-123)`',
57+
'- `feat: add user authentication (IN-123)`',
58+
'',
59+
'**Projects:**',
60+
'- CM: Community Data Platform',
61+
'- IN: Insights',
62+
'',
63+
'Please add a Jira issue key to your PR title.',
64+
].join('\n');
6165
62-
Please add a Jira issue key to your PR title.`;
63-
64-
if (existingComment) {
65-
if (existingComment.body !== warningMessage) {
66-
await github.rest.issues.updateComment({
67-
owner,
68-
repo,
69-
comment_id: existingComment.id,
70-
body: warningMessage,
71-
});
72-
}
73-
} else {
66+
if (matchingComments.length === 0) {
7467
await github.rest.issues.createComment({
7568
owner,
7669
repo,
7770
issue_number: prNumber,
7871
body: warningMessage,
7972
});
73+
} else {
74+
const [keep, ...extras] = matchingComments;
75+
if (keep.body !== warningMessage) {
76+
await github.rest.issues.updateComment({
77+
owner,
78+
repo,
79+
comment_id: keep.id,
80+
body: warningMessage,
81+
});
82+
}
83+
for (const extra of extras) {
84+
await github.rest.issues.deleteComment({ owner, repo, comment_id: extra.id });
85+
}
8086
}
8187
8288
await github.rest.checks.create({
@@ -95,12 +101,8 @@ jobs:
95101
const match = prTitle.match(jiraKeyRegex);
96102
console.log(`✅ Found Jira issue key: ${match[0]}`);
97103
98-
if (existingComment) {
99-
await github.rest.issues.deleteComment({
100-
owner,
101-
repo,
102-
comment_id: existingComment.id,
103-
});
104+
for (const c of matchingComments) {
105+
await github.rest.issues.deleteComment({ owner, repo, comment_id: c.id });
104106
}
105107
106108
await github.rest.checks.create({

0 commit comments

Comments
 (0)