diff --git a/api/issue.go b/api/issue.go index 7e012556af26b645d028fb9debe03b793d3a9d6a..0e19c3b19cf0c6a97cc8f2f9d370cf0fcfd08eff 100644 --- a/api/issue.go +++ b/api/issue.go @@ -129,6 +129,19 @@ var DeleteIssue = func(client *gitlab.Client, projectID interface{}, issueID int return nil } +var CreateIssueAwardEmoji = func(client *gitlab.Client, projectID interface{}, mrID int, opts *gitlab.CreateAwardEmojiOptions) (*gitlab.AwardEmoji, error) { + if client == nil { + client = apiClient.Lab() + } + + emoji, _, err := client.AwardEmoji.CreateIssueAwardEmoji(projectID, mrID, opts) + if err != nil { + return emoji, err + } + + return emoji, nil +} + var CreateIssueNote = func(client *gitlab.Client, projectID interface{}, mrID int, opts *gitlab.CreateIssueNoteOptions) (*gitlab.Note, error) { if client == nil { client = apiClient.Lab() diff --git a/api/merge_request.go b/api/merge_request.go index 41e4fdf7c7e3236800e12c8eb6f322edfd9d0674..4aacc4e5a025a024774740203541928ee4cb86ef 100644 --- a/api/merge_request.go +++ b/api/merge_request.go @@ -190,6 +190,19 @@ var GetMRLinkedIssues = func(client *gitlab.Client, projectID interface{}, mrID return mrIssues, nil } +var CreateMRAwardEmoji = func(client *gitlab.Client, projectID interface{}, mrID int, opts *gitlab.CreateAwardEmojiOptions) (*gitlab.AwardEmoji, error) { + if client == nil { + client = apiClient.Lab() + } + + emoji, _, err := client.AwardEmoji.CreateMergeRequestAwardEmoji(projectID, mrID, opts) + if err != nil { + return emoji, err + } + + return emoji, nil +} + var CreateMRNote = func(client *gitlab.Client, projectID interface{}, mrID int, opts *gitlab.CreateMergeRequestNoteOptions) (*gitlab.Note, error) { if client == nil { client = apiClient.Lab() diff --git a/commands/issue/award-emoji/issue_award-emoji_create.go b/commands/issue/award-emoji/issue_award-emoji_create.go new file mode 100644 index 0000000000000000000000000000000000000000..78fefcd9d47652fd2ff67ed910496514a3167420 --- /dev/null +++ b/commands/issue/award-emoji/issue_award-emoji_create.go @@ -0,0 +1,66 @@ +package award_emoji + +import ( + "errors" + "fmt" + + "gitlab.com/gitlab-org/cli/commands/issue/issueutils" + + "gitlab.com/gitlab-org/cli/api" + "gitlab.com/gitlab-org/cli/commands/cmdutils" + "gitlab.com/gitlab-org/cli/pkg/utils" + + "github.com/spf13/cobra" + gitlab "github.com/xanzy/go-gitlab" +) + +func NewCmdAwardEmoji(f *cmdutils.Factory) *cobra.Command { + issueAwardEmojiCreateCmd := &cobra.Command{ + Use: "award-emoji ", + Aliases: []string{"comment"}, + Short: "Award an emoji to an issue on GitLab", + Long: ``, + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + var err error + out := f.IO.StdOut + + apiClient, err := f.HttpClient() + if err != nil { + return err + } + + issue, repo, err := issueutils.IssueFromArg(apiClient, f.BaseRepo, args[0]) + if err != nil { + return err + } + + name, _ := cmd.Flags().GetString("name") + + if name == "" { + name = utils.Editor(utils.EditorOptions{ + Label: "Award Emoji Name:", + Help: "Enter the award emoji's name. ", + FileName: "ISSUE_AWARD_EMOJI_EDITMSG", + }) + } + + if name == "" { + return errors.New("aborted... Award Emoji name is empty") + } + + emoji, err := api.CreateIssueAwardEmoji(apiClient, repo.FullName(), issue.IID, &gitlab.CreateAwardEmojiOptions{ + Name: name, + }) + if err != nil { + return err + } + + fmt.Fprintf(out, "Added award emoji %d\n", emoji.AwardableID) + return nil + }, + } + issueAwardEmojiCreateCmd.Flags().StringP("name", "n", "", "Award Emoji name") + + return issueAwardEmojiCreateCmd +} diff --git a/commands/issue/issue.go b/commands/issue/issue.go index 3ab5002cf5177d7d863eec009cf90106cf1fba13..cbeffc245d084c0d1f585f2bc45904ffb7369726 100644 --- a/commands/issue/issue.go +++ b/commands/issue/issue.go @@ -3,6 +3,7 @@ package issue import ( "github.com/MakeNowJust/heredoc" "gitlab.com/gitlab-org/cli/commands/cmdutils" + issueAwardEmojiCmd "gitlab.com/gitlab-org/cli/commands/issue/award-emoji" issueBoardCmd "gitlab.com/gitlab-org/cli/commands/issue/board" issueCloseCmd "gitlab.com/gitlab-org/cli/commands/issue/close" issueCreateCmd "gitlab.com/gitlab-org/cli/commands/issue/create" @@ -40,6 +41,7 @@ func NewCmdIssue(f *cmdutils.Factory) *cobra.Command { cmdutils.EnableRepoOverride(issueCmd, f) + issueCmd.AddCommand(issueAwardEmojiCmd.NewCmdAwardEmoji(f)) issueCmd.AddCommand(issueCloseCmd.NewCmdClose(f)) issueCmd.AddCommand(issueBoardCmd.NewCmdBoard(f)) issueCmd.AddCommand(issueCreateCmd.NewCmdCreate(f)) diff --git a/commands/mr/award-emoji/mr_award-emoji_create.go b/commands/mr/award-emoji/mr_award-emoji_create.go new file mode 100644 index 0000000000000000000000000000000000000000..5a3e6c41c90b28e267b691c94e756495d1532eb6 --- /dev/null +++ b/commands/mr/award-emoji/mr_award-emoji_create.go @@ -0,0 +1,66 @@ +package award_emoji + +import ( + "errors" + "fmt" + + "gitlab.com/gitlab-org/cli/commands/mr/mrutils" + + "gitlab.com/gitlab-org/cli/api" + "gitlab.com/gitlab-org/cli/commands/cmdutils" + "gitlab.com/gitlab-org/cli/pkg/utils" + + "github.com/spf13/cobra" + gitlab "github.com/xanzy/go-gitlab" +) + +func NewCmdAwardEmoji(f *cmdutils.Factory) *cobra.Command { + mrAwardEmojiCreateCmd := &cobra.Command{ + Use: "award-emoji ", + Aliases: []string{"comment"}, + Short: "Award an emoji to an merge request on GitLab", + Long: ``, + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + var err error + out := f.IO.StdOut + + apiClient, err := f.HttpClient() + if err != nil { + return err + } + + mr, repo, err := mrutils.MRFromArgs(f, args, "any") + if err != nil { + return err + } + + name, _ := cmd.Flags().GetString("name") + + if name == "" { + name = utils.Editor(utils.EditorOptions{ + Label: "Award Emoji Name:", + Help: "Enter the award emoji's name. ", + FileName: "MR_AWARD_EMOJI_EDITMSG", + }) + } + + if name == "" { + return errors.New("aborted... Award Emoji name is empty") + } + + emoji, err := api.CreateMRAwardEmoji(apiClient, repo.FullName(), mr.IID, &gitlab.CreateAwardEmojiOptions{ + Name: name, + }) + if err != nil { + return err + } + + fmt.Fprintf(out, "Added award emoji %d\n", emoji.AwardableID) + return nil + }, + } + mrAwardEmojiCreateCmd.Flags().StringP("name", "n", "", "Award Emoji name") + + return mrAwardEmojiCreateCmd +} diff --git a/commands/mr/mr.go b/commands/mr/mr.go index a0656b0bc6f49130220e0fbf9a2a913c8d985728..dde881eb3a57acb4d455e1c665ab20eb5c7f1923 100644 --- a/commands/mr/mr.go +++ b/commands/mr/mr.go @@ -5,6 +5,7 @@ import ( "gitlab.com/gitlab-org/cli/commands/cmdutils" mrApproveCmd "gitlab.com/gitlab-org/cli/commands/mr/approve" mrApproversCmd "gitlab.com/gitlab-org/cli/commands/mr/approvers" + mrAwardEmojiCmd "gitlab.com/gitlab-org/cli/commands/mr/award-emoji" mrCheckoutCmd "gitlab.com/gitlab-org/cli/commands/mr/checkout" mrCloseCmd "gitlab.com/gitlab-org/cli/commands/mr/close" mrCreateCmd "gitlab.com/gitlab-org/cli/commands/mr/create" @@ -50,6 +51,7 @@ func NewCmdMR(f *cmdutils.Factory) *cobra.Command { mrCmd.AddCommand(mrApproveCmd.NewCmdApprove(f)) mrCmd.AddCommand(mrApproversCmd.NewCmdApprovers(f)) + mrCmd.AddCommand(mrAwardEmojiCmd.NewCmdAwardEmoji(f)) mrCmd.AddCommand(mrCheckoutCmd.NewCmdCheckout(f)) mrCmd.AddCommand(mrCloseCmd.NewCmdClose(f)) mrCmd.AddCommand(mrCreateCmd.NewCmdCreate(f, nil))