GithubHelp home page GithubHelp logo

stingraydigital / go-gitbucket Goto Github PK

View Code? Open in Web Editor NEW

This project forked from shiena/go-gitbucket

0.0 1.0 0.0 22 KB

Go library for accessing the GitBucket API

Home Page: http://godoc.org/github.com/shiena/go-gitbucket/gitbucket

License: MIT License

Go 100.00%

go-gitbucket's Introduction

  • Added organisations listing
  • Added users listing
  • Added go module support

go-gitbucket

GoDoc

go-gitbucket is a Go client library for accessing the GitBucket API.

Usage

import "github.com/StingrayDigital/go-gitbucket/gitbucket"

GitBucket API

url := "http://privatesite.example.org:8080/gitbucket/"
accessToken := "... your access token ..." // Generated from your account settings

client, err := gitbucket.NewClient(url, accessToken)

// Users API
user, res, err := client.Users.Get("username")

// Repositories API
repo, res, err := client.Repositories.Get("username", "reponame", "ref")
repos, res, err := client.Repositories.ListStatuses("username", "master", "ref")
stats, res, err := client.Repositories.GetCombinedStatus("username", "master", "ref")
stat, res, err := client.Repositories.CreateStatus(
	"username",
	"master",
	"sha",
	&gitbucket.RepoStatus{
		State: gitbucket.String("success"), // Required
		TargetURL: gitbucket.String("https://examples.org/build/status"),
		Description: gitbucket.String("The build succeeded"),
		Context: gitbucket.String("continuous-integration/jenkins"),
	},
)
newRepo, res, err := client.Repositories.Create(
	"", // if parameter is not empty, set group name.
	&gitbucket.Repository{
		Name: gitbucket.String("Hello-World"), // Required
		Description: gitbucket.String("This is your first repository"),
		Private: gitbucket.Bool(true), // Default: false
		AutoInit: gitbucket.Bool(true), // Default: false
	},
)

// Issues API
issues, res, err := client.Issues.ListComments("username", "reponame", 1)
issue, res, err := client.Issues.CreateComment(
	"username",
	"reponame",
	1,
	&gitbucket.IssueComment{
		Body: gitbucket.String("Me too"),
	},
)

// Pull Requests API
pull, res, err := client.PullRequests.Get("username", "reponame", 1)
pulls, res, err := client.PullRequests.List("username", "reponame")
commits, res, err := client.PullRequests.ListCommits("username", "reponame", 1)

// Others API
rateLimit, res, err := client.RateLimit()

Receive a GitBucket WebHook Events

package main

import (
	"encoding/json"
	"log"
	"net/http"

	"github.com/k0kubun/pp"
	"github.com/StingrayDigital/go-gitbucket/gitbucket"
)

func getEvent(r *http.Request) interface{} {
	event := gitbucket.GetWebHookEvent(r)
	switch event {
	case gitbucket.IssuesEvent:
		return &gitbucket.WebHookIssuesPayload{}
	case gitbucket.IssueCommentEvent:
		return &gitbucket.WebHookIssueCommentPayload{}
	case gitbucket.PullRequestEvent:
		return &gitbucket.WebHookPullRequestPayload{}
	case gitbucket.PullRequestReviewCommentEvent:
		return &gitbucket.WebHookPullRequestReviewCommentPayload{}
	case gitbucket.PushEvent:
		return &gitbucket.WebHookPushPayload{}
	default:
		return nil
	}
}

func printEventHandler(w http.ResponseWriter, r *http.Request) {
	payload := r.FormValue("payload")
	event := getEvent(r)
	if payload != "" && event != nil {
		if err := json.Unmarshal([]byte(payload), event); err == nil {
			log.Println(pp.Sprint(event))
		}
	} else {
		log.Println("Received a invalid message")
	}
}

func main() {
	http.HandleFunc("/", printEventHandler)
	log.Fatal(http.ListenAndServe(":8000", nil))
}

License

This library is distributed under the MIT license found in the LICENSE file.

go-gitbucket's People

Contributors

shiena avatar amaari-stingray avatar toversus avatar

Watchers

James Cloos avatar

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.