How to form a GitHub GraphQL API query to compare between branches, e.g., compare MASTER and SAMPLE_12 to get all commits for potential Pull Request?

How to form a GitHub GraphQL API query to compare between branches, e.g., compare MASTER and SAMPLE_12 to get all commits for potential Pull Request?


0

Looking for a GraphQl query to search for a list of all commits when comparing between two branches on GitHub within a repository.
For example, https://github.com/account-test/repo-test/compare/main…development will render all the commits, if any.
How to get the list of all commits when comparing between two branches using the GitHub GraphQL API?

I tried query to get the Pull requests

{
repository(owner: "sample", name: "sample-test") {
    refs(refPrefix: "refs/heads/", orderBy: {direction: DESC, field: TAG_COMMIT_DATE}, first: 100) {
      edges {
        node {
          ... on Ref {
            name
            target {
              ... on Commit {
                history(first: 2) {
                  edges {
                    node {
                      ... on Commit {
                        committedDate
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

However, comparing between two branches to get commits for a potential Pull Request is much more involved.

1 Answer
1


0

As it turns out Shell scripting is an answer to this task:
Clone all your repositories locally, "git pull" and output the defined search parameter.
PS. GitHub API has a certain limit of requests, which potentially can become costly if the application is big.



Leave a Reply

Your email address will not be published. Required fields are marked *