Replacement for v3 compare

In order to create a kind of release notes I would like to get the commit messages between two commits.

Given the following commit history, I need the logs between commit DEV and commit 5.

       1 ----- 3 ---
     /               \
a - b -- DEV --- 4 -- m1 -- m2 -- 5 -- i
           \               /
             2 ---------------- h

The following command does the job.

$ git log --no-merges --pretty='%h %s' <FROM_HASH>...<TO_HASH>
xxxx787 adds file 5
xxxx057 adds file 2
xxxxf8e adds file 4
xxxx6c7 adds file 3
xxxx8c1 adds file 1

For the GitHub REST API I found a solution on the internet.

DIV="<NEW COMMIT>"
hashes=$(curl -s https://api.github.com/repos/<OWNER>/<REPO>/compare/<FROM_HASH>...<TO_HASH> | jq '.commits[] | select(.parents | length <= 1) | .sha,.commit.author.name,.commit.message,"$DIV"')
sed -e 's/ *\"$DIV\" */\n/g' <<< $hashes

How can I do this with the GraphQL API? The following query gets some commit infos, but it’s a plain git log not a compare of two commits. For the example above, I don’t know how to figure out, that commit 1 is part of my release, because it got merged on the main branch with commit m1. Apart from that it seems like the before condition gets ignored.

{
  repository(owner: "<OWNER>", name: "<REPO>") {
    object(oid: "<TO_HASH>") {
      ... on Commit {
        history(before: "<FROM_HASH> 0") {
          edges {
            node {
              oid
              messageHeadline
              author {
                name
              }
              parents(first: 2) {
                totalCount
              }
            }
          }
        }
      }
    }
  }
}

Does anyone have an idea how to do that?

1 Like