|
40 | 40 | NO_TICKET_LABEL: ${{ inputs.no-ticket-label }} |
41 | 41 | with: |
42 | 42 | script: | |
| 43 | + // Log what triggered this workflow run |
| 44 | + const eventName = context.eventName; |
| 45 | + const action = context.payload.action; |
| 46 | + core.info(`🔍 Workflow triggered - Event: ${eventName}, Action: ${action}`); |
| 47 | +
|
43 | 48 | const prBody = context.payload.pull_request.body || ''; |
44 | 49 | const prTitle = context.payload.pull_request.title || ''; |
45 | 50 | const prNumber = context.payload.pull_request.number; |
@@ -193,18 +198,33 @@ jobs: |
193 | 198 | .join('\n'); |
194 | 199 |
|
195 | 200 | const jiraLinkHeader = '## Jira Links'; |
196 | | - const newJiraSection = `${jiraLinkHeader}\n${jiraLinksSection}`; |
| 201 | + const newJiraSection = `${jiraLinkHeader}\n${jiraLinksSection}\n`; |
197 | 202 |
|
198 | 203 | let updatedBody; |
199 | 204 | if (prBody.includes(jiraLinkHeader)) { |
200 | | - // Replace existing Jira links section |
201 | | - const regex = new RegExp(`${jiraLinkHeader}[\\s\\S]*?(?=\\n##|$)`, 'g'); |
| 205 | + // Replace existing Jira links section (only the ## Jira Links section and its list items) |
| 206 | + // Match: ## Jira Links\n- [TICKET](url)\n- [TICKET](url)\n... |
| 207 | + // Include trailing newline to match what we create |
| 208 | + const regex = new RegExp(`${jiraLinkHeader}\\n(?:- \\[.*?\\]\\(.*?\\)\\n)+`, 'g'); |
202 | 209 | updatedBody = prBody.replace(regex, newJiraSection); |
203 | 210 | } else { |
204 | 211 | // Append Jira links section at the end |
205 | 212 | updatedBody = prBody ? `${prBody}\n\n${newJiraSection}` : newJiraSection; |
206 | 213 | } |
207 | 214 |
|
| 215 | + // Only update PR if content actually changed |
| 216 | + if (updatedBody === prBody) { |
| 217 | + core.info('✓ Jira links section is already up to date, no PR update needed'); |
| 218 | + return; |
| 219 | + } |
| 220 | +
|
| 221 | + // Debug: show what's different |
| 222 | + core.info(`🔍 Current body length: ${prBody.length}, Updated body length: ${updatedBody.length}`); |
| 223 | + core.info(`🔍 Current body:\n${prBody}`); |
| 224 | + core.info(`🔍 Updated body:\n${updatedBody}`); |
| 225 | +
|
| 226 | + core.info('📝 Jira links section has changes, updating PR description'); |
| 227 | +
|
208 | 228 | // Update PR description |
209 | 229 | await github.rest.pulls.update({ |
210 | 230 | owner: context.repo.owner, |
|
0 commit comments