Git Product home page Git Product logo

bitbucket-go's Introduction

bitbucket-go

bitbucket-go?status

Bitbucket APIv2 library for Golang.

NOTE:

This repository was originally a fork of this repository. I have introduced breaking changes to my original fork which made it impossible to track upstream/parent. So, I have decided it is best to move my fork to a standalone repository. All the history from the fork remains intact.

I am aiming to implement all available API resources Bitbucket APIv2 provides to its users publically.

This fork also takes several 'inspirations' (with due credit) from the go-github library so if you see similarities, you know why =).

Install

go get github.com/davidji99/bitbucket-go

Usage

Sample:

package main

import (
        "fmt"

        "github.com/davidji99/bitbucket-go/bitbucket"
)

func main() {
        client := bitbucket.NewBasicAuth("<USERNAME>", "<PASSWORD>")
        
        title := "new issue"
        description := "new issue description"
        baseBranch := "master"
        sourceBranch := "bugFix/fix-this-issue"
        closeSourceBranch := true

        createOpts := &bitbucket.CreatePullRequestOpts{
            Title:       &title,
            Description: &description,
            Destination: &bitbucket.NewPullRequestDestinationOpts{
                Branch: &bitbucket.Branch{Name: &baseBranch},
            },
            Source: &bitbucket.NewPullRequestSourceOpts{
                Branch: &bitbucket.Branch{Name: &sourceBranch},
            },
            CloseSourceBranch: &closeSourceBranch,
        }

        newPullRequest, response, createErr := client.PullRequests.Create("<ORG>", "<REPO_SLUG>", createOpts)
        if createErr != nil {
        	panic(createErr)
        }
        
        if response.StatusCode == 201 {
            fmt.Println("Pull request created!")
        }

        fmt.Println(newPullRequest.GetLinks().GetSelf().GetHRef())
}

Query Parameters:

In addition to resource specific query parameters, Bitbucket offers what I like to call 'generic' query parameters that are not tied to a specific resource. These query parameters are:

  • List ?page=1&pagelen=35
  • Filter & Sort ?q=source.repository.full_name+%21%3D+%22main%2Frepo%22
  • Partial Response ?fields=values.id,values.reviewers.username

Not all of the above will work with every resource/endpoint so please refer to the official Bitbucket APIv2 documentation.

Users can mix and match generic parameters with resource parameters or even create their own struct for query parameters.

Example usage of query parameters:

api := bitbucket.NewBasicAuth("<USER>", "<APP_PASSWORD>")

opts1 := &bitbucket.PartialRespOpts{
    Fields: "-values.links",
}

opts2 := &bitbucket.FilterSortOpts{
    Query: "destination.branch.name = \"master\"",
}

opts3 := &bitbucket.PullRequestListOpts{
    State: []string{"OPEN"},
}

result, _, err := api.PullRequests.List(c.String("<ORG>", "<REPO_SLUG>", opts1, opts2, opts3)
if err != nil {
    return err
}

for _, i := range result.Values {
    fmt.Println(i.GetPriority())
    fmt.Println(i.GetLinks().GetSelf().GetHRef())
}

which will return all pull requests that are open, with no links in the results, and whose destination branch in master.

FAQ

  • Only supports Bitbucket APIv2.

Author

davidji99

bitbucket-go's People

Contributors

analogj avatar blacs30 avatar davidji99 avatar egorovv avatar ilius avatar jmartin84 avatar ktrysmt avatar mainiak avatar makkrnic avatar mjpitz avatar noodlensk avatar phanatic avatar rcarmstrong avatar soupdiver avatar srgrn avatar svedova avatar toneill-newinnov avatar xx-parks-xx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

bitbucket-go's Issues

Create comment on PR not working

It doesn't work because it's not passing the field content

Passing

map[string]interface{}{"content": po}

to the request fixes the issue

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.