Skip to content

[SPARK-58045][INFRA] Verify the linked JIRA matches the PR in merge_spark_pr.py#57131

Open
gengliangwang wants to merge 4 commits into
apache:masterfrom
gengliangwang:mergeScript
Open

[SPARK-58045][INFRA] Verify the linked JIRA matches the PR in merge_spark_pr.py#57131
gengliangwang wants to merge 4 commits into
apache:masterfrom
gengliangwang:mergeScript

Conversation

@gengliangwang

@gengliangwang gengliangwang commented Jul 8, 2026

Copy link
Copy Markdown
Member

What changes were proposed in this pull request?

This PR adds a JIRA-vs-PR verification step to dev/merge_spark_pr.py. After the committer enters the PR number (right after the existing Epic/Umbrella check, before the "Proceed with merging?" confirmation), the script now, for each SPARK JIRA id linked from the PR title, prints a verification block and requires an explicit y/N confirmation. The block:

  • prints the PR title next to the ticket's summary, status, and issue type, so a mismatch is easy to spot;
  • prints a red warning on the status line when the ticket is already Resolved/Closed (a fresh merge should target an open ticket);
  • prints a red warning when the PR title and the JIRA summary have low word overlap (a Match: score below a threshold), which is a strong signal the PR references the wrong ticket;
  • aborts the merge if the committer answers anything other than y, asking them to fix the PR title.

Implementation notes:

  • A new pure helper format_jira_verification(...) renders the block and is covered by inline doctests. Coloring the warnings is gated behind a use_color flag (off in doctests so the expected output stays plain text, on at the real call site).
  • Title/summary similarity is a stdlib Jaccard word-overlap (title_similarity): bracket tags ([SQL], the leading [SPARK-xxxx], ...) are stripped, words are lowercased, a small stopword set is dropped, and the two token sets are compared. No new dependency. The warning fires below SIMILARITY_WARN_THRESHOLD (0.2), tuned so an unrelated ticket (~0) warns while reworded-but-correct summaries stay above the line.
  • The existing Epic/Umbrella loop already fetches each linked issue; it now also collects them into linked_issues, so the verification step reuses those objects and performs no extra JIRA round-trips.
  • A small red(...) helper was factored out of print_error (no behavior change) and reused for the warnings.

No JIRA id is newly required by this change: [MINOR]/[TRIVIAL] PRs still merge with no SPARK id (the loop is a no-op for them). The existing Title.parse requirement is unchanged. [FOLLOWUP] PRs are handled (the id is extracted regardless of the tag), and Revert "..." PRs keep their title verbatim so the id is still extracted from it -- in both cases the warnings act as the intended nudge to double-check the ticket.

Why are the changes needed?

merge_spark_pr.py already prints each linked JIRA's summary, but nothing forces the committer to confirm the ticket actually matches the PR. A PR can therefore be merged against the wrong ticket - for example when a GitHub PR number in the body (Closes #NNNNN) is mistaken for a SPARK JIRA id - which resolves an unrelated, possibly already-Resolved ticket on merge. This step surfaces both signals (title/summary mismatch and an already-resolved ticket) and requires a human confirmation before the merge proceeds.

Does this PR introduce any user-facing change?

No. This only affects the committer-facing merge tooling.

How was this patch tested?

  • python3 -m doctest dev/merge_spark_pr.py - all doctests pass, including the new title_similarity cases (match, no-match, partial overlap, [FOLLOWUP], and Revert title patterns) and the two format_jira_verification cases (one exercising both warnings, one clean).
  • Manually rendered the block with use_color=True and confirmed both warnings are wrapped in the same red escape as print_error.
  • Verified all added lines are within the 100-char limit and contain no non-ASCII characters.

Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Opus 4.8)

…park_pr.py

