Giter Site home page Giter Site logo

go-gerrit's Introduction

go-gerrit

Quality Gate Status Codacy Badge

go-gerrit is a Go client library for the Gerrit Code Review system.

See https://pkg.go.dev/github.com/shijl0925/go-gerrit for supported endpoints.

Installation

go get github.com/shijl0925/go-gerrit

Usage

Use gerrit.NewClient to create a new Gerrit client. It needs a Gerrit baseUrl and username / password, and optionally accepts an existing *http.Client.

After creating the client, create a new request from one of the endpoint-specific packages, i.e. gerrit.ProjectOptions from github.com/shijl0925/go-gerrit/projects.

package main
import (
    "context"
    "fmt"
    "github.com/shijl0925/go-gerrit"
    "log"
)

func main() {
    ctx := context.Background()
    baseUrl := "https://review.lineageos.org"
    client, _ := gerrit.NewClient(baseUrl, gerrit.DefaultClient)

    option := gerrit.ProjectOptions{}
    option.Limit = 25
    option.Skip = 0

    projects, _, err := client.Projects.List(ctx, &option)
    if err != nil {
        log.Fatalf("could not search projects: %+v", err)
    }
    for name, project := range projects {
        fmt.Printf("Project Name: %s, ID: %s, State: %s\n", name, project.ID, project.State)
    }
}

Use gerrit.NewGitilesClient to create a new Gitiles client. It needs a Gitiles baseUrl and username / password, and optionally accepts an existing *http.Client.

package main
import (
    "context"
    "fmt"
    "github.com/shijl0925/go-gerrit"
    "log"
)

func main() {
    ctx := context.Background()
    // baseUrl := "http://127.0.0.1:8080/plugins/gitiles/"
    baseUrl := "https://gerrit.googlesource.com/"
    client, _ := gerrit.NewGitilesClient(baseUrl, nil)

    projectName := "gerrit"
    commitID := "ec36cba6080bac72790c7875c36f5b86fc55372c"
    commit, _, err := client.GetCommit(ctx, projectName, commitID)

    if err != nil {
        log.Panicf("Gitiles.GetCommit returned error: %v", err)
    }
    log.Printf("Commit: %v", commit)
}

go-gerrit's People

Contributors

shijl0925 avatar

Watchers

 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.