Skip to content

fix(github): resolve pull_request_number on retest for pushed commits#2473

Merged
chmouel merged 2 commits intotektoncd:mainfrom
zakisk:SRVKP-10662-fix-retest-comment-pr-number-variable
Feb 17, 2026
Merged

fix(github): resolve pull_request_number on retest for pushed commits#2473
chmouel merged 2 commits intotektoncd:mainfrom
zakisk:SRVKP-10662-fix-retest-comment-pr-number-variable

Conversation

@zakisk
Copy link
Copy Markdown
Member

@zakisk zakisk commented Feb 12, 2026

  • The {{ pull_request_number }} variable was not substituted when a /retest command was issued on a pushed commit (e.g. a commit resulting from a PR merge) because the commit comment handler in ParsePayload did not fetch the associated pull requests for the commit SHA.
  • Fetch PRs via getPullRequestsWithCommit in handleCommitCommentEvent so the PullRequestNumber is set on the event before variable substitution runs.
  • Add a unit test for commit_comment events to verify the PullRequestNumber is populated from the associated PR.
  • Add an e2e test that merges a PR, issues /retest on the merged commit, and asserts the PipelineRun logs contain the correct pull request number.
  • Add a new testdata PipelineRun fixture that echoes the {{ pull_request_number }} variable for validation.

https://issues.redhat.com/browse/SRVKP-10662

📝 Description of the Change

👨🏻‍ Linked Jira

🔗 Linked GitHub Issue

Fixes #

🚀 Type of Change

  • 🐛 Bug fix (fix:)
  • ✨ New feature (feat:)
  • 💥 Breaking change (feat!:, fix!:)
  • 📚 Documentation update (docs:)
  • ⚙️ Chore (chore:)
  • 💅 Refactor (refactor:)
  • 🔧 Enhancement (enhance:)
  • 📦 Dependency update (deps:)

🧪 Testing Strategy

  • Unit tests
  • Integration tests
  • End-to-end tests
  • Manual testing
  • Not Applicable

🤖 AI Assistance

  • I have not used any AI assistance for this PR.
  • I have used AI assistance for this PR.

If you have used AI assistance, please provide the following details:

Which LLM was used?

  • GitHub Copilot
  • ChatGPT (OpenAI)
  • Claude (Anthropic)
  • Cursor
  • Gemini (Google)
  • Other: ____________

Extent of AI Assistance:

  • Documentation and research only
  • Unit tests or E2E tests only
  • Code generation (parts of the code)
  • Full code generation (most of the PR)
  • PR description and comments
  • Commit message(s)

Important

If the majority of the code in this PR was generated by an AI, please add a Co-authored-by trailer to your commit message.
For example:

Co-authored-by: Gemini gemini@google.com
Co-authored-by: ChatGPT noreply@chatgpt.com
Co-authored-by: Claude noreply@anthropic.com
Co-authored-by: Cursor noreply@cursor.com
Co-authored-by: Copilot Copilot@users.noreply.github.com

**💡You can use the script ./hack/add-llm-coauthor.sh to automatically add
these co-author trailers to your commits.

✅ Submitter Checklist

  • 📝 My commit messages are clear, informative, and follow the project's How to write a git commit message guide. The Gitlint linter ensures in CI it's properly validated
  • ✨ I have ensured my commit message prefix (e.g., fix:, feat:) matches the "Type of Change" I selected above.
  • ♽ I have run make test and make lint locally to check for and fix any
    issues. For an efficient workflow, I have considered installing
    pre-commit and running pre-commit install to
    automate these checks.
  • 📖 I have added or updated documentation for any user-facing changes.
  • 🧪 I have added sufficient unit tests for my code changes.
  • 🎁 I have added end-to-end tests where feasible. See README for more details.
  • 🔎 I have addressed any CI test flakiness or provided a clear reason to bypass it.
  • If adding a provider feature, I have filled in the following and updated the provider documentation:
    • GitHub App
    • GitHub Webhook
    • Gitea/Forgejo
    • GitLab
    • Bitbucket Cloud
    • Bitbucket Data Center

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @zakisk, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request fixes a critical bug where the pull_request_number variable was not being correctly resolved when a /retest command was triggered on a commit that had been merged from a pull request. The changes ensure that the system can now accurately identify and substitute the correct pull request number in such scenarios, which is vital for the proper functioning of retest operations on merged code. This improves the reliability and consistency of automated pipeline execution.

Highlights

  • Bug Fix: Pull Request Number Resolution: Resolved an issue where the pull_request_number variable was not correctly substituted when a /retest command was issued on a commit that originated from a merged pull request.
  • Enhanced Commit Comment Handling: Implemented logic within the handleCommitCommentEvent function to fetch associated pull requests for a given commit SHA, ensuring the PullRequestNumber is correctly set before variable substitution.
  • New Unit Test Coverage: Added a dedicated unit test case to parse_payload_test.go to verify that the PullRequestNumber is accurately populated from associated pull requests during commit comment events.
  • End-to-End Test for Retest Scenario: Introduced a new end-to-end test (TestGithubPullRequestRetestPullRequestNumberSubstitution) that simulates merging a PR, issuing a /retest command on the merged commit, and asserting the correct pull_request_number substitution in the PipelineRun logs.
  • New PipelineRun Test Fixture: Created a new PipelineRun fixture (pipelinerun-pr-number-variable.yaml) specifically designed to echo the pull_request_number variable, facilitating validation in tests.
