Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-70200

Get only the git history from pull request's base

      Currently, when building PRs in a multi-branch pipeline job, one has two choices:

      • clone the repository with the whole history of the PR's branch (default)
      • clone the repository with a fixed amount of commits using the `cloneOptionTrait`

      A third option that would retrieve only the commits from the PR that are on top of the PR base would be awesome.

      Basically, I want to inspect the git history of my PR to implement checks on the git diff and currently, I either fetch the whole repository (in GitOps repositories it's heavyweight) or settle for an arbitrary depth and pray that no PR becomes too big.

      Even getting the number of commits in the PR (in the environment for example) would do, I can just call `git fetch --deepen=$PR_COMMITS_NUMBER` which would be enough.

          [JENKINS-70200] Get only the git history from pull request's base

          Mark Waite added a comment - - edited

          Thanks for the suggestion. Do you have rules or steps that a program can use to retrieve only the commits from the PR that are on top of the PR base?

          I've not been able to find a reliable way to ask command line git to report the base of a branch. Are you envisioning that it would use a branch provider specific API (GitHub, GitLab, Bitbucket, Gitea, etc.) or are you aware of a way to deduce the base of a pull request from command line git?

          The git merge-base command looks like it might help, so long as we know the destination branch or a commit on the destination branch.

          Mark Waite added a comment - - edited Thanks for the suggestion. Do you have rules or steps that a program can use to retrieve only the commits from the PR that are on top of the PR base? I've not been able to find a reliable way to ask command line git to report the base of a branch. Are you envisioning that it would use a branch provider specific API (GitHub, GitLab, Bitbucket, Gitea, etc.) or are you aware of a way to deduce the base of a pull request from command line git? The git merge-base command looks like it might help, so long as we know the destination branch or a commit on the destination branch.

          I was hoping that all Git servers send the base branch's name in the event sent to Jenkins and I was thinking about git merge-base to find the number of commits to fetch when cloning.

          It might be possible to simplify this if the event contains the number of commits in the PR though. Or by fetching additional information via the git server's API, although it would mean specializing implementations, I'd understand if it's not the direction you want this plugin to take.

          I'm just not familiar with how the multit-branch plugin works internally and what it has available when triggering the build so I'm not sure what makes the most sense.

           

          Cyprien Quilici added a comment - I was hoping that all Git servers send the base branch's name in the event sent to Jenkins and I was thinking about git merge-base to find the number of commits to fetch when cloning. It might be possible to simplify this if the event contains the number of commits in the PR though. Or by fetching additional information via the git server's API, although it would mean specializing implementations, I'd understand if it's not the direction you want this plugin to take. I'm just not familiar with how the multit-branch plugin works internally and what it has available when triggering the build so I'm not sure what makes the most sense.  

            Unassigned Unassigned
            quilicicf Cyprien Quilici
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: