Skip to content
This repository was archived by the owner on May 26, 2026. It is now read-only.

Commit b5acc39

Browse files
marek-sajiclaude
andcommitted
feat: Improve nag comment when no Jira issue linked
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Reviewed-by: Claude Sonnet 4.6 <noreply@anthropic.com> Reviewed-by: codex gpt-5.5 <codex@openai.com> Reviewed-by: CodeRabbit 0.5.0 <noreply@coderabbit.ai>
1 parent 93e9520 commit b5acc39

3 files changed

Lines changed: 105 additions & 87 deletions

File tree

dist/index.mjs

Lines changed: 51 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -42726,7 +42726,7 @@ var github_namespaceObject = /*#__PURE__*/__nccwpck_require__.t(github, 2);
4272642726

4272742727
const {
4272842728
context,
42729-
context: { payload, repo },
42729+
context: { payload },
4273042730
} = github_namespaceObject
4273142731
const pr = payload.pull_request || payload.issue
4273242732

@@ -42841,6 +42841,18 @@ async function getIssues(issuesKeys) {
4284142841
}))
4284242842
}
4284342843

42844+
const keywords = [
42845+
'closes',
42846+
'close',
42847+
'closed',
42848+
'fix',
42849+
'fixes',
42850+
'fixed',
42851+
'resolve',
42852+
'resolves',
42853+
'resolved',
42854+
]
42855+
4284442856
/**
4284542857
* @param {string} prBody
4284642858
* @param {Array<PullRequestComment>} comments
@@ -42849,17 +42861,6 @@ async function getIssues(issuesKeys) {
4284942861
function extractResolvedIssueKeys(prBody, comments) {
4285042862
const text = [prBody, ...comments.map((comment) => comment.body)].join('\0')
4285142863

42852-
const keywords = [
42853-
'close',
42854-
'closes',
42855-
'closed',
42856-
'fix',
42857-
'fixes',
42858-
'fixed',
42859-
'resolve',
42860-
'resolves',
42861-
'resolved',
42862-
]
4286342864
const keywordsRegExp = githubRequireKeywordPrefix
4286442865
? `(?:${keywords.join('|')})\\s+`
4286542866
: ''
@@ -42894,21 +42895,48 @@ function extractResolvedIssueKeys(prBody, comments) {
4289442895
async function getPullRequestComments() {
4289542896
core.info('Requesting pull request comments')
4289642897

42897-
const response = await octokit.rest.issues.listComments({
42898+
return octokit.paginate(octokit.rest.issues.listComments, {
4289842899
owner: repoOwner,
4289942900
repo: payload.repository.name,
4290042901
issue_number: issueNumber,
42902+
per_page: 100,
4290142903
})
42902-
return response.data
4290342904
}
4290442905

42905-
async function nagToLinkJiraIssue() {
42906-
await octokit.rest.issues.createComment({
42907-
issue_number: pr.number,
42908-
owner: repo.owner,
42909-
repo: repo.repo,
42910-
body: `@${context.actor} Please add Jira issue URL to the PR description (proceeded with “Closes” or “Fixes”) — it will make issues move when PR status changes.\n`,
42911-
})
42906+
async function postTipCommentLinkJiraIssue(comments) {
42907+
if (
42908+
// Only post a comment, if acting upon an event that could’ve
42909+
// changed PR body
42910+
['pull_request', 'pull_request_target'].includes(context.eventName) &&
42911+
['opened', 'edited'].includes(payload.action)
42912+
) {
42913+
try {
42914+
const tipCommentMarker = '<!-- JIRA_INTEGRATION_NAG -->'
42915+
42916+
const alreadyCommented = comments.some((comment) =>
42917+
comment.body?.includes(tipCommentMarker)
42918+
)
42919+
42920+
if (alreadyCommented) {
42921+
core.info('No issues found, but tip comment already present.')
42922+
} else {
42923+
core.info('No issues found — posting a tip comment.')
42924+
42925+
const keyword =
42926+
keywords[0].slice(0, 1).toUpperCase() + keywords[0].slice(1)
42927+
const body = `${tipCommentMarker}\n> [!TIP]\n> Include “${keyword} <var>JIRA_ISSUE_URL</var>” in the PR body to associate it with an issue.`
42928+
42929+
await octokit.rest.issues.createComment({
42930+
issue_number: pr.number,
42931+
owner: repoOwner,
42932+
repo: payload.repository.name,
42933+
body,
42934+
})
42935+
}
42936+
} catch (error) {
42937+
core.error(`Failed to post tip comment: ${error}`)
42938+
}
42939+
}
4291242940
}
4291342941

4291442942
/**
@@ -43057,15 +43085,9 @@ async function main() {
4305743085
const issueIds = extractResolvedIssueKeys(pr.body, comments)
4305843086

4305943087
if (!issueIds.length) {
43060-
if (
43061-
context.eventName === 'pull_request' &&
43062-
payload.action === 'opened' &&
43063-
!['main', 'production'].includes(pr.head.ref)
43064-
) {
43065-
void nagToLinkJiraIssue()
43066-
}
43067-
4306843088
core.info('Could not find issue IDs')
43089+
// Only post a tip comment when the PR body could have changed
43090+
await postTipCommentLinkJiraIssue(comments)
4306943091
return
4307043092
}
4307143093
core.info('Found issue IDs:', issueIds.join(', '))

index.mjs

Lines changed: 51 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import * as github from '@actions/github'
1212

1313
const {
1414
context,
15-
context: { payload, repo },
15+
context: { payload },
1616
} = github
1717
const pr = payload.pull_request || payload.issue
1818

@@ -127,6 +127,18 @@ async function getIssues(issuesKeys) {
127127
}))
128128
}
129129

130+
const keywords = [
131+
'closes',
132+
'close',
133+
'closed',
134+
'fix',
135+
'fixes',
136+
'fixed',
137+
'resolve',
138+
'resolves',
139+
'resolved',
140+
]
141+
130142
/**
131143
* @param {string} prBody
132144
* @param {Array<PullRequestComment>} comments
@@ -135,17 +147,6 @@ async function getIssues(issuesKeys) {
135147
function extractResolvedIssueKeys(prBody, comments) {
136148
const text = [prBody, ...comments.map((comment) => comment.body)].join('\0')
137149

138-
const keywords = [
139-
'close',
140-
'closes',
141-
'closed',
142-
'fix',
143-
'fixes',
144-
'fixed',
145-
'resolve',
146-
'resolves',
147-
'resolved',
148-
]
149150
const keywordsRegExp = githubRequireKeywordPrefix
150151
? `(?:${keywords.join('|')})\\s+`
151152
: ''
@@ -180,21 +181,48 @@ function extractResolvedIssueKeys(prBody, comments) {
180181
async function getPullRequestComments() {
181182
core.info('Requesting pull request comments')
182183

183-
const response = await octokit.rest.issues.listComments({
184+
return octokit.paginate(octokit.rest.issues.listComments, {
184185
owner: repoOwner,
185186
repo: payload.repository.name,
186187
issue_number: issueNumber,
188+
per_page: 100,
187189
})
188-
return response.data
189190
}
190191

191-
async function nagToLinkJiraIssue() {
192-
await octokit.rest.issues.createComment({
193-
issue_number: pr.number,
194-
owner: repo.owner,
195-
repo: repo.repo,
196-
body: `@${context.actor} Please add Jira issue URL to the PR description (proceeded with “Closes” or “Fixes”) — it will make issues move when PR status changes.\n`,
197-
})
192+
async function postTipCommentLinkJiraIssue(comments) {
193+
if (
194+
// Only post a comment, if acting upon an event that could’ve
195+
// changed PR body
196+
['pull_request', 'pull_request_target'].includes(context.eventName) &&
197+
['opened', 'edited'].includes(payload.action)
198+
) {
199+
try {
200+
const tipCommentMarker = '<!-- JIRA_INTEGRATION_NAG -->'
201+
202+
const alreadyCommented = comments.some((comment) =>
203+
comment.body?.includes(tipCommentMarker)
204+
)
205+
206+
if (alreadyCommented) {
207+
core.info('No issues found, but tip comment already present.')
208+
} else {
209+
core.info('No issues found — posting a tip comment.')
210+
211+
const keyword =
212+
keywords[0].slice(0, 1).toUpperCase() + keywords[0].slice(1)
213+
const body = `${tipCommentMarker}\n> [!TIP]\n> Include “${keyword} <var>JIRA_ISSUE_URL</var>” in the PR body to associate it with an issue.`
214+
215+
await octokit.rest.issues.createComment({
216+
issue_number: pr.number,
217+
owner: repoOwner,
218+
repo: payload.repository.name,
219+
body,
220+
})
221+
}
222+
} catch (error) {
223+
core.error(`Failed to post tip comment: ${error}`)
224+
}
225+
}
198226
}
199227

200228
/**
@@ -343,15 +371,9 @@ async function main() {
343371
const issueIds = extractResolvedIssueKeys(pr.body, comments)
344372

345373
if (!issueIds.length) {
346-
if (
347-
context.eventName === 'pull_request' &&
348-
payload.action === 'opened' &&
349-
!['main', 'production'].includes(pr.head.ref)
350-
) {
351-
void nagToLinkJiraIssue()
352-
}
353-
354374
core.info('Could not find issue IDs')
375+
// Only post a tip comment when the PR body could have changed
376+
await postTipCommentLinkJiraIssue(comments)
355377
return
356378
}
357379
core.info('Found issue IDs:', issueIds.join(', '))

0 commit comments

Comments
 (0)