-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update gerritctl, include account group change
- Loading branch information
Showing
6 changed files
with
341 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"github.com/shijl0925/go-gerrit" | ||
"github.com/spf13/cobra" | ||
"os" | ||
) | ||
|
||
// Account Commands | ||
var account = &cobra.Command{ | ||
Use: "account", | ||
Short: "account related commands", | ||
} | ||
|
||
var accountList = &cobra.Command{ | ||
Use: "list", | ||
Short: "list accounts", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
Limit, _ := cmd.Flags().GetInt("limit") | ||
Start, _ := cmd.Flags().GetInt("start") | ||
AdditionalFields, _ := cmd.Flags().GetStringSlice("additional_fields") | ||
|
||
option := gerrit.QueryAccountOptions{} | ||
option.Start = Start | ||
option.Limit = Limit | ||
option.Query = []string{"is:active"} | ||
option.AdditionalFields = AdditionalFields //[]string{"DETAILS"} | ||
accounts, _, err := gerritMod.Instance.Accounts.Query(gerritMod.Context, &option) | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
|
||
for _, account := range *accounts { | ||
fmt.Printf("✅ Account AccountID: %d.\n", account.AccountID) | ||
if Verbose { | ||
if out, err := ToIndentJSON(account); err != nil { | ||
fmt.Println(err) | ||
} else { | ||
fmt.Printf("%+v\n", out) | ||
} | ||
} | ||
} | ||
}, | ||
} | ||
|
||
var accountGet = &cobra.Command{ | ||
Use: "show", | ||
Short: "Retrieve the account.", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
accountID, _ := cmd.Flags().GetString("account_id") | ||
account, _, err := gerritMod.Instance.Accounts.Get(gerritMod.Context, accountID) | ||
if err != nil { | ||
fmt.Printf("❌ Unable to find the specific account: %s.\n %v", accountID, err) | ||
os.Exit(1) | ||
} | ||
fmt.Printf("✅ Account AccountID: %d.\n", account.Raw.AccountID) | ||
if Verbose { | ||
if out, err := ToIndentJSON(*account.Raw); err != nil { | ||
fmt.Println(err) | ||
} else { | ||
fmt.Printf("%+v\n", out) | ||
} | ||
} | ||
}, | ||
} | ||
|
||
var accountCreate = &cobra.Command{ | ||
Use: "create", | ||
Short: "Create a new account.", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
email, _ := cmd.Flags().GetString("email") | ||
username, _ := cmd.Flags().GetString("username") | ||
input := gerrit.AccountInput{ | ||
Email: email, | ||
Username: username, | ||
} | ||
if _, _, err := gerritMod.Instance.Accounts.Create(gerritMod.Context, username, &input); err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
fmt.Printf("✅ Create new account,Email: %s.\n", email) | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(account) | ||
|
||
account.AddCommand(accountList) | ||
accountList.Flags().IntP("limit", "l", 25, "Limit the number of accounts returned.") | ||
accountList.Flags().IntP("start", "s", 0, "Skip the first N accounts.") | ||
accountList.Flags().StringSliceP("additional_fields", "f", []string{}, "Additional fields to be returned.") | ||
|
||
account.AddCommand(accountGet) | ||
accountGet.Flags().StringP("account_id", "a", "", "The account ID.") | ||
accountGet.MarkFlagRequired("account_id") | ||
|
||
account.AddCommand(accountCreate) | ||
accountCreate.Flags().StringP("email", "e", "", "The email address of the new account.") | ||
accountCreate.Flags().StringP("username", "u", "", "The username of the new account.") | ||
accountCreate.MarkFlagRequired("email") | ||
accountCreate.MarkFlagRequired("username") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"github.com/shijl0925/go-gerrit" | ||
"github.com/spf13/cobra" | ||
"os" | ||
) | ||
|
||
// Change Commands | ||
var change = &cobra.Command{ | ||
Use: "change", | ||
Short: "change related commands", | ||
} | ||
|
||
var changeQuery = &cobra.Command{ | ||
Use: "query", | ||
Short: "Query changes.", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
Limit, _ := cmd.Flags().GetInt("limit") | ||
Start, _ := cmd.Flags().GetInt("start") | ||
Query, _ := cmd.Flags().GetStringSlice("query") | ||
AdditionalFields, _ := cmd.Flags().GetStringSlice("additional_fields") | ||
|
||
option := gerrit.QueryChangeOptions{} | ||
option.Start = Start | ||
option.Limit = Limit | ||
|
||
option.Query = Query | ||
option.AdditionalFields = AdditionalFields | ||
|
||
changes, _, err := gerritMod.Instance.Changes.Query(gerritMod.Context, &option) | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
|
||
for _, change := range *changes { | ||
fmt.Printf("✅ Change ChangeID: %s.\n", change.ID) | ||
if Verbose { | ||
if out, err := ToIndentJSON(change); err != nil { | ||
fmt.Println(err) | ||
} else { | ||
fmt.Printf("%+v\n", out) | ||
} | ||
} | ||
} | ||
}, | ||
} | ||
|
||
var changeCreate = &cobra.Command{ | ||
Use: "create", | ||
Short: "Create a new change.", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
projectName, _ := cmd.Flags().GetString("project_name") | ||
branchName, _ := cmd.Flags().GetString("branch_name") | ||
subject, _ := cmd.Flags().GetString("subject") | ||
input := gerrit.ChangeInput{ | ||
Project: projectName, | ||
Branch: branchName, | ||
Subject: subject, | ||
} | ||
if change, _, err := gerritMod.Instance.Changes.Create(gerritMod.Context, &input); err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} else { | ||
fmt.Printf("✅ Create new change,ChangeID: %s.\n", change.Raw.ID) | ||
if Verbose { | ||
if out, err := ToIndentJSON(change); err != nil { | ||
fmt.Println(err) | ||
} else { | ||
fmt.Printf("%+v\n", out) | ||
} | ||
} | ||
} | ||
}, | ||
} | ||
|
||
var changeGet = &cobra.Command{ | ||
Use: "show", | ||
Short: "Retrieve a change.", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
changeID, _ := cmd.Flags().GetString("change_id") | ||
change, _, err := gerritMod.Instance.Changes.Get(gerritMod.Context, changeID) | ||
if err != nil { | ||
fmt.Printf("❌ Unable to find the specific change: %s.\n %v", changeID, err) | ||
} | ||
fmt.Printf("✅ Change ChangeID: %s.\n", change.Raw.ID) | ||
if Verbose { | ||
if out, err := ToIndentJSON(change); err != nil { | ||
fmt.Println(err) | ||
} else { | ||
fmt.Printf("%+v\n", out) | ||
} | ||
} | ||
}, | ||
} | ||
|
||
var changeDelete = &cobra.Command{ | ||
Use: "delete", | ||
Short: "Delete a change.", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
changeID, _ := cmd.Flags().GetString("change_id") | ||
if _, _, err := gerritMod.Instance.Changes.Delete(gerritMod.Context, changeID); err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
fmt.Printf("✅ Delete change,ChangeID: %s.\n", changeID) | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(change) | ||
|
||
change.AddCommand(changeQuery) | ||
changeQuery.Flags().IntP("limit", "l", 25, "limit") | ||
changeQuery.Flags().IntP("start", "s", 0, "start") | ||
changeQuery.Flags().StringSliceP("query", "q", []string{"is:open"}, "query") | ||
changeQuery.Flags().StringSliceP("additional_fields", "a", []string{}, "additional fields") | ||
|
||
change.AddCommand(changeCreate) | ||
changeCreate.Flags().StringP("project_name", "p", "", "project name") | ||
changeCreate.Flags().StringP("branch_name", "b", "", "branch name") | ||
changeCreate.Flags().StringP("subject", "s", "", "subject") | ||
changeCreate.MarkFlagRequired("project_name") | ||
changeCreate.MarkFlagRequired("branch_name") | ||
changeCreate.MarkFlagRequired("subject") | ||
|
||
change.AddCommand(changeGet) | ||
changeGet.Flags().StringP("change_id", "c", "", "change id") | ||
changeGet.MarkFlagRequired("change_id") | ||
|
||
change.AddCommand(changeDelete) | ||
changeDelete.Flags().StringP("change_id", "c", "", "change id") | ||
changeDelete.MarkFlagRequired("change_id") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"github.com/shijl0925/go-gerrit" | ||
"github.com/spf13/cobra" | ||
"os" | ||
) | ||
|
||
// Group Commands | ||
var group = &cobra.Command{ | ||
Use: "group", | ||
Short: "group related commands", | ||
} | ||
|
||
var groupList = &cobra.Command{ | ||
Use: "list", | ||
Short: "List the groups.", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
Limit, _ := cmd.Flags().GetInt("limit") | ||
Skip, _ := cmd.Flags().GetInt("skip") | ||
|
||
option := gerrit.ListGroupsOptions{} | ||
option.Skip = Skip | ||
option.Limit = Limit | ||
|
||
groups, _, err := gerritMod.Instance.Groups.List(gerritMod.Context, &option) | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
for name, group := range groups { | ||
fmt.Printf("✅ Group Name: %s, GroupID: %d.\n", name, group.GroupID) | ||
if Verbose { | ||
if out, err := ToIndentJSON(group); err != nil { | ||
fmt.Println(err) | ||
} else { | ||
fmt.Printf("%+v\n", out) | ||
} | ||
} | ||
} | ||
}, | ||
} | ||
|
||
var groupCreate = &cobra.Command{ | ||
Use: "create", | ||
Short: "Create a new group.", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
groupName, _ := cmd.Flags().GetString("name") | ||
input := gerrit.GroupInput{ | ||
Name: groupName, | ||
} | ||
if _, _, err := gerritMod.Instance.Groups.Create(gerritMod.Context, groupName, &input); err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
fmt.Printf("✅ Create new group,Name: %s.\n", groupName) | ||
}, | ||
} | ||
|
||
var groupGet = &cobra.Command{ | ||
Use: "show", | ||
Short: "Retrieve the group.", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
groupID, _ := cmd.Flags().GetString("group_id") | ||
group, _, err := gerritMod.Instance.Groups.Get(gerritMod.Context, groupID) | ||
if err != nil { | ||
fmt.Printf("❌ Unable to find the specific group: %s.\n %v", groupID, err) | ||
} | ||
fmt.Printf("✅ Group GroupID: %d.\n", group.Raw.GroupID) | ||
if Verbose { | ||
if out, err := ToIndentJSON(*group.Raw); err != nil { | ||
fmt.Println(err) | ||
} else { | ||
fmt.Printf("%+v\n", out) | ||
} | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(group) | ||
|
||
group.AddCommand(groupList) | ||
groupList.Flags().IntP("limit", "l", 25, "limit") | ||
groupList.Flags().IntP("skip", "s", 0, "skip") | ||
|
||
group.AddCommand(groupCreate) | ||
groupCreate.Flags().StringP("name", "n", "", "group name") | ||
groupCreate.MarkFlagRequired("name") | ||
|
||
group.AddCommand(groupGet) | ||
groupGet.Flags().StringP("group_id", "g", "", "group id") | ||
groupGet.MarkFlagRequired("group_id") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters