Skip to content

Commit

Permalink
New example: Creating a project
Browse files Browse the repository at this point in the history
  • Loading branch information
andygrunwald committed Sep 19, 2021
1 parent 024fc51 commit 5a2c9c2
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions examples/create_new_project/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package main

import (
"fmt"

"github.com/andygrunwald/go-gerrit"
)

func main() {
instance := fmt.Sprintf("http://%s:8080", "localhost")
client, err := gerrit.NewClient(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(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'
}

0 comments on commit 5a2c9c2

Please sign in to comment.