Mergifyio / mergify

Mergify Community Issue Tracker
https://mergify.com
Apache License 2.0
318 stars 91 forks source link

`mergeCommit` is missing from the PR attribute list #5114

Closed fruch closed 1 month ago

fruch commented 1 month ago

mergeCommit is missing from the PR attribute list

https://docs.mergify.com/configuration/conditions/#attributes-list

in github api it called merge_commit_sha https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28#get-a-pull-request

in via gh cli:

❯ gh pr view 6968 --json mergeCommit
{
  "mergeCommit": {
    "oid": "35de46e2fe9f2cd5403f88ed9d4cbe3b0303a2cf"
  }
}

it would really be helpful, since that the commit on the target branch of the PR, the commits list available is from the origin branch that is coming from a fork, and even gonna be delete later, so it leaves pointing to dangling commit that are much less helpful

even this isn't enough, since there not way inside the jinja template to execute more api call, to retrieve the rest of the patchset commits

here's a bash script I'm using to retrieve the list of commit of the target branch of a PR (after it was merged):

function get_pr_commits() {
    PR_NUM=$1

    MERGE_COMMIT=$(gh pr view $PR_NUM --json mergeCommit | jq -r '.mergeCommit.oid')
    PR_COMMITS=""

    commit=$MERGE_COMMIT
    while :
    do
        COMMIT_PR=$(gh api /repos/{owner}/{repo}/commits/$commit/pulls | jq -r '.[].number')
        if [[ $COMMIT_PR == $PR_NUM ]]; then
            PR_COMMITS="$PR_COMMITS $commit"
            FOUND_FIRST=yes
        fi

        if [[ $COMMIT_PR != $PR_NUM ]] && [[ ! -z $FOUND_FIRST ]]; then
            break
        fi
        commit=$(gh api /repos/{owner}/{repo}/commits/$commit | jq -r '.parents[0].sha')
    done
    echo $(reverse $PR_COMMITS)
}

a way to get something equivalent would be really helpful

jd commented 1 month ago

Hi @fruch ! Thanks for reporting this. We'll look into this and try to add this to our the list of PR attribute.