Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimise fetching all commits in a pull request #416

Open
kellyselden opened this issue Jan 5, 2021 · 5 comments
Open

Optimise fetching all commits in a pull request #416

kellyselden opened this issue Jan 5, 2021 · 5 comments

Comments

@kellyselden
Copy link

kellyselden commented Jan 5, 2021

My goal is to lint all commit messages in a pull request, or in other words, since branching off the default branch. My workaround is

    - uses: actions/checkout@v2
      with:
        fetch-depth: 0
        ref: ${{ github.event.pull_request.head.sha }}
    # grab default branch to calculate branch point to know when to stop linting
    - if: ${{ github.base_ref }}
      run: git branch ${{ github.base_ref }} origin/${{ github.base_ref }}

but for large repos, it would be nice if this action could do the smart thing and only fetch what is needed. Thanks in advance.

@ericzolf
Copy link

My use case is different but the need is the same: I want to be able to list all files changed in the PR (and decide accordingly if a step needs to be run) but it can only work if the base_ref is also fetched, which currently, not knowing the number of commits required, can only be done by fetching the whole repository.

@ericsciple
Copy link
Contributor

ericsciple commented Jan 21, 2021

if the base_ref is also fetched

An easy workaround given the existing behavior may be to add an additional checkout step (first) that checks out the base ref. That way all the files get fetched, and you can do the diff after the second checkout step.

I say "easy" because it's easier than scripting the fetch command yourself and formulating the correct refspec and other options :)

@so0k
Copy link

so0k commented Jul 1, 2021

what does the correct refspec look like, what's the difference with running

git branch ${{ github.base_ref }} origin/${{ github.base_ref }}

I don't see anything in the pull_request body that tells me how many commits to fetch if you do a shallow clone

the alternative seems to be

https://stackoverflow.com/a/56113247

while [ -z $( git merge-base  ${{ github.base_ref }}  ${{ github.head_ref }}) ]; do
    git fetch -q --deepen=10 origin ${{ github.base_ref }}  ${{ github.head_ref }};
done

EDIT: the --deepen gave me an infinite loop

@aaglietti-itsrizzoli
Copy link

BassDrake pushed a commit to BassDrake/2021-23.SA.UFS07 that referenced this issue May 31, 2022
BassDrake pushed a commit to BassDrake/2021-23.SA.UFS07 that referenced this issue Jun 6, 2022
@polarathene
Copy link

I don't see anything in the pull_request body that tells me how many commits to fetch if you do a shallow clone

${{ github.event.pull_request.commits }} is available for that. I guess it was not a year ago.

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

No branches or pull requests

6 participants