Skip to content
This repository has been archived by the owner on Nov 22, 2022. It is now read-only.

feat: Issue link on create #613

Merged
merged 3 commits into from
Feb 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions api/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,16 @@ var UnsubscribeFromIssue = func(client *gitlab.Client, projectID interface{}, is

return issue, nil
}

var LinkIssues = func(client *gitlab.Client, projectID interface{}, issueIDD int, opts *gitlab.CreateIssueLinkOptions) (*gitlab.Issue, *gitlab.Issue, error) {
if client == nil {
client = apiClient.Lab()
}

issueLink, _, err := client.IssueLinks.CreateIssueLink(projectID, issueIDD, opts)
if err != nil {
return nil, nil, err
}

return issueLink.SourceIssue, issueLink.TargetIssue, nil
}
25 changes: 21 additions & 4 deletions commands/issue/create/issue_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"net/url"
"strconv"
"strings"

"github.com/profclems/glab/pkg/iostreams"
Expand All @@ -28,9 +29,11 @@ type CreateOpts struct {
Labels []string
Assignees []string

Weight int
MileStone int
LinkedMR int
Weight int
MileStone int
LinkedMR int
LinkedIssues []int
IssueLinkType string

MilestoneFlag string

Expand Down Expand Up @@ -129,6 +132,8 @@ func NewCmdCreate(f *cmdutils.Factory) *cobra.Command {
issueCreateCmd.Flags().BoolVarP(&opts.NoEditor, "no-editor", "", false, "Don't open editor to enter description. If set to true, uses prompt. Default is false")
issueCreateCmd.Flags().BoolVarP(&opts.Yes, "yes", "y", false, "Don't prompt for confirmation to submit the issue")
issueCreateCmd.Flags().BoolVar(&opts.Web, "web", false, "continue issue creation with web interface")
issueCreateCmd.Flags().IntSliceVarP(&opts.LinkedIssues, "linked-issues", "", []int{}, "The IIDs of issues that this issue links to")
issueCreateCmd.Flags().StringVarP(&opts.IssueLinkType, "link-type", "", "relates_to", "Type for the issue link")

return issueCreateCmd
}
Expand Down Expand Up @@ -328,11 +333,23 @@ func createRun(opts *CreateOpts) error {
}
issueCreateOpts.AssigneeIDs = cmdutils.IDsFromUsers(users)
}
fmt.Fprintln(opts.IO.StdErr, "\n- Creating issue in", repo.FullName())
fmt.Fprintln(opts.IO.StdErr, "- Creating issue in", repo.FullName())
issue, err := api.CreateIssue(apiClient, repo.FullName(), issueCreateOpts)
if err != nil {
return err
}
if len(opts.LinkedIssues) > 0 {
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.String(strconv.Itoa(targetIssueIID)),
LinkType: gitlab.String(opts.IssueLinkType),
})
if err != nil {
return err
}
}
}
fmt.Fprintln(opts.IO.StdOut, issueutils.DisplayIssue(opts.IO.Color(), issue))
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion commands/issue/create/issue_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func Test_IssueCreate(t *testing.T) {
outErr := stripansi.Strip(stderr.String())
expectedOut := fmt.Sprintf("#1 myissuetitle (%s)", utils.TimeToPrettyTimeAgo(timer))
cmdtest.Eq(t, cmdtest.FirstLine([]byte(out)), expectedOut)
cmdtest.Eq(t, outErr, "\n- Creating issue in glab-cli/test\n")
cmdtest.Eq(t, outErr, "- Creating issue in glab-cli/test\n")
assert.Contains(t, out, "https://gitlab.com/glab-cli/test/-/issues/1")

api.CreateIssue = oldCreateIssue
Expand Down