Skip to content

Commit 5a2c9c2

Browse files
committed
New example: Creating a project
1 parent 024fc51 commit 5a2c9c2

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

examples/create_new_project/main.go

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

0 commit comments

Comments
 (0)