Add branch-name to Bitbucket Rest API v2.0 GET

Issue #11627 wontfix
Christian Löw
created an issue

Please add a field "branch" to the response of:

api/2.0/repositories/teamname/project/commit/463b99d6f0axxxxxxxx

I need to get all commits of a team with the branch information. First i fetch all projects of a team and then all commits made in them. After that i need to read the branch of every commit.

Best regards,

Chris

Comments (10)

  1. Erik van Zijst staff

    What would you except to see? As in, what's your definition of a commit's branch? Something like the output of git branch --contains SHA1?

    A problem with a branch --contains approach is that a repo's root commit by definition is on all branches, which could be a list of 1000s of branch names and arguably not be terribly useful.

    Maybe you could be a little more specific?

  2. Christian Löw reporter

    Thank you for the fast reply. This is a short response-snipped from the codeship api. This is a response which returns the build-status of a specific commit:

    {
      "id": 3277309,
      "uuid": "80240b80-6742-0132-8d88-366b9ffd5919"
      "project_id": 33837,
      "status": "success",
      "branch": "master",
      "commit_id": "81d2282b97c37c30a40302282402828f61f4f4ee",
      "github_username": "mlocher",
      "message": "Fixed the second code block for skipping builds.",
      "started_at": "2014-12-16T11:13:35.178Z",
      "finished_at": "2014-12-16T11:14:08.271Z",
      "debug_connection": null,
    }
    

    As you can see there is a property called branch. And if i fetch a single commit on Bitbucket's API i just don't get the branch name like on codeship's api. Maybe it's my fault, but i could not figure it out where i should get the branch of a single commit.

  3. Christian Löw reporter

    Here is a single commit pulled from the bitbucket API-Response of https://bitbucket.org/api/2.0/repositories/{teamName}/{projectName}/commits.

    And im missing a "branch": "master" field in the response.

    {
        "hash":"aXXxxxxxx634dd22fa12ce09b966",
       "repository":{
        "links":{
            "self":{
                "href":"https:\/\/api.bitbucket.org\/2.0\/repositories\/xxxxx\/xxxxx"
             },
             "html":{
                "href":"https:\/\/bitbucket.org\/xxxxx\/xxxxx"
             },
             "avatar":{
                "href":"https:\/\/bitbucket.org\xxxxx\/xxxxx\/avatar\/16\/"
             }
          },
          "type":"repository",
          "name":"xxxxxx",
          "full_name":"xxxxx\/xxxxx",
          "uuid":"{xxxxxb1ec-9ca3040e9d19}"
       },
       "links":{
        "self":{
            "href":"https:\/\/api.bitbucket.org\/2.0\/repositories\/xxxxxx\/xxxxxx\/commit\/xxxxx323f17d10a3634dd22fa12ce09b966"
          },
          "comments":{
            "href":"https:\/\/api.bitbucket.org\/2.0\/repositories\/xxxxxx\/xxxxxx\/commit\/fcxxxxe3c323f17d10a3634dd22fa12ce09b966\/comments"
          },
          "patch":{
            "href":"https:\/\/api.bitbucket.org\/2.0\/repositories\/xxxxxx\/xxxxxx\/patch\/fcc0dxxxx23f17d10a3634dd22fa12ce09b966"
          },
          "html":{
            "href":"https:\/\/bitbucket.org\/xxxxxx\/xxxxxx\/commits\/fcc0daae3c323f1xxxx634dd22fa12ce09b966"
          },
          "diff":{
            "href":"https:\/\/api.bitbucket.org\/2.0\/repositories\/xxxxxx\/xxxxxx\/diff\/fccxxxxc323f17d10a3634dd22fa12ce09b966"
          },
          "approve":{
            "href":"https:\/\/api.bitbucket.org\/2.0\/repositories\/xxxxxx\/xxxxxx\/commit\/fcc0daaxxxxxx17d10a3634dd22fa12ce09b966\/approve"
          }
       },
       "author":{
        "raw":"Max Mustermann",
          "user":{
            "username":"my-name",
             "display_name":"Max Mustermann",
             "type":"user",
             "uuid":"{17ccccxxx-44c1-b8af-be9b56ba14dc}",
             "links":{
                "self":{
                    "href":"https:\/\/api.bitbucket.org\/2.0\/users\/my-name"
                },
                "html":{
                    "href":"https:\/\/bitbucket.org\/my-name\/"
                },
                "avatar":{
                    "href":"https:\/\/bitbucket.org\/account\/my-name\/avatar\/32\/"
                }
             }
          }
       },
       "parents":[
          {
              "hash":"23cadbb2032cxxxxx9c93f5968627c4b7681fd0e",
             "type":"commit",
             "links":{
              "self":{
                  "href":"https:\/\/api.bitbucket.org\/2.0\/repositories\/xxxxxx\/xxxxxx\/commit\/23cadbbxxxxx7f6a49c93f5968627c4b7681fd0e"
                },
                "html":{
                  "href":"https:\/\/bitbucket.org\/xxxxxx\/xxxxxx\/commits\/23caxxxx32c7f6a49cxxxxxxc4b7681fd0e"
                }
             }
          }
       ],
       "date":"2015-08-03T11:10:11+00:00",
       "message":"Set sys to v51!\n",
       "type":"commit"
    }
    
  4. Erik van Zijst staff

    Codeship's commit status API does a different thing than Bitbucket's commits API. Builds are typically associated with branches, and branches point to a commit.

    In Git (and similar for Mercurial bookmarks), a branch is merely a pointer to a commit. Branches are directly associated with commits, but not the other way around.

    One could argue that all ancestors of the commit a branch is pointing to are known to be "on that branch" (in fact, that is essentially the behavior of git log and Bitbucket's commit page) if you take the branch as the starting point, but this makes less sense in reverse.

    When you start with a commit, what branch is that known to be on? Following the above logic, it will be on all branches whose HEADs descend from our commit. In the case of the repo's root, the oldest commit, that is every single branch. There's no one specific branch. It's everything that is reachable through it.

    This makes it less useful and in cases of large repos, hugely impractical to include a potentially huge list of refs in each commit object.

    You can see this reflected elsewhere too (e.g. GitHub's commit object https://api.github.com/repos/mojombo/grit/git/commits/5608567286e64a1c55c5e7fcd415364e04f8986e does not have a branch element).

    While Git does allow you to compute this list[1], no branch information is displayed in git log SHA1 or git show SHA1.

    So considering there is no 1-to-1 relationship between branches and commits, I'm wondering about your use case.

    [1] Computing all branches the repo's oldest commit is on:

    $ git rev-list --reverse HEAD| head -n 1 # find the oldest commit
    bbd94625982726eb9ce7ae982df415edef3679f0
    $ git branch --contains bbd94625982726eb9ce7ae982df415edef3679f0 | wc -l
         307
    
  5. Log in to comment