Changelog
  • pkg/provider/github/parse_payload.go
    • Added a call to getPullRequestsWithCommit to fetch associated pull requests for the commit SHA in handleCommitCommentEvent.
    • Set the runevent.PullRequestNumber if associated pull requests are found.
  • pkg/provider/github/parse_payload_test.go
    • Introduced a new test case good/commit comment want pull request number to verify PullRequestNumber population for commit comment events.
    • Added an assertion for wantedPullRequestNumber in the test suite.
  • test/github_push_retest_test.go
    • Added a new end-to-end test TestGithubPullRequestRetestPullRequestNumberSubstitution to validate pull_request_number substitution after a PR merge and retest.
    • Included setup for creating temporary branches, pushing files, creating and merging a PR, and then commenting /retest on the merged commit.
  • test/testdata/pipelinerun-pr-number-variable.yaml
    • Added a new PipelineRun definition that echoes the {{ pull_request_number }} variable for testing purposes.
Activity
  • The author, zakisk, has addressed a bug related to pull_request_number substitution.
  • Unit tests and end-to-end tests have been implemented to validate the fix.
  • AI assistance (Claude) was used for generating the PR description, comments, and commit messages.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@pipelines-as-code
Copy link
Copy Markdown

pipelines-as-code bot commented Feb 12, 2026

🔍 PR Lint Feedback

Note: This automated check helps ensure your PR follows our contribution guidelines.

⚠️ Items that need attention:

🤖 AI attribution

The following commits lack an explicit AI attribution footer:

  • a0cac19 fix(github): resolve pull_request_number on retest for pushed commits

If no AI assistance was used for a commit, you can ignore this warning.
Otherwise add an Assisted-by: or Co-authored-by: footer referencing the AI used.


ℹ️ Next Steps

  • Review and address the items above
  • Push new commits to update this PR
  • This comment will be automatically updated when issues are resolved
🔧 Admin Tools (click to expand)

Automated Issue/Ticket Creation:

  • /issue-create - Generate a GitHub issue from this PR content using AI
  • /jira-create - Create a SRVKP Jira ticket from this PR content using AI

⚠️ Important: Always review and edit generated content before finalizing tickets/issues.
The AI-generated content should be used as a starting point and may need adjustments.

These commands are available to maintainers and will post the generated content as PR comments for review.

🤖 This feedback was generated automatically by the PR CI system

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request fixes an issue where the pull_request_number variable was not available in /retest comments on pushed commits. The changes look good and include necessary unit and end-to-end tests. I have one suggestion to improve the robustness of the implementation against potential API delays.

Comment on lines +629 to +635
prs, err := v.getPullRequestsWithCommit(ctx, runevent.SHA, runevent.Organization, runevent.Repository, false)
if err != nil {
v.Logger.Warnf("Error getting pull requests associated with the commit in this commit comment event: %v", err)
}
if len(prs) > 0 {
runevent.PullRequestNumber = *prs[0].Number
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

To improve robustness and prevent potential flakiness, I have a couple of suggestions for this block:

  1. Consider enabling the retry mechanism in getPullRequestsWithCommit by passing true for the isMergeCommit parameter. A /retest is often used on merged commits, and the GitHub API can have a propagation delay. The associated E2E test even includes a time.Sleep(10 * time.Second) to account for this, which this change could help eliminate. The retry logic only engages if no PRs are found initially, so the performance impact is minimal.

  2. It's safer to use the GetNumber() method to access the pull request number. This avoids a potential panic if prs[0].Number is nil and is consistent with how other parts of the codebase access this value.

Suggested change
prs, err := v.getPullRequestsWithCommit(ctx, runevent.SHA, runevent.Organization, runevent.Repository, false)
if err != nil {
v.Logger.Warnf("Error getting pull requests associated with the commit in this commit comment event: %v", err)
}
if len(prs) > 0 {
runevent.PullRequestNumber = *prs[0].Number
}
prs, err := v.getPullRequestsWithCommit(ctx, runevent.SHA, runevent.Organization, runevent.Repository, true)
if err != nil {
v.Logger.Warnf("Error getting pull requests associated with the commit in this commit comment event: %v", err)
}
if len(prs) > 0 {
runevent.PullRequestNumber = prs[0].GetNumber()
}

g.Logger.Infof("Pull request %d has been merged", g.PRNumber)

// wait for API to reflect this PR in response
time.Sleep(10 * time.Second)
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.

can't you add a wait for loop instead?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

what do you mean by wait loop? checking whether pull-request is in API or not??

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.

yes correct, with a timer to don't loop forever wiating it appears

- The {{ pull_request_number }} variable was not substituted
  when a /retest command was issued on a pushed commit (e.g.
  a commit resulting from a PR merge) because the commit
  comment handler in ParsePayload did not fetch the
  associated pull requests for the commit SHA.
- Fetch PRs via getPullRequestsWithCommit in
  handleCommitCommentEvent so the PullRequestNumber is set
  on the event before variable substitution runs.
- Add a unit test for commit_comment events to verify the
  PullRequestNumber is populated from the associated PR.
- Add an e2e test that merges a PR, issues /retest on the
  merged commit, and asserts the PipelineRun logs contain
  the correct pull request number.
- Add a new testdata PipelineRun fixture that echoes the
  {{ pull_request_number }} variable for validation.

https://issues.redhat.com/browse/SRVKP-10662

Signed-off-by: Zaki Shaikh <zashaikh@redhat.com>
@zakisk zakisk force-pushed the SRVKP-10662-fix-retest-comment-pr-number-variable branch from 6272ceb to a0cac19 Compare February 12, 2026 09:24
@zakisk
Copy link
Copy Markdown
Member Author

zakisk commented Feb 17, 2026

the e2e test I added in this PR is also flaky so fixing it (don't want another flake test)

@chmouel chmouel merged commit dd58833 into tektoncd:main Feb 17, 2026
13 checks passed
@zakisk zakisk deleted the SRVKP-10662-fix-retest-comment-pr-number-variable branch February 18, 2026 04:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants