feat!: MAJOR release. Update go to 1.25, and add migration path (#520)
BREAKING CHANGE: This bumps Go and external packages to later versions.
This commit is contained in:
12
.github/workflows/go.yaml
vendored
12
.github/workflows/go.yaml
vendored
@@ -21,16 +21,17 @@ jobs:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-go@v4
|
||||
with:
|
||||
go-version: '1.23.1'
|
||||
go-version: '1.25.1'
|
||||
cache: false
|
||||
- name: golangci-lint
|
||||
uses: golangci/golangci-lint-action@v3
|
||||
uses: golangci/golangci-lint-action@v7
|
||||
with:
|
||||
version: v1.61.0
|
||||
version: v2.7.2
|
||||
only-new-issues: true
|
||||
skip-cache: true
|
||||
- name: Install staticcheck
|
||||
run: go install honnef.co/go/tools/cmd/staticcheck@2024.1.1
|
||||
run: go install honnef.co/go/tools/cmd/staticcheck@2025.1.1
|
||||
|
||||
- name: Run staticcheck
|
||||
run: staticcheck ./...
|
||||
go_test:
|
||||
@@ -42,8 +43,9 @@ jobs:
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v4
|
||||
with:
|
||||
go-version: '1.19'
|
||||
go-version: '1.25.1'
|
||||
- name: Build
|
||||
run: make compile
|
||||
- name: Test
|
||||
run: make test
|
||||
|
||||
|
||||
4
.github/workflows/tag-and-release.yaml
vendored
4
.github/workflows/tag-and-release.yaml
vendored
@@ -39,5 +39,5 @@ jobs:
|
||||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
tag: ${{ needs.tag.outputs.tag }}
|
||||
body: ${{ github.event.head_commit.message }}
|
||||
skipIfReleaseExists: true # Do not release if NONE tag is used above
|
||||
generateReleaseNotes: true
|
||||
skipIfReleaseExists: true # Do not release if NONE tag is used above
|
||||
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -8,3 +8,5 @@ tests/plugins
|
||||
!tests/plugins/.placeholder
|
||||
luacov.*
|
||||
tags
|
||||
.claude
|
||||
cmd/cmd
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
version: "2"
|
||||
run:
|
||||
tests: true
|
||||
timeout: 30s
|
||||
|
||||
@@ -18,7 +18,7 @@ To view these help docs and to get more detailed help information, please run `:
|
||||
|
||||
## Requirements
|
||||
|
||||
- <a href="https://go.dev/">Go</a> >= v1.19
|
||||
- <a href="https://go.dev/">Go</a> >= v1.25.1
|
||||
|
||||
## Quick Start
|
||||
|
||||
|
||||
@@ -4,11 +4,11 @@ import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/xanzy/go-gitlab"
|
||||
gitlab "gitlab.com/gitlab-org/api/client-go"
|
||||
)
|
||||
|
||||
type MergeRequestApprover interface {
|
||||
ApproveMergeRequest(pid interface{}, mr int, opt *gitlab.ApproveMergeRequestOptions, options ...gitlab.RequestOptionFunc) (*gitlab.MergeRequestApprovals, *gitlab.Response, error)
|
||||
ApproveMergeRequest(pid interface{}, mr int64, opt *gitlab.ApproveMergeRequestOptions, options ...gitlab.RequestOptionFunc) (*gitlab.MergeRequestApprovals, *gitlab.Response, error)
|
||||
}
|
||||
|
||||
type mergeRequestApproverService struct {
|
||||
|
||||
@@ -4,14 +4,14 @@ import (
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/xanzy/go-gitlab"
|
||||
gitlab "gitlab.com/gitlab-org/api/client-go"
|
||||
)
|
||||
|
||||
type fakeApproverClient struct {
|
||||
testBase
|
||||
}
|
||||
|
||||
func (f fakeApproverClient) ApproveMergeRequest(pid interface{}, mr int, opt *gitlab.ApproveMergeRequestOptions, options ...gitlab.RequestOptionFunc) (*gitlab.MergeRequestApprovals, *gitlab.Response, error) {
|
||||
func (f fakeApproverClient) ApproveMergeRequest(pid interface{}, mr int64, opt *gitlab.ApproveMergeRequestOptions, options ...gitlab.RequestOptionFunc) (*gitlab.MergeRequestApprovals, *gitlab.Response, error) {
|
||||
resp, err := f.handleGitlabError()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
|
||||
@@ -5,11 +5,11 @@ import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/xanzy/go-gitlab"
|
||||
gitlab "gitlab.com/gitlab-org/api/client-go"
|
||||
)
|
||||
|
||||
type AssigneeUpdateRequest struct {
|
||||
Ids []int `json:"ids" validate:"required"`
|
||||
Ids []int64 `json:"ids" validate:"required"`
|
||||
}
|
||||
|
||||
type AssigneeUpdateResponse struct {
|
||||
|
||||
@@ -4,14 +4,14 @@ import (
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/xanzy/go-gitlab"
|
||||
gitlab "gitlab.com/gitlab-org/api/client-go"
|
||||
)
|
||||
|
||||
type fakeAssigneeClient struct {
|
||||
testBase
|
||||
}
|
||||
|
||||
func (f fakeAssigneeClient) UpdateMergeRequest(pid interface{}, mergeRequest int, opt *gitlab.UpdateMergeRequestOptions, options ...gitlab.RequestOptionFunc) (*gitlab.MergeRequest, *gitlab.Response, error) {
|
||||
func (f fakeAssigneeClient) UpdateMergeRequest(pid interface{}, mergeRequest int64, opt *gitlab.UpdateMergeRequestOptions, options ...gitlab.RequestOptionFunc) (*gitlab.MergeRequest, *gitlab.Response, error) {
|
||||
resp, err := f.handleGitlabError()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
@@ -20,7 +20,7 @@ func (f fakeAssigneeClient) UpdateMergeRequest(pid interface{}, mergeRequest int
|
||||
}
|
||||
|
||||
func TestAssigneeHandler(t *testing.T) {
|
||||
var updatePayload = AssigneeUpdateRequest{Ids: []int{1, 2}}
|
||||
var updatePayload = AssigneeUpdateRequest{Ids: []int64{1, 2}}
|
||||
|
||||
t.Run("Updates assignees", func(t *testing.T) {
|
||||
request := makeRequest(t, http.MethodPut, "/mr/assignee", updatePayload)
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/xanzy/go-gitlab"
|
||||
gitlab "gitlab.com/gitlab-org/api/client-go"
|
||||
)
|
||||
|
||||
type FileReader interface {
|
||||
@@ -48,7 +48,7 @@ func (ar attachmentReader) ReadFile(path string) (io.Reader, error) {
|
||||
}
|
||||
|
||||
type FileUploader interface {
|
||||
UploadFile(pid interface{}, content io.Reader, filename string, options ...gitlab.RequestOptionFunc) (*gitlab.ProjectFile, *gitlab.Response, error)
|
||||
UploadProjectMarkdown(pid any, content io.Reader, filename string, options ...gitlab.RequestOptionFunc) (*gitlab.ProjectMarkdownUploadedFile, *gitlab.Response, error)
|
||||
}
|
||||
|
||||
type attachmentService struct {
|
||||
@@ -67,7 +67,7 @@ func (a attachmentService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
projectFile, res, err := a.client.UploadFile(a.projectInfo.ProjectId, file, payload.FileName)
|
||||
projectFile, res, err := a.client.UploadProjectMarkdown(a.projectInfo.ProjectId, file, payload.FileName)
|
||||
if err != nil {
|
||||
handleError(w, err, fmt.Sprintf("Could not upload %s to Gitlab", payload.FileName), http.StatusInternalServerError)
|
||||
return
|
||||
|
||||
@@ -6,20 +6,20 @@ import (
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/xanzy/go-gitlab"
|
||||
gitlab "gitlab.com/gitlab-org/api/client-go"
|
||||
)
|
||||
|
||||
type fakeFileUploaderClient struct {
|
||||
testBase
|
||||
}
|
||||
|
||||
func (f fakeFileUploaderClient) UploadFile(pid interface{}, content io.Reader, filename string, options ...gitlab.RequestOptionFunc) (*gitlab.ProjectFile, *gitlab.Response, error) {
|
||||
func (f fakeFileUploaderClient) UploadProjectMarkdown(pid interface{}, content io.Reader, filename string, options ...gitlab.RequestOptionFunc) (*gitlab.ProjectMarkdownUploadedFile, *gitlab.Response, error) {
|
||||
resp, err := f.handleGitlabError()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
return &gitlab.ProjectFile{}, resp, nil
|
||||
return &gitlab.ProjectMarkdownUploadedFile{}, resp, nil
|
||||
}
|
||||
|
||||
type fakeFileReader struct{}
|
||||
|
||||
@@ -10,27 +10,28 @@ import (
|
||||
|
||||
"github.com/harrisoncramer/gitlab.nvim/cmd/app/git"
|
||||
"github.com/hashicorp/go-retryablehttp"
|
||||
"github.com/xanzy/go-gitlab"
|
||||
gitlab "gitlab.com/gitlab-org/api/client-go"
|
||||
)
|
||||
|
||||
type ProjectInfo struct {
|
||||
ProjectId string
|
||||
MergeId int
|
||||
MergeId int64
|
||||
}
|
||||
|
||||
/* The Client struct embeds all the methods from Gitlab for the different services */
|
||||
type Client struct {
|
||||
*gitlab.MergeRequestsService
|
||||
*gitlab.MergeRequestApprovalsService
|
||||
*gitlab.DiscussionsService
|
||||
*gitlab.ProjectsService
|
||||
*gitlab.ProjectMembersService
|
||||
*gitlab.JobsService
|
||||
*gitlab.PipelinesService
|
||||
*gitlab.LabelsService
|
||||
*gitlab.AwardEmojiService
|
||||
*gitlab.UsersService
|
||||
*gitlab.DraftNotesService
|
||||
gitlab.MergeRequestsServiceInterface
|
||||
gitlab.MergeRequestApprovalsServiceInterface
|
||||
gitlab.DiscussionsServiceInterface
|
||||
gitlab.ProjectsServiceInterface
|
||||
gitlab.ProjectMembersServiceInterface
|
||||
gitlab.JobsServiceInterface
|
||||
gitlab.PipelinesServiceInterface
|
||||
gitlab.LabelsServiceInterface
|
||||
gitlab.AwardEmojiServiceInterface
|
||||
gitlab.UsersServiceInterface
|
||||
gitlab.DraftNotesServiceInterface
|
||||
gitlab.ProjectMarkdownUploadsServiceInterface
|
||||
}
|
||||
|
||||
/* NewClient parses and validates the project settings and initializes the Gitlab client. */
|
||||
@@ -87,17 +88,18 @@ func NewClient() (*Client, error) {
|
||||
}
|
||||
|
||||
return &Client{
|
||||
MergeRequestsService: client.MergeRequests,
|
||||
MergeRequestApprovalsService: client.MergeRequestApprovals,
|
||||
DiscussionsService: client.Discussions,
|
||||
ProjectsService: client.Projects,
|
||||
ProjectMembersService: client.ProjectMembers,
|
||||
JobsService: client.Jobs,
|
||||
PipelinesService: client.Pipelines,
|
||||
LabelsService: client.Labels,
|
||||
AwardEmojiService: client.AwardEmoji,
|
||||
UsersService: client.Users,
|
||||
DraftNotesService: client.DraftNotes,
|
||||
client.MergeRequests,
|
||||
client.MergeRequestApprovals,
|
||||
client.Discussions,
|
||||
client.Projects,
|
||||
client.ProjectMembers,
|
||||
client.Jobs,
|
||||
client.Pipelines,
|
||||
client.Labels,
|
||||
client.AwardEmoji,
|
||||
client.Users,
|
||||
client.DraftNotes,
|
||||
client.ProjectMarkdownUploads,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/xanzy/go-gitlab"
|
||||
gitlab "gitlab.com/gitlab-org/api/client-go"
|
||||
)
|
||||
|
||||
type CommentResponse struct {
|
||||
@@ -14,9 +14,9 @@ type CommentResponse struct {
|
||||
}
|
||||
|
||||
type CommentManager interface {
|
||||
CreateMergeRequestDiscussion(pid interface{}, mergeRequest int, opt *gitlab.CreateMergeRequestDiscussionOptions, options ...gitlab.RequestOptionFunc) (*gitlab.Discussion, *gitlab.Response, error)
|
||||
UpdateMergeRequestDiscussionNote(pid interface{}, mergeRequest int, discussion string, note int, opt *gitlab.UpdateMergeRequestDiscussionNoteOptions, options ...gitlab.RequestOptionFunc) (*gitlab.Note, *gitlab.Response, error)
|
||||
DeleteMergeRequestDiscussionNote(pid interface{}, mergeRequest int, discussion string, note int, options ...gitlab.RequestOptionFunc) (*gitlab.Response, error)
|
||||
CreateMergeRequestDiscussion(pid interface{}, mergeRequest int64, opt *gitlab.CreateMergeRequestDiscussionOptions, options ...gitlab.RequestOptionFunc) (*gitlab.Discussion, *gitlab.Response, error)
|
||||
UpdateMergeRequestDiscussionNote(pid interface{}, mergeRequest int64, discussion string, note int64, opt *gitlab.UpdateMergeRequestDiscussionNoteOptions, options ...gitlab.RequestOptionFunc) (*gitlab.Note, *gitlab.Response, error)
|
||||
DeleteMergeRequestDiscussionNote(pid interface{}, mergeRequest int64, discussion string, note int64, options ...gitlab.RequestOptionFunc) (*gitlab.Response, error)
|
||||
}
|
||||
|
||||
type commentService struct {
|
||||
@@ -38,7 +38,7 @@ func (a commentService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
type DeleteCommentRequest struct {
|
||||
NoteId int `json:"note_id" validate:"required"`
|
||||
NoteId int64 `json:"note_id" validate:"required"`
|
||||
DiscussionId string `json:"discussion_id" validate:"required"`
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ func (a commentService) postComment(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
type EditCommentRequest struct {
|
||||
Comment string `json:"comment" validate:"required"`
|
||||
NoteId int `json:"note_id" validate:"required"`
|
||||
NoteId int64 `json:"note_id" validate:"required"`
|
||||
DiscussionId string `json:"discussion_id" validate:"required"`
|
||||
Resolved bool `json:"resolved"`
|
||||
}
|
||||
|
||||
@@ -4,14 +4,14 @@ import (
|
||||
"crypto/sha1"
|
||||
"fmt"
|
||||
|
||||
"github.com/xanzy/go-gitlab"
|
||||
gitlab "gitlab.com/gitlab-org/api/client-go"
|
||||
)
|
||||
|
||||
/* LinePosition represents a position in a line range. Unlike the Gitlab struct, this does not contain LineCode with a sha1 of the filename */
|
||||
type LinePosition struct {
|
||||
Type string `json:"type"`
|
||||
OldLine int `json:"old_line"`
|
||||
NewLine int `json:"new_line"`
|
||||
OldLine int64 `json:"old_line"`
|
||||
NewLine int64 `json:"new_line"`
|
||||
}
|
||||
|
||||
/* LineRange represents the range of a note. */
|
||||
@@ -24,8 +24,8 @@ type LineRange struct {
|
||||
type PositionData struct {
|
||||
FileName string `json:"file_name"`
|
||||
OldFileName string `json:"old_file_name"`
|
||||
NewLine *int `json:"new_line,omitempty"`
|
||||
OldLine *int `json:"old_line,omitempty"`
|
||||
NewLine *int64 `json:"new_line,omitempty"`
|
||||
OldLine *int64 `json:"old_line,omitempty"`
|
||||
HeadCommitSHA string `json:"head_commit_sha"`
|
||||
BaseCommitSHA string `json:"base_commit_sha"`
|
||||
StartCommitSHA string `json:"start_commit_sha"`
|
||||
|
||||
@@ -4,14 +4,14 @@ import (
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/xanzy/go-gitlab"
|
||||
gitlab "gitlab.com/gitlab-org/api/client-go"
|
||||
)
|
||||
|
||||
type fakeCommentClient struct {
|
||||
testBase
|
||||
}
|
||||
|
||||
func (f fakeCommentClient) CreateMergeRequestDiscussion(pid interface{}, mergeRequest int, opt *gitlab.CreateMergeRequestDiscussionOptions, options ...gitlab.RequestOptionFunc) (*gitlab.Discussion, *gitlab.Response, error) {
|
||||
func (f fakeCommentClient) CreateMergeRequestDiscussion(pid interface{}, mergeRequest int64, opt *gitlab.CreateMergeRequestDiscussionOptions, options ...gitlab.RequestOptionFunc) (*gitlab.Discussion, *gitlab.Response, error) {
|
||||
resp, err := f.handleGitlabError()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
@@ -19,7 +19,7 @@ func (f fakeCommentClient) CreateMergeRequestDiscussion(pid interface{}, mergeRe
|
||||
|
||||
return &gitlab.Discussion{Notes: []*gitlab.Note{{}}}, resp, err
|
||||
}
|
||||
func (f fakeCommentClient) UpdateMergeRequestDiscussionNote(pid interface{}, mergeRequest int, discussion string, note int, opt *gitlab.UpdateMergeRequestDiscussionNoteOptions, options ...gitlab.RequestOptionFunc) (*gitlab.Note, *gitlab.Response, error) {
|
||||
func (f fakeCommentClient) UpdateMergeRequestDiscussionNote(pid interface{}, mergeRequest int64, discussion string, note int64, opt *gitlab.UpdateMergeRequestDiscussionNoteOptions, options ...gitlab.RequestOptionFunc) (*gitlab.Note, *gitlab.Response, error) {
|
||||
resp, err := f.handleGitlabError()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
@@ -28,7 +28,7 @@ func (f fakeCommentClient) UpdateMergeRequestDiscussionNote(pid interface{}, mer
|
||||
return &gitlab.Note{}, resp, err
|
||||
}
|
||||
|
||||
func (f fakeCommentClient) DeleteMergeRequestDiscussionNote(pid interface{}, mergeRequest int, discussion string, note int, options ...gitlab.RequestOptionFunc) (*gitlab.Response, error) {
|
||||
func (f fakeCommentClient) DeleteMergeRequestDiscussionNote(pid interface{}, mergeRequest int64, discussion string, note int64, options ...gitlab.RequestOptionFunc) (*gitlab.Response, error) {
|
||||
resp, err := f.handleGitlabError()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -11,7 +11,7 @@ type PluginOptions struct {
|
||||
GitlabRequest bool `json:"gitlab_request"`
|
||||
GitlabResponse bool `json:"gitlab_response"`
|
||||
} `json:"debug"`
|
||||
ChosenMrIID int `json:"chosen_mr_iid"`
|
||||
ChosenMrIID int64 `json:"chosen_mr_iid"`
|
||||
ConnectionSettings struct {
|
||||
Proxy string `json:"proxy"`
|
||||
Insecure bool `json:"insecure"`
|
||||
@@ -20,7 +20,12 @@ type PluginOptions struct {
|
||||
}
|
||||
|
||||
var pluginOptions PluginOptions
|
||||
var version string
|
||||
|
||||
func SetPluginOptions(p PluginOptions) {
|
||||
pluginOptions = p
|
||||
}
|
||||
|
||||
func SetVersion(v string) {
|
||||
version = v
|
||||
}
|
||||
|
||||
@@ -5,14 +5,14 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/xanzy/go-gitlab"
|
||||
gitlab "gitlab.com/gitlab-org/api/client-go"
|
||||
)
|
||||
|
||||
type CreateMrRequest struct {
|
||||
Title string `json:"title" validate:"required"`
|
||||
TargetBranch string `json:"target_branch" validate:"required"`
|
||||
Description string `json:"description"`
|
||||
TargetProjectID int `json:"forked_project_id,omitempty"`
|
||||
TargetProjectID int64 `json:"forked_project_id,omitempty"`
|
||||
DeleteBranch bool `json:"delete_branch"`
|
||||
Squash bool `json:"squash"`
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/xanzy/go-gitlab"
|
||||
gitlab "gitlab.com/gitlab-org/api/client-go"
|
||||
)
|
||||
|
||||
type fakeMergeCreatorClient struct {
|
||||
|
||||
@@ -4,12 +4,12 @@ import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/xanzy/go-gitlab"
|
||||
gitlab "gitlab.com/gitlab-org/api/client-go"
|
||||
)
|
||||
|
||||
type DraftNotePublisher interface {
|
||||
PublishAllDraftNotes(pid interface{}, mergeRequest int, options ...gitlab.RequestOptionFunc) (*gitlab.Response, error)
|
||||
PublishDraftNote(pid interface{}, mergeRequest int, note int, options ...gitlab.RequestOptionFunc) (*gitlab.Response, error)
|
||||
PublishAllDraftNotes(pid interface{}, mergeRequest int64, options ...gitlab.RequestOptionFunc) (*gitlab.Response, error)
|
||||
PublishDraftNote(pid interface{}, mergeRequest int64, note int64, options ...gitlab.RequestOptionFunc) (*gitlab.Response, error)
|
||||
}
|
||||
|
||||
type draftNotePublisherService struct {
|
||||
@@ -18,7 +18,7 @@ type draftNotePublisherService struct {
|
||||
}
|
||||
|
||||
type DraftNotePublishRequest struct {
|
||||
Note int `json:"note,omitempty"`
|
||||
Note int64 `json:"note,omitempty"`
|
||||
}
|
||||
|
||||
func (a draftNotePublisherService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
@@ -4,17 +4,17 @@ import (
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/xanzy/go-gitlab"
|
||||
gitlab "gitlab.com/gitlab-org/api/client-go"
|
||||
)
|
||||
|
||||
type fakeDraftNotePublisher struct {
|
||||
testBase
|
||||
}
|
||||
|
||||
func (f fakeDraftNotePublisher) PublishAllDraftNotes(pid interface{}, mergeRequest int, options ...gitlab.RequestOptionFunc) (*gitlab.Response, error) {
|
||||
func (f fakeDraftNotePublisher) PublishAllDraftNotes(pid interface{}, mergeRequest int64, options ...gitlab.RequestOptionFunc) (*gitlab.Response, error) {
|
||||
return f.handleGitlabError()
|
||||
}
|
||||
func (f fakeDraftNotePublisher) PublishDraftNote(pid interface{}, mergeRequest int, note int, options ...gitlab.RequestOptionFunc) (*gitlab.Response, error) {
|
||||
func (f fakeDraftNotePublisher) PublishDraftNote(pid interface{}, mergeRequest int64, note int64, options ...gitlab.RequestOptionFunc) (*gitlab.Response, error) {
|
||||
return f.handleGitlabError()
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/xanzy/go-gitlab"
|
||||
gitlab "gitlab.com/gitlab-org/api/client-go"
|
||||
)
|
||||
|
||||
/* The data coming from the client when creating a draft note is the same
|
||||
@@ -29,10 +29,10 @@ func (draftNote DraftNoteWithPosition) GetPositionData() PositionData {
|
||||
}
|
||||
|
||||
type DraftNoteManager interface {
|
||||
ListDraftNotes(pid interface{}, mergeRequest int, opt *gitlab.ListDraftNotesOptions, options ...gitlab.RequestOptionFunc) ([]*gitlab.DraftNote, *gitlab.Response, error)
|
||||
CreateDraftNote(pid interface{}, mergeRequest int, opt *gitlab.CreateDraftNoteOptions, options ...gitlab.RequestOptionFunc) (*gitlab.DraftNote, *gitlab.Response, error)
|
||||
DeleteDraftNote(pid interface{}, mergeRequest int, note int, options ...gitlab.RequestOptionFunc) (*gitlab.Response, error)
|
||||
UpdateDraftNote(pid interface{}, mergeRequest int, note int, opt *gitlab.UpdateDraftNoteOptions, options ...gitlab.RequestOptionFunc) (*gitlab.DraftNote, *gitlab.Response, error)
|
||||
ListDraftNotes(pid interface{}, mergeRequest int64, opt *gitlab.ListDraftNotesOptions, options ...gitlab.RequestOptionFunc) ([]*gitlab.DraftNote, *gitlab.Response, error)
|
||||
CreateDraftNote(pid interface{}, mergeRequest int64, opt *gitlab.CreateDraftNoteOptions, options ...gitlab.RequestOptionFunc) (*gitlab.DraftNote, *gitlab.Response, error)
|
||||
DeleteDraftNote(pid interface{}, mergeRequest int64, note int64, options ...gitlab.RequestOptionFunc) (*gitlab.Response, error)
|
||||
UpdateDraftNote(pid interface{}, mergeRequest int64, note int64, opt *gitlab.UpdateDraftNoteOptions, options ...gitlab.RequestOptionFunc) (*gitlab.DraftNote, *gitlab.Response, error)
|
||||
}
|
||||
|
||||
type draftNoteService struct {
|
||||
@@ -139,7 +139,7 @@ func (a draftNoteService) postDraftNote(w http.ResponseWriter, r *http.Request)
|
||||
/* deleteDraftNote deletes a draft note */
|
||||
func (a draftNoteService) deleteDraftNote(w http.ResponseWriter, r *http.Request) {
|
||||
suffix := strings.TrimPrefix(r.URL.Path, "/mr/draft_notes/")
|
||||
id, err := strconv.Atoi(suffix)
|
||||
id, err := strconv.ParseInt(suffix, 10, 64)
|
||||
if err != nil {
|
||||
handleError(w, err, "Could not parse draft note ID", http.StatusBadRequest)
|
||||
return
|
||||
@@ -174,7 +174,7 @@ type UpdateDraftNoteRequest struct {
|
||||
/* updateDraftNote edits the text of a draft comment */
|
||||
func (a draftNoteService) updateDraftNote(w http.ResponseWriter, r *http.Request) {
|
||||
suffix := strings.TrimPrefix(r.URL.Path, "/mr/draft_notes/")
|
||||
id, err := strconv.Atoi(suffix)
|
||||
id, err := strconv.ParseInt(suffix, 10, 64)
|
||||
if err != nil {
|
||||
handleError(w, err, "Could not parse draft note ID", http.StatusBadRequest)
|
||||
return
|
||||
|
||||
@@ -4,14 +4,14 @@ import (
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/xanzy/go-gitlab"
|
||||
gitlab "gitlab.com/gitlab-org/api/client-go"
|
||||
)
|
||||
|
||||
type fakeDraftNoteManager struct {
|
||||
testBase
|
||||
}
|
||||
|
||||
func (f fakeDraftNoteManager) ListDraftNotes(pid interface{}, mergeRequest int, opt *gitlab.ListDraftNotesOptions, options ...gitlab.RequestOptionFunc) ([]*gitlab.DraftNote, *gitlab.Response, error) {
|
||||
func (f fakeDraftNoteManager) ListDraftNotes(pid interface{}, mergeRequest int64, opt *gitlab.ListDraftNotesOptions, options ...gitlab.RequestOptionFunc) ([]*gitlab.DraftNote, *gitlab.Response, error) {
|
||||
resp, err := f.handleGitlabError()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
@@ -19,7 +19,7 @@ func (f fakeDraftNoteManager) ListDraftNotes(pid interface{}, mergeRequest int,
|
||||
return []*gitlab.DraftNote{}, resp, err
|
||||
}
|
||||
|
||||
func (f fakeDraftNoteManager) CreateDraftNote(pid interface{}, mergeRequest int, opt *gitlab.CreateDraftNoteOptions, options ...gitlab.RequestOptionFunc) (*gitlab.DraftNote, *gitlab.Response, error) {
|
||||
func (f fakeDraftNoteManager) CreateDraftNote(pid interface{}, mergeRequest int64, opt *gitlab.CreateDraftNoteOptions, options ...gitlab.RequestOptionFunc) (*gitlab.DraftNote, *gitlab.Response, error) {
|
||||
resp, err := f.handleGitlabError()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
@@ -27,11 +27,11 @@ func (f fakeDraftNoteManager) CreateDraftNote(pid interface{}, mergeRequest int,
|
||||
return &gitlab.DraftNote{}, resp, err
|
||||
}
|
||||
|
||||
func (f fakeDraftNoteManager) DeleteDraftNote(pid interface{}, mergeRequest int, note int, options ...gitlab.RequestOptionFunc) (*gitlab.Response, error) {
|
||||
func (f fakeDraftNoteManager) DeleteDraftNote(pid interface{}, mergeRequest int64, note int64, options ...gitlab.RequestOptionFunc) (*gitlab.Response, error) {
|
||||
return f.handleGitlabError()
|
||||
}
|
||||
|
||||
func (f fakeDraftNoteManager) UpdateDraftNote(pid interface{}, mergeRequest int, note int, opt *gitlab.UpdateDraftNoteOptions, options ...gitlab.RequestOptionFunc) (*gitlab.DraftNote, *gitlab.Response, error) {
|
||||
func (f fakeDraftNoteManager) UpdateDraftNote(pid interface{}, mergeRequest int64, note int64, opt *gitlab.UpdateDraftNoteOptions, options ...gitlab.RequestOptionFunc) (*gitlab.DraftNote, *gitlab.Response, error) {
|
||||
resp, err := f.handleGitlabError()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/xanzy/go-gitlab"
|
||||
gitlab "gitlab.com/gitlab-org/api/client-go"
|
||||
)
|
||||
|
||||
type Emoji struct {
|
||||
@@ -30,7 +30,7 @@ type EmojiMap map[string]Emoji
|
||||
|
||||
type CreateNoteEmojiPost struct {
|
||||
Emoji string `json:"emoji"`
|
||||
NoteId int `json:"note_id"`
|
||||
NoteId int64 `json:"note_id"`
|
||||
}
|
||||
|
||||
type CreateEmojiResponse struct {
|
||||
@@ -39,8 +39,8 @@ type CreateEmojiResponse struct {
|
||||
}
|
||||
|
||||
type EmojiManager interface {
|
||||
DeleteMergeRequestAwardEmojiOnNote(pid interface{}, mergeRequestIID int, noteID int, awardID int, options ...gitlab.RequestOptionFunc) (*gitlab.Response, error)
|
||||
CreateMergeRequestAwardEmojiOnNote(pid interface{}, mergeRequestIID int, noteID int, opt *gitlab.CreateAwardEmojiOptions, options ...gitlab.RequestOptionFunc) (*gitlab.AwardEmoji, *gitlab.Response, error)
|
||||
DeleteMergeRequestAwardEmojiOnNote(pid interface{}, mergeRequestIID int64, noteID int64, awardID int64, options ...gitlab.RequestOptionFunc) (*gitlab.Response, error)
|
||||
CreateMergeRequestAwardEmojiOnNote(pid interface{}, mergeRequestIID int64, noteID int64, opt *gitlab.CreateAwardEmojiOptions, options ...gitlab.RequestOptionFunc) (*gitlab.AwardEmoji, *gitlab.Response, error)
|
||||
}
|
||||
|
||||
type emojiService struct {
|
||||
@@ -69,13 +69,13 @@ func (a emojiService) deleteEmojiFromNote(w http.ResponseWriter, r *http.Request
|
||||
return
|
||||
}
|
||||
|
||||
noteId, err := strconv.Atoi(ids[0])
|
||||
noteId, err := strconv.ParseInt(ids[0], 10, 64)
|
||||
if err != nil {
|
||||
handleError(w, err, "Could not convert note ID to integer", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
awardableId, err := strconv.Atoi(ids[1])
|
||||
awardableId, err := strconv.ParseInt(ids[1], 10, 64)
|
||||
if err != nil {
|
||||
handleError(w, err, "Could not convert awardable ID to integer", http.StatusBadRequest)
|
||||
return
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/xanzy/go-gitlab"
|
||||
gitlab "gitlab.com/gitlab-org/api/client-go"
|
||||
)
|
||||
|
||||
type InfoResponse struct {
|
||||
@@ -13,7 +13,7 @@ type InfoResponse struct {
|
||||
}
|
||||
|
||||
type MergeRequestGetter interface {
|
||||
GetMergeRequest(pid interface{}, mergeRequest int, opt *gitlab.GetMergeRequestsOptions, options ...gitlab.RequestOptionFunc) (*gitlab.MergeRequest, *gitlab.Response, error)
|
||||
GetMergeRequest(pid interface{}, mergeRequest int64, opt *gitlab.GetMergeRequestsOptions, options ...gitlab.RequestOptionFunc) (*gitlab.MergeRequest, *gitlab.Response, error)
|
||||
}
|
||||
|
||||
type infoService struct {
|
||||
|
||||
@@ -4,14 +4,14 @@ import (
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/xanzy/go-gitlab"
|
||||
gitlab "gitlab.com/gitlab-org/api/client-go"
|
||||
)
|
||||
|
||||
type fakeMergeRequestGetter struct {
|
||||
testBase
|
||||
}
|
||||
|
||||
func (f fakeMergeRequestGetter) GetMergeRequest(pid interface{}, mergeRequest int, opt *gitlab.GetMergeRequestsOptions, options ...gitlab.RequestOptionFunc) (*gitlab.MergeRequest, *gitlab.Response, error) {
|
||||
func (f fakeMergeRequestGetter) GetMergeRequest(pid interface{}, mergeRequest int64, opt *gitlab.GetMergeRequestsOptions, options ...gitlab.RequestOptionFunc) (*gitlab.MergeRequest, *gitlab.Response, error) {
|
||||
resp, err := f.handleGitlabError()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
|
||||
@@ -6,11 +6,11 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/xanzy/go-gitlab"
|
||||
gitlab "gitlab.com/gitlab-org/api/client-go"
|
||||
)
|
||||
|
||||
type JobTraceRequest struct {
|
||||
JobId int `json:"job_id" validate:"required"`
|
||||
JobId int64 `json:"job_id" validate:"required"`
|
||||
}
|
||||
|
||||
type JobTraceResponse struct {
|
||||
@@ -19,7 +19,7 @@ type JobTraceResponse struct {
|
||||
}
|
||||
|
||||
type TraceFileGetter interface {
|
||||
GetTraceFile(pid interface{}, jobID int, options ...gitlab.RequestOptionFunc) (*bytes.Reader, *gitlab.Response, error)
|
||||
GetTraceFile(pid interface{}, jobID int64, options ...gitlab.RequestOptionFunc) (*bytes.Reader, *gitlab.Response, error)
|
||||
}
|
||||
|
||||
type traceFileService struct {
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/xanzy/go-gitlab"
|
||||
gitlab "gitlab.com/gitlab-org/api/client-go"
|
||||
)
|
||||
|
||||
type fakeTraceFileGetter struct {
|
||||
@@ -26,7 +26,7 @@ func getTraceFileData(t *testing.T, svc http.Handler, request *http.Request) Job
|
||||
return data
|
||||
}
|
||||
|
||||
func (f fakeTraceFileGetter) GetTraceFile(pid interface{}, jobID int, options ...gitlab.RequestOptionFunc) (*bytes.Reader, *gitlab.Response, error) {
|
||||
func (f fakeTraceFileGetter) GetTraceFile(pid interface{}, jobID int64, options ...gitlab.RequestOptionFunc) (*bytes.Reader, *gitlab.Response, error) {
|
||||
resp, err := f.handleGitlabError()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/xanzy/go-gitlab"
|
||||
gitlab "gitlab.com/gitlab-org/api/client-go"
|
||||
)
|
||||
|
||||
type LabelUpdateRequest struct {
|
||||
@@ -28,7 +28,7 @@ type LabelsRequestResponse struct {
|
||||
}
|
||||
|
||||
type LabelManager interface {
|
||||
UpdateMergeRequest(interface{}, int, *gitlab.UpdateMergeRequestOptions, ...gitlab.RequestOptionFunc) (*gitlab.MergeRequest, *gitlab.Response, error)
|
||||
UpdateMergeRequest(interface{}, int64, *gitlab.UpdateMergeRequestOptions, ...gitlab.RequestOptionFunc) (*gitlab.MergeRequest, *gitlab.Response, error)
|
||||
ListLabels(interface{}, *gitlab.ListLabelsOptions, ...gitlab.RequestOptionFunc) ([]*gitlab.Label, *gitlab.Response, error)
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
"encoding/json"
|
||||
|
||||
"github.com/xanzy/go-gitlab"
|
||||
gitlab "gitlab.com/gitlab-org/api/client-go"
|
||||
)
|
||||
|
||||
func Contains[T comparable](elems []T, v T) bool {
|
||||
@@ -34,9 +34,9 @@ type DiscussionsRequest struct {
|
||||
|
||||
type DiscussionsResponse struct {
|
||||
SuccessResponse
|
||||
Discussions []*gitlab.Discussion `json:"discussions"`
|
||||
UnlinkedDiscussions []*gitlab.Discussion `json:"unlinked_discussions"`
|
||||
Emojis map[int][]*gitlab.AwardEmoji `json:"emojis"`
|
||||
Discussions []*gitlab.Discussion `json:"discussions"`
|
||||
UnlinkedDiscussions []*gitlab.Discussion `json:"unlinked_discussions"`
|
||||
Emojis map[int64][]*gitlab.AwardEmoji `json:"emojis"`
|
||||
}
|
||||
|
||||
type SortableDiscussions struct {
|
||||
@@ -66,8 +66,8 @@ func (d SortableDiscussions) Swap(i, j int) {
|
||||
}
|
||||
|
||||
type DiscussionsLister interface {
|
||||
ListMergeRequestDiscussions(pid interface{}, mergeRequest int, opt *gitlab.ListMergeRequestDiscussionsOptions, options ...gitlab.RequestOptionFunc) ([]*gitlab.Discussion, *gitlab.Response, error)
|
||||
ListMergeRequestAwardEmojiOnNote(pid interface{}, mergeRequestIID int, noteID int, opt *gitlab.ListAwardEmojiOptions, options ...gitlab.RequestOptionFunc) ([]*gitlab.AwardEmoji, *gitlab.Response, error)
|
||||
ListMergeRequestDiscussions(pid interface{}, mergeRequest int64, opt *gitlab.ListMergeRequestDiscussionsOptions, options ...gitlab.RequestOptionFunc) ([]*gitlab.Discussion, *gitlab.Response, error)
|
||||
ListMergeRequestAwardEmojiOnNote(pid any, mergeRequestIID int64, noteID int64, opt *gitlab.ListAwardEmojiOptions, options ...gitlab.RequestOptionFunc) ([]*gitlab.AwardEmoji, *gitlab.Response, error)
|
||||
}
|
||||
|
||||
type discussionsListerService struct {
|
||||
@@ -84,8 +84,10 @@ func (a discussionsListerService) ServeHTTP(w http.ResponseWriter, r *http.Reque
|
||||
request := r.Context().Value(payload(payload("payload"))).(*DiscussionsRequest)
|
||||
|
||||
mergeRequestDiscussionOptions := gitlab.ListMergeRequestDiscussionsOptions{
|
||||
Page: 1,
|
||||
PerPage: 250,
|
||||
ListOptions: gitlab.ListOptions{
|
||||
Page: 1,
|
||||
PerPage: 250,
|
||||
},
|
||||
}
|
||||
|
||||
discussions, res, err := a.client.ListMergeRequestDiscussions(a.projectInfo.ProjectId, a.projectInfo.MergeId, &mergeRequestDiscussionOptions)
|
||||
@@ -121,7 +123,7 @@ func (a discussionsListerService) ServeHTTP(w http.ResponseWriter, r *http.Reque
|
||||
}
|
||||
|
||||
/* Collect IDs in order to fetch emojis */
|
||||
var noteIds []int
|
||||
var noteIds []int64
|
||||
for _, discussion := range discussions {
|
||||
for _, note := range discussion.Notes {
|
||||
noteIds = append(noteIds, note.ID)
|
||||
@@ -164,20 +166,20 @@ func (a discussionsListerService) ServeHTTP(w http.ResponseWriter, r *http.Reque
|
||||
Fetches emojis for a set of notes and comments in parallel and returns a map of note IDs to their emojis.
|
||||
Gitlab's API does not allow for fetching notes for an entire discussion thread so we have to do it per-note.
|
||||
*/
|
||||
func (a discussionsListerService) fetchEmojisForNotesAndComments(noteIDs []int) (map[int][]*gitlab.AwardEmoji, error) {
|
||||
func (a discussionsListerService) fetchEmojisForNotesAndComments(noteIDs []int64) (map[int64][]*gitlab.AwardEmoji, error) {
|
||||
var wg sync.WaitGroup
|
||||
|
||||
emojis := make(map[int][]*gitlab.AwardEmoji)
|
||||
emojis := make(map[int64][]*gitlab.AwardEmoji)
|
||||
mu := &sync.Mutex{}
|
||||
errs := make(chan error, len(noteIDs))
|
||||
emojiChan := make(chan struct {
|
||||
noteID int
|
||||
noteID int64
|
||||
emojis []*gitlab.AwardEmoji
|
||||
}, len(noteIDs))
|
||||
|
||||
for _, noteID := range noteIDs {
|
||||
wg.Add(1)
|
||||
go func(noteID int) {
|
||||
go func(noteID int64) {
|
||||
defer wg.Done()
|
||||
emojis, _, err := a.client.ListMergeRequestAwardEmojiOnNote(a.projectInfo.ProjectId, a.projectInfo.MergeId, noteID, &gitlab.ListAwardEmojiOptions{})
|
||||
if err != nil {
|
||||
@@ -185,7 +187,7 @@ func (a discussionsListerService) fetchEmojisForNotesAndComments(noteIDs []int)
|
||||
return
|
||||
}
|
||||
emojiChan <- struct {
|
||||
noteID int
|
||||
noteID int64
|
||||
emojis []*gitlab.AwardEmoji
|
||||
}{noteID, emojis}
|
||||
}(noteID)
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/xanzy/go-gitlab"
|
||||
gitlab "gitlab.com/gitlab-org/api/client-go"
|
||||
)
|
||||
|
||||
type fakeDiscussionsLister struct {
|
||||
@@ -16,7 +16,7 @@ type fakeDiscussionsLister struct {
|
||||
badEmojiResponse bool
|
||||
}
|
||||
|
||||
func (f fakeDiscussionsLister) ListMergeRequestDiscussions(pid interface{}, mergeRequest int, opt *gitlab.ListMergeRequestDiscussionsOptions, options ...gitlab.RequestOptionFunc) ([]*gitlab.Discussion, *gitlab.Response, error) {
|
||||
func (f fakeDiscussionsLister) ListMergeRequestDiscussions(pid interface{}, mergeRequest int64, opt *gitlab.ListMergeRequestDiscussionsOptions, options ...gitlab.RequestOptionFunc) ([]*gitlab.Discussion, *gitlab.Response, error) {
|
||||
resp, err := f.handleGitlabError()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
@@ -30,34 +30,24 @@ func (f fakeDiscussionsLister) ListMergeRequestDiscussions(pid interface{}, merg
|
||||
*timePointers[i] = timePointers[i-1].Add(time.Second * 100)
|
||||
}
|
||||
|
||||
type Author struct {
|
||||
ID int `json:"id"`
|
||||
Username string `json:"username"`
|
||||
Email string `json:"email"`
|
||||
Name string `json:"name"`
|
||||
State string `json:"state"`
|
||||
AvatarURL string `json:"avatar_url"`
|
||||
WebURL string `json:"web_url"`
|
||||
}
|
||||
|
||||
testListDiscussionsResponse := []*gitlab.Discussion{
|
||||
{Notes: []*gitlab.Note{
|
||||
{CreatedAt: timePointers[0], Type: "DiffNote", Author: Author{Username: "hcramer0"}},
|
||||
{CreatedAt: timePointers[4], Type: "DiffNote", Author: Author{Username: "hcramer1"}},
|
||||
{CreatedAt: timePointers[0], Type: "DiffNote", Author: gitlab.NoteAuthor{Username: "hcramer0"}},
|
||||
{CreatedAt: timePointers[4], Type: "DiffNote", Author: gitlab.NoteAuthor{Username: "hcramer1"}},
|
||||
}},
|
||||
{Notes: []*gitlab.Note{
|
||||
{CreatedAt: timePointers[2], Type: "DiffNote", Author: Author{Username: "hcramer2"}},
|
||||
{CreatedAt: timePointers[3], Type: "DiffNote", Author: Author{Username: "hcramer3"}},
|
||||
{CreatedAt: timePointers[2], Type: "DiffNote", Author: gitlab.NoteAuthor{Username: "hcramer2"}},
|
||||
{CreatedAt: timePointers[3], Type: "DiffNote", Author: gitlab.NoteAuthor{Username: "hcramer3"}},
|
||||
}},
|
||||
{Notes: []*gitlab.Note{
|
||||
{CreatedAt: timePointers[1], Type: "DiffNote", Author: Author{Username: "hcramer4"}},
|
||||
{CreatedAt: timePointers[5], Type: "DiffNote", Author: Author{Username: "hcramer5"}},
|
||||
{CreatedAt: timePointers[1], Type: "DiffNote", Author: gitlab.NoteAuthor{Username: "hcramer4"}},
|
||||
{CreatedAt: timePointers[5], Type: "DiffNote", Author: gitlab.NoteAuthor{Username: "hcramer5"}},
|
||||
}},
|
||||
}
|
||||
return testListDiscussionsResponse, resp, err
|
||||
}
|
||||
|
||||
func (f fakeDiscussionsLister) ListMergeRequestAwardEmojiOnNote(pid interface{}, mergeRequestIID int, noteID int, opt *gitlab.ListAwardEmojiOptions, options ...gitlab.RequestOptionFunc) ([]*gitlab.AwardEmoji, *gitlab.Response, error) {
|
||||
func (f fakeDiscussionsLister) ListMergeRequestAwardEmojiOnNote(pid interface{}, mergeRequestIID int64, noteID int64, opt *gitlab.ListAwardEmojiOptions, options ...gitlab.RequestOptionFunc) ([]*gitlab.AwardEmoji, *gitlab.Response, error) {
|
||||
resp, err := f.handleGitlabError()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/xanzy/go-gitlab"
|
||||
gitlab "gitlab.com/gitlab-org/api/client-go"
|
||||
)
|
||||
|
||||
type ProjectMembersResponse struct {
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/xanzy/go-gitlab"
|
||||
gitlab "gitlab.com/gitlab-org/api/client-go"
|
||||
)
|
||||
|
||||
type fakeMemberLister struct {
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/xanzy/go-gitlab"
|
||||
gitlab "gitlab.com/gitlab-org/api/client-go"
|
||||
)
|
||||
|
||||
type AcceptMergeRequestRequest struct {
|
||||
@@ -14,7 +14,7 @@ type AcceptMergeRequestRequest struct {
|
||||
}
|
||||
|
||||
type MergeRequestAccepter interface {
|
||||
AcceptMergeRequest(pid interface{}, mergeRequest int, opt *gitlab.AcceptMergeRequestOptions, options ...gitlab.RequestOptionFunc) (*gitlab.MergeRequest, *gitlab.Response, error)
|
||||
AcceptMergeRequest(pid interface{}, mergeRequest int64, opt *gitlab.AcceptMergeRequestOptions, options ...gitlab.RequestOptionFunc) (*gitlab.MergeRequest, *gitlab.Response, error)
|
||||
}
|
||||
|
||||
type mergeRequestAccepterService struct {
|
||||
|
||||
@@ -4,14 +4,14 @@ import (
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/xanzy/go-gitlab"
|
||||
gitlab "gitlab.com/gitlab-org/api/client-go"
|
||||
)
|
||||
|
||||
type fakeMergeRequestAccepter struct {
|
||||
testBase
|
||||
}
|
||||
|
||||
func (f fakeMergeRequestAccepter) AcceptMergeRequest(pid interface{}, mergeRequest int, opt *gitlab.AcceptMergeRequestOptions, options ...gitlab.RequestOptionFunc) (*gitlab.MergeRequest, *gitlab.Response, error) {
|
||||
func (f fakeMergeRequestAccepter) AcceptMergeRequest(pid interface{}, mergeRequest int64, opt *gitlab.AcceptMergeRequestOptions, options ...gitlab.RequestOptionFunc) (*gitlab.MergeRequest, *gitlab.Response, error) {
|
||||
resp, err := f.handleGitlabError()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
|
||||
@@ -5,16 +5,16 @@ import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/xanzy/go-gitlab"
|
||||
gitlab "gitlab.com/gitlab-org/api/client-go"
|
||||
)
|
||||
|
||||
type ListMergeRequestResponse struct {
|
||||
SuccessResponse
|
||||
MergeRequests []*gitlab.MergeRequest `json:"merge_requests"`
|
||||
MergeRequests []*gitlab.BasicMergeRequest `json:"merge_requests"`
|
||||
}
|
||||
|
||||
type MergeRequestLister interface {
|
||||
ListProjectMergeRequests(pid interface{}, opt *gitlab.ListProjectMergeRequestsOptions, options ...gitlab.RequestOptionFunc) ([]*gitlab.MergeRequest, *gitlab.Response, error)
|
||||
ListProjectMergeRequests(pid interface{}, opt *gitlab.ListProjectMergeRequestsOptions, options ...gitlab.RequestOptionFunc) ([]*gitlab.BasicMergeRequest, *gitlab.Response, error)
|
||||
}
|
||||
|
||||
type mergeRequestListerService struct {
|
||||
|
||||
@@ -7,11 +7,11 @@ import (
|
||||
"net/http"
|
||||
"sync"
|
||||
|
||||
"github.com/xanzy/go-gitlab"
|
||||
gitlab "gitlab.com/gitlab-org/api/client-go"
|
||||
)
|
||||
|
||||
type MergeRequestListerByUsername interface {
|
||||
ListProjectMergeRequests(pid interface{}, opt *gitlab.ListProjectMergeRequestsOptions, options ...gitlab.RequestOptionFunc) ([]*gitlab.MergeRequest, *gitlab.Response, error)
|
||||
ListProjectMergeRequests(pid interface{}, opt *gitlab.ListProjectMergeRequestsOptions, options ...gitlab.RequestOptionFunc) ([]*gitlab.BasicMergeRequest, *gitlab.Response, error)
|
||||
}
|
||||
|
||||
type mergeRequestListerByUsernameService struct {
|
||||
@@ -53,7 +53,7 @@ func (a mergeRequestListerByUsernameService) ServeHTTP(w http.ResponseWriter, r
|
||||
}
|
||||
|
||||
type apiResponse struct {
|
||||
mrs []*gitlab.MergeRequest
|
||||
mrs []*gitlab.BasicMergeRequest
|
||||
err error
|
||||
}
|
||||
|
||||
@@ -73,8 +73,8 @@ func (a mergeRequestListerByUsernameService) ServeHTTP(w http.ResponseWriter, r
|
||||
}(payload)
|
||||
}
|
||||
|
||||
var mergeRequests []*gitlab.MergeRequest
|
||||
existingIds := make(map[int]bool)
|
||||
var mergeRequests []*gitlab.BasicMergeRequest
|
||||
existingIds := make(map[int64]bool)
|
||||
var errs []error
|
||||
for res := range mrChan {
|
||||
if res.err != nil {
|
||||
@@ -115,14 +115,14 @@ func (a mergeRequestListerByUsernameService) ServeHTTP(w http.ResponseWriter, r
|
||||
}
|
||||
}
|
||||
|
||||
func (a mergeRequestListerByUsernameService) getMrs(payload *gitlab.ListProjectMergeRequestsOptions) ([]*gitlab.MergeRequest, error) {
|
||||
func (a mergeRequestListerByUsernameService) getMrs(payload *gitlab.ListProjectMergeRequestsOptions) ([]*gitlab.BasicMergeRequest, error) {
|
||||
mrs, res, err := a.client.ListProjectMergeRequests(a.projectInfo.ProjectId, payload)
|
||||
if err != nil {
|
||||
return []*gitlab.MergeRequest{}, err
|
||||
return []*gitlab.BasicMergeRequest{}, err
|
||||
}
|
||||
|
||||
if res.StatusCode >= 300 {
|
||||
return []*gitlab.MergeRequest{}, GenericError{endpoint: "/merge_requests_by_username"}
|
||||
return []*gitlab.BasicMergeRequest{}, GenericError{endpoint: "/merge_requests_by_username"}
|
||||
}
|
||||
|
||||
defer res.Body.Close()
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/xanzy/go-gitlab"
|
||||
gitlab "gitlab.com/gitlab-org/api/client-go"
|
||||
)
|
||||
|
||||
type fakeMergeRequestListerByUsername struct {
|
||||
@@ -13,17 +13,17 @@ type fakeMergeRequestListerByUsername struct {
|
||||
emptyResponse bool
|
||||
}
|
||||
|
||||
func (f fakeMergeRequestListerByUsername) ListProjectMergeRequests(pid interface{}, opt *gitlab.ListProjectMergeRequestsOptions, options ...gitlab.RequestOptionFunc) ([]*gitlab.MergeRequest, *gitlab.Response, error) {
|
||||
func (f fakeMergeRequestListerByUsername) ListProjectMergeRequests(pid interface{}, opt *gitlab.ListProjectMergeRequestsOptions, options ...gitlab.RequestOptionFunc) ([]*gitlab.BasicMergeRequest, *gitlab.Response, error) {
|
||||
resp, err := f.handleGitlabError()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
if f.emptyResponse {
|
||||
return []*gitlab.MergeRequest{}, resp, err
|
||||
return []*gitlab.BasicMergeRequest{}, resp, err
|
||||
}
|
||||
|
||||
return []*gitlab.MergeRequest{{IID: 10}}, resp, err
|
||||
return []*gitlab.BasicMergeRequest{{IID: 10}}, resp, err
|
||||
}
|
||||
|
||||
func TestListMergeRequestByUsername(t *testing.T) {
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/xanzy/go-gitlab"
|
||||
gitlab "gitlab.com/gitlab-org/api/client-go"
|
||||
)
|
||||
|
||||
type fakeMergeRequestLister struct {
|
||||
@@ -13,21 +13,21 @@ type fakeMergeRequestLister struct {
|
||||
multipleMrs bool
|
||||
}
|
||||
|
||||
func (f fakeMergeRequestLister) ListProjectMergeRequests(pid interface{}, opt *gitlab.ListProjectMergeRequestsOptions, options ...gitlab.RequestOptionFunc) ([]*gitlab.MergeRequest, *gitlab.Response, error) {
|
||||
func (f fakeMergeRequestLister) ListProjectMergeRequests(pid interface{}, opt *gitlab.ListProjectMergeRequestsOptions, options ...gitlab.RequestOptionFunc) ([]*gitlab.BasicMergeRequest, *gitlab.Response, error) {
|
||||
resp, err := f.handleGitlabError()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
if f.emptyResponse {
|
||||
return []*gitlab.MergeRequest{}, resp, err
|
||||
return []*gitlab.BasicMergeRequest{}, resp, err
|
||||
}
|
||||
|
||||
if f.multipleMrs {
|
||||
return []*gitlab.MergeRequest{{IID: 10}, {IID: 11}}, resp, err
|
||||
return []*gitlab.BasicMergeRequest{{IID: 10}, {IID: 11}}, resp, err
|
||||
}
|
||||
|
||||
return []*gitlab.MergeRequest{{IID: 10}}, resp, err
|
||||
return []*gitlab.BasicMergeRequest{{IID: 10}}, resp, err
|
||||
}
|
||||
|
||||
func TestMergeRequestHandler(t *testing.T) {
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/go-playground/validator/v10"
|
||||
"github.com/xanzy/go-gitlab"
|
||||
gitlab "gitlab.com/gitlab-org/api/client-go"
|
||||
)
|
||||
|
||||
type mw func(http.Handler) http.Handler
|
||||
@@ -108,7 +108,7 @@ func (m withMrMiddleware) handle(next http.Handler) http.Handler {
|
||||
}
|
||||
|
||||
if pluginOptions.ChosenMrIID != 0 {
|
||||
options.IIDs = gitlab.Ptr([]int{pluginOptions.ChosenMrIID})
|
||||
options.IIDs = gitlab.Ptr([]int64{pluginOptions.ChosenMrIID})
|
||||
}
|
||||
|
||||
mergeRequests, _, err := m.client.ListProjectMergeRequests(m.data.projectInfo.ProjectId, &options)
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/harrisoncramer/gitlab.nvim/cmd/app/git"
|
||||
"github.com/xanzy/go-gitlab"
|
||||
gitlab "gitlab.com/gitlab-org/api/client-go"
|
||||
)
|
||||
|
||||
type RetriggerPipelineResponse struct {
|
||||
@@ -30,9 +30,9 @@ type GetPipelineAndJobsResponse struct {
|
||||
|
||||
type PipelineManager interface {
|
||||
ListProjectPipelines(pid interface{}, opt *gitlab.ListProjectPipelinesOptions, options ...gitlab.RequestOptionFunc) ([]*gitlab.PipelineInfo, *gitlab.Response, error)
|
||||
ListPipelineJobs(pid interface{}, pipelineID int, opts *gitlab.ListJobsOptions, options ...gitlab.RequestOptionFunc) ([]*gitlab.Job, *gitlab.Response, error)
|
||||
ListPipelineBridges(pid interface{}, pipelineID int, opts *gitlab.ListJobsOptions, options ...gitlab.RequestOptionFunc) ([]*gitlab.Bridge, *gitlab.Response, error)
|
||||
RetryPipelineBuild(pid interface{}, pipeline int, options ...gitlab.RequestOptionFunc) (*gitlab.Pipeline, *gitlab.Response, error)
|
||||
ListPipelineJobs(pid interface{}, pipelineID int64, opts *gitlab.ListJobsOptions, options ...gitlab.RequestOptionFunc) ([]*gitlab.Job, *gitlab.Response, error)
|
||||
ListPipelineBridges(pid interface{}, pipelineID int64, opts *gitlab.ListJobsOptions, options ...gitlab.RequestOptionFunc) ([]*gitlab.Bridge, *gitlab.Response, error)
|
||||
RetryPipelineBuild(pid interface{}, pipeline int64, options ...gitlab.RequestOptionFunc) (*gitlab.Pipeline, *gitlab.Response, error)
|
||||
}
|
||||
|
||||
type pipelineService struct {
|
||||
@@ -171,7 +171,7 @@ func (a pipelineService) RetriggerPipeline(w http.ResponseWriter, r *http.Reques
|
||||
|
||||
id := strings.TrimPrefix(r.URL.Path, "/pipeline/trigger/")
|
||||
|
||||
idInt, err := strconv.Atoi(id)
|
||||
idInt, err := strconv.ParseInt(id, 10, 64)
|
||||
if err != nil {
|
||||
handleError(w, err, "Could not convert pipeline ID to integer", http.StatusBadRequest)
|
||||
return
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/xanzy/go-gitlab"
|
||||
gitlab "gitlab.com/gitlab-org/api/client-go"
|
||||
)
|
||||
|
||||
type fakePipelineManager struct {
|
||||
@@ -19,7 +19,7 @@ func (f fakePipelineManager) ListProjectPipelines(pid interface{}, opt *gitlab.L
|
||||
return []*gitlab.PipelineInfo{{ID: 1234}}, resp, err
|
||||
}
|
||||
|
||||
func (f fakePipelineManager) ListPipelineJobs(pid interface{}, pipelineID int, opts *gitlab.ListJobsOptions, options ...gitlab.RequestOptionFunc) ([]*gitlab.Job, *gitlab.Response, error) {
|
||||
func (f fakePipelineManager) ListPipelineJobs(pid interface{}, pipelineID int64, opts *gitlab.ListJobsOptions, options ...gitlab.RequestOptionFunc) ([]*gitlab.Job, *gitlab.Response, error) {
|
||||
resp, err := f.handleGitlabError()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
@@ -27,7 +27,7 @@ func (f fakePipelineManager) ListPipelineJobs(pid interface{}, pipelineID int, o
|
||||
return []*gitlab.Job{}, resp, err
|
||||
}
|
||||
|
||||
func (f fakePipelineManager) ListPipelineBridges(pid interface{}, pipelineID int, opts *gitlab.ListJobsOptions, options ...gitlab.RequestOptionFunc) ([]*gitlab.Bridge, *gitlab.Response, error) {
|
||||
func (f fakePipelineManager) ListPipelineBridges(pid interface{}, pipelineID int64, opts *gitlab.ListJobsOptions, options ...gitlab.RequestOptionFunc) ([]*gitlab.Bridge, *gitlab.Response, error) {
|
||||
resp, err := f.handleGitlabError()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
@@ -35,7 +35,7 @@ func (f fakePipelineManager) ListPipelineBridges(pid interface{}, pipelineID int
|
||||
return []*gitlab.Bridge{}, resp, err
|
||||
}
|
||||
|
||||
func (f fakePipelineManager) RetryPipelineBuild(pid interface{}, pipeline int, options ...gitlab.RequestOptionFunc) (*gitlab.Pipeline, *gitlab.Response, error) {
|
||||
func (f fakePipelineManager) RetryPipelineBuild(pid interface{}, pipeline int64, options ...gitlab.RequestOptionFunc) (*gitlab.Pipeline, *gitlab.Response, error) {
|
||||
resp, err := f.handleGitlabError()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/xanzy/go-gitlab"
|
||||
gitlab "gitlab.com/gitlab-org/api/client-go"
|
||||
)
|
||||
|
||||
type ReplyRequest struct {
|
||||
@@ -20,7 +20,7 @@ type ReplyResponse struct {
|
||||
}
|
||||
|
||||
type ReplyManager interface {
|
||||
AddMergeRequestDiscussionNote(interface{}, int, string, *gitlab.AddMergeRequestDiscussionNoteOptions, ...gitlab.RequestOptionFunc) (*gitlab.Note, *gitlab.Response, error)
|
||||
AddMergeRequestDiscussionNote(interface{}, int64, string, *gitlab.AddMergeRequestDiscussionNoteOptions, ...gitlab.RequestOptionFunc) (*gitlab.Note, *gitlab.Response, error)
|
||||
}
|
||||
|
||||
type replyService struct {
|
||||
|
||||
@@ -4,14 +4,14 @@ import (
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/xanzy/go-gitlab"
|
||||
gitlab "gitlab.com/gitlab-org/api/client-go"
|
||||
)
|
||||
|
||||
type fakeReplyManager struct {
|
||||
testBase
|
||||
}
|
||||
|
||||
func (f fakeReplyManager) AddMergeRequestDiscussionNote(interface{}, int, string, *gitlab.AddMergeRequestDiscussionNoteOptions, ...gitlab.RequestOptionFunc) (*gitlab.Note, *gitlab.Response, error) {
|
||||
func (f fakeReplyManager) AddMergeRequestDiscussionNote(interface{}, int64, string, *gitlab.AddMergeRequestDiscussionNoteOptions, ...gitlab.RequestOptionFunc) (*gitlab.Note, *gitlab.Response, error) {
|
||||
resp, err := f.handleGitlabError()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
|
||||
@@ -5,11 +5,11 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/xanzy/go-gitlab"
|
||||
gitlab "gitlab.com/gitlab-org/api/client-go"
|
||||
)
|
||||
|
||||
type DiscussionResolver interface {
|
||||
ResolveMergeRequestDiscussion(pid interface{}, mergeRequest int, discussion string, opt *gitlab.ResolveMergeRequestDiscussionOptions, options ...gitlab.RequestOptionFunc) (*gitlab.Discussion, *gitlab.Response, error)
|
||||
ResolveMergeRequestDiscussion(pid interface{}, mergeRequest int64, discussion string, opt *gitlab.ResolveMergeRequestDiscussionOptions, options ...gitlab.RequestOptionFunc) (*gitlab.Discussion, *gitlab.Response, error)
|
||||
}
|
||||
|
||||
type discussionsResolutionService struct {
|
||||
|
||||
@@ -4,14 +4,14 @@ import (
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/xanzy/go-gitlab"
|
||||
gitlab "gitlab.com/gitlab-org/api/client-go"
|
||||
)
|
||||
|
||||
type fakeDiscussionResolver struct {
|
||||
testBase
|
||||
}
|
||||
|
||||
func (f fakeDiscussionResolver) ResolveMergeRequestDiscussion(pid interface{}, mergeRequest int, discussion string, opt *gitlab.ResolveMergeRequestDiscussionOptions, options ...gitlab.RequestOptionFunc) (*gitlab.Discussion, *gitlab.Response, error) {
|
||||
func (f fakeDiscussionResolver) ResolveMergeRequestDiscussion(pid interface{}, mergeRequest int64, discussion string, opt *gitlab.ResolveMergeRequestDiscussionOptions, options ...gitlab.RequestOptionFunc) (*gitlab.Discussion, *gitlab.Response, error) {
|
||||
resp, err := f.handleGitlabError()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
|
||||
@@ -4,11 +4,11 @@ import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/xanzy/go-gitlab"
|
||||
gitlab "gitlab.com/gitlab-org/api/client-go"
|
||||
)
|
||||
|
||||
type ReviewerUpdateRequest struct {
|
||||
Ids []int `json:"ids" validate:"required"`
|
||||
Ids []int64 `json:"ids" validate:"required"`
|
||||
}
|
||||
|
||||
type ReviewerUpdateResponse struct {
|
||||
@@ -22,7 +22,7 @@ type ReviewersRequestResponse struct {
|
||||
}
|
||||
|
||||
type MergeRequestUpdater interface {
|
||||
UpdateMergeRequest(pid interface{}, mergeRequest int, opt *gitlab.UpdateMergeRequestOptions, options ...gitlab.RequestOptionFunc) (*gitlab.MergeRequest, *gitlab.Response, error)
|
||||
UpdateMergeRequest(pid interface{}, mergeRequest int64, opt *gitlab.UpdateMergeRequestOptions, options ...gitlab.RequestOptionFunc) (*gitlab.MergeRequest, *gitlab.Response, error)
|
||||
}
|
||||
|
||||
type reviewerService struct {
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/xanzy/go-gitlab"
|
||||
gitlab "gitlab.com/gitlab-org/api/client-go"
|
||||
)
|
||||
|
||||
type RevisionsResponse struct {
|
||||
@@ -13,7 +13,7 @@ type RevisionsResponse struct {
|
||||
}
|
||||
|
||||
type RevisionsGetter interface {
|
||||
GetMergeRequestDiffVersions(pid interface{}, mergeRequest int, opt *gitlab.GetMergeRequestDiffVersionsOptions, options ...gitlab.RequestOptionFunc) ([]*gitlab.MergeRequestDiffVersion, *gitlab.Response, error)
|
||||
GetMergeRequestDiffVersions(pid interface{}, mergeRequest int64, opt *gitlab.GetMergeRequestDiffVersionsOptions, options ...gitlab.RequestOptionFunc) ([]*gitlab.MergeRequestDiffVersion, *gitlab.Response, error)
|
||||
}
|
||||
|
||||
type revisionsService struct {
|
||||
|
||||
@@ -4,11 +4,11 @@ import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/xanzy/go-gitlab"
|
||||
gitlab "gitlab.com/gitlab-org/api/client-go"
|
||||
)
|
||||
|
||||
type MergeRequestRevoker interface {
|
||||
UnapproveMergeRequest(interface{}, int, ...gitlab.RequestOptionFunc) (*gitlab.Response, error)
|
||||
UnapproveMergeRequest(interface{}, int64, ...gitlab.RequestOptionFunc) (*gitlab.Response, error)
|
||||
}
|
||||
|
||||
type mergeRequestRevokerService struct {
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/harrisoncramer/gitlab.nvim/cmd/app/git"
|
||||
"github.com/xanzy/go-gitlab"
|
||||
gitlab "gitlab.com/gitlab-org/api/client-go"
|
||||
)
|
||||
|
||||
/*
|
||||
@@ -89,7 +89,7 @@ func CreateRouter(gitlabClient *Client, projectInfo *ProjectInfo, s *shutdownSer
|
||||
if os.Getenv("DEBUG") != "" {
|
||||
// TODO: We have some JSON files (emojis.json) we import relative to the binary in production and
|
||||
// expect to break during debugging, do not throw when that occurs.
|
||||
fmt.Fprintf(os.Stdout, "Issue occured setting up router: %s\n", err)
|
||||
_, _ = fmt.Fprintf(os.Stdout, "Issue occured setting up router: %s\n", err)
|
||||
} else {
|
||||
panic(err)
|
||||
}
|
||||
@@ -241,7 +241,22 @@ func CreateRouter(gitlabClient *Client, projectInfo *ProjectInfo, s *shutdownSer
|
||||
|
||||
m.HandleFunc("/ping", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
fmt.Fprintln(w, "pong")
|
||||
_, _ = fmt.Fprintln(w, "pong")
|
||||
})
|
||||
|
||||
m.HandleFunc("/version", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_, _ = fmt.Fprintf(w, `{"version":"%s"}`, version)
|
||||
})
|
||||
|
||||
// Default 404 handler
|
||||
m.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path != "/" {
|
||||
handleError(w, fmt.Errorf("endpoint %s does not exist", r.URL.Path), "Not found", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
w.WriteHeader(http.StatusOK)
|
||||
})
|
||||
|
||||
return LoggingServer{handler: m}
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/xanzy/go-gitlab"
|
||||
gitlab "gitlab.com/gitlab-org/api/client-go"
|
||||
)
|
||||
|
||||
type SummaryUpdateRequest struct {
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/harrisoncramer/gitlab.nvim/cmd/app/git"
|
||||
"github.com/xanzy/go-gitlab"
|
||||
gitlab "gitlab.com/gitlab-org/api/client-go"
|
||||
)
|
||||
|
||||
var errorFromGitlab = errors.New("some error from Gitlab")
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/xanzy/go-gitlab"
|
||||
gitlab "gitlab.com/gitlab-org/api/client-go"
|
||||
)
|
||||
|
||||
type UserResponse struct {
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
)
|
||||
|
||||
var pluginOptions app.PluginOptions
|
||||
var Version = "unknown" // Set via ldflags
|
||||
|
||||
func main() {
|
||||
log.SetFlags(0)
|
||||
@@ -20,6 +21,7 @@ func main() {
|
||||
|
||||
err := json.Unmarshal([]byte(os.Args[1]), &pluginOptions)
|
||||
app.SetPluginOptions(pluginOptions)
|
||||
app.SetVersion(Version)
|
||||
|
||||
if err != nil {
|
||||
log.Fatalf("Failure parsing plugin settings: %v", err)
|
||||
|
||||
20
go.mod
20
go.mod
@@ -1,27 +1,25 @@
|
||||
module github.com/harrisoncramer/gitlab.nvim
|
||||
|
||||
go 1.19
|
||||
go 1.25.1
|
||||
|
||||
require (
|
||||
github.com/go-playground/validator/v10 v10.22.1
|
||||
github.com/hashicorp/go-retryablehttp v0.7.7
|
||||
github.com/xanzy/go-gitlab v0.108.0
|
||||
github.com/hashicorp/go-retryablehttp v0.7.8
|
||||
gitlab.com/gitlab-org/api/client-go v1.17.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
|
||||
github.com/go-playground/locales v0.14.1 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||
github.com/golang/protobuf v1.5.3 // indirect
|
||||
github.com/google/go-querystring v1.1.0 // indirect
|
||||
github.com/google/go-cmp v0.7.0 // indirect
|
||||
github.com/google/go-querystring v1.2.0 // indirect
|
||||
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
|
||||
github.com/leodido/go-urn v1.4.0 // indirect
|
||||
golang.org/x/crypto v0.19.0 // indirect
|
||||
golang.org/x/net v0.21.0 // indirect
|
||||
golang.org/x/oauth2 v0.6.0 // indirect
|
||||
golang.org/x/sys v0.20.0 // indirect
|
||||
golang.org/x/text v0.14.0 // indirect
|
||||
golang.org/x/time v0.3.0 // indirect
|
||||
google.golang.org/appengine v1.6.7 // indirect
|
||||
google.golang.org/protobuf v1.29.1 // indirect
|
||||
golang.org/x/oauth2 v0.34.0 // indirect
|
||||
golang.org/x/sys v0.39.0 // indirect
|
||||
golang.org/x/text v0.32.0 // indirect
|
||||
golang.org/x/time v0.14.0 // indirect
|
||||
)
|
||||
|
||||
62
go.sum
62
go.sum
@@ -1,59 +1,51 @@
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
|
||||
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
|
||||
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
|
||||
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
|
||||
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
|
||||
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
|
||||
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
|
||||
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
|
||||
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
|
||||
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
|
||||
github.com/go-playground/validator/v10 v10.22.1 h1:40JcKH+bBNGFczGuoBYgX4I6m/i27HYW8P9FDk5PbgA=
|
||||
github.com/go-playground/validator/v10 v10.22.1/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
|
||||
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
|
||||
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
||||
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
|
||||
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
|
||||
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
|
||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
||||
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
||||
github.com/google/go-querystring v1.2.0 h1:yhqkPbu2/OH+V9BfpCVPZkNmUXhb2gBxJArfhIxNtP0=
|
||||
github.com/google/go-querystring v1.2.0/go.mod h1:8IFJqpSRITyJ8QhQ13bmbeMBDfmeEJZD5A0egEOmkqU=
|
||||
github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ=
|
||||
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
|
||||
github.com/hashicorp/go-hclog v1.6.3 h1:Qr2kF+eVWjTiYmU7Y31tYlP1h0q/X3Nl3tPGdaB11/k=
|
||||
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-hclog v1.6.3/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M=
|
||||
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/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
|
||||
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
|
||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||
github.com/xanzy/go-gitlab v0.108.0 h1:IEvEUWFR5G1seslRhJ8gC//INiIUqYXuSUoBd7/gFKE=
|
||||
github.com/xanzy/go-gitlab v0.108.0/go.mod h1:wKNKh3GkYDMOsGmnfuX+ITCmDuSDWFO0G+C4AygL9RY=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
||||
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
||||
gitlab.com/gitlab-org/api/client-go v1.17.0 h1:4aVMqYyJONZXWHoH78wzhIMzWkzwqJ8cEPhJRQnUPFI=
|
||||
gitlab.com/gitlab-org/api/client-go v1.17.0/go.mod h1:ctGKgv9bErQHO0NOrfhoyFtKMAkBhUE7y53F2xHFAkE=
|
||||
golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo=
|
||||
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
|
||||
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
|
||||
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
|
||||
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
|
||||
golang.org/x/oauth2 v0.6.0 h1:Lh8GPgSKBfWSwFvtuWOfeI3aAAnbXTSutYxJiOJFgIw=
|
||||
golang.org/x/oauth2 v0.6.0/go.mod h1:ycmewcwgD4Rpr3eZJLSB4Kyyljb3qDh40vJ8STE5HKw=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
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/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
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/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4=
|
||||
golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c=
|
||||
google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
google.golang.org/protobuf v1.29.1 h1:7QBf+IK2gx70Ap/hDsOmam3GE0v9HicjfEdAxE62UoM=
|
||||
google.golang.org/protobuf v1.29.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
golang.org/x/oauth2 v0.34.0 h1:hqK/t4AKgbqWkdkcAeI8XLmbK+4m4G5YeQRrmiotGlw=
|
||||
golang.org/x/oauth2 v0.34.0/go.mod h1:lzm5WQJQwKZ3nwavOZ3IS5Aulzxi68dUSgRHujetwEA=
|
||||
golang.org/x/sys v0.39.0 h1:CvCKL8MeisomCi6qNZ+wbb0DN9E5AATixKsvNtMoMFk=
|
||||
golang.org/x/sys v0.39.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
|
||||
golang.org/x/text v0.32.0 h1:ZD01bjUt1FQ9WJ0ClOL5vxgxOI/sVCNgX1YtKwcY0mU=
|
||||
golang.org/x/text v0.32.0/go.mod h1:o/rUWzghvpD5TXrTIBuJU77MTaN0ljMWE47kxGJQ7jY=
|
||||
golang.org/x/time v0.14.0 h1:MRx4UaLrDotUKUdCIqzPC48t1Y9hANFKIRpNx+Te8PI=
|
||||
golang.org/x/time v0.14.0/go.mod h1:eL/Oa2bBBK0TkX57Fyni+NgnyQQN4LitPmob2Hjnqw4=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
||||
@@ -63,8 +63,7 @@ M.sequence = function(dependencies, cb)
|
||||
end
|
||||
|
||||
-- Otherwise, start the go server and start fetching the values
|
||||
server.start(function()
|
||||
state.go_server_running = true
|
||||
server.build_and_start(function()
|
||||
handler:fetch(dependencies, 1, argTable)
|
||||
end)
|
||||
end
|
||||
|
||||
@@ -1,22 +1,9 @@
|
||||
local state = require("gitlab.state")
|
||||
local List = require("gitlab.utils.list")
|
||||
local version = require("gitlab.version")
|
||||
local u = require("gitlab.utils")
|
||||
local M = {}
|
||||
|
||||
local function check_go_version()
|
||||
local go_version = io.popen("go version"):read("*a")
|
||||
if go_version then
|
||||
local major, minor, _ = go_version:match("(%d+)%.(%d+)%.(%d+)")
|
||||
if major and tonumber(major) >= 1 and tonumber(minor) >= 19 then
|
||||
return
|
||||
else
|
||||
return "Go is installed, but version is older than 1.19."
|
||||
end
|
||||
else
|
||||
return "Go is not installed."
|
||||
end
|
||||
end
|
||||
|
||||
---Checks the health of the plugin
|
||||
---@param return_results boolean
|
||||
M.check = function(return_results)
|
||||
@@ -60,7 +47,7 @@ M.check = function(return_results)
|
||||
},
|
||||
}
|
||||
|
||||
local go_version_problem = check_go_version()
|
||||
local go_version_problem = version.check_go_version()
|
||||
if go_version_problem ~= nil then
|
||||
table.insert(warnings, go_version_problem)
|
||||
end
|
||||
|
||||
@@ -12,6 +12,7 @@ local summary = require("gitlab.actions.summary")
|
||||
local data = require("gitlab.actions.data")
|
||||
local assignees_and_reviewers = require("gitlab.actions.assignees_and_reviewers")
|
||||
local comment = require("gitlab.actions.comment")
|
||||
local version = require("gitlab.version")
|
||||
local pipeline = require("gitlab.actions.pipeline")
|
||||
local create_mr = require("gitlab.actions.create_mr")
|
||||
local approvals = require("gitlab.actions.approvals")
|
||||
@@ -36,6 +37,13 @@ local function setup(args)
|
||||
if args == nil then
|
||||
args = {}
|
||||
end
|
||||
|
||||
local version_issue = version.check_go_version()
|
||||
if version_issue ~= nil then
|
||||
u.notify(version_issue, vim.log.levels.ERROR)
|
||||
return
|
||||
end
|
||||
|
||||
server.build() -- Builds the Go binary if it doesn't exist
|
||||
state.merge_settings(args) -- Merges user settings with default settings
|
||||
state.set_global_keymaps() -- Sets keymaps that are not bound to a specific buffer
|
||||
|
||||
@@ -4,7 +4,7 @@ local Job = require("plenary.job")
|
||||
local u = require("gitlab.utils")
|
||||
local M = {}
|
||||
|
||||
M.run_job = function(endpoint, method, body, callback, on_error_callback)
|
||||
M.run_job = function(endpoint, method, body, callback)
|
||||
local state = require("gitlab.state")
|
||||
local args = { "-s", "-X", (method or "POST"), string.format("localhost:%s", state.settings.port) .. endpoint }
|
||||
|
||||
@@ -16,10 +16,8 @@ M.run_job = function(endpoint, method, body, callback, on_error_callback)
|
||||
|
||||
-- This handler will handle all responses from the Go server. Anything with a successful
|
||||
-- status will call the callback (if it is supplied for the job). Otherwise, it will print out the
|
||||
-- success message or error message and details from the Go server and run the on_error_callback
|
||||
-- (if supplied for the job).
|
||||
-- success message or error message and details from the Go server.
|
||||
local stderr = {}
|
||||
|
||||
Job:new({
|
||||
command = "curl",
|
||||
args = args,
|
||||
@@ -55,9 +53,6 @@ M.run_job = function(endpoint, method, body, callback, on_error_callback)
|
||||
-- Handle error case
|
||||
local message = string.format("%s: %s", data.message, data.details)
|
||||
u.notify(message, vim.log.levels.ERROR)
|
||||
if on_error_callback then
|
||||
on_error_callback(data)
|
||||
end
|
||||
end
|
||||
end, 0)
|
||||
end,
|
||||
|
||||
@@ -5,8 +5,29 @@ local List = require("gitlab.utils.list")
|
||||
local state = require("gitlab.state")
|
||||
local u = require("gitlab.utils")
|
||||
local job = require("gitlab.job")
|
||||
local Job = require("plenary.job")
|
||||
local M = {}
|
||||
|
||||
-- Builds the binary if it doesn't exist, and starts the server. If the pre-existing binary has an older
|
||||
-- tag than the Lua code (exposed via the /version endpoint) then shuts down the server, rebuilds it, and
|
||||
-- restarts the server again.
|
||||
M.build_and_start = function(callback)
|
||||
M.build(false)
|
||||
M.start(function()
|
||||
M.get_version(function(version)
|
||||
if version.plugin_version ~= version.binary_version then
|
||||
M.shutdown(function()
|
||||
if M.build(true) then
|
||||
M.start(callback)
|
||||
end
|
||||
end)
|
||||
else
|
||||
callback()
|
||||
end
|
||||
end)
|
||||
end)
|
||||
end
|
||||
|
||||
-- Starts the Go server and call the callback provided
|
||||
M.start = function(callback)
|
||||
local port = tonumber(state.settings.port) or 0
|
||||
@@ -50,6 +71,7 @@ M.start = function(callback)
|
||||
-- Make sure that this actually check if port was correctly parsed based on server output
|
||||
-- because server outputs port only if it started successfully.
|
||||
if parsed_port ~= nil and not callback_called then
|
||||
state.go_server_running = true
|
||||
callback()
|
||||
callback_called = true
|
||||
end
|
||||
@@ -80,7 +102,7 @@ M.start = function(callback)
|
||||
end
|
||||
end
|
||||
|
||||
-- Builds the Go binary
|
||||
-- Builds the Go binary with the current Git tag.
|
||||
M.build = function(override)
|
||||
local file_path = u.current_file_path()
|
||||
local parent_dir = vim.fn.fnamemodify(file_path, ":h:h:h:h")
|
||||
@@ -96,8 +118,15 @@ M.build = function(override)
|
||||
end
|
||||
end
|
||||
|
||||
local version_output = vim.system({ "git", "describe", "--tags", "--always" }, { cwd = parent_dir }):wait()
|
||||
local version = version_output.code == 0 and vim.trim(version_output.stdout) or "unknown"
|
||||
|
||||
local ldflags = string.format("-X main.Version=%s", version)
|
||||
local res = vim
|
||||
.system({ "go", "build", "-o", bin_name }, { cwd = state.settings.root_path .. u.path_separator .. "cmd" })
|
||||
.system(
|
||||
{ "go", "build", "-ldflags", ldflags, "-o", bin_name },
|
||||
{ cwd = state.settings.root_path .. u.path_separator .. "cmd" }
|
||||
)
|
||||
:wait()
|
||||
|
||||
if res.code ~= 0 then
|
||||
@@ -134,7 +163,6 @@ M.restart = function(cb)
|
||||
job.run_job("/shutdown", "POST", { restart = true }, function(data)
|
||||
state.go_server_running = false
|
||||
M.start(function()
|
||||
state.go_server_running = true
|
||||
state.clear_data()
|
||||
if cb then
|
||||
cb()
|
||||
@@ -145,4 +173,44 @@ M.restart = function(cb)
|
||||
end)
|
||||
end
|
||||
|
||||
-- Returns the version (git tag) that was baked into the binary when it was last built
|
||||
M.get_version = function(callback)
|
||||
if not state.go_server_running then
|
||||
u.notify("Gitlab server not running", vim.log.levels.ERROR)
|
||||
return nil
|
||||
end
|
||||
local file_path = u.current_file_path()
|
||||
local parent_dir = vim.fn.fnamemodify(file_path, ":h:h:h:h")
|
||||
|
||||
local version_output = vim.system({ "git", "describe", "--tags", "--always" }, { cwd = parent_dir }):wait()
|
||||
local plugin_version = version_output.code == 0 and vim.trim(version_output.stdout) or "unknown"
|
||||
|
||||
local args = { "-s", "-X", "GET", string.format("localhost:%s/version", state.settings.port) }
|
||||
|
||||
-- We call the "/version" endpoint here instead of through the regular jobs pattern because earlier versions of the plugin
|
||||
-- may not have it. We handle a 404 as an "unknown" version error.
|
||||
Job:new({
|
||||
command = "curl",
|
||||
args = args,
|
||||
on_stdout = function(_, output)
|
||||
vim.defer_fn(function()
|
||||
if output == nil then
|
||||
callback({ plugin_version = plugin_version, binary_version = "unknown" })
|
||||
return
|
||||
end
|
||||
|
||||
local data_ok, data = pcall(vim.json.decode, output)
|
||||
if not data_ok or data == nil or data.version == nil then
|
||||
callback({ plugin_version = plugin_version, binary_version = "unknown" })
|
||||
return
|
||||
end
|
||||
|
||||
callback({ plugin_version = plugin_version, binary_version = data.version })
|
||||
end, 0)
|
||||
end,
|
||||
on_stderr = function() end,
|
||||
on_exit = function() end,
|
||||
}):start()
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
24
lua/gitlab/version.lua
Normal file
24
lua/gitlab/version.lua
Normal file
@@ -0,0 +1,24 @@
|
||||
local M = {}
|
||||
|
||||
M.is_go_valid = function()
|
||||
local go_version = io.popen("go version"):read("*a")
|
||||
if go_version then
|
||||
local major, minor, _ = go_version:match("(%d+)%.(%d+)%.?(%d*)")
|
||||
if major and tonumber(major) >= 1 and tonumber(minor) >= 25 then
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
M.check_go_version = function()
|
||||
local has_version = M.is_go_valid()
|
||||
if not has_version then
|
||||
return "Go is not installed, or version is older than 1.25.1. Please reinstall up-to-date Go version: https://go.dev/dl/"
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
Reference in New Issue
Block a user