{"id":16569986,"url":"https://github.com/andygrunwald/go-gerrit","last_synced_at":"2025-05-16T00:06:20.339Z","repository":{"id":36712484,"uuid":"41019046","full_name":"andygrunwald/go-gerrit","owner":"andygrunwald","description":"Go client/library for Gerrit Code Review","archived":false,"fork":false,"pushed_at":"2024-10-30T09:22:41.000Z","size":498,"stargazers_count":99,"open_issues_count":22,"forks_count":42,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-08T11:09:37.496Z","etag":null,"topics":["code-review","gerrit","go","golang","hacktoberfest","review"],"latest_commit_sha":null,"homepage":"https://godoc.org/github.com/andygrunwald/go-gerrit","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/andygrunwald.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"andygrunwald","custom":"https://paypal.me/andygrunwald"}},"created_at":"2015-08-19T07:10:36.000Z","updated_at":"2025-03-03T13:30:36.000Z","dependencies_parsed_at":"2024-03-31T08:33:45.894Z","dependency_job_id":"935f7008-9d9a-4d02-b274-da67a0d1458c","html_url":"https://github.com/andygrunwald/go-gerrit","commit_stats":{"total_commits":398,"total_committers":38,"mean_commits":"10.473684210526315","dds":0.5025125628140703,"last_synced_commit":"31687dc5673cabc520980d8b1de2fe4d8f7cf666"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andygrunwald%2Fgo-gerrit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andygrunwald%2Fgo-gerrit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andygrunwald%2Fgo-gerrit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andygrunwald%2Fgo-gerrit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andygrunwald","download_url":"https://codeload.github.com/andygrunwald/go-gerrit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254442854,"owners_count":22071878,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["code-review","gerrit","go","golang","hacktoberfest","review"],"created_at":"2024-10-11T21:16:16.448Z","updated_at":"2025-05-16T00:06:20.295Z","avatar_url":"https://github.com/andygrunwald.png","language":"Go","funding_links":["https://github.com/sponsors/andygrunwald","https://paypal.me/andygrunwald"],"categories":["Third-party APIs","第三方api"],"sub_categories":["Utility/Miscellaneous","实用程序/Miscellaneous"],"readme":"# go-gerrit\n\n[![GoDoc](https://pkg.go.dev/badge/github.com/andygrunwald/go-gerrit?utm_source=godoc)](https://pkg.go.dev/github.com/andygrunwald/go-gerrit)\n\ngo-gerrit is a [Go](https://golang.org/) client library for the [Gerrit Code Review](https://www.gerritcodereview.com/) system.\n\n![go-gerrit - Go client/library for Gerrit Code Review](./img/logo.png \"go-gerrit - Go client/library for Gerrit Code Review\")\n\n## Features\n\n* [Authentication](https://pkg.go.dev/github.com/andygrunwald/go-gerrit#AuthenticationService) (HTTP Basic, HTTP Digest, HTTP Cookie)\n* Every API Endpoint like Gerrit\n    * [/access/](https://pkg.go.dev/github.com/andygrunwald/go-gerrit#AccessService)\n    * [/accounts/](https://pkg.go.dev/github.com/andygrunwald/go-gerrit#AccountsService)\n    * [/changes/](https://pkg.go.dev/github.com/andygrunwald/go-gerrit#ChangesService)\n    * [/config/](https://pkg.go.dev/github.com/andygrunwald/go-gerrit#ConfigService)\n    * [/groups/](https://pkg.go.dev/github.com/andygrunwald/go-gerrit#GroupsService)\n    * [/plugins/](https://pkg.go.dev/github.com/andygrunwald/go-gerrit#PluginsService)\n    * [/projects/](https://pkg.go.dev/github.com/andygrunwald/go-gerrit#ProjectsService)\n* Supports optional plugin APIs such as\n    * events-log - [About](https://gerrit.googlesource.com/plugins/events-log/+/master/src/main/resources/Documentation/about.md), [REST API](https://gerrit.googlesource.com/plugins/events-log/+/master/src/main/resources/Documentation/rest-api-events.md)\n\n## Installation\n\n_go-gerrit_ follows the [Go Release Policy](https://golang.org/doc/devel/release.html#policy).\nThis means we support the current + 2 previous Go versions.\n\nIt is go gettable ...\n\n```sh\n$ go get github.com/andygrunwald/go-gerrit\n```\n\n## API / Usage\n\nHave a look at the [GoDoc documentation](https://pkg.go.dev/github.com/andygrunwald/go-gerrit) for a detailed API description.\n\nThe [Gerrit Code Review - REST API](https://gerrit-review.googlesource.com/Documentation/rest-api.html) was the foundation document.\n\n### Authentication\n\nGerrit supports multiple ways for [authentication](https://gerrit-review.googlesource.com/Documentation/rest-api.html#authentication).\n\n#### HTTP Basic\n\nSome Gerrit instances (like [TYPO3](https://review.typo3.org/)) has [auth.gitBasicAuth](https://gerrit-review.googlesource.com/Documentation/config-gerrit.html#auth.gitBasicAuth) activated.\nWith this, you can authenticate with HTTP Basic like this:\n\n```go\ninstance := \"https://review.typo3.org/\"\nclient, _ := gerrit.NewClient(instance, nil)\nclient.Authentication.SetBasicAuth(\"andy.grunwald\", \"my secrect password\")\n\nself, _, _ := client.Accounts.GetAccount(\"self\")\n\nfmt.Printf(\"Username: %s\", self.Name)\n\n// Username: Andy Grunwald\n```\n\nIf you get a `401 Unauthorized`, check your Account Settings and have a look at the `HTTP Password` configuration.\n\n#### HTTP Digest\n\nSome Gerrit instances (like [Wikimedia](https://gerrit.wikimedia.org/)) has [Digest access authentication](https://en.wikipedia.org/wiki/Digest_access_authentication) activated.\n\n```go\ninstance := \"https://gerrit.wikimedia.org/r/\"\nclient, _ := gerrit.NewClient(instance, nil)\nclient.Authentication.SetDigestAuth(\"andy.grunwald\", \"my secrect http password\")\n\nself, resp, err := client.Accounts.GetAccount(\"self\")\n\nfmt.Printf(\"Username: %s\", self.Name)\n\n// Username: Andy Grunwald\n```\n\nIf the chosen Gerrit instance does not support digest auth, an error like `WWW-Authenticate header type is not Digest` is thrown.\n\nIf you get a `401 Unauthorized`, check your Account Settings and have a look at the `HTTP Password` configuration.\n\n#### HTTP Cookie\n\nSome Gerrit instances hosted like the one hosted googlesource.com (e.g. [Go](https://go-review.googlesource.com/), [Android](https://android-review.googlesource.com/) or [Gerrit](https://gerrit-review.googlesource.com/)) support HTTP Cookie authentication.\n\nYou need the cookie name and the cookie value.\nYou can get them by click on \"Settings \u003e HTTP Password \u003e Obtain Password\" in your Gerrit instance.\n\nThere you can receive your values.\nThe cookie name will be (mostly) `o` (if hosted on googlesource.com).\nYour cookie secret will be something like `git-your@email.com=SomeHash...`.\n\n```go\ninstance := \"https://gerrit-review.googlesource.com/\"\nclient, _ := gerrit.NewClient(instance, nil)\nclient.Authentication.SetCookieAuth(\"o\", \"my-cookie-secret\")\n\nself, _, _ := client.Accounts.GetAccount(\"self\")\n\nfmt.Printf(\"Username: %s\", self.Name)\n\n// Username: Andy G.\n```\n\n## Examples\n\nMore examples are available\n\n* in the [GoDoc examples section](https://pkg.go.dev/github.com/andygrunwald/go-gerrit#pkg-examples).\n* in the [examples folder](./examples)\n\n### Get version of Gerrit instance\n\nReceive the version of the [Gerrit instance used by the Gerrit team](https://gerrit-review.googlesource.com/) for development:\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/andygrunwald/go-gerrit\"\n)\n\nfunc main() {\n\tinstance := \"https://gerrit-review.googlesource.com/\"\n\tclient, err := gerrit.NewClient(instance, nil)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tv, _, err := client.Config.GetVersion()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Printf(\"Version: %s\", v)\n\n\t// Version: 3.4.1-2066-g8db5605430\n}\n```\n\n### Get all public projects\n\nList all projects from [Chromium](https://chromium-review.googlesource.com/):\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/andygrunwald/go-gerrit\"\n)\n\nfunc main() {\n\tinstance := \"https://chromium-review.googlesource.com/\"\n\tclient, err := gerrit.NewClient(instance, nil)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\topt := \u0026gerrit.ProjectOptions{\n\t\tDescription: true,\n\t}\n\tprojects, _, err := client.Projects.ListProjects(opt)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfor name, p := range *projects {\n\t\tfmt.Printf(\"%s - State: %s\\n\", name, p.State)\n\t}\n\n\t// chromiumos/third_party/bluez - State: ACTIVE\n\t// external/github.com/Polymer/ShadowDOM - State: ACTIVE\n\t// external/github.com/domokit/mojo_sdk - State: ACTIVE\n\t// ...\n}\n```\n\n### Query changes\n\nGet some changes of the [kernel/common project](https://android-review.googlesource.com/#/q/project:kernel/common) from the [Android](http://source.android.com/)[Gerrit Review System](https://android-review.googlesource.com/).\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/andygrunwald/go-gerrit\"\n)\n\nfunc main() {\n\tinstance := \"https://android-review.googlesource.com/\"\n\tclient, err := gerrit.NewClient(instance, nil)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\topt := \u0026gerrit.QueryChangeOptions{}\n\topt.Query = []string{\"project:kernel/common\"}\n\topt.AdditionalFields = []string{\"LABELS\"}\n\tchanges, _, err := client.Changes.QueryChanges(opt)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfor _, change := range *changes {\n\t\tfmt.Printf(\"Project: %s -\u003e %s -\u003e %s%d\\n\", change.Project, change.Subject, instance, change.Number)\n\t}\n\n\t// Project: kernel/common -\u003e ANDROID: GKI: Update symbols to symbol list -\u003e https://android-review.googlesource.com/1830553\n\t// Project: kernel/common -\u003e ANDROID: db845c_gki.fragment: Remove CONFIG_USB_NET_AX8817X from fragment -\u003e https://android-review.googlesource.com/1830439\n\t// Project: kernel/common -\u003e ANDROID: Update the ABI representation -\u003e https://android-review.googlesource.com/1830469\n\t// ...\n}\n```\n\n## Development\n\n### Running tests and linters\n\nTests only:\n\n```sh\n$ make test\n```\n\nChecks, tests and linters\n\n```sh\n$ make vet staticcheck test\n```\n\n### Local Gerrit setup\n\nFor local development, we suggest the usage of the [official Gerrit Code Review docker image](https://hub.docker.com/r/gerritcodereview/gerrit):\n\n```\n$ docker run -ti -p 8080:8080 -p 29418:29418 gerritcodereview/gerrit:3.4.1\n```\n\nWait a few minutes until the ```Gerrit Code Review NNN ready``` message appears,\nwhere NNN is your current Gerrit version, then open your browser to http://localhost:8080\nand you will be in Gerrit Code Review.\n\n#### Authentication\n\nFor local development setups, go to http://localhost:8080/settings/#HTTPCredentials and click `GENERATE NEW PASSWORD`.\nNow you can use (only for development purposes):\n\n```go\nclient.Authentication.SetBasicAuth(\"admin\", \"secret\")\n```\n\nReplace `secret` with your new value.\n\n## Frequently Asked Questions (FAQ)\n\n### How is the source code organized?\n\nThe source code organization is inspired by [go-github by Google](https://github.com/google/go-github).\n\nEvery REST API Endpoint (e.g. [`/access/`](https://gerrit-review.googlesource.com/Documentation/rest-api-access.html), [`/changes/`](https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html)) is coupled in a service (e.g. [`AccessService` in access.go](./access.go), [`ChangesService` in changes.go](./changes.go)).\nEvery service is part of [`gerrit.Client`](./gerrit.go) as a member variable.\n\n`gerrit.Client` can provide essential helper functions to avoid unnecessary code duplications, such as building a new request or parse responses.\n\nBased on this structure, implementing a new API functionality is straight forward.\nHere is an example of `*ChangeService.DeleteTopic*` / [DELETE /changes/{change-id}/topic](https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#delete-topic):\n\n```go\nfunc (s *ChangesService) DeleteTopic(changeID string) (*Response, error) {\n    u := fmt.Sprintf(\"changes/%s/topic\", changeID)\n    return s.client.DeleteRequest(u, nil)\n}\n```\n\n### What about the version compatibility with Gerrit?\n\nThe library was implemented based on the REST API of Gerrit version 2.11.3-1230-gb8336f1 and tested against this version.\n\nThis library might be working with older versions as well.\nIf you notice an incompatibility [open a new issue](https://github.com/andygrunwald/go-gerrit/issues/new).\nWe also appreciate your Pull Requests to improve this library.\nWe welcome contributions!\n\n### What about adding code to support the REST API of an (optional) plugin?\n\nIt will depend on the plugin, and you are welcome to [open a new issue](https://github.com/andygrunwald/go-gerrit/issues/new) first to propose the idea and use-case.\nAs an example, the addition of support for `events-log` plugin was supported because the plugin itself is fairly\npopular.\nThe structures that the REST API uses could also be used by `gerrit stream-events`.\n\n## License\n\nThis project is released under the terms of the [MIT license](https://choosealicense.com/licenses/mit/).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandygrunwald%2Fgo-gerrit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandygrunwald%2Fgo-gerrit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandygrunwald%2Fgo-gerrit/lists"}