File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2020 - name : Count commits between merge base and HEAD
2121 id : count
2222 run : |
23- # Fetch the number of commits from base up to and including main.
23+ # Compare the base commit and HEAD to get the count of commits after base
24+ # up to and including HEAD. Add 2 to this total when fetching history.
25+ #
26+ # When opening a PR, GitHub will create a merge commit that squashes
27+ # your changes for use in the workflow. So your history locally
28+ # may look like
29+ # o---o---o---B - development
30+ # /
31+ # ---o---1---C---o---o---A - main
32+ # Note that the `1` is the merge-base of development and main. The
33+ # number of commits after `1` upto and including `A` is 4.
34+ # In the workflow, GitHub squashs development, so it becomes:
35+ # ---o---1---C---o---o---A - main
36+ # \--M - PR branch
37+ # Where `M`` is the new squashed commit. To fetch enough history to
38+ # include the merge base, we need to fetch `M`, `A` through `C` and
39+ # `1` for total of 4+2=6 commits. The +2 commits accounts for the
40+ # base `1` and merge commit `M`.
2441 RAW_COUNT="$(gh api "repos/$REPO/compare/${BASE}...main" | jq -r '.total_commits')"
25- # When fetching we need to fetch the history + base + temp merge commit, thus +2.
2642 ADJUSTED_COUNT=$((RAW_COUNT + 2))
2743 echo "count=$ADJUSTED_COUNT" >> "$GITHUB_OUTPUT"
2844 env :
You can’t perform that action at this time.
0 commit comments