Skip to content

shijl0925/go-gerrit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-gerrit

Alt

Quality Gate Status Codacy Badge DeepSource

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)
}