Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds 'update PR comment' routes to allowlist #82

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions privatevcs/validation/allowlist/azure_devops.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ var azureDevOpsPatterns = map[string]azureDevOpsPattern{
Method: http.MethodPost,
Path: regexp.MustCompile("/(?P<organization>[^/]+)/(?P<project>[^/]+)/_apis/git/repositories/(?P<repositoryId>[^/]+)/pullRequests/[^/]+/threads$"),
},
"Get Pull Request Thread": {
Method: http.MethodGet,
Path: regexp.MustCompile("/(?P<organization>[^/]+)/(?P<project>[^/]+)/_apis/git/repositories/(?P<repositoryId>[^/]+)/pullRequests/[^/]+/threads/[0-9]+$"),
},
"Update Pull Request Comment": {
Method: http.MethodPatch,
Path: regexp.MustCompile("/(?P<organization>[^/]+)/(?P<project>[^/]+)/_apis/git/repositories/(?P<repositoryId>[^/]+)/pullRequests/[^/]+/threads/[0-9]+/comments/[0-9]+$"),
},
"List Branch Stats": {
Method: http.MethodGet,
Path: regexp.MustCompile("/(?P<organization>[^/]+)/(?P<project>[^/]+)/_apis/git/repositories/(?P<repositoryId>[^/]+)/stats/branches$"),
Expand Down
12 changes: 12 additions & 0 deletions privatevcs/validation/allowlist/azure_devops_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,18 @@ func TestAzureDevOpsValidation(t *testing.T) {
// matches: false,
// method: http.MethodGet,
// },
{
path: "/spacelift-development/backend/_apis/git/repositories/spacelift-dev-stack/pullRequests/123/threads/1",
matches: true,
name: "Get Pull Request Thread",
method: http.MethodGet,
},
{
path: "/spacelift-development/backend/_apis/git/repositories/spacelift-dev-stack/pullRequests/123/threads/1/comments/1",
matches: true,
name: "Update Pull Request Comment",
method: http.MethodPatch,
},
}

executeTestCase := func(testCase azureDevOpsTestCase) {
Expand Down
8 changes: 8 additions & 0 deletions privatevcs/validation/allowlist/bitbucket_datacenter.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ var bitbucketDatacenterPatterns = map[string]bitbucketDatacenterPattern{
Method: http.MethodGet,
Path: regexp.MustCompile("^/rest/api/1.0/projects/(?P<projectKey>[^/]+)/repos/(?P<repositorySlug>[^/]+)/compare/commits$"),
},
"Get a single Pull Request Comment": {
Method: http.MethodGet,
Path: regexp.MustCompile("^/rest/api/1.0/projects/(?P<projectKey>[^/]+)/repos/(?P<repositorySlug>[^/]+)/pull-requests/[0-9]+/comments/[0-9]+$"),
},
"Update a Pull Request Comment": {
Method: http.MethodPut,
Path: regexp.MustCompile("^/rest/api/1.0/projects/(?P<projectKey>[^/]+)/repos/(?P<repositorySlug>[^/]+)/pull-requests/[0-9]+/comments/[0-9]+$"),
},
}

func matchBitbucketDatacenterRequest(r *http.Request) (string, string, error) {
Expand Down
4 changes: 4 additions & 0 deletions privatevcs/validation/allowlist/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ var gitlabPatterns = map[string]gitlabPattern{
Method: http.MethodPost,
Path: regexp.MustCompile("^/api/v4/projects/(?P<project>[^/]+)/merge_requests/[0-9]+/notes$"),
},
"Update Merge Request Note": {
Method: http.MethodPut,
Path: regexp.MustCompile("^/api/v4/projects/(?P<project>[^/]+)/merge_requests/[0-9]+/notes/[0-9]+$"),
},
"Git Clone - info/refs": {
Method: http.MethodGet,
Path: regexp.MustCompile(`^/(?P<project>[^/]+\/[^/]+)\.git/info/refs$`),
Expand Down
2 changes: 1 addition & 1 deletion privatevcs/validation/allowlist/match_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

// ErrNoMatch is returned when the request didn't match any planned API usage.
var ErrNoMatch = fmt.Errorf("no match for request")
var ErrNoMatch = fmt.Errorf("vcs-agent: no match for request")

var vendorMatchers = map[validation.Vendor]func(r *http.Request) (name string, project string, err error){
validation.AzureDevOps: matchAzureDevOpsRequest,
Expand Down
Loading