Add a verification step in merge_spark_pr.py that, after the committer enters
the PR number, shows the PR title next to each linked JIRA's summary/status/type,
warns in red when a ticket is already Resolved/Closed, and requires an explicit
y/N confirmation before merging. This guards against merging a PR against the
wrong ticket (e.g. mistaking a GitHub PR number for a SPARK JIRA id).

Co-authored-by: Isaac
@dongjoon-hyun

Copy link
Copy Markdown
Member

Thank you, @gengliangwang !

Add a title-similarity check to the JIRA verification block in merge_spark_pr.py.
For each linked JIRA, compute a Jaccard word-overlap score between the PR title
and the JIRA summary (component/version tags and stopwords stripped) and print it
on a new "Match:" line, with a red warning when the score falls below a threshold
(0.2) -- a strong signal the PR references the wrong ticket.

The Epic/Umbrella case is already guarded by the existing hard-fail before this
block, so no separate umbrella warning is added.

Co-authored-by: Isaac

@dongjoon-hyun dongjoon-hyun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work for [FOLLOWUP] PRs, @gengliangwang ? Maybe, add a test case for the follow-up PR patterns? And, Revert PR pattern, too.

… title patterns

Address review feedback: add title_similarity doctests covering the [FOLLOWUP]
tag (stripped like any bracket tag, so a matching follow-up still scores 1.0)
and the Revert "..." title pattern (kept verbatim, so the extra word lowers the
score but a genuine match still scores well above the warning threshold).

Co-authored-by: Isaac
@gengliangwang

Copy link
Copy Markdown
Member Author

Thanks @dongjoon-hyun! Good call on both — it works for both patterns:

  • [FOLLOWUP]: the JIRA id is extracted from the title regardless of the tag, so verification runs on the referenced ticket. A follow-up usually reuses the parent's (now-Resolved) ticket, so the Resolved/Closed warning tends to fire, and a reworded follow-up title can also trip the low-similarity warning — both advisory y/N, not hard blocks.
  • Revert "...": the title is kept verbatim and the id is still extracted from it, so it points at the original ticket and shows the warnings — the intended nudge to double-check.

I've added title_similarity doctests for both patterns (973733b): the [FOLLOWUP] tag is stripped like any bracket tag (still scores 1.0 on a match), and the Revert "..." prefix stays verbatim (the extra word lowers the score but a genuine match still scores well above the threshold).

Comment thread dev/merge_spark_pr.py Outdated
0.5

A [FOLLOWUP] tag is stripped like any other bracket tag, so a follow-up whose
title still matches the ticket scores the same as the untagged title:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this true? Usually, the follow-up title is supposed to describe its code which is usually missed in the original PR. Like the following. The following is an example in branch-3.5.

$ git log --oneline | grep SPARK-56463
77117c7b32a [SPARK-56463][PYTHON][FOLLOWUP][3.5] Fix wrong kwargs
092f02df06e [SPARK-56463][PYTHON] Disallow unpickling UDT

@dongjoon-hyun dongjoon-hyun Jul 8, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typically, the follow-up PR title's score is not the same with the original PR title (and the JIRA issue title).

…OLLOWUP] PRs

A follow-up PR title describes the fix it adds, not the original ticket, so it
legitimately scores low against the JIRA summary even when it references the
right ticket -- firing the low-similarity warning on the normal [FOLLOWUP]
workflow and training committers to click through it. Suppress the warning when
the title carries a [FOLLOWUP] tag: still show the Match score, but with an
explanatory note instead of a warning. The Resolved/Closed warning and the
warning for non-follow-up PRs are unchanged. Fix the misleading doctest that
implied follow-up titles match the ticket.

Co-authored-by: Isaac
@dongjoon-hyun

Copy link
Copy Markdown
Member

Thank you for updating, @gengliangwang .

@dongjoon-hyun dongjoon-hyun changed the title [SPARK-58045][INFRA] Verify the linked JIRA matches the PR in merge_spark_pr.py [SPARK-58045][INFRA] Verify the linked JIRA matches the PR in merge_spark_pr.py Jul 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants