Skip to content

Commit

Permalink
Merge branch 'hotfix/v1.0.21.14-create-team-via-kdt'
Browse files Browse the repository at this point in the history
  • Loading branch information
canack committed Aug 3, 2023
2 parents 9477c31 + 4952462 commit 1487102
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 0 deletions.
38 changes: 38 additions & 0 deletions client/team.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
Copyright © 2023 Kondukto
*/

package client

import "net/http"

type Team struct {
Name string `json:"name"`
IssueResponsible IssueResponsible `json:"issue_responsible"`
}

type IssueResponsible struct {
Username string `json:"username"`
}

func (c *Client) CreateTeam(teamName, responsible string) error {
var team = Team{
Name: teamName,
IssueResponsible: IssueResponsible{
Username: responsible,
},
}

req, err := c.newRequest(http.MethodPost, "/api/v3/teams", team)
if err != nil {
return err
}

_, err = c.do(req, nil)
if err != nil {
return err
}

return nil
}
63 changes: 63 additions & 0 deletions cmd/createTeam.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
Copyright © 2023 Kondukto
*/

package cmd

import (
"fmt"

"github.com/kondukto-io/kdt/client"

"github.com/spf13/cobra"
)

// createTeamCmd represents the create project command
var createTeamCmd = &cobra.Command{
Use: "team",
Short: "creates a new team on Kondukto",
Run: createTeamRootCommand,
}

func init() {
createCmd.AddCommand(createTeamCmd)

createTeamCmd.Flags().StringP("name", "n", "", "team name")
createTeamCmd.Flags().StringP("responsible", "r", "", "responsible user name")
}

func createTeamRootCommand(cmd *cobra.Command, _ []string) {
c, err := client.New()
if err != nil {
qwe(ExitCodeError, err, "could not initialize Kondukto client")
}

teamName, err := cmd.Flags().GetString("name")
if err != nil {
qwe(ExitCodeError, err, "failed to parse the name flag")
}

if teamName == "" {
qwm(ExitCodeError, "team name is required")
}

// Responsible is optional
responsible, err := cmd.Flags().GetString("responsible")
if err != nil {
qwe(ExitCodeError, err, "failed to parse the responsible flag")
}

if err := c.CreateTeam(teamName, responsible); err != nil {
qwe(ExitCodeError, err, "failed to create team")
}

var successfulMessage string
if responsible != "" {
successfulMessage = fmt.Sprintf("team [%s] created successfuly with responsible [%s]", teamName, responsible)
} else {
successfulMessage = fmt.Sprintf("team [%s] created successfuly with responsible [admin]", teamName)
}

qwm(ExitCodeSuccess, successfulMessage)
}

0 comments on commit 1487102

Please sign in to comment.