FIx shared structs + add better debugging/linting (#379)
* fix: Fixes issues w/ shared pointers to structs (#378) * feat: Adds even better debugging and linting support (#376) This is a #PATCH release.
This commit is contained in:
committed by
GitHub
parent
c3d7f26e3c
commit
5c9b88db4f
5
.github/CONTRIBUTING.md
vendored
5
.github/CONTRIBUTING.md
vendored
@@ -31,11 +31,12 @@ If you are making changes to the Go codebase, don't forget to run `make compile`
|
|||||||
|
|
||||||
3. Apply formatters and linters to your changes
|
3. Apply formatters and linters to your changes
|
||||||
|
|
||||||
For changes to the Go codebase: We use <a href="https://pkg.go.dev/cmd/gofmt">gofmt</a> to check formatting and <a href="https://github.com/golangci/golangci-lint">golangci-lint</a> to check linting. Run these commands in the root of the repository:
|
For changes to the Go codebase: We use <a href="https://pkg.go.dev/cmd/gofmt">gofmt</a> to check formatting and <a href="https://github.com/golangci/golangci-lint">golangci-lint</a> to check linting, and <a href="https://staticcheck.dev/">staticcheck</a>. Run these commands in the root of the repository:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ go fmt ./...
|
$ go fmt ./...
|
||||||
$ golangci-lint run
|
$ golangci-lint run ./...
|
||||||
|
$ staticcheck ./...
|
||||||
```
|
```
|
||||||
|
|
||||||
If you are writing tests and have added something to the Go client, you can test with:
|
If you are writing tests and have added something to the Go client, you can test with:
|
||||||
|
|||||||
8
.github/workflows/go.yaml
vendored
8
.github/workflows/go.yaml
vendored
@@ -12,14 +12,18 @@ jobs:
|
|||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-go@v4
|
- uses: actions/setup-go@v4
|
||||||
with:
|
with:
|
||||||
go-version: '1.19'
|
go-version: '1.23.1'
|
||||||
cache: false
|
cache: false
|
||||||
- name: golangci-lint
|
- name: golangci-lint
|
||||||
uses: golangci/golangci-lint-action@v3
|
uses: golangci/golangci-lint-action@v3
|
||||||
with:
|
with:
|
||||||
version: v1.54
|
version: v1.61.0
|
||||||
only-new-issues: true
|
only-new-issues: true
|
||||||
skip-cache: true
|
skip-cache: true
|
||||||
|
- name: Install staticcheck
|
||||||
|
run: go install honnef.co/go/tools/cmd/staticcheck@2024.1.1
|
||||||
|
- name: Run staticcheck
|
||||||
|
run: staticcheck ./...
|
||||||
go_test:
|
go_test:
|
||||||
name: Test Go 🧪
|
name: Test Go 🧪
|
||||||
needs: [go_lint]
|
needs: [go_lint]
|
||||||
|
|||||||
3
.golangci.yml
Normal file
3
.golangci.yml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
run:
|
||||||
|
tests: true
|
||||||
|
timeout: 30s
|
||||||
@@ -28,7 +28,7 @@ func (a assigneesService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
assigneeUpdateRequest, ok := r.Context().Value(payload("payload")).(*AssigneeUpdateRequest)
|
assigneeUpdateRequest, ok := r.Context().Value(payload("payload")).(*AssigneeUpdateRequest)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
handleError(w, errors.New("Could not get payload from context"), "Bad payload", http.StatusInternalServerError)
|
handleError(w, errors.New("could not get payload from context"), "Bad payload", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ func TestAssigneeHandler(t *testing.T) {
|
|||||||
svc := middleware(
|
svc := middleware(
|
||||||
assigneesService{testProjectData, fakeAssigneeClient{}},
|
assigneesService{testProjectData, fakeAssigneeClient{}},
|
||||||
withMr(testProjectData, fakeMergeRequestLister{}),
|
withMr(testProjectData, fakeMergeRequestLister{}),
|
||||||
withPayloadValidation(methodToPayload{http.MethodPut: &AssigneeUpdateRequest{}}),
|
withPayloadValidation(methodToPayload{http.MethodPut: newPayload[AssigneeUpdateRequest]}),
|
||||||
withMethodCheck(http.MethodPut),
|
withMethodCheck(http.MethodPut),
|
||||||
)
|
)
|
||||||
data := getSuccessData(t, svc, request)
|
data := getSuccessData(t, svc, request)
|
||||||
@@ -40,7 +40,7 @@ func TestAssigneeHandler(t *testing.T) {
|
|||||||
svc := middleware(
|
svc := middleware(
|
||||||
assigneesService{testProjectData, client},
|
assigneesService{testProjectData, client},
|
||||||
withMr(testProjectData, fakeMergeRequestLister{}),
|
withMr(testProjectData, fakeMergeRequestLister{}),
|
||||||
withPayloadValidation(methodToPayload{http.MethodPut: &AssigneeUpdateRequest{}}),
|
withPayloadValidation(methodToPayload{http.MethodPut: newPayload[AssigneeUpdateRequest]}),
|
||||||
withMethodCheck(http.MethodPut),
|
withMethodCheck(http.MethodPut),
|
||||||
)
|
)
|
||||||
data, _ := getFailData(t, svc, request)
|
data, _ := getFailData(t, svc, request)
|
||||||
@@ -53,7 +53,7 @@ func TestAssigneeHandler(t *testing.T) {
|
|||||||
svc := middleware(
|
svc := middleware(
|
||||||
assigneesService{testProjectData, client},
|
assigneesService{testProjectData, client},
|
||||||
withMr(testProjectData, fakeMergeRequestLister{}),
|
withMr(testProjectData, fakeMergeRequestLister{}),
|
||||||
withPayloadValidation(methodToPayload{http.MethodPut: &AssigneeUpdateRequest{}}),
|
withPayloadValidation(methodToPayload{http.MethodPut: newPayload[AssigneeUpdateRequest]}),
|
||||||
withMethodCheck(http.MethodPut),
|
withMethodCheck(http.MethodPut),
|
||||||
)
|
)
|
||||||
data, _ := getFailData(t, svc, request)
|
data, _ := getFailData(t, svc, request)
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ func TestAttachmentHandler(t *testing.T) {
|
|||||||
request := makeRequest(t, http.MethodPost, "/attachment", attachmentTestRequestData)
|
request := makeRequest(t, http.MethodPost, "/attachment", attachmentTestRequestData)
|
||||||
svc := middleware(
|
svc := middleware(
|
||||||
attachmentService{testProjectData, fakeFileReader{}, fakeFileUploaderClient{}},
|
attachmentService{testProjectData, fakeFileReader{}, fakeFileUploaderClient{}},
|
||||||
withPayloadValidation(methodToPayload{http.MethodPost: &AttachmentRequest{}}),
|
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[AttachmentRequest]}),
|
||||||
withMethodCheck(http.MethodPost),
|
withMethodCheck(http.MethodPost),
|
||||||
)
|
)
|
||||||
data := getSuccessData(t, svc, request)
|
data := getSuccessData(t, svc, request)
|
||||||
@@ -49,7 +49,7 @@ func TestAttachmentHandler(t *testing.T) {
|
|||||||
request := makeRequest(t, http.MethodPost, "/attachment", attachmentTestRequestData)
|
request := makeRequest(t, http.MethodPost, "/attachment", attachmentTestRequestData)
|
||||||
svc := middleware(
|
svc := middleware(
|
||||||
attachmentService{testProjectData, fakeFileReader{}, fakeFileUploaderClient{testBase{errFromGitlab: true}}},
|
attachmentService{testProjectData, fakeFileReader{}, fakeFileUploaderClient{testBase{errFromGitlab: true}}},
|
||||||
withPayloadValidation(methodToPayload{http.MethodPost: &AttachmentRequest{}}),
|
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[AttachmentRequest]}),
|
||||||
withMethodCheck(http.MethodPost),
|
withMethodCheck(http.MethodPost),
|
||||||
)
|
)
|
||||||
data, _ := getFailData(t, svc, request)
|
data, _ := getFailData(t, svc, request)
|
||||||
@@ -60,7 +60,7 @@ func TestAttachmentHandler(t *testing.T) {
|
|||||||
request := makeRequest(t, http.MethodPost, "/attachment", attachmentTestRequestData)
|
request := makeRequest(t, http.MethodPost, "/attachment", attachmentTestRequestData)
|
||||||
svc := middleware(
|
svc := middleware(
|
||||||
attachmentService{testProjectData, fakeFileReader{}, fakeFileUploaderClient{testBase{status: http.StatusSeeOther}}},
|
attachmentService{testProjectData, fakeFileReader{}, fakeFileUploaderClient{testBase{status: http.StatusSeeOther}}},
|
||||||
withPayloadValidation(methodToPayload{http.MethodPost: &AttachmentRequest{}}),
|
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[AttachmentRequest]}),
|
||||||
withMethodCheck(http.MethodPost),
|
withMethodCheck(http.MethodPost),
|
||||||
)
|
)
|
||||||
data, _ := getFailData(t, svc, request)
|
data, _ := getFailData(t, svc, request)
|
||||||
|
|||||||
@@ -33,13 +33,13 @@ type Client struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* NewClient parses and validates the project settings and initializes the Gitlab client. */
|
/* NewClient parses and validates the project settings and initializes the Gitlab client. */
|
||||||
func NewClient() (error, *Client) {
|
func NewClient() (*Client, error) {
|
||||||
|
|
||||||
if pluginOptions.GitlabUrl == "" {
|
if pluginOptions.GitlabUrl == "" {
|
||||||
return errors.New("GitLab instance URL cannot be empty"), nil
|
return nil, errors.New("GitLab instance URL cannot be empty")
|
||||||
}
|
}
|
||||||
|
|
||||||
var apiCustUrl = fmt.Sprintf(pluginOptions.GitlabUrl + "/api/v4")
|
var apiCustUrl = fmt.Sprintf("%s/api/v4", pluginOptions.GitlabUrl)
|
||||||
|
|
||||||
gitlabOptions := []gitlab.ClientOptionFunc{
|
gitlabOptions := []gitlab.ClientOptionFunc{
|
||||||
gitlab.WithBaseURL(apiCustUrl),
|
gitlab.WithBaseURL(apiCustUrl),
|
||||||
@@ -73,10 +73,10 @@ func NewClient() (error, *Client) {
|
|||||||
client, err := gitlab.NewClient(pluginOptions.AuthToken, gitlabOptions...)
|
client, err := gitlab.NewClient(pluginOptions.AuthToken, gitlabOptions...)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed to create client: %v", err), nil
|
return nil, fmt.Errorf("failed to create client: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, &Client{
|
return &Client{
|
||||||
MergeRequestsService: client.MergeRequests,
|
MergeRequestsService: client.MergeRequests,
|
||||||
MergeRequestApprovalsService: client.MergeRequestApprovals,
|
MergeRequestApprovalsService: client.MergeRequestApprovals,
|
||||||
DiscussionsService: client.Discussions,
|
DiscussionsService: client.Discussions,
|
||||||
@@ -88,28 +88,28 @@ func NewClient() (error, *Client) {
|
|||||||
AwardEmojiService: client.AwardEmoji,
|
AwardEmojiService: client.AwardEmoji,
|
||||||
UsersService: client.Users,
|
UsersService: client.Users,
|
||||||
DraftNotesService: client.DraftNotes,
|
DraftNotesService: client.DraftNotes,
|
||||||
}
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
/* InitProjectSettings fetch the project ID using the client */
|
/* InitProjectSettings fetch the project ID using the client */
|
||||||
func InitProjectSettings(c *Client, gitInfo git.GitData) (error, *ProjectInfo) {
|
func InitProjectSettings(c *Client, gitInfo git.GitData) (*ProjectInfo, error) {
|
||||||
|
|
||||||
opt := gitlab.GetProjectOptions{}
|
opt := gitlab.GetProjectOptions{}
|
||||||
project, _, err := c.GetProject(gitInfo.ProjectPath(), &opt)
|
project, _, err := c.GetProject(gitInfo.ProjectPath(), &opt)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf(fmt.Sprintf("Error getting project at %s", gitInfo.RemoteUrl), err), nil
|
return nil, fmt.Errorf(fmt.Sprintf("Error getting project at %s", gitInfo.RemoteUrl), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if project == nil {
|
if project == nil {
|
||||||
return fmt.Errorf(fmt.Sprintf("Could not find project at %s", gitInfo.RemoteUrl), err), nil
|
return nil, fmt.Errorf(fmt.Sprintf("Could not find project at %s", gitInfo.RemoteUrl), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
projectId := fmt.Sprint(project.ID)
|
projectId := fmt.Sprint(project.ID)
|
||||||
|
|
||||||
return nil, &ProjectInfo{
|
return &ProjectInfo{
|
||||||
ProjectId: projectId,
|
ProjectId: projectId,
|
||||||
}
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
/* handleError is a utililty handler that returns errors to the client along with their statuses and messages */
|
/* handleError is a utililty handler that returns errors to the client along with their statuses and messages */
|
||||||
|
|||||||
@@ -44,9 +44,9 @@ func TestPostComment(t *testing.T) {
|
|||||||
commentService{testProjectData, fakeCommentClient{}},
|
commentService{testProjectData, fakeCommentClient{}},
|
||||||
withMr(testProjectData, fakeMergeRequestLister{}),
|
withMr(testProjectData, fakeMergeRequestLister{}),
|
||||||
withPayloadValidation(methodToPayload{
|
withPayloadValidation(methodToPayload{
|
||||||
http.MethodPost: &PostCommentRequest{},
|
http.MethodPost: newPayload[PostCommentRequest],
|
||||||
http.MethodDelete: &DeleteCommentRequest{},
|
http.MethodDelete: newPayload[DeleteCommentRequest],
|
||||||
http.MethodPatch: &EditCommentRequest{},
|
http.MethodPatch: newPayload[EditCommentRequest],
|
||||||
}),
|
}),
|
||||||
withMethodCheck(http.MethodPost, http.MethodDelete, http.MethodPatch),
|
withMethodCheck(http.MethodPost, http.MethodDelete, http.MethodPatch),
|
||||||
)
|
)
|
||||||
@@ -66,9 +66,9 @@ func TestPostComment(t *testing.T) {
|
|||||||
commentService{testProjectData, fakeCommentClient{}},
|
commentService{testProjectData, fakeCommentClient{}},
|
||||||
withMr(testProjectData, fakeMergeRequestLister{}),
|
withMr(testProjectData, fakeMergeRequestLister{}),
|
||||||
withPayloadValidation(methodToPayload{
|
withPayloadValidation(methodToPayload{
|
||||||
http.MethodPost: &PostCommentRequest{},
|
http.MethodPost: newPayload[PostCommentRequest],
|
||||||
http.MethodDelete: &DeleteCommentRequest{},
|
http.MethodDelete: newPayload[DeleteCommentRequest],
|
||||||
http.MethodPatch: &EditCommentRequest{},
|
http.MethodPatch: newPayload[EditCommentRequest],
|
||||||
}),
|
}),
|
||||||
withMethodCheck(http.MethodPost, http.MethodDelete, http.MethodPatch),
|
withMethodCheck(http.MethodPost, http.MethodDelete, http.MethodPatch),
|
||||||
)
|
)
|
||||||
@@ -82,9 +82,9 @@ func TestPostComment(t *testing.T) {
|
|||||||
commentService{testProjectData, fakeCommentClient{testBase{errFromGitlab: true}}},
|
commentService{testProjectData, fakeCommentClient{testBase{errFromGitlab: true}}},
|
||||||
withMr(testProjectData, fakeMergeRequestLister{}),
|
withMr(testProjectData, fakeMergeRequestLister{}),
|
||||||
withPayloadValidation(methodToPayload{
|
withPayloadValidation(methodToPayload{
|
||||||
http.MethodPost: &PostCommentRequest{},
|
http.MethodPost: newPayload[PostCommentRequest],
|
||||||
http.MethodDelete: &DeleteCommentRequest{},
|
http.MethodDelete: newPayload[DeleteCommentRequest],
|
||||||
http.MethodPatch: &EditCommentRequest{},
|
http.MethodPatch: newPayload[EditCommentRequest],
|
||||||
}),
|
}),
|
||||||
withMethodCheck(http.MethodPost, http.MethodDelete, http.MethodPatch),
|
withMethodCheck(http.MethodPost, http.MethodDelete, http.MethodPatch),
|
||||||
)
|
)
|
||||||
@@ -98,9 +98,9 @@ func TestPostComment(t *testing.T) {
|
|||||||
commentService{testProjectData, fakeCommentClient{testBase{status: http.StatusSeeOther}}},
|
commentService{testProjectData, fakeCommentClient{testBase{status: http.StatusSeeOther}}},
|
||||||
withMr(testProjectData, fakeMergeRequestLister{}),
|
withMr(testProjectData, fakeMergeRequestLister{}),
|
||||||
withPayloadValidation(methodToPayload{
|
withPayloadValidation(methodToPayload{
|
||||||
http.MethodPost: &PostCommentRequest{},
|
http.MethodPost: newPayload[PostCommentRequest],
|
||||||
http.MethodDelete: &DeleteCommentRequest{},
|
http.MethodDelete: newPayload[DeleteCommentRequest],
|
||||||
http.MethodPatch: &EditCommentRequest{},
|
http.MethodPatch: newPayload[EditCommentRequest],
|
||||||
}),
|
}),
|
||||||
withMethodCheck(http.MethodPost, http.MethodDelete, http.MethodPatch),
|
withMethodCheck(http.MethodPost, http.MethodDelete, http.MethodPatch),
|
||||||
)
|
)
|
||||||
@@ -117,9 +117,9 @@ func TestDeleteComment(t *testing.T) {
|
|||||||
commentService{testProjectData, fakeCommentClient{}},
|
commentService{testProjectData, fakeCommentClient{}},
|
||||||
withMr(testProjectData, fakeMergeRequestLister{}),
|
withMr(testProjectData, fakeMergeRequestLister{}),
|
||||||
withPayloadValidation(methodToPayload{
|
withPayloadValidation(methodToPayload{
|
||||||
http.MethodPost: &PostCommentRequest{},
|
http.MethodPost: newPayload[PostCommentRequest],
|
||||||
http.MethodDelete: &DeleteCommentRequest{},
|
http.MethodDelete: newPayload[DeleteCommentRequest],
|
||||||
http.MethodPatch: &EditCommentRequest{},
|
http.MethodPatch: newPayload[EditCommentRequest],
|
||||||
}),
|
}),
|
||||||
withMethodCheck(http.MethodPost, http.MethodDelete, http.MethodPatch),
|
withMethodCheck(http.MethodPost, http.MethodDelete, http.MethodPatch),
|
||||||
)
|
)
|
||||||
@@ -136,9 +136,9 @@ func TestEditComment(t *testing.T) {
|
|||||||
commentService{testProjectData, fakeCommentClient{}},
|
commentService{testProjectData, fakeCommentClient{}},
|
||||||
withMr(testProjectData, fakeMergeRequestLister{}),
|
withMr(testProjectData, fakeMergeRequestLister{}),
|
||||||
withPayloadValidation(methodToPayload{
|
withPayloadValidation(methodToPayload{
|
||||||
http.MethodPost: &PostCommentRequest{},
|
http.MethodPost: newPayload[PostCommentRequest],
|
||||||
http.MethodDelete: &DeleteCommentRequest{},
|
http.MethodDelete: newPayload[DeleteCommentRequest],
|
||||||
http.MethodPatch: &EditCommentRequest{},
|
http.MethodPatch: newPayload[EditCommentRequest],
|
||||||
}),
|
}),
|
||||||
withMethodCheck(http.MethodPost, http.MethodDelete, http.MethodPatch),
|
withMethodCheck(http.MethodPost, http.MethodDelete, http.MethodPatch),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ func TestCreateMr(t *testing.T) {
|
|||||||
request := makeRequest(t, http.MethodPost, "/create_mr", testCreateMrRequestData)
|
request := makeRequest(t, http.MethodPost, "/create_mr", testCreateMrRequestData)
|
||||||
svc := middleware(
|
svc := middleware(
|
||||||
mergeRequestCreatorService{testProjectData, fakeMergeCreatorClient{}},
|
mergeRequestCreatorService{testProjectData, fakeMergeCreatorClient{}},
|
||||||
withPayloadValidation(methodToPayload{http.MethodPost: &CreateMrRequest{}}),
|
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[CreateMrRequest]}),
|
||||||
withMethodCheck(http.MethodPost),
|
withMethodCheck(http.MethodPost),
|
||||||
)
|
)
|
||||||
data := getSuccessData(t, svc, request)
|
data := getSuccessData(t, svc, request)
|
||||||
@@ -42,7 +42,7 @@ func TestCreateMr(t *testing.T) {
|
|||||||
request := makeRequest(t, http.MethodPost, "/create_mr", testCreateMrRequestData)
|
request := makeRequest(t, http.MethodPost, "/create_mr", testCreateMrRequestData)
|
||||||
svc := middleware(
|
svc := middleware(
|
||||||
mergeRequestCreatorService{testProjectData, fakeMergeCreatorClient{testBase{errFromGitlab: true}}},
|
mergeRequestCreatorService{testProjectData, fakeMergeCreatorClient{testBase{errFromGitlab: true}}},
|
||||||
withPayloadValidation(methodToPayload{http.MethodPost: &CreateMrRequest{}}),
|
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[CreateMrRequest]}),
|
||||||
withMethodCheck(http.MethodPost),
|
withMethodCheck(http.MethodPost),
|
||||||
)
|
)
|
||||||
data, _ := getFailData(t, svc, request)
|
data, _ := getFailData(t, svc, request)
|
||||||
@@ -53,7 +53,7 @@ func TestCreateMr(t *testing.T) {
|
|||||||
request := makeRequest(t, http.MethodPost, "/create_mr", testCreateMrRequestData)
|
request := makeRequest(t, http.MethodPost, "/create_mr", testCreateMrRequestData)
|
||||||
svc := middleware(
|
svc := middleware(
|
||||||
mergeRequestCreatorService{testProjectData, fakeMergeCreatorClient{testBase{status: http.StatusSeeOther}}},
|
mergeRequestCreatorService{testProjectData, fakeMergeCreatorClient{testBase{status: http.StatusSeeOther}}},
|
||||||
withPayloadValidation(methodToPayload{http.MethodPost: &CreateMrRequest{}}),
|
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[CreateMrRequest]}),
|
||||||
withMethodCheck(http.MethodPost),
|
withMethodCheck(http.MethodPost),
|
||||||
)
|
)
|
||||||
data, _ := getFailData(t, svc, request)
|
data, _ := getFailData(t, svc, request)
|
||||||
@@ -66,7 +66,7 @@ func TestCreateMr(t *testing.T) {
|
|||||||
request := makeRequest(t, http.MethodPost, "/create_mr", reqData)
|
request := makeRequest(t, http.MethodPost, "/create_mr", reqData)
|
||||||
svc := middleware(
|
svc := middleware(
|
||||||
mergeRequestCreatorService{testProjectData, fakeMergeCreatorClient{}},
|
mergeRequestCreatorService{testProjectData, fakeMergeCreatorClient{}},
|
||||||
withPayloadValidation(methodToPayload{http.MethodPost: &CreateMrRequest{}}),
|
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[CreateMrRequest]}),
|
||||||
withMethodCheck(http.MethodPost),
|
withMethodCheck(http.MethodPost),
|
||||||
)
|
)
|
||||||
data, _ := getFailData(t, svc, request)
|
data, _ := getFailData(t, svc, request)
|
||||||
@@ -80,7 +80,7 @@ func TestCreateMr(t *testing.T) {
|
|||||||
request := makeRequest(t, http.MethodPost, "/create_mr", reqData)
|
request := makeRequest(t, http.MethodPost, "/create_mr", reqData)
|
||||||
svc := middleware(
|
svc := middleware(
|
||||||
mergeRequestCreatorService{testProjectData, fakeMergeCreatorClient{}},
|
mergeRequestCreatorService{testProjectData, fakeMergeCreatorClient{}},
|
||||||
withPayloadValidation(methodToPayload{http.MethodPost: &CreateMrRequest{}}),
|
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[CreateMrRequest]}),
|
||||||
withMethodCheck(http.MethodPost),
|
withMethodCheck(http.MethodPost),
|
||||||
)
|
)
|
||||||
data, _ := getFailData(t, svc, request)
|
data, _ := getFailData(t, svc, request)
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ func TestPublishDraftNote(t *testing.T) {
|
|||||||
svc := middleware(
|
svc := middleware(
|
||||||
draftNotePublisherService{testProjectData, fakeDraftNotePublisher{}},
|
draftNotePublisherService{testProjectData, fakeDraftNotePublisher{}},
|
||||||
withMr(testProjectData, fakeMergeRequestLister{}),
|
withMr(testProjectData, fakeMergeRequestLister{}),
|
||||||
withPayloadValidation(methodToPayload{http.MethodPost: &DraftNotePublishRequest{}}),
|
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[DraftNotePublishRequest]}),
|
||||||
withMethodCheck(http.MethodPost),
|
withMethodCheck(http.MethodPost),
|
||||||
)
|
)
|
||||||
data := getSuccessData(t, svc, request)
|
data := getSuccessData(t, svc, request)
|
||||||
@@ -36,7 +36,7 @@ func TestPublishDraftNote(t *testing.T) {
|
|||||||
svc := middleware(
|
svc := middleware(
|
||||||
draftNotePublisherService{testProjectData, fakeDraftNotePublisher{testBase: testBase{errFromGitlab: true}}},
|
draftNotePublisherService{testProjectData, fakeDraftNotePublisher{testBase: testBase{errFromGitlab: true}}},
|
||||||
withMr(testProjectData, fakeMergeRequestLister{}),
|
withMr(testProjectData, fakeMergeRequestLister{}),
|
||||||
withPayloadValidation(methodToPayload{http.MethodPost: &DraftNotePublishRequest{}}),
|
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[DraftNotePublishRequest]}),
|
||||||
withMethodCheck(http.MethodPost),
|
withMethodCheck(http.MethodPost),
|
||||||
)
|
)
|
||||||
data, _ := getFailData(t, svc, request)
|
data, _ := getFailData(t, svc, request)
|
||||||
@@ -51,7 +51,7 @@ func TestPublishAllDraftNotes(t *testing.T) {
|
|||||||
svc := middleware(
|
svc := middleware(
|
||||||
draftNotePublisherService{testProjectData, fakeDraftNotePublisher{}},
|
draftNotePublisherService{testProjectData, fakeDraftNotePublisher{}},
|
||||||
withMr(testProjectData, fakeMergeRequestLister{}),
|
withMr(testProjectData, fakeMergeRequestLister{}),
|
||||||
withPayloadValidation(methodToPayload{http.MethodPost: &DraftNotePublishRequest{}}),
|
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[DraftNotePublishRequest]}),
|
||||||
withMethodCheck(http.MethodPost),
|
withMethodCheck(http.MethodPost),
|
||||||
)
|
)
|
||||||
data := getSuccessData(t, svc, request)
|
data := getSuccessData(t, svc, request)
|
||||||
@@ -62,7 +62,7 @@ func TestPublishAllDraftNotes(t *testing.T) {
|
|||||||
svc := middleware(
|
svc := middleware(
|
||||||
draftNotePublisherService{testProjectData, fakeDraftNotePublisher{testBase: testBase{errFromGitlab: true}}},
|
draftNotePublisherService{testProjectData, fakeDraftNotePublisher{testBase: testBase{errFromGitlab: true}}},
|
||||||
withMr(testProjectData, fakeMergeRequestLister{}),
|
withMr(testProjectData, fakeMergeRequestLister{}),
|
||||||
withPayloadValidation(methodToPayload{http.MethodPost: &DraftNotePublishRequest{}}),
|
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[DraftNotePublishRequest]}),
|
||||||
withMethodCheck(http.MethodPost),
|
withMethodCheck(http.MethodPost),
|
||||||
)
|
)
|
||||||
data, _ := getFailData(t, svc, request)
|
data, _ := getFailData(t, svc, request)
|
||||||
|
|||||||
@@ -183,7 +183,7 @@ func (a draftNoteService) updateDraftNote(w http.ResponseWriter, r *http.Request
|
|||||||
payload := r.Context().Value(payload("payload")).(*UpdateDraftNoteRequest)
|
payload := r.Context().Value(payload("payload")).(*UpdateDraftNoteRequest)
|
||||||
|
|
||||||
if payload.Note == "" {
|
if payload.Note == "" {
|
||||||
handleError(w, errors.New("Draft note text missing"), "Must provide draft note text", http.StatusBadRequest)
|
handleError(w, errors.New("draft note text missing"), "Must provide draft note text", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,8 +46,8 @@ func TestListDraftNotes(t *testing.T) {
|
|||||||
draftNoteService{testProjectData, fakeDraftNoteManager{}},
|
draftNoteService{testProjectData, fakeDraftNoteManager{}},
|
||||||
withMr(testProjectData, fakeMergeRequestLister{}),
|
withMr(testProjectData, fakeMergeRequestLister{}),
|
||||||
withPayloadValidation(methodToPayload{
|
withPayloadValidation(methodToPayload{
|
||||||
http.MethodPost: &PostDraftNoteRequest{},
|
http.MethodPost: newPayload[PostDraftNoteRequest],
|
||||||
http.MethodPatch: &UpdateDraftNoteRequest{},
|
http.MethodPatch: newPayload[UpdateDraftNoteRequest],
|
||||||
}),
|
}),
|
||||||
withMethodCheck(http.MethodGet, http.MethodPost, http.MethodPatch, http.MethodDelete),
|
withMethodCheck(http.MethodGet, http.MethodPost, http.MethodPatch, http.MethodDelete),
|
||||||
)
|
)
|
||||||
@@ -61,8 +61,8 @@ func TestListDraftNotes(t *testing.T) {
|
|||||||
draftNoteService{testProjectData, fakeDraftNoteManager{testBase: testBase{errFromGitlab: true}}},
|
draftNoteService{testProjectData, fakeDraftNoteManager{testBase: testBase{errFromGitlab: true}}},
|
||||||
withMr(testProjectData, fakeMergeRequestLister{}),
|
withMr(testProjectData, fakeMergeRequestLister{}),
|
||||||
withPayloadValidation(methodToPayload{
|
withPayloadValidation(methodToPayload{
|
||||||
http.MethodPost: &PostDraftNoteRequest{},
|
http.MethodPost: newPayload[PostDraftNoteRequest],
|
||||||
http.MethodPatch: &UpdateDraftNoteRequest{},
|
http.MethodPatch: newPayload[UpdateDraftNoteRequest],
|
||||||
}),
|
}),
|
||||||
withMethodCheck(http.MethodGet, http.MethodPost, http.MethodPatch, http.MethodDelete),
|
withMethodCheck(http.MethodGet, http.MethodPost, http.MethodPatch, http.MethodDelete),
|
||||||
)
|
)
|
||||||
@@ -75,8 +75,8 @@ func TestListDraftNotes(t *testing.T) {
|
|||||||
draftNoteService{testProjectData, fakeDraftNoteManager{testBase: testBase{status: http.StatusSeeOther}}},
|
draftNoteService{testProjectData, fakeDraftNoteManager{testBase: testBase{status: http.StatusSeeOther}}},
|
||||||
withMr(testProjectData, fakeMergeRequestLister{}),
|
withMr(testProjectData, fakeMergeRequestLister{}),
|
||||||
withPayloadValidation(methodToPayload{
|
withPayloadValidation(methodToPayload{
|
||||||
http.MethodPost: &PostDraftNoteRequest{},
|
http.MethodPost: newPayload[PostDraftNoteRequest],
|
||||||
http.MethodPatch: &UpdateDraftNoteRequest{},
|
http.MethodPatch: newPayload[UpdateDraftNoteRequest],
|
||||||
}),
|
}),
|
||||||
withMethodCheck(http.MethodGet, http.MethodPost, http.MethodPatch, http.MethodDelete),
|
withMethodCheck(http.MethodGet, http.MethodPost, http.MethodPatch, http.MethodDelete),
|
||||||
)
|
)
|
||||||
@@ -96,8 +96,8 @@ func TestPostDraftNote(t *testing.T) {
|
|||||||
draftNoteService{testProjectData, fakeDraftNoteManager{}},
|
draftNoteService{testProjectData, fakeDraftNoteManager{}},
|
||||||
withMr(testProjectData, fakeMergeRequestLister{}),
|
withMr(testProjectData, fakeMergeRequestLister{}),
|
||||||
withPayloadValidation(methodToPayload{
|
withPayloadValidation(methodToPayload{
|
||||||
http.MethodPost: &PostDraftNoteRequest{},
|
http.MethodPost: newPayload[PostDraftNoteRequest],
|
||||||
http.MethodPatch: &UpdateDraftNoteRequest{},
|
http.MethodPatch: newPayload[UpdateDraftNoteRequest],
|
||||||
}),
|
}),
|
||||||
withMethodCheck(http.MethodGet, http.MethodPost, http.MethodPatch, http.MethodDelete),
|
withMethodCheck(http.MethodGet, http.MethodPost, http.MethodPatch, http.MethodDelete),
|
||||||
)
|
)
|
||||||
@@ -113,8 +113,8 @@ func TestDeleteDraftNote(t *testing.T) {
|
|||||||
draftNoteService{testProjectData, fakeDraftNoteManager{}},
|
draftNoteService{testProjectData, fakeDraftNoteManager{}},
|
||||||
withMr(testProjectData, fakeMergeRequestLister{}),
|
withMr(testProjectData, fakeMergeRequestLister{}),
|
||||||
withPayloadValidation(methodToPayload{
|
withPayloadValidation(methodToPayload{
|
||||||
http.MethodPost: &PostDraftNoteRequest{},
|
http.MethodPost: newPayload[PostDraftNoteRequest],
|
||||||
http.MethodPatch: &UpdateDraftNoteRequest{},
|
http.MethodPatch: newPayload[UpdateDraftNoteRequest],
|
||||||
}),
|
}),
|
||||||
withMethodCheck(http.MethodGet, http.MethodPost, http.MethodPatch, http.MethodDelete),
|
withMethodCheck(http.MethodGet, http.MethodPost, http.MethodPatch, http.MethodDelete),
|
||||||
)
|
)
|
||||||
@@ -127,8 +127,8 @@ func TestDeleteDraftNote(t *testing.T) {
|
|||||||
draftNoteService{testProjectData, fakeDraftNoteManager{}},
|
draftNoteService{testProjectData, fakeDraftNoteManager{}},
|
||||||
withMr(testProjectData, fakeMergeRequestLister{}),
|
withMr(testProjectData, fakeMergeRequestLister{}),
|
||||||
withPayloadValidation(methodToPayload{
|
withPayloadValidation(methodToPayload{
|
||||||
http.MethodPost: &PostDraftNoteRequest{},
|
http.MethodPost: newPayload[PostDraftNoteRequest],
|
||||||
http.MethodPatch: &UpdateDraftNoteRequest{},
|
http.MethodPatch: newPayload[UpdateDraftNoteRequest],
|
||||||
}),
|
}),
|
||||||
withMethodCheck(http.MethodGet, http.MethodPost, http.MethodPatch, http.MethodDelete),
|
withMethodCheck(http.MethodGet, http.MethodPost, http.MethodPatch, http.MethodDelete),
|
||||||
)
|
)
|
||||||
@@ -146,8 +146,8 @@ func TestEditDraftNote(t *testing.T) {
|
|||||||
draftNoteService{testProjectData, fakeDraftNoteManager{}},
|
draftNoteService{testProjectData, fakeDraftNoteManager{}},
|
||||||
withMr(testProjectData, fakeMergeRequestLister{}),
|
withMr(testProjectData, fakeMergeRequestLister{}),
|
||||||
withPayloadValidation(methodToPayload{
|
withPayloadValidation(methodToPayload{
|
||||||
http.MethodPost: &PostDraftNoteRequest{},
|
http.MethodPost: newPayload[PostDraftNoteRequest],
|
||||||
http.MethodPatch: &UpdateDraftNoteRequest{},
|
http.MethodPatch: newPayload[UpdateDraftNoteRequest],
|
||||||
}),
|
}),
|
||||||
withMethodCheck(http.MethodGet, http.MethodPost, http.MethodPatch, http.MethodDelete),
|
withMethodCheck(http.MethodGet, http.MethodPost, http.MethodPatch, http.MethodDelete),
|
||||||
)
|
)
|
||||||
@@ -160,8 +160,8 @@ func TestEditDraftNote(t *testing.T) {
|
|||||||
draftNoteService{testProjectData, fakeDraftNoteManager{}},
|
draftNoteService{testProjectData, fakeDraftNoteManager{}},
|
||||||
withMr(testProjectData, fakeMergeRequestLister{}),
|
withMr(testProjectData, fakeMergeRequestLister{}),
|
||||||
withPayloadValidation(methodToPayload{
|
withPayloadValidation(methodToPayload{
|
||||||
http.MethodPost: &PostDraftNoteRequest{},
|
http.MethodPost: newPayload[PostDraftNoteRequest],
|
||||||
http.MethodPatch: &UpdateDraftNoteRequest{},
|
http.MethodPatch: newPayload[UpdateDraftNoteRequest],
|
||||||
}),
|
}),
|
||||||
withMethodCheck(http.MethodGet, http.MethodPost, http.MethodPatch, http.MethodDelete),
|
withMethodCheck(http.MethodGet, http.MethodPost, http.MethodPatch, http.MethodDelete),
|
||||||
)
|
)
|
||||||
@@ -177,8 +177,8 @@ func TestEditDraftNote(t *testing.T) {
|
|||||||
draftNoteService{testProjectData, fakeDraftNoteManager{}},
|
draftNoteService{testProjectData, fakeDraftNoteManager{}},
|
||||||
withMr(testProjectData, fakeMergeRequestLister{}),
|
withMr(testProjectData, fakeMergeRequestLister{}),
|
||||||
withPayloadValidation(methodToPayload{
|
withPayloadValidation(methodToPayload{
|
||||||
http.MethodPost: &PostDraftNoteRequest{},
|
http.MethodPost: newPayload[PostDraftNoteRequest],
|
||||||
http.MethodPatch: &UpdateDraftNoteRequest{},
|
http.MethodPatch: newPayload[UpdateDraftNoteRequest],
|
||||||
}),
|
}),
|
||||||
withMethodCheck(http.MethodGet, http.MethodPost, http.MethodPatch, http.MethodDelete),
|
withMethodCheck(http.MethodGet, http.MethodPost, http.MethodPatch, http.MethodDelete),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -64,6 +64,11 @@ func (a emojiService) deleteEmojiFromNote(w http.ResponseWriter, r *http.Request
|
|||||||
suffix := strings.TrimPrefix(r.URL.Path, "/mr/awardable/note/")
|
suffix := strings.TrimPrefix(r.URL.Path, "/mr/awardable/note/")
|
||||||
ids := strings.Split(suffix, "/")
|
ids := strings.Split(suffix, "/")
|
||||||
|
|
||||||
|
if len(ids) < 2 {
|
||||||
|
handleError(w, errors.New("missing IDs"), "Must provide note ID and awardable ID", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
noteId, err := strconv.Atoi(ids[0])
|
noteId, err := strconv.Atoi(ids[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
handleError(w, err, "Could not convert note ID to integer", http.StatusBadRequest)
|
handleError(w, err, "Could not convert note ID to integer", http.StatusBadRequest)
|
||||||
@@ -158,18 +163,18 @@ func attachEmojis(a *data, fr FileReader) error {
|
|||||||
reader, err := fr.ReadFile(filePath)
|
reader, err := fr.ReadFile(filePath)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Could not find emojis at %s", filePath)
|
return fmt.Errorf("could not find emojis at %s", filePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
bytes, err := io.ReadAll(reader)
|
bytes, err := io.ReadAll(reader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New("Could not read emoji file")
|
return errors.New("could not read emoji file")
|
||||||
}
|
}
|
||||||
|
|
||||||
var emojiMap EmojiMap
|
var emojiMap EmojiMap
|
||||||
err = json.Unmarshal(bytes, &emojiMap)
|
err = json.Unmarshal(bytes, &emojiMap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New("Could not unmarshal emojis")
|
return errors.New("could not unmarshal emojis")
|
||||||
}
|
}
|
||||||
|
|
||||||
a.emojiMap = emojiMap
|
a.emojiMap = emojiMap
|
||||||
|
|||||||
@@ -39,12 +39,12 @@ Gitlab project and the branch must be a feature branch
|
|||||||
func NewGitData(remote string, g GitManager) (GitData, error) {
|
func NewGitData(remote string, g GitManager) (GitData, error) {
|
||||||
err := g.RefreshProjectInfo(remote)
|
err := g.RefreshProjectInfo(remote)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return GitData{}, fmt.Errorf("Could not get latest information from remote: %v", err)
|
return GitData{}, fmt.Errorf("could not get latest information from remote: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
url, err := g.GetProjectUrlFromNativeGitCmd(remote)
|
url, err := g.GetProjectUrlFromNativeGitCmd(remote)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return GitData{}, fmt.Errorf("Could not get project Url: %v", err)
|
return GitData{}, fmt.Errorf("could not get project Url: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -62,7 +62,7 @@ func NewGitData(remote string, g GitManager) (GitData, error) {
|
|||||||
re := regexp.MustCompile(`^(?:git@[^\/:]*|https?:\/\/[^\/]+|ssh:\/\/[^\/:]+)(?::\d+)?[\/:](.*)\/([^\/]+?)(?:\.git)?\/?$`)
|
re := regexp.MustCompile(`^(?:git@[^\/:]*|https?:\/\/[^\/]+|ssh:\/\/[^\/:]+)(?::\d+)?[\/:](.*)\/([^\/]+?)(?:\.git)?\/?$`)
|
||||||
matches := re.FindStringSubmatch(url)
|
matches := re.FindStringSubmatch(url)
|
||||||
if len(matches) != 3 {
|
if len(matches) != 3 {
|
||||||
return GitData{}, fmt.Errorf("Invalid Git URL format: %s", url)
|
return GitData{}, fmt.Errorf("invalid git URL format: %s", url)
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace := matches[1]
|
namespace := matches[1]
|
||||||
@@ -70,7 +70,7 @@ func NewGitData(remote string, g GitManager) (GitData, error) {
|
|||||||
|
|
||||||
branchName, err := g.GetCurrentBranchNameFromNativeGitCmd()
|
branchName, err := g.GetCurrentBranchNameFromNativeGitCmd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return GitData{}, fmt.Errorf("Failed to get current branch: %v", err)
|
return GitData{}, fmt.Errorf("failed to get current branch: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return GitData{
|
return GitData{
|
||||||
@@ -88,7 +88,7 @@ func (g Git) GetCurrentBranchNameFromNativeGitCmd() (res string, e error) {
|
|||||||
|
|
||||||
output, err := gitCmd.Output()
|
output, err := gitCmd.Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("Error running git rev-parse: %w", err)
|
return "", fmt.Errorf("error running git rev-parse: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
branchName := strings.TrimSpace(string(output))
|
branchName := strings.TrimSpace(string(output))
|
||||||
@@ -101,7 +101,7 @@ func (g Git) GetProjectUrlFromNativeGitCmd(remote string) (string, error) {
|
|||||||
cmd := exec.Command("git", "remote", "get-url", remote)
|
cmd := exec.Command("git", "remote", "get-url", remote)
|
||||||
url, err := cmd.Output()
|
url, err := cmd.Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("Could not get remote")
|
return "", fmt.Errorf("could not get remote")
|
||||||
}
|
}
|
||||||
|
|
||||||
return strings.TrimSpace(string(url)), nil
|
return strings.TrimSpace(string(url)), nil
|
||||||
@@ -112,7 +112,7 @@ func (g Git) RefreshProjectInfo(remote string) error {
|
|||||||
cmd := exec.Command("git", "fetch", remote)
|
cmd := exec.Command("git", "fetch", remote)
|
||||||
_, err := cmd.Output()
|
_, err := cmd.Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed to run `git fetch %s`: %v", remote, err)
|
return fmt.Errorf("failed to run `git fetch %s`: %v", remote, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -123,7 +123,7 @@ func (g Git) GetLatestCommitOnRemote(remote string, branchName string) (string,
|
|||||||
|
|
||||||
out, err := cmd.Output()
|
out, err := cmd.Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("Failed to run `git log -1 --format=%%H " + fmt.Sprintf("%s/%s", remote, branchName))
|
return "", fmt.Errorf("failed to run `git log -1 --format=%%H %s/%s`", remote, branchName)
|
||||||
}
|
}
|
||||||
|
|
||||||
commit := strings.TrimSpace(string(out))
|
commit := strings.TrimSpace(string(out))
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ func TestJobHandler(t *testing.T) {
|
|||||||
request := makeRequest(t, http.MethodGet, "/job", JobTraceRequest{JobId: 3})
|
request := makeRequest(t, http.MethodGet, "/job", JobTraceRequest{JobId: 3})
|
||||||
svc := middleware(
|
svc := middleware(
|
||||||
traceFileService{testProjectData, fakeTraceFileGetter{}},
|
traceFileService{testProjectData, fakeTraceFileGetter{}},
|
||||||
withPayloadValidation(methodToPayload{http.MethodGet: &JobTraceRequest{}}),
|
withPayloadValidation(methodToPayload{http.MethodGet: newPayload[JobTraceRequest]}),
|
||||||
withMethodCheck(http.MethodGet),
|
withMethodCheck(http.MethodGet),
|
||||||
)
|
)
|
||||||
data := getTraceFileData(t, svc, request)
|
data := getTraceFileData(t, svc, request)
|
||||||
@@ -51,7 +51,7 @@ func TestJobHandler(t *testing.T) {
|
|||||||
request := makeRequest(t, http.MethodGet, "/job", JobTraceRequest{JobId: 2})
|
request := makeRequest(t, http.MethodGet, "/job", JobTraceRequest{JobId: 2})
|
||||||
svc := middleware(
|
svc := middleware(
|
||||||
traceFileService{testProjectData, fakeTraceFileGetter{testBase{errFromGitlab: true}}},
|
traceFileService{testProjectData, fakeTraceFileGetter{testBase{errFromGitlab: true}}},
|
||||||
withPayloadValidation(methodToPayload{http.MethodGet: &JobTraceRequest{}}),
|
withPayloadValidation(methodToPayload{http.MethodGet: newPayload[JobTraceRequest]}),
|
||||||
withMethodCheck(http.MethodGet),
|
withMethodCheck(http.MethodGet),
|
||||||
)
|
)
|
||||||
data, _ := getFailData(t, svc, request)
|
data, _ := getFailData(t, svc, request)
|
||||||
@@ -62,7 +62,7 @@ func TestJobHandler(t *testing.T) {
|
|||||||
request := makeRequest(t, http.MethodGet, "/job", JobTraceRequest{JobId: 1})
|
request := makeRequest(t, http.MethodGet, "/job", JobTraceRequest{JobId: 1})
|
||||||
svc := middleware(
|
svc := middleware(
|
||||||
traceFileService{testProjectData, fakeTraceFileGetter{testBase{status: http.StatusSeeOther}}},
|
traceFileService{testProjectData, fakeTraceFileGetter{testBase{status: http.StatusSeeOther}}},
|
||||||
withPayloadValidation(methodToPayload{http.MethodGet: &JobTraceRequest{}}),
|
withPayloadValidation(methodToPayload{http.MethodGet: newPayload[JobTraceRequest]}),
|
||||||
withMethodCheck(http.MethodGet),
|
withMethodCheck(http.MethodGet),
|
||||||
)
|
)
|
||||||
data, _ := getFailData(t, svc, request)
|
data, _ := getFailData(t, svc, request)
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ func (a discussionsListerService) ServeHTTP(w http.ResponseWriter, r *http.Reque
|
|||||||
var linkedDiscussions []*gitlab.Discussion
|
var linkedDiscussions []*gitlab.Discussion
|
||||||
|
|
||||||
for _, discussion := range discussions {
|
for _, discussion := range discussions {
|
||||||
if discussion.Notes == nil || len(discussion.Notes) == 0 || Contains(request.Blacklist, discussion.Notes[0].Author.Username) {
|
if len(discussion.Notes) == 0 || Contains(request.Blacklist, discussion.Notes[0].Author.Username) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
for _, note := range discussion.Notes {
|
for _, note := range discussion.Notes {
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ func TestListDiscussions(t *testing.T) {
|
|||||||
svc := middleware(
|
svc := middleware(
|
||||||
discussionsListerService{testProjectData, fakeDiscussionsLister{}},
|
discussionsListerService{testProjectData, fakeDiscussionsLister{}},
|
||||||
withMr(testProjectData, fakeMergeRequestLister{}),
|
withMr(testProjectData, fakeMergeRequestLister{}),
|
||||||
withPayloadValidation(methodToPayload{http.MethodPost: &DiscussionsRequest{}}),
|
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[DiscussionsRequest]}),
|
||||||
withMethodCheck(http.MethodPost),
|
withMethodCheck(http.MethodPost),
|
||||||
)
|
)
|
||||||
data := getDiscussionsList(t, svc, request)
|
data := getDiscussionsList(t, svc, request)
|
||||||
@@ -85,7 +85,7 @@ func TestListDiscussions(t *testing.T) {
|
|||||||
svc := middleware(
|
svc := middleware(
|
||||||
discussionsListerService{testProjectData, fakeDiscussionsLister{}},
|
discussionsListerService{testProjectData, fakeDiscussionsLister{}},
|
||||||
withMr(testProjectData, fakeMergeRequestLister{}),
|
withMr(testProjectData, fakeMergeRequestLister{}),
|
||||||
withPayloadValidation(methodToPayload{http.MethodPost: &DiscussionsRequest{}}),
|
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[DiscussionsRequest]}),
|
||||||
withMethodCheck(http.MethodPost),
|
withMethodCheck(http.MethodPost),
|
||||||
)
|
)
|
||||||
data := getDiscussionsList(t, svc, request)
|
data := getDiscussionsList(t, svc, request)
|
||||||
@@ -98,7 +98,7 @@ func TestListDiscussions(t *testing.T) {
|
|||||||
svc := middleware(
|
svc := middleware(
|
||||||
discussionsListerService{testProjectData, fakeDiscussionsLister{testBase: testBase{errFromGitlab: true}}},
|
discussionsListerService{testProjectData, fakeDiscussionsLister{testBase: testBase{errFromGitlab: true}}},
|
||||||
withMr(testProjectData, fakeMergeRequestLister{}),
|
withMr(testProjectData, fakeMergeRequestLister{}),
|
||||||
withPayloadValidation(methodToPayload{http.MethodPost: &DiscussionsRequest{}}),
|
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[DiscussionsRequest]}),
|
||||||
withMethodCheck(http.MethodPost),
|
withMethodCheck(http.MethodPost),
|
||||||
)
|
)
|
||||||
data, _ := getFailData(t, svc, request)
|
data, _ := getFailData(t, svc, request)
|
||||||
@@ -109,7 +109,7 @@ func TestListDiscussions(t *testing.T) {
|
|||||||
svc := middleware(
|
svc := middleware(
|
||||||
discussionsListerService{testProjectData, fakeDiscussionsLister{testBase: testBase{status: http.StatusSeeOther}}},
|
discussionsListerService{testProjectData, fakeDiscussionsLister{testBase: testBase{status: http.StatusSeeOther}}},
|
||||||
withMr(testProjectData, fakeMergeRequestLister{}),
|
withMr(testProjectData, fakeMergeRequestLister{}),
|
||||||
withPayloadValidation(methodToPayload{http.MethodPost: &DiscussionsRequest{}}),
|
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[DiscussionsRequest]}),
|
||||||
withMethodCheck(http.MethodPost),
|
withMethodCheck(http.MethodPost),
|
||||||
)
|
)
|
||||||
data, _ := getFailData(t, svc, request)
|
data, _ := getFailData(t, svc, request)
|
||||||
@@ -120,7 +120,7 @@ func TestListDiscussions(t *testing.T) {
|
|||||||
svc := middleware(
|
svc := middleware(
|
||||||
discussionsListerService{testProjectData, fakeDiscussionsLister{badEmojiResponse: true, testBase: testBase{}}},
|
discussionsListerService{testProjectData, fakeDiscussionsLister{badEmojiResponse: true, testBase: testBase{}}},
|
||||||
withMr(testProjectData, fakeMergeRequestLister{}),
|
withMr(testProjectData, fakeMergeRequestLister{}),
|
||||||
withPayloadValidation(methodToPayload{http.MethodPost: &DiscussionsRequest{}}),
|
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[DiscussionsRequest]}),
|
||||||
withMethodCheck(http.MethodPost),
|
withMethodCheck(http.MethodPost),
|
||||||
)
|
)
|
||||||
data, _ := getFailData(t, svc, request)
|
data, _ := getFailData(t, svc, request)
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ func (l LoggingServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
Request: r,
|
Request: r,
|
||||||
}
|
}
|
||||||
if pluginOptions.Debug.Response {
|
if pluginOptions.Debug.Response {
|
||||||
logResponse("RESPONSE FROM GO SERVER", resp)
|
logResponse("RESPONSE FROM GO SERVER", resp) //nolint:errcheck
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,7 +62,7 @@ func logRequest(prefix string, r *http.Request) {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
r.Header.Set("Private-Token", token)
|
r.Header.Set("Private-Token", token)
|
||||||
_, err = file.Write([]byte(fmt.Sprintf("\n-- %s --\n%s\n", prefix, res))) //nolint:all
|
fmt.Fprintf(file, "\n-- %s --\n%s\n", prefix, res) //nolint:errcheck
|
||||||
}
|
}
|
||||||
|
|
||||||
func logResponse(prefix string, r *http.Response) {
|
func logResponse(prefix string, r *http.Response) {
|
||||||
@@ -75,7 +75,7 @@ func logResponse(prefix string, r *http.Response) {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = file.Write([]byte(fmt.Sprintf("\n-- %s --\n%s\n", prefix, res))) //nolint:all
|
fmt.Fprintf(file, "\n-- %s --\n%s\n", prefix, res) //nolint:errcheck
|
||||||
}
|
}
|
||||||
|
|
||||||
func openLogFile() *os.File {
|
func openLogFile() *os.File {
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ func TestAcceptAndMergeHandler(t *testing.T) {
|
|||||||
mergeRequestAccepterService{testProjectData, fakeMergeRequestAccepter{}},
|
mergeRequestAccepterService{testProjectData, fakeMergeRequestAccepter{}},
|
||||||
withMr(testProjectData, fakeMergeRequestLister{}),
|
withMr(testProjectData, fakeMergeRequestLister{}),
|
||||||
withPayloadValidation(methodToPayload{
|
withPayloadValidation(methodToPayload{
|
||||||
http.MethodPost: &AcceptMergeRequestRequest{},
|
http.MethodPost: newPayload[AcceptMergeRequestRequest],
|
||||||
}),
|
}),
|
||||||
withMethodCheck(http.MethodPost),
|
withMethodCheck(http.MethodPost),
|
||||||
)
|
)
|
||||||
@@ -41,7 +41,7 @@ func TestAcceptAndMergeHandler(t *testing.T) {
|
|||||||
mergeRequestAccepterService{testProjectData, fakeMergeRequestAccepter{testBase{errFromGitlab: true}}},
|
mergeRequestAccepterService{testProjectData, fakeMergeRequestAccepter{testBase{errFromGitlab: true}}},
|
||||||
withMr(testProjectData, fakeMergeRequestLister{}),
|
withMr(testProjectData, fakeMergeRequestLister{}),
|
||||||
withPayloadValidation(methodToPayload{
|
withPayloadValidation(methodToPayload{
|
||||||
http.MethodPost: &AcceptMergeRequestRequest{},
|
http.MethodPost: newPayload[AcceptMergeRequestRequest],
|
||||||
}),
|
}),
|
||||||
withMethodCheck(http.MethodPost),
|
withMethodCheck(http.MethodPost),
|
||||||
)
|
)
|
||||||
@@ -54,7 +54,7 @@ func TestAcceptAndMergeHandler(t *testing.T) {
|
|||||||
mergeRequestAccepterService{testProjectData, fakeMergeRequestAccepter{testBase{status: http.StatusSeeOther}}},
|
mergeRequestAccepterService{testProjectData, fakeMergeRequestAccepter{testBase{status: http.StatusSeeOther}}},
|
||||||
withMr(testProjectData, fakeMergeRequestLister{}),
|
withMr(testProjectData, fakeMergeRequestLister{}),
|
||||||
withPayloadValidation(methodToPayload{
|
withPayloadValidation(methodToPayload{
|
||||||
http.MethodPost: &AcceptMergeRequestRequest{},
|
http.MethodPost: newPayload[AcceptMergeRequestRequest],
|
||||||
}),
|
}),
|
||||||
withMethodCheck(http.MethodPost),
|
withMethodCheck(http.MethodPost),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ func (a mergeRequestListerService) ServeHTTP(w http.ResponseWriter, r *http.Requ
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(mergeRequests) == 0 {
|
if len(mergeRequests) == 0 {
|
||||||
handleError(w, errors.New("No merge requests found"), "No merge requests found", http.StatusNotFound)
|
handleError(w, errors.New("no merge requests found"), "No merge requests found", http.StatusNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,6 +60,6 @@ func (a mergeRequestListerService) ServeHTTP(w http.ResponseWriter, r *http.Requ
|
|||||||
|
|
||||||
err = json.NewEncoder(w).Encode(response)
|
err = json.NewEncoder(w).Encode(response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
handleError(w, err, "Could not encode response", http.StatusInternalServerError)
|
handleError(w, err, "could not encode response", http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ func TestListMergeRequestByUsername(t *testing.T) {
|
|||||||
request := makeRequest(t, http.MethodPost, "/merge_requests_by_username", testListMrsByUsernamePayload)
|
request := makeRequest(t, http.MethodPost, "/merge_requests_by_username", testListMrsByUsernamePayload)
|
||||||
svc := middleware(
|
svc := middleware(
|
||||||
mergeRequestListerByUsernameService{testProjectData, fakeMergeRequestListerByUsername{}},
|
mergeRequestListerByUsernameService{testProjectData, fakeMergeRequestListerByUsername{}},
|
||||||
withPayloadValidation(methodToPayload{http.MethodPost: &MergeRequestByUsernameRequest{}}),
|
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[MergeRequestByUsernameRequest]}),
|
||||||
withMethodCheck(http.MethodPost),
|
withMethodCheck(http.MethodPost),
|
||||||
)
|
)
|
||||||
data := getSuccessData(t, svc, request)
|
data := getSuccessData(t, svc, request)
|
||||||
@@ -43,7 +43,7 @@ func TestListMergeRequestByUsername(t *testing.T) {
|
|||||||
request := makeRequest(t, http.MethodPost, "/merge_requests_by_username", testListMrsByUsernamePayload)
|
request := makeRequest(t, http.MethodPost, "/merge_requests_by_username", testListMrsByUsernamePayload)
|
||||||
svc := middleware(
|
svc := middleware(
|
||||||
mergeRequestListerByUsernameService{testProjectData, fakeMergeRequestListerByUsername{emptyResponse: true}},
|
mergeRequestListerByUsernameService{testProjectData, fakeMergeRequestListerByUsername{emptyResponse: true}},
|
||||||
withPayloadValidation(methodToPayload{http.MethodPost: &MergeRequestByUsernameRequest{}}),
|
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[MergeRequestByUsernameRequest]}),
|
||||||
withMethodCheck(http.MethodPost),
|
withMethodCheck(http.MethodPost),
|
||||||
)
|
)
|
||||||
data, status := getFailData(t, svc, request)
|
data, status := getFailData(t, svc, request)
|
||||||
@@ -58,7 +58,7 @@ func TestListMergeRequestByUsername(t *testing.T) {
|
|||||||
request := makeRequest(t, http.MethodPost, "/merge_requests_by_username", missingUsernamePayload)
|
request := makeRequest(t, http.MethodPost, "/merge_requests_by_username", missingUsernamePayload)
|
||||||
svc := middleware(
|
svc := middleware(
|
||||||
mergeRequestListerByUsernameService{testProjectData, fakeMergeRequestListerByUsername{}},
|
mergeRequestListerByUsernameService{testProjectData, fakeMergeRequestListerByUsername{}},
|
||||||
withPayloadValidation(methodToPayload{http.MethodPost: &MergeRequestByUsernameRequest{}}),
|
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[MergeRequestByUsernameRequest]}),
|
||||||
withMethodCheck(http.MethodPost),
|
withMethodCheck(http.MethodPost),
|
||||||
)
|
)
|
||||||
data, status := getFailData(t, svc, request)
|
data, status := getFailData(t, svc, request)
|
||||||
@@ -73,7 +73,7 @@ func TestListMergeRequestByUsername(t *testing.T) {
|
|||||||
request := makeRequest(t, http.MethodPost, "/merge_requests_by_username", missingUsernamePayload)
|
request := makeRequest(t, http.MethodPost, "/merge_requests_by_username", missingUsernamePayload)
|
||||||
svc := middleware(
|
svc := middleware(
|
||||||
mergeRequestListerByUsernameService{testProjectData, fakeMergeRequestListerByUsername{}},
|
mergeRequestListerByUsernameService{testProjectData, fakeMergeRequestListerByUsername{}},
|
||||||
withPayloadValidation(methodToPayload{http.MethodPost: &MergeRequestByUsernameRequest{}}),
|
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[MergeRequestByUsernameRequest]}),
|
||||||
withMethodCheck(http.MethodPost),
|
withMethodCheck(http.MethodPost),
|
||||||
)
|
)
|
||||||
data, status := getFailData(t, svc, request)
|
data, status := getFailData(t, svc, request)
|
||||||
@@ -86,12 +86,12 @@ func TestListMergeRequestByUsername(t *testing.T) {
|
|||||||
request := makeRequest(t, http.MethodPost, "/merge_requests_by_username", testListMrsByUsernamePayload)
|
request := makeRequest(t, http.MethodPost, "/merge_requests_by_username", testListMrsByUsernamePayload)
|
||||||
svc := middleware(
|
svc := middleware(
|
||||||
mergeRequestListerByUsernameService{testProjectData, fakeMergeRequestListerByUsername{testBase: testBase{errFromGitlab: true}}},
|
mergeRequestListerByUsernameService{testProjectData, fakeMergeRequestListerByUsername{testBase: testBase{errFromGitlab: true}}},
|
||||||
withPayloadValidation(methodToPayload{http.MethodPost: &MergeRequestByUsernameRequest{}}),
|
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[MergeRequestByUsernameRequest]}),
|
||||||
withMethodCheck(http.MethodPost),
|
withMethodCheck(http.MethodPost),
|
||||||
)
|
)
|
||||||
data, status := getFailData(t, svc, request)
|
data, status := getFailData(t, svc, request)
|
||||||
assert(t, data.Message, "An error occurred")
|
assert(t, data.Message, "An error occurred")
|
||||||
assert(t, data.Details, strings.Repeat("Some error from Gitlab; ", 3))
|
assert(t, data.Details, strings.Repeat("some error from Gitlab; ", 3))
|
||||||
assert(t, status, http.StatusInternalServerError)
|
assert(t, status, http.StatusInternalServerError)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -99,7 +99,7 @@ func TestListMergeRequestByUsername(t *testing.T) {
|
|||||||
request := makeRequest(t, http.MethodPost, "/merge_requests_by_username", testListMrsByUsernamePayload)
|
request := makeRequest(t, http.MethodPost, "/merge_requests_by_username", testListMrsByUsernamePayload)
|
||||||
svc := middleware(
|
svc := middleware(
|
||||||
mergeRequestListerByUsernameService{testProjectData, fakeMergeRequestListerByUsername{testBase: testBase{status: http.StatusSeeOther}}},
|
mergeRequestListerByUsernameService{testProjectData, fakeMergeRequestListerByUsername{testBase: testBase{status: http.StatusSeeOther}}},
|
||||||
withPayloadValidation(methodToPayload{http.MethodPost: &MergeRequestByUsernameRequest{}}),
|
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[MergeRequestByUsernameRequest]}),
|
||||||
withMethodCheck(http.MethodPost),
|
withMethodCheck(http.MethodPost),
|
||||||
)
|
)
|
||||||
data, status := getFailData(t, svc, request)
|
data, status := getFailData(t, svc, request)
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ func TestMergeRequestHandler(t *testing.T) {
|
|||||||
request := makeRequest(t, http.MethodPost, "/merge_requests", testListMergeRequestsRequest)
|
request := makeRequest(t, http.MethodPost, "/merge_requests", testListMergeRequestsRequest)
|
||||||
svc := middleware(
|
svc := middleware(
|
||||||
mergeRequestListerService{testProjectData, fakeMergeRequestLister{}},
|
mergeRequestListerService{testProjectData, fakeMergeRequestLister{}},
|
||||||
withPayloadValidation(methodToPayload{http.MethodPost: &gitlab.ListProjectMergeRequestsOptions{}}),
|
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[gitlab.ListProjectMergeRequestsOptions]}),
|
||||||
withMethodCheck(http.MethodPost),
|
withMethodCheck(http.MethodPost),
|
||||||
)
|
)
|
||||||
data := getSuccessData(t, svc, request)
|
data := getSuccessData(t, svc, request)
|
||||||
@@ -46,7 +46,7 @@ func TestMergeRequestHandler(t *testing.T) {
|
|||||||
request := makeRequest(t, http.MethodPost, "/merge_requests", testListMergeRequestsRequest)
|
request := makeRequest(t, http.MethodPost, "/merge_requests", testListMergeRequestsRequest)
|
||||||
svc := middleware(
|
svc := middleware(
|
||||||
mergeRequestListerService{testProjectData, fakeMergeRequestLister{testBase: testBase{errFromGitlab: true}}},
|
mergeRequestListerService{testProjectData, fakeMergeRequestLister{testBase: testBase{errFromGitlab: true}}},
|
||||||
withPayloadValidation(methodToPayload{http.MethodPost: &gitlab.ListProjectMergeRequestsOptions{}}),
|
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[gitlab.ListProjectMergeRequestsOptions]}),
|
||||||
withMethodCheck(http.MethodPost),
|
withMethodCheck(http.MethodPost),
|
||||||
)
|
)
|
||||||
data, status := getFailData(t, svc, request)
|
data, status := getFailData(t, svc, request)
|
||||||
@@ -57,7 +57,7 @@ func TestMergeRequestHandler(t *testing.T) {
|
|||||||
request := makeRequest(t, http.MethodPost, "/merge_requests", testListMergeRequestsRequest)
|
request := makeRequest(t, http.MethodPost, "/merge_requests", testListMergeRequestsRequest)
|
||||||
svc := middleware(
|
svc := middleware(
|
||||||
mergeRequestListerService{testProjectData, fakeMergeRequestLister{testBase: testBase{status: http.StatusSeeOther}}},
|
mergeRequestListerService{testProjectData, fakeMergeRequestLister{testBase: testBase{status: http.StatusSeeOther}}},
|
||||||
withPayloadValidation(methodToPayload{http.MethodPost: &gitlab.ListProjectMergeRequestsOptions{}}),
|
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[gitlab.ListProjectMergeRequestsOptions]}),
|
||||||
withMethodCheck(http.MethodPost),
|
withMethodCheck(http.MethodPost),
|
||||||
)
|
)
|
||||||
data, status := getFailData(t, svc, request)
|
data, status := getFailData(t, svc, request)
|
||||||
@@ -68,7 +68,7 @@ func TestMergeRequestHandler(t *testing.T) {
|
|||||||
request := makeRequest(t, http.MethodPost, "/merge_requests", testListMergeRequestsRequest)
|
request := makeRequest(t, http.MethodPost, "/merge_requests", testListMergeRequestsRequest)
|
||||||
svc := middleware(
|
svc := middleware(
|
||||||
mergeRequestListerService{testProjectData, fakeMergeRequestLister{emptyResponse: true}},
|
mergeRequestListerService{testProjectData, fakeMergeRequestLister{emptyResponse: true}},
|
||||||
withPayloadValidation(methodToPayload{http.MethodPost: &gitlab.ListProjectMergeRequestsOptions{}}),
|
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[gitlab.ListProjectMergeRequestsOptions]}),
|
||||||
withMethodCheck(http.MethodPost),
|
withMethodCheck(http.MethodPost),
|
||||||
)
|
)
|
||||||
data, status := getFailData(t, svc, request)
|
data, status := getFailData(t, svc, request)
|
||||||
|
|||||||
@@ -28,7 +28,13 @@ func middleware(h http.Handler, middlewares ...mw) http.HandlerFunc {
|
|||||||
|
|
||||||
var validate = validator.New()
|
var validate = validator.New()
|
||||||
|
|
||||||
type methodToPayload map[string]any
|
type methodToPayload map[string]func() any
|
||||||
|
|
||||||
|
// Generic factory function to create new payload instances per request
|
||||||
|
func newPayload[T any]() any {
|
||||||
|
var p T
|
||||||
|
return &p
|
||||||
|
}
|
||||||
|
|
||||||
type validatorMiddleware struct {
|
type validatorMiddleware struct {
|
||||||
validate *validator.Validate
|
validate *validator.Validate
|
||||||
@@ -40,7 +46,8 @@ type validatorMiddleware struct {
|
|||||||
func (p validatorMiddleware) handle(next http.Handler) http.Handler {
|
func (p validatorMiddleware) handle(next http.Handler) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
if p.methodToPayload[r.Method] == nil { // If no payload to validate for this method type...
|
constructor, exists := p.methodToPayload[r.Method]
|
||||||
|
if !exists { // If no payload to validate for this method type...
|
||||||
next.ServeHTTP(w, r)
|
next.ServeHTTP(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -51,7 +58,9 @@ func (p validatorMiddleware) handle(next http.Handler) http.Handler {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
pl := p.methodToPayload[r.Method]
|
// Create a new instance for this request
|
||||||
|
pl := constructor()
|
||||||
|
|
||||||
err = json.Unmarshal(body, &pl)
|
err = json.Unmarshal(body, &pl)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -72,7 +81,7 @@ func (p validatorMiddleware) handle(next http.Handler) http.Handler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Pass the parsed data so we don't have to re-parse it in the handler
|
// Pass the parsed data so we don't have to re-parse it in the handler
|
||||||
ctx := context.WithValue(r.Context(), payload(payload("payload")), pl)
|
ctx := context.WithValue(r.Context(), payload("payload"), pl)
|
||||||
r = r.WithContext(ctx)
|
r = r.WithContext(ctx)
|
||||||
|
|
||||||
next.ServeHTTP(w, r)
|
next.ServeHTTP(w, r)
|
||||||
@@ -101,18 +110,18 @@ func (m withMrMiddleware) handle(next http.Handler) http.Handler {
|
|||||||
|
|
||||||
mergeRequests, _, err := m.client.ListProjectMergeRequests(m.data.projectInfo.ProjectId, &options)
|
mergeRequests, _, err := m.client.ListProjectMergeRequests(m.data.projectInfo.ProjectId, &options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
handleError(w, fmt.Errorf("Failed to list merge requests: %w", err), "Failed to list merge requests", http.StatusInternalServerError)
|
handleError(w, fmt.Errorf("failed to list merge requests: %w", err), "Failed to list merge requests", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(mergeRequests) == 0 {
|
if len(mergeRequests) == 0 {
|
||||||
err := fmt.Errorf("Branch '%s' does not have any merge requests", m.data.gitInfo.BranchName)
|
err := fmt.Errorf("branch '%s' does not have any merge requests", m.data.gitInfo.BranchName)
|
||||||
handleError(w, err, "No MRs Found", http.StatusNotFound)
|
handleError(w, err, "No MRs Found", http.StatusNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(mergeRequests) > 1 {
|
if len(mergeRequests) > 1 {
|
||||||
err := errors.New("Please call gitlab.choose_merge_request()")
|
err := errors.New("please call gitlab.choose_merge_request()")
|
||||||
handleError(w, err, "Multiple MRs found", http.StatusBadRequest)
|
handleError(w, err, "Multiple MRs found", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -155,9 +164,9 @@ func withMethodCheck(methods ...string) mw {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Helper function to format validation errors into more readable strings
|
// Helper function to format validation errors into more readable strings
|
||||||
func formatValidationErrors(errors validator.ValidationErrors) error {
|
func formatValidationErrors(errs validator.ValidationErrors) error {
|
||||||
var s strings.Builder
|
var s strings.Builder
|
||||||
for i, e := range errors {
|
for i, e := range errs {
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
s.WriteString("; ")
|
s.WriteString("; ")
|
||||||
}
|
}
|
||||||
@@ -169,5 +178,5 @@ func formatValidationErrors(errors validator.ValidationErrors) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Errorf(s.String())
|
return errors.New(s.String())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ func TestWithMrMiddleware(t *testing.T) {
|
|||||||
data, status := getFailData(t, handler, request)
|
data, status := getFailData(t, handler, request)
|
||||||
assert(t, status, http.StatusNotFound)
|
assert(t, status, http.StatusNotFound)
|
||||||
assert(t, data.Message, "No MRs Found")
|
assert(t, data.Message, "No MRs Found")
|
||||||
assert(t, data.Details, "Branch 'foo' does not have any merge requests")
|
assert(t, data.Details, "branch 'foo' does not have any merge requests")
|
||||||
})
|
})
|
||||||
t.Run("Handles when there are too many MRs", func(t *testing.T) {
|
t.Run("Handles when there are too many MRs", func(t *testing.T) {
|
||||||
request := makeRequest(t, http.MethodGet, "/foo", nil)
|
request := makeRequest(t, http.MethodGet, "/foo", nil)
|
||||||
@@ -88,7 +88,7 @@ func TestWithMrMiddleware(t *testing.T) {
|
|||||||
data, status := getFailData(t, handler, request)
|
data, status := getFailData(t, handler, request)
|
||||||
assert(t, status, http.StatusBadRequest)
|
assert(t, status, http.StatusBadRequest)
|
||||||
assert(t, data.Message, "Multiple MRs found")
|
assert(t, data.Message, "Multiple MRs found")
|
||||||
assert(t, data.Details, "Please call gitlab.choose_merge_request()")
|
assert(t, data.Details, "please call gitlab.choose_merge_request()")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,7 +97,7 @@ func TestValidatorMiddleware(t *testing.T) {
|
|||||||
request := makeRequest(t, http.MethodPost, "/foo", FakePayload{}) // No Foo field
|
request := makeRequest(t, http.MethodPost, "/foo", FakePayload{}) // No Foo field
|
||||||
data, status := getFailData(t, middleware(
|
data, status := getFailData(t, middleware(
|
||||||
fakeHandler{},
|
fakeHandler{},
|
||||||
withPayloadValidation(methodToPayload{http.MethodPost: &FakePayload{}}),
|
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[FakePayload]}),
|
||||||
), request)
|
), request)
|
||||||
assert(t, data.Message, "Invalid payload")
|
assert(t, data.Message, "Invalid payload")
|
||||||
assert(t, data.Details, "Foo is required")
|
assert(t, data.Details, "Foo is required")
|
||||||
@@ -107,7 +107,7 @@ func TestValidatorMiddleware(t *testing.T) {
|
|||||||
request := makeRequest(t, http.MethodPost, "/foo", FakePayload{Foo: "Some payload"})
|
request := makeRequest(t, http.MethodPost, "/foo", FakePayload{Foo: "Some payload"})
|
||||||
data := getSuccessData(t, middleware(
|
data := getSuccessData(t, middleware(
|
||||||
fakeHandler{},
|
fakeHandler{},
|
||||||
withPayloadValidation(methodToPayload{http.MethodPost: &FakePayload{}}),
|
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[FakePayload]}),
|
||||||
), request)
|
), request)
|
||||||
assert(t, data.Message, "Some message")
|
assert(t, data.Message, "Some message")
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ func (a pipelineService) GetLastPipeline(commit string) (*gitlab.PipelineInfo, e
|
|||||||
}
|
}
|
||||||
|
|
||||||
if res.StatusCode >= 300 {
|
if res.StatusCode >= 300 {
|
||||||
return nil, errors.New("Could not get pipelines")
|
return nil, errors.New("could not get pipelines")
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(pipes) == 0 {
|
if len(pipes) == 0 {
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ func TestReplyHandler(t *testing.T) {
|
|||||||
svc := middleware(
|
svc := middleware(
|
||||||
replyService{testProjectData, fakeReplyManager{}},
|
replyService{testProjectData, fakeReplyManager{}},
|
||||||
withMr(testProjectData, fakeMergeRequestLister{}),
|
withMr(testProjectData, fakeMergeRequestLister{}),
|
||||||
withPayloadValidation(methodToPayload{http.MethodPost: &ReplyRequest{}}),
|
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[ReplyRequest]}),
|
||||||
withMethodCheck(http.MethodPost),
|
withMethodCheck(http.MethodPost),
|
||||||
)
|
)
|
||||||
data := getSuccessData(t, svc, request)
|
data := getSuccessData(t, svc, request)
|
||||||
@@ -38,7 +38,7 @@ func TestReplyHandler(t *testing.T) {
|
|||||||
svc := middleware(
|
svc := middleware(
|
||||||
replyService{testProjectData, fakeReplyManager{testBase{errFromGitlab: true}}},
|
replyService{testProjectData, fakeReplyManager{testBase{errFromGitlab: true}}},
|
||||||
withMr(testProjectData, fakeMergeRequestLister{}),
|
withMr(testProjectData, fakeMergeRequestLister{}),
|
||||||
withPayloadValidation(methodToPayload{http.MethodPost: &ReplyRequest{}}),
|
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[ReplyRequest]}),
|
||||||
withMethodCheck(http.MethodPost),
|
withMethodCheck(http.MethodPost),
|
||||||
)
|
)
|
||||||
data, _ := getFailData(t, svc, request)
|
data, _ := getFailData(t, svc, request)
|
||||||
@@ -50,7 +50,7 @@ func TestReplyHandler(t *testing.T) {
|
|||||||
svc := middleware(
|
svc := middleware(
|
||||||
replyService{testProjectData, fakeReplyManager{testBase{status: http.StatusSeeOther}}},
|
replyService{testProjectData, fakeReplyManager{testBase{status: http.StatusSeeOther}}},
|
||||||
withMr(testProjectData, fakeMergeRequestLister{}),
|
withMr(testProjectData, fakeMergeRequestLister{}),
|
||||||
withPayloadValidation(methodToPayload{http.MethodPost: &ReplyRequest{}}),
|
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[ReplyRequest]}),
|
||||||
withMethodCheck(http.MethodPost),
|
withMethodCheck(http.MethodPost),
|
||||||
)
|
)
|
||||||
data, _ := getFailData(t, svc, request)
|
data, _ := getFailData(t, svc, request)
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ func TestResolveDiscussion(t *testing.T) {
|
|||||||
svc := middleware(
|
svc := middleware(
|
||||||
discussionsResolutionService{testProjectData, fakeDiscussionResolver{}},
|
discussionsResolutionService{testProjectData, fakeDiscussionResolver{}},
|
||||||
withMr(testProjectData, fakeMergeRequestLister{}),
|
withMr(testProjectData, fakeMergeRequestLister{}),
|
||||||
withPayloadValidation(methodToPayload{http.MethodPut: &DiscussionResolveRequest{}}),
|
withPayloadValidation(methodToPayload{http.MethodPut: newPayload[DiscussionResolveRequest]}),
|
||||||
withMethodCheck(http.MethodPut),
|
withMethodCheck(http.MethodPut),
|
||||||
)
|
)
|
||||||
request := makeRequest(t, http.MethodPut, "/mr/discussions/resolve", testResolveMergeRequestPayload)
|
request := makeRequest(t, http.MethodPut, "/mr/discussions/resolve", testResolveMergeRequestPayload)
|
||||||
@@ -44,7 +44,7 @@ func TestResolveDiscussion(t *testing.T) {
|
|||||||
svc := middleware(
|
svc := middleware(
|
||||||
discussionsResolutionService{testProjectData, fakeDiscussionResolver{}},
|
discussionsResolutionService{testProjectData, fakeDiscussionResolver{}},
|
||||||
withMr(testProjectData, fakeMergeRequestLister{}),
|
withMr(testProjectData, fakeMergeRequestLister{}),
|
||||||
withPayloadValidation(methodToPayload{http.MethodPut: &DiscussionResolveRequest{}}),
|
withPayloadValidation(methodToPayload{http.MethodPut: newPayload[DiscussionResolveRequest]}),
|
||||||
withMethodCheck(http.MethodPut),
|
withMethodCheck(http.MethodPut),
|
||||||
)
|
)
|
||||||
request := makeRequest(t, http.MethodPut, "/mr/discussions/resolve", payload)
|
request := makeRequest(t, http.MethodPut, "/mr/discussions/resolve", payload)
|
||||||
@@ -58,7 +58,7 @@ func TestResolveDiscussion(t *testing.T) {
|
|||||||
svc := middleware(
|
svc := middleware(
|
||||||
discussionsResolutionService{testProjectData, fakeDiscussionResolver{}},
|
discussionsResolutionService{testProjectData, fakeDiscussionResolver{}},
|
||||||
withMr(testProjectData, fakeMergeRequestLister{}),
|
withMr(testProjectData, fakeMergeRequestLister{}),
|
||||||
withPayloadValidation(methodToPayload{http.MethodPut: &DiscussionResolveRequest{}}),
|
withPayloadValidation(methodToPayload{http.MethodPut: newPayload[DiscussionResolveRequest]}),
|
||||||
withMethodCheck(http.MethodPut),
|
withMethodCheck(http.MethodPut),
|
||||||
)
|
)
|
||||||
request := makeRequest(t, http.MethodPut, "/mr/discussions/resolve", payload)
|
request := makeRequest(t, http.MethodPut, "/mr/discussions/resolve", payload)
|
||||||
@@ -72,13 +72,13 @@ func TestResolveDiscussion(t *testing.T) {
|
|||||||
svc := middleware(
|
svc := middleware(
|
||||||
discussionsResolutionService{testProjectData, fakeDiscussionResolver{testBase: testBase{errFromGitlab: true}}},
|
discussionsResolutionService{testProjectData, fakeDiscussionResolver{testBase: testBase{errFromGitlab: true}}},
|
||||||
withMr(testProjectData, fakeMergeRequestLister{}),
|
withMr(testProjectData, fakeMergeRequestLister{}),
|
||||||
withPayloadValidation(methodToPayload{http.MethodPut: &DiscussionResolveRequest{}}),
|
withPayloadValidation(methodToPayload{http.MethodPut: newPayload[DiscussionResolveRequest]}),
|
||||||
withMethodCheck(http.MethodPut),
|
withMethodCheck(http.MethodPut),
|
||||||
)
|
)
|
||||||
request := makeRequest(t, http.MethodPut, "/mr/discussions/resolve", testResolveMergeRequestPayload)
|
request := makeRequest(t, http.MethodPut, "/mr/discussions/resolve", testResolveMergeRequestPayload)
|
||||||
data, status := getFailData(t, svc, request)
|
data, status := getFailData(t, svc, request)
|
||||||
assert(t, data.Message, "Could not resolve discussion")
|
assert(t, data.Message, "Could not resolve discussion")
|
||||||
assert(t, data.Details, "Some error from Gitlab")
|
assert(t, data.Details, "some error from Gitlab")
|
||||||
assert(t, status, http.StatusInternalServerError)
|
assert(t, status, http.StatusInternalServerError)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,7 +86,13 @@ func CreateRouter(gitlabClient *Client, projectInfo *ProjectInfo, s *shutdownSer
|
|||||||
for _, optFunc := range optFuncs {
|
for _, optFunc := range optFuncs {
|
||||||
err := optFunc(&d)
|
err := optFunc(&d)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
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)
|
||||||
|
} else {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,28 +105,28 @@ func CreateRouter(gitlabClient *Client, projectInfo *ProjectInfo, s *shutdownSer
|
|||||||
commentService{d, gitlabClient},
|
commentService{d, gitlabClient},
|
||||||
withMr(d, gitlabClient),
|
withMr(d, gitlabClient),
|
||||||
withPayloadValidation(methodToPayload{
|
withPayloadValidation(methodToPayload{
|
||||||
http.MethodPost: &PostCommentRequest{},
|
http.MethodPost: newPayload[PostCommentRequest],
|
||||||
http.MethodDelete: &DeleteCommentRequest{},
|
http.MethodDelete: newPayload[DeleteCommentRequest],
|
||||||
http.MethodPatch: &EditCommentRequest{},
|
http.MethodPatch: newPayload[EditCommentRequest],
|
||||||
}),
|
}),
|
||||||
withMethodCheck(http.MethodPost, http.MethodDelete, http.MethodPatch),
|
withMethodCheck(http.MethodPost, http.MethodDelete, http.MethodPatch),
|
||||||
))
|
))
|
||||||
m.HandleFunc("/mr/merge", middleware(
|
m.HandleFunc("/mr/merge", middleware(
|
||||||
mergeRequestAccepterService{d, gitlabClient},
|
mergeRequestAccepterService{d, gitlabClient},
|
||||||
withMr(d, gitlabClient),
|
withMr(d, gitlabClient),
|
||||||
withPayloadValidation(methodToPayload{http.MethodPost: &AcceptMergeRequestRequest{}}),
|
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[AcceptMergeRequestRequest]}),
|
||||||
withMethodCheck(http.MethodPost),
|
withMethodCheck(http.MethodPost),
|
||||||
))
|
))
|
||||||
m.HandleFunc("/mr/discussions/list", middleware(
|
m.HandleFunc("/mr/discussions/list", middleware(
|
||||||
discussionsListerService{d, gitlabClient},
|
discussionsListerService{d, gitlabClient},
|
||||||
withMr(d, gitlabClient),
|
withMr(d, gitlabClient),
|
||||||
withPayloadValidation(methodToPayload{http.MethodPost: &DiscussionsRequest{}}),
|
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[DiscussionsRequest]}),
|
||||||
withMethodCheck(http.MethodPost),
|
withMethodCheck(http.MethodPost),
|
||||||
))
|
))
|
||||||
m.HandleFunc("/mr/discussions/resolve", middleware(
|
m.HandleFunc("/mr/discussions/resolve", middleware(
|
||||||
discussionsResolutionService{d, gitlabClient},
|
discussionsResolutionService{d, gitlabClient},
|
||||||
withMr(d, gitlabClient),
|
withMr(d, gitlabClient),
|
||||||
withPayloadValidation(methodToPayload{http.MethodPut: &DiscussionResolveRequest{}}),
|
withPayloadValidation(methodToPayload{http.MethodPut: newPayload[DiscussionResolveRequest]}),
|
||||||
withMethodCheck(http.MethodPut),
|
withMethodCheck(http.MethodPut),
|
||||||
))
|
))
|
||||||
m.HandleFunc("/mr/info", middleware(
|
m.HandleFunc("/mr/info", middleware(
|
||||||
@@ -131,19 +137,19 @@ func CreateRouter(gitlabClient *Client, projectInfo *ProjectInfo, s *shutdownSer
|
|||||||
m.HandleFunc("/mr/assignee", middleware(
|
m.HandleFunc("/mr/assignee", middleware(
|
||||||
assigneesService{d, gitlabClient},
|
assigneesService{d, gitlabClient},
|
||||||
withMr(d, gitlabClient),
|
withMr(d, gitlabClient),
|
||||||
withPayloadValidation(methodToPayload{http.MethodPut: &AssigneeUpdateRequest{}}),
|
withPayloadValidation(methodToPayload{http.MethodPut: newPayload[AssigneeUpdateRequest]}),
|
||||||
withMethodCheck(http.MethodPut),
|
withMethodCheck(http.MethodPut),
|
||||||
))
|
))
|
||||||
m.HandleFunc("/mr/summary", middleware(
|
m.HandleFunc("/mr/summary", middleware(
|
||||||
summaryService{d, gitlabClient},
|
summaryService{d, gitlabClient},
|
||||||
withMr(d, gitlabClient),
|
withMr(d, gitlabClient),
|
||||||
withPayloadValidation(methodToPayload{http.MethodPut: &SummaryUpdateRequest{}}),
|
withPayloadValidation(methodToPayload{http.MethodPut: newPayload[SummaryUpdateRequest]}),
|
||||||
withMethodCheck(http.MethodPut),
|
withMethodCheck(http.MethodPut),
|
||||||
))
|
))
|
||||||
m.HandleFunc("/mr/reviewer", middleware(
|
m.HandleFunc("/mr/reviewer", middleware(
|
||||||
reviewerService{d, gitlabClient},
|
reviewerService{d, gitlabClient},
|
||||||
withMr(d, gitlabClient),
|
withMr(d, gitlabClient),
|
||||||
withPayloadValidation(methodToPayload{http.MethodPut: &ReviewerUpdateRequest{}}),
|
withPayloadValidation(methodToPayload{http.MethodPut: newPayload[ReviewerUpdateRequest]}),
|
||||||
withMethodCheck(http.MethodPut),
|
withMethodCheck(http.MethodPut),
|
||||||
))
|
))
|
||||||
m.HandleFunc("/mr/revisions", middleware(
|
m.HandleFunc("/mr/revisions", middleware(
|
||||||
@@ -154,7 +160,7 @@ func CreateRouter(gitlabClient *Client, projectInfo *ProjectInfo, s *shutdownSer
|
|||||||
m.HandleFunc("/mr/reply", middleware(
|
m.HandleFunc("/mr/reply", middleware(
|
||||||
replyService{d, gitlabClient},
|
replyService{d, gitlabClient},
|
||||||
withMr(d, gitlabClient),
|
withMr(d, gitlabClient),
|
||||||
withPayloadValidation(methodToPayload{http.MethodPost: &ReplyRequest{}}),
|
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[ReplyRequest]}),
|
||||||
withMethodCheck(http.MethodPost),
|
withMethodCheck(http.MethodPost),
|
||||||
))
|
))
|
||||||
m.HandleFunc("/mr/label", middleware(
|
m.HandleFunc("/mr/label", middleware(
|
||||||
@@ -175,15 +181,15 @@ func CreateRouter(gitlabClient *Client, projectInfo *ProjectInfo, s *shutdownSer
|
|||||||
draftNoteService{d, gitlabClient},
|
draftNoteService{d, gitlabClient},
|
||||||
withMr(d, gitlabClient),
|
withMr(d, gitlabClient),
|
||||||
withPayloadValidation(methodToPayload{
|
withPayloadValidation(methodToPayload{
|
||||||
http.MethodPost: &PostDraftNoteRequest{},
|
http.MethodPost: newPayload[PostDraftNoteRequest],
|
||||||
http.MethodPatch: &UpdateDraftNoteRequest{},
|
http.MethodPatch: newPayload[UpdateDraftNoteRequest],
|
||||||
}),
|
}),
|
||||||
withMethodCheck(http.MethodGet, http.MethodPost, http.MethodPatch, http.MethodDelete),
|
withMethodCheck(http.MethodGet, http.MethodPost, http.MethodPatch, http.MethodDelete),
|
||||||
))
|
))
|
||||||
m.HandleFunc("/mr/draft_notes/publish", middleware(
|
m.HandleFunc("/mr/draft_notes/publish", middleware(
|
||||||
draftNotePublisherService{d, gitlabClient},
|
draftNotePublisherService{d, gitlabClient},
|
||||||
withMr(d, gitlabClient),
|
withMr(d, gitlabClient),
|
||||||
withPayloadValidation(methodToPayload{http.MethodPost: &DraftNotePublishRequest{}}),
|
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[DraftNotePublishRequest]}),
|
||||||
withMethodCheck(http.MethodPost),
|
withMethodCheck(http.MethodPost),
|
||||||
))
|
))
|
||||||
m.HandleFunc("/pipeline", middleware(
|
m.HandleFunc("/pipeline", middleware(
|
||||||
@@ -200,17 +206,17 @@ func CreateRouter(gitlabClient *Client, projectInfo *ProjectInfo, s *shutdownSer
|
|||||||
))
|
))
|
||||||
m.HandleFunc("/attachment", middleware(
|
m.HandleFunc("/attachment", middleware(
|
||||||
attachmentService{data: d, client: gitlabClient, fileReader: attachmentReader{}},
|
attachmentService{data: d, client: gitlabClient, fileReader: attachmentReader{}},
|
||||||
withPayloadValidation(methodToPayload{http.MethodPost: &AttachmentRequest{}}),
|
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[AttachmentRequest]}),
|
||||||
withMethodCheck(http.MethodPost),
|
withMethodCheck(http.MethodPost),
|
||||||
))
|
))
|
||||||
m.HandleFunc("/create_mr", middleware(
|
m.HandleFunc("/create_mr", middleware(
|
||||||
mergeRequestCreatorService{d, gitlabClient},
|
mergeRequestCreatorService{d, gitlabClient},
|
||||||
withPayloadValidation(methodToPayload{http.MethodPost: &CreateMrRequest{}}),
|
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[CreateMrRequest]}),
|
||||||
withMethodCheck(http.MethodPost),
|
withMethodCheck(http.MethodPost),
|
||||||
))
|
))
|
||||||
m.HandleFunc("/job", middleware(
|
m.HandleFunc("/job", middleware(
|
||||||
traceFileService{d, gitlabClient},
|
traceFileService{d, gitlabClient},
|
||||||
withPayloadValidation(methodToPayload{http.MethodGet: &JobTraceRequest{}}),
|
withPayloadValidation(methodToPayload{http.MethodGet: newPayload[JobTraceRequest]}),
|
||||||
withMethodCheck(http.MethodGet),
|
withMethodCheck(http.MethodGet),
|
||||||
))
|
))
|
||||||
m.HandleFunc("/project/members", middleware(
|
m.HandleFunc("/project/members", middleware(
|
||||||
@@ -219,17 +225,17 @@ func CreateRouter(gitlabClient *Client, projectInfo *ProjectInfo, s *shutdownSer
|
|||||||
))
|
))
|
||||||
m.HandleFunc("/merge_requests", middleware(
|
m.HandleFunc("/merge_requests", middleware(
|
||||||
mergeRequestListerService{d, gitlabClient},
|
mergeRequestListerService{d, gitlabClient},
|
||||||
withPayloadValidation(methodToPayload{http.MethodPost: &gitlab.ListProjectMergeRequestsOptions{}}), // TODO: How to validate external object
|
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[gitlab.ListProjectMergeRequestsOptions]}), // TODO: How to validate external object
|
||||||
withMethodCheck(http.MethodPost),
|
withMethodCheck(http.MethodPost),
|
||||||
))
|
))
|
||||||
m.HandleFunc("/merge_requests_by_username", middleware(
|
m.HandleFunc("/merge_requests_by_username", middleware(
|
||||||
mergeRequestListerByUsernameService{d, gitlabClient},
|
mergeRequestListerByUsernameService{d, gitlabClient},
|
||||||
withPayloadValidation(methodToPayload{http.MethodPost: &MergeRequestByUsernameRequest{}}),
|
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[MergeRequestByUsernameRequest]}),
|
||||||
withMethodCheck(http.MethodPost),
|
withMethodCheck(http.MethodPost),
|
||||||
))
|
))
|
||||||
m.HandleFunc("/shutdown", middleware(
|
m.HandleFunc("/shutdown", middleware(
|
||||||
*s,
|
*s,
|
||||||
withPayloadValidation(methodToPayload{http.MethodPost: &ShutdownRequest{}}),
|
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[ShutdownRequest]}),
|
||||||
withMethodCheck(http.MethodPost),
|
withMethodCheck(http.MethodPost),
|
||||||
))
|
))
|
||||||
|
|
||||||
@@ -245,13 +251,13 @@ func CreateRouter(gitlabClient *Client, projectInfo *ProjectInfo, s *shutdownSer
|
|||||||
func checkServer(port int) error {
|
func checkServer(port int) error {
|
||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < 10; i++ {
|
||||||
resp, err := http.Get("http://localhost:" + fmt.Sprintf("%d", port) + "/ping")
|
resp, err := http.Get("http://localhost:" + fmt.Sprintf("%d", port) + "/ping")
|
||||||
if resp.StatusCode == 200 && err == nil {
|
if resp != nil && resp.StatusCode == 200 && err == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
time.Sleep(100 * time.Microsecond)
|
time.Sleep(100 * time.Microsecond)
|
||||||
}
|
}
|
||||||
|
|
||||||
return errors.New("Could not start server!")
|
return errors.New("could not start server")
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Creates a TCP listener on the port specified by the user or a random port */
|
/* Creates a TCP listener on the port specified by the user or a random port */
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import (
|
|||||||
"github.com/xanzy/go-gitlab"
|
"github.com/xanzy/go-gitlab"
|
||||||
)
|
)
|
||||||
|
|
||||||
var errorFromGitlab = errors.New("Some error from Gitlab")
|
var errorFromGitlab = errors.New("some error from Gitlab")
|
||||||
|
|
||||||
/* The assert function is a helper function used to check two comparables */
|
/* The assert function is a helper function used to check two comparables */
|
||||||
func assert[T comparable](t *testing.T, got T, want T) {
|
func assert[T comparable](t *testing.T, got T, want T) {
|
||||||
|
|||||||
@@ -14,6 +14,10 @@ var pluginOptions app.PluginOptions
|
|||||||
func main() {
|
func main() {
|
||||||
log.SetFlags(0)
|
log.SetFlags(0)
|
||||||
|
|
||||||
|
if len(os.Args) < 2 {
|
||||||
|
log.Fatal("Must provide server configuration")
|
||||||
|
}
|
||||||
|
|
||||||
err := json.Unmarshal([]byte(os.Args[1]), &pluginOptions)
|
err := json.Unmarshal([]byte(os.Args[1]), &pluginOptions)
|
||||||
app.SetPluginOptions(pluginOptions)
|
app.SetPluginOptions(pluginOptions)
|
||||||
|
|
||||||
@@ -28,12 +32,12 @@ func main() {
|
|||||||
log.Fatalf("Failure initializing plugin: %v", err)
|
log.Fatalf("Failure initializing plugin: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err, client := app.NewClient()
|
client, err := app.NewClient()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed to initialize Gitlab client: %v", err)
|
log.Fatalf("Failed to initialize Gitlab client: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err, projectInfo := app.InitProjectSettings(client, gitData)
|
projectInfo, err := app.InitProjectSettings(client, gitData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed to initialize project settings: %v", err)
|
log.Fatalf("Failed to initialize project settings: %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,6 +69,8 @@ local confirm_create_comment = function(text, visual_range, unlinked, discussion
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
vim.print("Here: ", unlinked, discussion_id)
|
||||||
|
|
||||||
local reviewer_data = reviewer.get_reviewer_data()
|
local reviewer_data = reviewer.get_reviewer_data()
|
||||||
if reviewer_data == nil then
|
if reviewer_data == nil then
|
||||||
u.notify("Error getting reviewer data", vim.log.levels.ERROR)
|
u.notify("Error getting reviewer data", vim.log.levels.ERROR)
|
||||||
@@ -255,6 +257,7 @@ end
|
|||||||
--- This function will open a comment popup in order to create a comment on the changed/updated
|
--- This function will open a comment popup in order to create a comment on the changed/updated
|
||||||
--- line in the current MR
|
--- line in the current MR
|
||||||
M.create_comment = function()
|
M.create_comment = function()
|
||||||
|
vim.print("Creating comment...")
|
||||||
local has_clean_tree, err = git.has_clean_tree()
|
local has_clean_tree, err = git.has_clean_tree()
|
||||||
if err ~= nil then
|
if err ~= nil then
|
||||||
return
|
return
|
||||||
@@ -298,6 +301,7 @@ end
|
|||||||
--- This function will open a a popup to create a "note" (e.g. unlinked comment)
|
--- This function will open a a popup to create a "note" (e.g. unlinked comment)
|
||||||
--- on the changed/updated line in the current MR
|
--- on the changed/updated line in the current MR
|
||||||
M.create_note = function()
|
M.create_note = function()
|
||||||
|
vim.print("Creating note...")
|
||||||
local layout = M.create_comment_layout({ ranged = false, unlinked = true })
|
local layout = M.create_comment_layout({ ranged = false, unlinked = true })
|
||||||
if layout ~= nil then
|
if layout ~= nil then
|
||||||
layout:mount()
|
layout:mount()
|
||||||
|
|||||||
Reference in New Issue
Block a user