Skip to content

Commit 636106e

Browse files
committed
feat: improve Jira PR sync workflow reliability
prevent infinite loops by skipping unchanged PR updates, and add trigger event logging for debugging Signed-off-by: Nir Argaman <nargaman@redhat.com>
1 parent 992a026 commit 636106e

1 file changed

Lines changed: 23 additions & 3 deletions

File tree

.github/workflows/jira-pr-sync.yml

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ jobs:
4040
NO_TICKET_LABEL: ${{ inputs.no-ticket-label }}
4141
with:
4242
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+
4348
const prBody = context.payload.pull_request.body || '';
4449
const prTitle = context.payload.pull_request.title || '';
4550
const prNumber = context.payload.pull_request.number;
@@ -193,18 +198,33 @@ jobs:
193198
.join('\n');
194199
195200
const jiraLinkHeader = '## Jira Links';
196-
const newJiraSection = `${jiraLinkHeader}\n${jiraLinksSection}`;
201+
const newJiraSection = `${jiraLinkHeader}\n${jiraLinksSection}\n`;
197202
198203
let updatedBody;
199204
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');
202209
updatedBody = prBody.replace(regex, newJiraSection);
203210
} else {
204211
// Append Jira links section at the end
205212
updatedBody = prBody ? `${prBody}\n\n${newJiraSection}` : newJiraSection;
206213
}
207214
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+
208228
// Update PR description
209229
await github.rest.pulls.update({
210230
owner: context.repo.owner,

0 commit comments

Comments
 (0)