Skip to content

Instantly share code, notes, and snippets.

@ImUser773
Created April 18, 2019 07:58
Show Gist options
  • Save ImUser773/b460a5df4be26aa6bbcbcc57f05322cb to your computer and use it in GitHub Desktop.
Save ImUser773/b460a5df4be26aa6bbcbcc57f05322cb to your computer and use it in GitHub Desktop.
bitbucket-api-with-groovy.md

This gist I want to shere how to get data from bitbucket api.

In my case, I want to list all repo tag

curl -v https://user:[email protected]/2.0/repositories/reposname/project-name/refs/tags

find Authorization key
> Host: api.bitbucket.org
> Authorization: Basic #TOKEN
> User-Agent: curl/7.54.0
> Accept: */*

curl -H "Authorization: Basic #TOKEN" https://api.bitbucket.org/2.0/repositories/reposname/project-name/refs/tags

import groovy.json.JsonSlurper

def name = "reponame"
def git_path = "https://api.bitbucket.org/2.0/repositories/reposname/${name}/refs/tags"
def get = new URL(git_path)
            .openConnection();

get.addRequestProperty("Authorization", "Basic #TOKEN");
def responseCode = get.getResponseCode();
def content = get.getInputStream().getText();
def contentList = new JsonSlurper().parseText(content);

println(responseCode)
def jsondata = [tags:contentList.values.sort { it.date }]
jsondata.tags.each {
    println(it.name)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment