github-branch-source-plugin icon indicating copy to clipboard operation
github-branch-source-plugin copied to clipboard

[JENKINS-75704] Fix Copilot user null name/email handling

Open IvanGasant opened this issue 5 months ago • 1 comments

Description

This PR improves the handling of pull requests and commits authored by GitHub IA, Copilot, who may not have a real GitHub account or may lack a defined name or email.
It prevents exceptions and ensures that these contributions are not discarded during indexing or processing.


Changes

  • Special handling for the "copilot" user:

    • If a pull request is authored by a user with login "copilot", a synthetic ContributorMetadataAction is created with:
    • This ensures PRs from Copilot are processed and visible, even though "copilot" is not a real GitHub user.
  • Other users:

    • For all other users, the contributor metadata is still created using the values returned by the GitHub API (login, name, and email) with no fallback.
      If user.getName() or user.getEmail() are null, those fields will remain null as before.
  • Unchanged logic for missing users:

    • If the user does not exist (for example, if the API returns 404), the PR is still ignored just like before.

Motivation

GitHub Copilot and other bots can appear as authors of commits and pull requests, but may not exist as real users in GitHub.
Without this special handling, such PRs would be discarded or cause exceptions, impacting the visibility and traceability of AI-generated or bot-generated contributions.

See JENKINS-75704 for further information.

Submitter checklist

  • [x] Link to JIRA ticket in description, if appropriate.
  • [x] Change is code complete and matches issue description
  • [x] Automated tests have been added to exercise the changes

No automated tests were added because this is a trivial change: it only handles null values or exceptions when fetching the GitHub user's name/email for logging purposes, defaulting to safe values if missing. It does not affect business logic or the core functionality of the plugin.

  • [x] Reviewer's manual test instructions provided in PR description. See Reviewer's first task below.

Reviewer checklist

  • [ ] Run the changes and verify that the change matches the issue description
  • [ ] Reviewed the code
  • [ ] Verified that the appropriate tests have been written or valid explanation given

Documentation changes

  • [ ] Link to jenkins.io PR, or an explanation for why no doc changes are needed

Users/aliases to notify

IvanGasant avatar Jun 10 '25 08:06 IvanGasant

Fallback for missing user name or email:

* For all other users, if `user.getName()` or `user.getEmail()` are `null` or throw exceptions, the code now defaults to:
  
  * Name: `user.getLogin()`
  * Email: `user.getLogin() + "@unknown.user"`

* This prevents exceptions when processing PRs or commits from bot users or users with incomplete profiles.

I see no evidence of such a change in the current patch; did you revert it? If so, please update the PR description accordingly.

jglick avatar Jun 20 '25 22:06 jglick

Dear @jglick and @IvanGasant , Do you have an estimated timeline for merging this pull request and creating a new release? I'm particularly interested in this fix, as it's currently blocking some of our Jenkins CI/CD workflows when Copilot creates pull requests in our repositories.

Thank you!

julianatienza avatar Jul 07 '25 09:07 julianatienza

Hey @IvanGasant , thanks a lot for your contribution! Hey @jglick , @jenkinsci/github-plugin-owners , @jenkinsci/github-branch-source-plugin-developers , could you please merge this PR? The issue is currently impacting our Jenkins pipelines and breaking our CI/CD flow. Thank you so much!

gsanchezu avatar Jul 09 '25 11:07 gsanchezu

It's true that Jesse did approve the pull request but a few comments were not addressed, specifically about retaining the comments, for future reviewers.

alecharp avatar Jul 09 '25 11:07 alecharp

It's true that Jesse did approve the pull request but a few comments were not addressed, specifically about retaining the comments, for future reviewers.

Thank you Adrien for your reply. Hey @IvanGasant , hola! Would it be possible for you to address the pending comments so we can expedite your code to be merged? Muchas gracias!

gsanchezu avatar Jul 09 '25 11:07 gsanchezu

It would be nice if @IvanGasant could manage the comments to merge this PR. The fix helps us use Copilot in systems with Jenkins in their pipelines.

cristb avatar Jul 09 '25 12:07 cristb

we are running into this issue as well, is there any way around it until this get merged and released ?

fruch avatar Jul 24 '25 07:07 fruch

Hi everyone, thank you for your comments and for your interest in this PR. Apologies for the delay in progressing with this—it’s been a busy period for me, but I plan to resume work on it soon. I’ll make sure to address all suggestions and questions raised and will keep you updated on my progress. If there’s any particular priority or information you need, please let me know.

Thanks again for your patience!

IvanGasant avatar Jul 24 '25 20:07 IvanGasant

Ready for Review @jglick

IvanGasant avatar Jul 31 '25 07:07 IvanGasant

I am not maintaining this plugin, will leave it some other maintainer.

jglick avatar Jul 31 '25 13:07 jglick