From a7d7c529254063ed2d26f37fd22ff8c490625451 Mon Sep 17 00:00:00 2001 From: Kai Armstrong Date: Sun, 2 Jun 2024 13:12:22 -0500 Subject: [PATCH 01/20] feat: add linked-issues option to issue update --- commands/issue/update/issue_update.go | 41 +++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/commands/issue/update/issue_update.go b/commands/issue/update/issue_update.go index 3ff0f927b..495f65ff1 100644 --- a/commands/issue/update/issue_update.go +++ b/commands/issue/update/issue_update.go @@ -3,18 +3,32 @@ package update import ( "errors" "fmt" + "strconv" "strings" + "gitlab.com/gitlab-org/cli/pkg/iostreams" + "gitlab.com/gitlab-org/cli/api" "gitlab.com/gitlab-org/cli/commands/cmdutils" "gitlab.com/gitlab-org/cli/commands/issue/issueutils" + "gitlab.com/gitlab-org/cli/internal/glrepo" "github.com/MakeNowJust/heredoc/v2" "github.com/spf13/cobra" "github.com/xanzy/go-gitlab" ) +type LinkIssueOpts struct { + LinkedIssues []int `json:"linked_issues,omitempty"` + IssueLinkType string `json:"issue_link_type,omitempty"` + + IO *iostreams.IOStreams `json:"-"` +} + func NewCmdUpdate(f *cmdutils.Factory) *cobra.Command { + opts := &LinkIssueOpts{ + IO: f.IO, + } issueUpdateCmd := &cobra.Command{ Use: "update ", Short: `Update issue`, @@ -165,6 +179,14 @@ func NewCmdUpdate(f *cmdutils.Factory) *cobra.Command { fmt.Fprintf(out, "- Updating issue #%d\n", issue.IID) + // If the linked-issues flag is passed call to update LinkedIssues + if len(opts.LinkedIssues) > 0 { + err = linkedIssueUpdate(apiClient, issue, opts, repo) + if err != nil { + return err + } + } + issue, err = api.UpdateIssue(apiClient, repo.FullName(), issue.IID, l) if err != nil { return err @@ -191,6 +213,25 @@ func NewCmdUpdate(f *cmdutils.Factory) *cobra.Command { issueUpdateCmd.Flags(). StringSliceP("assignee", "a", []string{}, "assign users via username, prefix with '!' or '-' to remove from existing assignees, '+' to add, otherwise replace existing assignees with given users") issueUpdateCmd.Flags().Bool("unassign", false, "unassign all users") + issueUpdateCmd.Flags().IntSliceVarP(&opts.LinkedIssues, "linked-issues", "", []int{}, "The IIDs of issues that this issue links to") + issueUpdateCmd.Flags().StringVarP(&opts.IssueLinkType, "link-type", "", "relates_to", "Type for the issue link") return issueUpdateCmd } + +func linkedIssueUpdate(apiClient *gitlab.Client, issue *gitlab.Issue, opts *LinkIssueOpts, repo glrepo.Interface) error { + if len(opts.LinkedIssues) > 0 { + var err error + for _, targetIssueIID := range opts.LinkedIssues { + fmt.Fprintln(opts.IO.StdErr, "- Linking to issue ", targetIssueIID) + issue, _, err = api.LinkIssues(apiClient, repo.FullName(), issue.IID, &gitlab.CreateIssueLinkOptions{ + TargetIssueIID: gitlab.Ptr(strconv.Itoa(targetIssueIID)), + LinkType: gitlab.Ptr(opts.IssueLinkType), + }) + if err != nil { + return err + } + } + } + return nil +} -- GitLab From 4f139b8df7eb1e561dea847ef9fa418a38bc5e30 Mon Sep 17 00:00:00 2001 From: Kai Armstrong Date: Tue, 11 Jun 2024 17:12:40 -0500 Subject: [PATCH 02/20] broken --- commands/issue/create/issue_create.go | 13 +++-------- commands/issue/issueutils/utils.go | 22 ++++++++++++++++++ commands/issue/update/issue_update.go | 32 ++------------------------- 3 files changed, 27 insertions(+), 40 deletions(-) diff --git a/commands/issue/create/issue_create.go b/commands/issue/create/issue_create.go index b45075267..98957f3dc 100644 --- a/commands/issue/create/issue_create.go +++ b/commands/issue/create/issue_create.go @@ -5,7 +5,6 @@ import ( "fmt" "net/url" "os" - "strconv" "strings" "gitlab.com/gitlab-org/cli/pkg/iostreams" @@ -397,15 +396,9 @@ func createRun(opts *CreateOpts) error { func postCreateActions(apiClient *gitlab.Client, issue *gitlab.Issue, opts *CreateOpts, repo glrepo.Interface) error { if len(opts.LinkedIssues) > 0 { var err error - for _, targetIssueIID := range opts.LinkedIssues { - fmt.Fprintln(opts.IO.StdErr, "- Linking to issue ", targetIssueIID) - issue, _, err = api.LinkIssues(apiClient, repo.FullName(), issue.IID, &gitlab.CreateIssueLinkOptions{ - TargetIssueIID: gitlab.Ptr(strconv.Itoa(targetIssueIID)), - LinkType: gitlab.Ptr(opts.IssueLinkType), - }) - if err != nil { - return err - } + err = issueutils.linkIssues(apiClient, issue, opts, repo) + if err != nil { + return err } } if opts.TimeEstimate != "" { diff --git a/commands/issue/issueutils/utils.go b/commands/issue/issueutils/utils.go index d5891cf09..0ad7790e2 100644 --- a/commands/issue/issueutils/utils.go +++ b/commands/issue/issueutils/utils.go @@ -21,6 +21,13 @@ import ( "github.com/xanzy/go-gitlab" ) +type LinkIssueOpts struct { + LinkedIssues []int `json:"linked_issues,omitempty"` + IssueLinkType string `json:"issue_link_type,omitempty"` + + IO *iostreams.IOStreams `json:"-"` +} + func DisplayIssueList(streams *iostreams.IOStreams, issues []*gitlab.Issue, projectID string) string { c := streams.Color() table := tableprinter.NewTablePrinter() @@ -180,3 +187,18 @@ func issueMetadataFromURL(s string) (int, glrepo.Interface) { func issueFromIID(apiClient *gitlab.Client, repo glrepo.Interface, issueIID int) (*gitlab.Issue, error) { return api.GetIssue(apiClient, repo.FullName(), issueIID) } + +func linkIssues(apiClient *gitlab.Client, issue *gitlab.Issue, opts LinkIssueOpts, repo glrepo.Interface) error { + var err error + for _, targetIssueIID := range opts.LinkedIssues { + fmt.Fprintln(opts.IO.StdErr, "- Linking to issue ", targetIssueIID) + issue, _, err = api.LinkIssues(apiClient, repo.FullName(), issue.IID, &gitlab.CreateIssueLinkOptions{ + TargetIssueIID: gitlab.Ptr(strconv.Itoa(targetIssueIID)), + LinkType: gitlab.Ptr(opts.IssueLinkType), + }) + if err != nil { + return err + } + } + return nil +} diff --git a/commands/issue/update/issue_update.go b/commands/issue/update/issue_update.go index 495f65ff1..d361ce2f0 100644 --- a/commands/issue/update/issue_update.go +++ b/commands/issue/update/issue_update.go @@ -3,30 +3,19 @@ package update import ( "errors" "fmt" - "strconv" "strings" - "gitlab.com/gitlab-org/cli/pkg/iostreams" - "gitlab.com/gitlab-org/cli/api" "gitlab.com/gitlab-org/cli/commands/cmdutils" "gitlab.com/gitlab-org/cli/commands/issue/issueutils" - "gitlab.com/gitlab-org/cli/internal/glrepo" "github.com/MakeNowJust/heredoc/v2" "github.com/spf13/cobra" "github.com/xanzy/go-gitlab" ) -type LinkIssueOpts struct { - LinkedIssues []int `json:"linked_issues,omitempty"` - IssueLinkType string `json:"issue_link_type,omitempty"` - - IO *iostreams.IOStreams `json:"-"` -} - func NewCmdUpdate(f *cmdutils.Factory) *cobra.Command { - opts := &LinkIssueOpts{ + opts := issueutils.LinkIssueOpts{ IO: f.IO, } issueUpdateCmd := &cobra.Command{ @@ -181,7 +170,7 @@ func NewCmdUpdate(f *cmdutils.Factory) *cobra.Command { // If the linked-issues flag is passed call to update LinkedIssues if len(opts.LinkedIssues) > 0 { - err = linkedIssueUpdate(apiClient, issue, opts, repo) + err = issueutils.linkIssues(apiClient, issue, opts, repo) if err != nil { return err } @@ -218,20 +207,3 @@ func NewCmdUpdate(f *cmdutils.Factory) *cobra.Command { return issueUpdateCmd } - -func linkedIssueUpdate(apiClient *gitlab.Client, issue *gitlab.Issue, opts *LinkIssueOpts, repo glrepo.Interface) error { - if len(opts.LinkedIssues) > 0 { - var err error - for _, targetIssueIID := range opts.LinkedIssues { - fmt.Fprintln(opts.IO.StdErr, "- Linking to issue ", targetIssueIID) - issue, _, err = api.LinkIssues(apiClient, repo.FullName(), issue.IID, &gitlab.CreateIssueLinkOptions{ - TargetIssueIID: gitlab.Ptr(strconv.Itoa(targetIssueIID)), - LinkType: gitlab.Ptr(opts.IssueLinkType), - }) - if err != nil { - return err - } - } - } - return nil -} -- GitLab From 87f9ae0cb9354c8d4a47bad86799e48f390ee024 Mon Sep 17 00:00:00 2001 From: Kai Armstrong Date: Sun, 2 Jun 2024 13:12:22 -0500 Subject: [PATCH 03/20] feat: add linked-issues option to issue update --- commands/issue/update/issue_update.go | 41 +++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/commands/issue/update/issue_update.go b/commands/issue/update/issue_update.go index 3ff0f927b..495f65ff1 100644 --- a/commands/issue/update/issue_update.go +++ b/commands/issue/update/issue_update.go @@ -3,18 +3,32 @@ package update import ( "errors" "fmt" + "strconv" "strings" + "gitlab.com/gitlab-org/cli/pkg/iostreams" + "gitlab.com/gitlab-org/cli/api" "gitlab.com/gitlab-org/cli/commands/cmdutils" "gitlab.com/gitlab-org/cli/commands/issue/issueutils" + "gitlab.com/gitlab-org/cli/internal/glrepo" "github.com/MakeNowJust/heredoc/v2" "github.com/spf13/cobra" "github.com/xanzy/go-gitlab" ) +type LinkIssueOpts struct { + LinkedIssues []int `json:"linked_issues,omitempty"` + IssueLinkType string `json:"issue_link_type,omitempty"` + + IO *iostreams.IOStreams `json:"-"` +} + func NewCmdUpdate(f *cmdutils.Factory) *cobra.Command { + opts := &LinkIssueOpts{ + IO: f.IO, + } issueUpdateCmd := &cobra.Command{ Use: "update ", Short: `Update issue`, @@ -165,6 +179,14 @@ func NewCmdUpdate(f *cmdutils.Factory) *cobra.Command { fmt.Fprintf(out, "- Updating issue #%d\n", issue.IID) + // If the linked-issues flag is passed call to update LinkedIssues + if len(opts.LinkedIssues) > 0 { + err = linkedIssueUpdate(apiClient, issue, opts, repo) + if err != nil { + return err + } + } + issue, err = api.UpdateIssue(apiClient, repo.FullName(), issue.IID, l) if err != nil { return err @@ -191,6 +213,25 @@ func NewCmdUpdate(f *cmdutils.Factory) *cobra.Command { issueUpdateCmd.Flags(). StringSliceP("assignee", "a", []string{}, "assign users via username, prefix with '!' or '-' to remove from existing assignees, '+' to add, otherwise replace existing assignees with given users") issueUpdateCmd.Flags().Bool("unassign", false, "unassign all users") + issueUpdateCmd.Flags().IntSliceVarP(&opts.LinkedIssues, "linked-issues", "", []int{}, "The IIDs of issues that this issue links to") + issueUpdateCmd.Flags().StringVarP(&opts.IssueLinkType, "link-type", "", "relates_to", "Type for the issue link") return issueUpdateCmd } + +func linkedIssueUpdate(apiClient *gitlab.Client, issue *gitlab.Issue, opts *LinkIssueOpts, repo glrepo.Interface) error { + if len(opts.LinkedIssues) > 0 { + var err error + for _, targetIssueIID := range opts.LinkedIssues { + fmt.Fprintln(opts.IO.StdErr, "- Linking to issue ", targetIssueIID) + issue, _, err = api.LinkIssues(apiClient, repo.FullName(), issue.IID, &gitlab.CreateIssueLinkOptions{ + TargetIssueIID: gitlab.Ptr(strconv.Itoa(targetIssueIID)), + LinkType: gitlab.Ptr(opts.IssueLinkType), + }) + if err != nil { + return err + } + } + } + return nil +} -- GitLab From d3dacfcff859d5f64aefd1514dfd7807ea7917e3 Mon Sep 17 00:00:00 2001 From: Kai Armstrong Date: Tue, 11 Jun 2024 17:12:40 -0500 Subject: [PATCH 04/20] broken --- commands/issue/create/issue_create.go | 13 +++-------- commands/issue/issueutils/utils.go | 22 ++++++++++++++++++ commands/issue/update/issue_update.go | 32 ++------------------------- 3 files changed, 27 insertions(+), 40 deletions(-) diff --git a/commands/issue/create/issue_create.go b/commands/issue/create/issue_create.go index b45075267..98957f3dc 100644 --- a/commands/issue/create/issue_create.go +++ b/commands/issue/create/issue_create.go @@ -5,7 +5,6 @@ import ( "fmt" "net/url" "os" - "strconv" "strings" "gitlab.com/gitlab-org/cli/pkg/iostreams" @@ -397,15 +396,9 @@ func createRun(opts *CreateOpts) error { func postCreateActions(apiClient *gitlab.Client, issue *gitlab.Issue, opts *CreateOpts, repo glrepo.Interface) error { if len(opts.LinkedIssues) > 0 { var err error - for _, targetIssueIID := range opts.LinkedIssues { - fmt.Fprintln(opts.IO.StdErr, "- Linking to issue ", targetIssueIID) - issue, _, err = api.LinkIssues(apiClient, repo.FullName(), issue.IID, &gitlab.CreateIssueLinkOptions{ - TargetIssueIID: gitlab.Ptr(strconv.Itoa(targetIssueIID)), - LinkType: gitlab.Ptr(opts.IssueLinkType), - }) - if err != nil { - return err - } + err = issueutils.linkIssues(apiClient, issue, opts, repo) + if err != nil { + return err } } if opts.TimeEstimate != "" { diff --git a/commands/issue/issueutils/utils.go b/commands/issue/issueutils/utils.go index d5891cf09..0ad7790e2 100644 --- a/commands/issue/issueutils/utils.go +++ b/commands/issue/issueutils/utils.go @@ -21,6 +21,13 @@ import ( "github.com/xanzy/go-gitlab" ) +type LinkIssueOpts struct { + LinkedIssues []int `json:"linked_issues,omitempty"` + IssueLinkType string `json:"issue_link_type,omitempty"` + + IO *iostreams.IOStreams `json:"-"` +} + func DisplayIssueList(streams *iostreams.IOStreams, issues []*gitlab.Issue, projectID string) string { c := streams.Color() table := tableprinter.NewTablePrinter() @@ -180,3 +187,18 @@ func issueMetadataFromURL(s string) (int, glrepo.Interface) { func issueFromIID(apiClient *gitlab.Client, repo glrepo.Interface, issueIID int) (*gitlab.Issue, error) { return api.GetIssue(apiClient, repo.FullName(), issueIID) } + +func linkIssues(apiClient *gitlab.Client, issue *gitlab.Issue, opts LinkIssueOpts, repo glrepo.Interface) error { + var err error + for _, targetIssueIID := range opts.LinkedIssues { + fmt.Fprintln(opts.IO.StdErr, "- Linking to issue ", targetIssueIID) + issue, _, err = api.LinkIssues(apiClient, repo.FullName(), issue.IID, &gitlab.CreateIssueLinkOptions{ + TargetIssueIID: gitlab.Ptr(strconv.Itoa(targetIssueIID)), + LinkType: gitlab.Ptr(opts.IssueLinkType), + }) + if err != nil { + return err + } + } + return nil +} diff --git a/commands/issue/update/issue_update.go b/commands/issue/update/issue_update.go index 495f65ff1..d361ce2f0 100644 --- a/commands/issue/update/issue_update.go +++ b/commands/issue/update/issue_update.go @@ -3,30 +3,19 @@ package update import ( "errors" "fmt" - "strconv" "strings" - "gitlab.com/gitlab-org/cli/pkg/iostreams" - "gitlab.com/gitlab-org/cli/api" "gitlab.com/gitlab-org/cli/commands/cmdutils" "gitlab.com/gitlab-org/cli/commands/issue/issueutils" - "gitlab.com/gitlab-org/cli/internal/glrepo" "github.com/MakeNowJust/heredoc/v2" "github.com/spf13/cobra" "github.com/xanzy/go-gitlab" ) -type LinkIssueOpts struct { - LinkedIssues []int `json:"linked_issues,omitempty"` - IssueLinkType string `json:"issue_link_type,omitempty"` - - IO *iostreams.IOStreams `json:"-"` -} - func NewCmdUpdate(f *cmdutils.Factory) *cobra.Command { - opts := &LinkIssueOpts{ + opts := issueutils.LinkIssueOpts{ IO: f.IO, } issueUpdateCmd := &cobra.Command{ @@ -181,7 +170,7 @@ func NewCmdUpdate(f *cmdutils.Factory) *cobra.Command { // If the linked-issues flag is passed call to update LinkedIssues if len(opts.LinkedIssues) > 0 { - err = linkedIssueUpdate(apiClient, issue, opts, repo) + err = issueutils.linkIssues(apiClient, issue, opts, repo) if err != nil { return err } @@ -218,20 +207,3 @@ func NewCmdUpdate(f *cmdutils.Factory) *cobra.Command { return issueUpdateCmd } - -func linkedIssueUpdate(apiClient *gitlab.Client, issue *gitlab.Issue, opts *LinkIssueOpts, repo glrepo.Interface) error { - if len(opts.LinkedIssues) > 0 { - var err error - for _, targetIssueIID := range opts.LinkedIssues { - fmt.Fprintln(opts.IO.StdErr, "- Linking to issue ", targetIssueIID) - issue, _, err = api.LinkIssues(apiClient, repo.FullName(), issue.IID, &gitlab.CreateIssueLinkOptions{ - TargetIssueIID: gitlab.Ptr(strconv.Itoa(targetIssueIID)), - LinkType: gitlab.Ptr(opts.IssueLinkType), - }) - if err != nil { - return err - } - } - } - return nil -} -- GitLab From e8fc5bee0961b3b988f4fe90599ecd59631e3d88 Mon Sep 17 00:00:00 2001 From: Kai Armstrong Date: Wed, 26 Jun 2024 12:29:08 -0500 Subject: [PATCH 05/20] Export function name --- commands/issue/create/issue_create.go | 2 +- commands/issue/issueutils/utils.go | 2 +- commands/issue/update/issue_update.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/commands/issue/create/issue_create.go b/commands/issue/create/issue_create.go index 98957f3dc..7f9e4138e 100644 --- a/commands/issue/create/issue_create.go +++ b/commands/issue/create/issue_create.go @@ -396,7 +396,7 @@ func createRun(opts *CreateOpts) error { func postCreateActions(apiClient *gitlab.Client, issue *gitlab.Issue, opts *CreateOpts, repo glrepo.Interface) error { if len(opts.LinkedIssues) > 0 { var err error - err = issueutils.linkIssues(apiClient, issue, opts, repo) + err = issueutils.LinkIssues(apiClient, issue, opts, repo) if err != nil { return err } diff --git a/commands/issue/issueutils/utils.go b/commands/issue/issueutils/utils.go index 0ad7790e2..59751c2d9 100644 --- a/commands/issue/issueutils/utils.go +++ b/commands/issue/issueutils/utils.go @@ -188,7 +188,7 @@ func issueFromIID(apiClient *gitlab.Client, repo glrepo.Interface, issueIID int) return api.GetIssue(apiClient, repo.FullName(), issueIID) } -func linkIssues(apiClient *gitlab.Client, issue *gitlab.Issue, opts LinkIssueOpts, repo glrepo.Interface) error { +func LinkIssues(apiClient *gitlab.Client, issue *gitlab.Issue, opts LinkIssueOpts, repo glrepo.Interface) error { var err error for _, targetIssueIID := range opts.LinkedIssues { fmt.Fprintln(opts.IO.StdErr, "- Linking to issue ", targetIssueIID) diff --git a/commands/issue/update/issue_update.go b/commands/issue/update/issue_update.go index d361ce2f0..f1868c194 100644 --- a/commands/issue/update/issue_update.go +++ b/commands/issue/update/issue_update.go @@ -170,7 +170,7 @@ func NewCmdUpdate(f *cmdutils.Factory) *cobra.Command { // If the linked-issues flag is passed call to update LinkedIssues if len(opts.LinkedIssues) > 0 { - err = issueutils.linkIssues(apiClient, issue, opts, repo) + err = issueutils.LinkIssues(apiClient, issue, opts, repo) if err != nil { return err } -- GitLab From 0b139115ad00d8324c32e80ac6274d46be148f5d Mon Sep 17 00:00:00 2001 From: Kai Armstrong Date: Wed, 26 Jun 2024 16:29:51 -0500 Subject: [PATCH 06/20] sorta fixed --- commands/issue/update/issue_update.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/commands/issue/update/issue_update.go b/commands/issue/update/issue_update.go index f1868c194..6ad1a4b8e 100644 --- a/commands/issue/update/issue_update.go +++ b/commands/issue/update/issue_update.go @@ -5,6 +5,8 @@ import ( "fmt" "strings" + "gitlab.com/gitlab-org/cli/pkg/iostreams" + "gitlab.com/gitlab-org/cli/api" "gitlab.com/gitlab-org/cli/commands/cmdutils" "gitlab.com/gitlab-org/cli/commands/issue/issueutils" @@ -14,8 +16,15 @@ import ( "github.com/xanzy/go-gitlab" ) +type UpdateOpts struct { + LinkedIssues []int `json:"linked_issues,omitempty"` + IssueLinkType string `json:"issue_link_type,omitempty"` + + IO *iostreams.IOStreams `json:"-"` +} + func NewCmdUpdate(f *cmdutils.Factory) *cobra.Command { - opts := issueutils.LinkIssueOpts{ + opts := &UpdateOpts{ IO: f.IO, } issueUpdateCmd := &cobra.Command{ -- GitLab From c4e9b9161289ecfc4fc189bb4274bd071296c94f Mon Sep 17 00:00:00 2001 From: Kai Armstrong Date: Fri, 28 Jun 2024 15:44:19 -0500 Subject: [PATCH 07/20] still broken --- commands/issue/issueutils/utils.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/commands/issue/issueutils/utils.go b/commands/issue/issueutils/utils.go index 59751c2d9..25fffbefe 100644 --- a/commands/issue/issueutils/utils.go +++ b/commands/issue/issueutils/utils.go @@ -21,13 +21,6 @@ import ( "github.com/xanzy/go-gitlab" ) -type LinkIssueOpts struct { - LinkedIssues []int `json:"linked_issues,omitempty"` - IssueLinkType string `json:"issue_link_type,omitempty"` - - IO *iostreams.IOStreams `json:"-"` -} - func DisplayIssueList(streams *iostreams.IOStreams, issues []*gitlab.Issue, projectID string) string { c := streams.Color() table := tableprinter.NewTablePrinter() @@ -188,10 +181,15 @@ func issueFromIID(apiClient *gitlab.Client, repo glrepo.Interface, issueIID int) return api.GetIssue(apiClient, repo.FullName(), issueIID) } -func LinkIssues(apiClient *gitlab.Client, issue *gitlab.Issue, opts LinkIssueOpts, repo glrepo.Interface) error { +func LinkIssues(apiClient *gitlab.Client, issue *gitlab.Issue, opts interface{}, repo glrepo.Interface) error { var err error + fmt.Println(opts) + // interface format is {int[], str, byte_code} + // intefface data is {linkissue, typerelation, byte_code} + //&{[12] relates_to 0x140000ae360} + linkOpts := opts.(struct{}) for _, targetIssueIID := range opts.LinkedIssues { - fmt.Fprintln(opts.IO.StdErr, "- Linking to issue ", targetIssueIID) + //fmt.Fprintln(opts.IO.StdErr, "- Linking to issue ", targetIssueIID) issue, _, err = api.LinkIssues(apiClient, repo.FullName(), issue.IID, &gitlab.CreateIssueLinkOptions{ TargetIssueIID: gitlab.Ptr(strconv.Itoa(targetIssueIID)), LinkType: gitlab.Ptr(opts.IssueLinkType), -- GitLab From 25c730814744175ccff7dff8815cba73fb04bb1e Mon Sep 17 00:00:00 2001 From: Kai Armstrong Date: Fri, 26 Jul 2024 11:07:11 -0400 Subject: [PATCH 08/20] passing? --- commands/issue/create/issue_create.go | 2 +- commands/issue/issueutils/utils.go | 11 +++-------- commands/issue/update/issue_update.go | 21 ++++++++++++--------- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/commands/issue/create/issue_create.go b/commands/issue/create/issue_create.go index 7f9e4138e..3e3fc22fa 100644 --- a/commands/issue/create/issue_create.go +++ b/commands/issue/create/issue_create.go @@ -396,7 +396,7 @@ func createRun(opts *CreateOpts) error { func postCreateActions(apiClient *gitlab.Client, issue *gitlab.Issue, opts *CreateOpts, repo glrepo.Interface) error { if len(opts.LinkedIssues) > 0 { var err error - err = issueutils.LinkIssues(apiClient, issue, opts, repo) + err = issueutils.LinkIssues(apiClient, issue, opts.LinkedIssues, opts.IssueLinkType, repo) if err != nil { return err } diff --git a/commands/issue/issueutils/utils.go b/commands/issue/issueutils/utils.go index 25fffbefe..cca16e51f 100644 --- a/commands/issue/issueutils/utils.go +++ b/commands/issue/issueutils/utils.go @@ -181,18 +181,13 @@ func issueFromIID(apiClient *gitlab.Client, repo glrepo.Interface, issueIID int) return api.GetIssue(apiClient, repo.FullName(), issueIID) } -func LinkIssues(apiClient *gitlab.Client, issue *gitlab.Issue, opts interface{}, repo glrepo.Interface) error { +func LinkIssues(apiClient *gitlab.Client, issue *gitlab.Issue, LinkedIssues []int, IssueLinkType string, repo glrepo.Interface) error { var err error - fmt.Println(opts) - // interface format is {int[], str, byte_code} - // intefface data is {linkissue, typerelation, byte_code} - //&{[12] relates_to 0x140000ae360} - linkOpts := opts.(struct{}) - for _, targetIssueIID := range opts.LinkedIssues { + for _, targetIssueIID := range LinkedIssues { //fmt.Fprintln(opts.IO.StdErr, "- Linking to issue ", targetIssueIID) issue, _, err = api.LinkIssues(apiClient, repo.FullName(), issue.IID, &gitlab.CreateIssueLinkOptions{ TargetIssueIID: gitlab.Ptr(strconv.Itoa(targetIssueIID)), - LinkType: gitlab.Ptr(opts.IssueLinkType), + LinkType: gitlab.Ptr(IssueLinkType), }) if err != nil { return err diff --git a/commands/issue/update/issue_update.go b/commands/issue/update/issue_update.go index 6ad1a4b8e..fac617da8 100644 --- a/commands/issue/update/issue_update.go +++ b/commands/issue/update/issue_update.go @@ -16,7 +16,7 @@ import ( "github.com/xanzy/go-gitlab" ) -type UpdateOpts struct { +type LinkIssueOpts struct { LinkedIssues []int `json:"linked_issues,omitempty"` IssueLinkType string `json:"issue_link_type,omitempty"` @@ -24,7 +24,7 @@ type UpdateOpts struct { } func NewCmdUpdate(f *cmdutils.Factory) *cobra.Command { - opts := &UpdateOpts{ + opts := &LinkIssueOpts{ IO: f.IO, } issueUpdateCmd := &cobra.Command{ @@ -179,19 +179,22 @@ func NewCmdUpdate(f *cmdutils.Factory) *cobra.Command { // If the linked-issues flag is passed call to update LinkedIssues if len(opts.LinkedIssues) > 0 { - err = issueutils.LinkIssues(apiClient, issue, opts, repo) + err = issueutils.LinkIssues(apiClient, issue, opts.LinkedIssues, opts.IssueLinkType, repo) if err != nil { return err } } - issue, err = api.UpdateIssue(apiClient, repo.FullName(), issue.IID, l) - if err != nil { - return err - } + // Only run the UpdateIssue function if flags are passed - FIXME + if cmd.Flags().Changed("linked-issues") && cmd.Flags().Changed("link-type") { + issue, err = api.UpdateIssue(apiClient, repo.FullName(), issue.IID, l) + if err != nil { + return err + } - for _, s := range actions { - fmt.Fprintln(out, c.GreenCheck(), s) + for _, s := range actions { + fmt.Fprintln(out, c.GreenCheck(), s) + } } fmt.Fprintln(out, issueutils.DisplayIssue(c, issue, f.IO.IsaTTY)) -- GitLab From 8ee1eabaa866bb3e242a175d79121611345c039d Mon Sep 17 00:00:00 2001 From: Kai Armstrong Date: Fri, 26 Jul 2024 11:19:14 -0400 Subject: [PATCH 09/20] broken --- commands/issue/update/issue_update.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/issue/update/issue_update.go b/commands/issue/update/issue_update.go index fac617da8..a11a0b3d4 100644 --- a/commands/issue/update/issue_update.go +++ b/commands/issue/update/issue_update.go @@ -186,7 +186,7 @@ func NewCmdUpdate(f *cmdutils.Factory) *cobra.Command { } // Only run the UpdateIssue function if flags are passed - FIXME - if cmd.Flags().Changed("linked-issues") && cmd.Flags().Changed("link-type") { + if (&gitlab.UpdateIssueOptions{}) != l { issue, err = api.UpdateIssue(apiClient, repo.FullName(), issue.IID, l) if err != nil { return err -- GitLab From fcf2f77855c63e5c041e7e9ae88b2e3ee3bbf297 Mon Sep 17 00:00:00 2001 From: Kai Armstrong Date: Sun, 2 Jun 2024 13:12:22 -0500 Subject: [PATCH 10/20] feat: add linked-issues option to issue update --- commands/issue/update/issue_update.go | 41 +++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/commands/issue/update/issue_update.go b/commands/issue/update/issue_update.go index a72409147..b60783f48 100644 --- a/commands/issue/update/issue_update.go +++ b/commands/issue/update/issue_update.go @@ -3,18 +3,32 @@ package update import ( "errors" "fmt" + "strconv" "strings" + "gitlab.com/gitlab-org/cli/pkg/iostreams" + "gitlab.com/gitlab-org/cli/api" "gitlab.com/gitlab-org/cli/commands/cmdutils" "gitlab.com/gitlab-org/cli/commands/issue/issueutils" + "gitlab.com/gitlab-org/cli/internal/glrepo" "github.com/MakeNowJust/heredoc/v2" "github.com/spf13/cobra" "github.com/xanzy/go-gitlab" ) +type LinkIssueOpts struct { + LinkedIssues []int `json:"linked_issues,omitempty"` + IssueLinkType string `json:"issue_link_type,omitempty"` + + IO *iostreams.IOStreams `json:"-"` +} + func NewCmdUpdate(f *cmdutils.Factory) *cobra.Command { + opts := &LinkIssueOpts{ + IO: f.IO, + } issueUpdateCmd := &cobra.Command{ Use: "update ", Short: `Update issue`, @@ -165,6 +179,14 @@ func NewCmdUpdate(f *cmdutils.Factory) *cobra.Command { fmt.Fprintf(out, "- Updating issue #%d\n", issue.IID) + // If the linked-issues flag is passed call to update LinkedIssues + if len(opts.LinkedIssues) > 0 { + err = linkedIssueUpdate(apiClient, issue, opts, repo) + if err != nil { + return err + } + } + issue, err = api.UpdateIssue(apiClient, repo.FullName(), issue.IID, l) if err != nil { return err @@ -191,6 +213,25 @@ func NewCmdUpdate(f *cmdutils.Factory) *cobra.Command { issueUpdateCmd.Flags(). StringSliceP("assignee", "a", []string{}, "Assign users by username. Prefix with '!' or '-' to remove from existing assignees, or '+' to add new. Otherwise, replace existing assignees with these users.") issueUpdateCmd.Flags().Bool("unassign", false, "Unassign all users.") + issueUpdateCmd.Flags().IntSliceVarP(&opts.LinkedIssues, "linked-issues", "", []int{}, "The IIDs of issues that this issue links to") + issueUpdateCmd.Flags().StringVarP(&opts.IssueLinkType, "link-type", "", "relates_to", "Type for the issue link") return issueUpdateCmd } + +func linkedIssueUpdate(apiClient *gitlab.Client, issue *gitlab.Issue, opts *LinkIssueOpts, repo glrepo.Interface) error { + if len(opts.LinkedIssues) > 0 { + var err error + for _, targetIssueIID := range opts.LinkedIssues { + fmt.Fprintln(opts.IO.StdErr, "- Linking to issue ", targetIssueIID) + issue, _, err = api.LinkIssues(apiClient, repo.FullName(), issue.IID, &gitlab.CreateIssueLinkOptions{ + TargetIssueIID: gitlab.Ptr(strconv.Itoa(targetIssueIID)), + LinkType: gitlab.Ptr(opts.IssueLinkType), + }) + if err != nil { + return err + } + } + } + return nil +} -- GitLab From 4053221ac8f541f7d85c28d2c5ee7156ec4b89ff Mon Sep 17 00:00:00 2001 From: Kai Armstrong Date: Tue, 11 Jun 2024 17:12:40 -0500 Subject: [PATCH 11/20] broken --- commands/issue/create/issue_create.go | 13 +++-------- commands/issue/issueutils/utils.go | 22 ++++++++++++++++++ commands/issue/update/issue_update.go | 32 ++------------------------- 3 files changed, 27 insertions(+), 40 deletions(-) diff --git a/commands/issue/create/issue_create.go b/commands/issue/create/issue_create.go index b45075267..98957f3dc 100644 --- a/commands/issue/create/issue_create.go +++ b/commands/issue/create/issue_create.go @@ -5,7 +5,6 @@ import ( "fmt" "net/url" "os" - "strconv" "strings" "gitlab.com/gitlab-org/cli/pkg/iostreams" @@ -397,15 +396,9 @@ func createRun(opts *CreateOpts) error { func postCreateActions(apiClient *gitlab.Client, issue *gitlab.Issue, opts *CreateOpts, repo glrepo.Interface) error { if len(opts.LinkedIssues) > 0 { var err error - for _, targetIssueIID := range opts.LinkedIssues { - fmt.Fprintln(opts.IO.StdErr, "- Linking to issue ", targetIssueIID) - issue, _, err = api.LinkIssues(apiClient, repo.FullName(), issue.IID, &gitlab.CreateIssueLinkOptions{ - TargetIssueIID: gitlab.Ptr(strconv.Itoa(targetIssueIID)), - LinkType: gitlab.Ptr(opts.IssueLinkType), - }) - if err != nil { - return err - } + err = issueutils.linkIssues(apiClient, issue, opts, repo) + if err != nil { + return err } } if opts.TimeEstimate != "" { diff --git a/commands/issue/issueutils/utils.go b/commands/issue/issueutils/utils.go index dea8b7aff..9e6ac6629 100644 --- a/commands/issue/issueutils/utils.go +++ b/commands/issue/issueutils/utils.go @@ -21,6 +21,13 @@ import ( "github.com/xanzy/go-gitlab" ) +type LinkIssueOpts struct { + LinkedIssues []int `json:"linked_issues,omitempty"` + IssueLinkType string `json:"issue_link_type,omitempty"` + + IO *iostreams.IOStreams `json:"-"` +} + func DisplayIssueList(streams *iostreams.IOStreams, issues []*gitlab.Issue, projectID string) string { c := streams.Color() table := tableprinter.NewTablePrinter() @@ -180,3 +187,18 @@ func issueMetadataFromURL(s string) (int, glrepo.Interface) { func issueFromIID(apiClient *gitlab.Client, repo glrepo.Interface, issueIID int) (*gitlab.Issue, error) { return api.GetIssue(apiClient, repo.FullName(), issueIID) } + +func linkIssues(apiClient *gitlab.Client, issue *gitlab.Issue, opts LinkIssueOpts, repo glrepo.Interface) error { + var err error + for _, targetIssueIID := range opts.LinkedIssues { + fmt.Fprintln(opts.IO.StdErr, "- Linking to issue ", targetIssueIID) + issue, _, err = api.LinkIssues(apiClient, repo.FullName(), issue.IID, &gitlab.CreateIssueLinkOptions{ + TargetIssueIID: gitlab.Ptr(strconv.Itoa(targetIssueIID)), + LinkType: gitlab.Ptr(opts.IssueLinkType), + }) + if err != nil { + return err + } + } + return nil +} diff --git a/commands/issue/update/issue_update.go b/commands/issue/update/issue_update.go index b60783f48..95955b694 100644 --- a/commands/issue/update/issue_update.go +++ b/commands/issue/update/issue_update.go @@ -3,30 +3,19 @@ package update import ( "errors" "fmt" - "strconv" "strings" - "gitlab.com/gitlab-org/cli/pkg/iostreams" - "gitlab.com/gitlab-org/cli/api" "gitlab.com/gitlab-org/cli/commands/cmdutils" "gitlab.com/gitlab-org/cli/commands/issue/issueutils" - "gitlab.com/gitlab-org/cli/internal/glrepo" "github.com/MakeNowJust/heredoc/v2" "github.com/spf13/cobra" "github.com/xanzy/go-gitlab" ) -type LinkIssueOpts struct { - LinkedIssues []int `json:"linked_issues,omitempty"` - IssueLinkType string `json:"issue_link_type,omitempty"` - - IO *iostreams.IOStreams `json:"-"` -} - func NewCmdUpdate(f *cmdutils.Factory) *cobra.Command { - opts := &LinkIssueOpts{ + opts := issueutils.LinkIssueOpts{ IO: f.IO, } issueUpdateCmd := &cobra.Command{ @@ -181,7 +170,7 @@ func NewCmdUpdate(f *cmdutils.Factory) *cobra.Command { // If the linked-issues flag is passed call to update LinkedIssues if len(opts.LinkedIssues) > 0 { - err = linkedIssueUpdate(apiClient, issue, opts, repo) + err = issueutils.linkIssues(apiClient, issue, opts, repo) if err != nil { return err } @@ -218,20 +207,3 @@ func NewCmdUpdate(f *cmdutils.Factory) *cobra.Command { return issueUpdateCmd } - -func linkedIssueUpdate(apiClient *gitlab.Client, issue *gitlab.Issue, opts *LinkIssueOpts, repo glrepo.Interface) error { - if len(opts.LinkedIssues) > 0 { - var err error - for _, targetIssueIID := range opts.LinkedIssues { - fmt.Fprintln(opts.IO.StdErr, "- Linking to issue ", targetIssueIID) - issue, _, err = api.LinkIssues(apiClient, repo.FullName(), issue.IID, &gitlab.CreateIssueLinkOptions{ - TargetIssueIID: gitlab.Ptr(strconv.Itoa(targetIssueIID)), - LinkType: gitlab.Ptr(opts.IssueLinkType), - }) - if err != nil { - return err - } - } - } - return nil -} -- GitLab From 2eaeec6634d75377e68c1ef17485a833a5654697 Mon Sep 17 00:00:00 2001 From: Kai Armstrong Date: Sun, 2 Jun 2024 13:12:22 -0500 Subject: [PATCH 12/20] feat: add linked-issues option to issue update --- commands/issue/update/issue_update.go | 34 +++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/commands/issue/update/issue_update.go b/commands/issue/update/issue_update.go index 95955b694..e9fb6c382 100644 --- a/commands/issue/update/issue_update.go +++ b/commands/issue/update/issue_update.go @@ -3,19 +3,30 @@ package update import ( "errors" "fmt" + "strconv" "strings" + "gitlab.com/gitlab-org/cli/pkg/iostreams" + "gitlab.com/gitlab-org/cli/api" "gitlab.com/gitlab-org/cli/commands/cmdutils" "gitlab.com/gitlab-org/cli/commands/issue/issueutils" + "gitlab.com/gitlab-org/cli/internal/glrepo" "github.com/MakeNowJust/heredoc/v2" "github.com/spf13/cobra" "github.com/xanzy/go-gitlab" ) +type LinkIssueOpts struct { + LinkedIssues []int `json:"linked_issues,omitempty"` + IssueLinkType string `json:"issue_link_type,omitempty"` + + IO *iostreams.IOStreams `json:"-"` +} + func NewCmdUpdate(f *cmdutils.Factory) *cobra.Command { - opts := issueutils.LinkIssueOpts{ + opts := &LinkIssueOpts{ IO: f.IO, } issueUpdateCmd := &cobra.Command{ @@ -170,7 +181,7 @@ func NewCmdUpdate(f *cmdutils.Factory) *cobra.Command { // If the linked-issues flag is passed call to update LinkedIssues if len(opts.LinkedIssues) > 0 { - err = issueutils.linkIssues(apiClient, issue, opts, repo) + err = linkedIssueUpdate(apiClient, issue, opts, repo) if err != nil { return err } @@ -204,6 +215,25 @@ func NewCmdUpdate(f *cmdutils.Factory) *cobra.Command { issueUpdateCmd.Flags().Bool("unassign", false, "Unassign all users.") issueUpdateCmd.Flags().IntSliceVarP(&opts.LinkedIssues, "linked-issues", "", []int{}, "The IIDs of issues that this issue links to") issueUpdateCmd.Flags().StringVarP(&opts.IssueLinkType, "link-type", "", "relates_to", "Type for the issue link") + issueUpdateCmd.Flags().IntSliceVarP(&opts.LinkedIssues, "linked-issues", "", []int{}, "The IIDs of issues that this issue links to") + issueUpdateCmd.Flags().StringVarP(&opts.IssueLinkType, "link-type", "", "relates_to", "Type for the issue link") return issueUpdateCmd } + +func linkedIssueUpdate(apiClient *gitlab.Client, issue *gitlab.Issue, opts *LinkIssueOpts, repo glrepo.Interface) error { + if len(opts.LinkedIssues) > 0 { + var err error + for _, targetIssueIID := range opts.LinkedIssues { + fmt.Fprintln(opts.IO.StdErr, "- Linking to issue ", targetIssueIID) + issue, _, err = api.LinkIssues(apiClient, repo.FullName(), issue.IID, &gitlab.CreateIssueLinkOptions{ + TargetIssueIID: gitlab.Ptr(strconv.Itoa(targetIssueIID)), + LinkType: gitlab.Ptr(opts.IssueLinkType), + }) + if err != nil { + return err + } + } + } + return nil +} -- GitLab From cc67a31d5f269e95dcca4bbbd030d5be852f07ed Mon Sep 17 00:00:00 2001 From: Kai Armstrong Date: Tue, 11 Jun 2024 17:12:40 -0500 Subject: [PATCH 13/20] broken --- commands/issue/update/issue_update.go | 32 ++------------------------- 1 file changed, 2 insertions(+), 30 deletions(-) diff --git a/commands/issue/update/issue_update.go b/commands/issue/update/issue_update.go index e9fb6c382..cf479615b 100644 --- a/commands/issue/update/issue_update.go +++ b/commands/issue/update/issue_update.go @@ -3,30 +3,19 @@ package update import ( "errors" "fmt" - "strconv" "strings" - "gitlab.com/gitlab-org/cli/pkg/iostreams" - "gitlab.com/gitlab-org/cli/api" "gitlab.com/gitlab-org/cli/commands/cmdutils" "gitlab.com/gitlab-org/cli/commands/issue/issueutils" - "gitlab.com/gitlab-org/cli/internal/glrepo" "github.com/MakeNowJust/heredoc/v2" "github.com/spf13/cobra" "github.com/xanzy/go-gitlab" ) -type LinkIssueOpts struct { - LinkedIssues []int `json:"linked_issues,omitempty"` - IssueLinkType string `json:"issue_link_type,omitempty"` - - IO *iostreams.IOStreams `json:"-"` -} - func NewCmdUpdate(f *cmdutils.Factory) *cobra.Command { - opts := &LinkIssueOpts{ + opts := issueutils.LinkIssueOpts{ IO: f.IO, } issueUpdateCmd := &cobra.Command{ @@ -181,7 +170,7 @@ func NewCmdUpdate(f *cmdutils.Factory) *cobra.Command { // If the linked-issues flag is passed call to update LinkedIssues if len(opts.LinkedIssues) > 0 { - err = linkedIssueUpdate(apiClient, issue, opts, repo) + err = issueutils.linkIssues(apiClient, issue, opts, repo) if err != nil { return err } @@ -220,20 +209,3 @@ func NewCmdUpdate(f *cmdutils.Factory) *cobra.Command { return issueUpdateCmd } - -func linkedIssueUpdate(apiClient *gitlab.Client, issue *gitlab.Issue, opts *LinkIssueOpts, repo glrepo.Interface) error { - if len(opts.LinkedIssues) > 0 { - var err error - for _, targetIssueIID := range opts.LinkedIssues { - fmt.Fprintln(opts.IO.StdErr, "- Linking to issue ", targetIssueIID) - issue, _, err = api.LinkIssues(apiClient, repo.FullName(), issue.IID, &gitlab.CreateIssueLinkOptions{ - TargetIssueIID: gitlab.Ptr(strconv.Itoa(targetIssueIID)), - LinkType: gitlab.Ptr(opts.IssueLinkType), - }) - if err != nil { - return err - } - } - } - return nil -} -- GitLab From 6400af0f414b769870528196362c26aec0d16aff Mon Sep 17 00:00:00 2001 From: Kai Armstrong Date: Wed, 26 Jun 2024 12:29:08 -0500 Subject: [PATCH 14/20] Export function name --- commands/issue/create/issue_create.go | 2 +- commands/issue/issueutils/utils.go | 2 +- commands/issue/update/issue_update.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/commands/issue/create/issue_create.go b/commands/issue/create/issue_create.go index 98957f3dc..7f9e4138e 100644 --- a/commands/issue/create/issue_create.go +++ b/commands/issue/create/issue_create.go @@ -396,7 +396,7 @@ func createRun(opts *CreateOpts) error { func postCreateActions(apiClient *gitlab.Client, issue *gitlab.Issue, opts *CreateOpts, repo glrepo.Interface) error { if len(opts.LinkedIssues) > 0 { var err error - err = issueutils.linkIssues(apiClient, issue, opts, repo) + err = issueutils.LinkIssues(apiClient, issue, opts, repo) if err != nil { return err } diff --git a/commands/issue/issueutils/utils.go b/commands/issue/issueutils/utils.go index 9e6ac6629..26a34bac2 100644 --- a/commands/issue/issueutils/utils.go +++ b/commands/issue/issueutils/utils.go @@ -188,7 +188,7 @@ func issueFromIID(apiClient *gitlab.Client, repo glrepo.Interface, issueIID int) return api.GetIssue(apiClient, repo.FullName(), issueIID) } -func linkIssues(apiClient *gitlab.Client, issue *gitlab.Issue, opts LinkIssueOpts, repo glrepo.Interface) error { +func LinkIssues(apiClient *gitlab.Client, issue *gitlab.Issue, opts LinkIssueOpts, repo glrepo.Interface) error { var err error for _, targetIssueIID := range opts.LinkedIssues { fmt.Fprintln(opts.IO.StdErr, "- Linking to issue ", targetIssueIID) diff --git a/commands/issue/update/issue_update.go b/commands/issue/update/issue_update.go index cf479615b..8dead6daf 100644 --- a/commands/issue/update/issue_update.go +++ b/commands/issue/update/issue_update.go @@ -170,7 +170,7 @@ func NewCmdUpdate(f *cmdutils.Factory) *cobra.Command { // If the linked-issues flag is passed call to update LinkedIssues if len(opts.LinkedIssues) > 0 { - err = issueutils.linkIssues(apiClient, issue, opts, repo) + err = issueutils.LinkIssues(apiClient, issue, opts, repo) if err != nil { return err } -- GitLab From 777a1f56e1aabf1f63d16bc5fbd2f3583649ce69 Mon Sep 17 00:00:00 2001 From: Kai Armstrong Date: Wed, 26 Jun 2024 16:29:51 -0500 Subject: [PATCH 15/20] sorta fixed --- commands/issue/update/issue_update.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/commands/issue/update/issue_update.go b/commands/issue/update/issue_update.go index 8dead6daf..c357e5a21 100644 --- a/commands/issue/update/issue_update.go +++ b/commands/issue/update/issue_update.go @@ -5,6 +5,8 @@ import ( "fmt" "strings" + "gitlab.com/gitlab-org/cli/pkg/iostreams" + "gitlab.com/gitlab-org/cli/api" "gitlab.com/gitlab-org/cli/commands/cmdutils" "gitlab.com/gitlab-org/cli/commands/issue/issueutils" @@ -14,8 +16,15 @@ import ( "github.com/xanzy/go-gitlab" ) +type UpdateOpts struct { + LinkedIssues []int `json:"linked_issues,omitempty"` + IssueLinkType string `json:"issue_link_type,omitempty"` + + IO *iostreams.IOStreams `json:"-"` +} + func NewCmdUpdate(f *cmdutils.Factory) *cobra.Command { - opts := issueutils.LinkIssueOpts{ + opts := &UpdateOpts{ IO: f.IO, } issueUpdateCmd := &cobra.Command{ -- GitLab From e6b7e2ec054d1c12ca5357c9be8a3bd7f4712859 Mon Sep 17 00:00:00 2001 From: Kai Armstrong Date: Fri, 28 Jun 2024 15:44:19 -0500 Subject: [PATCH 16/20] still broken --- commands/issue/issueutils/utils.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/commands/issue/issueutils/utils.go b/commands/issue/issueutils/utils.go index 26a34bac2..5775329f2 100644 --- a/commands/issue/issueutils/utils.go +++ b/commands/issue/issueutils/utils.go @@ -21,13 +21,6 @@ import ( "github.com/xanzy/go-gitlab" ) -type LinkIssueOpts struct { - LinkedIssues []int `json:"linked_issues,omitempty"` - IssueLinkType string `json:"issue_link_type,omitempty"` - - IO *iostreams.IOStreams `json:"-"` -} - func DisplayIssueList(streams *iostreams.IOStreams, issues []*gitlab.Issue, projectID string) string { c := streams.Color() table := tableprinter.NewTablePrinter() @@ -188,10 +181,15 @@ func issueFromIID(apiClient *gitlab.Client, repo glrepo.Interface, issueIID int) return api.GetIssue(apiClient, repo.FullName(), issueIID) } -func LinkIssues(apiClient *gitlab.Client, issue *gitlab.Issue, opts LinkIssueOpts, repo glrepo.Interface) error { +func LinkIssues(apiClient *gitlab.Client, issue *gitlab.Issue, opts interface{}, repo glrepo.Interface) error { var err error + fmt.Println(opts) + // interface format is {int[], str, byte_code} + // intefface data is {linkissue, typerelation, byte_code} + //&{[12] relates_to 0x140000ae360} + linkOpts := opts.(struct{}) for _, targetIssueIID := range opts.LinkedIssues { - fmt.Fprintln(opts.IO.StdErr, "- Linking to issue ", targetIssueIID) + //fmt.Fprintln(opts.IO.StdErr, "- Linking to issue ", targetIssueIID) issue, _, err = api.LinkIssues(apiClient, repo.FullName(), issue.IID, &gitlab.CreateIssueLinkOptions{ TargetIssueIID: gitlab.Ptr(strconv.Itoa(targetIssueIID)), LinkType: gitlab.Ptr(opts.IssueLinkType), -- GitLab From 8afbd0bd4a271ca0f3a093ae22379a52c74053b8 Mon Sep 17 00:00:00 2001 From: Kai Armstrong Date: Fri, 26 Jul 2024 11:07:11 -0400 Subject: [PATCH 17/20] passing? --- commands/issue/create/issue_create.go | 2 +- commands/issue/issueutils/utils.go | 11 +++-------- commands/issue/update/issue_update.go | 21 ++++++++++++--------- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/commands/issue/create/issue_create.go b/commands/issue/create/issue_create.go index 7f9e4138e..3e3fc22fa 100644 --- a/commands/issue/create/issue_create.go +++ b/commands/issue/create/issue_create.go @@ -396,7 +396,7 @@ func createRun(opts *CreateOpts) error { func postCreateActions(apiClient *gitlab.Client, issue *gitlab.Issue, opts *CreateOpts, repo glrepo.Interface) error { if len(opts.LinkedIssues) > 0 { var err error - err = issueutils.LinkIssues(apiClient, issue, opts, repo) + err = issueutils.LinkIssues(apiClient, issue, opts.LinkedIssues, opts.IssueLinkType, repo) if err != nil { return err } diff --git a/commands/issue/issueutils/utils.go b/commands/issue/issueutils/utils.go index 5775329f2..4075068aa 100644 --- a/commands/issue/issueutils/utils.go +++ b/commands/issue/issueutils/utils.go @@ -181,18 +181,13 @@ func issueFromIID(apiClient *gitlab.Client, repo glrepo.Interface, issueIID int) return api.GetIssue(apiClient, repo.FullName(), issueIID) } -func LinkIssues(apiClient *gitlab.Client, issue *gitlab.Issue, opts interface{}, repo glrepo.Interface) error { +func LinkIssues(apiClient *gitlab.Client, issue *gitlab.Issue, LinkedIssues []int, IssueLinkType string, repo glrepo.Interface) error { var err error - fmt.Println(opts) - // interface format is {int[], str, byte_code} - // intefface data is {linkissue, typerelation, byte_code} - //&{[12] relates_to 0x140000ae360} - linkOpts := opts.(struct{}) - for _, targetIssueIID := range opts.LinkedIssues { + for _, targetIssueIID := range LinkedIssues { //fmt.Fprintln(opts.IO.StdErr, "- Linking to issue ", targetIssueIID) issue, _, err = api.LinkIssues(apiClient, repo.FullName(), issue.IID, &gitlab.CreateIssueLinkOptions{ TargetIssueIID: gitlab.Ptr(strconv.Itoa(targetIssueIID)), - LinkType: gitlab.Ptr(opts.IssueLinkType), + LinkType: gitlab.Ptr(IssueLinkType), }) if err != nil { return err diff --git a/commands/issue/update/issue_update.go b/commands/issue/update/issue_update.go index c357e5a21..b9750a48c 100644 --- a/commands/issue/update/issue_update.go +++ b/commands/issue/update/issue_update.go @@ -16,7 +16,7 @@ import ( "github.com/xanzy/go-gitlab" ) -type UpdateOpts struct { +type LinkIssueOpts struct { LinkedIssues []int `json:"linked_issues,omitempty"` IssueLinkType string `json:"issue_link_type,omitempty"` @@ -24,7 +24,7 @@ type UpdateOpts struct { } func NewCmdUpdate(f *cmdutils.Factory) *cobra.Command { - opts := &UpdateOpts{ + opts := &LinkIssueOpts{ IO: f.IO, } issueUpdateCmd := &cobra.Command{ @@ -179,19 +179,22 @@ func NewCmdUpdate(f *cmdutils.Factory) *cobra.Command { // If the linked-issues flag is passed call to update LinkedIssues if len(opts.LinkedIssues) > 0 { - err = issueutils.LinkIssues(apiClient, issue, opts, repo) + err = issueutils.LinkIssues(apiClient, issue, opts.LinkedIssues, opts.IssueLinkType, repo) if err != nil { return err } } - issue, err = api.UpdateIssue(apiClient, repo.FullName(), issue.IID, l) - if err != nil { - return err - } + // Only run the UpdateIssue function if flags are passed - FIXME + if cmd.Flags().Changed("linked-issues") && cmd.Flags().Changed("link-type") { + issue, err = api.UpdateIssue(apiClient, repo.FullName(), issue.IID, l) + if err != nil { + return err + } - for _, s := range actions { - fmt.Fprintln(out, c.GreenCheck(), s) + for _, s := range actions { + fmt.Fprintln(out, c.GreenCheck(), s) + } } fmt.Fprintln(out, issueutils.DisplayIssue(c, issue, f.IO.IsaTTY)) -- GitLab From c141171a30bad569c707a63ff378c2c5c98e14a3 Mon Sep 17 00:00:00 2001 From: Kai Armstrong Date: Fri, 26 Jul 2024 11:19:14 -0400 Subject: [PATCH 18/20] broken --- commands/issue/update/issue_update.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/issue/update/issue_update.go b/commands/issue/update/issue_update.go index b9750a48c..55c7f0f52 100644 --- a/commands/issue/update/issue_update.go +++ b/commands/issue/update/issue_update.go @@ -186,7 +186,7 @@ func NewCmdUpdate(f *cmdutils.Factory) *cobra.Command { } // Only run the UpdateIssue function if flags are passed - FIXME - if cmd.Flags().Changed("linked-issues") && cmd.Flags().Changed("link-type") { + if (&gitlab.UpdateIssueOptions{}) != l { issue, err = api.UpdateIssue(apiClient, repo.FullName(), issue.IID, l) if err != nil { return err -- GitLab From a507b59739136271b9b4671e7dc2a2944dbd6895 Mon Sep 17 00:00:00 2001 From: Kai Armstrong Date: Mon, 5 Aug 2024 14:48:17 -0500 Subject: [PATCH 19/20] still broken --- commands/issue/update/issue_update.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/commands/issue/update/issue_update.go b/commands/issue/update/issue_update.go index 0878f4b01..9c62d68d8 100644 --- a/commands/issue/update/issue_update.go +++ b/commands/issue/update/issue_update.go @@ -185,8 +185,16 @@ func NewCmdUpdate(f *cmdutils.Factory) *cobra.Command { } } - // Only run the UpdateIssue function if flags are passed - FIXME - if (&gitlab.UpdateIssueOptions{}) != l { + // We want to only run the UpdateIssue function if flags are passed + // and the passed flags are not `linked-issues` or `link-type`. + // First we check that some number of flags was passed. We then check that + // if the flags are `linked-issues` or `link-type`. If it is NOT a link flag + // we return nil and continue. + if cmd.Flags().NFlag() > 0 { + if !cmd.Flags().Changed("linked-issues") && !cmd.Flags().Changed("link-type") { + return nil + } + issue, err = api.UpdateIssue(apiClient, repo.FullName(), issue.IID, l) if err != nil { return err -- GitLab From 43fc715a02c0e21ca29875f01f13ee22aa0ae84f Mon Sep 17 00:00:00 2001 From: Kai Armstrong Date: Wed, 4 Sep 2024 09:10:34 -0500 Subject: [PATCH 20/20] more changes --- commands/issue/update/issue_update.go | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/commands/issue/update/issue_update.go b/commands/issue/update/issue_update.go index 9c62d68d8..f6f6fecbd 100644 --- a/commands/issue/update/issue_update.go +++ b/commands/issue/update/issue_update.go @@ -190,8 +190,26 @@ func NewCmdUpdate(f *cmdutils.Factory) *cobra.Command { // First we check that some number of flags was passed. We then check that // if the flags are `linked-issues` or `link-type`. If it is NOT a link flag // we return nil and continue. - if cmd.Flags().NFlag() > 0 { - if !cmd.Flags().Changed("linked-issues") && !cmd.Flags().Changed("link-type") { + switch cmd.Flags().NFlag() { + case 1: + if cmd.Flags().Changed("linked-issues") { + return errors.New("cannot update issue when only --linked-issues is set") + } + if cmd.Flags().Changed("link-type") { + return errors.New("cannot update issue when only --link-type is set") + } + + // continue execution to api.UpdateIssue + fallthrough + case 2: + if cmd.Flags().Changed("linked-issues") && cmd.Flags().Changed("link-type") { + return errors.New("cannot update issue when only --link-type and --linked-issues are set") + } + + // continue execution to api.UpdateIssue + fallthrough + default: + if cmd.Flags().NFlag() < 0 { return nil } -- GitLab