diff --git a/cmd/ci_trace.go b/cmd/ci_trace.go index c699a874..2b3fc13c 100644 --- a/cmd/ci_trace.go +++ b/cmd/ci_trace.go @@ -83,7 +83,7 @@ var ciTraceCmd = &cobra.Command{ }, } -func doTrace(ctx context.Context, w io.Writer, projID string, pipelineID int, name string) error { +func doTrace(ctx context.Context, w io.Writer, projID string, pipelineID int64, name string) error { var ( once sync.Once offset int64 diff --git a/cmd/ci_view.go b/cmd/ci_view.go index 6899cfdd..39b328b4 100644 --- a/cmd/ci_view.go +++ b/cmd/ci_view.go @@ -26,7 +26,7 @@ import ( var ( projectID string - pipelineID int + pipelineID int64 ) // ciViewCmd represents the ci command diff --git a/cmd/edit_common.go b/cmd/edit_common.go index 9355e3fe..8f1adbf0 100644 --- a/cmd/edit_common.go +++ b/cmd/edit_common.go @@ -16,19 +16,19 @@ import ( // GetUpdateUsers returns an int slice of user IDs based on the // current users and flags from the command line, and a bool // indicating whether the users have changed -func getUpdateUsers(currentUsers []string, users []string, remove []string) ([]int, bool, error) { +func getUpdateUsers(currentUsers []string, users []string, remove []string) ([]int64, bool, error) { // add the new users to the current users, then remove the "remove" group users = difference(union(currentUsers, users), remove) usersChanged := !same(currentUsers, users) // turn the new user list into a list of user IDs - var userIDs []int + var userIDs []int64 if usersChanged && len(users) == 0 { // if we're removing all users, we have to use []int{0} // see https://github.com/xanzy/go-gitlab/issues/427 - userIDs = []int{0} + userIDs = []int64{0} } else { - userIDs = make([]int, len(users)) + userIDs = make([]int64, len(users)) for i, a := range users { if getUserID(a) == nil { return nil, false, fmt.Errorf("%s is not a valid username", a) diff --git a/cmd/fork.go b/cmd/fork.go index 0159753c..03a9de47 100644 --- a/cmd/fork.go +++ b/cmd/fork.go @@ -55,9 +55,9 @@ var forkCmd = &cobra.Command{ if targetData.project != "" || targetData.group != "" || targetData.path != "" { forkOpts = &gitlab.ForkProjectOptions{ - Name: gitlab.String(targetData.project), - Namespace: gitlab.String(targetData.group), - Path: gitlab.String(targetData.path), + Name: gitlab.Ptr(targetData.project), + Namespace: gitlab.Ptr(targetData.group), + Path: gitlab.Ptr(targetData.path), } } diff --git a/cmd/fork_test.go b/cmd/fork_test.go index 84f53953..f146857f 100644 --- a/cmd/fork_test.go +++ b/cmd/fork_test.go @@ -10,6 +10,7 @@ import ( "github.com/pkg/errors" "github.com/stretchr/testify/require" lab "github.com/zaquestion/lab/internal/gitlab" + gitlab "gitlab.com/gitlab-org/api/client-go" ) func cleanupFork(t *testing.T, project string) { @@ -20,7 +21,7 @@ func cleanupFork(t *testing.T, project string) { if err != nil { t.Fatal(errors.Wrap(err, "failed to find project "+project+" for cleanup")) } - err = lab.ProjectDelete(p.ID) + err = lab.ProjectDelete(p.ID, &gitlab.DeleteProjectOptions{}) if err != nil { t.Fatal(errors.Wrap(err, "failed to delete project "+project+" during cleanup")) } diff --git a/cmd/issue_close.go b/cmd/issue_close.go index 509e5f1e..6bd03804 100644 --- a/cmd/issue_close.go +++ b/cmd/issue_close.go @@ -32,13 +32,13 @@ var issueCloseCmd = &cobra.Command{ if !strings.Contains(dupID, "#") { dupID = "#" + dupID } - err = lab.IssueDuplicate(rn, int(id), dupID) + err = lab.IssueDuplicate(rn, id, dupID) if err != nil { log.Fatal(err) } fmt.Printf("Issue #%d closed as duplicate of %s\n", id, dupID) } else { - err = lab.IssueClose(rn, int(id)) + err = lab.IssueClose(rn, id) if err != nil { log.Fatal(err) } diff --git a/cmd/issue_create.go b/cmd/issue_create.go index e56be8de..e906c43d 100644 --- a/cmd/issue_create.go +++ b/cmd/issue_create.go @@ -12,10 +12,10 @@ import ( "github.com/MakeNowJust/heredoc/v2" "github.com/rsteube/carapace" "github.com/spf13/cobra" - gitlab "gitlab.com/gitlab-org/api/client-go" "github.com/zaquestion/lab/internal/action" "github.com/zaquestion/lab/internal/git" lab "github.com/zaquestion/lab/internal/gitlab" + gitlab "gitlab.com/gitlab-org/api/client-go" ) var issueCreateCmd = &cobra.Command{ @@ -72,7 +72,7 @@ var issueCreateCmd = &cobra.Command{ log.Fatal(err) } - var milestoneID *int + var milestoneID *int64 if milestoneName != "" { milestone, err := lab.MilestoneGet(rn, milestoneName) if err != nil { @@ -95,7 +95,7 @@ var issueCreateCmd = &cobra.Command{ body = textToMarkdown(body) } - assigneeIDs := make([]int, len(assignees)) + assigneeIDs := make([]int64, len(assignees)) for i, a := range assignees { assigneeIDs[i] = *getUserID(a) } diff --git a/cmd/issue_edit.go b/cmd/issue_edit.go index 4c46c44f..e1451d85 100644 --- a/cmd/issue_edit.go +++ b/cmd/issue_edit.go @@ -2,16 +2,15 @@ package cmd import ( "fmt" - "strconv" "strings" "github.com/MakeNowJust/heredoc/v2" "github.com/rsteube/carapace" "github.com/spf13/cobra" "github.com/spf13/pflag" - gitlab "gitlab.com/gitlab-org/api/client-go" "github.com/zaquestion/lab/internal/action" lab "github.com/zaquestion/lab/internal/gitlab" + gitlab "gitlab.com/gitlab-org/api/client-go" ) var issueEditCmd = &cobra.Command{ @@ -38,16 +37,16 @@ var issueEditCmd = &cobra.Command{ } var ( - issueNum int = 0 - commentNum int = 0 + issueNum int64 = 0 + commentNum int64 = 0 ) if strings.Contains(idString, ":") { ids := strings.Split(idString, ":") - issueNum, _ = strconv.Atoi(ids[0]) - commentNum, _ = strconv.Atoi(ids[1]) + issueNum, _ = Atoi(ids[0]) + commentNum, _ = Atoi(ids[1]) } else { - issueNum, _ = strconv.Atoi(idString) + issueNum, _ = Atoi(idString) } issue, err := lab.IssueGet(rn, issueNum) @@ -60,7 +59,7 @@ var issueEditCmd = &cobra.Command{ log.Fatal(err) } if deleteNote { - discussions, err := lab.IssueListDiscussions(rn, int(issueNum)) + discussions, err := lab.IssueListDiscussions(rn, issueNum) if err != nil { log.Fatal(err) } @@ -145,7 +144,7 @@ var issueEditCmd = &cobra.Command{ log.Fatal(err) } updateMilestone := cmd.Flags().Lookup("milestone").Changed - milestoneID := -1 + var milestoneID int64 = -1 if milestoneName != "" { ms, err := lab.MilestoneGet(rn, milestoneName) diff --git a/cmd/issue_list.go b/cmd/issue_list.go index 8421c9f7..463b2af8 100644 --- a/cmd/issue_list.go +++ b/cmd/issue_list.go @@ -9,9 +9,9 @@ import ( "github.com/pkg/errors" "github.com/rsteube/carapace" "github.com/spf13/cobra" - gitlab "gitlab.com/gitlab-org/api/client-go" "github.com/zaquestion/lab/internal/action" lab "github.com/zaquestion/lab/internal/gitlab" + gitlab "gitlab.com/gitlab-org/api/client-go" ) var ( @@ -25,7 +25,7 @@ var ( issueAssignee string issueAssigneeID *gitlab.AssigneeIDValue issueAuthor string - issueAuthorID *int + issueAuthorID *int64 issueOrder string issueSortedBy string ) @@ -113,20 +113,17 @@ func issueList(args []string) ([]*gitlab.Issue, error) { log.Fatalf("%s user not found\n", issueAssignee) } issueAssigneeID = gitlab.AssigneeID(*assigneeID) + } else { + issueAssigneeID = nil } - orderBy := gitlab.String(issueOrder) - - sort := gitlab.String(issueSortedBy) + orderBy := gitlab.Ptr(issueOrder) - intIssueAssigneeID, err := strconv.Atoi(fmt.Sprintf("%v", issueAssigneeID)) - if err != nil { - log.Fatalf("issueAssigneeID (%s) cannot be converted to int", issueAssigneeID) - } + sort := gitlab.Ptr(issueSortedBy) opts := gitlab.ListProjectIssuesOptions{ ListOptions: gitlab.ListOptions{ - PerPage: num, + PerPage: int64(num), }, Labels: &labels, Milestone: &issueMilestone, @@ -134,7 +131,7 @@ func issueList(args []string) ([]*gitlab.Issue, error) { OrderBy: orderBy, Sort: sort, AuthorID: issueAuthorID, - AssigneeID: &intIssueAssigneeID, + AssigneeID: issueAssigneeID, } if issueExactMatch { diff --git a/cmd/issue_move.go b/cmd/issue_move.go index aca99dfb..bc6acf3d 100644 --- a/cmd/issue_move.go +++ b/cmd/issue_move.go @@ -2,7 +2,6 @@ package cmd import ( "fmt" - "strconv" "github.com/rsteube/carapace" "github.com/spf13/cobra" @@ -25,7 +24,7 @@ var issueMoveCmd = &cobra.Command{ } // get the issue ID - id, err := strconv.Atoi(args[0]) + id, err := Atoi(args[0]) if err != nil { log.Fatal(err) } diff --git a/cmd/issue_reopen.go b/cmd/issue_reopen.go index af8ac2e4..f52635e8 100644 --- a/cmd/issue_reopen.go +++ b/cmd/issue_reopen.go @@ -2,6 +2,7 @@ package cmd import ( "fmt" + "github.com/MakeNowJust/heredoc/v2" "github.com/rsteube/carapace" @@ -23,7 +24,7 @@ var issueReopenCmd = &cobra.Command{ log.Fatal(err) } - err = lab.IssueReopen(rn, int(id)) + err = lab.IssueReopen(rn, id) if err != nil { log.Fatal(err) } diff --git a/cmd/issue_show.go b/cmd/issue_show.go index 49afb659..406bb1d7 100644 --- a/cmd/issue_show.go +++ b/cmd/issue_show.go @@ -35,7 +35,7 @@ var issueShowCmd = &cobra.Command{ log.Fatalf("Specify of issue to be shown") } - issue, err := lab.IssueGet(rn, int(issueNum)) + issue, err := lab.IssueGet(rn, issueNum) if err != nil { log.Fatal(err) } @@ -69,7 +69,7 @@ var issueShowCmd = &cobra.Command{ } if noteLevel != NoteLevelNone { - discussions, err := lab.IssueListDiscussions(rn, int(issueNum)) + discussions, err := lab.IssueListDiscussions(rn, issueNum) if err != nil { log.Fatal(err) } @@ -79,7 +79,7 @@ var issueShowCmd = &cobra.Command{ log.Fatal(err) } - printDiscussions(rn, discussions, since, "issues", int(issueNum), renderMarkdown, noteLevel) + printDiscussions(rn, discussions, since, "issues", issueNum, renderMarkdown, noteLevel) } }, } diff --git a/cmd/issue_subscribe.go b/cmd/issue_subscribe.go index 9bf5aa24..a703689f 100644 --- a/cmd/issue_subscribe.go +++ b/cmd/issue_subscribe.go @@ -21,7 +21,7 @@ var issueSubscribeCmd = &cobra.Command{ log.Fatal(err) } - err = lab.IssueSubscribe(rn, int(id)) + err = lab.IssueSubscribe(rn, id) if err != nil { log.Fatal(err) } diff --git a/cmd/issue_unsubscribe.go b/cmd/issue_unsubscribe.go index 614cec8e..396d1c24 100644 --- a/cmd/issue_unsubscribe.go +++ b/cmd/issue_unsubscribe.go @@ -22,7 +22,7 @@ var issueUnsubscribeCmd = &cobra.Command{ log.Fatal(err) } - err = lab.IssueUnsubscribe(rn, int(id)) + err = lab.IssueUnsubscribe(rn, id) if err != nil { log.Fatal(err) } diff --git a/cmd/mr_approve.go b/cmd/mr_approve.go index cf1d9ce0..79267f0c 100644 --- a/cmd/mr_approve.go +++ b/cmd/mr_approve.go @@ -2,12 +2,13 @@ package cmd import ( "fmt" + "os" + "github.com/MakeNowJust/heredoc/v2" "github.com/rsteube/carapace" "github.com/spf13/cobra" "github.com/zaquestion/lab/internal/action" lab "github.com/zaquestion/lab/internal/gitlab" - "os" ) var mrApproveCmd = &cobra.Command{ @@ -27,7 +28,7 @@ var mrApproveCmd = &cobra.Command{ log.Fatal(err) } - approvalConfig, err := lab.GetMRApprovalsConfiguration(rn, int(id)) + approvalConfig, err := lab.GetMRApprovalsConfiguration(rn, id) if err != nil { log.Fatal(err) } @@ -62,14 +63,14 @@ var mrApproveCmd = &cobra.Command{ log.Fatal(err) } if comment { - state := noteGetState(rn, true, int(id)) - msg, _ := noteMsg(msgs, true, int(id), state, "", "") + state := noteGetState(rn, true, id) + msg, _ := noteMsg(msgs, true, id, state, "", "") msgs = append(msgs, msg) } } msgs = append(msgs, "/approve") - createNote(rn, true, int(id), msgs, filename, linebreak, "", note) + createNote(rn, true, id, msgs, filename, linebreak, "", note) fmt.Printf("Merge Request !%d approved\n", id) }, diff --git a/cmd/mr_checkout.go b/cmd/mr_checkout.go index fa299012..dc3d7667 100644 --- a/cmd/mr_checkout.go +++ b/cmd/mr_checkout.go @@ -51,7 +51,7 @@ var checkoutCmd = &cobra.Command{ targetRemote = args[0] } - mr, err := lab.MRGet(rn, int(mrID)) + mr, err := lab.MRGet(rn, mrID) if err != nil { log.Fatal(err) } diff --git a/cmd/mr_close.go b/cmd/mr_close.go index 5c7514ae..81eafd35 100644 --- a/cmd/mr_close.go +++ b/cmd/mr_close.go @@ -20,7 +20,7 @@ var mrCloseCmd = &cobra.Command{ log.Fatal(err) } - err = lab.MRClose(rn, int(id)) + err = lab.MRClose(rn, id) if err != nil { log.Fatal(err) } diff --git a/cmd/mr_create.go b/cmd/mr_create.go index 463c419a..ebebf142 100644 --- a/cmd/mr_create.go +++ b/cmd/mr_create.go @@ -13,10 +13,10 @@ import ( "github.com/MakeNowJust/heredoc/v2" "github.com/rsteube/carapace" "github.com/spf13/cobra" - gitlab "gitlab.com/gitlab-org/api/client-go" "github.com/zaquestion/lab/internal/action" "github.com/zaquestion/lab/internal/git" lab "github.com/zaquestion/lab/internal/gitlab" + gitlab "gitlab.com/gitlab-org/api/client-go" ) // mrCmd represents the mr command @@ -225,9 +225,9 @@ func runMRCreate(cmd *cobra.Command, args []string) { } milestoneArg, _ := cmd.Flags().GetString("milestone") - milestoneID, _ := strconv.Atoi(milestoneArg) + milestoneID, _ := Atoi(milestoneArg) - var milestone *int + var milestone *int64 if milestoneID > 0 { milestone = &milestoneID } else if milestoneArg != "" { @@ -344,7 +344,7 @@ func runMRCreate(cmd *cobra.Command, args []string) { mrURL, err := lab.MRCreate(sourceProjectName, &gitlab.CreateMergeRequestOptions{ SourceBranch: &sourceBranch, - TargetBranch: gitlab.String(targetBranch), + TargetBranch: gitlab.Ptr(targetBranch), TargetProjectID: &targetProject.ID, Title: &title, Description: &body, diff --git a/cmd/mr_delete.go b/cmd/mr_delete.go index a8c194a0..cee95cc9 100644 --- a/cmd/mr_delete.go +++ b/cmd/mr_delete.go @@ -23,7 +23,7 @@ var mrDeleteCmd = &cobra.Command{ if err != nil { log.Fatal(err) } - mrNum := int(id) + mrNum := id err = lab.MRDelete(remote, mrNum) if err != nil { diff --git a/cmd/mr_discussion.go b/cmd/mr_discussion.go index c16b7d02..47262107 100644 --- a/cmd/mr_discussion.go +++ b/cmd/mr_discussion.go @@ -11,10 +11,10 @@ import ( "github.com/MakeNowJust/heredoc/v2" "github.com/rsteube/carapace" "github.com/spf13/cobra" - gitlab "gitlab.com/gitlab-org/api/client-go" "github.com/zaquestion/lab/internal/action" "github.com/zaquestion/lab/internal/git" lab "github.com/zaquestion/lab/internal/gitlab" + gitlab "gitlab.com/gitlab-org/api/client-go" ) var mrCreateDiscussionCmd = &cobra.Command{ @@ -94,7 +94,7 @@ var mrCreateDiscussionCmd = &cobra.Command{ } } - state := noteGetState(rn, true, int(mrNum)) + state := noteGetState(rn, true, mrNum) body := "" if filename != "" { @@ -105,19 +105,19 @@ var mrCreateDiscussionCmd = &cobra.Command{ body = string(content) } else if position != "" || commit == "" { // TODO If we are commenting on a specific position in the diff, we should include some context in the template. - body, err = mrDiscussionMsg(int(mrNum), state, commit, msgs, "\n") + body, err = mrDiscussionMsg(mrNum, state, commit, msgs, "\n") if err != nil { _, f, l, _ := runtime.Caller(0) log.Fatal(f+":"+strconv.Itoa(l)+" ", err) } } else { body = getCommitBody(rn, commit) - body, err = mrDiscussionMsg(int(mrNum), state, commit, nil, body) + body, err = mrDiscussionMsg(mrNum, state, commit, nil, body) if err != nil { _, f, l, _ := runtime.Caller(0) log.Fatal(f+":"+strconv.Itoa(l)+" ", err) } - createCommitComments(rn, int(mrNum), commit, body, true) + createCommitComments(rn, mrNum, commit, body, true) return } @@ -137,17 +137,16 @@ var mrCreateDiscussionCmd = &cobra.Command{ log.Fatal(err) } // WORKAROUND For added (-) and deleted (+) lines we only need one line number parameter, but for context lines we need both. https://gitlab.com/gitlab-org/gitlab/-/issues/325161 - newLine64 := posLineNumberNew + newLine := int64(posLineNumberNew) if posLineType == '-' { - newLine64 = 0 + newLine = 0 } - newLine := int(newLine64) + // newLine := int(newLine64) - oldLine64 := posLineNumberOld + oldLine := int64(posLineNumberOld) if posLineType == '+' { - oldLine64 = 0 + oldLine = 0 } - oldLine := int(oldLine64) positionType := "text" notePos = gitlab.PositionOptions{ @@ -170,7 +169,7 @@ var mrCreateDiscussionCmd = &cobra.Command{ commitID = &commit } - discussionURL, err := lab.MRCreateDiscussion(rn, int(mrNum), &gitlab.CreateMergeRequestDiscussionOptions{ + discussionURL, err := lab.MRCreateDiscussion(rn, mrNum, &gitlab.CreateMergeRequestDiscussionOptions{ Body: &body, CommitID: commitID, Position: ¬ePos, @@ -182,7 +181,7 @@ var mrCreateDiscussionCmd = &cobra.Command{ }, } -func mrDiscussionMsg(mrNum int, state string, commit string, msgs []string, body string) (string, error) { +func mrDiscussionMsg(mrNum int64, state string, commit string, msgs []string, body string) (string, error) { if len(msgs) > 0 { return strings.Join(msgs[0:], "\n\n"), nil } @@ -224,7 +223,7 @@ func init() { is ignored. If the line type is "-", then is ignored. Here's an example diff that explains how to determine the old/new line numbers: - + --- a/README.md old new +++ b/README.md @@ -100,3 +100,4 @@ diff --git a/cmd/mr_edit.go b/cmd/mr_edit.go index ed5c5a86..3d8c7ee5 100644 --- a/cmd/mr_edit.go +++ b/cmd/mr_edit.go @@ -10,9 +10,9 @@ import ( "github.com/rsteube/carapace" "github.com/spf13/cobra" "github.com/spf13/pflag" - gitlab "gitlab.com/gitlab-org/api/client-go" "github.com/zaquestion/lab/internal/action" lab "github.com/zaquestion/lab/internal/gitlab" + gitlab "gitlab.com/gitlab-org/api/client-go" ) var mrEditCmd = &cobra.Command{ @@ -47,7 +47,7 @@ var mrEditCmd = &cobra.Command{ if err != nil { log.Fatal(err) } - mrNum := int(id) + mrNum := id if mrNum == 0 { fmt.Println("Error: Cannot determine MR id.") @@ -64,7 +64,7 @@ var mrEditCmd = &cobra.Command{ log.Fatal(err) } if deleteNote { - discussions, err := lab.MRListDiscussions(rn, int(mrNum)) + discussions, err := lab.MRListDiscussions(rn, mrNum) if err != nil { log.Fatal(err) } @@ -186,7 +186,7 @@ var mrEditCmd = &cobra.Command{ log.Fatal(err) } updateMilestone := cmd.Flags().Lookup("milestone").Changed - milestoneID := 0 + var milestoneID int64 = 0 if milestoneName != "" { ms, err := lab.MilestoneGet(rn, milestoneName) @@ -323,7 +323,7 @@ var mrEditCmd = &cobra.Command{ opts.TargetBranch = &targetBranchName } - mrURL, err := lab.MRUpdate(rn, int(mrNum), opts) + mrURL, err := lab.MRUpdate(rn, mrNum, opts) if err != nil { log.Fatal(err) } diff --git a/cmd/mr_list.go b/cmd/mr_list.go index 7a734d2a..1724b507 100644 --- a/cmd/mr_list.go +++ b/cmd/mr_list.go @@ -9,7 +9,6 @@ import ( "github.com/MakeNowJust/heredoc/v2" "github.com/fatih/color" - gitlab "gitlab.com/gitlab-org/api/client-go" "github.com/pkg/errors" "github.com/rsteube/carapace" "github.com/savioxavier/termlink" @@ -17,6 +16,7 @@ import ( "github.com/zaquestion/lab/internal/action" "github.com/zaquestion/lab/internal/git" lab "github.com/zaquestion/lab/internal/gitlab" + gitlab "gitlab.com/gitlab-org/api/client-go" "golang.org/x/term" ) @@ -29,7 +29,7 @@ var ( mrAll bool mrMine bool mrAuthor string - mrAuthorID *int + mrAuthorID *int64 mrDraft bool mrReady bool mrConflicts bool @@ -45,7 +45,7 @@ var ( mrReviewerID *gitlab.ReviewerIDValue ) -func truncateText(s string, length int) (string) { +func truncateText(s string, length int) string { if length > len(s) { return s } @@ -57,7 +57,7 @@ func overwriteEndOfString(str string, index int, replacement string) string { return str } // The output looks weird if the character before the index is a space - if str[index - 1] == ' ' { + if str[index-1] == ' ' { index-- } return str[:index] + replacement @@ -110,7 +110,7 @@ func printColumns(data [][]string) { // This is the actual line length. It is the columnWidths (calculated in the // for loop above), extra spacing in the middle columns (ie, 2 * (# of cols - 2) // and one extra character for the newline. - linelength = linelength + (spacing * (len(columnWidths) - 2) + 1) + linelength = linelength + (spacing*(len(columnWidths)-2) + 1) // If the line length is greater than the width of the terminal, truncate // the Title column. The title text itself is truncated in the switch statement below. @@ -141,12 +141,12 @@ func printColumns(data [][]string) { case 2: // MRID (and weburl link) // Requires initial offset of width+spacing-len(cell) link := termlink.Link(cell, weburl) - fmt.Printf("%s%-"+fmt.Sprintf("%d", columnWidths[cellnum]+spacing-len(cell))+"s",link, "") + fmt.Printf("%s%-"+fmt.Sprintf("%d", columnWidths[cellnum]+spacing-len(cell))+"s", link, "") case 3: // MR Title author := fmt.Sprintf(" (%s)", row[1]) title := truncateText(cell, columnWidths[cellnum]) - if len(author) + len(title) < columnWidths[cellnum] { + if len(author)+len(title) < columnWidths[cellnum] { title = fmt.Sprintf("%s%s", title, author) } else { index := columnWidths[cellnum] - len(author) @@ -239,7 +239,7 @@ var listCmd = &cobra.Command{ output := [][]string{{"", "", "MRID", "Title (Author)", "CI", "MRStatus"}} for _, mr := range mrs { - mrx, err := lab.MRGet(rn, int(mr.IID)) + mrx, err := lab.MRGet(rn, mr.IID) if err != nil { log.Fatal(err) } @@ -322,12 +322,12 @@ var listCmd = &cobra.Command{ detailedMergeStatus = fmt.Sprintf("%s(%d/%d)", detailedMergeStatus, len(approvals.ApprovedBy), approvals.ApprovalsRequired) } output = append(output, - []string{mr.WebURL, // weburl (used to convert MRID to URL) - mr.Author.Username, // (Author) - strconv.Itoa(mr.IID), // MRID - mr.Title, // Title - CIStatus, // CI Status - detailedMergeStatus}) // MR Status + []string{mr.WebURL, // weburl (used to convert MRID to URL) + mr.Author.Username, // (Author) + Itoa(mr.IID), // MRID + mr.Title, // Title + CIStatus, // CI Status + detailedMergeStatus}) // MR Status } printColumns(output) }, @@ -345,7 +345,7 @@ func mrList(args []string) ([]*gitlab.BasicMergeRequest, error) { } num, err := strconv.Atoi(mrNumRet) - if err != nil || num == 0 { + if err != nil || num == 0 { num = -1 } @@ -358,7 +358,7 @@ func mrList(args []string) ([]*gitlab.BasicMergeRequest, error) { if approverID == nil { log.Fatalf("%s user not found\n", mrApprover) } - mrApproverID = gitlab.ApproverIDs([]int{*approverID}) + mrApproverID = gitlab.ApproverIDs([]int64{*approverID}) } // gitlab lib still doesn't have search by assignee and author username @@ -412,9 +412,9 @@ func mrList(args []string) ([]*gitlab.BasicMergeRequest, error) { mrReviewerID = gitlab.ReviewerID(*reviewerID) } - orderBy := gitlab.String(mrOrder) + orderBy := gitlab.Ptr(mrOrder) - sort := gitlab.String(mrSortedBy) + sort := gitlab.Ptr(mrSortedBy) // if none of the flags are set, return every single MR mrCheckConflicts := (mrConflicts || mrNoConflicts) @@ -429,14 +429,14 @@ func mrList(args []string) ([]*gitlab.BasicMergeRequest, error) { AuthorID: mrAuthorID, ApprovedByIDs: mrApproverID, AssigneeID: mrAssigneeID, - WithMergeStatusRecheck: gitlab.Bool(mrCheckConflicts), + WithMergeStatusRecheck: gitlab.Ptr(mrCheckConflicts), ReviewerID: mrReviewerID, } if mrDraft && !mrReady { - opts.WIP = gitlab.String("yes") + opts.WIP = gitlab.Ptr("yes") } else if mrReady && !mrDraft { - opts.WIP = gitlab.String("no") + opts.WIP = gitlab.Ptr("no") } if mrExactMatch { @@ -507,7 +507,6 @@ func init() { listCmd.Flags().BoolP("show-status", "", false, "show CI and MR status (slow on projects with large number of MRs)") listCmd.Flags().BoolP("no-unicode", "", false, "Do not use unicode in output") - mrCmd.AddCommand(listCmd) carapace.Gen(listCmd).FlagCompletion(carapace.ActionMap{ "label": carapace.ActionMultiParts(",", func(c carapace.Context) carapace.Action { diff --git a/cmd/mr_merge.go b/cmd/mr_merge.go index 0425085f..46d07052 100644 --- a/cmd/mr_merge.go +++ b/cmd/mr_merge.go @@ -6,9 +6,9 @@ import ( "github.com/MakeNowJust/heredoc/v2" "github.com/rsteube/carapace" "github.com/spf13/cobra" - gitlab "gitlab.com/gitlab-org/api/client-go" "github.com/zaquestion/lab/internal/action" lab "github.com/zaquestion/lab/internal/gitlab" + gitlab "gitlab.com/gitlab-org/api/client-go" ) var mergeImmediate bool @@ -32,10 +32,10 @@ var mrMergeCmd = &cobra.Command{ } opts := gitlab.AcceptMergeRequestOptions{ - MergeWhenPipelineSucceeds: gitlab.Bool(!mergeImmediate), + MergeWhenPipelineSucceeds: gitlab.Ptr(!mergeImmediate), } - err = lab.MRMerge(rn, int(id), &opts) + err = lab.MRMerge(rn, id, &opts) if err != nil { log.Fatal(err) } diff --git a/cmd/mr_rebase.go b/cmd/mr_rebase.go index 112b1038..8db38ab1 100644 --- a/cmd/mr_rebase.go +++ b/cmd/mr_rebase.go @@ -19,7 +19,7 @@ var mrRebaseCmd = &cobra.Command{ } // FIXME use gitlab.RebaseMergeRequestOptions - err = lab.MRRebase(rn, int(id), nil) + err = lab.MRRebase(rn, id, nil) if err != nil { log.Fatal(err) } diff --git a/cmd/mr_reopen.go b/cmd/mr_reopen.go index e5b3aa90..a5e6a85d 100644 --- a/cmd/mr_reopen.go +++ b/cmd/mr_reopen.go @@ -20,7 +20,7 @@ var mrReopenCmd = &cobra.Command{ log.Fatal(err) } - err = lab.MRReopen(rn, int(id)) + err = lab.MRReopen(rn, id) if err != nil { log.Fatal(err) } diff --git a/cmd/mr_show.go b/cmd/mr_show.go index e8284a36..7c0a0a35 100644 --- a/cmd/mr_show.go +++ b/cmd/mr_show.go @@ -6,14 +6,14 @@ import ( "strings" "github.com/MakeNowJust/heredoc/v2" - "github.com/fatih/color" "github.com/charmbracelet/glamour" + "github.com/fatih/color" "github.com/rsteube/carapace" "github.com/spf13/cobra" - gitlab "gitlab.com/gitlab-org/api/client-go" "github.com/zaquestion/lab/internal/action" "github.com/zaquestion/lab/internal/git" lab "github.com/zaquestion/lab/internal/gitlab" + gitlab "gitlab.com/gitlab-org/api/client-go" ) var ( @@ -43,7 +43,7 @@ var mrShowCmd = &cobra.Command{ os.Exit(0x16) // EINVAL } - mr, err := lab.MRGet(rn, int(mrNum)) + mr, err := lab.MRGet(rn, mrNum) if err != nil { log.Fatal(err) } @@ -96,7 +96,7 @@ var mrShowCmd = &cobra.Command{ } if noteLevel != NoteLevelNone { - discussions, err := lab.MRListDiscussions(rn, int(mrNum)) + discussions, err := lab.MRListDiscussions(rn, mrNum) if err != nil { log.Fatal(err) } @@ -106,12 +106,12 @@ var mrShowCmd = &cobra.Command{ log.Fatal(err) } - printDiscussions(rn, discussions, since, "mr", int(mrNum), renderMarkdown, noteLevel) + printDiscussions(rn, discussions, since, "mr", mrNum, renderMarkdown, noteLevel) } }, } -func findLocalRemote(ProjectID int) string { +func findLocalRemote(ProjectID int64) string { var remote string project, err := lab.GetProject(ProjectID) diff --git a/cmd/mr_subscribe.go b/cmd/mr_subscribe.go index 2b60fb1a..f8dc9b55 100644 --- a/cmd/mr_subscribe.go +++ b/cmd/mr_subscribe.go @@ -2,6 +2,7 @@ package cmd import ( "fmt" + "github.com/MakeNowJust/heredoc/v2" "github.com/rsteube/carapace" @@ -24,7 +25,7 @@ var mrSubscribeCmd = &cobra.Command{ log.Fatal(err) } - err = lab.MRSubscribe(rn, int(id)) + err = lab.MRSubscribe(rn, id) if err != nil { log.Fatal(err) } diff --git a/cmd/mr_thumb.go b/cmd/mr_thumb.go index 68cea49f..35819e13 100644 --- a/cmd/mr_thumb.go +++ b/cmd/mr_thumb.go @@ -2,6 +2,7 @@ package cmd import ( "fmt" + "github.com/MakeNowJust/heredoc/v2" "github.com/rsteube/carapace" @@ -31,7 +32,7 @@ var mrThumbUpCmd = &cobra.Command{ log.Fatal(err) } - err = lab.MRThumbUp(rn, int(id)) + err = lab.MRThumbUp(rn, id) if err != nil { log.Fatal(err) } @@ -52,7 +53,7 @@ var mrThumbDownCmd = &cobra.Command{ log.Fatal(err) } - err = lab.MRThumbDown(rn, int(id)) + err = lab.MRThumbDown(rn, id) if err != nil { log.Fatal(err) } diff --git a/cmd/mr_unapprove.go b/cmd/mr_unapprove.go index ff913c33..11a0d521 100644 --- a/cmd/mr_unapprove.go +++ b/cmd/mr_unapprove.go @@ -2,9 +2,10 @@ package cmd import ( "fmt" - "github.com/MakeNowJust/heredoc/v2" "os" + "github.com/MakeNowJust/heredoc/v2" + "github.com/rsteube/carapace" "github.com/spf13/cobra" "github.com/zaquestion/lab/internal/action" @@ -28,7 +29,7 @@ var mrUnapproveCmd = &cobra.Command{ log.Fatal(err) } - approvalConfig, err := lab.GetMRApprovalsConfiguration(rn, int(id)) + approvalConfig, err := lab.GetMRApprovalsConfiguration(rn, id) if err != nil { log.Fatal(err) } @@ -68,14 +69,14 @@ var mrUnapproveCmd = &cobra.Command{ log.Fatal(err) } if comment { - state := noteGetState(rn, true, int(id)) - msg, _ := noteMsg(msgs, true, int(id), state, "", "") + state := noteGetState(rn, true, id) + msg, _ := noteMsg(msgs, true, id, state, "", "") msgs = append(msgs, msg) } } msgs = append(msgs, "/unapprove") - createNote(rn, true, int(id), msgs, filename, linebreak, "", note) + createNote(rn, true, id, msgs, filename, linebreak, "", note) fmt.Printf("Merge Request !%d unapproved\n", id) }, diff --git a/cmd/mr_unsubscribe.go b/cmd/mr_unsubscribe.go index c93e9ab3..1dc9e0ff 100644 --- a/cmd/mr_unsubscribe.go +++ b/cmd/mr_unsubscribe.go @@ -2,6 +2,7 @@ package cmd import ( "fmt" + "github.com/MakeNowJust/heredoc/v2" "github.com/rsteube/carapace" @@ -24,7 +25,7 @@ var mrUnsubscribeCmd = &cobra.Command{ log.Fatal(err) } - err = lab.MRUnsubscribe(rn, int(id)) + err = lab.MRUnsubscribe(rn, id) if err != nil { log.Fatal(err) } diff --git a/cmd/note_common.go b/cmd/note_common.go index 24b5f73f..f13fa876 100644 --- a/cmd/note_common.go +++ b/cmd/note_common.go @@ -13,9 +13,9 @@ import ( "github.com/MakeNowJust/heredoc/v2" "github.com/spf13/cobra" - gitlab "gitlab.com/gitlab-org/api/client-go" "github.com/zaquestion/lab/internal/git" lab "github.com/zaquestion/lab/internal/gitlab" + gitlab "gitlab.com/gitlab-org/api/client-go" ) func noteRunFn(cmd *cobra.Command, args []string) { @@ -31,7 +31,7 @@ func noteRunFn(cmd *cobra.Command, args []string) { var ( rn string - idNum int = 0 + idNum int64 = 0 ) if isMR { @@ -40,7 +40,7 @@ func noteRunFn(cmd *cobra.Command, args []string) { fmt.Println("Error: Cannot determine MR id.") os.Exit(1) } - idNum = int(mrNum) + idNum = mrNum rn = s } else { s, issueNum, _ := parseArgsRemoteAndID(branchArgs) @@ -48,7 +48,7 @@ func noteRunFn(cmd *cobra.Command, args []string) { fmt.Println("Error: Cannot determine issue id.") os.Exit(1) } - idNum = int(issueNum) + idNum = issueNum rn = s } @@ -87,14 +87,14 @@ func noteRunFn(cmd *cobra.Command, args []string) { log.Fatal(err) } - replyNote(rn, isMR, int(idNum), reply, quote, false, filename, linebreak, resolve, msgs) + replyNote(rn, isMR, idNum, reply, quote, false, filename, linebreak, resolve, msgs) return } - createNote(rn, isMR, int(idNum), msgs, filename, linebreak, commit, true) + createNote(rn, isMR, idNum, msgs, filename, linebreak, commit, true) } -func createCommitNote(rn string, mrID int, sha string, newFile string, oldFile string, linetype string, oldline int, newline int, comment string, block bool) { +func createCommitNote(rn string, mrID int64, sha string, newFile string, oldFile string, linetype string, oldline int64, newline int64, comment string, block bool) { line := oldline if oldline == -1 { line = newline @@ -136,7 +136,7 @@ func getCommitBody(project string, commit string) (body string) { return body } -func createCommitComments(project string, mrID int, commit string, body string, block bool) { +func createCommitComments(project string, mrID int64, commit string, body string, block bool) { // Go through the body line-by-line and find lines that do not // begin with |. These lines are comments that have been made // on the patch. The lines that begin with | contain patch @@ -210,7 +210,7 @@ func createCommitComments(project string, mrID int, commit string, body string, } } - createCommitNote(project, mrID, commit, newfile, oldfile, linetype, oldLineNum, newLineNum, comments, block) + createCommitNote(project, mrID, commit, newfile, oldfile, linetype, int64(oldLineNum), int64(newLineNum), comments, block) comments = "" } @@ -245,7 +245,7 @@ func createCommitComments(project string, mrID int, commit string, body string, } } -func noteGetState(rn string, isMR bool, idNum int) (state string) { +func noteGetState(rn string, isMR bool, idNum int64) (state string) { if isMR { mr, err := lab.MRGet(rn, idNum) if err != nil { @@ -272,7 +272,7 @@ func noteGetState(rn string, isMR bool, idNum int) (state string) { return state } -func createNote(rn string, isMR bool, idNum int, msgs []string, filename string, linebreak bool, commit string, hasNote bool) { +func createNote(rn string, isMR bool, idNum int64, msgs []string, filename string, linebreak bool, commit string, hasNote bool) { // hasNote is used by action that take advantage of Gitlab 'quick-action' notes, which do not create a noteURL var err error @@ -314,7 +314,7 @@ func createNote(rn string, isMR bool, idNum int, msgs []string, filename string, if isMR { if commit != "" { - createCommitComments(rn, int(idNum), commit, body, false) + createCommitComments(rn, idNum, commit, body, false) } else { noteURL, err = lab.MRCreateNote(rn, idNum, &gitlab.CreateMergeRequestNoteOptions{ Body: &body, @@ -333,7 +333,7 @@ func createNote(rn string, isMR bool, idNum int, msgs []string, filename string, } } -func noteMsg(msgs []string, isMR bool, idNum int, state string, commit string, body string) (string, error) { +func noteMsg(msgs []string, isMR bool, idNum int64, state string, commit string, body string) (string, error) { if len(msgs) > 0 { return strings.Join(msgs[0:], "\n\n"), nil } @@ -370,7 +370,7 @@ func noteGetTemplate(isMR bool, commit string) string { {{.CommentChar}} Comment lines beginning with '{{.CommentChar}}' are discarded.`) } -func noteText(idNum int, state string, commit string, body string, tmpl string) (string, error) { +func noteText(idNum int64, state string, commit string, body string, tmpl string) (string, error) { initMsg := body commentChar := git.CommentChar() @@ -389,7 +389,7 @@ func noteText(idNum int, state string, commit string, body string, tmpl string) InitMsg string CommentChar string State string - IDnum int + IDnum int64 Commit string }{ InitMsg: initMsg, @@ -408,7 +408,7 @@ func noteText(idNum int, state string, commit string, body string, tmpl string) return b.String(), nil } -func replyNote(rn string, isMR bool, idNum int, reply int, quote bool, update bool, filename string, linebreak bool, resolve bool, msgs []string) { +func replyNote(rn string, isMR bool, idNum int64, reply int64, quote bool, update bool, filename string, linebreak bool, resolve bool, msgs []string) { var ( discussions []*gitlab.Discussion diff --git a/cmd/project_create.go b/cmd/project_create.go index 3293b1f6..93ef6394 100644 --- a/cmd/project_create.go +++ b/cmd/project_create.go @@ -6,9 +6,9 @@ import ( "github.com/MakeNowJust/heredoc/v2" "github.com/spf13/cobra" - "gitlab.com/gitlab-org/api/client-go" "github.com/zaquestion/lab/internal/git" lab "github.com/zaquestion/lab/internal/gitlab" + gitlab "gitlab.com/gitlab-org/api/client-go" ) // projectCreateCmd represents the create command @@ -52,7 +52,7 @@ var projectCreateCmd = &cobra.Command{ group = g } - var namespaceID *int + var namespaceID *int64 if group != "" { groupObj, err := lab.GroupSearch(group) if err != nil { @@ -80,11 +80,11 @@ var projectCreateCmd = &cobra.Command{ // if namespaceID is nil, the project will be created in user's // namespace NamespaceID: namespaceID, - Path: gitlab.String(path), - Name: gitlab.String(name), - Description: gitlab.String(desc), + Path: gitlab.Ptr(path), + Name: gitlab.Ptr(name), + Description: gitlab.Ptr(desc), Visibility: &visibility, - ApprovalsBeforeMerge: gitlab.Int(0), + ApprovalsBeforeMerge: gitlab.Ptr(int64(0)), } p, err := lab.ProjectCreate(&opts) if err != nil { diff --git a/cmd/project_create_test.go b/cmd/project_create_test.go index bb0c5a8d..2ff7396c 100644 --- a/cmd/project_create_test.go +++ b/cmd/project_create_test.go @@ -11,6 +11,7 @@ import ( "github.com/stretchr/testify/require" "github.com/zaquestion/lab/internal/git" lab "github.com/zaquestion/lab/internal/gitlab" + gitlab "gitlab.com/gitlab-org/api/client-go" ) func Test_projectCreateCmd(t *testing.T) { @@ -53,7 +54,7 @@ func Test_projectCreateCmd(t *testing.T) { if err != nil { t.Fatal(errors.Wrap(err, "failed to find project for cleanup")) } - err = lab.ProjectDelete(p.ID) + err = lab.ProjectDelete(p.ID, &gitlab.DeleteProjectOptions{}) if err != nil { t.Fatal(errors.Wrap(err, "failed to delete project during cleanup")) } diff --git a/cmd/project_list.go b/cmd/project_list.go index 91f21222..7bb2be81 100644 --- a/cmd/project_list.go +++ b/cmd/project_list.go @@ -2,12 +2,13 @@ package cmd import ( "fmt" - "github.com/MakeNowJust/heredoc/v2" "strconv" + "github.com/MakeNowJust/heredoc/v2" + "github.com/spf13/cobra" - "gitlab.com/gitlab-org/api/client-go" lab "github.com/zaquestion/lab/internal/gitlab" + gitlab "gitlab.com/gitlab-org/api/client-go" ) var projectListConfig struct { @@ -42,15 +43,15 @@ var projectListCmd = &cobra.Command{ opt := gitlab.ListProjectsOptions{ ListOptions: gitlab.ListOptions{ - PerPage: num, + PerPage: int64(num), }, - Simple: gitlab.Bool(true), - OrderBy: gitlab.String("id"), - Sort: gitlab.String("asc"), - Owned: gitlab.Bool(projectListConfig.Owned), - Membership: gitlab.Bool(projectListConfig.Membership), - Starred: gitlab.Bool(projectListConfig.Starred), - Search: gitlab.String(search), + Simple: gitlab.Ptr(true), + OrderBy: gitlab.Ptr("id"), + Sort: gitlab.Ptr("asc"), + Owned: gitlab.Ptr(projectListConfig.Owned), + Membership: gitlab.Ptr(projectListConfig.Membership), + Starred: gitlab.Ptr(projectListConfig.Starred), + Search: gitlab.Ptr(search), } projects, err := lab.ProjectList(opt, num) if err != nil { diff --git a/cmd/show_common.go b/cmd/show_common.go index eec53167..49b6f9c7 100644 --- a/cmd/show_common.go +++ b/cmd/show_common.go @@ -4,7 +4,6 @@ import ( "bufio" "fmt" "regexp" - "strconv" "strings" "time" @@ -15,21 +14,21 @@ import ( "github.com/fatih/color" "github.com/jaytaylor/html2text" "github.com/muesli/termenv" - gitlab "gitlab.com/gitlab-org/api/client-go" "github.com/zaquestion/lab/internal/config" lab "github.com/zaquestion/lab/internal/gitlab" + gitlab "gitlab.com/gitlab-org/api/client-go" ) -func inRange(val int, min int, max int) bool { - return val >= min && val <= max +func inRange(val int64, min int64, max int64) bool { + return val >= int64(min) && val <= int64(max) } // maxPadding returns the max value of two string numbers -func maxPadding(x int, y int) int { +func maxPadding(x int64, y int64) int { if x > y { - return len(strconv.Itoa(x)) + return len(Itoa(x)) } - return len(strconv.Itoa(y)) + return len(Itoa(y)) } // printDiffLine does a color print of a diff lines. Red lines are removals @@ -46,10 +45,10 @@ func printDiffLine(strColor string, maxChars int, sOld string, sNew string, ltex } // displayDiff displays the diff referenced in a discussion -func displayDiff(diff string, newLine int, oldLine int, outputAll bool) string { +func displayDiff(diff string, newLine int64, oldLine int64, outputAll bool) string { var ( - oldLineNum int = 0 - newLineNum int = 0 + oldLineNum int64 = 0 + newLineNum int64 = 0 maxChars int output bool = false diffOutput string = "" @@ -63,13 +62,13 @@ func displayDiff(diff string, newLine int, oldLine int, outputAll bool) string { dNew := strings.Split(s[2], ",") // get the new line number of the first line of the diff - newDiffStart, err := strconv.Atoi(strings.Replace(dNew[0], "+", "", -1)) + newDiffStart, err := Atoi(strings.Replace(dNew[0], "+", "", -1)) if err != nil { log.Fatal(err) } - newDiffRange := 1 + var newDiffRange int64 = 1 if len(dNew) == 2 { - newDiffRange, err = strconv.Atoi(dNew[1]) + newDiffRange, err = Atoi(dNew[1]) if err != nil { log.Fatal(err) } @@ -78,7 +77,7 @@ func displayDiff(diff string, newLine int, oldLine int, outputAll bool) string { newLineNum = newDiffStart - 1 // get the old line number of the first line of the diff - oldDiffStart, err := strconv.Atoi(strings.Replace(dOld[0], "-", "", -1)) + oldDiffStart, err := Atoi(strings.Replace(dOld[0], "-", "", -1)) if err != nil { log.Fatal(err) } @@ -86,7 +85,7 @@ func displayDiff(diff string, newLine int, oldLine int, outputAll bool) string { oldDiffEnd := newDiffRange oldLineNum = oldDiffStart - 1 if len(dOld) > 1 { - oldDiffRange, err := strconv.Atoi(dOld[1]) + oldDiffRange, err := Atoi(dOld[1]) if err != nil { log.Fatal(err) } @@ -131,18 +130,18 @@ func displayDiff(diff string, newLine int, oldLine int, outputAll bool) string { strColor = "" oldLineNum++ newLineNum++ - sOld = strconv.Itoa(oldLineNum) - sNew = strconv.Itoa(newLineNum) + sOld = Itoa(oldLineNum) + sNew = Itoa(newLineNum) case "-": strColor = "red" oldLineNum++ - sOld = strconv.Itoa(oldLineNum) + sOld = Itoa(oldLineNum) sNew = " " case "+": strColor = "green" newLineNum++ sOld = " " - sNew = strconv.Itoa(newLineNum) + sNew = Itoa(newLineNum) } // output line @@ -162,7 +161,7 @@ func displayDiff(diff string, newLine int, oldLine int, outputAll bool) string { return diffOutput } -func displayCommitDiscussion(project string, idNum int, note *gitlab.Note) { +func displayCommitDiscussion(project string, idNum int64, note *gitlab.Note) { // Previously, the GitLab API only supports showing comments on the // entire changeset and not per-commit. IOW, all diffs were shown @@ -249,7 +248,7 @@ const ( NoteLevelFull ) -func printDiscussions(project string, discussions []*gitlab.Discussion, since string, idstr string, idNum int, renderMarkdown bool, noteLevel int) { +func printDiscussions(project string, discussions []*gitlab.Discussion, since string, idstr string, idNum int64, renderMarkdown bool, noteLevel int) { newAccessTime := time.Now().UTC() issueEntry := fmt.Sprintf("%s%d", idstr, idNum) diff --git a/cmd/snippet_create.go b/cmd/snippet_create.go index ffa8f21b..f1cd2aa8 100644 --- a/cmd/snippet_create.go +++ b/cmd/snippet_create.go @@ -83,10 +83,10 @@ var snippetCreateCmd = &cobra.Command{ rn, _ := git.PathWithNamespace(remote) if global || rn == "" { opts := gitlab.CreateSnippetOptions{ - Title: gitlab.String(title), - Description: gitlab.String(body), - Content: gitlab.String(code), - FileName: gitlab.String(name), + Title: gitlab.Ptr(title), + Description: gitlab.Ptr(body), + Content: gitlab.Ptr(code), + FileName: gitlab.Ptr(name), Visibility: &visibility, } snip, err := lab.SnippetCreate(&opts) @@ -98,10 +98,10 @@ var snippetCreateCmd = &cobra.Command{ } opts := gitlab.CreateProjectSnippetOptions{ - Title: gitlab.String(title), - Description: gitlab.String(body), - Content: gitlab.String(code), - FileName: gitlab.String(name), + Title: gitlab.Ptr(title), + Description: gitlab.Ptr(body), + Content: gitlab.Ptr(code), + FileName: gitlab.Ptr(name), Visibility: &visibility, } snip, err := lab.ProjectSnippetCreate(rn, &opts) diff --git a/cmd/snippet_delete.go b/cmd/snippet_delete.go index e9f4857a..dc4c1ed6 100644 --- a/cmd/snippet_delete.go +++ b/cmd/snippet_delete.go @@ -2,6 +2,7 @@ package cmd import ( "fmt" + "github.com/MakeNowJust/heredoc/v2" "github.com/rsteube/carapace" @@ -24,7 +25,7 @@ var snippetDeleteCmd = &cobra.Command{ log.Fatal(err) } if global || rn == "" { - err = lab.SnippetDelete(int(id)) + err = lab.SnippetDelete(id) if err != nil { log.Fatal(err) } @@ -32,7 +33,7 @@ var snippetDeleteCmd = &cobra.Command{ return } - err = lab.ProjectSnippetDelete(rn, int(id)) + err = lab.ProjectSnippetDelete(rn, id) if err != nil { log.Fatal(err) } diff --git a/cmd/snippet_list.go b/cmd/snippet_list.go index d6d98375..b3f7f4b8 100644 --- a/cmd/snippet_list.go +++ b/cmd/snippet_list.go @@ -2,14 +2,15 @@ package cmd import ( "fmt" - "github.com/MakeNowJust/heredoc/v2" "strconv" + "github.com/MakeNowJust/heredoc/v2" + "github.com/rsteube/carapace" "github.com/spf13/cobra" - gitlab "gitlab.com/gitlab-org/api/client-go" "github.com/zaquestion/lab/internal/action" lab "github.com/zaquestion/lab/internal/gitlab" + gitlab "gitlab.com/gitlab-org/api/client-go" ) var snippetListConfig struct { @@ -55,17 +56,17 @@ func snippetList(args []string) ([]*gitlab.Snippet, error) { } listOpts := gitlab.ListOptions{ - PerPage: num, + PerPage: int64(num), } // See if we're in a git repo or if global is set to determine // if this should be a personal snippet if global || rn == "" { - opts := gitlab.ListSnippetsOptions(listOpts) + opts := gitlab.ListSnippetsOptions{ListOptions: listOpts} return lab.SnippetList(opts, num) } - opts := gitlab.ListProjectSnippetsOptions(listOpts) + opts := gitlab.ListProjectSnippetsOptions{ListOptions: listOpts} return lab.ProjectSnippetList(rn, opts, num) } diff --git a/cmd/todo_done.go b/cmd/todo_done.go index f1512fd1..9bfc91d3 100644 --- a/cmd/todo_done.go +++ b/cmd/todo_done.go @@ -2,8 +2,8 @@ package cmd import ( "fmt" + "github.com/MakeNowJust/heredoc/v2" - "strconv" "github.com/spf13/cobra" lab "github.com/zaquestion/lab/internal/gitlab" @@ -35,7 +35,7 @@ var todoDoneCmd = &cobra.Command{ if len(args) == 0 { log.Fatalf("Specify todo id to be marked as done") } - toDoNum, err := strconv.Atoi(args[0]) + toDoNum, err := Atoi(args[0]) if err != nil { log.Fatal(err) } diff --git a/cmd/todo_issue.go b/cmd/todo_issue.go index 335ebdec..17c70214 100644 --- a/cmd/todo_issue.go +++ b/cmd/todo_issue.go @@ -21,12 +21,12 @@ var todoIssueCmd = &cobra.Command{ log.Fatal(err) } - todoAddIssue(rn, int(num)) + todoAddIssue(rn, num) }, } -func todoAddIssue(project string, issueNum int) { +func todoAddIssue(project string, issueNum int64) { todoID, err := lab.TodoIssueCreate(project, issueNum) if err != nil { if err == lab.ErrNotModified { diff --git a/cmd/todo_list.go b/cmd/todo_list.go index 47a7bb4c..19ebe3b9 100644 --- a/cmd/todo_list.go +++ b/cmd/todo_list.go @@ -2,14 +2,15 @@ package cmd import ( "fmt" - "github.com/MakeNowJust/heredoc/v2" "strconv" "strings" + "github.com/MakeNowJust/heredoc/v2" + "github.com/fatih/color" "github.com/spf13/cobra" - gitlab "gitlab.com/gitlab-org/api/client-go" lab "github.com/zaquestion/lab/internal/gitlab" + gitlab "gitlab.com/gitlab-org/api/client-go" ) var ( @@ -113,7 +114,7 @@ func todoList(args []string) ([]*gitlab.Todo, error) { opts := gitlab.ListTodosOptions{ ListOptions: gitlab.ListOptions{ - PerPage: num, + PerPage: int64(num), }, } diff --git a/cmd/todo_mr.go b/cmd/todo_mr.go index 11954d4e..f7e2fa66 100644 --- a/cmd/todo_mr.go +++ b/cmd/todo_mr.go @@ -21,11 +21,11 @@ var todoMRCmd = &cobra.Command{ log.Fatal(err) } - todoAddMergeRequest(rn, int(num)) + todoAddMergeRequest(rn, num) }, } -func todoAddMergeRequest(remote string, mrNum int) { +func todoAddMergeRequest(remote string, mrNum int64) { todoID, err := lab.TodoMRCreate(remote, mrNum) if err != nil { if err == lab.ErrNotModified { diff --git a/cmd/token_revoke.go b/cmd/token_revoke.go index d1b42bd9..b2b7c7b2 100644 --- a/cmd/token_revoke.go +++ b/cmd/token_revoke.go @@ -1,8 +1,6 @@ package cmd import ( - "strconv" - "github.com/MakeNowJust/heredoc/v2" "github.com/spf13/cobra" @@ -18,10 +16,10 @@ var tokenRevokeCmd = &cobra.Command{ PersistentPreRun: labPersistentPreRun, Run: func(cmd *cobra.Command, args []string) { - id := 0 + var id int64 = 0 if len(args) == 1 { var err error - id, err = strconv.Atoi(args[0]) + id, err = Atoi(args[0]) if err != nil { log.Fatal(err) } diff --git a/cmd/util.go b/cmd/util.go index 0440a6cf..e14d632a 100644 --- a/cmd/util.go +++ b/cmd/util.go @@ -16,10 +16,10 @@ import ( "github.com/spf13/viper" gitconfig "github.com/tcnksm/go-gitconfig" giturls "github.com/whilp/git-urls" - gitlab "gitlab.com/gitlab-org/api/client-go" "github.com/zaquestion/lab/internal/config" "github.com/zaquestion/lab/internal/git" lab "github.com/zaquestion/lab/internal/gitlab" + gitlab "gitlab.com/gitlab-org/api/client-go" "golang.org/x/crypto/ssh/terminal" ) @@ -83,9 +83,19 @@ func flagConfig(fs *flag.FlagSet) { } } +// Atoi is like strconv.Atoi, but kept as an int64 +func Atoi(s string) (int64, error) { + return strconv.ParseInt(s, 10, 0) +} + +// Itoa is like strconv.Itoa, but for int64 +func Itoa(i int64) string { + return strconv.FormatInt(i, 10) +} + // getCurrentBranchMR returns the MR ID associated with the current branch. // If a MR ID cannot be found, the function returns 0. -func getCurrentBranchMR(rn string) int { +func getCurrentBranchMR(rn string) int64 { currentBranch, err := git.CurrentBranch() if err != nil { return 0 @@ -94,8 +104,8 @@ func getCurrentBranchMR(rn string) int { return getBranchMR(rn, currentBranch) } -func getBranchMR(rn, branch string) int { - var num int = 0 +func getBranchMR(rn, branch string) int64 { + var num int64 = 0 mrBranch, err := git.UpstreamBranch(branch) if err != nil { @@ -120,8 +130,8 @@ func getBranchMR(rn, branch string) int { mrs, err := lab.MRList(rn, gitlab.ListProjectMergeRequestsOptions{ State: &mrState, - OrderBy: gitlab.String("updated_at"), - SourceBranch: gitlab.String(mrBranch), + OrderBy: gitlab.Ptr("updated_at"), + SourceBranch: gitlab.Ptr(mrBranch), }, -1) if err != nil { log.Fatal(err) @@ -230,14 +240,14 @@ func parseArgsRemoteAndBranch(args []string) (string, string, error) { return remote, branch, nil } -func getPipelineFromArgs(args []string, forMR bool) (string, int, error) { +func getPipelineFromArgs(args []string, forMR bool) (string, int64, error) { if forMR { rn, mrNum, err := parseArgsWithGitBranchMR(args) if err != nil { return "", 0, err } - mr, err := lab.MRGet(rn, int(mrNum)) + mr, err := lab.MRGet(rn, mrNum) if err != nil { return "", 0, err } @@ -376,7 +386,7 @@ func parseArgsWithGitBranchMR(args []string) (string, int64, error) { // filterCommentArg separate the case where a command can have both the // remote and ":" at the same time. -func filterCommentArg(args []string) (int, []string, error) { +func filterCommentArg(args []string) (int64, []string, error) { branchArgs := []string{} idString := "" @@ -404,7 +414,7 @@ func filterCommentArg(args []string) (int, []string, error) { idString = "" } - idNum, _ := strconv.Atoi(idString) + idNum, _ := Atoi(idString) return idNum, branchArgs, nil } @@ -642,10 +652,10 @@ func same(a, b []string) bool { } // getUser returns the userID for use with other GitLab API calls. -func getUserID(user string) *int { +func getUserID(user string) *int64 { var ( err error - userID int + userID int64 ) if user == "" { @@ -668,12 +678,12 @@ func getUserID(user string) *int { return nil } - return gitlab.Int(userID) + return gitlab.Ptr(userID) } // getUsers returns the userIDs for use with other GitLab API calls. -func getUserIDs(users []string) []int { - var ids []int +func getUserIDs(users []string) []int64 { + var ids []int64 for _, user := range users { userID := getUserID(user) if userID != nil { @@ -720,6 +730,7 @@ func mapLabelsAsLabelOptions(rn string, labelTerms []string) (gitlab.LabelOption return gitlab.LabelOptions(matches), nil } + // dumpToken dumps information about a specific Personal Access Token func dumpToken(tokendata *gitlab.PersonalAccessToken) { fmt.Println("ID: ", tokendata.ID) diff --git a/go.mod b/go.mod index a003d1ca..be2d2fd5 100644 --- a/go.mod +++ b/go.mod @@ -21,9 +21,9 @@ require ( github.com/spf13/cobra v1.8.0 github.com/spf13/pflag v1.0.5 github.com/spf13/viper v1.18.2 - github.com/stretchr/testify v1.10.0 + github.com/stretchr/testify v1.11.1 github.com/tcnksm/go-gitconfig v0.1.2 - gitlab.com/gitlab-org/api/client-go v0.126.0 + gitlab.com/gitlab-org/api/client-go v1.0.0 golang.org/x/crypto v0.18.0 ) @@ -35,7 +35,7 @@ require ( github.com/sagikazarmark/slog-shim v0.1.0 // indirect github.com/sourcegraph/conc v0.3.0 // indirect go.uber.org/multierr v1.11.0 // indirect - golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc // indirect + golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect ) require ( @@ -49,7 +49,7 @@ require ( github.com/google/go-querystring v1.1.0 // indirect github.com/gorilla/css v1.0.1 // indirect github.com/hashicorp/go-cleanhttp v0.5.2 // indirect - github.com/hashicorp/go-retryablehttp v0.7.7 // indirect + github.com/hashicorp/go-retryablehttp v0.7.8 // indirect github.com/hashicorp/hcl v1.0.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/lucasb-eyer/go-colorful v1.2.0 // indirect @@ -72,16 +72,14 @@ require ( github.com/yuin/goldmark v1.6.0 // indirect github.com/yuin/goldmark-emoji v1.0.2 // indirect golang.org/x/net v0.20.0 // indirect - golang.org/x/oauth2 v0.25.0 // indirect - golang.org/x/sys v0.20.0 // indirect + golang.org/x/oauth2 v0.30.0 // indirect + golang.org/x/sys v0.34.0 // indirect golang.org/x/term v0.16.0 - golang.org/x/text v0.14.0 // indirect - golang.org/x/time v0.10.0 // indirect + golang.org/x/text v0.28.0 // indirect + golang.org/x/time v0.12.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) -go 1.22 - -toolchain go1.22.12 +go 1.24 diff --git a/go.sum b/go.sum index d2ff9f81..599c031a 100644 --- a/go.sum +++ b/go.sum @@ -52,6 +52,8 @@ github.com/hashicorp/go-hclog v1.6.3 h1:Qr2kF+eVWjTiYmU7Y31tYlP1h0q/X3Nl3tPGdaB1 github.com/hashicorp/go-hclog v1.6.3/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M= github.com/hashicorp/go-retryablehttp v0.7.7 h1:C8hUCYzor8PIfXHa4UrZkU4VvK8o9ISHxT2Q8+VepXU= github.com/hashicorp/go-retryablehttp v0.7.7/go.mod h1:pkQpWZeYWskR+D1tR2O5OcBFOxfA7DoAO6xtkuQnHTk= +github.com/hashicorp/go-retryablehttp v0.7.8 h1:ylXZWnqa7Lhqpk0L1P1LzDtGcCR0rPVUrx/c8Unxc48= +github.com/hashicorp/go-retryablehttp v0.7.8/go.mod h1:rjiScheydd+CxvumBsIrFKlx3iS0jrZ7LvzFGFmuKbw= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= @@ -154,6 +156,7 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= github.com/tcnksm/go-gitconfig v0.1.2 h1:iiDhRitByXAEyjgBqsKi9QU4o2TNtv9kPP3RgPgXBPw= @@ -171,6 +174,10 @@ github.com/yuin/goldmark-emoji v1.0.2 h1:c/RgTShNgHTtc6xdz2KKI74jJr6rWi7FPgnP9GA github.com/yuin/goldmark-emoji v1.0.2/go.mod h1:RhP/RWpexdp+KHs7ghKnifRoIs/Bq4nDS7tRbCkOwKY= gitlab.com/gitlab-org/api/client-go v0.126.0 h1:VV5TdkF6pMbEdFGvbR2CwEgJwg6qdg1u3bj5eD2tiWk= gitlab.com/gitlab-org/api/client-go v0.126.0/go.mod h1:bYC6fPORKSmtuPRyD9Z2rtbAjE7UeNatu2VWHRf4/LE= +gitlab.com/gitlab-org/api/client-go v0.159.0 h1:ibKeribio/OCsrsUz7pkgIN4E7HWDyrw/lDR6P2R7lU= +gitlab.com/gitlab-org/api/client-go v0.159.0/go.mod h1:D0DHF7ILUfFo/JcoGMAEndiKMm8SiP/WjyJ4OfXxCKw= +gitlab.com/gitlab-org/api/client-go v1.0.0 h1:k1kdiJRPHNNPveJ5Kww8MAGZFJCMaItLuLyDZ8j0/Ns= +gitlab.com/gitlab-org/api/client-go v1.0.0/go.mod h1:hxFLApm0RqUWU3xmXCrRpxO47BQnAIWdZh9VtMaV648= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= @@ -179,6 +186,8 @@ golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc= golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg= golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc h1:ao2WRsKSzW6KuUY9IWPwWahcHCgR0s52IfwutMfEbdM= golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI= +golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 h1:vr/HnozRka3pE4EsMEg1lgkXJkTFJCVUX+S/ZT6wYzM= +golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842/go.mod h1:XtvwrStGgqGPLc4cjQfWqZHG1YFdYs6swckp8vpsjnc= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -191,6 +200,8 @@ golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo= golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY= golang.org/x/oauth2 v0.25.0 h1:CY4y7XT9v0cRI9oupztF8AgiIu99L/ksR/Xp/6jrZ70= golang.org/x/oauth2 v0.25.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= +golang.org/x/oauth2 v0.30.0 h1:dnDm7JmhM45NNpd8FDDeLhK6FwqbOf4MLCM9zb1BOHI= +golang.org/x/oauth2 v0.30.0/go.mod h1:B++QgG3ZKulg6sRPGD/mqlHQs5rB3Ml9erfeDY7xKlU= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -208,6 +219,8 @@ golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.34.0 h1:H5Y5sJ2L2JRdyv7ROF1he/lPdvFsd0mJHFw2ThKHxLA= +golang.org/x/sys v0.34.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= @@ -220,8 +233,12 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng= +golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU= golang.org/x/time v0.10.0 h1:3usCWA8tQn0L8+hFJQNgzpWbd89begxN66o1Ojdn5L4= golang.org/x/time v0.10.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= +golang.org/x/time v0.12.0 h1:ScB/8o8olJvc+CQPWrK3fPZNfh7qgwCrY0zJmoEQLSE= +golang.org/x/time v0.12.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= diff --git a/internal/action/action.go b/internal/action/action.go index 058eb974..bc095a01 100644 --- a/internal/action/action.go +++ b/internal/action/action.go @@ -7,9 +7,9 @@ import ( "github.com/rsteube/carapace" "github.com/rsteube/carapace/pkg/cache" - "gitlab.com/gitlab-org/api/client-go" "github.com/zaquestion/lab/internal/git" lab "github.com/zaquestion/lab/internal/gitlab" + gitlab "gitlab.com/gitlab-org/api/client-go" ) // Remotes returns a carapace.Action containing all possible remote values @@ -49,7 +49,7 @@ func Snippets(snippetList func(args []string) ([]*gitlab.Snippet, error)) carapa values := make([]string, len(snips)*2) for index, snip := range snips { - values[index*2] = strconv.Itoa(snip.ID) + values[index*2] = strconv.FormatInt(snip.ID, 10) values[index*2+1] = snip.Title } return carapace.ActionValuesDescribed(values...) @@ -66,7 +66,7 @@ func Issues(issueList func(args []string) ([]*gitlab.Issue, error)) carapace.Act values := make([]string, len(issues)*2) for index, issue := range issues { - values[index*2] = strconv.Itoa(issue.IID) + values[index*2] = strconv.FormatInt(issue.IID, 10) values[index*2+1] = issue.Title } return carapace.ActionValuesDescribed(values...) @@ -84,7 +84,7 @@ func MergeRequests(mrList func(args []string) ([]*gitlab.BasicMergeRequest, erro values := make([]string, len(mergeRequests)*2) for index, mergeRequest := range mergeRequests { - values[index*2] = strconv.Itoa(mergeRequest.IID) + values[index*2] = strconv.FormatInt(mergeRequest.IID, 10) values[index*2+1] = mergeRequest.Title } return carapace.ActionValuesDescribed(values...) diff --git a/internal/gitlab/gitlab.go b/internal/gitlab/gitlab.go index e0e9934b..1e5f9266 100644 --- a/internal/gitlab/gitlab.go +++ b/internal/gitlab/gitlab.go @@ -20,9 +20,9 @@ import ( "time" "github.com/pkg/errors" - gitlab "gitlab.com/gitlab-org/api/client-go" "github.com/zaquestion/lab/internal/git" "github.com/zaquestion/lab/internal/logger" + gitlab "gitlab.com/gitlab-org/api/client-go" ) // Get internal lab logger instance @@ -61,7 +61,7 @@ func User() string { } // UserID get the current user ID from gitlab server -func UserID() (int, error) { +func UserID() (int64, error) { u, _, err := lab.Users.CurrentUser() if err != nil { return 0, err @@ -275,7 +275,7 @@ func Fork(projID interface{}, opts *gitlab.ForkProjectOptions, useHTTP bool, wai } else if optPath != "" { name = optPath } else { - opts.Name = gitlab.String(name) + opts.Name = gitlab.Ptr(name) } } @@ -366,7 +366,7 @@ func MRCreate(projID interface{}, opts *gitlab.CreateMergeRequestOptions) (strin } // MRCreateDiscussion creates a discussion on a merge request on GitLab -func MRCreateDiscussion(projID interface{}, id int, opts *gitlab.CreateMergeRequestDiscussionOptions) (string, error) { +func MRCreateDiscussion(projID interface{}, id int64, opts *gitlab.CreateMergeRequestDiscussionOptions) (string, error) { discussion, _, err := lab.Discussions.CreateMergeRequestDiscussion(projID, id, opts) if err != nil { return "", err @@ -384,7 +384,7 @@ func MRCreateDiscussion(projID interface{}, id int, opts *gitlab.CreateMergeRequ } // MRUpdate edits an merge request on a GitLab project -func MRUpdate(projID interface{}, id int, opts *gitlab.UpdateMergeRequestOptions) (string, error) { +func MRUpdate(projID interface{}, id int64, opts *gitlab.UpdateMergeRequestOptions) (string, error) { mr, _, err := lab.MergeRequests.UpdateMergeRequest(projID, id, opts) if err != nil { return "", err @@ -394,8 +394,8 @@ func MRUpdate(projID interface{}, id int, opts *gitlab.UpdateMergeRequestOptions } // MRDelete deletes an merge request on a GitLab project -func MRDelete(projID interface{}, id int) error { - resp, err := lab.MergeRequests.DeleteMergeRequest(projID, id) +func MRDelete(projID interface{}, id int64) error { + resp, err := lab.MergeRequests.DeleteMergeRequest(projID, int64(id)) if resp != nil && resp.StatusCode == http.StatusForbidden { return ErrStatusForbidden } @@ -406,7 +406,7 @@ func MRDelete(projID interface{}, id int) error { } // MRCreateNote adds a note to a merge request on GitLab -func MRCreateNote(projID interface{}, id int, opts *gitlab.CreateMergeRequestNoteOptions) (string, error) { +func MRCreateNote(projID interface{}, id int64, opts *gitlab.CreateMergeRequestNoteOptions) (string, error) { note, _, err := lab.Notes.CreateMergeRequestNote(projID, id, opts) if err != nil { return "", err @@ -422,7 +422,7 @@ func MRCreateNote(projID interface{}, id int, opts *gitlab.CreateMergeRequestNot } // MRGet retrieves the merge request from GitLab project -func MRGet(projID interface{}, id int) (*gitlab.MergeRequest, error) { +func MRGet(projID interface{}, id int64) (*gitlab.MergeRequest, error) { mr, _, err := lab.MergeRequests.GetMergeRequest(projID, id, nil) if err != nil { return nil, err @@ -437,7 +437,7 @@ func MRList(projID interface{}, opts gitlab.ListProjectMergeRequestsOptions, n i for true { opts.PerPage = maxItemsPerPage if n != -1 { - opts.PerPage = n - len(list) + opts.PerPage = int64(n - len(list)) if opts.PerPage > maxItemsPerPage { opts.PerPage = maxItemsPerPage } @@ -451,7 +451,6 @@ func MRList(projID interface{}, opts gitlab.ListProjectMergeRequestsOptions, n i if n != -1 && len(list) >= n { return list[:n], nil - break } var ok bool @@ -464,7 +463,7 @@ func MRList(projID interface{}, opts gitlab.ListProjectMergeRequestsOptions, n i } // MRClose closes an mr on a GitLab project -func MRClose(projID interface{}, id int) error { +func MRClose(projID interface{}, id int64) error { mr, _, err := lab.MergeRequests.GetMergeRequest(projID, id, nil) if err != nil { return err @@ -472,8 +471,8 @@ func MRClose(projID interface{}, id int) error { if mr.State == "closed" { return fmt.Errorf("mr already closed") } - _, _, err = lab.MergeRequests.UpdateMergeRequest(projID, int(id), &gitlab.UpdateMergeRequestOptions{ - StateEvent: gitlab.String("close"), + _, _, err = lab.MergeRequests.UpdateMergeRequest(projID, id, &gitlab.UpdateMergeRequestOptions{ + StateEvent: gitlab.Ptr("close"), }) if err != nil { return err @@ -482,7 +481,7 @@ func MRClose(projID interface{}, id int) error { } // MRReopen reopen an already close mr on a GitLab project -func MRReopen(projID interface{}, id int) error { +func MRReopen(projID interface{}, id int64) error { mr, _, err := lab.MergeRequests.GetMergeRequest(projID, id, nil) if err != nil { return err @@ -490,8 +489,8 @@ func MRReopen(projID interface{}, id int) error { if mr.State == "opened" { return fmt.Errorf("mr not closed") } - _, _, err = lab.MergeRequests.UpdateMergeRequest(projID, int(id), &gitlab.UpdateMergeRequestOptions{ - StateEvent: gitlab.String("reopen"), + _, _, err = lab.MergeRequests.UpdateMergeRequest(projID, id, &gitlab.UpdateMergeRequestOptions{ + StateEvent: gitlab.Ptr("reopen"), }) if err != nil { return err @@ -500,11 +499,13 @@ func MRReopen(projID interface{}, id int) error { } // MRListDiscussions retrieves the discussions (aka notes & comments) for a merge request -func MRListDiscussions(projID interface{}, id int) ([]*gitlab.Discussion, error) { +func MRListDiscussions(projID interface{}, id int64) ([]*gitlab.Discussion, error) { discussions := []*gitlab.Discussion{} opt := &gitlab.ListMergeRequestDiscussionsOptions{ - // 100 is the maximum allowed by the API - PerPage: maxItemsPerPage, + ListOptions: gitlab.ListOptions{ + // 100 is the maximum allowed by the API + PerPage: maxItemsPerPage, + }, } for { @@ -529,8 +530,8 @@ func MRListDiscussions(projID interface{}, id int) ([]*gitlab.Discussion, error) } // MRRebase merges an mr on a GitLab project -func MRRebase(projID interface{}, id int, opts *gitlab.RebaseMergeRequestOptions) error { - _, err := lab.MergeRequests.RebaseMergeRequest(projID, int(id), opts) +func MRRebase(projID interface{}, id int64, opts *gitlab.RebaseMergeRequestOptions) error { + _, err := lab.MergeRequests.RebaseMergeRequest(projID, id, opts) if err != nil { return err } @@ -538,8 +539,8 @@ func MRRebase(projID interface{}, id int, opts *gitlab.RebaseMergeRequestOptions } // MRMerge merges an mr on a GitLab project -func MRMerge(projID interface{}, id int, opts *gitlab.AcceptMergeRequestOptions) error { - _, _, err := lab.MergeRequests.AcceptMergeRequest(projID, int(id), opts) +func MRMerge(projID interface{}, id int64, opts *gitlab.AcceptMergeRequestOptions) error { + _, _, err := lab.MergeRequests.AcceptMergeRequest(projID, id, opts) if err != nil { return err } @@ -547,7 +548,7 @@ func MRMerge(projID interface{}, id int, opts *gitlab.AcceptMergeRequestOptions) } // MRApprove approves an mr on a GitLab project -func MRApprove(projID interface{}, id int) error { +func MRApprove(projID interface{}, id int64) error { _, resp, err := lab.MergeRequestApprovals.ApproveMergeRequest(projID, id, &gitlab.ApproveMergeRequestOptions{}) if resp != nil && resp.StatusCode == http.StatusForbidden { return ErrStatusForbidden @@ -563,7 +564,7 @@ func MRApprove(projID interface{}, id int) error { } // MRUnapprove Unapproves a previously approved mr on a GitLab project -func MRUnapprove(projID interface{}, id int) error { +func MRUnapprove(projID interface{}, id int64) error { resp, err := lab.MergeRequestApprovals.UnapproveMergeRequest(projID, id, nil) if resp != nil && resp.StatusCode == http.StatusForbidden { return ErrStatusForbidden @@ -579,7 +580,7 @@ func MRUnapprove(projID interface{}, id int) error { } // MRSubscribe subscribes to an mr on a GitLab project -func MRSubscribe(projID interface{}, id int) error { +func MRSubscribe(projID interface{}, id int64) error { _, resp, err := lab.MergeRequests.SubscribeToMergeRequest(projID, id, nil) if resp != nil && resp.StatusCode == http.StatusNotModified { return errors.New("Already subscribed") @@ -591,7 +592,7 @@ func MRSubscribe(projID interface{}, id int) error { } // MRUnsubscribe unsubscribes from a previously mr on a GitLab project -func MRUnsubscribe(projID interface{}, id int) error { +func MRUnsubscribe(projID interface{}, id int64) error { _, resp, err := lab.MergeRequests.UnsubscribeFromMergeRequest(projID, id, nil) if resp != nil && resp.StatusCode == http.StatusNotModified { return errors.New("Not subscribed") @@ -603,7 +604,7 @@ func MRUnsubscribe(projID interface{}, id int) error { } // MRThumbUp places a thumb up/down on a merge request -func MRThumbUp(projID interface{}, id int) error { +func MRThumbUp(projID interface{}, id int64) error { _, _, err := lab.AwardEmoji.CreateMergeRequestAwardEmoji(projID, id, &gitlab.CreateAwardEmojiOptions{ Name: "thumbsup", }) @@ -614,7 +615,7 @@ func MRThumbUp(projID interface{}, id int) error { } // MRThumbDown places a thumb up/down on a merge request -func MRThumbDown(projID interface{}, id int) error { +func MRThumbDown(projID interface{}, id int64) error { _, _, err := lab.AwardEmoji.CreateMergeRequestAwardEmoji(projID, id, &gitlab.CreateAwardEmojiOptions{ Name: "thumbsdown", }) @@ -634,7 +635,7 @@ func IssueCreate(projID interface{}, opts *gitlab.CreateIssueOptions) (string, e } // IssueUpdate edits an issue on a GitLab project -func IssueUpdate(projID interface{}, id int, opts *gitlab.UpdateIssueOptions) (string, error) { +func IssueUpdate(projID interface{}, id int64, opts *gitlab.UpdateIssueOptions) (string, error) { issue, _, err := lab.Issues.UpdateIssue(projID, id, opts) if err != nil { return "", err @@ -643,7 +644,7 @@ func IssueUpdate(projID interface{}, id int, opts *gitlab.UpdateIssueOptions) (s } // IssueCreateNote creates a new note on an issue and returns the note URL -func IssueCreateNote(projID interface{}, id int, opts *gitlab.CreateIssueNoteOptions) (string, error) { +func IssueCreateNote(projID interface{}, id int64, opts *gitlab.CreateIssueNoteOptions) (string, error) { note, _, err := lab.Notes.CreateIssueNote(projID, id, opts) if err != nil { return "", err @@ -659,7 +660,7 @@ func IssueCreateNote(projID interface{}, id int, opts *gitlab.CreateIssueNoteOpt } // IssueGet retrieves the issue information from a GitLab project -func IssueGet(projID interface{}, id int) (*gitlab.Issue, error) { +func IssueGet(projID interface{}, id int64) (*gitlab.Issue, error) { issue, _, err := lab.Issues.GetIssue(projID, id) if err != nil { return nil, err @@ -674,7 +675,7 @@ func IssueList(projID interface{}, opts gitlab.ListProjectIssuesOptions, n int) for true { opts.PerPage = maxItemsPerPage if n != -1 { - opts.PerPage = n - len(list) + opts.PerPage = int64(int64(n - len(list))) if opts.PerPage > maxItemsPerPage { opts.PerPage = maxItemsPerPage } @@ -699,7 +700,7 @@ func IssueList(projID interface{}, opts gitlab.ListProjectIssuesOptions, n int) } // IssueClose closes an issue on a GitLab project -func IssueClose(projID interface{}, id int) error { +func IssueClose(projID interface{}, id int64) error { issue, _, err := lab.Issues.GetIssue(projID, id) if err != nil { return err @@ -708,7 +709,7 @@ func IssueClose(projID interface{}, id int) error { return fmt.Errorf("issue already closed") } _, _, err = lab.Issues.UpdateIssue(projID, id, &gitlab.UpdateIssueOptions{ - StateEvent: gitlab.String("close"), + StateEvent: gitlab.Ptr("close"), }) if err != nil { return err @@ -717,7 +718,7 @@ func IssueClose(projID interface{}, id int) error { } // IssueDuplicate closes an issue as duplicate of another -func IssueDuplicate(projID interface{}, id int, dupID interface{}) error { +func IssueDuplicate(projID interface{}, id int64, dupID interface{}) error { dID, err := parseID(dupID) if err != nil { return err @@ -741,7 +742,7 @@ func IssueDuplicate(projID interface{}, id int, dupID interface{}) error { } // IssueReopen reopens a closed issue -func IssueReopen(projID interface{}, id int) error { +func IssueReopen(projID interface{}, id int64) error { issue, _, err := lab.Issues.GetIssue(projID, id) if err != nil { return err @@ -750,7 +751,7 @@ func IssueReopen(projID interface{}, id int) error { return fmt.Errorf("issue not closed") } _, _, err = lab.Issues.UpdateIssue(projID, id, &gitlab.UpdateIssueOptions{ - StateEvent: gitlab.String("reopen"), + StateEvent: gitlab.Ptr("reopen"), }) if err != nil { return err @@ -759,11 +760,13 @@ func IssueReopen(projID interface{}, id int) error { } // IssueListDiscussions retrieves the discussions (aka notes & comments) for an issue -func IssueListDiscussions(projID interface{}, id int) ([]*gitlab.Discussion, error) { +func IssueListDiscussions(projID interface{}, id int64) ([]*gitlab.Discussion, error) { discussions := []*gitlab.Discussion{} opt := &gitlab.ListIssueDiscussionsOptions{ - // 100 is the maximum allowed by the API - PerPage: maxItemsPerPage, + ListOptions: gitlab.ListOptions{ + // 100 is the maximum allowed by the API + PerPage: maxItemsPerPage, + }, } for { @@ -788,7 +791,7 @@ func IssueListDiscussions(projID interface{}, id int) ([]*gitlab.Discussion, err } // IssueSubscribe subscribes to an issue on a GitLab project -func IssueSubscribe(projID interface{}, id int) error { +func IssueSubscribe(projID interface{}, id int64) error { _, resp, err := lab.Issues.SubscribeToIssue(projID, id, nil) if resp != nil && resp.StatusCode == http.StatusNotModified { return errors.New("Already subscribed") @@ -800,7 +803,7 @@ func IssueSubscribe(projID interface{}, id int) error { } // IssueUnsubscribe unsubscribes from an issue on a GitLab project -func IssueUnsubscribe(projID interface{}, id int) error { +func IssueUnsubscribe(projID interface{}, id int64) error { _, resp, err := lab.Issues.UnsubscribeFromIssue(projID, id, nil) if resp != nil && resp.StatusCode == http.StatusNotModified { return errors.New("Not subscribed") @@ -997,7 +1000,7 @@ func ProjectSnippetCreate(projID interface{}, opts *gitlab.CreateProjectSnippetO } // ProjectSnippetDelete deletes a project snippet -func ProjectSnippetDelete(projID interface{}, id int) error { +func ProjectSnippetDelete(projID interface{}, id int64) error { _, err := lab.ProjectSnippets.DeleteSnippet(projID, id) return err } @@ -1008,7 +1011,7 @@ func ProjectSnippetList(projID interface{}, opts gitlab.ListProjectSnippetsOptio for true { opts.PerPage = maxItemsPerPage if n != -1 { - opts.PerPage = n - len(list) + opts.PerPage = int64(n - len(list)) if opts.PerPage > maxItemsPerPage { opts.PerPage = maxItemsPerPage } @@ -1044,7 +1047,7 @@ func SnippetCreate(opts *gitlab.CreateSnippetOptions) (*gitlab.Snippet, error) { } // SnippetDelete deletes a personal snippet -func SnippetDelete(id int) error { +func SnippetDelete(id int64) error { _, err := lab.Snippets.DeleteSnippet(id) return err } @@ -1057,7 +1060,7 @@ func SnippetList(opts gitlab.ListSnippetsOptions, n int) ([]*gitlab.Snippet, err var list []*gitlab.Snippet for len(list) < n { - opts.PerPage = n - len(list) + opts.PerPage = int64(n - len(list)) snips, resp, err := lab.Snippets.ListSnippets(&opts) if err != nil { return nil, err @@ -1116,7 +1119,7 @@ func ProjectList(opts gitlab.ListProjectsOptions, n int) ([]*gitlab.Project, err var list []*gitlab.Project for len(list) < n { - opts.PerPage = n - len(list) + opts.PerPage = int64(n - len(list)) projects, resp, err := lab.Projects.ListProjects(&opts) if err != nil { return nil, err @@ -1187,7 +1190,7 @@ func GroupSearch(query string) (*gitlab.Group, error) { // CIJobs returns a list of jobs in the pipeline with given id. // This function by default doesn't follow bridge jobs. // The jobs are returned sorted by their CreatedAt time -func CIJobs(projID interface{}, id int, followBridge bool, bridgeName string) ([]JobStruct, error) { +func CIJobs(projID interface{}, id int64, followBridge bool, bridgeName string) ([]JobStruct, error) { opts := &gitlab.ListJobsOptions{ ListOptions: gitlab.ListOptions{ PerPage: maxItemsPerPage, @@ -1272,7 +1275,7 @@ func CIJobs(projID interface{}, id int, followBridge bool, bridgeName string) ([ // 1. Last Running Job // 2. First Pending Job // 3. Last Job in Pipeline -func CITrace(projID interface{}, id int, name string, followBridge bool, bridgeName string) (io.Reader, *gitlab.Job, error) { +func CITrace(projID interface{}, id int64, name string, followBridge bool, bridgeName string) (io.Reader, *gitlab.Job, error) { jobs, err := CIJobs(projID, id, followBridge, bridgeName) if len(jobs) == 0 || err != nil { return nil, nil, err @@ -1320,7 +1323,7 @@ func CITrace(projID interface{}, id int, name string, followBridge bool, bridgeN // together with the upstream filename. If path is specified and refers to // a single file within the artifacts archive, that file is returned instead. // If no name is provided, the last job with an artifacts file is picked. -func CIArtifacts(projID interface{}, id int, name, path string, followBridge bool, bridgeName string) (io.Reader, string, error) { +func CIArtifacts(projID interface{}, id int64, name, path string, followBridge bool, bridgeName string) (io.Reader, string, error) { jobs, err := CIJobs(projID, id, followBridge, bridgeName) if len(jobs) == 0 || err != nil { return nil, "", err @@ -1376,7 +1379,7 @@ func CIArtifacts(projID interface{}, id int, name, path string, followBridge boo // CIPlayOrRetry runs a job either by playing it for the first time or by // retrying it based on the currently known job state -func CIPlayOrRetry(projID interface{}, jobID int, status string) (*gitlab.Job, error) { +func CIPlayOrRetry(projID interface{}, jobID int64, status string) (*gitlab.Job, error) { switch status { case "pending", "running": return nil, nil @@ -1399,7 +1402,7 @@ func CIPlayOrRetry(projID interface{}, jobID int, status string) (*gitlab.Job, e } // CICancel cancels a job for a given project by its ID. -func CICancel(projID interface{}, jobID int) (*gitlab.Job, error) { +func CICancel(projID interface{}, jobID int64) (*gitlab.Job, error) { j, _, err := lab.Jobs.CancelJob(projID, jobID) if err != nil { return nil, err @@ -1427,9 +1430,9 @@ func CITrigger(projID interface{}, opts gitlab.RunPipelineTriggerOptions) (*gitl // UserIDFromUsername returns the associated Users ID in GitLab. This is useful // for API calls that allow you to reference a user, but only by ID. -func UserIDFromUsername(username string) (int, error) { +func UserIDFromUsername(username string) (int64, error) { us, _, err := lab.Users.ListUsers(&gitlab.ListUsersOptions{ - Username: gitlab.String(username), + Username: gitlab.Ptr(username), }) if err != nil || len(us) == 0 { return -1, err @@ -1439,9 +1442,9 @@ func UserIDFromUsername(username string) (int, error) { // UserIDFromEmail returns the associated Users ID in GitLab. This is useful // for API calls that allow you to reference a user, but only by ID. -func UserIDFromEmail(email string) (int, error) { +func UserIDFromEmail(email string) (int64, error) { us, _, err := lab.Users.ListUsers(&gitlab.ListUsersOptions{ - Search: gitlab.String(email), + Search: gitlab.Ptr(email), }) if err != nil || len(us) == 0 { return -1, err @@ -1450,7 +1453,7 @@ func UserIDFromEmail(email string) (int, error) { } // AddMRDiscussionNote adds a note to an existing MR discussion on GitLab -func AddMRDiscussionNote(projID interface{}, mrID int, discussionID string, body string) (string, error) { +func AddMRDiscussionNote(projID interface{}, mrID int64, discussionID string, body string) (string, error) { opts := &gitlab.AddMergeRequestDiscussionNoteOptions{ Body: &body, } @@ -1468,7 +1471,7 @@ func AddMRDiscussionNote(projID interface{}, mrID int, discussionID string, body } // AddIssueDiscussionNote adds a note to an existing issue discussion on GitLab -func AddIssueDiscussionNote(projID interface{}, issueID int, discussionID string, body string) (string, error) { +func AddIssueDiscussionNote(projID interface{}, issueID int64, discussionID string, body string) (string, error) { opts := &gitlab.AddIssueDiscussionNoteOptions{ Body: &body, } @@ -1487,7 +1490,7 @@ func AddIssueDiscussionNote(projID interface{}, issueID int, discussionID string // UpdateIssueDiscussionNote updates a specific discussion or note in the // specified issue number -func UpdateIssueDiscussionNote(projID interface{}, issueID int, discussionID string, noteID int, body string) (string, error) { +func UpdateIssueDiscussionNote(projID interface{}, issueID int64, discussionID string, noteID int64, body string) (string, error) { opts := &gitlab.UpdateIssueDiscussionNoteOptions{ Body: &body, } @@ -1506,7 +1509,7 @@ func UpdateIssueDiscussionNote(projID interface{}, issueID int, discussionID str // UpdateMRDiscussionNote updates a specific discussion or note in the // specified MR ID. -func UpdateMRDiscussionNote(projID interface{}, mrID int, discussionID string, noteID int, body string) (string, error) { +func UpdateMRDiscussionNote(projID interface{}, mrID int64, discussionID string, noteID int64, body string) (string, error) { opts := &gitlab.UpdateMergeRequestDiscussionNoteOptions{ Body: &body, } @@ -1525,8 +1528,8 @@ func UpdateMRDiscussionNote(projID interface{}, mrID int, discussionID string, n // ListMRsClosingIssue returns a list of MR IDs that has relation to an issue // being closed -func ListMRsClosingIssue(projID interface{}, id int) ([]int, error) { - var retArray []int +func ListMRsClosingIssue(projID interface{}, id int64) ([]int64, error) { + var retArray []int64 mrs, _, err := lab.Issues.ListMergeRequestsClosingIssue(projID, id, nil, nil) if err != nil { @@ -1542,8 +1545,8 @@ func ListMRsClosingIssue(projID interface{}, id int) ([]int, error) { // ListMRsRelatedToIssue return a list of MR IDs that has any relations to a // certain issue -func ListMRsRelatedToIssue(projID interface{}, id int) ([]int, error) { - var retArray []int +func ListMRsRelatedToIssue(projID interface{}, id int64) ([]int64, error) { + var retArray []int64 mrs, _, err := lab.Issues.ListMergeRequestsRelatedToIssue(projID, id, nil, nil) if err != nil { @@ -1559,8 +1562,8 @@ func ListMRsRelatedToIssue(projID interface{}, id int) ([]int, error) { // ListIssuesClosedOnMerge retuns a list of issue numbers that were closed by // an MR being merged -func ListIssuesClosedOnMerge(projID interface{}, id int) ([]int, error) { - var retArray []int +func ListIssuesClosedOnMerge(projID interface{}, id int64) ([]int64, error) { + var retArray []int64 issues, _, err := lab.MergeRequests.GetIssuesClosedOnMerge(projID, id, nil, nil) if err != nil { @@ -1575,7 +1578,7 @@ func ListIssuesClosedOnMerge(projID interface{}, id int) ([]int, error) { } // MoveIssue moves one issue from one project to another -func MoveIssue(projID interface{}, id int, destProjID interface{}) (string, error) { +func MoveIssue(projID interface{}, id int64, destProjID interface{}) (string, error) { destProject, err := FindProject(destProjID) if err != nil { return "", err @@ -1594,7 +1597,7 @@ func MoveIssue(projID interface{}, id int, destProjID interface{}) (string, erro } // GetMRApprovalsConfiguration returns the current MR approval rule -func GetMRApprovalsConfiguration(projID interface{}, id int) (*gitlab.MergeRequestApprovals, error) { +func GetMRApprovalsConfiguration(projID interface{}, id int64) (*gitlab.MergeRequestApprovals, error) { configuration, _, err := lab.MergeRequestApprovals.GetConfiguration(projID, id) if err != nil { return nil, err @@ -1604,9 +1607,9 @@ func GetMRApprovalsConfiguration(projID interface{}, id int) (*gitlab.MergeReque } // ResolveMRDiscussion resolves a discussion (blocking thread) based on its ID -func ResolveMRDiscussion(projID interface{}, mrID int, discussionID string, noteID int) (string, error) { +func ResolveMRDiscussion(projID interface{}, mrID int64, discussionID string, noteID int64) (string, error) { opts := &gitlab.ResolveMergeRequestDiscussionOptions{ - Resolved: gitlab.Bool(true), + Resolved: gitlab.Ptr(true), } discussion, _, err := lab.Discussions.ResolveMergeRequestDiscussion(projID, mrID, discussionID, opts) @@ -1629,7 +1632,7 @@ func TodoList(opts gitlab.ListTodosOptions, n int) ([]*gitlab.Todo, error) { var list []*gitlab.Todo for len(list) < n { - opts.PerPage = n - len(list) + opts.PerPage = int64(n - len(list)) todos, resp, err := lab.Todos.ListTodos(&opts) if err != nil { return nil, err @@ -1646,7 +1649,7 @@ func TodoList(opts gitlab.ListTodosOptions, n int) ([]*gitlab.Todo, error) { } // TodoMarkDone marks a specific Todo as done -func TodoMarkDone(id int) error { +func TodoMarkDone(id int64) error { _, err := lab.Todos.MarkTodoAsDone(id) if err != nil { return err @@ -1664,7 +1667,7 @@ func TodoMarkAllDone() error { } // TodoMRCreate create a Todo item for an specific MR -func TodoMRCreate(projID interface{}, id int) (int, error) { +func TodoMRCreate(projID interface{}, id int64) (int64, error) { todo, resp, err := lab.MergeRequests.CreateTodo(projID, id) if err != nil { if resp.StatusCode == http.StatusNotModified { @@ -1676,7 +1679,7 @@ func TodoMRCreate(projID interface{}, id int) (int, error) { } // TodoIssueCreate create a Todo item for an specific Issue -func TodoIssueCreate(projID interface{}, id int) (int, error) { +func TodoIssueCreate(projID interface{}, id int64) (int64, error) { todo, resp, err := lab.Issues.CreateTodo(projID, id) if err != nil { if resp.StatusCode == http.StatusNotModified { @@ -1717,7 +1720,7 @@ func GetCommitDiff(projID interface{}, sha string) ([]*gitlab.Diff, error) { return diffs, nil } -func IssueDeleteNote(projID interface{}, issue int, discussion string, note int) error { +func IssueDeleteNote(projID interface{}, issue int64, discussion string, note int64) error { if discussion == "" { _, err := lab.Notes.DeleteIssueNote(projID, issue, note) @@ -1734,7 +1737,7 @@ func IssueDeleteNote(projID interface{}, issue int, discussion string, note int) return nil } -func MRDeleteNote(projID interface{}, mr int, discussion string, note int) error { +func MRDeleteNote(projID interface{}, mr int64, discussion string, note int64) error { if discussion == "" { _, err := lab.Notes.DeleteMergeRequestNote(projID, mr, note) @@ -1751,7 +1754,7 @@ func MRDeleteNote(projID interface{}, mr int, discussion string, note int) error return nil } -func CreateCommitComment(projID interface{}, sha string, newFile string, oldFile string, line int, linetype string, comment string) (string, error) { +func CreateCommitComment(projID interface{}, sha string, newFile string, oldFile string, line int64, linetype string, comment string) (string, error) { // Ideally want to use lab.Commits.PostCommitComment, however, // that API only support comments on linetype=new. // @@ -1802,7 +1805,7 @@ func CreateCommitComment(projID interface{}, sha string, newFile string, oldFile return fmt.Sprintf("%s#note_%d", commitInfo.WebURL, commitDiscussion.Notes[0].ID), nil } -func CreateMergeRequestCommitDiscussion(projID interface{}, id int, sha string, newFile string, oldFile string, line int, linetype string, comment string) (string, error) { +func CreateMergeRequestCommitDiscussion(projID interface{}, id int64, sha string, newFile string, oldFile string, line int64, linetype string, comment string) (string, error) { // FIXME: Pass *gitlab.GetCommitOptions instead of nil commitInfo, err := GetCommit(projID, sha, nil) if err != nil { @@ -1860,7 +1863,7 @@ func CreateMergeRequestCommitDiscussion(projID interface{}, id int, sha string, // since in some cases the API response may come without the HTTP // X-Total(-Page) header. Reference: // https://docs.gitlab.com/ee/user/gitlab_com/index.html#pagination-response-headers -func hasNextPage(resp *gitlab.Response) (int, bool) { +func hasNextPage(resp *gitlab.Response) (int64, bool) { if resp.CurrentPage >= resp.NextPage { return 0, false } @@ -1908,7 +1911,7 @@ func CreatePAT(name string, ExpiresAt time.Time, scopes []string) (*gitlab.Perso return token, nil } -func RevokePAT(id int) error { +func RevokePAT(id int64) error { PATs, err := GetAllPATs() if err != nil { return err diff --git a/internal/gitlab/gitlab_test.go b/internal/gitlab/gitlab_test.go index f58b86fb..40ff29e4 100644 --- a/internal/gitlab/gitlab_test.go +++ b/internal/gitlab/gitlab_test.go @@ -146,7 +146,7 @@ func TestGetCommit(t *testing.T) { t.Run(test.desc, func(t *testing.T) { test := test t.Parallel() - b, err := GetCommit(4181224, test.ref) + b, err := GetCommit(4181224, test.ref, &gitlab.GetCommitOptions{}) if test.ok { require.NoError(t, err) require.Equal(t, test.expectID, b.ID)