-
-
Notifications
You must be signed in to change notification settings - Fork 39
/
main.go
41 lines (33 loc) · 1 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main
import (
"context"
"fmt"
"github.com/andygrunwald/go-gerrit"
)
func main() {
instance := fmt.Sprintf("http://%s:8080", "localhost")
ctx := context.Background()
client, err := gerrit.NewClient(ctx, instance, nil)
if err != nil {
panic(err)
}
// Get your credentials
// For local development setups, go to
// http://localhost:8080/settings/#HTTPCredentials
// and click `GENERATE NEW PASSWORD`.
// Replace `secret` with your new value.
client.Authentication.SetBasicAuth("admin", "secret")
gerritProject := "Example project to the moon"
gerritBranch := "main"
data := &gerrit.ProjectInput{
Name: gerritProject,
Branches: []string{gerritBranch},
CreateEmptyCommit: true,
}
projectInfo, _, err := client.Projects.CreateProject(ctx, gerritProject, data)
if err != nil {
panic(err)
}
fmt.Printf("Project '%s' created with ID '%+v'", projectInfo.Name, projectInfo.ID)
// Project 'Example project to the moon' created with ID 'Example+project+to+the+moon'
}