Using the Github API is it possible to determine if a branch is ahead of the default branch?
Asked Answered
L

1

6

Using the Github API (no local git commands), is it possible to compare a branch to see if it has any changes ahead of the default branch?

I'm building an auditing tool, and would like to identify branches that are candidates to be closed, because all of their changes exist in the default branch.

I want the same information that drives the charts on the branches page: branch that has (See https://github.com/octokit/octokit.rb/branches)

Is it possible to do get this information purely with the Github API?

Lehr answered 28/7, 2018 at 8:53 Comment(0)
N
7

You can:

In that case it would be : https://api.github.com/repos/octokit/octokit.rb/compare/kytrinyx/generator/spike...master

Example using , & :

branch=kytrinyx/generator/spike
default_branch=$(curl -s "https://api.github.com/repos/octokit/octokit.rb" | jq -r '.default_branch')
curl -s "https://api.github.com/repos/octokit/octokit.rb/compare/$branch...$default_branch" | \
     jq -r '.ahead_by, .behind_by'
Neuralgia answered 28/7, 2018 at 14:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.