diff --git a/go.mod b/go.mod index 4226df86..fe68a901 100644 --- a/go.mod +++ b/go.mod @@ -17,12 +17,12 @@ require ( golang.org/x/time v0.14.0 // indirect ) -require gitlab.com/gitlab-org/api/client-go v1.9.1 +require gitlab.com/gitlab-org/api/client-go v1.31.0 require ( github.com/fsnotify/fsnotify v1.9.0 // indirect github.com/google/go-cmp v0.7.0 // indirect - github.com/google/go-querystring v1.1.0 // indirect + github.com/google/go-querystring v1.2.0 // indirect go.yaml.in/yaml/v3 v3.0.4 // indirect google.golang.org/protobuf v1.36.11 // indirect gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect diff --git a/go.sum b/go.sum index ded4820c..811b0e53 100644 --- a/go.sum +++ b/go.sum @@ -28,11 +28,11 @@ github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= -github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= -github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= +github.com/google/go-querystring v1.2.0 h1:yhqkPbu2/OH+V9BfpCVPZkNmUXhb2gBxJArfhIxNtP0= +github.com/google/go-querystring v1.2.0/go.mod h1:8IFJqpSRITyJ8QhQ13bmbeMBDfmeEJZD5A0egEOmkqU= github.com/google/pprof v0.0.0-20250403155104-27863c87afa6 h1:BHT72Gu3keYf3ZEu2J0b1vyeLSOYI8bm5wbJM/8yDe8= github.com/google/pprof v0.0.0-20250403155104-27863c87afa6/go.mod h1:boTsfXsheKC2y+lKOCMpSfarhxDeIzfZG1jqGcPl3cA= github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ= @@ -69,8 +69,8 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5 github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -gitlab.com/gitlab-org/api/client-go v1.9.1 h1:tZm+URa36sVy8UCEHQyGGJ8COngV4YqMHpM6k9O5tK8= -gitlab.com/gitlab-org/api/client-go v1.9.1/go.mod h1:71yTJk1lnHCWcZLvM5kPAXzeJ2fn5GjaoV8gTOPd4ME= +gitlab.com/gitlab-org/api/client-go v1.31.0 h1:GTsWZO4EeafjmH459DsoeLCE3NTB1gnM6JGrGFcolPE= +gitlab.com/gitlab-org/api/client-go v1.31.0/go.mod h1:1LZ/6Q075HHVa1u9GBQjt8StFwFTRvfjo596slHmDbo= go.uber.org/automaxprocs v1.6.0 h1:O3y2/QNTOdbF+e/dpXNNW7Rx2hZ4sTIPyybbxyNqTUs= go.uber.org/automaxprocs v1.6.0/go.mod h1:ifeIMSnPZuznNm6jmdzmU3/bfk01Fe2fotchwEFJ8r8= go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc= diff --git a/vendor/github.com/google/go-querystring/query/encode.go b/vendor/github.com/google/go-querystring/query/encode.go index 91198f81..c9369540 100644 --- a/vendor/github.com/google/go-querystring/query/encode.go +++ b/vendor/github.com/google/go-querystring/query/encode.go @@ -6,22 +6,21 @@ // // As a simple example: // -// type Options struct { -// Query string `url:"q"` -// ShowAll bool `url:"all"` -// Page int `url:"page"` -// } +// type Options struct { +// Query string `url:"q"` +// ShowAll bool `url:"all"` +// Page int `url:"page"` +// } // -// opt := Options{ "foo", true, 2 } -// v, _ := query.Values(opt) -// fmt.Print(v.Encode()) // will output: "q=foo&all=true&page=2" +// opt := Options{ "foo", true, 2 } +// v, _ := query.Values(opt) +// fmt.Print(v.Encode()) // will output: "q=foo&all=true&page=2" // // The exact mapping between Go values and url.Values is described in the // documentation for the Values() function. package query import ( - "bytes" "fmt" "net/url" "reflect" @@ -47,8 +46,8 @@ type Encoder interface { // // Each exported struct field is encoded as a URL parameter unless // -// - the field's tag is "-", or -// - the field is empty and its tag specifies the "omitempty" option +// - the field's tag is "-", or +// - the field is empty and its tag specifies the "omitempty" option // // The empty values are false, 0, any nil pointer or interface value, any array // slice, map, or string of length zero, and any type (such as time.Time) that @@ -59,19 +58,19 @@ type Encoder interface { // field's tag value is the key name, followed by an optional comma and // options. For example: // -// // Field is ignored by this package. -// Field int `url:"-"` +// // Field is ignored by this package. +// Field int `url:"-"` // -// // Field appears as URL parameter "myName". -// Field int `url:"myName"` +// // Field appears as URL parameter "myName". +// Field int `url:"myName"` // -// // Field appears as URL parameter "myName" and the field is omitted if -// // its value is empty -// Field int `url:"myName,omitempty"` +// // Field appears as URL parameter "myName" and the field is omitted if +// // its value is empty +// Field int `url:"myName,omitempty"` // -// // Field appears as URL parameter "Field" (the default), but the field -// // is skipped if empty. Note the leading comma. -// Field int `url:",omitempty"` +// // Field appears as URL parameter "Field" (the default), but the field +// // is skipped if empty. Note the leading comma. +// Field int `url:",omitempty"` // // For encoding individual field values, the following type-dependent rules // apply: @@ -88,8 +87,8 @@ type Encoder interface { // "url" tag) will use the value of the "layout" tag as a layout passed to // time.Format. For example: // -// // Encode a time.Time as YYYY-MM-DD -// Field time.Time `layout:"2006-01-02"` +// // Encode a time.Time as YYYY-MM-DD +// Field time.Time `layout:"2006-01-02"` // // Slice and Array values default to encoding as multiple URL values of the // same name. Including the "comma" option signals that the field should be @@ -103,9 +102,9 @@ type Encoder interface { // from the "url" tag) will use the value of the "del" tag as the delimiter. // For example: // -// // Encode a slice of bools as ints ("1" for true, "0" for false), -// // separated by exclamation points "!". -// Field []bool `url:",int" del:"!"` +// // Encode a slice of bools as ints ("1" for true, "0" for false), +// // separated by exclamation points "!". +// Field []bool `url:",int" del:"!"` // // Anonymous struct fields are usually encoded as if their inner exported // fields were fields in the outer struct, subject to the standard Go @@ -114,10 +113,10 @@ type Encoder interface { // // Non-nil pointer values are encoded as the value pointed to. // -// Nested structs are encoded including parent fields in value names for -// scoping. e.g: +// Nested structs have their fields processed recursively and are encoded +// including parent fields in value names for scoping. For example, // -// "user[name]=acme&user[addr][postcode]=1234&user[addr][city]=SFO" +// "user[name]=acme&user[addr][postcode]=1234&user[addr][city]=SFO" // // All other values are encoded using their default string representation. // @@ -125,6 +124,11 @@ type Encoder interface { // as multiple URL values of the same name. func Values(v interface{}) (url.Values, error) { values := make(url.Values) + + if v == nil { + return values, nil + } + val := reflect.ValueOf(v) for val.Kind() == reflect.Ptr { if val.IsNil() { @@ -133,10 +137,6 @@ func Values(v interface{}) (url.Values, error) { val = val.Elem() } - if v == nil { - return values, nil - } - if val.Kind() != reflect.Struct { return nil, fmt.Errorf("query: Values() expects struct input. Got %v", val.Kind()) } @@ -209,6 +209,11 @@ func reflectValue(values url.Values, val reflect.Value, scope string) error { } if sv.Kind() == reflect.Slice || sv.Kind() == reflect.Array { + if sv.Len() == 0 { + // skip if slice or array is empty + continue + } + var del string if opts.Contains("comma") { del = "," @@ -223,7 +228,7 @@ func reflectValue(values url.Values, val reflect.Value, scope string) error { } if del != "" { - s := new(bytes.Buffer) + s := new(strings.Builder) first := true for i := 0; i < sv.Len(); i++ { if first { diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/.gitignore b/vendor/gitlab.com/gitlab-org/api/client-go/.gitignore index 49b01759..6dc065c6 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/.gitignore +++ b/vendor/gitlab.com/gitlab-org/api/client-go/.gitignore @@ -40,3 +40,4 @@ gl-code-quality-report.json .mise/ Gitlab-license.txt +.vscode/ diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/.gitlab-ci.yml b/vendor/gitlab.com/gitlab-org/api/client-go/.gitlab-ci.yml index d5e1a082..3fd0bd02 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/.gitlab-ci.yml +++ b/vendor/gitlab.com/gitlab-org/api/client-go/.gitlab-ci.yml @@ -9,9 +9,9 @@ include: - template: Jobs/SAST.gitlab-ci.yml - component: ${CI_SERVER_FQDN}/components/dependency-scanning/main@0.8.0 - component: ${CI_SERVER_FQDN}/components/dependency-scanning/main@0.8.0 - - component: ${CI_SERVER_FQDN}/gitlab-org/components/danger-review/danger-review@2.0.0 + - component: ${CI_SERVER_FQDN}/gitlab-com/gl-infra/common-ci-tasks/danger@v3.5.3 inputs: - job_stage: lint + stage: lint job_allow_failure: true # NOTE: the two includes below are a hack to conditionally set the tags node @@ -121,7 +121,7 @@ golangci-lint: needs: [] variables: REPORT_FILENAME: "gl-code-quality-report.json" - image: golangci/golangci-lint:v2.7.2 + image: golangci/golangci-lint:v2.8.0 script: - golangci-lint run artifacts: @@ -199,7 +199,7 @@ tests:integration: image: golang:1.25-bookworm timeout: 2 hours services: - - docker:29.1.3-dind + - docker:29.2.1-dind variables: # Docker-in-docker configuration DOCKER_HOST: tcp://docker:2376 diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/.golangci.yml b/vendor/gitlab.com/gitlab-org/api/client-go/.golangci.yml index 79d506cc..2df0746b 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/.golangci.yml +++ b/vendor/gitlab.com/gitlab-org/api/client-go/.golangci.yml @@ -29,10 +29,12 @@ linters: - nakedret - nolintlint - revive + - sloglint - staticcheck - testifylint - unconvert - usestdlibvars + - usetesting - whitespace - tparallel - paralleltest @@ -49,12 +51,19 @@ linters: revive: enable-all-rules: false rules: + - name: comment-spacings - name: deep-exit + - name: error-strings - name: get-return + - name: identical-switch-branches + - name: increment-decrement + - name: indent-error-flow - name: redundant-import-alias - name: struct-tag - name: time-date + - name: unnecessary-stmt - name: unused-parameter + - name: use-errors-new - name: var-naming staticcheck: checks: @@ -85,6 +94,10 @@ linters: http-method: false http-status-code: false time-date-month: true + usetesting: + context-background: true + context-todo: true + os-temp-dir: true # List of regexps of issue texts to exclude. exclusions: diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/.tool-versions b/vendor/gitlab.com/gitlab-org/api/client-go/.tool-versions index 1704438c..d209d613 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/.tool-versions +++ b/vendor/gitlab.com/gitlab-org/api/client-go/.tool-versions @@ -1,5 +1,5 @@ golang 1.24 -golangci-lint 2.6.1 +golangci-lint 2.8.0 gofumpt 0.8.0 buf 1.55.1 -node 24.8.0 \ No newline at end of file +node 24.8.0 diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/AGENTS.md b/vendor/gitlab.com/gitlab-org/api/client-go/AGENTS.md index 234019da..26c89096 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/AGENTS.md +++ b/vendor/gitlab.com/gitlab-org/api/client-go/AGENTS.md @@ -37,14 +37,31 @@ mise exec -- make reviewable ### Test Patterns -- All tests use the `testing` package with `testify/assert` - Tests are parallelized using `t.Parallel()` - Mock HTTP handlers are used for API testing - Test data is stored in `testdata/` directory - Each service method should have corresponding test coverage - **CRITICAL** - When fixing bugs or creating new features, ensure new test scenarios are added to cover the new logic. - When writing a test, write Gherkin comments in-line with the test to make the tests easier to read. This means adding GIVEN/WHEN/THEN comments in tests. +- All tests use the `testing` package with `testify/assert` + +Do not use `reflect.DeepEqual` in tests, use testify instead. +```go +// This is an example of the incorrect test setup +want := &MyStruct{ + MyField: "Meow Kitty" +} +if !reflect.DeepEqual(want, otherStruct) { + t.Errorf("MyStruct returned %+v, want %+v", otherStruct, want) +} + +// Instead, use this +want := &MyStruct{ + MyField: "Meow Kitty" +} +assert.Equal(t, want, otherStruct) +``` ### Test Structure Example diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/CHANGELOG.md b/vendor/gitlab.com/gitlab-org/api/client-go/CHANGELOG.md index 65d01394..12d700ec 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/CHANGELOG.md +++ b/vendor/gitlab.com/gitlab-org/api/client-go/CHANGELOG.md @@ -1,3 +1,445 @@ +## 1.31.0 + +### ๐Ÿš€ Features + +- Add missing fields to emoji and milestone event types ([!2704](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2704)) by [Huijie Shi](https://gitlab.com/lcdlyxrqy) + + + +# [1.31.0](https://gitlab.com/gitlab-org/api/client-go/compare/v1.30.0...v1.31.0) (2026-02-11) + +## 1.30.0 + +### ๐Ÿš€ Features + +- Add missing query params to ListGroupsOptions ([!2726](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2726)) by [Mohamed Mongy](https://gitlab.com/mohamedmongy96) + +### ๐Ÿ”„ Other Changes + +- chore(deps): update module buf.build/go/protovalidate to v1.1.1 ([!2750](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2750)) by [GitLab Dependency Bot](https://gitlab.com/gitlab-dependency-update-bot) +- docs(no-release): update url for community fork ([!2748](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2748)) by [Oleksandr Redko](https://gitlab.com/alexandear) + + + +# [1.30.0](https://gitlab.com/gitlab-org/api/client-go/compare/v1.29.0...v1.30.0) (2026-02-10) + +## 1.29.0 + +### ๐Ÿš€ Features + +- Update runner controllers to match latest state ([!2747](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2747)) by [Timo Furrer](https://gitlab.com/timofurrer) + +### ๐Ÿ”„ Other Changes + +- chore(deps): migrate from gopkg.in/yaml.v3 to go.yaml.in/yaml/v3 ([!2639](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2639)) by [Ville Skyttรค](https://gitlab.com/scop) + + + +# [1.29.0](https://gitlab.com/gitlab-org/api/client-go/compare/v1.28.1...v1.29.0) (2026-02-09) + +## 1.28.1 + +### ๐Ÿ› Bug Fixes + +- Fix error where GetNamespace double escaped URL-encoded projects ([!2743](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2743)) by [Patrick Rice](https://gitlab.com/PatrickRice) + +### ๐Ÿ”„ Other Changes + +- refactor: moved comments to interface ([!2716](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2716)) by [Zubeen](https://gitlab.com/syedzubeen) + + + +## [1.28.1](https://gitlab.com/gitlab-org/api/client-go/compare/v1.28.0...v1.28.1) (2026-02-06) + +## 1.28.0 + +### ๐Ÿš€ Features + +- Add `destroy` attribute for pipeline schedule inputs ([!2702](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2702)) by [long nguyen huy](https://gitlab.com/n.h.long.9697) + +### ๐Ÿ”„ Other Changes + +- Migrate bytes endpoints to new `do` pattern ([!2738](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2738)) by [Timo Furrer](https://gitlab.com/timofurrer) +- docs(users): document the `Locked` and `State` fields ([!2741](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2741)) by [Florian Forster](https://gitlab.com/fforster) +- ci: migrate to Danger from `common-ci-tasks` ([!2742](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2742)) by [Florian Forster](https://gitlab.com/fforster) +- chore(oauth): improve the look of the OAuth confirmation page ([!2739](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2739)) by [Tomas Vik](https://gitlab.com/viktomas) + + + +# [1.28.0](https://gitlab.com/gitlab-org/api/client-go/compare/v1.27.0...v1.28.0) (2026-02-05) + +## 1.27.0 + +### ๐Ÿš€ Features + +- Trim leading `@` in user ids in `do()` requests paths ([!2736](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2736)) by [Timo Furrer](https://gitlab.com/timofurrer) + +### ๐Ÿ”„ Other Changes + +- Migrate endpoints with special status code handling to new `do` pattern ([!2733](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2733)) by [Timo Furrer](https://gitlab.com/timofurrer) +- Support file uploads in `do()` request handler ([!2732](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2732)) by [Timo Furrer](https://gitlab.com/timofurrer) +- Migrate more endpoints to the `do()` pattern ([!2731](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2731)) by [Timo Furrer](https://gitlab.com/timofurrer) +- Revert "refactor(http): preserve response body without copying in multiple services" ([!2730](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2730)) by [Timo Furrer](https://gitlab.com/timofurrer) +- chore(deps): update docker docker tag to v29.2.1 ([!2729](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2729)) by [GitLab Dependency Bot](https://gitlab.com/gitlab-dependency-update-bot) + + + +# [1.27.0](https://gitlab.com/gitlab-org/api/client-go/compare/v1.26.0...v1.27.0) (2026-02-04) + +## 1.26.0 + +### ๐Ÿš€ Features + +- Add slack integration support ([!2692](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2692)) by [Hamza Hassanain](https://gitlab.com/HamzaHassanain) + +### ๐Ÿ”„ Other Changes + +- refactor(no-release): fix minor revive issues ([!2711](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2711)) by [Oleksandr Redko](https://gitlab.com/alexandear) + + + +# [1.26.0](https://gitlab.com/gitlab-org/api/client-go/compare/v1.25.0...v1.26.0) (2026-02-03) + +## 1.25.0 + +### ๐Ÿš€ Features + +- feat(hooks): Add webexintegration ([!2707](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2707)) by [Preethi Atchudan](https://gitlab.com/preethiatchudan) + +### ๐Ÿ”„ Other Changes + +- fix: Fix broken GitLab docs anchors for Wikis API ([!2723](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2723)) by [Mohamed Othman](https://gitlab.com/mohamed.othman27) +- refactor: moved comments to interface 7 ([!2715](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2715)) by [Zubeen](https://gitlab.com/syedzubeen) +- chore(deps): update module github.com/google/cel-go to v0.27.0 ([!2721](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2721)) by [GitLab Dependency Bot](https://gitlab.com/gitlab-dependency-update-bot) +- refactor: moved comments to interface 1 ([!2706](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2706)) by [Zubeen](https://gitlab.com/syedzubeen) +- Refactor low complexity endpoints to use new `do` request function ([!2718](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2718)) by [Timo Furrer](https://gitlab.com/timofurrer) +- Add some additional test coverage for functions before migrating to `do` ([!2720](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2720)) by [Patrick Rice](https://gitlab.com/PatrickRice) + + + +# [1.25.0](https://gitlab.com/gitlab-org/api/client-go/compare/v1.24.0...v1.25.0) (2026-02-01) + + +### Bug Fixes + +* Fix broken GitLab docs anchors for Wikis API ([bdbb5c0](https://gitlab.com/gitlab-org/api/client-go/commit/bdbb5c0e93847846f6f786c93d649bec18db38e4)) + + +### Features + +* **hooks:** Add webexintegration ([857ac6a](https://gitlab.com/gitlab-org/api/client-go/commit/857ac6a82ff63a65ae4df221cf8347fed8946f53)) + +## 1.24.0 + +### ๐Ÿš€ Features + +- Add assignee_id to issues api ([!2673](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2673)) by [David Schneider](https://gitlab.com/dvob) + + + +# [1.24.0](https://gitlab.com/gitlab-org/api/client-go/compare/v1.23.0...v1.24.0) (2026-01-29) + +## 1.23.0 + +### ๐Ÿš€ Features + +- feat: add group protected branches service ([!2685](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2685)) by [Prakash Divy](https://gitlab.com/prakashdivyy) + +### ๐Ÿ”„ Other Changes + +- chore(no-release): refactor to slog.DiscardHandler ([!2710](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2710)) by [Oleksandr Redko](https://gitlab.com/alexandear) + + + +# [1.23.0](https://gitlab.com/gitlab-org/api/client-go/compare/v1.22.1...v1.23.0) (2026-01-28) + + +### Features + +* add group protected branches service ([c7ffe6f](https://gitlab.com/gitlab-org/api/client-go/commit/c7ffe6ff7bc12996ce27df767a706a253a3ce00b)) + +## 1.22.1 + +### ๐Ÿ› Bug Fixes + +- fix: Type Mismatch in UpdateSettingsOptions for SentryEnabled ([!2690](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2690)) by [Zubeen](https://gitlab.com/syedzubeen) + +### ๐Ÿ”„ Other Changes + +- fix: URL tags for throttle protected path settings in UpdateSettingsOptions ([!2705](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2705)) by [Zubeen](https://gitlab.com/syedzubeen) +- test: Refactor tests to use testify assertions 7 ([!2700](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2700)) by [Zubeen](https://gitlab.com/syedzubeen) +- test: Refactor tests to use testify assertions 4 ([!2696](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2696)) by [Zubeen](https://gitlab.com/syedzubeen) +- test: Refactor tests to use testify assertions 3 ([!2695](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2695)) by [Zubeen](https://gitlab.com/syedzubeen) +- test(no-release): Refactor tests to use testify assertions 2 ([!2694](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2694)) by [Zubeen](https://gitlab.com/syedzubeen) +- test(no-release): Refactor tests to use testify assertions ([!2693](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2693)) by [Zubeen](https://gitlab.com/syedzubeen) +- test(no-release): Refactor tests to use testify assertions 6 ([!2699](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2699)) by [Zubeen](https://gitlab.com/syedzubeen) + + + +## [1.22.1](https://gitlab.com/gitlab-org/api/client-go/compare/v1.22.0...v1.22.1) (2026-01-28) + + +### Bug Fixes + +* Type Mismatch in UpdateSettingsOptions for SentryEnabled ([c2d3ca9](https://gitlab.com/gitlab-org/api/client-go/commit/c2d3ca98450719f615a951930153ad9fc2585b19)) +* URL tags for throttle protected path settings in UpdateSettingsOptions ([a4a525d](https://gitlab.com/gitlab-org/api/client-go/commit/a4a525dce32ba6aa80f45b48fbc0261e59cdabd3)) + +## 1.22.0 + +### ๐Ÿš€ Features + +- feat(project_mirror): add ForceSyncProjectMirror ([!2683](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2683)) by [Prakash Divy](https://gitlab.com/prakashdivyy) + +### ๐Ÿ”„ Other Changes + +- test: Refactor tests to use testify assertions 5 ([!2697](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2697)) by [Zubeen](https://gitlab.com/syedzubeen) + + + +# [1.22.0](https://gitlab.com/gitlab-org/api/client-go/compare/v1.21.0...v1.22.0) (2026-01-28) + + +### Features + +* **project_mirror:** add ForceSyncProjectMirror ([b13fcb7](https://gitlab.com/gitlab-org/api/client-go/commit/b13fcb79e6ffb454dc9fd7e332bde90c79a62376)) + +## 1.21.0 + +### ๐Ÿš€ Features + +- feat(settings): Add AnonymousSearchesAllowed field support ([!2678](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2678)) by [Seif Hatem](https://gitlab.com/seif-hatem) + +### ๐Ÿ”„ Other Changes + +- feat: improve URL validation and error handling in client initialization ([!2656](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2656)) by [Amer Khaled](https://gitlab.com/amrkhald777) + + + +# [1.21.0](https://gitlab.com/gitlab-org/api/client-go/compare/v1.20.0...v1.21.0) (2026-01-27) + + +### Features + +* improve URL validation and error handling in client initialization ([9417155](https://gitlab.com/gitlab-org/api/client-go/commit/9417155f9c8a5d7c044d052e61d8da5c91bbe57d)) +* **settings:** Add AnonymousSearchesAllowed field support ([7185888](https://gitlab.com/gitlab-org/api/client-go/commit/7185888208173e18216ecb353fdfebe91423f0c4)) + +## 1.20.0 + +### ๐Ÿš€ Features + +- feat: update events ([!2689](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2689)) by [Huijie Shi](https://gitlab.com/lcdlyxrqy) + +### ๐Ÿ”„ Other Changes + +- chore(no-release): remove redundant build tag ([!2701](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2701)) by [Oleksandr Redko](https://gitlab.com/alexandear) +- chore(deps): update docker docker tag to v29.2.0 ([!2698](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2698)) by [GitLab Dependency Bot](https://gitlab.com/gitlab-dependency-update-bot) + + + +# [1.20.0](https://gitlab.com/gitlab-org/api/client-go/compare/v1.19.0...v1.20.0) (2026-01-27) + + +### Features + +* update events ([46ba91c](https://gitlab.com/gitlab-org/api/client-go/commit/46ba91cabfe7c13cf4f80738d48ca60b810f520a)) + +## 1.19.0 + +### ๐Ÿš€ Features + +- feat(integrations): Add Chat & Notify integrations ([!2691](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2691)) by [Hamza Hassanain](https://gitlab.com/HamzaHassanain) + +### ๐Ÿ”„ Other Changes + +- refactor: use do function for requests ([!2674](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2674)) by [Timo Furrer](https://gitlab.com/timofurrer) +- chore(docs): Update adding API support guide for new coding patterns ([!2688](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2688)) by [Heidi Berry](https://gitlab.com/heidi.berry) + + + +# [1.19.0](https://gitlab.com/gitlab-org/api/client-go/compare/v1.18.0...v1.19.0) (2026-01-26) + + +### Features + +* **integrations:** Add Chat & Notify integrations ([cc692ed](https://gitlab.com/gitlab-org/api/client-go/commit/cc692edd6d8dfed55fd411559af7e53b55d4e2dd)) +* **mocks:** add streaming methods for various services ([889b407](https://gitlab.com/gitlab-org/api/client-go/commit/889b407e48432b32b4c1589102ceed6fadb857db)) + +## 1.18.0 + +### ๐Ÿš€ Features + +- feat(settings): Added support for inactive_resource_access_tokens_delete_after_days to the... ([!2686](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2686)) by [Preethi Atchudan](https://gitlab.com/preethiatchudan) + +### ๐Ÿ”„ Other Changes + +- Add missing tests for refactored functions ([!2676](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2676)) by [Patrick Rice](https://gitlab.com/PatrickRice) + + + +# [1.18.0](https://gitlab.com/gitlab-org/api/client-go/compare/v1.17.0...v1.18.0) (2026-01-25) + + +### Features + +* **settings:** Added support for inactive_resource_access_tokens_delete_after_days to the... ([52b60c3](https://gitlab.com/gitlab-org/api/client-go/commit/52b60c3345ef56cc18ae7e8e1e2dd7c9f7f71344)) + +## 1.17.0 + +### ๐Ÿš€ Features + +- Add support for Group Mattermost integrations ([!2675](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2675)) by [Hamza Hassanain](https://gitlab.com/HamzaHassanain) + + + +# [1.17.0](https://gitlab.com/gitlab-org/api/client-go/compare/v1.16.0...v1.17.0) (2026-01-23) + +## 1.16.0 + +### ๐Ÿš€ Features + +- Add environment, deployed_after, and deployed_before params to merge requests options struct ([!2672](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2672)) by [Filip Aleksic](https://gitlab.com/faleksic) + +### ๐Ÿ”„ Other Changes + +- chore(deps): update module golang.org/x/oauth2 to v0.34.0 ([!2640](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2640)) by [GitLab Dependency Bot](https://gitlab.com/gitlab-dependency-update-bot) + + + +# [1.16.0](https://gitlab.com/gitlab-org/api/client-go/compare/v1.15.0...v1.16.0) (2026-01-20) + +## 1.15.0 + +### ๐Ÿš€ Features + +- Add ExpiresAt field to ProjectSharedWithGroup struct ([!2671](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2671)) by [cindy](https://gitlab.com/wscix) + +### ๐Ÿ”„ Other Changes + +- feat: convert examples to testable examples for pkg.go.dev ([!2655](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2655)) by [Amer Khaled](https://gitlab.com/amrkhald777) +- refactor(no-release): enable usetesting linter ([!2664](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2664)) by [Oleksandr Redko](https://gitlab.com/alexandear) +- chore(deps): update docker docker tag to v29.1.5 ([!2665](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2665)) by [GitLab Dependency Bot](https://gitlab.com/gitlab-dependency-update-bot) +- Draft: Users: Fix GetUsersOptions naming inconsistency ([!2667](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2667)) by [Seif Hatem](https://gitlab.com/seif-hatem) + + + +# [1.15.0](https://gitlab.com/gitlab-org/api/client-go/compare/v1.14.0...v1.15.0) (2026-01-20) + + +### Bug Fixes + +* Deprecate incorrect fields returned in response for Emails on Push integration ([71d747d](https://gitlab.com/gitlab-org/api/client-go/commit/71d747da9a297451911b0c4eb4850632a588e3e8)) + + +### Features + +* convert examples to testable examples for pkg.go.dev ([fee39f1](https://gitlab.com/gitlab-org/api/client-go/commit/fee39f1f21b264765bbbed80ba23265bd3f633a9)) +* **issue_links:** Add ID field to IssueLink struct ([8f813a8](https://gitlab.com/gitlab-org/api/client-go/commit/8f813a8a2e73c41bc81403aceb82d7d94e9ff684)) + +## 1.14.0 + +### ๐Ÿš€ Features + +- feat(hooks): Add project hook support for vulnerability events and branch filter strategy ([!2658](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2658)) by [Heidi Berry](https://gitlab.com/heidi.berry) +- Add max_artifacts_size parameter to groups and projects ([!2652](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2652)) by [Betty Godier](https://gitlab.com/betty-godier) + + + +# [1.14.0](https://gitlab.com/gitlab-org/api/client-go/compare/v1.13.0...v1.14.0) (2026-01-13) + + +### Features + +* **hooks:** Add project hook support for vulnerability events and branch filter strategy ([4f6d252](https://gitlab.com/gitlab-org/api/client-go/commit/4f6d252a47411602ac6757400e6b5479d807cdb8)) + +## 1.13.0 + +### ๐Ÿš€ Features + +- feat(groups): add Active parameter to ListGroupProjects ([!2657](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2657)) by [Kai Armstrong](https://gitlab.com/phikai) + +### ๐Ÿ”„ Other Changes + +- chore(deps): update docker docker tag to v29.1.4 ([!2651](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2651)) by [GitLab Dependency Bot](https://gitlab.com/gitlab-dependency-update-bot) + + + +# [1.13.0](https://gitlab.com/gitlab-org/api/client-go/compare/v1.12.0...v1.13.0) (2026-01-12) + + +### Features + +* **groups:** add Active parameter to ListGroupProjects ([dec511a](https://gitlab.com/gitlab-org/api/client-go/commit/dec511a199b0adb7ba87f5a02a50651049b68b71)) + +## 1.12.0 + +### ๐Ÿš€ Features + +- feat: add EmojiEvents field support to Project Webhooks ([!2653](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2653)) by [Yugan](https://gitlab.com/yugannkt) + +### ๐Ÿ”„ Other Changes + +- chore(deps): update dependency golangci-lint to v2.8.0 ([!2650](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2650)) by [GitLab Dependency Bot](https://gitlab.com/gitlab-dependency-update-bot) +- refactor(no-release): use errors.New instead of fmt.Errorf ([!2644](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2644)) by [Oleksandr Redko](https://gitlab.com/alexandear) + + + +# [1.12.0](https://gitlab.com/gitlab-org/api/client-go/compare/v1.11.0...v1.12.0) (2026-01-11) + + +### Features + +* add EmojiEvents field support to Project Webhooks ([2bcfa1f](https://gitlab.com/gitlab-org/api/client-go/commit/2bcfa1fd77756a3ccdb2bcf685736ee839b745be)) + +## 1.11.0 + +### ๐Ÿš€ Features + +- feat(groups): add support for merge related settings ([!2625](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2625)) by [Zubeen](https://gitlab.com/syedzubeen) + +### ๐Ÿ› Bug Fixes + +- fix(api): typo in ms teams slug ([!2643](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2643)) by [aishahsofea](https://gitlab.com/aishahsofea) + +### ๐Ÿ”„ Other Changes + +- chore(deps): update module golang.org/x/text to v0.32.0 ([!2642](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2642)) by [GitLab Dependency Bot](https://gitlab.com/gitlab-dependency-update-bot) +- chore(deps): update module golang.org/x/sys to v0.39.0 ([!2641](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2641)) by [GitLab Dependency Bot](https://gitlab.com/gitlab-dependency-update-bot) +- chore(deps): update module github.com/godbus/dbus/v5 to v5.2.2 ([!2637](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2637)) by [GitLab Dependency Bot](https://gitlab.com/gitlab-dependency-update-bot) +- chore(deps): update module github.com/google/go-querystring to v1.2.0 ([!2638](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2638)) by [GitLab Dependency Bot](https://gitlab.com/gitlab-dependency-update-bot) + + + +# [1.11.0](https://gitlab.com/gitlab-org/api/client-go/compare/v1.10.0...v1.11.0) (2026-01-05) + + +### Bug Fixes + +* **api:** typo in ms teams slug ([1ed6c95](https://gitlab.com/gitlab-org/api/client-go/commit/1ed6c9509b23db53c3988a2dde2f11d22c8be5f9)) + + +### Features + +* **groups:** add support for merge related settings ([cb8412f](https://gitlab.com/gitlab-org/api/client-go/commit/cb8412fc495d19ee6e44819a2f69fd213d19a199)) + +## 1.10.0 + +### ๐Ÿš€ Features + +- feat: implement Runner Controller API ([!2634](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2634)) by [Duo Developer](https://gitlab.com/duo-developer) + +### ๐Ÿ”„ Other Changes + +- chore(deps): update module github.com/godbus/dbus/v5 to v5.2.1 ([!2635](https://gitlab.com/gitlab-org/api/client-go/-/merge_requests/2635)) by [GitLab Dependency Bot](https://gitlab.com/gitlab-dependency-update-bot) + + + +# [1.10.0](https://gitlab.com/gitlab-org/api/client-go/compare/v1.9.1...v1.10.0) (2025-12-19) + + +### Features + +* implement Runner Controller API ([66f19f4](https://gitlab.com/gitlab-org/api/client-go/commit/66f19f4073ce87566c7751e0987f857eeb008849)) + ## 1.9.1 ### ๐Ÿ› Bug Fixes diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/CONTRIBUTING.md b/vendor/gitlab.com/gitlab-org/api/client-go/CONTRIBUTING.md index 25c74f5b..550771cc 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/CONTRIBUTING.md +++ b/vendor/gitlab.com/gitlab-org/api/client-go/CONTRIBUTING.md @@ -23,7 +23,7 @@ this project only supports what is in the public API docs. ### Use community fork to contribute To contribute to this project we recommend that you use the -[community fork](https://gitlab.com/gitlab-community/api/client-go). +[community fork](https://gitlab.com/gitlab-community/gitlab-org/api/client-go). Have a look at the [community fork README](https://gitlab.com/gitlab-community#gitlab-community-forks) to learn more about what it is and why you should prefer it over diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/Makefile b/vendor/gitlab.com/gitlab-org/api/client-go/Makefile index 4c6a1897..95682856 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/Makefile +++ b/vendor/gitlab.com/gitlab-org/api/client-go/Makefile @@ -10,7 +10,7 @@ reviewable: setup generate fmt lint test ## Run before committing. fmt: ## Format code @buf format -w - @gofumpt -l -w *.go testing/*.go examples/*.go + @gofumpt -l -w *.go testing/*.go lint: ## Run linter @golangci-lint run diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/alert_management.go b/vendor/gitlab.com/gitlab-org/api/client-go/alert_management.go index 5fa0ee6b..232ce487 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/alert_management.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/alert_management.go @@ -15,7 +15,6 @@ package gitlab import ( - "fmt" "io" "net/http" "time" @@ -83,24 +82,13 @@ type UploadMetricImageOptions struct { } func (s *AlertManagementService) UploadMetricImage(pid any, alertIID int64, content io.Reader, filename string, opt *UploadMetricImageOptions, options ...RequestOptionFunc) (*MetricImage, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/alert_management_alerts/%d/metric_images", PathEscape(project), alertIID) - - req, err := s.client.UploadRequest(http.MethodPost, u, content, filename, UploadFile, opt, options) - if err != nil { - return nil, nil, err - } - - mi := new(MetricImage) - resp, err := s.client.Do(req, mi) - if err != nil { - return nil, resp, err - } - - return mi, resp, nil + return do[*MetricImage](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/alert_management_alerts/%d/metric_images", ProjectID{pid}, alertIID), + withUpload(content, filename, UploadFile), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // ListMetricImagesOptions represents the available ListMetricImages() options. diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/bulk_imports.go b/vendor/gitlab.com/gitlab-org/api/client-go/bulk_imports.go index 6ee80bb6..fe5f319d 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/bulk_imports.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/bulk_imports.go @@ -62,16 +62,10 @@ type BulkImportStartMigrationResponse struct { } func (b *BulkImportsService) StartMigration(startMigrationOptions *BulkImportStartMigrationOptions, options ...RequestOptionFunc) (*BulkImportStartMigrationResponse, *Response, error) { - request, err := b.client.NewRequest(http.MethodPost, "bulk_imports", startMigrationOptions, options) - if err != nil { - return nil, nil, err - } - - startMigrationResponse := new(BulkImportStartMigrationResponse) - response, err := b.client.Do(request, startMigrationResponse) - if err != nil { - return nil, response, err - } - - return startMigrationResponse, response, nil + return do[*BulkImportStartMigrationResponse](b.client, + withMethod(http.MethodPost), + withPath("bulk_imports"), + withAPIOpts(startMigrationOptions), + withRequestOpts(options...), + ) } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/client_options.go b/vendor/gitlab.com/gitlab-org/api/client-go/client_options.go index 57a7f202..b416acac 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/client_options.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/client_options.go @@ -17,7 +17,8 @@ package gitlab import ( - "fmt" + "errors" + "log/slog" "net/http" "time" @@ -150,6 +151,19 @@ func WithUserAgent(userAgent string) ClientOptionFunc { } } +// WithURLWarningLogger sets a custom logger for URL validation warnings. +// By default, warnings are logged using slog.Default(). +// Pass slog.New(slog.DiscardHandler) to disable warnings. +func WithURLWarningLogger(logger *slog.Logger) ClientOptionFunc { + return func(c *Client) error { + if logger == nil { + return errors.New("logger cannot be nil, use slog.New(slog.DiscardHandler) to discard warnings") + } + c.urlWarningLogger = logger + return nil + } +} + // WithCookieJar can be used to configure a cookie jar. func WithCookieJar(jar http.CookieJar) ClientOptionFunc { return func(c *Client) error { @@ -163,7 +177,7 @@ func WithCookieJar(jar http.CookieJar) ClientOptionFunc { func WithInterceptor(i Interceptor) ClientOptionFunc { return func(c *Client) error { if i == nil { - return fmt.Errorf("interceptor cannot be nil") + return errors.New("interceptor cannot be nil") } c.interceptors = append(c.interceptors, i) return nil diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/commits.go b/vendor/gitlab.com/gitlab-org/api/client-go/commits.go index 5a53fd90..36e67846 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/commits.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/commits.go @@ -17,7 +17,7 @@ package gitlab import ( - "fmt" + "errors" "net/http" "time" ) @@ -221,7 +221,7 @@ type GetCommitOptions struct { func (s *CommitsService) GetCommit(pid any, sha string, opt *GetCommitOptions, options ...RequestOptionFunc) (*Commit, *Response, error) { if sha == "" { - return nil, nil, fmt.Errorf("SHA must be a non-empty string") + return nil, nil, errors.New("SHA must be a non-empty string") } return do[*Commit](s.client, diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/dependency_list_export.go b/vendor/gitlab.com/gitlab-org/api/client-go/dependency_list_export.go index e6c21d9e..6f82f596 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/dependency_list_export.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/dependency_list_export.go @@ -2,7 +2,6 @@ package gitlab import ( "bytes" - "fmt" "io" "net/http" ) @@ -77,9 +76,6 @@ type DependencyListExport struct { const defaultExportType = "sbom" func (s *DependencyListExportService) CreateDependencyListExport(pipelineID int64, opt *CreateDependencyListExportOptions, options ...RequestOptionFunc) (*DependencyListExport, *Response, error) { - // POST /pipelines/:id/dependency_list_exports - createExportPath := fmt.Sprintf("pipelines/%d/dependency_list_exports", pipelineID) - if opt == nil { opt = &CreateDependencyListExportOptions{} } @@ -87,52 +83,28 @@ func (s *DependencyListExportService) CreateDependencyListExport(pipelineID int6 opt.ExportType = Ptr(defaultExportType) } - req, err := s.client.NewRequest(http.MethodPost, createExportPath, opt, options) - if err != nil { - return nil, nil, err - } - - export := new(DependencyListExport) - resp, err := s.client.Do(req, &export) - if err != nil { - return nil, resp, err - } - - return export, resp, nil + return do[*DependencyListExport](s.client, + withMethod(http.MethodPost), + withPath("pipelines/%d/dependency_list_exports", pipelineID), + withAPIOpts(opt), + withRequestOpts(options...), + ) } func (s *DependencyListExportService) GetDependencyListExport(id int64, options ...RequestOptionFunc) (*DependencyListExport, *Response, error) { - // GET /dependency_list_exports/:id - getExportPath := fmt.Sprintf("dependency_list_exports/%d", id) - - req, err := s.client.NewRequest(http.MethodGet, getExportPath, nil, options) - if err != nil { - return nil, nil, err - } - - export := new(DependencyListExport) - resp, err := s.client.Do(req, &export) - if err != nil { - return nil, resp, err - } - - return export, resp, nil + return do[*DependencyListExport](s.client, + withPath("dependency_list_exports/%d", id), + withRequestOpts(options...), + ) } func (s *DependencyListExportService) DownloadDependencyListExport(id int64, options ...RequestOptionFunc) (io.Reader, *Response, error) { - // GET /dependency_list_exports/:id/download - downloadExportPath := fmt.Sprintf("dependency_list_exports/%d/download", id) - - req, err := s.client.NewRequest(http.MethodGet, downloadExportPath, nil, options) - if err != nil { - return nil, nil, err - } - - var sbomBuffer bytes.Buffer - resp, err := s.client.Do(req, &sbomBuffer) + buf, resp, err := do[bytes.Buffer](s.client, + withPath("dependency_list_exports/%d/download", id), + withRequestOpts(options...), + ) if err != nil { return nil, resp, err } - - return &sbomBuffer, resp, nil + return &buf, resp, nil } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/dependency_proxy.go b/vendor/gitlab.com/gitlab-org/api/client-go/dependency_proxy.go index c210e8e9..a9516e64 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/dependency_proxy.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/dependency_proxy.go @@ -14,10 +14,7 @@ package gitlab -import ( - "fmt" - "net/http" -) +import "net/http" type ( DependencyProxyServiceInterface interface { @@ -41,16 +38,10 @@ type ( var _ DependencyProxyServiceInterface = (*DependencyProxyService)(nil) func (s *DependencyProxyService) PurgeGroupDependencyProxy(gid any, options ...RequestOptionFunc) (*Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("groups/%s/dependency_proxy/cache", PathEscape(group)) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("groups/%s/dependency_proxy/cache", GroupID{gid}), + withRequestOpts(options...), + ) + return resp, err } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/deploy_keys.go b/vendor/gitlab.com/gitlab-org/api/client-go/deploy_keys.go index 66e79d9c..78c98899 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/deploy_keys.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/deploy_keys.go @@ -59,10 +59,8 @@ type ( // ListUserProjectDeployKeys gets a list of a user's deploy keys. // - // GitLab API docs: - // https://docs.gitlab.com/api/deploy_keys/#list-project-deploy-keys-for-user - - // ListUserProjectDeployKeys gets a list of a user's deploy keys. + // uid can be either a user ID (int) or a username (string). If a username + // is provided with a leading "@" (e.g., "@johndoe"), it will be trimmed. // // GitLab API docs: // https://docs.gitlab.com/api/deploy_keys/#list-project-deploy-keys-for-user @@ -225,6 +223,13 @@ type ListUserProjectDeployKeysOptions struct { ListOptions } +// ListUserProjectDeployKeys gets a list of a user's deploy keys. +// +// uid can be either a user ID (int) or a username (string). If a username +// is provided with a leading "@" (e.g., "@johndoe"), it will be trimmed. +// +// GitLab API docs: +// https://docs.gitlab.com/api/deploy_keys/#list-project-deploy-keys-for-user func (s *DeployKeysService) ListUserProjectDeployKeys(uid any, opt *ListUserProjectDeployKeysOptions, options ...RequestOptionFunc) ([]*ProjectDeployKey, *Response, error) { return do[[]*ProjectDeployKey](s.client, withPath("users/%s/project_deploy_keys", UserID{uid}), diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/deploy_tokens.go b/vendor/gitlab.com/gitlab-org/api/client-go/deploy_tokens.go index c43394bb..8083c845 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/deploy_tokens.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/deploy_tokens.go @@ -17,7 +17,6 @@ package gitlab import ( - "fmt" "net/http" "time" ) @@ -114,18 +113,10 @@ func (k DeployToken) String() string { } func (s *DeployTokensService) ListAllDeployTokens(options ...RequestOptionFunc) ([]*DeployToken, *Response, error) { - req, err := s.client.NewRequest(http.MethodGet, "deploy_tokens", nil, options) - if err != nil { - return nil, nil, err - } - - var ts []*DeployToken - resp, err := s.client.Do(req, &ts) - if err != nil { - return nil, resp, err - } - - return ts, resp, nil + return do[[]*DeployToken](s.client, + withPath("deploy_tokens"), + withRequestOpts(options...), + ) } // ListProjectDeployTokensOptions represents the available ListProjectDeployTokens() @@ -138,45 +129,18 @@ type ListProjectDeployTokensOptions struct { } func (s *DeployTokensService) ListProjectDeployTokens(pid any, opt *ListProjectDeployTokensOptions, options ...RequestOptionFunc) ([]*DeployToken, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/deploy_tokens", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var ts []*DeployToken - resp, err := s.client.Do(req, &ts) - if err != nil { - return nil, resp, err - } - - return ts, resp, nil + return do[[]*DeployToken](s.client, + withPath("projects/%s/deploy_tokens", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } func (s *DeployTokensService) GetProjectDeployToken(pid any, deployToken int64, options ...RequestOptionFunc) (*DeployToken, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/deploy_tokens/%d", PathEscape(project), deployToken) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - t := new(DeployToken) - resp, err := s.client.Do(req, t) - if err != nil { - return nil, resp, err - } - - return t, resp, nil + return do[*DeployToken](s.client, + withPath("projects/%s/deploy_tokens/%d", ProjectID{pid}, deployToken), + withRequestOpts(options...), + ) } // CreateProjectDeployTokenOptions represents the available CreateProjectDeployToken() options. @@ -191,39 +155,21 @@ type CreateProjectDeployTokenOptions struct { } func (s *DeployTokensService) CreateProjectDeployToken(pid any, opt *CreateProjectDeployTokenOptions, options ...RequestOptionFunc) (*DeployToken, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/deploy_tokens", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - t := new(DeployToken) - resp, err := s.client.Do(req, t) - if err != nil { - return nil, resp, err - } - - return t, resp, nil + return do[*DeployToken](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/deploy_tokens", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } func (s *DeployTokensService) DeleteProjectDeployToken(pid any, deployToken int64, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/deploy_tokens/%d", PathEscape(project), deployToken) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/deploy_tokens/%d", ProjectID{pid}, deployToken), + withRequestOpts(options...), + ) + return resp, err } // ListGroupDeployTokensOptions represents the available ListGroupDeployTokens() @@ -236,45 +182,18 @@ type ListGroupDeployTokensOptions struct { } func (s *DeployTokensService) ListGroupDeployTokens(gid any, opt *ListGroupDeployTokensOptions, options ...RequestOptionFunc) ([]*DeployToken, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/deploy_tokens", PathEscape(group)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var ts []*DeployToken - resp, err := s.client.Do(req, &ts) - if err != nil { - return nil, resp, err - } - - return ts, resp, nil + return do[[]*DeployToken](s.client, + withPath("groups/%s/deploy_tokens", GroupID{gid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } func (s *DeployTokensService) GetGroupDeployToken(gid any, deployToken int64, options ...RequestOptionFunc) (*DeployToken, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/deploy_tokens/%d", PathEscape(group), deployToken) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - t := new(DeployToken) - resp, err := s.client.Do(req, t) - if err != nil { - return nil, resp, err - } - - return t, resp, nil + return do[*DeployToken](s.client, + withPath("groups/%s/deploy_tokens/%d", GroupID{gid}, deployToken), + withRequestOpts(options...), + ) } // CreateGroupDeployTokenOptions represents the available CreateGroupDeployToken() options. @@ -289,37 +208,19 @@ type CreateGroupDeployTokenOptions struct { } func (s *DeployTokensService) CreateGroupDeployToken(gid any, opt *CreateGroupDeployTokenOptions, options ...RequestOptionFunc) (*DeployToken, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/deploy_tokens", PathEscape(group)) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - t := new(DeployToken) - resp, err := s.client.Do(req, t) - if err != nil { - return nil, resp, err - } - - return t, resp, nil + return do[*DeployToken](s.client, + withMethod(http.MethodPost), + withPath("groups/%s/deploy_tokens", GroupID{gid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } func (s *DeployTokensService) DeleteGroupDeployToken(gid any, deployToken int64, options ...RequestOptionFunc) (*Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("groups/%s/deploy_tokens/%d", PathEscape(group), deployToken) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("groups/%s/deploy_tokens/%d", GroupID{gid}, deployToken), + withRequestOpts(options...), + ) + return resp, err } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/deployments_merge_requests.go b/vendor/gitlab.com/gitlab-org/api/client-go/deployments_merge_requests.go index 3f247964..4d418e51 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/deployments_merge_requests.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/deployments_merge_requests.go @@ -14,11 +14,6 @@ package gitlab -import ( - "fmt" - "net/http" -) - type ( // DeploymentMergeRequestsServiceInterface defines all the API methods for the DeploymentMergeRequestsService DeploymentMergeRequestsServiceInterface interface { @@ -42,22 +37,9 @@ type ( var _ DeploymentMergeRequestsServiceInterface = (*DeploymentMergeRequestsService)(nil) func (s *DeploymentMergeRequestsService) ListDeploymentMergeRequests(pid any, deployment int64, opts *ListMergeRequestsOptions, options ...RequestOptionFunc) ([]*MergeRequest, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/deployments/%d/merge_requests", PathEscape(project), deployment) - - req, err := s.client.NewRequest(http.MethodGet, u, opts, options) - if err != nil { - return nil, nil, err - } - - var mrs []*MergeRequest - resp, err := s.client.Do(req, &mrs) - if err != nil { - return nil, resp, err - } - - return mrs, resp, nil + return do[[]*MergeRequest](s.client, + withPath("projects/%s/deployments/%d/merge_requests", ProjectID{pid}, deployment), + withAPIOpts(opts), + withRequestOpts(options...), + ) } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/discussions.go b/vendor/gitlab.com/gitlab-org/api/client-go/discussions.go index 72d8ddf7..e305dcaf 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/discussions.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/discussions.go @@ -17,7 +17,6 @@ package gitlab import ( - "fmt" "net/http" "time" ) @@ -260,49 +259,18 @@ type ListIssueDiscussionsOptions struct { } func (s *DiscussionsService) ListIssueDiscussions(pid any, issue int64, opt *ListIssueDiscussionsOptions, options ...RequestOptionFunc) ([]*Discussion, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/issues/%d/discussions", PathEscape(project), issue) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var ds []*Discussion - resp, err := s.client.Do(req, &ds) - if err != nil { - return nil, resp, err - } - - return ds, resp, nil + return do[[]*Discussion](s.client, + withPath("projects/%s/issues/%d/discussions", ProjectID{pid}, issue), + withAPIOpts(opt), + withRequestOpts(options...), + ) } func (s *DiscussionsService) GetIssueDiscussion(pid any, issue int64, discussion string, options ...RequestOptionFunc) (*Discussion, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/issues/%d/discussions/%s", - PathEscape(project), - issue, - discussion, + return do[*Discussion](s.client, + withPath("projects/%s/issues/%d/discussions/%s", ProjectID{pid}, issue, discussion), + withRequestOpts(options...), ) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - d := new(Discussion) - resp, err := s.client.Do(req, d) - if err != nil { - return nil, resp, err - } - - return d, resp, nil } // CreateIssueDiscussionOptions represents the available CreateIssueDiscussion() @@ -316,24 +284,12 @@ type CreateIssueDiscussionOptions struct { } func (s *DiscussionsService) CreateIssueDiscussion(pid any, issue int64, opt *CreateIssueDiscussionOptions, options ...RequestOptionFunc) (*Discussion, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/issues/%d/discussions", PathEscape(project), issue) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - d := new(Discussion) - resp, err := s.client.Do(req, d) - if err != nil { - return nil, resp, err - } - - return d, resp, nil + return do[*Discussion](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/issues/%d/discussions", ProjectID{pid}, issue), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // AddIssueDiscussionNoteOptions represents the available AddIssueDiscussionNote() @@ -347,28 +303,12 @@ type AddIssueDiscussionNoteOptions struct { } func (s *DiscussionsService) AddIssueDiscussionNote(pid any, issue int64, discussion string, opt *AddIssueDiscussionNoteOptions, options ...RequestOptionFunc) (*Note, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/issues/%d/discussions/%s/notes", - PathEscape(project), - issue, - discussion, + return do[*Note](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/issues/%d/discussions/%s/notes", ProjectID{pid}, issue, discussion), + withAPIOpts(opt), + withRequestOpts(options...), ) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - n := new(Note) - resp, err := s.client.Do(req, n) - if err != nil { - return nil, resp, err - } - - return n, resp, nil } // UpdateIssueDiscussionNoteOptions represents the available @@ -382,49 +322,21 @@ type UpdateIssueDiscussionNoteOptions struct { } func (s *DiscussionsService) UpdateIssueDiscussionNote(pid any, issue int64, discussion string, note int64, opt *UpdateIssueDiscussionNoteOptions, options ...RequestOptionFunc) (*Note, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/issues/%d/discussions/%s/notes/%d", - PathEscape(project), - issue, - discussion, - note, + return do[*Note](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/issues/%d/discussions/%s/notes/%d", ProjectID{pid}, issue, discussion, note), + withAPIOpts(opt), + withRequestOpts(options...), ) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - n := new(Note) - resp, err := s.client.Do(req, n) - if err != nil { - return nil, resp, err - } - - return n, resp, nil } func (s *DiscussionsService) DeleteIssueDiscussionNote(pid any, issue int64, discussion string, note int64, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/issues/%d/discussions/%s/notes/%d", - PathEscape(project), - issue, - discussion, - note, + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/issues/%d/discussions/%s/notes/%d", ProjectID{pid}, issue, discussion, note), + withRequestOpts(options...), ) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + return resp, err } // ListSnippetDiscussionsOptions represents the available ListSnippetDiscussions() @@ -437,49 +349,18 @@ type ListSnippetDiscussionsOptions struct { } func (s *DiscussionsService) ListSnippetDiscussions(pid any, snippet int64, opt *ListSnippetDiscussionsOptions, options ...RequestOptionFunc) ([]*Discussion, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/snippets/%d/discussions", PathEscape(project), snippet) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var ds []*Discussion - resp, err := s.client.Do(req, &ds) - if err != nil { - return nil, resp, err - } - - return ds, resp, nil + return do[[]*Discussion](s.client, + withPath("projects/%s/snippets/%d/discussions", ProjectID{pid}, snippet), + withAPIOpts(opt), + withRequestOpts(options...), + ) } func (s *DiscussionsService) GetSnippetDiscussion(pid any, snippet int64, discussion string, options ...RequestOptionFunc) (*Discussion, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/snippets/%d/discussions/%s", - PathEscape(project), - snippet, - discussion, + return do[*Discussion](s.client, + withPath("projects/%s/snippets/%d/discussions/%s", ProjectID{pid}, snippet, discussion), + withRequestOpts(options...), ) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - d := new(Discussion) - resp, err := s.client.Do(req, d) - if err != nil { - return nil, resp, err - } - - return d, resp, nil } // CreateSnippetDiscussionOptions represents the available @@ -493,24 +374,12 @@ type CreateSnippetDiscussionOptions struct { } func (s *DiscussionsService) CreateSnippetDiscussion(pid any, snippet int64, opt *CreateSnippetDiscussionOptions, options ...RequestOptionFunc) (*Discussion, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/snippets/%d/discussions", PathEscape(project), snippet) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - d := new(Discussion) - resp, err := s.client.Do(req, d) - if err != nil { - return nil, resp, err - } - - return d, resp, nil + return do[*Discussion](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/snippets/%d/discussions", ProjectID{pid}, snippet), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // AddSnippetDiscussionNoteOptions represents the available @@ -524,28 +393,12 @@ type AddSnippetDiscussionNoteOptions struct { } func (s *DiscussionsService) AddSnippetDiscussionNote(pid any, snippet int64, discussion string, opt *AddSnippetDiscussionNoteOptions, options ...RequestOptionFunc) (*Note, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/snippets/%d/discussions/%s/notes", - PathEscape(project), - snippet, - discussion, + return do[*Note](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/snippets/%d/discussions/%s/notes", ProjectID{pid}, snippet, discussion), + withAPIOpts(opt), + withRequestOpts(options...), ) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - n := new(Note) - resp, err := s.client.Do(req, n) - if err != nil { - return nil, resp, err - } - - return n, resp, nil } // UpdateSnippetDiscussionNoteOptions represents the available @@ -559,49 +412,21 @@ type UpdateSnippetDiscussionNoteOptions struct { } func (s *DiscussionsService) UpdateSnippetDiscussionNote(pid any, snippet int64, discussion string, note int64, opt *UpdateSnippetDiscussionNoteOptions, options ...RequestOptionFunc) (*Note, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/snippets/%d/discussions/%s/notes/%d", - PathEscape(project), - snippet, - discussion, - note, + return do[*Note](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/snippets/%d/discussions/%s/notes/%d", ProjectID{pid}, snippet, discussion, note), + withAPIOpts(opt), + withRequestOpts(options...), ) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - n := new(Note) - resp, err := s.client.Do(req, n) - if err != nil { - return nil, resp, err - } - - return n, resp, nil } func (s *DiscussionsService) DeleteSnippetDiscussionNote(pid any, snippet int64, discussion string, note int64, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/snippets/%d/discussions/%s/notes/%d", - PathEscape(project), - snippet, - discussion, - note, + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/snippets/%d/discussions/%s/notes/%d", ProjectID{pid}, snippet, discussion, note), + withRequestOpts(options...), ) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + return resp, err } // ListGroupEpicDiscussionsOptions represents the available @@ -614,52 +439,18 @@ type ListGroupEpicDiscussionsOptions struct { } func (s *DiscussionsService) ListGroupEpicDiscussions(gid any, epic int64, opt *ListGroupEpicDiscussionsOptions, options ...RequestOptionFunc) ([]*Discussion, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/epics/%d/discussions", - PathEscape(group), - epic, + return do[[]*Discussion](s.client, + withPath("groups/%s/epics/%d/discussions", GroupID{gid}, epic), + withAPIOpts(opt), + withRequestOpts(options...), ) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var ds []*Discussion - resp, err := s.client.Do(req, &ds) - if err != nil { - return nil, resp, err - } - - return ds, resp, nil } func (s *DiscussionsService) GetEpicDiscussion(gid any, epic int64, discussion string, options ...RequestOptionFunc) (*Discussion, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/epics/%d/discussions/%s", - PathEscape(group), - epic, - discussion, + return do[*Discussion](s.client, + withPath("groups/%s/epics/%d/discussions/%s", GroupID{gid}, epic, discussion), + withRequestOpts(options...), ) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - d := new(Discussion) - resp, err := s.client.Do(req, d) - if err != nil { - return nil, resp, err - } - - return d, resp, nil } // CreateEpicDiscussionOptions represents the available CreateEpicDiscussion() @@ -673,27 +464,12 @@ type CreateEpicDiscussionOptions struct { } func (s *DiscussionsService) CreateEpicDiscussion(gid any, epic int64, opt *CreateEpicDiscussionOptions, options ...RequestOptionFunc) (*Discussion, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/epics/%d/discussions", - PathEscape(group), - epic, + return do[*Discussion](s.client, + withMethod(http.MethodPost), + withPath("groups/%s/epics/%d/discussions", GroupID{gid}, epic), + withAPIOpts(opt), + withRequestOpts(options...), ) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - d := new(Discussion) - resp, err := s.client.Do(req, d) - if err != nil { - return nil, resp, err - } - - return d, resp, nil } // AddEpicDiscussionNoteOptions represents the available @@ -707,28 +483,12 @@ type AddEpicDiscussionNoteOptions struct { } func (s *DiscussionsService) AddEpicDiscussionNote(gid any, epic int64, discussion string, opt *AddEpicDiscussionNoteOptions, options ...RequestOptionFunc) (*Note, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/epics/%d/discussions/%s/notes", - PathEscape(group), - epic, - discussion, + return do[*Note](s.client, + withMethod(http.MethodPost), + withPath("groups/%s/epics/%d/discussions/%s/notes", GroupID{gid}, epic, discussion), + withAPIOpts(opt), + withRequestOpts(options...), ) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - n := new(Note) - resp, err := s.client.Do(req, n) - if err != nil { - return nil, resp, err - } - - return n, resp, nil } // UpdateEpicDiscussionNoteOptions represents the available UpdateEpicDiscussion() @@ -742,49 +502,21 @@ type UpdateEpicDiscussionNoteOptions struct { } func (s *DiscussionsService) UpdateEpicDiscussionNote(gid any, epic int64, discussion string, note int64, opt *UpdateEpicDiscussionNoteOptions, options ...RequestOptionFunc) (*Note, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/epics/%d/discussions/%s/notes/%d", - PathEscape(group), - epic, - discussion, - note, + return do[*Note](s.client, + withMethod(http.MethodPut), + withPath("groups/%s/epics/%d/discussions/%s/notes/%d", GroupID{gid}, epic, discussion, note), + withAPIOpts(opt), + withRequestOpts(options...), ) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - n := new(Note) - resp, err := s.client.Do(req, n) - if err != nil { - return nil, resp, err - } - - return n, resp, nil } func (s *DiscussionsService) DeleteEpicDiscussionNote(gid any, epic int64, discussion string, note int64, options ...RequestOptionFunc) (*Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("groups/%s/epics/%d/discussions/%s/notes/%d", - PathEscape(group), - epic, - discussion, - note, + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("groups/%s/epics/%d/discussions/%s/notes/%d", GroupID{gid}, epic, discussion, note), + withRequestOpts(options...), ) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + return resp, err } // ListMergeRequestDiscussionsOptions represents the available @@ -797,52 +529,18 @@ type ListMergeRequestDiscussionsOptions struct { } func (s *DiscussionsService) ListMergeRequestDiscussions(pid any, mergeRequest int64, opt *ListMergeRequestDiscussionsOptions, options ...RequestOptionFunc) ([]*Discussion, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/merge_requests/%d/discussions", - PathEscape(project), - mergeRequest, + return do[[]*Discussion](s.client, + withPath("projects/%s/merge_requests/%d/discussions", ProjectID{pid}, mergeRequest), + withAPIOpts(opt), + withRequestOpts(options...), ) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var ds []*Discussion - resp, err := s.client.Do(req, &ds) - if err != nil { - return nil, resp, err - } - - return ds, resp, nil } func (s *DiscussionsService) GetMergeRequestDiscussion(pid any, mergeRequest int64, discussion string, options ...RequestOptionFunc) (*Discussion, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/merge_requests/%d/discussions/%s", - PathEscape(project), - mergeRequest, - discussion, + return do[*Discussion](s.client, + withPath("projects/%s/merge_requests/%d/discussions/%s", ProjectID{pid}, mergeRequest, discussion), + withRequestOpts(options...), ) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - d := new(Discussion) - resp, err := s.client.Do(req, d) - if err != nil { - return nil, resp, err - } - - return d, resp, nil } // CreateMergeRequestDiscussionOptions represents the available @@ -889,27 +587,12 @@ type LinePositionOptions struct { } func (s *DiscussionsService) CreateMergeRequestDiscussion(pid any, mergeRequest int64, opt *CreateMergeRequestDiscussionOptions, options ...RequestOptionFunc) (*Discussion, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/merge_requests/%d/discussions", - PathEscape(project), - mergeRequest, + return do[*Discussion](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/merge_requests/%d/discussions", ProjectID{pid}, mergeRequest), + withAPIOpts(opt), + withRequestOpts(options...), ) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - d := new(Discussion) - resp, err := s.client.Do(req, d) - if err != nil { - return nil, resp, err - } - - return d, resp, nil } // ResolveMergeRequestDiscussionOptions represents the available @@ -922,28 +605,12 @@ type ResolveMergeRequestDiscussionOptions struct { } func (s *DiscussionsService) ResolveMergeRequestDiscussion(pid any, mergeRequest int64, discussion string, opt *ResolveMergeRequestDiscussionOptions, options ...RequestOptionFunc) (*Discussion, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/merge_requests/%d/discussions/%s", - PathEscape(project), - mergeRequest, - discussion, + return do[*Discussion](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/merge_requests/%d/discussions/%s", ProjectID{pid}, mergeRequest, discussion), + withAPIOpts(opt), + withRequestOpts(options...), ) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - d := new(Discussion) - resp, err := s.client.Do(req, d) - if err != nil { - return nil, resp, err - } - - return d, resp, nil } // AddMergeRequestDiscussionNoteOptions represents the available @@ -957,28 +624,12 @@ type AddMergeRequestDiscussionNoteOptions struct { } func (s *DiscussionsService) AddMergeRequestDiscussionNote(pid any, mergeRequest int64, discussion string, opt *AddMergeRequestDiscussionNoteOptions, options ...RequestOptionFunc) (*Note, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/merge_requests/%d/discussions/%s/notes", - PathEscape(project), - mergeRequest, - discussion, + return do[*Note](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/merge_requests/%d/discussions/%s/notes", ProjectID{pid}, mergeRequest, discussion), + withAPIOpts(opt), + withRequestOpts(options...), ) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - n := new(Note) - resp, err := s.client.Do(req, n) - if err != nil { - return nil, resp, err - } - - return n, resp, nil } // UpdateMergeRequestDiscussionNoteOptions represents the available @@ -993,49 +644,21 @@ type UpdateMergeRequestDiscussionNoteOptions struct { } func (s *DiscussionsService) UpdateMergeRequestDiscussionNote(pid any, mergeRequest int64, discussion string, note int64, opt *UpdateMergeRequestDiscussionNoteOptions, options ...RequestOptionFunc) (*Note, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/merge_requests/%d/discussions/%s/notes/%d", - PathEscape(project), - mergeRequest, - discussion, - note, + return do[*Note](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/merge_requests/%d/discussions/%s/notes/%d", ProjectID{pid}, mergeRequest, discussion, note), + withAPIOpts(opt), + withRequestOpts(options...), ) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - n := new(Note) - resp, err := s.client.Do(req, n) - if err != nil { - return nil, resp, err - } - - return n, resp, nil } func (s *DiscussionsService) DeleteMergeRequestDiscussionNote(pid any, mergeRequest int64, discussion string, note int64, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/merge_requests/%d/discussions/%s/notes/%d", - PathEscape(project), - mergeRequest, - discussion, - note, + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/merge_requests/%d/discussions/%s/notes/%d", ProjectID{pid}, mergeRequest, discussion, note), + withRequestOpts(options...), ) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + return resp, err } // ListCommitDiscussionsOptions represents the available @@ -1048,52 +671,18 @@ type ListCommitDiscussionsOptions struct { } func (s *DiscussionsService) ListCommitDiscussions(pid any, commit string, opt *ListCommitDiscussionsOptions, options ...RequestOptionFunc) ([]*Discussion, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/repository/commits/%s/discussions", - PathEscape(project), - commit, + return do[[]*Discussion](s.client, + withPath("projects/%s/repository/commits/%s/discussions", ProjectID{pid}, commit), + withAPIOpts(opt), + withRequestOpts(options...), ) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var ds []*Discussion - resp, err := s.client.Do(req, &ds) - if err != nil { - return nil, resp, err - } - - return ds, resp, nil } func (s *DiscussionsService) GetCommitDiscussion(pid any, commit string, discussion string, options ...RequestOptionFunc) (*Discussion, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/repository/commits/%s/discussions/%s", - PathEscape(project), - commit, - discussion, + return do[*Discussion](s.client, + withPath("projects/%s/repository/commits/%s/discussions/%s", ProjectID{pid}, commit, discussion), + withRequestOpts(options...), ) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - d := new(Discussion) - resp, err := s.client.Do(req, d) - if err != nil { - return nil, resp, err - } - - return d, resp, nil } // CreateCommitDiscussionOptions represents the available @@ -1108,27 +697,12 @@ type CreateCommitDiscussionOptions struct { } func (s *DiscussionsService) CreateCommitDiscussion(pid any, commit string, opt *CreateCommitDiscussionOptions, options ...RequestOptionFunc) (*Discussion, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/repository/commits/%s/discussions", - PathEscape(project), - commit, + return do[*Discussion](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/repository/commits/%s/discussions", ProjectID{pid}, commit), + withAPIOpts(opt), + withRequestOpts(options...), ) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - d := new(Discussion) - resp, err := s.client.Do(req, d) - if err != nil { - return nil, resp, err - } - - return d, resp, nil } // AddCommitDiscussionNoteOptions represents the available @@ -1142,28 +716,12 @@ type AddCommitDiscussionNoteOptions struct { } func (s *DiscussionsService) AddCommitDiscussionNote(pid any, commit string, discussion string, opt *AddCommitDiscussionNoteOptions, options ...RequestOptionFunc) (*Note, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/repository/commits/%s/discussions/%s/notes", - PathEscape(project), - commit, - discussion, + return do[*Note](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/repository/commits/%s/discussions/%s/notes", ProjectID{pid}, commit, discussion), + withAPIOpts(opt), + withRequestOpts(options...), ) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - n := new(Note) - resp, err := s.client.Do(req, n) - if err != nil { - return nil, resp, err - } - - return n, resp, nil } // UpdateCommitDiscussionNoteOptions represents the available @@ -1177,47 +735,19 @@ type UpdateCommitDiscussionNoteOptions struct { } func (s *DiscussionsService) UpdateCommitDiscussionNote(pid any, commit string, discussion string, note int64, opt *UpdateCommitDiscussionNoteOptions, options ...RequestOptionFunc) (*Note, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/repository/commits/%s/discussions/%s/notes/%d", - PathEscape(project), - commit, - discussion, - note, + return do[*Note](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/repository/commits/%s/discussions/%s/notes/%d", ProjectID{pid}, commit, discussion, note), + withAPIOpts(opt), + withRequestOpts(options...), ) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - n := new(Note) - resp, err := s.client.Do(req, n) - if err != nil { - return nil, resp, err - } - - return n, resp, nil } func (s *DiscussionsService) DeleteCommitDiscussionNote(pid any, commit string, discussion string, note int64, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/repository/commits/%s/discussions/%s/notes/%d", - PathEscape(project), - commit, - discussion, - note, + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/repository/commits/%s/discussions/%s/notes/%d", ProjectID{pid}, commit, discussion, note), + withRequestOpts(options...), ) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + return resp, err } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/dockerfile_templates.go b/vendor/gitlab.com/gitlab-org/api/client-go/dockerfile_templates.go index ba71346f..438cba90 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/dockerfile_templates.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/dockerfile_templates.go @@ -16,12 +16,6 @@ package gitlab -import ( - "fmt" - "net/http" - "net/url" -) - type ( // DockerfileTemplatesServiceInterface defines all the API methods for the DockerfileTemplatesService DockerfileTemplatesServiceInterface interface { @@ -74,33 +68,16 @@ type ListDockerfileTemplatesOptions struct { } func (s *DockerfileTemplatesService) ListTemplates(opt *ListDockerfileTemplatesOptions, options ...RequestOptionFunc) ([]*DockerfileTemplateListItem, *Response, error) { - req, err := s.client.NewRequest(http.MethodGet, "templates/dockerfiles", opt, options) - if err != nil { - return nil, nil, err - } - - var gs []*DockerfileTemplateListItem - resp, err := s.client.Do(req, &gs) - if err != nil { - return nil, resp, err - } - - return gs, resp, nil + return do[[]*DockerfileTemplateListItem](s.client, + withPath("templates/dockerfiles"), + withAPIOpts(opt), + withRequestOpts(options...), + ) } func (s *DockerfileTemplatesService) GetTemplate(key string, options ...RequestOptionFunc) (*DockerfileTemplate, *Response, error) { - u := fmt.Sprintf("templates/dockerfiles/%s", url.PathEscape(key)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - g := new(DockerfileTemplate) - resp, err := s.client.Do(req, g) - if err != nil { - return nil, resp, err - } - - return g, resp, nil + return do[*DockerfileTemplate](s.client, + withPath("templates/dockerfiles/%s", key), + withRequestOpts(options...), + ) } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/draft_notes.go b/vendor/gitlab.com/gitlab-org/api/client-go/draft_notes.go index c4eb8ef3..e82570cf 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/draft_notes.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/draft_notes.go @@ -17,7 +17,6 @@ package gitlab import ( - "fmt" "net/http" ) @@ -103,45 +102,18 @@ type ListDraftNotesOptions struct { } func (s *DraftNotesService) ListDraftNotes(pid any, mergeRequest int64, opt *ListDraftNotesOptions, options ...RequestOptionFunc) ([]*DraftNote, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/merge_requests/%d/draft_notes", PathEscape(project), mergeRequest) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var n []*DraftNote - resp, err := s.client.Do(req, &n) - if err != nil { - return nil, resp, err - } - - return n, resp, nil + return do[[]*DraftNote](s.client, + withPath("projects/%s/merge_requests/%d/draft_notes", ProjectID{pid}, mergeRequest), + withAPIOpts(opt), + withRequestOpts(options...), + ) } func (s *DraftNotesService) GetDraftNote(pid any, mergeRequest int64, note int64, options ...RequestOptionFunc) (*DraftNote, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/merge_requests/%d/draft_notes/%d", PathEscape(project), mergeRequest, note) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - n := new(DraftNote) - resp, err := s.client.Do(req, &n) - if err != nil { - return nil, resp, err - } - - return n, resp, nil + return do[*DraftNote](s.client, + withPath("projects/%s/merge_requests/%d/draft_notes/%d", ProjectID{pid}, mergeRequest, note), + withRequestOpts(options...), + ) } // CreateDraftNoteOptions represents the available CreateDraftNote() @@ -159,24 +131,12 @@ type CreateDraftNoteOptions struct { } func (s *DraftNotesService) CreateDraftNote(pid any, mergeRequest int64, opt *CreateDraftNoteOptions, options ...RequestOptionFunc) (*DraftNote, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/merge_requests/%d/draft_notes", PathEscape(project), mergeRequest) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - n := new(DraftNote) - resp, err := s.client.Do(req, &n) - if err != nil { - return nil, resp, err - } - - return n, resp, nil + return do[*DraftNote](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/merge_requests/%d/draft_notes", ProjectID{pid}, mergeRequest), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // UpdateDraftNoteOptions represents the available UpdateDraftNote() @@ -191,67 +151,37 @@ type UpdateDraftNoteOptions struct { } func (s *DraftNotesService) UpdateDraftNote(pid any, mergeRequest int64, note int64, opt *UpdateDraftNoteOptions, options ...RequestOptionFunc) (*DraftNote, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/merge_requests/%d/draft_notes/%d", PathEscape(project), mergeRequest, note) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - n := new(DraftNote) - resp, err := s.client.Do(req, &n) - if err != nil { - return nil, resp, err - } - - return n, resp, nil + return do[*DraftNote](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/merge_requests/%d/draft_notes/%d", ProjectID{pid}, mergeRequest, note), + withAPIOpts(opt), + withRequestOpts(options...), + ) } func (s *DraftNotesService) DeleteDraftNote(pid any, mergeRequest int64, note int64, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/merge_requests/%d/draft_notes/%d", PathEscape(project), mergeRequest, note) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/merge_requests/%d/draft_notes/%d", ProjectID{pid}, mergeRequest, note), + withRequestOpts(options...), + ) + return resp, err } func (s *DraftNotesService) PublishDraftNote(pid any, mergeRequest int64, note int64, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/merge_requests/%d/draft_notes/%d/publish", PathEscape(project), mergeRequest, note) - - req, err := s.client.NewRequest(http.MethodPut, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/merge_requests/%d/draft_notes/%d/publish", ProjectID{pid}, mergeRequest, note), + withRequestOpts(options...), + ) + return resp, err } func (s *DraftNotesService) PublishAllDraftNotes(pid any, mergeRequest int64, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/merge_requests/%d/draft_notes/bulk_publish", PathEscape(project), mergeRequest) - - req, err := s.client.NewRequest(http.MethodPost, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/merge_requests/%d/draft_notes/bulk_publish", ProjectID{pid}, mergeRequest), + withRequestOpts(options...), + ) + return resp, err } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/enterprise_users.go b/vendor/gitlab.com/gitlab-org/api/client-go/enterprise_users.go index 230dbb4f..74f6c93f 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/enterprise_users.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/enterprise_users.go @@ -15,7 +15,6 @@ package gitlab import ( - "fmt" "net/http" "time" ) @@ -60,24 +59,11 @@ type ListEnterpriseUsersOptions struct { } func (s *EnterpriseUsersService) ListEnterpriseUsers(gid any, opt *ListEnterpriseUsersOptions, options ...RequestOptionFunc) ([]*User, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/enterprise_users", PathEscape(group)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var users []*User - resp, err := s.client.Do(req, &users) - if err != nil { - return nil, resp, err - } - - return users, resp, nil + return do[[]*User](s.client, + withPath("groups/%s/enterprise_users", GroupID{gid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // GetEnterpriseUser gets details on a specified enterprise user. @@ -85,24 +71,10 @@ func (s *EnterpriseUsersService) ListEnterpriseUsers(gid any, opt *ListEnterpris // GitLab API docs: // https://docs.gitlab.com/api/group_enterprise_users/#get-details-on-an-enterprise-user func (s *EnterpriseUsersService) GetEnterpriseUser(gid any, uid int64, options ...RequestOptionFunc) (*User, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/enterprise_users/%d", PathEscape(group), uid) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - user := new(User) - resp, err := s.client.Do(req, &user) - if err != nil { - return nil, resp, err - } - - return user, resp, nil + return do[*User](s.client, + withPath("groups/%s/enterprise_users/%d", GroupID{gid}, uid), + withRequestOpts(options...), + ) } // Disable2FAForEnterpriseUser disables two-factor authentication (2FA) for a @@ -111,18 +83,12 @@ func (s *EnterpriseUsersService) GetEnterpriseUser(gid any, uid int64, options . // GitLab API docs: // https://docs.gitlab.com/api/group_enterprise_users/#disable-two-factor-authentication-for-an-enterprise-user func (s *EnterpriseUsersService) Disable2FAForEnterpriseUser(gid any, uid int64, options ...RequestOptionFunc) (*Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("groups/%s/enterprise_users/%d/disable_two_factor", PathEscape(group), uid) - - req, err := s.client.NewRequest(http.MethodPatch, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodPatch), + withPath("groups/%s/enterprise_users/%d/disable_two_factor", GroupID{gid}, uid), + withRequestOpts(options...), + ) + return resp, err } // DeleteEnterpriseUserOptions represents the available DeleteEnterpriseUser options. @@ -138,16 +104,11 @@ type DeleteEnterpriseUserOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/group_enterprise_users/#delete-an-enterprise-user func (s *EnterpriseUsersService) DeleteEnterpriseUser(gid any, uid int64, opt *DeleteEnterpriseUserOptions, options ...RequestOptionFunc) (*Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("groups/%s/enterprise_users/%d", PathEscape(group), uid) - - req, err := s.client.NewRequest(http.MethodDelete, u, opt, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("groups/%s/enterprise_users/%d", GroupID{gid}, uid), + withAPIOpts(opt), + withRequestOpts(options...), + ) + return resp, err } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/epic_issues.go b/vendor/gitlab.com/gitlab-org/api/client-go/epic_issues.go index f27bfb85..738db84e 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/epic_issues.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/epic_issues.go @@ -17,7 +17,6 @@ package gitlab import ( - "fmt" "net/http" ) @@ -65,24 +64,11 @@ type EpicIssueAssignment struct { // Gitlab API docs: // https://docs.gitlab.com/api/epic_issues/#list-issues-for-an-epic func (s *EpicIssuesService) ListEpicIssues(gid any, epic int64, opt *ListOptions, options ...RequestOptionFunc) ([]*Issue, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/epics/%d/issues", PathEscape(group), epic) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var is []*Issue - resp, err := s.client.Do(req, &is) - if err != nil { - return nil, resp, err - } - - return is, resp, nil + return do[[]*Issue](s.client, + withPath("groups/%s/epics/%d/issues", GroupID{gid}, epic), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // AssignEpicIssue assigns an existing issue to an epic. @@ -91,24 +77,11 @@ func (s *EpicIssuesService) ListEpicIssues(gid any, epic int64, opt *ListOptions // Gitlab API Docs: // https://docs.gitlab.com/api/epic_issues/#assign-an-issue-to-the-epic func (s *EpicIssuesService) AssignEpicIssue(gid any, epic, issue int64, options ...RequestOptionFunc) (*EpicIssueAssignment, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/epics/%d/issues/%d", PathEscape(group), epic, issue) - - req, err := s.client.NewRequest(http.MethodPost, u, nil, options) - if err != nil { - return nil, nil, err - } - - a := new(EpicIssueAssignment) - resp, err := s.client.Do(req, a) - if err != nil { - return nil, resp, err - } - - return a, resp, nil + return do[*EpicIssueAssignment](s.client, + withMethod(http.MethodPost), + withPath("groups/%s/epics/%d/issues/%d", GroupID{gid}, epic, issue), + withRequestOpts(options...), + ) } // RemoveEpicIssue removes an issue from an epic. @@ -117,24 +90,11 @@ func (s *EpicIssuesService) AssignEpicIssue(gid any, epic, issue int64, options // Gitlab API Docs: // https://docs.gitlab.com/api/epic_issues/#remove-an-issue-from-the-epic func (s *EpicIssuesService) RemoveEpicIssue(gid any, epic, epicIssue int64, options ...RequestOptionFunc) (*EpicIssueAssignment, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/epics/%d/issues/%d", PathEscape(group), epic, epicIssue) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, nil, err - } - - a := new(EpicIssueAssignment) - resp, err := s.client.Do(req, a) - if err != nil { - return nil, resp, err - } - - return a, resp, nil + return do[*EpicIssueAssignment](s.client, + withMethod(http.MethodDelete), + withPath("groups/%s/epics/%d/issues/%d", GroupID{gid}, epic, epicIssue), + withRequestOpts(options...), + ) } type UpdateEpicIssueAssignmentOptions struct { @@ -150,22 +110,10 @@ type UpdateEpicIssueAssignmentOptions struct { // Gitlab API Docs: // https://docs.gitlab.com/api/epic_issues/#update-epic---issue-association func (s *EpicIssuesService) UpdateEpicIssueAssignment(gid any, epic, epicIssue int64, opt *UpdateEpicIssueAssignmentOptions, options ...RequestOptionFunc) ([]*Issue, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/epics/%d/issues/%d", PathEscape(group), epic, epicIssue) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - var is []*Issue - resp, err := s.client.Do(req, &is) - if err != nil { - return nil, resp, err - } - - return is, resp, nil + return do[[]*Issue](s.client, + withMethod(http.MethodPut), + withPath("groups/%s/epics/%d/issues/%d", GroupID{gid}, epic, epicIssue), + withAPIOpts(opt), + withRequestOpts(options...), + ) } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/epics.go b/vendor/gitlab.com/gitlab-org/api/client-go/epics.go index eb4ded33..9f4818a7 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/epics.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/epics.go @@ -17,7 +17,6 @@ package gitlab import ( - "fmt" "net/http" "time" ) @@ -138,24 +137,11 @@ type ListGroupEpicsOptions struct { } func (s *EpicsService) ListGroupEpics(gid any, opt *ListGroupEpicsOptions, options ...RequestOptionFunc) ([]*Epic, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/epics", PathEscape(group)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var es []*Epic - resp, err := s.client.Do(req, &es) - if err != nil { - return nil, resp, err - } - - return es, resp, nil + return do[[]*Epic](s.client, + withPath("groups/%s/epics", GroupID{gid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // GetEpic gets a single group epic. @@ -163,24 +149,10 @@ func (s *EpicsService) ListGroupEpics(gid any, opt *ListGroupEpicsOptions, optio // // GitLab API docs: https://docs.gitlab.com/api/epics/#single-epic func (s *EpicsService) GetEpic(gid any, epic int64, options ...RequestOptionFunc) (*Epic, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/epics/%d", PathEscape(group), epic) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - e := new(Epic) - resp, err := s.client.Do(req, e) - if err != nil { - return nil, resp, err - } - - return e, resp, nil + return do[*Epic](s.client, + withPath("groups/%s/epics/%d", GroupID{gid}, epic), + withRequestOpts(options...), + ) } // GetEpicLinks gets all child epics of an epic. @@ -188,24 +160,10 @@ func (s *EpicsService) GetEpic(gid any, epic int64, options ...RequestOptionFunc // // GitLab API docs: https://docs.gitlab.com/api/epic_links/ func (s *EpicsService) GetEpicLinks(gid any, epic int64, options ...RequestOptionFunc) ([]*Epic, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/epics/%d/epics", PathEscape(group), epic) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - var e []*Epic - resp, err := s.client.Do(req, &e) - if err != nil { - return nil, resp, err - } - - return e, resp, nil + return do[[]*Epic](s.client, + withPath("groups/%s/epics/%d/epics", GroupID{gid}, epic), + withRequestOpts(options...), + ) } // CreateEpicOptions represents the available CreateEpic() options. @@ -227,24 +185,12 @@ type CreateEpicOptions struct { } func (s *EpicsService) CreateEpic(gid any, opt *CreateEpicOptions, options ...RequestOptionFunc) (*Epic, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/epics", PathEscape(group)) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - e := new(Epic) - resp, err := s.client.Do(req, e) - if err != nil { - return nil, resp, err - } - - return e, resp, nil + return do[*Epic](s.client, + withMethod(http.MethodPost), + withPath("groups/%s/epics", GroupID{gid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // UpdateEpicOptions represents the available UpdateEpic() options. @@ -274,24 +220,12 @@ type UpdateEpicOptions struct { // // GitLab API docs: https://docs.gitlab.com/api/epics/#update-epic func (s *EpicsService) UpdateEpic(gid any, epic int64, opt *UpdateEpicOptions, options ...RequestOptionFunc) (*Epic, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/epics/%d", PathEscape(group), epic) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - e := new(Epic) - resp, err := s.client.Do(req, e) - if err != nil { - return nil, resp, err - } - - return e, resp, nil + return do[*Epic](s.client, + withMethod(http.MethodPut), + withPath("groups/%s/epics/%d", GroupID{gid}, epic), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // DeleteEpic deletes a single group epic. @@ -299,16 +233,10 @@ func (s *EpicsService) UpdateEpic(gid any, epic int64, opt *UpdateEpicOptions, o // // GitLab API docs: https://docs.gitlab.com/api/epics/#delete-epic func (s *EpicsService) DeleteEpic(gid any, epic int64, options ...RequestOptionFunc) (*Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("groups/%s/epics/%d", PathEscape(group), epic) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("groups/%s/epics/%d", GroupID{gid}, epic), + withRequestOpts(options...), + ) + return resp, err } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/error_tracking.go b/vendor/gitlab.com/gitlab-org/api/client-go/error_tracking.go index 5512b2ed..d39a1061 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/error_tracking.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/error_tracking.go @@ -16,10 +16,7 @@ package gitlab -import ( - "fmt" - "net/http" -) +import "net/http" type ( // ErrorTrackingServiceInterface defines all the API methods for the ErrorTrackingService @@ -98,24 +95,10 @@ func (p ErrorTrackingSettings) String() string { } func (s *ErrorTrackingService) GetErrorTrackingSettings(pid any, options ...RequestOptionFunc) (*ErrorTrackingSettings, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/error_tracking/settings", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - ets := new(ErrorTrackingSettings) - resp, err := s.client.Do(req, ets) - if err != nil { - return nil, resp, err - } - - return ets, resp, nil + return do[*ErrorTrackingSettings](s.client, + withPath("projects/%s/error_tracking/settings", ProjectID{pid}), + withRequestOpts(options...), + ) } // EnableDisableErrorTrackingOptions represents the available @@ -129,24 +112,12 @@ type EnableDisableErrorTrackingOptions struct { } func (s *ErrorTrackingService) EnableDisableErrorTracking(pid any, opt *EnableDisableErrorTrackingOptions, options ...RequestOptionFunc) (*ErrorTrackingSettings, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/error_tracking/settings", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPatch, u, opt, options) - if err != nil { - return nil, nil, err - } - - ets := new(ErrorTrackingSettings) - resp, err := s.client.Do(req, &ets) - if err != nil { - return nil, resp, err - } - - return ets, resp, nil + return do[*ErrorTrackingSettings](s.client, + withMethod(http.MethodPatch), + withPath("projects/%s/error_tracking/settings", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // ListClientKeysOptions represents the available ListClientKeys() options. @@ -158,45 +129,19 @@ type ListClientKeysOptions struct { } func (s *ErrorTrackingService) ListClientKeys(pid any, opt *ListClientKeysOptions, options ...RequestOptionFunc) ([]*ErrorTrackingClientKey, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/error_tracking/client_keys", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var cks []*ErrorTrackingClientKey - resp, err := s.client.Do(req, &cks) - if err != nil { - return nil, resp, err - } - - return cks, resp, nil + return do[[]*ErrorTrackingClientKey](s.client, + withPath("projects/%s/error_tracking/client_keys", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } func (s *ErrorTrackingService) CreateClientKey(pid any, options ...RequestOptionFunc) (*ErrorTrackingClientKey, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/error_tracking/client_keys", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPost, u, nil, options) - if err != nil { - return nil, nil, err - } - - ck := new(ErrorTrackingClientKey) - resp, err := s.client.Do(req, ck) - if err != nil { - return nil, resp, err - } - - return ck, resp, nil + return do[*ErrorTrackingClientKey](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/error_tracking/client_keys", ProjectID{pid}), + withRequestOpts(options...), + ) } // DeleteClientKey removes a client key from the project. @@ -204,16 +149,10 @@ func (s *ErrorTrackingService) CreateClientKey(pid any, options ...RequestOption // GitLab API docs: // https://docs.gitlab.com/api/error_tracking/#delete-a-client-key func (s *ErrorTrackingService) DeleteClientKey(pid any, keyID int64, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/error_tracking/client_keys/%d", PathEscape(project), keyID) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/error_tracking/client_keys/%d", ProjectID{pid}, keyID), + withRequestOpts(options...), + ) + return resp, err } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/event_parsing.go b/vendor/gitlab.com/gitlab-org/api/client-go/event_parsing.go index 803608bc..c446da3f 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/event_parsing.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/event_parsing.go @@ -18,6 +18,7 @@ package gitlab import ( "encoding/json" + "errors" "fmt" "net/http" ) @@ -31,13 +32,16 @@ const ( EventConfidentialNote EventType = "Confidential Note Hook" EventTypeBuild EventType = "Build Hook" EventTypeDeployment EventType = "Deployment Hook" + EventTypeEmoji EventType = "Emoji Hook" EventTypeFeatureFlag EventType = "Feature Flag Hook" EventTypeIssue EventType = "Issue Hook" EventTypeJob EventType = "Job Hook" EventTypeMember EventType = "Member Hook" EventTypeMergeRequest EventType = "Merge Request Hook" + EventTypeMilestone EventType = "Milestone Hook" EventTypeNote EventType = "Note Hook" EventTypePipeline EventType = "Pipeline Hook" + EventTypeProject EventType = "Project Hook" EventTypePush EventType = "Push Hook" EventTypeRelease EventType = "Release Hook" EventTypeResourceAccessToken EventType = "Resource Access Token Hook" @@ -45,6 +49,7 @@ const ( EventTypeSubGroup EventType = "Subgroup Hook" EventTypeSystemHook EventType = "System Hook" EventTypeTagPush EventType = "Tag Push Hook" + EventTypeVulnerability EventType = "Vulnerability Hook" EventTypeWikiPage EventType = "Wiki Page Hook" ) @@ -223,6 +228,8 @@ func ParseWebhook(eventType EventType, payload []byte) (event any, err error) { event = &BuildEvent{} case EventTypeDeployment: event = &DeploymentEvent{} + case EventTypeEmoji: + event = &EmojiEvent{} case EventTypeFeatureFlag: event = &FeatureFlagEvent{} case EventTypeIssue, EventConfidentialIssue: @@ -233,6 +240,8 @@ func ParseWebhook(eventType EventType, payload []byte) (event any, err error) { event = &MemberEvent{} case EventTypeMergeRequest: event = &MergeEvent{} + case EventTypeMilestone: + event = &MilestoneWebhookEvent{} case EventTypeNote, EventConfidentialNote: note := ¬eEvent{} err := json.Unmarshal(payload, note) @@ -258,6 +267,8 @@ func ParseWebhook(eventType EventType, payload []byte) (event any, err error) { } case EventTypePipeline: event = &PipelineEvent{} + case EventTypeProject: + event = &ProjectWebhookEvent{} case EventTypePush: event = &PushEvent{} case EventTypeRelease: @@ -278,7 +289,7 @@ func ParseWebhook(eventType EventType, payload []byte) (event any, err error) { case projectEvent: event = &ProjectResourceAccessTokenEvent{} default: - return nil, fmt.Errorf("unexpected resource access token payload") + return nil, errors.New("unexpected resource access token payload") } case EventTypeServiceHook: service := &serviceEvent{} @@ -300,6 +311,8 @@ func ParseWebhook(eventType EventType, payload []byte) (event any, err error) { event = &SubGroupEvent{} case EventTypeTagPush: event = &TagEvent{} + case EventTypeVulnerability: + event = &VulnerabilityEvent{} case EventTypeWikiPage: event = &WikiPageEvent{} default: diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/event_webhook_types.go b/vendor/gitlab.com/gitlab-org/api/client-go/event_webhook_types.go index 0d4af58b..3963dca5 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/event_webhook_types.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/event_webhook_types.go @@ -234,10 +234,13 @@ type GroupResourceAccessTokenEvent struct { ObjectAttributes GroupResourceAccessTokenEventObjectAttributes `json:"object_attributes"` } +// GroupResourceAccessTokenEventGroup represents a group in a resource access +// token event. type GroupResourceAccessTokenEventGroup struct { GroupID int64 `json:"group_id"` GroupName string `json:"group_name"` GroupPath string `json:"group_path"` + FullPath string `json:"full_path"` } type GroupResourceAccessTokenEventObjectAttributes struct { @@ -839,7 +842,7 @@ type MergeEventChangesTargetProjectID struct { Current int64 `json:"current"` } -// EventUser represents a user record in an event and is used as an even +// EventUser represents a user record in an event and is used as an event // initiator or a merge assignee. type EventUser struct { ID int64 `json:"id"` @@ -1351,6 +1354,343 @@ type WikiPageEventObjectAttributes struct { DiffURL string `json:"diff_url"` } +// EmojiEvent represents an emoji event. +// +// GitLab API docs: +// https://docs.gitlab.com/user/project/integrations/webhook_events/#emoji-events +type EmojiEvent struct { + ObjectKind string `json:"object_kind"` + EventType string `json:"event_type"` + User EventUser `json:"user"` + ProjectID int64 `json:"project_id"` + Project EmojiEventProject `json:"project"` + ObjectAttributes EmojiEventObjectAttributes `json:"object_attributes"` + Note *EmojiEventNote `json:"note,omitempty"` + Issue *EmojiEventIssue `json:"issue,omitempty"` + MergeRequest *EmojiEventMergeRequest `json:"merge_request,omitempty"` + ProjectSnippet *EmojiEventSnippet `json:"project_snippet,omitempty"` + Commit *EmojiEventCommit `json:"commit,omitempty"` +} + +// EmojiEventProject represents a project in an emoji event. +type EmojiEventProject struct { + ID int64 `json:"id"` + Name string `json:"name"` + Description string `json:"description"` + WebURL string `json:"web_url"` + AvatarURL string `json:"avatar_url"` + GitSSHURL string `json:"git_ssh_url"` + GitHTTPURL string `json:"git_http_url"` + Namespace string `json:"namespace"` + VisibilityLevel int64 `json:"visibility_level"` + PathWithNamespace string `json:"path_with_namespace"` + DefaultBranch string `json:"default_branch"` + CIConfigPath string `json:"ci_config_path"` + Homepage string `json:"homepage"` + URL string `json:"url"` + SSHURL string `json:"ssh_url"` + HTTPURL string `json:"http_url"` +} + +type EmojiEventObjectAttributes struct { + UserID int64 `json:"user_id"` + CreatedAt string `json:"created_at"` + ID int64 `json:"id"` + Name string `json:"name"` + AwardableType string `json:"awardable_type"` + AwardableID int64 `json:"awardable_id"` + UpdatedAt string `json:"updated_at"` + Action string `json:"action"` + AwardedOnURL string `json:"awarded_on_url"` +} + +type EmojiEventNote struct { + Attachment *string `json:"attachment"` + AuthorID int64 `json:"author_id"` + ChangePosition *NotePosition `json:"change_position"` + CommitID *string `json:"commit_id"` + CreatedAt string `json:"created_at"` + DiscussionID string `json:"discussion_id"` + ID int64 `json:"id"` + LineCode *string `json:"line_code"` + Note string `json:"note"` + NoteableID int64 `json:"noteable_id"` + NoteableType string `json:"noteable_type"` + OriginalPosition *NotePosition `json:"original_position"` + Position *NotePosition `json:"position"` + ProjectID int64 `json:"project_id"` + ResolvedAt *string `json:"resolved_at"` + ResolvedByID *int64 `json:"resolved_by_id"` + ResolvedByPush *bool `json:"resolved_by_push"` + StDiff *Diff `json:"st_diff"` + System bool `json:"system"` + Type *string `json:"type"` + UpdatedAt string `json:"updated_at"` + UpdatedByID *int64 `json:"updated_by_id"` + Description string `json:"description"` + URL string `json:"url"` +} + +type EmojiEventIssue struct { + ID int64 `json:"id"` + IID int64 `json:"iid"` + ProjectID int64 `json:"project_id"` + AuthorID int64 `json:"author_id"` + ClosedAt *string `json:"closed_at"` + Confidential bool `json:"confidential"` + CreatedAt string `json:"created_at"` + Description string `json:"description"` + DiscussionLocked *bool `json:"discussion_locked"` + DueDate *ISOTime `json:"due_date"` + LastEditedAt *string `json:"last_edited_at"` + LastEditedByID *int64 `json:"last_edited_by_id"` + MilestoneID *int64 `json:"milestone_id"` + MovedToID *int64 `json:"moved_to_id"` + DuplicatedToID *int64 `json:"duplicated_to_id"` + RelativePosition int64 `json:"relative_position"` + StateID StateID `json:"state_id"` + TimeEstimate int64 `json:"time_estimate"` + Title string `json:"title"` + UpdatedAt string `json:"updated_at"` + UpdatedByID *int64 `json:"updated_by_id"` + Weight *int64 `json:"weight"` + HealthStatus *string `json:"health_status"` + URL string `json:"url"` + TotalTimeSpent int64 `json:"total_time_spent"` + TimeChange int64 `json:"time_change"` + HumanTotalTimeSpent *string `json:"human_total_time_spent"` + HumanTimeChange *string `json:"human_time_change"` + HumanTimeEstimate *string `json:"human_time_estimate"` + AssigneeIDs []int64 `json:"assignee_ids"` + AssigneeID *int64 `json:"assignee_id"` + Labels []*EventLabel `json:"labels"` + State string `json:"state"` + Severity string `json:"severity"` +} + +// EmojiEventMergeRequest represents a merge request in an emoji event. +type EmojiEventMergeRequest struct { + ID int64 `json:"id"` + TargetBranch string `json:"target_branch"` + SourceBranch string `json:"source_branch"` + SourceProjectID int64 `json:"source_project_id"` + AuthorID int64 `json:"author_id"` + AssigneeID int64 `json:"assignee_id"` + AssigneeIDs []int64 `json:"assignee_ids"` + ReviewerIDs []int64 `json:"reviewer_ids"` + Title string `json:"title"` + CreatedAt string `json:"created_at"` + UpdatedAt string `json:"updated_at"` + MilestoneID int64 `json:"milestone_id"` + State string `json:"state"` + MergeStatus string `json:"merge_status"` + TargetProjectID int64 `json:"target_project_id"` + IID int64 `json:"iid"` + Description string `json:"description"` + Position int64 `json:"position"` + Labels []*EventLabel `json:"labels"` + LockedAt string `json:"locked_at"` + UpdatedByID int64 `json:"updated_by_id"` + MergeError string `json:"merge_error"` + MergeParams *MergeParams `json:"merge_params"` + MergeWhenPipelineSucceeds bool `json:"merge_when_pipeline_succeeds"` + MergeUserID int64 `json:"merge_user_id"` + MergeCommitSHA string `json:"merge_commit_sha"` + DeletedAt string `json:"deleted_at"` + InProgressMergeCommitSHA string `json:"in_progress_merge_commit_sha"` + LockVersion int64 `json:"lock_version"` + ApprovalsBeforeMerge string `json:"approvals_before_merge"` + RebaseCommitSHA string `json:"rebase_commit_sha"` + TimeEstimate int64 `json:"time_estimate"` + Squash bool `json:"squash"` + LastEditedAt string `json:"last_edited_at"` + LastEditedByID int64 `json:"last_edited_by_id"` + Source *Repository `json:"source"` + Target *Repository `json:"target"` + LastCommit EventMergeRequestLastCommit `json:"last_commit"` + WorkInProgress bool `json:"work_in_progress"` + TotalTimeSpent int64 `json:"total_time_spent"` + HeadPipelineID int64 `json:"head_pipeline_id"` + Assignee *EventUser `json:"assignee"` + DetailedMergeStatus string `json:"detailed_merge_status"` + URL string `json:"url"` +} + +// EmojiEventSnippet represents a snippet in an emoji event. +type EmojiEventSnippet struct { + ID int64 `json:"id"` + Title string `json:"title"` + Content string `json:"content"` + AuthorID int64 `json:"author_id"` + ProjectID int64 `json:"project_id"` + CreatedAt string `json:"created_at"` + UpdatedAt string `json:"updated_at"` + Filename string `json:"file_name"` + ExpiresAt string `json:"expires_at"` + Type string `json:"type"` + VisibilityLevel int64 `json:"visibility_level"` + Description string `json:"description"` + Secret bool `json:"secret"` + RepositoryReadOnly bool `json:"repository_read_only"` +} + +// EmojiEventCommit represents a commit in an emoji event. +type EmojiEventCommit struct { + ID string `json:"id"` + Title string `json:"title"` + Message string `json:"message"` + Timestamp *time.Time `json:"timestamp"` + URL string `json:"url"` + Author EventCommitAuthor `json:"author"` +} + +// MilestoneWebhookEvent represents a milestone webhook event. +// +// GitLab API docs: +// https://docs.gitlab.com/user/project/integrations/webhook_events/#milestone-events +type MilestoneWebhookEvent struct { + ObjectKind string `json:"object_kind"` + EventType string `json:"event_type"` + Project MilestoneEventProject `json:"project"` + Group *MilestoneEventGroup `json:"group,omitempty"` + ObjectAttributes MilestoneEventObjectAttributes `json:"object_attributes"` + Action string `json:"action"` +} + +type MilestoneEventObjectAttributes struct { + ID int64 `json:"id"` + IID int64 `json:"iid"` + Title string `json:"title"` + Description string `json:"description"` + State string `json:"state"` + CreatedAt string `json:"created_at"` + UpdatedAt string `json:"updated_at"` + DueDate *ISOTime `json:"due_date"` + StartDate *ISOTime `json:"start_date"` + GroupID *int64 `json:"group_id"` + ProjectID int64 `json:"project_id"` +} + +// MilestoneEventGroup represents a group in a milestone event. +type MilestoneEventGroup struct { + GroupID int64 `json:"group_id"` + GroupName string `json:"group_name"` + GroupPath string `json:"group_path"` + FullPath string `json:"full_path"` +} + +// MilestoneEventProject represents a project in a milestone event. +type MilestoneEventProject struct { + ID int64 `json:"id"` + Name string `json:"name"` + Description string `json:"description"` + WebURL string `json:"web_url"` + AvatarURL string `json:"avatar_url"` + GitSSHURL string `json:"git_ssh_url"` + GitHTTPURL string `json:"git_http_url"` + Namespace string `json:"namespace"` + VisibilityLevel int64 `json:"visibility_level"` + PathWithNamespace string `json:"path_with_namespace"` + DefaultBranch string `json:"default_branch"` + CIConfigPath string `json:"ci_config_path"` + Homepage string `json:"homepage"` + URL string `json:"url"` + SSHURL string `json:"ssh_url"` + HTTPURL string `json:"http_url"` +} + +// ProjectWebhookEvent represents a project webhook event for group webhooks. +// +// GitLab API docs: +// https://docs.gitlab.com/user/project/integrations/webhook_events/#project-events +type ProjectWebhookEvent struct { + EventName string `json:"event_name"` + CreatedAt string `json:"created_at"` + UpdatedAt string `json:"updated_at"` + Name string `json:"name"` + Path string `json:"path"` + PathWithNamespace string `json:"path_with_namespace"` + ProjectID int64 `json:"project_id"` + ProjectNamespaceID int64 `json:"project_namespace_id"` + Owners []ProjectEventOwner `json:"owners"` + ProjectVisibility string `json:"project_visibility"` + OldPathWithNamespace string `json:"old_path_with_namespace,omitempty"` +} + +type ProjectEventOwner struct { + Name string `json:"name"` + Email string `json:"email"` +} + +// VulnerabilityEvent represents a vulnerability event. +// +// GitLab API docs: +// https://docs.gitlab.com/user/project/integrations/webhook_events/#vulnerability-events +type VulnerabilityEvent struct { + ObjectKind string `json:"object_kind"` + ObjectAttributes VulnerabilityEventObjectAttributes `json:"object_attributes"` +} + +type VulnerabilityEventObjectAttributes struct { + ID int64 `json:"id"` + URL string `json:"url"` + Title string `json:"title"` + State string `json:"state"` + ProjectID int64 `json:"project_id"` + Location VulnerabilityEventLocation `json:"location"` + CVSS []VulnerabilityEventCVSS `json:"cvss"` + Severity string `json:"severity"` + SeverityOverridden bool `json:"severity_overridden"` + Identifiers []VulnerabilityEventIdentifier `json:"identifiers"` + Issues []VulnerabilityEventIssue `json:"issues"` + ReportType string `json:"report_type"` + Confidence string `json:"confidence"` + ConfidenceOverridden bool `json:"confidence_overridden"` + ConfirmedAt string `json:"confirmed_at"` + ConfirmedByID int64 `json:"confirmed_by_id"` + DismissedAt string `json:"dismissed_at"` + DismissedByID int64 `json:"dismissed_by_id"` + ResolvedAt string `json:"resolved_at"` + ResolvedByID int64 `json:"resolved_by_id"` + AutoResolved bool `json:"auto_resolved"` + ResolvedOnDefaultBranch bool `json:"resolved_on_default_branch"` + CreatedAt string `json:"created_at"` + UpdatedAt string `json:"updated_at"` +} + +type VulnerabilityEventLocation struct { + File string `json:"file"` + Dependency VulnerabilityEventLocationDependency `json:"dependency"` +} + +type VulnerabilityEventLocationDependency struct { + Package VulnerabilityEventLocationDependencyPackage `json:"package"` + Version string `json:"version"` +} + +type VulnerabilityEventLocationDependencyPackage struct { + Name string `json:"name"` +} + +type VulnerabilityEventCVSS struct { + Vector string `json:"vector"` + Vendor string `json:"vendor"` +} + +type VulnerabilityEventIdentifier struct { + Name string `json:"name"` + ExternalID string `json:"external_id"` + ExternalType string `json:"external_type"` + URL string `json:"url"` +} + +type VulnerabilityEventIssue struct { + Title string `json:"title"` + URL string `json:"url"` + CreatedAt string `json:"created_at"` + UpdatedAt string `json:"updated_at"` +} + // EventLabel represents a label inside a webhook event. // // GitLab API docs: diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/external_status_checks.go b/vendor/gitlab.com/gitlab-org/api/client-go/external_status_checks.go index 7bfbcf05..227f17bf 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/external_status_checks.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/external_status_checks.go @@ -1,7 +1,6 @@ package gitlab import ( - "fmt" "net/http" "time" ) @@ -146,24 +145,11 @@ type StatusCheckProtectedBranch struct { // GitLab API docs: // https://docs.gitlab.com/api/status_checks/#list-status-checks-for-a-merge-request func (s *ExternalStatusChecksService) ListMergeStatusChecks(pid any, mr int64, opt *ListOptions, options ...RequestOptionFunc) ([]*MergeStatusCheck, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/merge_requests/%d/status_checks", PathEscape(project), mr) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var mscs []*MergeStatusCheck - resp, err := s.client.Do(req, &mscs) - if err != nil { - return nil, resp, err - } - - return mscs, resp, nil + return do[[]*MergeStatusCheck](s.client, + withPath("projects/%s/merge_requests/%d/status_checks", ProjectID{pid}, mr), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // SetExternalStatusCheckStatusOptions represents the available @@ -184,39 +170,21 @@ type SetExternalStatusCheckStatusOptions struct { // Gitlab API docs: // https://docs.gitlab.com/api/status_checks/#set-status-of-an-external-status-check func (s *ExternalStatusChecksService) SetExternalStatusCheckStatus(pid any, mergeRequest int64, opt *SetExternalStatusCheckStatusOptions, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/merge_requests/%d/status_check_responses", PathEscape(project), mergeRequest) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/merge_requests/%d/status_check_responses", ProjectID{pid}, mergeRequest), + withAPIOpts(opt), + withRequestOpts(options...), + ) + return resp, err } func (s *ExternalStatusChecksService) ListProjectStatusChecks(pid any, opt *ListOptions, options ...RequestOptionFunc) ([]*ProjectStatusCheck, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/external_status_checks", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var pscs []*ProjectStatusCheck - resp, err := s.client.Do(req, &pscs) - if err != nil { - return nil, resp, err - } - - return pscs, resp, nil + return do[[]*ProjectStatusCheck](s.client, + withPath("projects/%s/external_status_checks", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // CreateExternalStatusCheckOptions represents the available @@ -232,18 +200,13 @@ type CreateExternalStatusCheckOptions struct { } func (s *ExternalStatusChecksService) CreateExternalStatusCheck(pid any, opt *CreateExternalStatusCheckOptions, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/external_status_checks", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/external_status_checks", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) + return resp, err } // DeleteExternalStatusCheck deletes an external status check. @@ -252,18 +215,12 @@ func (s *ExternalStatusChecksService) CreateExternalStatusCheck(pid any, opt *Cr // Gitlab API docs: // https://docs.gitlab.com/api/status_checks/#delete-external-status-check-service func (s *ExternalStatusChecksService) DeleteExternalStatusCheck(pid any, check int64, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/external_status_checks/%d", PathEscape(project), check) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/external_status_checks/%d", ProjectID{pid}, check), + withRequestOpts(options...), + ) + return resp, err } // UpdateExternalStatusCheckOptions represents the available @@ -284,18 +241,13 @@ type UpdateExternalStatusCheckOptions struct { // Gitlab API docs: // https://docs.gitlab.com/api/status_checks/#update-external-status-check-service func (s *ExternalStatusChecksService) UpdateExternalStatusCheck(pid any, check int64, opt *UpdateExternalStatusCheckOptions, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/external_status_checks/%d", PathEscape(project), check) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/external_status_checks/%d", ProjectID{pid}, check), + withAPIOpts(opt), + withRequestOpts(options...), + ) + return resp, err } // RetryFailedStatusCheckForAMergeRequest retries the specified failed external status check. @@ -304,18 +256,12 @@ func (s *ExternalStatusChecksService) UpdateExternalStatusCheck(pid any, check i // Gitlab API docs: // https://docs.gitlab.com/api/status_checks/#retry-failed-status-check-for-a-merge-request func (s *ExternalStatusChecksService) RetryFailedStatusCheckForAMergeRequest(pid any, mergeRequest int64, externalStatusCheck int64, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/merge_requests/%d/status_checks/%d/retry", PathEscape(project), mergeRequest, externalStatusCheck) - - req, err := s.client.NewRequest(http.MethodPost, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/merge_requests/%d/status_checks/%d/retry", ProjectID{pid}, mergeRequest, externalStatusCheck), + withRequestOpts(options...), + ) + return resp, err } // ListProjectMergeRequestExternalStatusChecksOptions represents the available @@ -333,24 +279,11 @@ type ListProjectMergeRequestExternalStatusChecksOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/status_checks/#list-status-checks-for-a-merge-request func (s *ExternalStatusChecksService) ListProjectMergeRequestExternalStatusChecks(pid any, mr int64, opt *ListProjectMergeRequestExternalStatusChecksOptions, options ...RequestOptionFunc) ([]*MergeStatusCheck, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/merge_requests/%d/status_checks", PathEscape(project), mr) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var mscs []*MergeStatusCheck - resp, err := s.client.Do(req, &mscs) - if err != nil { - return nil, resp, err - } - - return mscs, resp, nil + return do[[]*MergeStatusCheck](s.client, + withPath("projects/%s/merge_requests/%d/status_checks", ProjectID{pid}, mr), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // ListProjectExternalStatusChecksOptions represents the available @@ -363,24 +296,11 @@ type ListProjectExternalStatusChecksOptions struct { } func (s *ExternalStatusChecksService) ListProjectExternalStatusChecks(pid any, opt *ListProjectExternalStatusChecksOptions, options ...RequestOptionFunc) ([]*ProjectStatusCheck, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/external_status_checks", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var pscs []*ProjectStatusCheck - resp, err := s.client.Do(req, &pscs) - if err != nil { - return nil, resp, err - } - - return pscs, resp, nil + return do[[]*ProjectStatusCheck](s.client, + withPath("projects/%s/external_status_checks", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // CreateProjectExternalStatusCheckOptions represents the available @@ -396,24 +316,12 @@ type CreateProjectExternalStatusCheckOptions struct { } func (s *ExternalStatusChecksService) CreateProjectExternalStatusCheck(pid any, opt *CreateProjectExternalStatusCheckOptions, options ...RequestOptionFunc) (*ProjectStatusCheck, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/external_status_checks", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - statusCheck := new(ProjectStatusCheck) - resp, err := s.client.Do(req, statusCheck) - if err != nil { - return nil, resp, err - } - - return statusCheck, resp, nil + return do[*ProjectStatusCheck](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/external_status_checks", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // DeleteProjectExternalStatusCheckOptions represents the available @@ -428,18 +336,13 @@ type DeleteProjectExternalStatusCheckOptions struct{} // Gitlab API docs: // https://docs.gitlab.com/api/status_checks/#delete-external-status-check-service func (s *ExternalStatusChecksService) DeleteProjectExternalStatusCheck(pid any, check int64, opt *DeleteProjectExternalStatusCheckOptions, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/external_status_checks/%d", PathEscape(project), check) - - req, err := s.client.NewRequest(http.MethodDelete, u, opt, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/external_status_checks/%d", ProjectID{pid}, check), + withAPIOpts(opt), + withRequestOpts(options...), + ) + return resp, err } // UpdateProjectExternalStatusCheckOptions represents the available @@ -459,24 +362,12 @@ type UpdateProjectExternalStatusCheckOptions struct { // Gitlab API docs: // https://docs.gitlab.com/api/status_checks/#update-external-status-check-service func (s *ExternalStatusChecksService) UpdateProjectExternalStatusCheck(pid any, check int64, opt *UpdateProjectExternalStatusCheckOptions, options ...RequestOptionFunc) (*ProjectStatusCheck, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/external_status_checks/%d", PathEscape(project), check) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - statusCheck := new(ProjectStatusCheck) - resp, err := s.client.Do(req, statusCheck) - if err != nil { - return nil, resp, err - } - - return statusCheck, resp, nil + return do[*ProjectStatusCheck](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/external_status_checks/%d", ProjectID{pid}, check), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // RetryFailedExternalStatusCheckForProjectMergeRequestOptions represents the available @@ -491,18 +382,13 @@ type RetryFailedExternalStatusCheckForProjectMergeRequestOptions struct{} // Gitlab API docs: // https://docs.gitlab.com/api/status_checks/#retry-failed-status-check-for-a-merge-request func (s *ExternalStatusChecksService) RetryFailedExternalStatusCheckForProjectMergeRequest(pid any, mergeRequest int64, externalStatusCheck int64, opt *RetryFailedExternalStatusCheckForProjectMergeRequestOptions, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/merge_requests/%d/status_checks/%d/retry", PathEscape(project), mergeRequest, externalStatusCheck) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/merge_requests/%d/status_checks/%d/retry", ProjectID{pid}, mergeRequest, externalStatusCheck), + withAPIOpts(opt), + withRequestOpts(options...), + ) + return resp, err } // SetProjectMergeRequestExternalStatusCheckStatusOptions represents the available @@ -521,16 +407,11 @@ type SetProjectMergeRequestExternalStatusCheckStatusOptions struct { // Gitlab API docs: // https://docs.gitlab.com/api/status_checks/#set-status-of-an-external-status-check func (s *ExternalStatusChecksService) SetProjectMergeRequestExternalStatusCheckStatus(pid any, mergeRequest int64, opt *SetProjectMergeRequestExternalStatusCheckStatusOptions, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/merge_requests/%d/status_check_responses", PathEscape(project), mergeRequest) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/merge_requests/%d/status_check_responses", ProjectID{pid}, mergeRequest), + withAPIOpts(opt), + withRequestOpts(options...), + ) + return resp, err } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/feature_flags.go b/vendor/gitlab.com/gitlab-org/api/client-go/feature_flags.go index d0a5d84d..9fa0d30a 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/feature_flags.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/feature_flags.go @@ -16,11 +16,7 @@ package gitlab -import ( - "fmt" - "net/http" - "net/url" -) +import "net/http" type ( // FeaturesServiceInterface defines all the API methods for the FeaturesService @@ -69,17 +65,10 @@ func (f Feature) String() string { // GitLab API docs: // https://docs.gitlab.com/api/features/#list-all-features func (s *FeaturesService) ListFeatures(options ...RequestOptionFunc) ([]*Feature, *Response, error) { - req, err := s.client.NewRequest(http.MethodGet, "features", nil, options) - if err != nil { - return nil, nil, err - } - - var f []*Feature - resp, err := s.client.Do(req, &f) - if err != nil { - return nil, resp, err - } - return f, resp, nil + return do[[]*Feature](s.client, + withPath("features"), + withRequestOpts(options...), + ) } // FeatureDefinition represents a Feature Definition. @@ -106,17 +95,10 @@ func (fd FeatureDefinition) String() string { // GitLab API docs: // https://docs.gitlab.com/api/features/#list-all-feature-definitions func (s *FeaturesService) ListFeatureDefinitions(options ...RequestOptionFunc) ([]*FeatureDefinition, *Response, error) { - req, err := s.client.NewRequest(http.MethodGet, "features/definitions", nil, options) - if err != nil { - return nil, nil, err - } - - var fd []*FeatureDefinition - resp, err := s.client.Do(req, &fd) - if err != nil { - return nil, resp, err - } - return fd, resp, nil + return do[[]*FeatureDefinition](s.client, + withPath("features/definitions"), + withRequestOpts(options...), + ) } // SetFeatureFlagOptions represents the available options for @@ -141,19 +123,12 @@ type SetFeatureFlagOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/features/#set-or-create-a-feature func (s *FeaturesService) SetFeatureFlag(name string, opt *SetFeatureFlagOptions, options ...RequestOptionFunc) (*Feature, *Response, error) { - u := fmt.Sprintf("features/%s", url.PathEscape(name)) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - f := &Feature{} - resp, err := s.client.Do(req, f) - if err != nil { - return nil, resp, err - } - return f, resp, nil + return do[*Feature](s.client, + withMethod(http.MethodPost), + withPath("features/%s", name), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // DeleteFeatureFlag deletes a feature flag. @@ -161,12 +136,10 @@ func (s *FeaturesService) SetFeatureFlag(name string, opt *SetFeatureFlagOptions // GitLab API docs: // https://docs.gitlab.com/api/features/#delete-a-feature func (s *FeaturesService) DeleteFeatureFlag(name string, options ...RequestOptionFunc) (*Response, error) { - u := fmt.Sprintf("features/%s", url.PathEscape(name)) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("features/%s", name), + withRequestOpts(options...), + ) + return resp, err } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/freeze_periods.go b/vendor/gitlab.com/gitlab-org/api/client-go/freeze_periods.go index ef12aca2..bb41500c 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/freeze_periods.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/freeze_periods.go @@ -17,7 +17,6 @@ package gitlab import ( - "fmt" "net/http" "time" ) @@ -74,24 +73,11 @@ type ListFreezePeriodsOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/freeze_periods/#list-freeze-periods func (s *FreezePeriodsService) ListFreezePeriods(pid any, opt *ListFreezePeriodsOptions, options ...RequestOptionFunc) ([]*FreezePeriod, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/freeze_periods", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var fp []*FreezePeriod - resp, err := s.client.Do(req, &fp) - if err != nil { - return nil, resp, err - } - - return fp, resp, nil + return do[[]*FreezePeriod](s.client, + withPath("projects/%s/freeze_periods", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // GetFreezePeriod gets a specific freeze period for a project. @@ -99,24 +85,10 @@ func (s *FreezePeriodsService) ListFreezePeriods(pid any, opt *ListFreezePeriods // GitLab API docs: // https://docs.gitlab.com/api/freeze_periods/#get-a-freeze-period-by-a-freeze_period_id func (s *FreezePeriodsService) GetFreezePeriod(pid any, freezePeriod int64, options ...RequestOptionFunc) (*FreezePeriod, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/freeze_periods/%d", PathEscape(project), freezePeriod) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - fp := new(FreezePeriod) - resp, err := s.client.Do(req, fp) - if err != nil { - return nil, resp, err - } - - return fp, resp, nil + return do[*FreezePeriod](s.client, + withPath("projects/%s/freeze_periods/%d", ProjectID{pid}, freezePeriod), + withRequestOpts(options...), + ) } // CreateFreezePeriodOptions represents the available CreateFreezePeriodOptions() @@ -135,24 +107,12 @@ type CreateFreezePeriodOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/freeze_periods/#create-a-freeze-period func (s *FreezePeriodsService) CreateFreezePeriodOptions(pid any, opt *CreateFreezePeriodOptions, options ...RequestOptionFunc) (*FreezePeriod, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/freeze_periods", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - fp := new(FreezePeriod) - resp, err := s.client.Do(req, fp) - if err != nil { - return nil, resp, err - } - - return fp, resp, nil + return do[*FreezePeriod](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/freeze_periods", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // UpdateFreezePeriodOptions represents the available UpdateFreezePeriodOptions() @@ -171,24 +131,12 @@ type UpdateFreezePeriodOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/freeze_periods/#update-a-freeze-period func (s *FreezePeriodsService) UpdateFreezePeriodOptions(pid any, freezePeriod int64, opt *UpdateFreezePeriodOptions, options ...RequestOptionFunc) (*FreezePeriod, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/freeze_periods/%d", PathEscape(project), freezePeriod) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - fp := new(FreezePeriod) - resp, err := s.client.Do(req, fp) - if err != nil { - return nil, resp, err - } - - return fp, resp, nil + return do[*FreezePeriod](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/freeze_periods/%d", ProjectID{pid}, freezePeriod), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // DeleteFreezePeriod removes a freeze period from a project. This is an @@ -198,16 +146,10 @@ func (s *FreezePeriodsService) UpdateFreezePeriodOptions(pid any, freezePeriod i // GitLab API docs: // https://docs.gitlab.com/api/freeze_periods/#delete-a-freeze-period func (s *FreezePeriodsService) DeleteFreezePeriod(pid any, freezePeriod int64, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/freeze_periods/%d", PathEscape(project), freezePeriod) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/freeze_periods/%d", ProjectID{pid}, freezePeriod), + withRequestOpts(options...), + ) + return resp, err } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/generic_packages.go b/vendor/gitlab.com/gitlab-org/api/client-go/generic_packages.go index aa64403f..e9771e57 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/generic_packages.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/generic_packages.go @@ -148,28 +148,12 @@ func (s *GenericPackagesService) PublishPackageFile(pid any, packageName, packag // GitLab docs: // https://docs.gitlab.com/user/packages/generic_packages/#download-a-single-file func (s *GenericPackagesService) DownloadPackageFile(pid any, packageName, packageVersion, fileName string, options ...RequestOptionFunc) ([]byte, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf( - "projects/%s/packages/generic/%s/%s/%s", - PathEscape(project), - PathEscape(packageName), - PathEscape(packageVersion), - PathEscape(fileName), + buf, resp, err := do[bytes.Buffer](s.client, + withPath("projects/%s/packages/generic/%s/%s/%s", ProjectID{pid}, packageName, packageVersion, fileName), + withRequestOpts(options...), ) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - var f bytes.Buffer - resp, err := s.client.Do(req, &f) if err != nil { return nil, resp, err } - - return f.Bytes(), resp, err + return buf.Bytes(), resp, nil } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/geo_nodes.go b/vendor/gitlab.com/gitlab-org/api/client-go/geo_nodes.go index 720731a9..670343a1 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/geo_nodes.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/geo_nodes.go @@ -16,10 +16,7 @@ package gitlab -import ( - "fmt" - "net/http" -) +import "net/http" type ( // Deprecated: will be removed in v5 of the API, use Geo Sites API instead @@ -120,18 +117,12 @@ type CreateGeoNodesOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/geo_nodes/#create-a-new-geo-node func (s *GeoNodesService) CreateGeoNode(opt *CreateGeoNodesOptions, options ...RequestOptionFunc) (*GeoNode, *Response, error) { - req, err := s.client.NewRequest(http.MethodPost, "geo_nodes", opt, options) - if err != nil { - return nil, nil, err - } - - g := new(GeoNode) - resp, err := s.client.Do(req, g) - if err != nil { - return nil, resp, err - } - - return g, resp, nil + return do[*GeoNode](s.client, + withMethod(http.MethodPost), + withPath("geo_nodes"), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // ListGeoNodesOptions represents the available ListGeoNodes() options. @@ -149,18 +140,11 @@ type ListGeoNodesOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/geo_nodes/#retrieve-configuration-about-all-geo-nodes func (s *GeoNodesService) ListGeoNodes(opt *ListGeoNodesOptions, options ...RequestOptionFunc) ([]*GeoNode, *Response, error) { - req, err := s.client.NewRequest(http.MethodGet, "geo_nodes", opt, options) - if err != nil { - return nil, nil, err - } - - var gs []*GeoNode - resp, err := s.client.Do(req, &gs) - if err != nil { - return nil, resp, err - } - - return gs, resp, nil + return do[[]*GeoNode](s.client, + withPath("geo_nodes"), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // GetGeoNode gets a specific geo node. @@ -169,20 +153,10 @@ func (s *GeoNodesService) ListGeoNodes(opt *ListGeoNodesOptions, options ...Requ // GitLab API docs: // https://docs.gitlab.com/api/geo_nodes/#retrieve-configuration-about-a-specific-geo-node func (s *GeoNodesService) GetGeoNode(id int64, options ...RequestOptionFunc) (*GeoNode, *Response, error) { - u := fmt.Sprintf("geo_nodes/%d", id) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - g := new(GeoNode) - resp, err := s.client.Do(req, g) - if err != nil { - return nil, resp, err - } - - return g, resp, nil + return do[*GeoNode](s.client, + withPath("geo_nodes/%d", id), + withRequestOpts(options...), + ) } // UpdateGeoNodesOptions represents the available EditGeoNode() options. @@ -213,20 +187,12 @@ type UpdateGeoNodesOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/geo_nodes/#edit-a-geo-node func (s *GeoNodesService) EditGeoNode(id int64, opt *UpdateGeoNodesOptions, options ...RequestOptionFunc) (*GeoNode, *Response, error) { - u := fmt.Sprintf("geo_nodes/%d", id) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - g := new(GeoNode) - resp, err := s.client.Do(req, g) - if err != nil { - return nil, resp, err - } - - return g, resp, nil + return do[*GeoNode](s.client, + withMethod(http.MethodPut), + withPath("geo_nodes/%d", id), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // DeleteGeoNode removes the Geo node. @@ -235,14 +201,12 @@ func (s *GeoNodesService) EditGeoNode(id int64, opt *UpdateGeoNodesOptions, opti // GitLab API docs: // https://docs.gitlab.com/api/geo_nodes/#delete-a-geo-node func (s *GeoNodesService) DeleteGeoNode(id int64, options ...RequestOptionFunc) (*Response, error) { - u := fmt.Sprintf("geo_nodes/%d", id) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("geo_nodes/%d", id), + withRequestOpts(options...), + ) + return resp, err } // RepairGeoNode to repair the OAuth authentication of a Geo node. @@ -251,20 +215,11 @@ func (s *GeoNodesService) DeleteGeoNode(id int64, options ...RequestOptionFunc) // GitLab API docs: // https://docs.gitlab.com/api/geo_nodes/#repair-a-geo-node func (s *GeoNodesService) RepairGeoNode(id int64, options ...RequestOptionFunc) (*GeoNode, *Response, error) { - u := fmt.Sprintf("geo_nodes/%d/repair", id) - - req, err := s.client.NewRequest(http.MethodPost, u, nil, options) - if err != nil { - return nil, nil, err - } - - g := new(GeoNode) - resp, err := s.client.Do(req, g) - if err != nil { - return nil, resp, err - } - - return g, resp, nil + return do[*GeoNode](s.client, + withMethod(http.MethodPost), + withPath("geo_nodes/%d/repair", id), + withRequestOpts(options...), + ) } // GeoNodeStatus represents the status of Geo Node. @@ -438,18 +393,10 @@ type GeoNodeStatus struct { // GitLab API docs: // https://docs.gitlab.com/api/geo_nodes/#retrieve-status-about-all-geo-nodes func (s *GeoNodesService) RetrieveStatusOfAllGeoNodes(options ...RequestOptionFunc) ([]*GeoNodeStatus, *Response, error) { - req, err := s.client.NewRequest(http.MethodGet, "geo_nodes/status", nil, options) - if err != nil { - return nil, nil, err - } - - var gnss []*GeoNodeStatus - resp, err := s.client.Do(req, &gnss) - if err != nil { - return nil, resp, err - } - - return gnss, resp, nil + return do[[]*GeoNodeStatus](s.client, + withPath("geo_nodes/status"), + withRequestOpts(options...), + ) } // RetrieveStatusOfGeoNode get the of status of a specific Geo Nodes. @@ -458,18 +405,8 @@ func (s *GeoNodesService) RetrieveStatusOfAllGeoNodes(options ...RequestOptionFu // GitLab API docs: // https://docs.gitlab.com/api/geo_nodes/#retrieve-status-about-a-specific-geo-node func (s *GeoNodesService) RetrieveStatusOfGeoNode(id int64, options ...RequestOptionFunc) (*GeoNodeStatus, *Response, error) { - u := fmt.Sprintf("geo_nodes/%d/status", id) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - gns := new(GeoNodeStatus) - resp, err := s.client.Do(req, gns) - if err != nil { - return nil, resp, err - } - - return gns, resp, nil + return do[*GeoNodeStatus](s.client, + withPath("geo_nodes/%d/status", id), + withRequestOpts(options...), + ) } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/geo_sites.go b/vendor/gitlab.com/gitlab-org/api/client-go/geo_sites.go index afce62fc..4ed4b164 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/geo_sites.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/geo_sites.go @@ -21,13 +21,45 @@ import ( type ( GeoSitesServiceInterface interface { + // CreateGeoSite creates a new Geo Site. + // + // GitLab API docs: + // https://docs.gitlab.com/api/geo_sites/#create-a-new-geo-site CreateGeoSite(*CreateGeoSitesOptions, ...RequestOptionFunc) (*GeoSite, *Response, error) + // ListGeoSites gets a list of geo sites. + // + // GitLab API docs: + // https://docs.gitlab.com/api/geo_sites/#retrieve-configuration-about-all-geo-sites ListGeoSites(*ListGeoSitesOptions, ...RequestOptionFunc) ([]*GeoSite, *Response, error) + // GetGeoSite gets a specific geo site. + // + // GitLab API docs: + // https://docs.gitlab.com/api/geo_sites/#retrieve-configuration-about-a-specific-geo-site GetGeoSite(int64, ...RequestOptionFunc) (*GeoSite, *Response, error) + // EditGeoSite updates settings of an existing Geo site. + // + // GitLab API docs: + // https://docs.gitlab.com/api/geo_sites/#edit-a-geo-site EditGeoSite(int64, *EditGeoSiteOptions, ...RequestOptionFunc) (*GeoSite, *Response, error) + // DeleteGeoSite removes the Geo site. + // + // GitLab API docs: + // https://docs.gitlab.com/api/geo_sites/#delete-a-geo-site DeleteGeoSite(int64, ...RequestOptionFunc) (*Response, error) + // RepairGeoSite to repair the OAuth authentication of a Geo site. + // + // GitLab API docs: + // https://docs.gitlab.com/api/geo_sites/#repair-a-geo-site RepairGeoSite(int64, ...RequestOptionFunc) (*GeoSite, *Response, error) + // ListStatusOfAllGeoSites get the list of status of all Geo Sites. + // + // GitLab API docs: + // https://docs.gitlab.com/api/geo_sites/#retrieve-status-about-all-geo-sites ListStatusOfAllGeoSites(*ListStatusOfAllGeoSitesOptions, ...RequestOptionFunc) ([]*GeoSiteStatus, *Response, error) + // GetStatusOfGeoSite gets the status of a specific Geo Site. + // + // GitLab API docs: + // https://docs.gitlab.com/api/geo_sites/#retrieve-status-about-a-specific-geo-site GetStatusOfGeoSite(int64, ...RequestOptionFunc) (*GeoSiteStatus, *Response, error) } @@ -97,10 +129,6 @@ type CreateGeoSitesOptions struct { MinimumReverificationInterval *int64 `url:"minimum_reverification_interval,omitempty" json:"minimum_reverification_interval,omitempty"` } -// CreateGeoSite creates a new Geo Site. -// -// GitLab API docs: -// https://docs.gitlab.com/api/geo_sites/#create-a-new-geo-site func (s *GeoSitesService) CreateGeoSite(opt *CreateGeoSitesOptions, options ...RequestOptionFunc) (*GeoSite, *Response, error) { return do[*GeoSite](s.client, withMethod(http.MethodPost), @@ -118,10 +146,6 @@ type ListGeoSitesOptions struct { ListOptions } -// ListGeoSites gets a list of geo sites. -// -// GitLab API docs: -// https://docs.gitlab.com/api/geo_sites/#retrieve-configuration-about-all-geo-sites func (s *GeoSitesService) ListGeoSites(opt *ListGeoSitesOptions, options ...RequestOptionFunc) ([]*GeoSite, *Response, error) { return do[[]*GeoSite](s.client, withPath("geo_sites"), @@ -130,10 +154,6 @@ func (s *GeoSitesService) ListGeoSites(opt *ListGeoSitesOptions, options ...Requ ) } -// GetGeoSite gets a specific geo site. -// -// GitLab API docs: -// https://docs.gitlab.com/api/geo_sites/#retrieve-configuration-about-a-specific-geo-site func (s *GeoSitesService) GetGeoSite(id int64, options ...RequestOptionFunc) (*GeoSite, *Response, error) { return do[*GeoSite](s.client, withPath("geo_sites/%d", id), @@ -160,10 +180,6 @@ type EditGeoSiteOptions struct { MinimumReverificationInterval *int64 `url:"minimum_reverification_interval,omitempty" json:"minimum_reverification_interval,omitempty"` } -// EditGeoSite updates settings of an existing Geo site. -// -// GitLab API docs: -// https://docs.gitlab.com/api/geo_sites/#edit-a-geo-site func (s *GeoSitesService) EditGeoSite(id int64, opt *EditGeoSiteOptions, options ...RequestOptionFunc) (*GeoSite, *Response, error) { return do[*GeoSite](s.client, withMethod(http.MethodPut), @@ -173,10 +189,6 @@ func (s *GeoSitesService) EditGeoSite(id int64, opt *EditGeoSiteOptions, options ) } -// DeleteGeoSite removes the Geo site. -// -// GitLab API docs: -// https://docs.gitlab.com/api/geo_sites/#delete-a-geo-site func (s *GeoSitesService) DeleteGeoSite(id int64, options ...RequestOptionFunc) (*Response, error) { _, resp, err := do[none](s.client, withMethod(http.MethodDelete), @@ -186,10 +198,6 @@ func (s *GeoSitesService) DeleteGeoSite(id int64, options ...RequestOptionFunc) return resp, err } -// RepairGeoSite to repair the OAuth authentication of a Geo site. -// -// GitLab API docs: -// https://docs.gitlab.com/api/geo_sites/#repair-a-geo-site func (s *GeoSitesService) RepairGeoSite(id int64, options ...RequestOptionFunc) (*GeoSite, *Response, error) { return do[*GeoSite](s.client, withMethod(http.MethodPost), @@ -433,10 +441,6 @@ type ListStatusOfAllGeoSitesOptions struct { ListOptions } -// ListStatusOfAllGeoSites get the list of status of all Geo Sites. -// -// GitLab API docs: -// https://docs.gitlab.com/api/geo_sites/#retrieve-status-about-all-geo-sites func (s *GeoSitesService) ListStatusOfAllGeoSites(opt *ListStatusOfAllGeoSitesOptions, options ...RequestOptionFunc) ([]*GeoSiteStatus, *Response, error) { return do[[]*GeoSiteStatus](s.client, withPath("geo_sites/status"), @@ -445,10 +449,6 @@ func (s *GeoSitesService) ListStatusOfAllGeoSites(opt *ListStatusOfAllGeoSitesOp ) } -// GetStatusOfGeoSite get the of status of a specific Geo Sites. -// -// GitLab API docs: -// https://docs.gitlab.com/api/geo_sites/#retrieve-status-about-a-specific-geo-site func (s *GeoSitesService) GetStatusOfGeoSite(id int64, options ...RequestOptionFunc) (*GeoSiteStatus, *Response, error) { return do[*GeoSiteStatus](s.client, withPath("geo_sites/%d/status", id), diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/gitlab.go b/vendor/gitlab.com/gitlab-org/api/client-go/gitlab.go index dd67b1f6..a75fa20e 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/gitlab.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/gitlab.go @@ -24,6 +24,7 @@ import ( "errors" "fmt" "io" + "log/slog" "maps" "math" "math/rand" @@ -74,6 +75,21 @@ const ( var ErrNotFound = errors.New("404 Not Found") +// URLValidationError wraps URL parsing errors with helpful context +type URLValidationError struct { + URL string + Err error + Hint string +} + +func (e *URLValidationError) Error() string { + msg := fmt.Sprintf("invalid base URL %q: %v", e.URL, e.Err) + if e.Hint != "" { + msg += fmt.Sprintf(" (hint: %s)", e.Hint) + } + return msg +} + // A Client manages communication with the GitLab API. type Client struct { // HTTP client used to communicate with the API. @@ -111,6 +127,9 @@ type Client struct { // which are used to decorate the http.Client#Transport value. interceptors []Interceptor + // urlWarningLogger is used to print URL validation warnings + urlWarningLogger *slog.Logger + // User agent used when communicating with the GitLab API. UserAgent string @@ -179,6 +198,7 @@ type Client struct { GroupMembers GroupMembersServiceInterface GroupMilestones GroupMilestonesServiceInterface GroupProtectedEnvironments GroupProtectedEnvironmentsServiceInterface + GroupProtectedBranches GroupProtectedBranchesServiceInterface GroupRelationsExport GroupRelationsExportServiceInterface GroupReleases GroupReleasesServiceInterface GroupRepositoryStorageMove GroupRepositoryStorageMoveServiceInterface @@ -255,6 +275,8 @@ type Client struct { ResourceMilestoneEvents ResourceMilestoneEventsServiceInterface ResourceStateEvents ResourceStateEventsServiceInterface ResourceWeightEvents ResourceWeightEventsServiceInterface + RunnerControllers RunnerControllersServiceInterface + RunnerControllerTokens RunnerControllerTokensServiceInterface Runners RunnersServiceInterface Search SearchServiceInterface SecureFiles SecureFilesServiceInterface @@ -377,8 +399,9 @@ func NewOAuthClient(token string, options ...ClientOptionFunc) (*Client, error) // NewAuthSourceClient returns a new GitLab API client that uses the AuthSource for authentication. func NewAuthSourceClient(as AuthSource, options ...ClientOptionFunc) (*Client, error) { c := &Client{ - UserAgent: userAgent, - authSource: as, + UserAgent: userAgent, + authSource: as, + urlWarningLogger: slog.Default(), } // Configure the HTTP client. @@ -495,6 +518,7 @@ func NewAuthSourceClient(as AuthSource, options ...ClientOptionFunc) (*Client, e c.GroupMembers = &GroupMembersService{client: c} c.GroupMilestones = &GroupMilestonesService{client: c} c.GroupProtectedEnvironments = &GroupProtectedEnvironmentsService{client: c} + c.GroupProtectedBranches = &GroupProtectedBranchesService{client: c} c.GroupRelationsExport = &GroupRelationsExportService{client: c} c.GroupReleases = &GroupReleasesService{client: c} c.GroupRepositoryStorageMove = &GroupRepositoryStorageMoveService{client: c} @@ -571,6 +595,8 @@ func NewAuthSourceClient(as AuthSource, options ...ClientOptionFunc) (*Client, e c.ResourceMilestoneEvents = &ResourceMilestoneEventsService{client: c} c.ResourceStateEvents = &ResourceStateEventsService{client: c} c.ResourceWeightEvents = &ResourceWeightEventsService{client: c} + c.RunnerControllers = &RunnerControllersService{client: c} + c.RunnerControllerTokens = &RunnerControllerTokensService{client: c} c.Runners = &RunnersService{client: c} c.Search = &SearchService{client: c} c.SecureFiles = &SecureFilesService{client: c} @@ -794,16 +820,71 @@ func (c *Client) BaseURL() *url.URL { return &u } +// validateBaseURL checks for common real-world mistakes and returns them as errors. +// Returns the parsed URL if validation succeeds. +func validateBaseURL(baseURL string) (*url.URL, error) { + if baseURL == "" { + return nil, &URLValidationError{ + URL: baseURL, + Err: errors.New("empty URL"), + Hint: `provide a valid GitLab instance URL (e.g., "https://gitlab.com")`, + } + } + + if !strings.Contains(baseURL, "://") { + return nil, &URLValidationError{ + URL: baseURL, + Err: errors.New("missing scheme"), + Hint: fmt.Sprintf(`try "https://%s"`, baseURL), + } + } + + parsedURL, err := url.Parse(baseURL) + if err != nil { + return nil, &URLValidationError{ + URL: baseURL, + Err: err, + Hint: `possible issues: + - missing hostname + - invalid characters/spaces + - invalid port (must be 1-65535) + - query parameters (?) + - fragments (#) + - invalid URL encoding`, + } + } + + if parsedURL.Scheme != "http" && parsedURL.Scheme != "https" { + return nil, &URLValidationError{ + URL: baseURL, + Err: fmt.Errorf("unsupported scheme %q", parsedURL.Scheme), + Hint: fmt.Sprintf(`GitLab API requires http or https (try "https://%s")`, parsedURL.Host), + } + } + + return parsedURL, nil +} + // setBaseURL sets the base URL for API requests to a custom endpoint. func (c *Client) setBaseURL(urlStr string) error { - // Make sure the given URL end with a slash + // Make sure the given URL ends with a slash if !strings.HasSuffix(urlStr, "/") { urlStr += "/" } - baseURL, err := url.Parse(urlStr) + // Validate and parse + baseURL, err := validateBaseURL(urlStr) if err != nil { - return err + // Log the validation warning + c.urlWarningLogger.Warn("URL validation warning", "error", err) + + // Don't return the error - just warn and continue + // Try to parse anyway as a fallback + baseURL, err = url.Parse(urlStr) + if err != nil { + // If we really can't parse it, we have to give up + return fmt.Errorf("failed to parse base URL: %w", err) + } } if !strings.HasSuffix(baseURL.Path, apiVersionPath) { @@ -882,8 +963,12 @@ func (c *Client) NewRequestToURL(method string, u *url.URL, opt any, options []R } } - // Set the request specific headers. - maps.Copy(req.Header, reqHeaders) + // Set the request specific headers if they don't yet exist. + for k, v := range reqHeaders { + if _, ok := req.Header[k]; !ok { + req.Header[k] = v + } + } return req, nil } @@ -1180,9 +1265,8 @@ func (e *ErrorResponse) Error() string { if e.Message == "" { return fmt.Sprintf("%s %s: %d", e.Response.Request.Method, url, e.Response.StatusCode) - } else { - return fmt.Sprintf("%s %s: %d %s", e.Response.Request.Method, url, e.Response.StatusCode, e.Message) } + return fmt.Sprintf("%s %s: %d %s", e.Response.Request.Method, url, e.Response.StatusCode, e.Message) } func (e *ErrorResponse) HasStatusCode(statusCode int) bool { diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/graphql.go b/vendor/gitlab.com/gitlab-org/api/client-go/graphql.go index 18fd6c9a..57a240a5 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/graphql.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/graphql.go @@ -87,7 +87,7 @@ func (g *GraphQL) Do(query GraphQLQuery, response any, options ...RequestOptionF resp, err := g.client.Do(request, response) if err != nil { // return error, details can be read from Response - if errResp, ok := err.(*ErrorResponse); ok { //nolint: errorlint + if errResp, ok := err.(*ErrorResponse); ok { //nolint:errorlint var v GenericGraphQLErrors if json.Unmarshal(errResp.Body, &v) == nil { return resp, &GraphQLResponseError{ diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/group_activity_analytics.go b/vendor/gitlab.com/gitlab-org/api/client-go/group_activity_analytics.go index ad24616b..3c5e9bea 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/group_activity_analytics.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/group_activity_analytics.go @@ -18,8 +18,21 @@ import "net/http" type ( GroupActivityAnalyticsServiceInterface interface { + // GetRecentlyCreatedIssuesCount gets the count of recently created issues for a group. + // + // GitLab API docs: + // https://docs.gitlab.com/api/group_activity_analytics/#get-count-of-recently-created-issues-for-group GetRecentlyCreatedIssuesCount(opt *GetRecentlyCreatedIssuesCountOptions, options ...RequestOptionFunc) (*IssuesCount, *Response, error) + // GetRecentlyCreatedMergeRequestsCount gets the count of recently created merge + // requests for a group. + // + // GitLab API docs: + // https://docs.gitlab.com/api/group_activity_analytics/#get-count-of-recently-created-merge-requests-for-group GetRecentlyCreatedMergeRequestsCount(opt *GetRecentlyCreatedMergeRequestsCountOptions, options ...RequestOptionFunc) (*MergeRequestsCount, *Response, error) + // GetRecentlyAddedMembersCount gets the count of recently added members to a group. + // + // GitLab API docs: + // https://docs.gitlab.com/api/group_activity_analytics/#get-count-of-members-recently-added-to-group GetRecentlyAddedMembersCount(opt *GetRecentlyAddedMembersCountOptions, options ...RequestOptionFunc) (*NewMembersCount, *Response, error) } @@ -51,10 +64,6 @@ type GetRecentlyCreatedIssuesCountOptions struct { GroupPath string `url:"group_path" json:"group_path"` } -// GetRecentlyCreatedIssuesCount gets the count of recently created issues for a group. -// -// GitLab API docs: -// https://docs.gitlab.com/api/group_activity_analytics/#get-count-of-recently-created-issues-for-group func (s *GroupActivityAnalyticsService) GetRecentlyCreatedIssuesCount(opt *GetRecentlyCreatedIssuesCountOptions, options ...RequestOptionFunc) (*IssuesCount, *Response, error) { return do[*IssuesCount](s.client, withMethod(http.MethodGet), @@ -82,11 +91,6 @@ type GetRecentlyCreatedMergeRequestsCountOptions struct { GroupPath string `url:"group_path" json:"group_path"` } -// GetRecentlyCreatedMergeRequestsCount gets the count of recently created merge -// requests for a group. -// -// GitLab API docs: -// https://docs.gitlab.com/api/group_activity_analytics/#get-count-of-recently-created-merge-requests-for-group func (s *GroupActivityAnalyticsService) GetRecentlyCreatedMergeRequestsCount(opt *GetRecentlyCreatedMergeRequestsCountOptions, options ...RequestOptionFunc) (*MergeRequestsCount, *Response, error) { return do[*MergeRequestsCount](s.client, withMethod(http.MethodGet), @@ -113,10 +117,6 @@ type GetRecentlyAddedMembersCountOptions struct { GroupPath string `url:"group_path" json:"group_path"` } -// GetRecentlyAddedMembersCount gets the count of recently added members to a group. -// -// GitLab API docs: -// https://docs.gitlab.com/api/group_activity_analytics/#get-count-of-members-recently-added-to-group func (s *GroupActivityAnalyticsService) GetRecentlyAddedMembersCount(opt *GetRecentlyAddedMembersCountOptions, options ...RequestOptionFunc) (*NewMembersCount, *Response, error) { return do[*NewMembersCount](s.client, withMethod(http.MethodGet), diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/group_badges.go b/vendor/gitlab.com/gitlab-org/api/client-go/group_badges.go index 39d639ce..614fe024 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/group_badges.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/group_badges.go @@ -16,10 +16,7 @@ package gitlab -import ( - "fmt" - "net/http" -) +import "net/http" type ( // GroupBadgesServiceInterface defines all the API methods for the GroupBadgesService @@ -80,24 +77,11 @@ type ListGroupBadgesOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/group_badges/#list-all-badges-of-a-group func (s *GroupBadgesService) ListGroupBadges(gid any, opt *ListGroupBadgesOptions, options ...RequestOptionFunc) ([]*GroupBadge, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/badges", PathEscape(group)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var gb []*GroupBadge - resp, err := s.client.Do(req, &gb) - if err != nil { - return nil, resp, err - } - - return gb, resp, nil + return do[[]*GroupBadge](s.client, + withPath("groups/%s/badges", GroupID{gid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // GetGroupBadge gets a group badge. @@ -105,24 +89,10 @@ func (s *GroupBadgesService) ListGroupBadges(gid any, opt *ListGroupBadgesOption // GitLab API docs: // https://docs.gitlab.com/api/group_badges/#get-a-badge-of-a-group func (s *GroupBadgesService) GetGroupBadge(gid any, badge int64, options ...RequestOptionFunc) (*GroupBadge, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/badges/%d", PathEscape(group), badge) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - gb := new(GroupBadge) - resp, err := s.client.Do(req, gb) - if err != nil { - return nil, resp, err - } - - return gb, resp, nil + return do[*GroupBadge](s.client, + withPath("groups/%s/badges/%d", GroupID{gid}, badge), + withRequestOpts(options...), + ) } // AddGroupBadgeOptions represents the available AddGroupBadge() options. @@ -140,24 +110,12 @@ type AddGroupBadgeOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/group_badges/#add-a-badge-to-a-group func (s *GroupBadgesService) AddGroupBadge(gid any, opt *AddGroupBadgeOptions, options ...RequestOptionFunc) (*GroupBadge, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/badges", PathEscape(group)) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - gb := new(GroupBadge) - resp, err := s.client.Do(req, gb) - if err != nil { - return nil, resp, err - } - - return gb, resp, nil + return do[*GroupBadge](s.client, + withMethod(http.MethodPost), + withPath("groups/%s/badges", GroupID{gid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // EditGroupBadgeOptions represents the available EditGroupBadge() options. @@ -175,24 +133,12 @@ type EditGroupBadgeOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/group_badges/#edit-a-badge-of-a-group func (s *GroupBadgesService) EditGroupBadge(gid any, badge int64, opt *EditGroupBadgeOptions, options ...RequestOptionFunc) (*GroupBadge, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/badges/%d", PathEscape(group), badge) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - gb := new(GroupBadge) - resp, err := s.client.Do(req, gb) - if err != nil { - return nil, resp, err - } - - return gb, resp, nil + return do[*GroupBadge](s.client, + withMethod(http.MethodPut), + withPath("groups/%s/badges/%d", GroupID{gid}, badge), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // DeleteGroupBadge removes a badge from a group. @@ -200,18 +146,12 @@ func (s *GroupBadgesService) EditGroupBadge(gid any, badge int64, opt *EditGroup // GitLab API docs: // https://docs.gitlab.com/api/group_badges/#remove-a-badge-from-a-group func (s *GroupBadgesService) DeleteGroupBadge(gid any, badge int64, options ...RequestOptionFunc) (*Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("groups/%s/badges/%d", PathEscape(group), badge) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("groups/%s/badges/%d", GroupID{gid}, badge), + withRequestOpts(options...), + ) + return resp, err } // GroupBadgePreviewOptions represents the available PreviewGroupBadge() options. @@ -230,22 +170,9 @@ type GroupBadgePreviewOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/group_badges/#preview-a-badge-from-a-group func (s *GroupBadgesService) PreviewGroupBadge(gid any, opt *GroupBadgePreviewOptions, options ...RequestOptionFunc) (*GroupBadge, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/badges/render", PathEscape(group)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - gb := new(GroupBadge) - resp, err := s.client.Do(req, &gb) - if err != nil { - return nil, resp, err - } - - return gb, resp, nil + return do[*GroupBadge](s.client, + withPath("groups/%s/badges/render", GroupID{gid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/group_boards.go b/vendor/gitlab.com/gitlab-org/api/client-go/group_boards.go index efa29350..63f0986c 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/group_boards.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/group_boards.go @@ -22,14 +22,51 @@ import ( type ( GroupIssueBoardsServiceInterface interface { + // ListGroupIssueBoards gets a list of all issue boards in a group. + // + // GitLab API docs: + // https://docs.gitlab.com/api/group_boards/#list-all-group-issue-boards-in-a-group ListGroupIssueBoards(gid any, opt *ListGroupIssueBoardsOptions, options ...RequestOptionFunc) ([]*GroupIssueBoard, *Response, error) + // CreateGroupIssueBoard creates a new issue board. + // + // GitLab API docs: + // https://docs.gitlab.com/api/group_boards/#create-a-group-issue-board CreateGroupIssueBoard(gid any, opt *CreateGroupIssueBoardOptions, options ...RequestOptionFunc) (*GroupIssueBoard, *Response, error) + // GetGroupIssueBoard gets a single issue board of a group. + // + // GitLab API docs: + // https://docs.gitlab.com/api/group_boards/#single-group-issue-board GetGroupIssueBoard(gid any, board int64, options ...RequestOptionFunc) (*GroupIssueBoard, *Response, error) + // UpdateIssueBoard updates a single issue board of a group. + // + // GitLab API docs: + // https://docs.gitlab.com/api/group_boards/#update-a-group-issue-board UpdateIssueBoard(gid any, board int64, opt *UpdateGroupIssueBoardOptions, options ...RequestOptionFunc) (*GroupIssueBoard, *Response, error) + // DeleteIssueBoard deletes a single issue board of a group. + // + // GitLab API docs: + // https://docs.gitlab.com/api/group_boards/#delete-a-group-issue-board DeleteIssueBoard(gid any, board int64, options ...RequestOptionFunc) (*Response, error) + // ListGroupIssueBoardLists gets a list of the issue board's lists. Does not include + // backlog and closed lists. + // + // GitLab API docs: https://docs.gitlab.com/api/group_boards/#list-group-issue-board-lists ListGroupIssueBoardLists(gid any, board int64, opt *ListGroupIssueBoardListsOptions, options ...RequestOptionFunc) ([]*BoardList, *Response, error) + // GetGroupIssueBoardList gets a single issue board list. + // + // GitLab API docs: + // https://docs.gitlab.com/api/group_boards/#single-group-issue-board-list GetGroupIssueBoardList(gid any, board, list int64, options ...RequestOptionFunc) (*BoardList, *Response, error) + // CreateGroupIssueBoardList creates a new issue board list. + // + // GitLab API docs: + // https://docs.gitlab.com/api/group_boards/#new-group-issue-board-list CreateGroupIssueBoardList(gid any, board int64, opt *CreateGroupIssueBoardListOptions, options ...RequestOptionFunc) (*BoardList, *Response, error) + // UpdateIssueBoardList updates the position of an existing + // group issue board list. + // + // GitLab API docs: + // https://docs.gitlab.com/api/group_boards/#edit-group-issue-board-list UpdateIssueBoardList(gid any, board, list int64, opt *UpdateGroupIssueBoardListOptions, options ...RequestOptionFunc) ([]*BoardList, *Response, error) DeleteGroupIssueBoardList(gid any, board, list int64, options ...RequestOptionFunc) (*Response, error) } @@ -72,10 +109,6 @@ type ListGroupIssueBoardsOptions struct { ListOptions } -// ListGroupIssueBoards gets a list of all issue boards in a group. -// -// GitLab API docs: -// https://docs.gitlab.com/api/group_boards/#list-all-group-issue-boards-in-a-group func (s *GroupIssueBoardsService) ListGroupIssueBoards(gid any, opt *ListGroupIssueBoardsOptions, options ...RequestOptionFunc) ([]*GroupIssueBoard, *Response, error) { return do[[]*GroupIssueBoard](s.client, withMethod(http.MethodGet), @@ -94,10 +127,6 @@ type CreateGroupIssueBoardOptions struct { Name *string `url:"name" json:"name"` } -// CreateGroupIssueBoard creates a new issue board. -// -// GitLab API docs: -// https://docs.gitlab.com/api/group_boards/#create-a-group-issue-board func (s *GroupIssueBoardsService) CreateGroupIssueBoard(gid any, opt *CreateGroupIssueBoardOptions, options ...RequestOptionFunc) (*GroupIssueBoard, *Response, error) { return do[*GroupIssueBoard](s.client, withMethod(http.MethodPost), @@ -107,10 +136,6 @@ func (s *GroupIssueBoardsService) CreateGroupIssueBoard(gid any, opt *CreateGrou ) } -// GetGroupIssueBoard gets a single issue board of a group. -// -// GitLab API docs: -// https://docs.gitlab.com/api/group_boards/#single-group-issue-board func (s *GroupIssueBoardsService) GetGroupIssueBoard(gid any, board int64, options ...RequestOptionFunc) (*GroupIssueBoard, *Response, error) { return do[*GroupIssueBoard](s.client, withMethod(http.MethodGet), @@ -131,10 +156,6 @@ type UpdateGroupIssueBoardOptions struct { Weight *int64 `url:"weight,omitempty" json:"weight,omitempty"` } -// UpdateIssueBoard updates a single issue board of a group. -// -// GitLab API docs: -// https://docs.gitlab.com/api/group_boards/#update-a-group-issue-board func (s *GroupIssueBoardsService) UpdateIssueBoard(gid any, board int64, opt *UpdateGroupIssueBoardOptions, options ...RequestOptionFunc) (*GroupIssueBoard, *Response, error) { return do[*GroupIssueBoard](s.client, withMethod(http.MethodPut), @@ -144,10 +165,6 @@ func (s *GroupIssueBoardsService) UpdateIssueBoard(gid any, board int64, opt *Up ) } -// DeleteIssueBoard delete a single issue board of a group. -// -// GitLab API docs: -// https://docs.gitlab.com/api/group_boards/#delete-a-group-issue-board func (s *GroupIssueBoardsService) DeleteIssueBoard(gid any, board int64, options ...RequestOptionFunc) (*Response, error) { _, resp, err := do[none](s.client, withMethod(http.MethodDelete), @@ -166,10 +183,6 @@ type ListGroupIssueBoardListsOptions struct { ListOptions } -// ListGroupIssueBoardLists gets a list of the issue board's lists. Does not include -// backlog and closed lists. -// -// GitLab API docs: https://docs.gitlab.com/api/group_boards/#list-group-issue-board-lists func (s *GroupIssueBoardsService) ListGroupIssueBoardLists(gid any, board int64, opt *ListGroupIssueBoardListsOptions, options ...RequestOptionFunc) ([]*BoardList, *Response, error) { return do[[]*BoardList](s.client, withMethod(http.MethodGet), @@ -179,10 +192,6 @@ func (s *GroupIssueBoardsService) ListGroupIssueBoardLists(gid any, board int64, ) } -// GetGroupIssueBoardList gets a single issue board list. -// -// GitLab API docs: -// https://docs.gitlab.com/api/group_boards/#single-group-issue-board-list func (s *GroupIssueBoardsService) GetGroupIssueBoardList(gid any, board, list int64, options ...RequestOptionFunc) (*BoardList, *Response, error) { return do[*BoardList](s.client, withMethod(http.MethodGet), @@ -200,10 +209,6 @@ type CreateGroupIssueBoardListOptions struct { LabelID *int64 `url:"label_id" json:"label_id"` } -// CreateGroupIssueBoardList creates a new issue board list. -// -// GitLab API docs: -// https://docs.gitlab.com/api/group_boards/#new-group-issue-board-list func (s *GroupIssueBoardsService) CreateGroupIssueBoardList(gid any, board int64, opt *CreateGroupIssueBoardListOptions, options ...RequestOptionFunc) (*BoardList, *Response, error) { return do[*BoardList](s.client, withMethod(http.MethodPost), @@ -222,11 +227,6 @@ type UpdateGroupIssueBoardListOptions struct { Position *int64 `url:"position" json:"position"` } -// UpdateIssueBoardList updates the position of an existing -// group issue board list. -// -// GitLab API docs: -// https://docs.gitlab.com/api/group_boards/#edit-group-issue-board-list func (s *GroupIssueBoardsService) UpdateIssueBoardList(gid any, board, list int64, opt *UpdateGroupIssueBoardListOptions, options ...RequestOptionFunc) ([]*BoardList, *Response, error) { return do[[]*BoardList](s.client, withMethod(http.MethodPut), diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/group_clusters.go b/vendor/gitlab.com/gitlab-org/api/client-go/group_clusters.go index 5ec29914..7bb5e4f9 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/group_clusters.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/group_clusters.go @@ -17,7 +17,6 @@ package gitlab import ( - "fmt" "net/http" "time" ) @@ -83,24 +82,10 @@ func (v GroupCluster) String() string { // GitLab API docs: // https://docs.gitlab.com/api/group_clusters/#list-group-clusters func (s *GroupClustersService) ListClusters(pid any, options ...RequestOptionFunc) ([]*GroupCluster, *Response, error) { - group, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/clusters", PathEscape(group)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - var pcs []*GroupCluster - resp, err := s.client.Do(req, &pcs) - if err != nil { - return nil, resp, err - } - - return pcs, resp, nil + return do[[]*GroupCluster](s.client, + withPath("groups/%s/clusters", GroupID{pid}), + withRequestOpts(options...), + ) } // GetCluster gets a cluster. @@ -109,24 +94,10 @@ func (s *GroupClustersService) ListClusters(pid any, options ...RequestOptionFun // GitLab API docs: // https://docs.gitlab.com/api/group_clusters/#get-a-single-group-cluster func (s *GroupClustersService) GetCluster(pid any, cluster int64, options ...RequestOptionFunc) (*GroupCluster, *Response, error) { - group, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/clusters/%d", PathEscape(group), cluster) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - gc := new(GroupCluster) - resp, err := s.client.Do(req, &gc) - if err != nil { - return nil, resp, err - } - - return gc, resp, nil + return do[*GroupCluster](s.client, + withPath("groups/%s/clusters/%d", GroupID{pid}, cluster), + withRequestOpts(options...), + ) } // AddGroupClusterOptions represents the available AddCluster() options. @@ -160,24 +131,12 @@ type AddGroupPlatformKubernetesOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/group_clusters/#add-existing-cluster-to-group func (s *GroupClustersService) AddCluster(pid any, opt *AddGroupClusterOptions, options ...RequestOptionFunc) (*GroupCluster, *Response, error) { - group, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/clusters/user", PathEscape(group)) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - gc := new(GroupCluster) - resp, err := s.client.Do(req, gc) - if err != nil { - return nil, resp, err - } - - return gc, resp, nil + return do[*GroupCluster](s.client, + withMethod(http.MethodPost), + withPath("groups/%s/clusters/user", GroupID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // EditGroupClusterOptions represents the available EditCluster() options. @@ -207,24 +166,12 @@ type EditGroupPlatformKubernetesOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/group_clusters/#edit-group-cluster func (s *GroupClustersService) EditCluster(pid any, cluster int64, opt *EditGroupClusterOptions, options ...RequestOptionFunc) (*GroupCluster, *Response, error) { - group, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/clusters/%d", PathEscape(group), cluster) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - gc := new(GroupCluster) - resp, err := s.client.Do(req, gc) - if err != nil { - return nil, resp, err - } - - return gc, resp, nil + return do[*GroupCluster](s.client, + withMethod(http.MethodPut), + withPath("groups/%s/clusters/%d", GroupID{pid}, cluster), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // DeleteCluster deletes an existing group cluster. @@ -233,16 +180,10 @@ func (s *GroupClustersService) EditCluster(pid any, cluster int64, opt *EditGrou // GitLab API docs: // https://docs.gitlab.com/api/group_clusters/#delete-group-cluster func (s *GroupClustersService) DeleteCluster(pid any, cluster int64, options ...RequestOptionFunc) (*Response, error) { - group, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("groups/%s/clusters/%d", PathEscape(group), cluster) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("groups/%s/clusters/%d", GroupID{pid}, cluster), + withRequestOpts(options...), + ) + return resp, err } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/group_hooks.go b/vendor/gitlab.com/gitlab-org/api/client-go/group_hooks.go index 30c8818e..05b82366 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/group_hooks.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/group_hooks.go @@ -17,7 +17,6 @@ package gitlab import ( - "fmt" "net/http" "time" ) @@ -75,23 +74,11 @@ type ListGroupHooksOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/group_webhooks/#list-group-hooks func (s *GroupsService) ListGroupHooks(gid any, opt *ListGroupHooksOptions, options ...RequestOptionFunc) ([]*GroupHook, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/hooks", PathEscape(group)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - var gh []*GroupHook - resp, err := s.client.Do(req, &gh) - if err != nil { - return nil, resp, err - } - - return gh, resp, nil + return do[[]*GroupHook](s.client, + withPath("groups/%s/hooks", GroupID{gid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // GetGroupHook gets a specific hook for a group. @@ -99,24 +86,10 @@ func (s *GroupsService) ListGroupHooks(gid any, opt *ListGroupHooksOptions, opti // GitLab API docs: // https://docs.gitlab.com/api/group_webhooks/#get-a-group-hook func (s *GroupsService) GetGroupHook(gid any, hook int64, options ...RequestOptionFunc) (*GroupHook, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/hooks/%d", PathEscape(group), hook) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - gh := new(GroupHook) - resp, err := s.client.Do(req, gh) - if err != nil { - return nil, resp, err - } - - return gh, resp, nil + return do[*GroupHook](s.client, + withPath("groups/%s/hooks/%d", GroupID{gid}, hook), + withRequestOpts(options...), + ) } // ResendGroupHookEvent resends a specific hook event. @@ -124,18 +97,12 @@ func (s *GroupsService) GetGroupHook(gid any, hook int64, options ...RequestOpti // GitLab API docs: // https://docs.gitlab.com/api/group_webhooks/#resend-group-hook-event func (s *GroupsService) ResendGroupHookEvent(gid any, hook int64, hookEventID int64, options ...RequestOptionFunc) (*Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("groups/%s/hooks/%d/events/%d/resend", PathEscape(group), hook, hookEventID) - - req, err := s.client.NewRequest(http.MethodPost, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodPost), + withPath("groups/%s/hooks/%d/events/%d/resend", GroupID{gid}, hook, hookEventID), + withRequestOpts(options...), + ) + return resp, err } // AddGroupHookOptions represents the available AddGroupHook() options. @@ -179,24 +146,12 @@ type AddGroupHookOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/group_webhooks/#add-a-group-hook func (s *GroupsService) AddGroupHook(gid any, opt *AddGroupHookOptions, options ...RequestOptionFunc) (*GroupHook, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/hooks", PathEscape(group)) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - gh := new(GroupHook) - resp, err := s.client.Do(req, gh) - if err != nil { - return nil, resp, err - } - - return gh, resp, nil + return do[*GroupHook](s.client, + withMethod(http.MethodPost), + withPath("groups/%s/hooks", GroupID{gid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // EditGroupHookOptions represents the available EditGroupHook() options. @@ -241,24 +196,12 @@ type EditGroupHookOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/group_webhooks/#edit-group-hook func (s *GroupsService) EditGroupHook(gid any, hook int64, opt *EditGroupHookOptions, options ...RequestOptionFunc) (*GroupHook, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/hooks/%d", PathEscape(group), hook) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - gh := new(GroupHook) - resp, err := s.client.Do(req, gh) - if err != nil { - return nil, resp, err - } - - return gh, resp, nil + return do[*GroupHook](s.client, + withMethod(http.MethodPut), + withPath("groups/%s/hooks/%d", GroupID{gid}, hook), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // DeleteGroupHook removes a hook from a group. This is an idempotent @@ -267,18 +210,12 @@ func (s *GroupsService) EditGroupHook(gid any, hook int64, opt *EditGroupHookOpt // GitLab API docs: // https://docs.gitlab.com/api/group_webhooks/#delete-a-group-hook func (s *GroupsService) DeleteGroupHook(gid any, hook int64, options ...RequestOptionFunc) (*Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("groups/%s/hooks/%d", PathEscape(group), hook) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("groups/%s/hooks/%d", GroupID{gid}, hook), + withRequestOpts(options...), + ) + return resp, err } // TriggerTestGroupHook triggers a test hook for a specified group. @@ -286,18 +223,12 @@ func (s *GroupsService) DeleteGroupHook(gid any, hook int64, options ...RequestO // GitLab API docs: // https://docs.gitlab.com/api/group_webhooks/#trigger-a-test-group-hook func (s *GroupsService) TriggerTestGroupHook(pid any, hook int64, trigger GroupHookTrigger, options ...RequestOptionFunc) (*Response, error) { - group, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("groups/%s/hooks/%d/test/%s", PathEscape(group), hook, trigger) - - req, err := s.client.NewRequest(http.MethodPost, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodPost), + withPath("groups/%s/hooks/%d/test/%s", GroupID{pid}, hook, NoEscape{string(trigger)}), + withRequestOpts(options...), + ) + return resp, err } // SetGroupCustomHeader creates or updates a group custom webhook header. @@ -305,18 +236,13 @@ func (s *GroupsService) TriggerTestGroupHook(pid any, hook int64, trigger GroupH // GitLab API docs: // https://docs.gitlab.com/api/group_webhooks/#set-a-custom-header func (s *GroupsService) SetGroupCustomHeader(gid any, hook int64, key string, opt *SetHookCustomHeaderOptions, options ...RequestOptionFunc) (*Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("groups/%s/hooks/%d/custom_headers/%s", PathEscape(group), hook, key) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodPut), + withPath("groups/%s/hooks/%d/custom_headers/%s", GroupID{gid}, hook, key), + withAPIOpts(opt), + withRequestOpts(options...), + ) + return resp, err } // DeleteGroupCustomHeader deletes a group custom webhook header. @@ -324,18 +250,12 @@ func (s *GroupsService) SetGroupCustomHeader(gid any, hook int64, key string, op // GitLab API docs: // https://docs.gitlab.com/api/group_webhooks/#delete-a-custom-header func (s *GroupsService) DeleteGroupCustomHeader(gid any, hook int64, key string, options ...RequestOptionFunc) (*Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("groups/%s/hooks/%d/custom_headers/%s", PathEscape(group), hook, key) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("groups/%s/hooks/%d/custom_headers/%s", GroupID{gid}, hook, key), + withRequestOpts(options...), + ) + return resp, err } // SetHookURLVariableOptions represents the available SetGroupHookURLVariable() @@ -352,18 +272,13 @@ type SetHookURLVariableOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/group_webhooks/#set-a-url-variable func (s *GroupsService) SetGroupHookURLVariable(gid any, hook int64, key string, opt *SetHookURLVariableOptions, options ...RequestOptionFunc) (*Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("groups/%s/hooks/%d/url_variables/%s", PathEscape(group), hook, key) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodPut), + withPath("groups/%s/hooks/%d/url_variables/%s", GroupID{gid}, hook, key), + withAPIOpts(opt), + withRequestOpts(options...), + ) + return resp, err } // DeleteGroupHookURLVariable sets a group hook URL variable. @@ -371,16 +286,10 @@ func (s *GroupsService) SetGroupHookURLVariable(gid any, hook int64, key string, // GitLab API docs: // https://docs.gitlab.com/api/group_webhooks/#delete-a-url-variable func (s *GroupsService) DeleteGroupHookURLVariable(gid any, hook int64, key string, options ...RequestOptionFunc) (*Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("groups/%s/hooks/%d/url_variables/%s", PathEscape(group), hook, key) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("groups/%s/hooks/%d/url_variables/%s", GroupID{gid}, hook, key), + withRequestOpts(options...), + ) + return resp, err } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/group_import_export.go b/vendor/gitlab.com/gitlab-org/api/client-go/group_import_export.go index 77b74f01..5b54c2fc 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/group_import_export.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/group_import_export.go @@ -18,7 +18,7 @@ package gitlab import ( "bytes" - "fmt" + "errors" "io" "mime/multipart" "net/http" @@ -64,23 +64,14 @@ func (s *GroupImportExportService) ScheduleExport(gid any, options ...RequestOpt // GitLab API docs: // https://docs.gitlab.com/api/group_import_export/#export-download func (s *GroupImportExportService) ExportDownload(gid any, options ...RequestOptionFunc) (*bytes.Reader, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - - req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("groups/%s/export/download", group), nil, options) - if err != nil { - return nil, nil, err - } - - exportDownload := new(bytes.Buffer) - resp, err := s.client.Do(req, exportDownload) + buf, resp, err := do[bytes.Buffer](s.client, + withPath("groups/%s/export/download", GroupID{gid}), + withRequestOpts(options...), + ) if err != nil { return nil, resp, err } - - return bytes.NewReader(exportDownload.Bytes()), resp, err + return bytes.NewReader(buf.Bytes()), resp, nil } // GroupImportFileOptions represents the available ImportFile() options. @@ -101,13 +92,13 @@ type GroupImportFileOptions struct { func (s *GroupImportExportService) ImportFile(opt *GroupImportFileOptions, options ...RequestOptionFunc) (*Response, error) { // First check if we got all required options. if opt.Name == nil || *opt.Name == "" { - return nil, fmt.Errorf("missing required option: Name") + return nil, errors.New("missing required option: Name") } if opt.Path == nil || *opt.Path == "" { - return nil, fmt.Errorf("missing required option: Path") + return nil, errors.New("missing required option: Path") } if opt.File == nil || *opt.File == "" { - return nil, fmt.Errorf("missing required option: File") + return nil, errors.New("missing required option: File") } f, err := os.Open(*opt.File) diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/group_integrations.go b/vendor/gitlab.com/gitlab-org/api/client-go/group_integrations.go new file mode 100644 index 00000000..bf3f87e6 --- /dev/null +++ b/vendor/gitlab.com/gitlab-org/api/client-go/group_integrations.go @@ -0,0 +1,184 @@ +package gitlab + +import ( + "net/http" + "time" +) + +// GroupMattermostIntegration represents a Mattermost integration for a group. +// +// GitLab API docs: +// https://docs.gitlab.com/api/group_integrations/#mattermost-notifications +type GroupMattermostIntegration struct { + Integration + NotifyOnlyBrokenPipelines bool `json:"notify_only_broken_pipelines"` + BranchesToBeNotified string `json:"branches_to_be_notified"` + LabelsToBeNotified string `json:"labels_to_be_notified"` + LabelsToBeNotifiedBehavior string `json:"labels_to_be_notified_behavior"` + NotifyOnlyDefaultBranch bool `json:"notify_only_default_branch"` + Properties *GroupMattermostIntegrationProperties `json:"properties"` +} + +type GroupMattermostIntegrationProperties struct { + WebHook string `json:"webhook"` + Username string `json:"username"` + Channel string `json:"channel"` + PushChannel string `json:"push_channel"` + IssueChannel string `json:"issue_channel"` + ConfidentialIssueChannel string `json:"confidential_issue_channel"` + MergeRequestChannel string `json:"merge_request_channel"` + NoteChannel string `json:"note_channel"` + ConfidentialNoteChannel string `json:"confidential_note_channel"` + TagPushChannel string `json:"tag_push_channel"` + PipelineChannel string `json:"pipeline_channel"` + WikiPageChannel string `json:"wiki_page_channel"` + DeploymentChannel string `json:"deployment_channel"` + AlertChannel string `json:"alert_channel"` + VulnerabilityChannel string `json:"vulnerability_channel"` +} + +// GroupMattermostIntegrationOptions represents the available options for +// creating or updating a Mattermost integration for a group. +// +// GitLab API docs: +// https://docs.gitlab.com/api/group_integrations/#mattermost-notifications +type GroupMattermostIntegrationOptions struct { + WebHook *string `url:"webhook,omitempty" json:"webhook,omitempty"` + Username *string `url:"username,omitempty" json:"username,omitempty"` + Channel *string `url:"channel,omitempty" json:"channel,omitempty"` + NotifyOnlyBrokenPipelines *bool `url:"notify_only_broken_pipelines,omitempty" json:"notify_only_broken_pipelines,omitempty"` + BranchesToBeNotified *string `url:"branches_to_be_notified,omitempty" json:"branches_to_be_notified,omitempty"` + PushEvents *bool `url:"push_events,omitempty" json:"push_events,omitempty"` + IssuesEvents *bool `url:"issues_events,omitempty" json:"issues_events,omitempty"` + ConfidentialIssuesEvents *bool `url:"confidential_issues_events,omitempty" json:"confidential_issues_events,omitempty"` + MergeRequestsEvents *bool `url:"merge_requests_events,omitempty" json:"merge_requests_events,omitempty"` + TagPushEvents *bool `url:"tag_push_events,omitempty" json:"tag_push_events,omitempty"` + NoteEvents *bool `url:"note_events,omitempty" json:"note_events,omitempty"` + ConfidentialNoteEvents *bool `url:"confidential_note_events,omitempty" json:"confidential_note_events,omitempty"` + PipelineEvents *bool `url:"pipeline_events,omitempty" json:"pipeline_events,omitempty"` + WikiPageEvents *bool `url:"wiki_page_events,omitempty" json:"wiki_page_events,omitempty"` + DeploymentEvents *bool `url:"deployment_events,omitempty" json:"deployment_events,omitempty"` + AlertEvents *bool `url:"alert_events,omitempty" json:"alert_events,omitempty"` + VulnerabilityEvents *bool `url:"vulnerability_events,omitempty" json:"vulnerability_events,omitempty"` + PushChannel *string `url:"push_channel,omitempty" json:"push_channel,omitempty"` + IssueChannel *string `url:"issue_channel,omitempty" json:"issue_channel,omitempty"` + ConfidentialIssueChannel *string `url:"confidential_issue_channel,omitempty" json:"confidential_issue_channel,omitempty"` + MergeRequestChannel *string `url:"merge_request_channel,omitempty" json:"merge_request_channel,omitempty"` + NoteChannel *string `url:"note_channel,omitempty" json:"note_channel,omitempty"` + ConfidentialNoteChannel *string `url:"confidential_note_channel,omitempty" json:"confidential_note_channel,omitempty"` + TagPushChannel *string `url:"tag_push_channel,omitempty" json:"tag_push_channel,omitempty"` + PipelineChannel *string `url:"pipeline_channel,omitempty" json:"pipeline_channel,omitempty"` + WikiPageChannel *string `url:"wiki_page_channel,omitempty" json:"wiki_page_channel,omitempty"` + DeploymentChannel *string `url:"deployment_channel,omitempty" json:"deployment_channel,omitempty"` + AlertChannel *string `url:"alert_channel,omitempty" json:"alert_channel,omitempty"` + VulnerabilityChannel *string `url:"vulnerability_channel,omitempty" json:"vulnerability_channel,omitempty"` + LabelsToBeNotified *string `url:"labels_to_be_notified,omitempty" json:"labels_to_be_notified,omitempty"` + LabelsToBeNotifiedBehavior *string `url:"labels_to_be_notified_behavior,omitempty" json:"labels_to_be_notified_behavior,omitempty"` + NotifyOnlyDefaultBranch *bool `url:"notify_only_default_branch,omitempty" json:"notify_only_default_branch,omitempty"` + UseInheritedSettings *bool `url:"use_inherited_settings,omitempty" json:"use_inherited_settings,omitempty"` +} + +// GetGroupMattermostIntegration retrieves the Mattermost integration for a group. +// +// GitLab API docs: +// https://docs.gitlab.com/api/group_integrations/#mattermost-notifications +func (s *IntegrationsService) GetGroupMattermostIntegration(gid any, options ...RequestOptionFunc) (*GroupMattermostIntegration, *Response, error) { + return do[*GroupMattermostIntegration]( + s.client, + withPath("groups/%s/integrations/mattermost", GroupID{gid}), + withMethod(http.MethodGet), + withRequestOpts(options...), + ) +} + +// SetGroupMattermostIntegration creates or updates the Mattermost integration for a group. +// +// GitLab API docs: +// https://docs.gitlab.com/api/group_integrations/#mattermost-notifications +func (s *IntegrationsService) SetGroupMattermostIntegration(gid any, opt *GroupMattermostIntegrationOptions, options ...RequestOptionFunc) (*GroupMattermostIntegration, *Response, error) { + return do[*GroupMattermostIntegration]( + s.client, + withPath("groups/%s/integrations/mattermost", GroupID{gid}), + withMethod(http.MethodPut), + withAPIOpts(opt), + withRequestOpts(options...), + ) +} + +// DeleteGroupMattermostIntegration removes the Mattermost integration from a group. +// +// GitLab API docs: +// https://docs.gitlab.com/api/group_integrations/#mattermost-notifications +func (s *IntegrationsService) DeleteGroupMattermostIntegration(gid any, options ...RequestOptionFunc) (*Response, error) { + _, resp, err := do[none]( + s.client, + withPath("groups/%s/integrations/mattermost", GroupID{gid}), + withMethod(http.MethodDelete), + withRequestOpts(options...), + ) + return resp, err +} + +// GroupMattermostSlashCommandsIntegration represents a Mattermost slash commands integration for a group. +// +// GitLab API docs: +// https://docs.gitlab.com/api/group_integrations/#mattermost-slash-commands +type GroupMattermostSlashCommandsIntegration struct { + ID int `json:"id"` + Title string `json:"title"` + Slug string `json:"slug"` + CreatedAt *time.Time `json:"created_at"` + UpdatedAt *time.Time `json:"updated_at"` + Token string `json:"token"` +} + +// GroupMattermostSlashCommandsIntegrationOptions represents the available options for +// creating or updating a Mattermost slash commands integration for a group. +// +// GitLab API docs: +// https://docs.gitlab.com/api/group_integrations/#mattermost-slash-commands +type GroupMattermostSlashCommandsIntegrationOptions struct { + Token *string `url:"token,omitempty" json:"token,omitempty"` + UseInheritedSettings *bool `url:"use_inherited_settings,omitempty" json:"use_inherited_settings,omitempty"` +} + +// GetGroupMattermostSlashCommandsIntegration retrieves the Mattermost slash commands integration for a group. +// +// GitLab API docs: +// https://docs.gitlab.com/api/group_integrations/#mattermost-slash-commands +func (s *IntegrationsService) GetGroupMattermostSlashCommandsIntegration(gid any, options ...RequestOptionFunc) (*GroupMattermostSlashCommandsIntegration, *Response, error) { + return do[*GroupMattermostSlashCommandsIntegration]( + s.client, + withPath("groups/%s/integrations/mattermost-slash-commands", GroupID{gid}), + withMethod(http.MethodGet), + withRequestOpts(options...), + ) +} + +// SetGroupMattermostSlashCommandsIntegration creates or updates the Mattermost slash commands integration for a group. +// +// GitLab API docs: +// https://docs.gitlab.com/api/group_integrations/#mattermost-slash-commands +func (s *IntegrationsService) SetGroupMattermostSlashCommandsIntegration(gid any, opt *GroupMattermostSlashCommandsIntegrationOptions, options ...RequestOptionFunc) (*GroupMattermostSlashCommandsIntegration, *Response, error) { + return do[*GroupMattermostSlashCommandsIntegration]( + s.client, + withPath("groups/%s/integrations/mattermost-slash-commands", GroupID{gid}), + withMethod(http.MethodPut), + withAPIOpts(opt), + withRequestOpts(options...), + ) +} + +// DeleteGroupMattermostSlashCommandsIntegration removes the Mattermost slash commands integration from a group. +// +// GitLab API docs: +// https://docs.gitlab.com/api/group_integrations/#mattermost-slash-commands +func (s *IntegrationsService) DeleteGroupMattermostSlashCommandsIntegration(gid any, options ...RequestOptionFunc) (*Response, error) { + _, resp, err := do[none]( + s.client, + withPath("groups/%s/integrations/mattermost-slash-commands", GroupID{gid}), + withMethod(http.MethodDelete), + withRequestOpts(options...), + ) + return resp, err +} diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/group_iterations.go b/vendor/gitlab.com/gitlab-org/api/client-go/group_iterations.go index 7f7b84a2..2b14b1bd 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/group_iterations.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/group_iterations.go @@ -16,11 +16,7 @@ package gitlab -import ( - "fmt" - "net/http" - "time" -) +import "time" type ( GroupIterationsServiceInterface interface { @@ -77,22 +73,9 @@ type ListGroupIterationsOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/group_iterations/#list-group-iterations func (s *GroupIterationsService) ListGroupIterations(gid any, opt *ListGroupIterationsOptions, options ...RequestOptionFunc) ([]*GroupIteration, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/iterations", PathEscape(group)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var gis []*GroupIteration - resp, err := s.client.Do(req, &gis) - if err != nil { - return nil, nil, err - } - - return gis, resp, nil + return do[[]*GroupIteration](s.client, + withPath("groups/%s/iterations", GroupID{gid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/group_labels.go b/vendor/gitlab.com/gitlab-org/api/client-go/group_labels.go index 44118489..838acda6 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/group_labels.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/group_labels.go @@ -16,10 +16,7 @@ package gitlab -import ( - "fmt" - "net/http" -) +import "net/http" type ( GroupLabelsServiceInterface interface { @@ -69,24 +66,11 @@ type ListGroupLabelsOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/group_labels/#list-group-labels func (s *GroupLabelsService) ListGroupLabels(gid any, opt *ListGroupLabelsOptions, options ...RequestOptionFunc) ([]*GroupLabel, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/labels", PathEscape(group)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var l []*GroupLabel - resp, err := s.client.Do(req, &l) - if err != nil { - return nil, resp, err - } - - return l, resp, nil + return do[[]*GroupLabel](s.client, + withPath("groups/%s/labels", GroupID{gid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // GetGroupLabel get a single label for a given group. @@ -94,28 +78,10 @@ func (s *GroupLabelsService) ListGroupLabels(gid any, opt *ListGroupLabelsOption // GitLab API docs: // https://docs.gitlab.com/api/group_labels/#get-a-single-group-label func (s *GroupLabelsService) GetGroupLabel(gid any, lid any, options ...RequestOptionFunc) (*GroupLabel, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - label, err := parseID(lid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/labels/%s", PathEscape(group), PathEscape(label)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - var l *GroupLabel - resp, err := s.client.Do(req, &l) - if err != nil { - return nil, resp, err - } - - return l, resp, nil + return do[*GroupLabel](s.client, + withPath("groups/%s/labels/%s", GroupID{gid}, LabelID{lid}), + withRequestOpts(options...), + ) } // CreateGroupLabelOptions represents the available CreateGroupLabel() options. @@ -135,24 +101,12 @@ type CreateGroupLabelOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/group_labels/#create-a-new-group-label func (s *GroupLabelsService) CreateGroupLabel(gid any, opt *CreateGroupLabelOptions, options ...RequestOptionFunc) (*GroupLabel, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/labels", PathEscape(group)) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - l := new(GroupLabel) - resp, err := s.client.Do(req, l) - if err != nil { - return nil, resp, err - } - - return l, resp, nil + return do[*GroupLabel](s.client, + withMethod(http.MethodPost), + withPath("groups/%s/labels", GroupID{gid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // DeleteGroupLabelOptions represents the available DeleteGroupLabel() options. @@ -168,26 +122,21 @@ type DeleteGroupLabelOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/group_labels/#delete-a-group-label func (s *GroupLabelsService) DeleteGroupLabel(gid any, lid any, opt *DeleteGroupLabelOptions, options ...RequestOptionFunc) (*Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("groups/%s/labels", PathEscape(group)) + reqOpts := make([]doOption, 0, 4) + reqOpts = append(reqOpts, + withMethod(http.MethodDelete), + withAPIOpts(opt), + withRequestOpts(options...), + ) if lid != nil { - label, err := parseID(lid) - if err != nil { - return nil, err - } - u = fmt.Sprintf("groups/%s/labels/%s", PathEscape(group), PathEscape(label)) - } - - req, err := s.client.NewRequest(http.MethodDelete, u, opt, options) - if err != nil { - return nil, err + reqOpts = append(reqOpts, withPath("groups/%s/labels/%s", GroupID{gid}, LabelID{lid})) + } else { + reqOpts = append(reqOpts, withPath("groups/%s/labels", GroupID{gid})) } - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, reqOpts...) + return resp, err } // UpdateGroupLabelOptions represents the available UpdateGroupLabel() options. @@ -208,32 +157,20 @@ type UpdateGroupLabelOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/group_labels/#update-a-group-label func (s *GroupLabelsService) UpdateGroupLabel(gid any, lid any, opt *UpdateGroupLabelOptions, options ...RequestOptionFunc) (*GroupLabel, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/labels", PathEscape(group)) + reqOpts := make([]doOption, 0, 4) + reqOpts = append(reqOpts, + withMethod(http.MethodPut), + withAPIOpts(opt), + withRequestOpts(options...), + ) if lid != nil { - label, err := parseID(lid) - if err != nil { - return nil, nil, err - } - u = fmt.Sprintf("groups/%s/labels/%s", PathEscape(group), PathEscape(label)) - } - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - l := new(GroupLabel) - resp, err := s.client.Do(req, l) - if err != nil { - return nil, resp, err + reqOpts = append(reqOpts, withPath("groups/%s/labels/%s", GroupID{gid}, LabelID{lid})) + } else { + reqOpts = append(reqOpts, withPath("groups/%s/labels", GroupID{gid})) } - return l, resp, nil + return do[*GroupLabel](s.client, reqOpts...) } // SubscribeToGroupLabel subscribes the authenticated user to a label to receive @@ -243,28 +180,11 @@ func (s *GroupLabelsService) UpdateGroupLabel(gid any, lid any, opt *UpdateGroup // GitLab API docs: // https://docs.gitlab.com/api/group_labels/#subscribe-to-a-group-label func (s *GroupLabelsService) SubscribeToGroupLabel(gid any, lid any, options ...RequestOptionFunc) (*GroupLabel, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - label, err := parseID(lid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/labels/%s/subscribe", PathEscape(group), PathEscape(label)) - - req, err := s.client.NewRequest(http.MethodPost, u, nil, options) - if err != nil { - return nil, nil, err - } - - l := new(GroupLabel) - resp, err := s.client.Do(req, l) - if err != nil { - return nil, resp, err - } - - return l, resp, nil + return do[*GroupLabel](s.client, + withMethod(http.MethodPost), + withPath("groups/%s/labels/%s/subscribe", GroupID{gid}, LabelID{lid}), + withRequestOpts(options...), + ) } // UnsubscribeFromGroupLabel unsubscribes the authenticated user from a label to not @@ -274,20 +194,10 @@ func (s *GroupLabelsService) SubscribeToGroupLabel(gid any, lid any, options ... // GitLab API docs: // https://docs.gitlab.com/api/group_labels/#unsubscribe-from-a-group-label func (s *GroupLabelsService) UnsubscribeFromGroupLabel(gid any, lid any, options ...RequestOptionFunc) (*Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, err - } - label, err := parseID(lid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("groups/%s/labels/%s/unsubscribe", PathEscape(group), PathEscape(label)) - - req, err := s.client.NewRequest(http.MethodPost, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodPost), + withPath("groups/%s/labels/%s/unsubscribe", GroupID{gid}, LabelID{lid}), + withRequestOpts(options...), + ) + return resp, err } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/group_markdown_uploads.go b/vendor/gitlab.com/gitlab-org/api/client-go/group_markdown_uploads.go index c15434c1..6d12350a 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/group_markdown_uploads.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/group_markdown_uploads.go @@ -22,10 +22,32 @@ import ( type ( GroupMarkdownUploadsServiceInterface interface { + // ListGroupMarkdownUploads gets all markdown uploads for a group. + // + // GitLab API Docs: + // https://docs.gitlab.com/api/group_markdown_uploads/#list-uploads ListGroupMarkdownUploads(gid any, opt *ListMarkdownUploadsOptions, options ...RequestOptionFunc) ([]*GroupMarkdownUpload, *Response, error) + // DownloadGroupMarkdownUploadByID downloads a specific upload by ID. + // + // GitLab API Docs: + // https://docs.gitlab.com/api/group_markdown_uploads/#download-an-uploaded-file-by-id DownloadGroupMarkdownUploadByID(gid any, uploadID int64, options ...RequestOptionFunc) (io.Reader, *Response, error) + // DownloadGroupMarkdownUploadBySecretAndFilename downloads a specific upload + // by secret and filename. + // + // GitLab API Docs: + // https://docs.gitlab.com/api/group_markdown_uploads/#download-an-uploaded-file-by-secret-and-filename DownloadGroupMarkdownUploadBySecretAndFilename(gid any, secret string, filename string, options ...RequestOptionFunc) (io.Reader, *Response, error) + // DeleteGroupMarkdownUploadByID deletes an upload by ID. + // + // GitLab API Docs: + // https://docs.gitlab.com/api/group_markdown_uploads/#delete-an-uploaded-file-by-id DeleteGroupMarkdownUploadByID(gid any, uploadID int64, options ...RequestOptionFunc) (*Response, error) + // DeleteGroupMarkdownUploadBySecretAndFilename deletes an upload + // by secret and filename. + // + // GitLab API Docs: + // https://docs.gitlab.com/api/group_markdown_uploads/#delete-an-uploaded-file-by-secret-and-filename DeleteGroupMarkdownUploadBySecretAndFilename(gid any, secret string, filename string, options ...RequestOptionFunc) (*Response, error) } @@ -46,18 +68,10 @@ type ( GroupMarkdownUpload = MarkdownUpload ) -// ListGroupMarkdownUploads gets all markdown uploads for a group. -// -// GitLab API Docs: -// https://docs.gitlab.com/api/group_markdown_uploads/#list-uploads func (s *GroupMarkdownUploadsService) ListGroupMarkdownUploads(gid any, opt *ListMarkdownUploadsOptions, options ...RequestOptionFunc) ([]*GroupMarkdownUpload, *Response, error) { return listMarkdownUploads[GroupMarkdownUpload](s.client, GroupResource, GroupID{gid}, opt, options) } -// DownloadGroupMarkdownUploadByID downloads a specific upload by ID. -// -// GitLab API Docs: -// https://docs.gitlab.com/api/group_markdown_uploads/#download-an-uploaded-file-by-id func (s *GroupMarkdownUploadsService) DownloadGroupMarkdownUploadByID(gid any, uploadID int64, options ...RequestOptionFunc) (io.Reader, *Response, error) { buffer, resp, err := downloadMarkdownUploadByID(s.client, GroupResource, GroupID{gid}, uploadID, options) if err != nil { @@ -66,11 +80,6 @@ func (s *GroupMarkdownUploadsService) DownloadGroupMarkdownUploadByID(gid any, u return buffer, resp, nil } -// DownloadGroupMarkdownUploadBySecretAndFilename downloads a specific upload -// by secret and filename. -// -// GitLab API Docs: -// https://docs.gitlab.com/api/group_markdown_uploads/#download-an-uploaded-file-by-secret-and-filename func (s *GroupMarkdownUploadsService) DownloadGroupMarkdownUploadBySecretAndFilename(gid any, secret string, filename string, options ...RequestOptionFunc) (io.Reader, *Response, error) { buffer, resp, err := downloadMarkdownUploadBySecretAndFilename(s.client, GroupResource, GroupID{gid}, secret, filename, options) if err != nil { @@ -79,19 +88,10 @@ func (s *GroupMarkdownUploadsService) DownloadGroupMarkdownUploadBySecretAndFile return buffer, resp, nil } -// DeleteGroupMarkdownUploadByID deletes an upload by ID. -// -// GitLab API Docs: -// https://docs.gitlab.com/api/group_markdown_uploads/#delete-an-uploaded-file-by-id func (s *GroupMarkdownUploadsService) DeleteGroupMarkdownUploadByID(gid any, uploadID int64, options ...RequestOptionFunc) (*Response, error) { return deleteMarkdownUploadByID(s.client, GroupResource, GroupID{gid}, uploadID, options) } -// DeleteGroupMarkdownUploadBySecretAndFilename deletes an upload -// by secret and filename. -// -// GitLab API Docs: -// https://docs.gitlab.com/api/group_markdown_uploads/#delete-an-uploaded-file-by-secret-and-filename func (s *GroupMarkdownUploadsService) DeleteGroupMarkdownUploadBySecretAndFilename(gid any, secret string, filename string, options ...RequestOptionFunc) (*Response, error) { return deleteMarkdownUploadBySecretAndFilename(s.client, GroupResource, GroupID{gid}, secret, filename, options) } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/group_members.go b/vendor/gitlab.com/gitlab-org/api/client-go/group_members.go index a6c7653f..c5ab2003 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/group_members.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/group_members.go @@ -23,12 +23,41 @@ import ( type ( GroupMembersServiceInterface interface { + // GetGroupMember gets a member of a group. + // + // GitLab API docs: + // https://docs.gitlab.com/api/members/#get-a-member-of-a-group-or-project GetGroupMember(gid any, user int64, options ...RequestOptionFunc) (*GroupMember, *Response, error) + // GetInheritedGroupMember gets a member of a group or project, including + // inherited and invited members + // + // GitLab API docs: + // https://docs.gitlab.com/api/members/#get-a-member-of-a-group-or-project-including-inherited-and-invited-members GetInheritedGroupMember(gid any, user int64, options ...RequestOptionFunc) (*GroupMember, *Response, error) + // AddGroupMember adds a user to the list of group members. + // + // GitLab API docs: + // https://docs.gitlab.com/api/members/#add-a-member-to-a-group-or-project AddGroupMember(gid any, opt *AddGroupMemberOptions, options ...RequestOptionFunc) (*GroupMember, *Response, error) + // ShareWithGroup shares a group with the group. + // + // GitLab API docs: + // https://docs.gitlab.com/api/groups/#create-a-link-to-share-a-group-with-another-group ShareWithGroup(gid any, opt *ShareWithGroupOptions, options ...RequestOptionFunc) (*Group, *Response, error) + // DeleteShareWithGroup allows to unshare a group from a group. + // + // GitLab API docs: + // https://docs.gitlab.com/api/groups/#delete-the-link-that-shares-a-group-with-another-group DeleteShareWithGroup(gid any, groupID int64, options ...RequestOptionFunc) (*Response, error) + // EditGroupMember updates a member of a group. + // + // GitLab API docs: + // https://docs.gitlab.com/api/members/#edit-a-member-of-a-group-or-project EditGroupMember(gid any, user int64, opt *EditGroupMemberOptions, options ...RequestOptionFunc) (*GroupMember, *Response, error) + // RemoveGroupMember removes user from user team. + // + // GitLab API docs: + // https://docs.gitlab.com/api/members/#remove-a-member-from-a-group-or-project RemoveGroupMember(gid any, user int64, opt *RemoveGroupMemberOptions, options ...RequestOptionFunc) (*Response, error) } @@ -158,10 +187,6 @@ type AddGroupMemberOptions struct { MemberRoleID *int64 `url:"member_role_id,omitempty" json:"member_role_id,omitempty"` } -// GetGroupMember gets a member of a group. -// -// GitLab API docs: -// https://docs.gitlab.com/api/members/#get-a-member-of-a-group-or-project func (s *GroupMembersService) GetGroupMember(gid any, user int64, options ...RequestOptionFunc) (*GroupMember, *Response, error) { return do[*GroupMember](s.client, withPath("groups/%s/members/%d", GroupID{gid}, user), @@ -169,11 +194,6 @@ func (s *GroupMembersService) GetGroupMember(gid any, user int64, options ...Req ) } -// GetInheritedGroupMember get a member of a group or project, including -// inherited and invited members -// -// GitLab API docs: -// https://docs.gitlab.com/api/members/#get-a-member-of-a-group-or-project-including-inherited-and-invited-members func (s *GroupMembersService) GetInheritedGroupMember(gid any, user int64, options ...RequestOptionFunc) (*GroupMember, *Response, error) { return do[*GroupMember](s.client, withPath("groups/%s/members/all/%d", GroupID{gid}, user), @@ -240,10 +260,6 @@ func (s *GroupsService) RemoveBillableGroupMember(gid any, user int64, options . return resp, err } -// AddGroupMember adds a user to the list of group members. -// -// GitLab API docs: -// https://docs.gitlab.com/api/members/#add-a-member-to-a-group-or-project func (s *GroupMembersService) AddGroupMember(gid any, opt *AddGroupMemberOptions, options ...RequestOptionFunc) (*GroupMember, *Response, error) { return do[*GroupMember](s.client, withMethod(http.MethodPost), @@ -253,10 +269,6 @@ func (s *GroupMembersService) AddGroupMember(gid any, opt *AddGroupMemberOptions ) } -// ShareWithGroup shares a group with the group. -// -// GitLab API docs: -// https://docs.gitlab.com/api/groups/#create-a-link-to-share-a-group-with-another-group func (s *GroupMembersService) ShareWithGroup(gid any, opt *ShareWithGroupOptions, options ...RequestOptionFunc) (*Group, *Response, error) { return do[*Group](s.client, withMethod(http.MethodPost), @@ -266,10 +278,6 @@ func (s *GroupMembersService) ShareWithGroup(gid any, opt *ShareWithGroupOptions ) } -// DeleteShareWithGroup allows to unshare a group from a group. -// -// GitLab API docs: -// https://docs.gitlab.com/api/groups/#delete-the-link-that-shares-a-group-with-another-group func (s *GroupMembersService) DeleteShareWithGroup(gid any, groupID int64, options ...RequestOptionFunc) (*Response, error) { _, resp, err := do[none](s.client, withMethod(http.MethodDelete), @@ -290,10 +298,6 @@ type EditGroupMemberOptions struct { MemberRoleID *int64 `url:"member_role_id,omitempty" json:"member_role_id,omitempty"` } -// EditGroupMember updates a member of a group. -// -// GitLab API docs: -// https://docs.gitlab.com/api/members/#edit-a-member-of-a-group-or-project func (s *GroupMembersService) EditGroupMember(gid any, user int64, opt *EditGroupMemberOptions, options ...RequestOptionFunc) (*GroupMember, *Response, error) { return do[*GroupMember](s.client, withMethod(http.MethodPut), @@ -312,10 +316,6 @@ type RemoveGroupMemberOptions struct { UnassignIssuables *bool `url:"unassign_issuables,omitempty" json:"unassign_issuables,omitempty"` } -// RemoveGroupMember removes user from user team. -// -// GitLab API docs: -// https://docs.gitlab.com/api/members/#remove-a-member-from-a-group-or-project func (s *GroupMembersService) RemoveGroupMember(gid any, user int64, opt *RemoveGroupMemberOptions, options ...RequestOptionFunc) (*Response, error) { _, resp, err := do[none](s.client, withMethod(http.MethodDelete), diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/group_milestones.go b/vendor/gitlab.com/gitlab-org/api/client-go/group_milestones.go index 2a687ab1..0607e253 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/group_milestones.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/group_milestones.go @@ -17,7 +17,6 @@ package gitlab import ( - "fmt" "net/http" "time" ) @@ -95,24 +94,11 @@ type ListGroupMilestonesOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/group_milestones/#list-group-milestones func (s *GroupMilestonesService) ListGroupMilestones(gid any, opt *ListGroupMilestonesOptions, options ...RequestOptionFunc) ([]*GroupMilestone, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/milestones", PathEscape(group)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var m []*GroupMilestone - resp, err := s.client.Do(req, &m) - if err != nil { - return nil, resp, err - } - - return m, resp, nil + return do[[]*GroupMilestone](s.client, + withPath("groups/%s/milestones", GroupID{gid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // GetGroupMilestone gets a single group milestone. @@ -120,24 +106,10 @@ func (s *GroupMilestonesService) ListGroupMilestones(gid any, opt *ListGroupMile // GitLab API docs: // https://docs.gitlab.com/api/group_milestones/#get-single-milestone func (s *GroupMilestonesService) GetGroupMilestone(gid any, milestone int64, options ...RequestOptionFunc) (*GroupMilestone, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/milestones/%d", PathEscape(group), milestone) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - m := new(GroupMilestone) - resp, err := s.client.Do(req, m) - if err != nil { - return nil, resp, err - } - - return m, resp, nil + return do[*GroupMilestone](s.client, + withPath("groups/%s/milestones/%d", GroupID{gid}, milestone), + withRequestOpts(options...), + ) } // CreateGroupMilestoneOptions represents the available CreateGroupMilestone() options. @@ -156,24 +128,12 @@ type CreateGroupMilestoneOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/group_milestones/#create-new-milestone func (s *GroupMilestonesService) CreateGroupMilestone(gid any, opt *CreateGroupMilestoneOptions, options ...RequestOptionFunc) (*GroupMilestone, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/milestones", PathEscape(group)) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - m := new(GroupMilestone) - resp, err := s.client.Do(req, m) - if err != nil { - return nil, resp, err - } - - return m, resp, nil + return do[*GroupMilestone](s.client, + withMethod(http.MethodPost), + withPath("groups/%s/milestones", GroupID{gid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // UpdateGroupMilestoneOptions represents the available UpdateGroupMilestone() options. @@ -193,24 +153,12 @@ type UpdateGroupMilestoneOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/group_milestones/#edit-milestone func (s *GroupMilestonesService) UpdateGroupMilestone(gid any, milestone int64, opt *UpdateGroupMilestoneOptions, options ...RequestOptionFunc) (*GroupMilestone, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/milestones/%d", PathEscape(group), milestone) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - m := new(GroupMilestone) - resp, err := s.client.Do(req, m) - if err != nil { - return nil, resp, err - } - - return m, resp, nil + return do[*GroupMilestone](s.client, + withMethod(http.MethodPut), + withPath("groups/%s/milestones/%d", GroupID{gid}, milestone), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // DeleteGroupMilestone deletes a specified group milestone. @@ -218,17 +166,12 @@ func (s *GroupMilestonesService) UpdateGroupMilestone(gid any, milestone int64, // GitLab API docs: // https://docs.gitlab.com/api/group_milestones/#delete-group-milestone func (s *GroupMilestonesService) DeleteGroupMilestone(pid any, milestone int64, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("groups/%s/milestones/%d", PathEscape(project), milestone) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("groups/%s/milestones/%d", GroupID{pid}, milestone), + withRequestOpts(options...), + ) + return resp, err } // GetGroupMilestoneIssuesOptions represents the available GetGroupMilestoneIssues() options. @@ -244,24 +187,11 @@ type GetGroupMilestoneIssuesOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/group_milestones/#get-all-issues-assigned-to-a-single-milestone func (s *GroupMilestonesService) GetGroupMilestoneIssues(gid any, milestone int64, opt *GetGroupMilestoneIssuesOptions, options ...RequestOptionFunc) ([]*Issue, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/milestones/%d/issues", PathEscape(group), milestone) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var i []*Issue - resp, err := s.client.Do(req, &i) - if err != nil { - return nil, resp, err - } - - return i, resp, nil + return do[[]*Issue](s.client, + withPath("groups/%s/milestones/%d/issues", GroupID{gid}, milestone), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // GetGroupMilestoneMergeRequestsOptions represents the available @@ -279,24 +209,11 @@ type GetGroupMilestoneMergeRequestsOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/group_milestones/#get-all-merge-requests-assigned-to-a-single-milestone func (s *GroupMilestonesService) GetGroupMilestoneMergeRequests(gid any, milestone int64, opt *GetGroupMilestoneMergeRequestsOptions, options ...RequestOptionFunc) ([]*BasicMergeRequest, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/milestones/%d/merge_requests", PathEscape(group), milestone) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var mr []*BasicMergeRequest - resp, err := s.client.Do(req, &mr) - if err != nil { - return nil, resp, err - } - - return mr, resp, nil + return do[[]*BasicMergeRequest](s.client, + withPath("groups/%s/milestones/%d/merge_requests", GroupID{gid}, milestone), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // BurndownChartEvent represents a burnout chart event. @@ -324,22 +241,9 @@ type GetGroupMilestoneBurndownChartEventsOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/group_milestones/#get-all-burndown-chart-events-for-a-single-milestone func (s *GroupMilestonesService) GetGroupMilestoneBurndownChartEvents(gid any, milestone int64, opt *GetGroupMilestoneBurndownChartEventsOptions, options ...RequestOptionFunc) ([]*BurndownChartEvent, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/milestones/%d/burndown_events", PathEscape(group), milestone) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var be []*BurndownChartEvent - resp, err := s.client.Do(req, &be) - if err != nil { - return nil, resp, err - } - - return be, resp, nil + return do[[]*BurndownChartEvent](s.client, + withPath("groups/%s/milestones/%d/burndown_events", GroupID{gid}, milestone), + withAPIOpts(opt), + withRequestOpts(options...), + ) } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/group_protected_branches.go b/vendor/gitlab.com/gitlab-org/api/client-go/group_protected_branches.go new file mode 100644 index 00000000..f43c6ed6 --- /dev/null +++ b/vendor/gitlab.com/gitlab-org/api/client-go/group_protected_branches.go @@ -0,0 +1,177 @@ +package gitlab + +import ( + "net/http" + "net/url" +) + +type ( + GroupProtectedBranchesServiceInterface interface { + // ListProtectedBranches returns a list of protected branches from a group. + // + // GitLab API docs: + // https://docs.gitlab.com/api/group_protected_branches/#list-protected-branches + ListProtectedBranches(gid any, opt *ListGroupProtectedBranchesOptions, options ...RequestOptionFunc) ([]*GroupProtectedBranch, *Response, error) + + // GetProtectedBranch returns a single group-level protected branch. + // + // GitLab API docs: + // https://docs.gitlab.com/api/group_protected_branches/#get-a-single-protected-branch-or-wildcard-protected-branch + GetProtectedBranch(gid any, branch string, options ...RequestOptionFunc) (*GroupProtectedBranch, *Response, error) + + // ProtectRepositoryBranches protects a single group-level branch. + // + // GitLab API docs: + // https://docs.gitlab.com/api/group_protected_branches/#protect-repository-branches + ProtectRepositoryBranches(gid any, opt *ProtectGroupRepositoryBranchesOptions, options ...RequestOptionFunc) (*GroupProtectedBranch, *Response, error) + + // UpdateProtectedBranch updates a single group-level protected branch. + // + // GitLab API docs: + // https://docs.gitlab.com/api/group_protected_branches/#update-a-protected-branch + UpdateProtectedBranch(gid any, branch string, opt *UpdateGroupProtectedBranchOptions, options ...RequestOptionFunc) (*GroupProtectedBranch, *Response, error) + + // UnprotectRepositoryBranches unprotects the given protected group-level branch. + // + // GitLab API docs: + // https://docs.gitlab.com/api/group_protected_branches/#unprotect-repository-branches + UnprotectRepositoryBranches(gid any, branch string, options ...RequestOptionFunc) (*Response, error) + } + + // GroupProtectedBranchesService handles communication with the group-level + // protected branch methods of the GitLab API. + // + // GitLab API docs: + // https://docs.gitlab.com/api/group_protected_branches/ + GroupProtectedBranchesService struct { + client *Client + } +) + +var _ GroupProtectedBranchesServiceInterface = (*GroupProtectedBranchesService)(nil) + +// GroupProtectedBranch represents a group protected branch. +// +// GitLab API docs: +// https://docs.gitlab.com/api/group_protected_branches/#list-protected-branches +type GroupProtectedBranch struct { + ID int64 `json:"id"` + Name string `json:"name"` + PushAccessLevels []*GroupBranchAccessDescription `json:"push_access_levels"` + MergeAccessLevels []*GroupBranchAccessDescription `json:"merge_access_levels"` + UnprotectAccessLevels []*GroupBranchAccessDescription `json:"unprotect_access_levels"` + AllowForcePush bool `json:"allow_force_push"` + CodeOwnerApprovalRequired bool `json:"code_owner_approval_required"` +} + +// GroupBranchAccessDescription represents the access description for a group protected +// branch. +// +// GitLab API docs: +// https://docs.gitlab.com/api/group_protected_branches/#list-protected-branches +type GroupBranchAccessDescription struct { + ID int64 `json:"id"` + AccessLevel AccessLevelValue `json:"access_level"` + AccessLevelDescription string `json:"access_level_description"` + DeployKeyID int64 `json:"deploy_key_id"` + UserID int64 `json:"user_id"` + GroupID int64 `json:"group_id"` +} + +// ListGroupProtectedBranchesOptions represents the available ListProtectedBranches() +// options. +// +// GitLab API docs: +// https://docs.gitlab.com/api/group_protected_branches/#list-protected-branches +type ListGroupProtectedBranchesOptions struct { + ListOptions + Search *string `url:"search,omitempty" json:"search,omitempty"` +} + +func (s *GroupProtectedBranchesService) ListProtectedBranches(gid any, opt *ListGroupProtectedBranchesOptions, options ...RequestOptionFunc) ([]*GroupProtectedBranch, *Response, error) { + return do[[]*GroupProtectedBranch](s.client, + withMethod(http.MethodGet), + withPath("groups/%s/protected_branches", GroupID{gid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) +} + +func (s *GroupProtectedBranchesService) GetProtectedBranch(gid any, branch string, options ...RequestOptionFunc) (*GroupProtectedBranch, *Response, error) { + return do[*GroupProtectedBranch](s.client, + withMethod(http.MethodGet), + withPath("groups/%s/protected_branches/%s", GroupID{gid}, url.PathEscape(branch)), + withRequestOpts(options...), + ) +} + +// ProtectGroupRepositoryBranchesOptions represents the available +// ProtectRepositoryBranches() options. +// +// GitLab API docs: +// https://docs.gitlab.com/api/group_protected_branches/#protect-repository-branches +type ProtectGroupRepositoryBranchesOptions struct { + Name *string `url:"name,omitempty" json:"name,omitempty"` + PushAccessLevel *AccessLevelValue `url:"push_access_level,omitempty" json:"push_access_level,omitempty"` + MergeAccessLevel *AccessLevelValue `url:"merge_access_level,omitempty" json:"merge_access_level,omitempty"` + UnprotectAccessLevel *AccessLevelValue `url:"unprotect_access_level,omitempty" json:"unprotect_access_level,omitempty"` + AllowForcePush *bool `url:"allow_force_push,omitempty" json:"allow_force_push,omitempty"` + AllowedToPush *[]*GroupBranchPermissionOptions `url:"allowed_to_push,omitempty" json:"allowed_to_push,omitempty"` + AllowedToMerge *[]*GroupBranchPermissionOptions `url:"allowed_to_merge,omitempty" json:"allowed_to_merge,omitempty"` + AllowedToUnprotect *[]*GroupBranchPermissionOptions `url:"allowed_to_unprotect,omitempty" json:"allowed_to_unprotect,omitempty"` + CodeOwnerApprovalRequired *bool `url:"code_owner_approval_required,omitempty" json:"code_owner_approval_required,omitempty"` +} + +// GroupBranchPermissionOptions represents a branch permission option. +// +// GitLab API docs: +// https://docs.gitlab.com/api/group_protected_branches/#protect-repository-branches +type GroupBranchPermissionOptions struct { + ID *int64 `url:"id,omitempty" json:"id,omitempty"` + UserID *int64 `url:"user_id,omitempty" json:"user_id,omitempty"` + GroupID *int64 `url:"group_id,omitempty" json:"group_id,omitempty"` + DeployKeyID *int64 `url:"deploy_key_id,omitempty" json:"deploy_key_id,omitempty"` + AccessLevel *AccessLevelValue `url:"access_level,omitempty" json:"access_level,omitempty"` + Destroy *bool `url:"_destroy,omitempty" json:"_destroy,omitempty"` +} + +func (s *GroupProtectedBranchesService) ProtectRepositoryBranches(gid any, opt *ProtectGroupRepositoryBranchesOptions, options ...RequestOptionFunc) (*GroupProtectedBranch, *Response, error) { + return do[*GroupProtectedBranch](s.client, + withMethod(http.MethodPost), + withPath("groups/%s/protected_branches", GroupID{gid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) +} + +// UpdateGroupProtectedBranchOptions represents the available +// UpdateProtectedBranch() options. +// +// GitLab API docs: +// https://docs.gitlab.com/api/group_protected_branches/#update-a-protected-branch +type UpdateGroupProtectedBranchOptions struct { + Name *string `url:"name,omitempty" json:"name,omitempty"` + AllowForcePush *bool `url:"allow_force_push,omitempty" json:"allow_force_push,omitempty"` + CodeOwnerApprovalRequired *bool `url:"code_owner_approval_required,omitempty" json:"code_owner_approval_required,omitempty"` + AllowedToPush *[]*GroupBranchPermissionOptions `url:"allowed_to_push,omitempty" json:"allowed_to_push,omitempty"` + AllowedToMerge *[]*GroupBranchPermissionOptions `url:"allowed_to_merge,omitempty" json:"allowed_to_merge,omitempty"` + AllowedToUnprotect *[]*GroupBranchPermissionOptions `url:"allowed_to_unprotect,omitempty" json:"allowed_to_unprotect,omitempty"` +} + +func (s *GroupProtectedBranchesService) UpdateProtectedBranch(gid any, branch string, opt *UpdateGroupProtectedBranchOptions, options ...RequestOptionFunc) (*GroupProtectedBranch, *Response, error) { + return do[*GroupProtectedBranch](s.client, + withMethod(http.MethodPatch), + withPath("groups/%s/protected_branches/%s", GroupID{gid}, url.PathEscape(branch)), + withAPIOpts(opt), + withRequestOpts(options...), + ) +} + +func (s *GroupProtectedBranchesService) UnprotectRepositoryBranches(gid any, branch string, options ...RequestOptionFunc) (*Response, error) { + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("groups/%s/protected_branches/%s", GroupID{gid}, url.PathEscape(branch)), + withRequestOpts(options...), + ) + return resp, err +} diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/group_relations_export.go b/vendor/gitlab.com/gitlab-org/api/client-go/group_relations_export.go index 38863ba2..4574f90e 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/group_relations_export.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/group_relations_export.go @@ -2,7 +2,6 @@ package gitlab import ( "bytes" - "fmt" "net/http" "time" ) @@ -81,65 +80,31 @@ type ( var _ GroupRelationsExportServiceInterface = (*GroupRelationsExportService)(nil) func (s *GroupRelationsExportService) ScheduleExport(gid any, opt *GroupRelationsScheduleExportOptions, options ...RequestOptionFunc) (*Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, err - } - - u := fmt.Sprintf("groups/%s/export_relations", - PathEscape(group), + _, resp, err := do[none](s.client, + withMethod(http.MethodPost), + withPath("groups/%s/export_relations", GroupID{gid}), + withAPIOpts(opt), + withRequestOpts(options...), ) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + return resp, err } func (s *GroupRelationsExportService) ListExportStatus(gid any, opt *ListGroupRelationsStatusOptions, options ...RequestOptionFunc) ([]*GroupRelationStatus, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - - u := fmt.Sprintf("groups/%s/export_relations/status", PathEscape(group)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var groups []*GroupRelationStatus - resp, err := s.client.Do(req, &groups) - if err != nil { - return nil, resp, err - } - - return groups, resp, nil + return do[[]*GroupRelationStatus](s.client, + withPath("groups/%s/export_relations/status", GroupID{gid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } func (s *GroupRelationsExportService) ExportDownload(gid any, opt *GroupRelationsDownloadOptions, options ...RequestOptionFunc) (*bytes.Reader, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - - u := fmt.Sprintf("groups/%s/export_relations/download", - PathEscape(group), + buf, resp, err := do[bytes.Buffer](s.client, + withPath("groups/%s/export_relations/download", GroupID{gid}), + withAPIOpts(opt), + withRequestOpts(options...), ) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - groupRelationsExportDownload := new(bytes.Buffer) - resp, err := s.client.Do(req, groupRelationsExportDownload) if err != nil { return nil, resp, err } - - return bytes.NewReader(groupRelationsExportDownload.Bytes()), resp, err + return bytes.NewReader(buf.Bytes()), resp, nil } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/group_releases.go b/vendor/gitlab.com/gitlab-org/api/client-go/group_releases.go index da52ce9e..ce012678 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/group_releases.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/group_releases.go @@ -13,11 +13,6 @@ package gitlab -import ( - "fmt" - "net/http" -) - type ( GroupReleasesServiceInterface interface { ListGroupReleases(gid any, opts *ListGroupReleasesOptions, options ...RequestOptionFunc) ([]*Release, *Response, error) @@ -49,21 +44,9 @@ type ListGroupReleasesOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/group_releases.html#list-group-releases func (s *GroupReleasesService) ListGroupReleases(gid any, opts *ListGroupReleasesOptions, options ...RequestOptionFunc) ([]*Release, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/releases", PathEscape(group)) - - req, err := s.client.NewRequest(http.MethodGet, u, opts, options) - if err != nil { - return nil, nil, err - } - - var releases []*Release - resp, err := s.client.Do(req, &releases) - if err != nil { - return nil, resp, err - } - return releases, resp, nil + return do[[]*Release](s.client, + withPath("groups/%s/releases", GroupID{gid}), + withAPIOpts(opts), + withRequestOpts(options...), + ) } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/group_scim.go b/vendor/gitlab.com/gitlab-org/api/client-go/group_scim.go index e99a266e..936290e5 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/group_scim.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/group_scim.go @@ -14,7 +14,6 @@ package gitlab import ( - "fmt" "net/http" ) @@ -51,23 +50,10 @@ type GroupSCIMIdentity struct { // GitLab API docs: // https://docs.gitlab.com/api/scim/#get-scim-identities-for-a-group func (s *GroupSCIMService) GetSCIMIdentitiesForGroup(gid any, options ...RequestOptionFunc) ([]*GroupSCIMIdentity, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/scim/identities", PathEscape(group)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - var identities []*GroupSCIMIdentity - resp, err := s.client.Do(req, &identities) - if err != nil { - return nil, resp, err - } - return identities, resp, nil + return do[[]*GroupSCIMIdentity](s.client, + withPath("groups/%s/scim/identities", GroupID{gid}), + withRequestOpts(options...), + ) } // GetSCIMIdentity gets a SCIM identity for a group. @@ -75,23 +61,10 @@ func (s *GroupSCIMService) GetSCIMIdentitiesForGroup(gid any, options ...Request // GitLab API docs: // https://docs.gitlab.com/api/scim/#get-a-single-scim-identity func (s *GroupSCIMService) GetSCIMIdentity(gid any, uid string, options ...RequestOptionFunc) (*GroupSCIMIdentity, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/scim/%s", PathEscape(group), uid) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - identity := new(GroupSCIMIdentity) - resp, err := s.client.Do(req, identity) - if err != nil { - return nil, resp, err - } - return identity, resp, nil + return do[*GroupSCIMIdentity](s.client, + withPath("groups/%s/scim/%s", GroupID{gid}, uid), + withRequestOpts(options...), + ) } // UpdateSCIMIdentityOptions represent the request options for @@ -108,18 +81,13 @@ type UpdateSCIMIdentityOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/scim/#update-extern_uid-field-for-a-scim-identity func (s *GroupSCIMService) UpdateSCIMIdentity(gid any, uid string, opt *UpdateSCIMIdentityOptions, options ...RequestOptionFunc) (*Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("groups/%s/scim/%s", PathEscape(group), uid) - - req, err := s.client.NewRequest(http.MethodPatch, u, opt, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodPatch), + withPath("groups/%s/scim/%s", GroupID{gid}, uid), + withAPIOpts(opt), + withRequestOpts(options...), + ) + return resp, err } // DeleteSCIMIdentity deletes a SCIM identity. @@ -127,16 +95,10 @@ func (s *GroupSCIMService) UpdateSCIMIdentity(gid any, uid string, opt *UpdateSC // GitLab API docs: // https://docs.gitlab.com/api/scim/#delete-a-single-scim-identity func (s *GroupSCIMService) DeleteSCIMIdentity(gid any, uid string, options ...RequestOptionFunc) (*Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("groups/%s/scim/%s", PathEscape(group), uid) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("groups/%s/scim/%s", GroupID{gid}, uid), + withRequestOpts(options...), + ) + return resp, err } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/group_security_settings.go b/vendor/gitlab.com/gitlab-org/api/client-go/group_security_settings.go index 8f5e0eaf..445e757f 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/group_security_settings.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/group_security_settings.go @@ -16,7 +16,6 @@ package gitlab import ( - "fmt" "net/http" ) @@ -70,21 +69,10 @@ type UpdateGroupSecuritySettingsOptions struct { // GitLab API Docs: // https://docs.gitlab.com/api/group_security_settings/#update-secret_push_protection_enabled-setting func (s *GroupSecuritySettingsService) UpdateSecretPushProtectionEnabledSetting(gid any, opt UpdateGroupSecuritySettingsOptions, options ...RequestOptionFunc) (*GroupSecuritySettings, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/security_settings", PathEscape(group)) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - settings := new(GroupSecuritySettings) - resp, err := s.client.Do(req, &settings) - if err != nil { - return nil, resp, err - } - - return settings, resp, err + return do[*GroupSecuritySettings](s.client, + withMethod(http.MethodPut), + withPath("groups/%s/security_settings", GroupID{gid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/group_serviceaccounts.go b/vendor/gitlab.com/gitlab-org/api/client-go/group_serviceaccounts.go index b4e31343..f8cd5bf3 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/group_serviceaccounts.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/group_serviceaccounts.go @@ -17,7 +17,6 @@ package gitlab import ( - "fmt" "net/http" "time" ) @@ -48,24 +47,11 @@ type ListServiceAccountsOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/service_accounts/#list-all-group-service-accounts func (s *GroupsService) ListServiceAccounts(gid any, opt *ListServiceAccountsOptions, options ...RequestOptionFunc) ([]*GroupServiceAccount, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/service_accounts", PathEscape(group)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var sa []*GroupServiceAccount - resp, err := s.client.Do(req, &sa) - if err != nil { - return nil, resp, err - } - - return sa, resp, nil + return do[[]*GroupServiceAccount](s.client, + withPath("groups/%s/service_accounts", GroupID{gid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // CreateServiceAccountOptions represents the available CreateServiceAccount() options. @@ -85,24 +71,12 @@ type CreateServiceAccountOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/service_accounts/#create-a-group-service-account func (s *GroupsService) CreateServiceAccount(gid any, opt *CreateServiceAccountOptions, options ...RequestOptionFunc) (*GroupServiceAccount, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/service_accounts", PathEscape(group)) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - sa := new(GroupServiceAccount) - resp, err := s.client.Do(req, sa) - if err != nil { - return nil, resp, err - } - - return sa, resp, nil + return do[*GroupServiceAccount](s.client, + withMethod(http.MethodPost), + withPath("groups/%s/service_accounts", GroupID{gid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // UpdateServiceAccountOptions represents the available UpdateServiceAccount() options. @@ -122,24 +96,12 @@ type UpdateServiceAccountOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/service_accounts/#update-a-group-service-account func (s *GroupsService) UpdateServiceAccount(gid any, serviceAccount int64, opt *UpdateServiceAccountOptions, options ...RequestOptionFunc) (*GroupServiceAccount, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/service_accounts/%d", PathEscape(group), serviceAccount) - - req, err := s.client.NewRequest(http.MethodPatch, u, opt, options) - if err != nil { - return nil, nil, err - } - - sa := new(GroupServiceAccount) - resp, err := s.client.Do(req, sa) - if err != nil { - return nil, resp, err - } - - return sa, resp, nil + return do[*GroupServiceAccount](s.client, + withMethod(http.MethodPatch), + withPath("groups/%s/service_accounts/%d", GroupID{gid}, serviceAccount), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // DeleteServiceAccountOptions represents the available DeleteServiceAccount() options. @@ -157,18 +119,13 @@ type DeleteServiceAccountOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/service_accounts/#delete-a-group-service-account func (s *GroupsService) DeleteServiceAccount(gid any, serviceAccount int64, opt *DeleteServiceAccountOptions, options ...RequestOptionFunc) (*Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("groups/%s/service_accounts/%d", PathEscape(group), serviceAccount) - - req, err := s.client.NewRequest(http.MethodDelete, u, opt, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("groups/%s/service_accounts/%d", GroupID{gid}, serviceAccount), + withAPIOpts(opt), + withRequestOpts(options...), + ) + return resp, err } // ListServiceAccountPersonalAccessTokensOptions represents the available @@ -197,24 +154,11 @@ type ListServiceAccountPersonalAccessTokensOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/service_accounts/#list-all-personal-access-tokens-for-a-group-service-account func (s *GroupsService) ListServiceAccountPersonalAccessTokens(gid any, serviceAccount int64, opt *ListServiceAccountPersonalAccessTokensOptions, options ...RequestOptionFunc) ([]*PersonalAccessToken, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/service_accounts/%d/personal_access_tokens", PathEscape(group), serviceAccount) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var pats []*PersonalAccessToken - resp, err := s.client.Do(req, &pats) - if err != nil { - return nil, resp, err - } - - return pats, resp, nil + return do[[]*PersonalAccessToken](s.client, + withPath("groups/%s/service_accounts/%d/personal_access_tokens", GroupID{gid}, serviceAccount), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // CreateServiceAccountPersonalAccessTokenOptions represents the available @@ -235,24 +179,12 @@ type CreateServiceAccountPersonalAccessTokenOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/service_accounts/#create-a-personal-access-token-for-a-group-service-account func (s *GroupsService) CreateServiceAccountPersonalAccessToken(gid any, serviceAccount int64, opt *CreateServiceAccountPersonalAccessTokenOptions, options ...RequestOptionFunc) (*PersonalAccessToken, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/service_accounts/%d/personal_access_tokens", PathEscape(group), serviceAccount) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - pat := new(PersonalAccessToken) - resp, err := s.client.Do(req, pat) - if err != nil { - return nil, resp, err - } - - return pat, resp, nil + return do[*PersonalAccessToken](s.client, + withMethod(http.MethodPost), + withPath("groups/%s/service_accounts/%d/personal_access_tokens", GroupID{gid}, serviceAccount), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // RevokeServiceAccountPersonalAccessToken revokes a personal access token for an @@ -261,18 +193,12 @@ func (s *GroupsService) CreateServiceAccountPersonalAccessToken(gid any, service // GitLab API docs: // https://docs.gitlab.com/api/service_accounts/#revoke-a-personal-access-token-for-a-group-service-account func (s *GroupsService) RevokeServiceAccountPersonalAccessToken(gid any, serviceAccount, token int64, options ...RequestOptionFunc) (*Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("groups/%s/service_accounts/%d/personal_access_tokens/%d", PathEscape(group), serviceAccount, token) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("groups/%s/service_accounts/%d/personal_access_tokens/%d", GroupID{gid}, serviceAccount, token), + withRequestOpts(options...), + ) + return resp, err } // RotateServiceAccountPersonalAccessTokenOptions represents the available RotateServiceAccountPersonalAccessToken() @@ -290,22 +216,10 @@ type RotateServiceAccountPersonalAccessTokenOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/service_accounts/#rotate-a-personal-access-token-for-a-group-service-account func (s *GroupsService) RotateServiceAccountPersonalAccessToken(gid any, serviceAccount, token int64, opt *RotateServiceAccountPersonalAccessTokenOptions, options ...RequestOptionFunc) (*PersonalAccessToken, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/service_accounts/%d/personal_access_tokens/%d/rotate", PathEscape(group), serviceAccount, token) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - pat := new(PersonalAccessToken) - resp, err := s.client.Do(req, pat) - if err != nil { - return nil, resp, err - } - - return pat, resp, nil + return do[*PersonalAccessToken](s.client, + withMethod(http.MethodPost), + withPath("groups/%s/service_accounts/%d/personal_access_tokens/%d/rotate", GroupID{gid}, serviceAccount, token), + withAPIOpts(opt), + withRequestOpts(options...), + ) } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/group_ssh_certificates.go b/vendor/gitlab.com/gitlab-org/api/client-go/group_ssh_certificates.go index 67a190ab..1be649ad 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/group_ssh_certificates.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/group_ssh_certificates.go @@ -1,7 +1,6 @@ package gitlab import ( - "fmt" "net/http" "time" ) @@ -41,24 +40,10 @@ type GroupSSHCertificate struct { // GitLab API docs: // https://docs.gitlab.com/api/group_ssh_certificates/#get-all-ssh-certificates-for-a-particular-group func (s *GroupSSHCertificatesService) ListGroupSSHCertificates(gid any, options ...RequestOptionFunc) ([]*GroupSSHCertificate, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/ssh_certificates", PathEscape(group)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - var certs []*GroupSSHCertificate - resp, err := s.client.Do(req, &certs) - if err != nil { - return nil, resp, err - } - - return certs, resp, nil + return do[[]*GroupSSHCertificate](s.client, + withPath("groups/%s/ssh_certificates", GroupID{gid}), + withRequestOpts(options...), + ) } // CreateGroupSSHCertificateOptions represents the available @@ -76,24 +61,12 @@ type CreateGroupSSHCertificateOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/group_ssh_certificates/#create-ssh-certificate func (s *GroupSSHCertificatesService) CreateGroupSSHCertificate(gid any, opt *CreateGroupSSHCertificateOptions, options ...RequestOptionFunc) (*GroupSSHCertificate, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/ssh_certificates", PathEscape(group)) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - cert := new(GroupSSHCertificate) - resp, err := s.client.Do(req, cert) - if err != nil { - return nil, resp, err - } - - return cert, resp, nil + return do[*GroupSSHCertificate](s.client, + withMethod(http.MethodPost), + withPath("groups/%s/ssh_certificates", GroupID{gid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // DeleteGroupSSHCertificate deletes a SSH certificate from a specified group. @@ -101,16 +74,10 @@ func (s *GroupSSHCertificatesService) CreateGroupSSHCertificate(gid any, opt *Cr // GitLab API docs: // https://docs.gitlab.com/api/group_ssh_certificates/#delete-group-ssh-certificate func (s *GroupSSHCertificatesService) DeleteGroupSSHCertificate(gid any, cert int64, options ...RequestOptionFunc) (*Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("groups/%s/ssh_certificates/%d", PathEscape(group), cert) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("groups/%s/ssh_certificates/%d", GroupID{gid}, cert), + withRequestOpts(options...), + ) + return resp, err } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/group_variables.go b/vendor/gitlab.com/gitlab-org/api/client-go/group_variables.go index 9da67d8b..f85db4ef 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/group_variables.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/group_variables.go @@ -24,10 +24,30 @@ import ( type ( // GroupVariablesServiceInterface defines methods for the GroupVariablesService. GroupVariablesServiceInterface interface { + // ListVariables gets a list of all variables for a group. + // + // GitLab API docs: + // https://docs.gitlab.com/api/group_level_variables/#list-group-variables ListVariables(gid any, opt *ListGroupVariablesOptions, options ...RequestOptionFunc) ([]*GroupVariable, *Response, error) + // GetVariable gets a variable. + // + // GitLab API docs: + // https://docs.gitlab.com/api/group_level_variables/#show-variable-details GetVariable(gid any, key string, opt *GetGroupVariableOptions, options ...RequestOptionFunc) (*GroupVariable, *Response, error) + // CreateVariable creates a new group variable. + // + // GitLab API docs: + // https://docs.gitlab.com/api/group_level_variables/#create-variable CreateVariable(gid any, opt *CreateGroupVariableOptions, options ...RequestOptionFunc) (*GroupVariable, *Response, error) + // UpdateVariable updates an existing group variable. + // + // GitLab API docs: + // https://docs.gitlab.com/api/group_level_variables/#update-variable UpdateVariable(gid any, key string, opt *UpdateGroupVariableOptions, options ...RequestOptionFunc) (*GroupVariable, *Response, error) + // RemoveVariable removes a group's variable. + // + // GitLab API docs: + // https://docs.gitlab.com/api/group_level_variables/#remove-variable RemoveVariable(gid any, key string, opt *RemoveGroupVariableOptions, options ...RequestOptionFunc) (*Response, error) } @@ -72,10 +92,6 @@ type ListGroupVariablesOptions struct { ListOptions } -// ListVariables gets a list of all variables for a group. -// -// GitLab API docs: -// https://docs.gitlab.com/api/group_level_variables/#list-group-variables func (s *GroupVariablesService) ListVariables(gid any, opt *ListGroupVariablesOptions, options ...RequestOptionFunc) ([]*GroupVariable, *Response, error) { return do[[]*GroupVariable](s.client, withPath("groups/%s/variables", GroupID{gid}), @@ -93,10 +109,6 @@ type GetGroupVariableOptions struct { Filter *VariableFilter `url:"filter,omitempty" json:"filter,omitempty"` } -// GetVariable gets a variable. -// -// GitLab API docs: -// https://docs.gitlab.com/api/group_level_variables/#show-variable-details func (s *GroupVariablesService) GetVariable(gid any, key string, opt *GetGroupVariableOptions, options ...RequestOptionFunc) (*GroupVariable, *Response, error) { return do[*GroupVariable](s.client, withPath("groups/%s/variables/%s", GroupID{gid}, url.PathEscape(key)), @@ -122,10 +134,6 @@ type CreateGroupVariableOptions struct { VariableType *VariableTypeValue `url:"variable_type,omitempty" json:"variable_type,omitempty"` } -// CreateVariable creates a new group variable. -// -// GitLab API docs: -// https://docs.gitlab.com/api/group_level_variables/#create-variable func (s *GroupVariablesService) CreateVariable(gid any, opt *CreateGroupVariableOptions, options ...RequestOptionFunc) (*GroupVariable, *Response, error) { return do[*GroupVariable](s.client, withMethod(http.MethodPost), @@ -151,11 +159,6 @@ type UpdateGroupVariableOptions struct { VariableType *VariableTypeValue `url:"variable_type,omitempty" json:"variable_type,omitempty"` } -// UpdateVariable updates the position of an existing -// group issue board list. -// -// GitLab API docs: -// https://docs.gitlab.com/api/group_level_variables/#update-variable func (s *GroupVariablesService) UpdateVariable(gid any, key string, opt *UpdateGroupVariableOptions, options ...RequestOptionFunc) (*GroupVariable, *Response, error) { return do[*GroupVariable](s.client, withMethod(http.MethodPut), @@ -174,10 +177,6 @@ type RemoveGroupVariableOptions struct { Filter *VariableFilter `url:"filter,omitempty" json:"filter,omitempty"` } -// RemoveVariable removes a group's variable. -// -// GitLab API docs: -// https://docs.gitlab.com/api/group_level_variables/#remove-variable func (s *GroupVariablesService) RemoveVariable(gid any, key string, opt *RemoveGroupVariableOptions, options ...RequestOptionFunc) (*Response, error) { _, resp, err := do[none](s.client, withMethod(http.MethodDelete), diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/groups.go b/vendor/gitlab.com/gitlab-org/api/client-go/groups.go index 8800288c..79eef12e 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/groups.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/groups.go @@ -19,14 +19,12 @@ package gitlab import ( "bytes" "encoding/json" - "fmt" + "errors" "io" "net/http" "net/url" "strconv" "time" - - retryablehttp "github.com/hashicorp/go-retryablehttp" ) type ( @@ -116,6 +114,7 @@ type Group struct { MembershipLock bool `json:"membership_lock"` Visibility VisibilityValue `json:"visibility"` LFSEnabled bool `json:"lfs_enabled"` + MaxArtifactsSize int64 `json:"max_artifacts_size"` DefaultBranch string `json:"default_branch"` DefaultBranchProtectionDefaults *BranchProtectionDefaults `json:"default_branch_protection_defaults"` AvatarURL string `json:"avatar_url"` @@ -152,6 +151,10 @@ type Group struct { AllowedEmailDomainsList string `json:"allowed_email_domains_list"` WikiAccessLevel AccessControlValue `json:"wiki_access_level"` + OnlyAllowMergeIfPipelineSucceeds bool `json:"only_allow_merge_if_pipeline_succeeds"` + AllowMergeOnSkippedPipeline bool `json:"allow_merge_on_skipped_pipeline"` + OnlyAllowMergeIfAllDiscussionsAreResolved bool `json:"only_allow_merge_if_all_discussions_are_resolved"` + // Deprecated: will be removed in v5 of the API, use ListGroupProjects instead Projects []*Project `json:"projects"` @@ -250,6 +253,9 @@ type ListGroupsOptions struct { MinAccessLevel *AccessLevelValue `url:"min_access_level,omitempty" json:"min_access_level,omitempty"` TopLevelOnly *bool `url:"top_level_only,omitempty" json:"top_level_only,omitempty"` RepositoryStorage *string `url:"repository_storage,omitempty" json:"repository_storage,omitempty"` + MarkedForDeletionOn *ISOTime `url:"marked_for_deletion_on,omitempty" json:"marked_for_deletion_on,omitempty"` + Active *bool `url:"active,omitempty" json:"active,omitempty"` + Archived *bool `url:"archived,omitempty" json:"archived,omitempty"` } // ListGroups gets a list of groups (as user: my groups, as admin: all groups). @@ -257,18 +263,11 @@ type ListGroupsOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/groups/#list-groups func (s *GroupsService) ListGroups(opt *ListGroupsOptions, options ...RequestOptionFunc) ([]*Group, *Response, error) { - req, err := s.client.NewRequest(http.MethodGet, "groups", opt, options) - if err != nil { - return nil, nil, err - } - - var gs []*Group - resp, err := s.client.Do(req, &gs) - if err != nil { - return nil, resp, err - } - - return gs, resp, nil + return do[[]*Group](s.client, + withPath("groups"), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // ListSubGroupsOptions represents the available ListSubGroups() options. @@ -282,24 +281,11 @@ type ListSubGroupsOptions ListGroupsOptions // GitLab API docs: // https://docs.gitlab.com/api/groups/#list-subgroups func (s *GroupsService) ListSubGroups(gid any, opt *ListSubGroupsOptions, options ...RequestOptionFunc) ([]*Group, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/subgroups", PathEscape(group)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var gs []*Group - resp, err := s.client.Do(req, &gs) - if err != nil { - return nil, resp, err - } - - return gs, resp, nil + return do[[]*Group](s.client, + withPath("groups/%s/subgroups", GroupID{gid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // ListDescendantGroupsOptions represents the available ListDescendantGroups() @@ -314,24 +300,11 @@ type ListDescendantGroupsOptions ListGroupsOptions // GitLab API docs: // https://docs.gitlab.com/api/groups/#list-descendant-groups func (s *GroupsService) ListDescendantGroups(gid any, opt *ListDescendantGroupsOptions, options ...RequestOptionFunc) ([]*Group, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/descendant_groups", PathEscape(group)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var gs []*Group - resp, err := s.client.Do(req, &gs) - if err != nil { - return nil, resp, err - } - - return gs, resp, nil + return do[[]*Group](s.client, + withPath("groups/%s/descendant_groups", GroupID{gid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // ListGroupProjectsOptions represents the available ListGroupProjects() options. @@ -340,6 +313,7 @@ func (s *GroupsService) ListDescendantGroups(gid any, opt *ListDescendantGroupsO // https://docs.gitlab.com/api/groups/#list-projects type ListGroupProjectsOptions struct { ListOptions + Active *bool `url:"active,omitempty" json:"active,omitempty"` Archived *bool `url:"archived,omitempty" json:"archived,omitempty"` IncludeSubGroups *bool `url:"include_subgroups,omitempty" json:"include_subgroups,omitempty"` MinAccessLevel *AccessLevelValue `url:"min_access_level,omitempty" json:"min_access_level,omitempty"` @@ -363,24 +337,11 @@ type ListGroupProjectsOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/groups/#list-projects func (s *GroupsService) ListGroupProjects(gid any, opt *ListGroupProjectsOptions, options ...RequestOptionFunc) ([]*Project, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/projects", PathEscape(group)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var ps []*Project - resp, err := s.client.Do(req, &ps) - if err != nil { - return nil, resp, err - } - - return ps, resp, nil + return do[[]*Project](s.client, + withPath("groups/%s/projects", GroupID{gid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // GetGroupOptions represents the available GetGroup() options. @@ -398,24 +359,11 @@ type GetGroupOptions struct { // // GitLab API docs: https://docs.gitlab.com/api/groups/#get-a-single-group func (s *GroupsService) GetGroup(gid any, opt *GetGroupOptions, options ...RequestOptionFunc) (*Group, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s", PathEscape(group)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - g := new(Group) - resp, err := s.client.Do(req, g) - if err != nil { - return nil, resp, err - } - - return g, resp, nil + return do[*Group](s.client, + withPath("groups/%s", GroupID{gid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // DownloadAvatar downloads a group avatar. @@ -423,24 +371,14 @@ func (s *GroupsService) GetGroup(gid any, opt *GetGroupOptions, options ...Reque // GitLab API docs: // https://docs.gitlab.com/api/groups/#download-a-group-avatar func (s *GroupsService) DownloadAvatar(gid any, options ...RequestOptionFunc) (*bytes.Reader, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/avatar", PathEscape(group)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - avatar := new(bytes.Buffer) - resp, err := s.client.Do(req, avatar) + buf, resp, err := do[bytes.Buffer](s.client, + withPath("groups/%s/avatar", GroupID{gid}), + withRequestOpts(options...), + ) if err != nil { return nil, resp, err } - - return bytes.NewReader(avatar.Bytes()), resp, err + return bytes.NewReader(buf.Bytes()), resp, nil } // CreateGroupOptions represents the available CreateGroup() options. @@ -531,38 +469,19 @@ func (d *DefaultBranchProtectionDefaultsOptions) EncodeValues(key string, v *url // // GitLab API docs: https://docs.gitlab.com/api/groups/#create-a-group func (s *GroupsService) CreateGroup(opt *CreateGroupOptions, options ...RequestOptionFunc) (*Group, *Response, error) { - var err error - var req *retryablehttp.Request - - if opt.Avatar == nil { - req, err = s.client.NewRequest(http.MethodPost, "groups", opt, options) - } else { - // since the Avatar is provided, check allowed_to_push and - // allowed_to_merge access levels and error if multiples are provided + reqOpts := []doOption{ + withMethod(http.MethodPost), + withPath("groups"), + withAPIOpts(opt), + withRequestOpts(options...), + } + if opt.Avatar != nil { if opt.DefaultBranchProtectionDefaults != nil && (len(*opt.DefaultBranchProtectionDefaults.AllowedToMerge) > 1 || len(*opt.DefaultBranchProtectionDefaults.AllowedToPush) > 1) { - return nil, nil, fmt.Errorf("multiple access levels for allowed_to_merge or allowed_to_push are not permitted when an Avatar is also specified as it will result in unexpected behavior") + return nil, nil, errors.New("multiple access levels for allowed_to_merge or allowed_to_push are not permitted when an Avatar is also specified as it will result in unexpected behavior") } - req, err = s.client.UploadRequest( - http.MethodPost, - "groups", - opt.Avatar.Image, - opt.Avatar.Filename, - UploadAvatar, - opt, - options, - ) - } - if err != nil { - return nil, nil, err + reqOpts = append(reqOpts, withUpload(opt.Avatar.Image, opt.Avatar.Filename, UploadAvatar)) } - - g := new(Group) - resp, err := s.client.Do(req, g) - if err != nil { - return nil, resp, err - } - - return g, resp, nil + return do[*Group](s.client, reqOpts...) } // TransferGroup transfers a project to the Group namespace. Available only @@ -571,28 +490,11 @@ func (s *GroupsService) CreateGroup(opt *CreateGroupOptions, options ...RequestO // GitLab API docs: // https://docs.gitlab.com/api/groups/#transfer-a-project-to-a-group func (s *GroupsService) TransferGroup(gid any, pid any, options ...RequestOptionFunc) (*Group, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/projects/%s", PathEscape(group), PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPost, u, nil, options) - if err != nil { - return nil, nil, err - } - - g := new(Group) - resp, err := s.client.Do(req, g) - if err != nil { - return nil, resp, err - } - - return g, resp, nil + return do[*Group](s.client, + withMethod(http.MethodPost), + withPath("groups/%s/projects/%s", GroupID{gid}, ProjectID{pid}), + withRequestOpts(options...), + ) } // TransferSubGroupOptions represents the available TransferSubGroup() options. @@ -609,24 +511,12 @@ type TransferSubGroupOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/groups/#transfer-a-group func (s *GroupsService) TransferSubGroup(gid any, opt *TransferSubGroupOptions, options ...RequestOptionFunc) (*Group, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/transfer", PathEscape(group)) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - g := new(Group) - resp, err := s.client.Do(req, g) - if err != nil { - return nil, resp, err - } - - return g, resp, nil + return do[*Group](s.client, + withMethod(http.MethodPost), + withPath("groups/%s/transfer", GroupID{gid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // UpdateGroupOptions represents the available UpdateGroup() options. @@ -649,6 +539,7 @@ type UpdateGroupOptions struct { EmailsEnabled *bool `url:"emails_enabled,omitempty" json:"emails_enabled,omitempty"` MentionsDisabled *bool `url:"mentions_disabled,omitempty" json:"mentions_disabled,omitempty"` LFSEnabled *bool `url:"lfs_enabled,omitempty" json:"lfs_enabled,omitempty"` + MaxArtifactsSize *int64 `url:"max_artifacts_size,omitempty" json:"max_artifacts_size,omitempty"` RequestAccessEnabled *bool `url:"request_access_enabled,omitempty" json:"request_access_enabled,omitempty"` DefaultBranchProtectionDefaults *DefaultBranchProtectionDefaultsOptions `url:"default_branch_protection_defaults,omitempty" json:"default_branch_protection_defaults,omitempty"` FileTemplateProjectID *int64 `url:"file_template_project_id,omitempty" json:"file_template_project_id,omitempty"` @@ -661,6 +552,10 @@ type UpdateGroupOptions struct { AllowedEmailDomainsList *string `url:"allowed_email_domains_list,omitempty" json:"allowed_email_domains_list,omitempty"` WikiAccessLevel *AccessControlValue `url:"wiki_access_level,omitempty" json:"wiki_access_level,omitempty"` + OnlyAllowMergeIfPipelineSucceeds *bool `url:"only_allow_merge_if_pipeline_succeeds,omitempty" json:"only_allow_merge_if_pipeline_succeeds,omitempty"` + AllowMergeOnSkippedPipeline *bool `url:"allow_merge_on_skipped_pipeline,omitempty" json:"allow_merge_on_skipped_pipeline,omitempty"` + OnlyAllowMergeIfAllDiscussionsAreResolved *bool `url:"only_allow_merge_if_all_discussions_are_resolved,omitempty" json:"only_allow_merge_if_all_discussions_are_resolved,omitempty"` + // Deprecated: Use EmailsEnabled instead EmailsDisabled *bool `url:"emails_disabled,omitempty" json:"emails_disabled,omitempty"` @@ -679,43 +574,19 @@ type UpdateGroupOptions struct { // // GitLab API docs: https://docs.gitlab.com/api/groups/#update-group-attributes func (s *GroupsService) UpdateGroup(gid any, opt *UpdateGroupOptions, options ...RequestOptionFunc) (*Group, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err + reqOpts := []doOption{ + withMethod(http.MethodPut), + withPath("groups/%s", GroupID{gid}), + withAPIOpts(opt), + withRequestOpts(options...), } - u := fmt.Sprintf("groups/%s", PathEscape(group)) - - var req *retryablehttp.Request - - if opt.Avatar == nil || (opt.Avatar.Filename == "" && opt.Avatar.Image == nil) { - req, err = s.client.NewRequest(http.MethodPut, u, opt, options) - } else { - // since the Avatar is provided, check allowed_to_push and - // allowed_to_merge access levels and error if multiples are provided + if opt.Avatar != nil && (opt.Avatar.Filename != "" || opt.Avatar.Image != nil) { if opt.DefaultBranchProtectionDefaults != nil && (len(*opt.DefaultBranchProtectionDefaults.AllowedToMerge) > 1 || len(*opt.DefaultBranchProtectionDefaults.AllowedToPush) > 1) { - return nil, nil, fmt.Errorf("multiple access levels for allowed_to_merge or allowed_to_push are not permitted when an Avatar is also specified as it will result in unexpected behavior") + return nil, nil, errors.New("multiple access levels for allowed_to_merge or allowed_to_push are not permitted when an Avatar is also specified as it will result in unexpected behavior") } - req, err = s.client.UploadRequest( - http.MethodPut, - u, - opt.Avatar.Image, - opt.Avatar.Filename, - UploadAvatar, - opt, - options, - ) - } - if err != nil { - return nil, nil, err + reqOpts = append(reqOpts, withUpload(opt.Avatar.Image, opt.Avatar.Filename, UploadAvatar)) } - - g := new(Group) - resp, err := s.client.Do(req, g) - if err != nil { - return nil, resp, err - } - - return g, resp, nil + return do[*Group](s.client, reqOpts...) } // UploadAvatar uploads a group avatar. @@ -723,32 +594,12 @@ func (s *GroupsService) UpdateGroup(gid any, opt *UpdateGroupOptions, options .. // GitLab API docs: // https://docs.gitlab.com/api/groups/#upload-a-group-avatar func (s *GroupsService) UploadAvatar(gid any, avatar io.Reader, filename string, options ...RequestOptionFunc) (*Group, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s", PathEscape(group)) - - req, err := s.client.UploadRequest( - http.MethodPut, - u, - avatar, - filename, - UploadAvatar, - nil, - options, + return do[*Group](s.client, + withMethod(http.MethodPut), + withPath("groups/%s", GroupID{gid}), + withUpload(avatar, filename, UploadAvatar), + withRequestOpts(options...), ) - if err != nil { - return nil, nil, err - } - - g := new(Group) - resp, err := s.client.Do(req, g) - if err != nil { - return nil, resp, err - } - - return g, resp, nil } // DeleteGroupOptions represents the available DeleteGroup() options. @@ -763,18 +614,13 @@ type DeleteGroupOptions struct { // // GitLab API docs: https://docs.gitlab.com/api/groups/#delete-a-group func (s *GroupsService) DeleteGroup(gid any, opt *DeleteGroupOptions, options ...RequestOptionFunc) (*Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("groups/%s", PathEscape(group)) - - req, err := s.client.NewRequest(http.MethodDelete, u, opt, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("groups/%s", GroupID{gid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) + return resp, err } // RestoreGroup restores a previously deleted group @@ -782,24 +628,11 @@ func (s *GroupsService) DeleteGroup(gid any, opt *DeleteGroupOptions, options .. // GitLab API docs: // https://docs.gitlab.com/api/groups/#restore-a-group-marked-for-deletion func (s *GroupsService) RestoreGroup(gid any, options ...RequestOptionFunc) (*Group, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/restore", PathEscape(group)) - - req, err := s.client.NewRequest(http.MethodPost, u, nil, options) - if err != nil { - return nil, nil, err - } - - g := new(Group) - resp, err := s.client.Do(req, g) - if err != nil { - return nil, resp, err - } - - return g, resp, nil + return do[*Group](s.client, + withMethod(http.MethodPost), + withPath("groups/%s/restore", GroupID{gid}), + withRequestOpts(options...), + ) } // SearchGroup get all groups that match your string in their name or path. @@ -811,18 +644,11 @@ func (s *GroupsService) SearchGroup(query string, options ...RequestOptionFunc) } q.Search = query - req, err := s.client.NewRequest(http.MethodGet, "groups", &q, options) - if err != nil { - return nil, nil, err - } - - var gs []*Group - resp, err := s.client.Do(req, &gs) - if err != nil { - return nil, resp, err - } - - return gs, resp, nil + return do[[]*Group](s.client, + withPath("groups"), + withAPIOpts(&q), + withRequestOpts(options...), + ) } // ListProvisionedUsersOptions represents the available ListProvisionedUsers() @@ -845,24 +671,11 @@ type ListProvisionedUsersOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/groups/#list-provisioned-users func (s *GroupsService) ListProvisionedUsers(gid any, opt *ListProvisionedUsersOptions, options ...RequestOptionFunc) ([]*User, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/provisioned_users", PathEscape(group)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var us []*User - resp, err := s.client.Do(req, &us) - if err != nil { - return nil, resp, err - } - - return us, resp, nil + return do[[]*User](s.client, + withPath("groups/%s/provisioned_users", GroupID{gid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // ListGroupLDAPLinks lists the group's LDAP links. Available only for users who @@ -871,24 +684,10 @@ func (s *GroupsService) ListProvisionedUsers(gid any, opt *ListProvisionedUsersO // GitLab API docs: // https://docs.gitlab.com/api/group_ldap_links/#list-ldap-group-links func (s *GroupsService) ListGroupLDAPLinks(gid any, options ...RequestOptionFunc) ([]*LDAPGroupLink, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/ldap_group_links", PathEscape(group)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - var gls []*LDAPGroupLink - resp, err := s.client.Do(req, &gls) - if err != nil { - return nil, resp, err - } - - return gls, resp, nil + return do[[]*LDAPGroupLink](s.client, + withPath("groups/%s/ldap_group_links", GroupID{gid}), + withRequestOpts(options...), + ) } // AddGroupLDAPLinkOptions represents the available AddGroupLDAPLink() options. @@ -909,24 +708,12 @@ type AddGroupLDAPLinkOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/group_ldap_links/#add-an-ldap-group-link-with-cn-or-filter func (s *GroupsService) AddGroupLDAPLink(gid any, opt *AddGroupLDAPLinkOptions, options ...RequestOptionFunc) (*LDAPGroupLink, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/ldap_group_links", PathEscape(group)) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - gl := new(LDAPGroupLink) - resp, err := s.client.Do(req, gl) - if err != nil { - return nil, resp, err - } - - return gl, resp, nil + return do[*LDAPGroupLink](s.client, + withMethod(http.MethodPost), + withPath("groups/%s/ldap_group_links", GroupID{gid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // DeleteGroupLDAPLink deletes a group LDAP link. Available only for users who @@ -936,18 +723,12 @@ func (s *GroupsService) AddGroupLDAPLink(gid any, opt *AddGroupLDAPLinkOptions, // GitLab API docs: // https://docs.gitlab.com/api/group_ldap_links/#delete-an-ldap-group-link-deprecated func (s *GroupsService) DeleteGroupLDAPLink(gid any, cn string, options ...RequestOptionFunc) (*Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("groups/%s/ldap_group_links/%s", PathEscape(group), PathEscape(cn)) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("groups/%s/ldap_group_links/%s", GroupID{gid}, cn), + withRequestOpts(options...), + ) + return resp, err } // DeleteGroupLDAPLinkWithCNOrFilterOptions represents the available DeleteGroupLDAPLinkWithCNOrFilter() options. @@ -966,18 +747,13 @@ type DeleteGroupLDAPLinkWithCNOrFilterOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/group_ldap_links/#delete-an-ldap-group-link-with-cn-or-filter func (s *GroupsService) DeleteGroupLDAPLinkWithCNOrFilter(gid any, opts *DeleteGroupLDAPLinkWithCNOrFilterOptions, options ...RequestOptionFunc) (*Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("groups/%s/ldap_group_links", PathEscape(group)) - - req, err := s.client.NewRequest(http.MethodDelete, u, opts, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("groups/%s/ldap_group_links", GroupID{gid}), + withAPIOpts(opts), + withRequestOpts(options...), + ) + return resp, err } // DeleteGroupLDAPLinkForProvider deletes a group LDAP link from a specific @@ -986,23 +762,12 @@ func (s *GroupsService) DeleteGroupLDAPLinkWithCNOrFilter(gid any, opts *DeleteG // GitLab API docs: // https://docs.gitlab.com/api/group_ldap_links/#delete-an-ldap-group-link-deprecated func (s *GroupsService) DeleteGroupLDAPLinkForProvider(gid any, provider, cn string, options ...RequestOptionFunc) (*Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, err - } - u := fmt.Sprintf( - "groups/%s/ldap_group_links/%s/%s", - PathEscape(group), - PathEscape(provider), - PathEscape(cn), + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("groups/%s/ldap_group_links/%s/%s", GroupID{gid}, provider, cn), + withRequestOpts(options...), ) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + return resp, err } // ListGroupSAMLLinks lists the group's SAML links. Available only for users who @@ -1011,24 +776,10 @@ func (s *GroupsService) DeleteGroupLDAPLinkForProvider(gid any, provider, cn str // GitLab API docs: // https://docs.gitlab.com/api/saml/#list-saml-group-links func (s *GroupsService) ListGroupSAMLLinks(gid any, options ...RequestOptionFunc) ([]*SAMLGroupLink, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/saml_group_links", PathEscape(group)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - var gl []*SAMLGroupLink - resp, err := s.client.Do(req, &gl) - if err != nil { - return nil, resp, err - } - - return gl, resp, nil + return do[[]*SAMLGroupLink](s.client, + withPath("groups/%s/saml_group_links", GroupID{gid}), + withRequestOpts(options...), + ) } // ListGroupSharedProjectsOptions represents the available ListGroupSharedProjects() options. @@ -1055,24 +806,11 @@ type ListGroupSharedProjectsOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/groups/#list-shared-projects func (s *GroupsService) ListGroupSharedProjects(gid any, opt *ListGroupSharedProjectsOptions, options ...RequestOptionFunc) ([]*Project, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/projects/shared", PathEscape(group)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var p []*Project - resp, err := s.client.Do(req, &p) - if err != nil { - return nil, resp, err - } - - return p, resp, nil + return do[[]*Project](s.client, + withPath("groups/%s/projects/shared", GroupID{gid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // GetGroupSAMLLink get a specific group SAML link. Available only for users who @@ -1081,24 +819,10 @@ func (s *GroupsService) ListGroupSharedProjects(gid any, opt *ListGroupSharedPro // GitLab API docs: // https://docs.gitlab.com/api/saml/#get-a-saml-group-link func (s *GroupsService) GetGroupSAMLLink(gid any, samlGroupName string, options ...RequestOptionFunc) (*SAMLGroupLink, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/saml_group_links/%s", PathEscape(group), PathEscape(samlGroupName)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - gl := new(SAMLGroupLink) - resp, err := s.client.Do(req, &gl) - if err != nil { - return nil, resp, err - } - - return gl, resp, nil + return do[*SAMLGroupLink](s.client, + withPath("groups/%s/saml_group_links/%s", GroupID{gid}, samlGroupName), + withRequestOpts(options...), + ) } // AddGroupSAMLLinkOptions represents the available AddGroupSAMLLink() options. @@ -1117,24 +841,12 @@ type AddGroupSAMLLinkOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/saml/#add-a-saml-group-link func (s *GroupsService) AddGroupSAMLLink(gid any, opt *AddGroupSAMLLinkOptions, options ...RequestOptionFunc) (*SAMLGroupLink, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/saml_group_links", PathEscape(group)) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - gl := new(SAMLGroupLink) - resp, err := s.client.Do(req, &gl) - if err != nil { - return nil, resp, err - } - - return gl, resp, nil + return do[*SAMLGroupLink](s.client, + withMethod(http.MethodPost), + withPath("groups/%s/saml_group_links", GroupID{gid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // DeleteGroupSAMLLink deletes a group SAML link. Available only for users who @@ -1143,18 +855,12 @@ func (s *GroupsService) AddGroupSAMLLink(gid any, opt *AddGroupSAMLLinkOptions, // GitLab API docs: // https://docs.gitlab.com/api/saml/#delete-a-saml-group-link func (s *GroupsService) DeleteGroupSAMLLink(gid any, samlGroupName string, options ...RequestOptionFunc) (*Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("groups/%s/saml_group_links/%s", PathEscape(group), PathEscape(samlGroupName)) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("groups/%s/saml_group_links/%s", GroupID{gid}, samlGroupName), + withRequestOpts(options...), + ) + return resp, err } // ShareGroupWithGroupOptions represents the available ShareGroupWithGroup() options. @@ -1173,24 +879,12 @@ type ShareGroupWithGroupOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/groups/#create-a-link-to-share-a-group-with-another-group func (s *GroupsService) ShareGroupWithGroup(gid any, opt *ShareGroupWithGroupOptions, options ...RequestOptionFunc) (*Group, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/share", PathEscape(group)) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - g := new(Group) - resp, err := s.client.Do(req, g) - if err != nil { - return nil, resp, err - } - - return g, resp, nil + return do[*Group](s.client, + withMethod(http.MethodPost), + withPath("groups/%s/share", GroupID{gid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // UnshareGroupFromGroup unshares a group from another group. @@ -1198,18 +892,12 @@ func (s *GroupsService) ShareGroupWithGroup(gid any, opt *ShareGroupWithGroupOpt // GitLab API docs: // https://docs.gitlab.com/api/groups/#delete-the-link-that-shares-a-group-with-another-group func (s *GroupsService) UnshareGroupFromGroup(gid any, groupID int64, options ...RequestOptionFunc) (*Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("groups/%s/share/%d", PathEscape(group), groupID) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("groups/%s/share/%d", GroupID{gid}, groupID), + withRequestOpts(options...), + ) + return resp, err } // GroupPushRules represents a group push rule. @@ -1239,24 +927,10 @@ type GroupPushRules struct { // GitLab API docs: // https://docs.gitlab.com/api/group_push_rules/#get-the-push-rules-of-a-group func (s *GroupsService) GetGroupPushRules(gid any, options ...RequestOptionFunc) (*GroupPushRules, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/push_rule", PathEscape(group)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - gpr := new(GroupPushRules) - resp, err := s.client.Do(req, gpr) - if err != nil { - return nil, resp, err - } - - return gpr, resp, nil + return do[*GroupPushRules](s.client, + withPath("groups/%s/push_rule", GroupID{gid}), + withRequestOpts(options...), + ) } // AddGroupPushRuleOptions represents the available AddGroupPushRule() @@ -1285,24 +959,12 @@ type AddGroupPushRuleOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/group_push_rules/#add-push-rules-to-a-group func (s *GroupsService) AddGroupPushRule(gid any, opt *AddGroupPushRuleOptions, options ...RequestOptionFunc) (*GroupPushRules, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/push_rule", PathEscape(group)) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - gpr := new(GroupPushRules) - resp, err := s.client.Do(req, gpr) - if err != nil { - return nil, resp, err - } - - return gpr, resp, nil + return do[*GroupPushRules](s.client, + withMethod(http.MethodPost), + withPath("groups/%s/push_rule", GroupID{gid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // EditGroupPushRuleOptions represents the available EditGroupPushRule() @@ -1331,24 +993,12 @@ type EditGroupPushRuleOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/group_push_rules/#edit-the-push-rules-of-a-group func (s *GroupsService) EditGroupPushRule(gid any, opt *EditGroupPushRuleOptions, options ...RequestOptionFunc) (*GroupPushRules, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/push_rule", PathEscape(group)) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - gpr := new(GroupPushRules) - resp, err := s.client.Do(req, gpr) - if err != nil { - return nil, resp, err - } - - return gpr, resp, nil + return do[*GroupPushRules](s.client, + withMethod(http.MethodPut), + withPath("groups/%s/push_rule", GroupID{gid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // DeleteGroupPushRule deletes the push rules of a group. @@ -1356,16 +1006,10 @@ func (s *GroupsService) EditGroupPushRule(gid any, opt *EditGroupPushRuleOptions // GitLab API docs: // https://docs.gitlab.com/api/group_push_rules/#delete-the-push-rules-of-a-group func (s *GroupsService) DeleteGroupPushRule(gid any, options ...RequestOptionFunc) (*Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("groups/%s/push_rule", PathEscape(group)) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("groups/%s/push_rule", GroupID{gid}), + withRequestOpts(options...), + ) + return resp, err } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/instance_clusters.go b/vendor/gitlab.com/gitlab-org/api/client-go/instance_clusters.go index ae143e20..cc06e9db 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/instance_clusters.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/instance_clusters.go @@ -17,7 +17,6 @@ package gitlab import ( - "fmt" "net/http" "time" ) @@ -81,20 +80,10 @@ func (v InstanceCluster) String() string { // GitLab API docs: // https://docs.gitlab.com/api/instance_clusters/#list-instance-clusters func (s *InstanceClustersService) ListClusters(options ...RequestOptionFunc) ([]*InstanceCluster, *Response, error) { - u := "admin/clusters" - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - var ics []*InstanceCluster - resp, err := s.client.Do(req, &ics) - if err != nil { - return nil, resp, err - } - - return ics, resp, nil + return do[[]*InstanceCluster](s.client, + withPath("admin/clusters"), + withRequestOpts(options...), + ) } // GetCluster gets an instance cluster. @@ -103,20 +92,10 @@ func (s *InstanceClustersService) ListClusters(options ...RequestOptionFunc) ([] // GitLab API docs: // https://docs.gitlab.com/api/instance_clusters/#get-a-single-instance-cluster func (s *InstanceClustersService) GetCluster(cluster int64, options ...RequestOptionFunc) (*InstanceCluster, *Response, error) { - u := fmt.Sprintf("admin/clusters/%d", cluster) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - ic := new(InstanceCluster) - resp, err := s.client.Do(req, &ic) - if err != nil { - return nil, resp, err - } - - return ic, resp, nil + return do[*InstanceCluster](s.client, + withPath("admin/clusters/%d", cluster), + withRequestOpts(options...), + ) } // AddCluster adds an existing cluster to the instance. @@ -125,20 +104,12 @@ func (s *InstanceClustersService) GetCluster(cluster int64, options ...RequestOp // GitLab API docs: // https://docs.gitlab.com/api/instance_clusters/#add-existing-instance-cluster func (s *InstanceClustersService) AddCluster(opt *AddClusterOptions, options ...RequestOptionFunc) (*InstanceCluster, *Response, error) { - u := "admin/clusters/add" - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - ic := new(InstanceCluster) - resp, err := s.client.Do(req, ic) - if err != nil { - return nil, resp, err - } - - return ic, resp, nil + return do[*InstanceCluster](s.client, + withMethod(http.MethodPost), + withPath("admin/clusters/add"), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // EditCluster updates an existing instance cluster. @@ -147,20 +118,12 @@ func (s *InstanceClustersService) AddCluster(opt *AddClusterOptions, options ... // GitLab API docs: // https://docs.gitlab.com/api/instance_clusters/#edit-instance-cluster func (s *InstanceClustersService) EditCluster(cluster int64, opt *EditClusterOptions, options ...RequestOptionFunc) (*InstanceCluster, *Response, error) { - u := fmt.Sprintf("admin/clusters/%d", cluster) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - ic := new(InstanceCluster) - resp, err := s.client.Do(req, ic) - if err != nil { - return nil, resp, err - } - - return ic, resp, nil + return do[*InstanceCluster](s.client, + withMethod(http.MethodPut), + withPath("admin/clusters/%d", cluster), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // DeleteCluster deletes an existing instance cluster. @@ -169,12 +132,10 @@ func (s *InstanceClustersService) EditCluster(cluster int64, opt *EditClusterOpt // GitLab API docs: // https://docs.gitlab.com/api/instance_clusters/#delete-instance-cluster func (s *InstanceClustersService) DeleteCluster(cluster int64, options ...RequestOptionFunc) (*Response, error) { - u := fmt.Sprintf("admin/clusters/%d", cluster) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("admin/clusters/%d", cluster), + withRequestOpts(options...), + ) + return resp, err } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/instance_variables.go b/vendor/gitlab.com/gitlab-org/api/client-go/instance_variables.go index d5b6fd1b..2a4c05c3 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/instance_variables.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/instance_variables.go @@ -17,17 +17,36 @@ package gitlab import ( - "fmt" "net/http" "net/url" ) type ( InstanceVariablesServiceInterface interface { + // ListVariables gets a list of all variables for an instance. + // + // GitLab API docs: + // https://docs.gitlab.com/api/instance_level_ci_variables/#list-all-instance-variables ListVariables(opt *ListInstanceVariablesOptions, options ...RequestOptionFunc) ([]*InstanceVariable, *Response, error) + // GetVariable gets a variable. + // + // GitLab API docs: + // https://docs.gitlab.com/api/instance_level_ci_variables/#show-instance-variable-details GetVariable(key string, options ...RequestOptionFunc) (*InstanceVariable, *Response, error) + // CreateVariable creates a new instance level CI variable. + // + // GitLab API docs: + // https://docs.gitlab.com/api/instance_level_ci_variables/#create-instance-variable CreateVariable(opt *CreateInstanceVariableOptions, options ...RequestOptionFunc) (*InstanceVariable, *Response, error) + // UpdateVariable updates an existing instance level CI variable. + // + // GitLab API docs: + // https://docs.gitlab.com/api/instance_level_ci_variables/#update-instance-variable UpdateVariable(key string, opt *UpdateInstanceVariableOptions, options ...RequestOptionFunc) (*InstanceVariable, *Response, error) + // RemoveVariable removes an instance level CI variable. + // + // GitLab API docs: + // https://docs.gitlab.com/api/instance_level_ci_variables/#remove-instance-variable RemoveVariable(key string, options ...RequestOptionFunc) (*Response, error) } @@ -70,46 +89,19 @@ type ListInstanceVariablesOptions struct { ListOptions } -// ListVariables gets a list of all variables for an instance. -// -// GitLab API docs: -// https://docs.gitlab.com/api/instance_level_ci_variables/#list-all-instance-variables func (s *InstanceVariablesService) ListVariables(opt *ListInstanceVariablesOptions, options ...RequestOptionFunc) ([]*InstanceVariable, *Response, error) { - u := "admin/ci/variables" - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var vs []*InstanceVariable - resp, err := s.client.Do(req, &vs) - if err != nil { - return nil, resp, err - } - - return vs, resp, nil + return do[[]*InstanceVariable](s.client, + withPath("admin/ci/variables"), + withAPIOpts(opt), + withRequestOpts(options...), + ) } -// GetVariable gets a variable. -// -// GitLab API docs: -// https://docs.gitlab.com/api/instance_level_ci_variables/#show-instance-variable-details func (s *InstanceVariablesService) GetVariable(key string, options ...RequestOptionFunc) (*InstanceVariable, *Response, error) { - u := fmt.Sprintf("admin/ci/variables/%s", url.PathEscape(key)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - v := new(InstanceVariable) - resp, err := s.client.Do(req, v) - if err != nil { - return nil, resp, err - } - - return v, resp, nil + return do[*InstanceVariable](s.client, + withPath("admin/ci/variables/%s", url.PathEscape(key)), + withRequestOpts(options...), + ) } // CreateInstanceVariableOptions represents the available CreateVariable() @@ -127,25 +119,13 @@ type CreateInstanceVariableOptions struct { VariableType *VariableTypeValue `url:"variable_type,omitempty" json:"variable_type,omitempty"` } -// CreateVariable creates a new instance level CI variable. -// -// GitLab API docs: -// https://docs.gitlab.com/api/instance_level_ci_variables/#create-instance-variable func (s *InstanceVariablesService) CreateVariable(opt *CreateInstanceVariableOptions, options ...RequestOptionFunc) (*InstanceVariable, *Response, error) { - u := "admin/ci/variables" - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - v := new(InstanceVariable) - resp, err := s.client.Do(req, v) - if err != nil { - return nil, resp, err - } - - return v, resp, nil + return do[*InstanceVariable](s.client, + withMethod(http.MethodPost), + withPath("admin/ci/variables"), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // UpdateInstanceVariableOptions represents the available UpdateVariable() @@ -162,39 +142,20 @@ type UpdateInstanceVariableOptions struct { VariableType *VariableTypeValue `url:"variable_type,omitempty" json:"variable_type,omitempty"` } -// UpdateVariable updates the position of an existing -// instance level CI variable. -// -// GitLab API docs: -// https://docs.gitlab.com/api/instance_level_ci_variables/#update-instance-variable func (s *InstanceVariablesService) UpdateVariable(key string, opt *UpdateInstanceVariableOptions, options ...RequestOptionFunc) (*InstanceVariable, *Response, error) { - u := fmt.Sprintf("admin/ci/variables/%s", url.PathEscape(key)) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - v := new(InstanceVariable) - resp, err := s.client.Do(req, v) - if err != nil { - return nil, resp, err - } - - return v, resp, nil + return do[*InstanceVariable](s.client, + withMethod(http.MethodPut), + withPath("admin/ci/variables/%s", url.PathEscape(key)), + withAPIOpts(opt), + withRequestOpts(options...), + ) } -// RemoveVariable removes an instance level CI variable. -// -// GitLab API docs: -// https://docs.gitlab.com/api/instance_level_ci_variables/#remove-instance-variable func (s *InstanceVariablesService) RemoveVariable(key string, options ...RequestOptionFunc) (*Response, error) { - u := fmt.Sprintf("admin/ci/variables/%s", url.PathEscape(key)) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("admin/ci/variables/%s", url.PathEscape(key)), + withRequestOpts(options...), + ) + return resp, err } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/integrations.go b/vendor/gitlab.com/gitlab-org/api/client-go/integrations.go index 9eeb3906..f1452633 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/integrations.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/integrations.go @@ -83,6 +83,110 @@ type ( // GitLab API docs: // https://docs.gitlab.com/api/group_integrations/#get-jira-settings GetGroupJiraSettings(gid any, options ...RequestOptionFunc) (*Integration, *Response, error) + + // GetGroupSlackSettings gets the Slack integration for a group. + // + // GitLab API docs: + // https://docs.gitlab.com/api/group_integrations/#get-slack-settings + GetGroupSlackSettings(gid any, options ...RequestOptionFunc) (*SlackIntegration, *Response, error) + + // SetGroupSlackSettings sets up the Slack integration for a group. + // + // GitLab API docs: + // https://docs.gitlab.com/api/group_integrations/#set-up-slack + SetGroupSlackSettings(gid any, opt *SetGroupSlackOptions, options ...RequestOptionFunc) (*SlackIntegration, *Response, error) + + // DisableGroupSlack disables the Slack integration for a group. + // Integration settings are reset. + // + // GitLab API docs: + // https://docs.gitlab.com/api/group_integrations/#disable-slack + DisableGroupSlack(gid any, options ...RequestOptionFunc) (*Response, error) + + // GetGroupDiscordSettings gets the Discord integration settings for a group. + // + // GitLab API docs: + // https://docs.gitlab.com/api/group_integrations/#discord + GetGroupDiscordSettings(gid any, options ...RequestOptionFunc) (*DiscordIntegration, *Response, error) + + // GetGroupTelegramSettings gets the Telegram integration settings for a group. + // + // GitLab API docs: + // https://docs.gitlab.com/api/group_integrations/#telegram + GetGroupTelegramSettings(gid any, options ...RequestOptionFunc) (*TelegramIntegration, *Response, error) + + // GetGroupMattermostSettings gets the Mattermost integration settings for a group. + // + // GitLab API docs: + // https://docs.gitlab.com/api/group_integrations/#mattermost-notifications + GetGroupMattermostSettings(gid any, options ...RequestOptionFunc) (*MattermostIntegration, *Response, error) + + // GetGroupMatrixSettings gets the Matrix integration settings for a group. + // + // GitLab API docs: + // https://docs.gitlab.com/api/group_integrations/#matrix-notifications + GetGroupMatrixSettings(gid any, options ...RequestOptionFunc) (*MatrixIntegration, *Response, error) + + // GetGroupGoogleChatSettings gets the Google Chat integration settings for a group. + // + // GitLab API docs: + // https://docs.gitlab.com/api/group_integrations/#google-chat + GetGroupGoogleChatSettings(gid any, options ...RequestOptionFunc) (*GoogleChatIntegration, *Response, error) + + // GetGroupMattermostIntegration retrieves the Mattermost integration for a group. + // + // GitLab API docs: + // https://docs.gitlab.com/api/group_integrations/#mattermost-notifications + GetGroupMattermostIntegration(gid any, options ...RequestOptionFunc) (*GroupMattermostIntegration, *Response, error) + + // SetGroupMattermostIntegration creates or updates the Mattermost integration for a group. + // + // GitLab API docs: + // https://docs.gitlab.com/api/group_integrations/#mattermost-notifications + SetGroupMattermostIntegration(gid any, opt *GroupMattermostIntegrationOptions, options ...RequestOptionFunc) (*GroupMattermostIntegration, *Response, error) + + // DeleteGroupMattermostIntegration removes the Mattermost integration from a group. + // + // GitLab API docs: + // https://docs.gitlab.com/api/group_integrations/#mattermost-notifications + DeleteGroupMattermostIntegration(gid any, options ...RequestOptionFunc) (*Response, error) + + // GetGroupMattermostSlashCommandsIntegration retrieves the Mattermost slash commands integration for a group. + // + // GitLab API docs: + // https://docs.gitlab.com/api/group_integrations/#mattermost-slash-commands + GetGroupMattermostSlashCommandsIntegration(gid any, options ...RequestOptionFunc) (*GroupMattermostSlashCommandsIntegration, *Response, error) + + // SetGroupMattermostSlashCommandsIntegration creates or updates the Mattermost slash commands integration for a group. + // + // GitLab API docs: + // https://docs.gitlab.com/api/group_integrations/#mattermost-slash-commands + SetGroupMattermostSlashCommandsIntegration(gid any, opt *GroupMattermostSlashCommandsIntegrationOptions, options ...RequestOptionFunc) (*GroupMattermostSlashCommandsIntegration, *Response, error) + + // DeleteGroupMattermostSlashCommandsIntegration removes the Mattermost slash commands integration from a group. + // + // GitLab API docs: + // https://docs.gitlab.com/api/group_integrations/#mattermost-slash-commands + DeleteGroupMattermostSlashCommandsIntegration(gid any, options ...RequestOptionFunc) (*Response, error) + + // GetGroupWebexTeamsSettings gets the Webex Teams integration for a group. + // + // GitLab API docs: + // https://docs.gitlab.com/api/group_integrations/#get-webex-teams-settings + GetGroupWebexTeamsSettings(gid any, options ...RequestOptionFunc) (*WebexTeamsIntegration, *Response, error) + + // SetGroupWebexTeamsSettings sets up the Webex Teams integration for a group. + // + // GitLab API docs: + // https://docs.gitlab.com/api/group_integrations/#set-up-webex-teams + SetGroupWebexTeamsSettings(gid any, opt *SetGroupWebexTeamsOptions, options ...RequestOptionFunc) (*WebexTeamsIntegration, *Response, error) + + // DisableGroupWebexTeams disables the Webex Teams integration for a group. + // Integration settings are reset. + // + // GitLab API docs: + // https://docs.gitlab.com/api/group_integrations/#disable-webex-teams + DisableGroupWebexTeams(gid any, options ...RequestOptionFunc) (*Response, error) } // IntegrationsService handles communication with the group @@ -129,6 +233,163 @@ type Integration struct { Inherited bool `json:"inherited"` } +// SlackIntegration represents the Slack integration settings. +// It embeds the generic Integration struct and adds Slack-specific properties. +// +// GitLab API docs: +// https://docs.gitlab.com/api/group_integrations/#get-slack-settings +type SlackIntegration struct { + Integration + Properties SlackIntegrationProperties `json:"properties"` +} + +// SlackIntegrationProperties represents Slack specific properties +// returned by the GitLab API. +// +// GitLab API docs: +// https://docs.gitlab.com/api/group_integrations/#get-slack-settings +type SlackIntegrationProperties struct { + Username string `json:"username"` + Channel string `json:"channel"` + NotifyOnlyBrokenPipelines bool `json:"notify_only_broken_pipelines"` + BranchesToBeNotified string `json:"branches_to_be_notified"` + LabelsToBeNotified string `json:"labels_to_be_notified"` + LabelsToBeNotifiedBehavior string `json:"labels_to_be_notified_behavior"` + PushChannel string `json:"push_channel"` + IssueChannel string `json:"issue_channel"` + ConfidentialIssueChannel string `json:"confidential_issue_channel"` + MergeRequestChannel string `json:"merge_request_channel"` + NoteChannel string `json:"note_channel"` + ConfidentialNoteChannel string `json:"confidential_note_channel"` + TagPushChannel string `json:"tag_push_channel"` + PipelineChannel string `json:"pipeline_channel"` + WikiPageChannel string `json:"wiki_page_channel"` + DeploymentChannel string `json:"deployment_channel"` + IncidentChannel string `json:"incident_channel"` + AlertChannel string `json:"alert_channel"` + GroupMentionChannel string `json:"group_mention_channel"` + GroupConfidentialMentionChannel string `json:"group_confidential_mention_channel"` +} + +// DiscordIntegration represents the Discord integration settings. +// +// GitLab API docs: +// https://docs.gitlab.com/api/group_integrations/#discord +type DiscordIntegration struct { + Integration + Properties DiscordIntegrationProperties `json:"properties"` +} + +// DiscordIntegrationProperties represents Discord specific properties. +type DiscordIntegrationProperties struct { + NotifyOnlyBrokenPipelines bool `json:"notify_only_broken_pipelines,omitempty"` + BranchesToBeNotified string `json:"branches_to_be_notified,omitempty"` +} + +// TelegramIntegration represents the Telegram integration settings. +// +// GitLab API docs: +// https://docs.gitlab.com/api/group_integrations/#telegram +type TelegramIntegration struct { + Integration + Properties TelegramIntegrationProperties `json:"properties"` +} + +// TelegramIntegrationProperties represents Telegram specific properties. +type TelegramIntegrationProperties struct { + Hostname string `json:"hostname,omitempty"` + Room string `json:"room,omitempty"` + Thread string `json:"thread,omitempty"` + NotifyOnlyBrokenPipelines bool `json:"notify_only_broken_pipelines,omitempty"` + BranchesToBeNotified string `json:"branches_to_be_notified,omitempty"` +} + +// MattermostIntegration represents the Mattermost integration settings. +// +// GitLab API docs: +// https://docs.gitlab.com/api/group_integrations/#mattermost-notifications +type MattermostIntegration struct { + Integration + Properties MattermostIntegrationProperties `json:"properties"` +} + +// MattermostIntegrationProperties represents Mattermost specific properties. +type MattermostIntegrationProperties struct { + Username string `json:"username,omitempty"` + Channel string `json:"channel,omitempty"` + NotifyOnlyBrokenPipelines bool `json:"notify_only_broken_pipelines,omitempty"` + BranchesToBeNotified string `json:"branches_to_be_notified,omitempty"` + LabelsToBeNotified string `json:"labels_to_be_notified,omitempty"` + LabelsToBeNotifiedBehavior string `json:"labels_to_be_notified_behavior,omitempty"` + PushChannel string `json:"push_channel,omitempty"` + IssueChannel string `json:"issue_channel,omitempty"` + ConfidentialIssueChannel string `json:"confidential_issue_channel,omitempty"` + MergeRequestChannel string `json:"merge_request_channel,omitempty"` + NoteChannel string `json:"note_channel,omitempty"` + ConfidentialNoteChannel string `json:"confidential_note_channel,omitempty"` + TagPushChannel string `json:"tag_push_channel,omitempty"` + PipelineChannel string `json:"pipeline_channel,omitempty"` + WikiPageChannel string `json:"wiki_page_channel,omitempty"` + DeploymentChannel string `json:"deployment_channel,omitempty"` + IncidentChannel string `json:"incident_channel,omitempty"` +} + +// MatrixIntegration represents the Matrix integration settings. +// +// GitLab API docs: +// https://docs.gitlab.com/api/group_integrations/#matrix-notifications +type MatrixIntegration struct { + Integration + Properties MatrixIntegrationProperties `json:"properties"` +} + +// MatrixIntegrationProperties represents Matrix specific properties. +type MatrixIntegrationProperties struct { + Hostname string `json:"hostname,omitempty"` + Room string `json:"room,omitempty"` + NotifyOnlyBrokenPipelines bool `json:"notify_only_broken_pipelines,omitempty"` + BranchesToBeNotified string `json:"branches_to_be_notified,omitempty"` +} + +// GoogleChatIntegration represents the Google Chat integration settings. +// +// GitLab API docs: +// https://docs.gitlab.com/api/group_integrations/#google-chat +type GoogleChatIntegration struct { + Integration + Properties GoogleChatIntegrationProperties `json:"properties"` +} + +// GoogleChatIntegrationProperties represents Google Chat specific properties. +type GoogleChatIntegrationProperties struct { + NotifyOnlyBrokenPipelines bool `json:"notify_only_broken_pipelines,omitempty"` + BranchesToBeNotified string `json:"branches_to_be_notified,omitempty"` +} + +// WebexTeamsIntegration represents the WebexTeams integration settings. +// +// GitLab API docs: +// https://docs.gitlab.com/api/group_integrations/#get-webex-teams-settings +type WebexTeamsIntegration struct { + Integration + Properties WebexTeamsIntegrationProperties `json:"properties"` +} + +// WebexTeamsIntegrationProperties represents WebexTeams specific properties +type WebexTeamsIntegrationProperties struct { + NotifyOnlyBrokenPipelines bool `json:"notify_only_broken_pipelines,omitempty"` + BranchesToBeNotified string `json:"branches_to_be_notified,omitempty"` +} + +// SetGroupWebexTeamsOptions represents the available SetGroupWebexTeamsSettings() options. +// +// GitLab API docs: +// https://docs.gitlab.com/api/group_integrations/#set-up-webex-teams +type SetGroupWebexTeamsOptions struct { + NotifyOnlyBrokenPipelines *bool `url:"notify_only_broken_pipelines,omitempty" json:"notify_only_broken_pipelines,omitempty"` + BranchesToBeNotified *string `url:"branches_to_be_notified,omitempty" json:"branches_to_be_notified,omitempty"` +} + // ListActiveIntegrationsOptions represents the available // ListActiveIntegrations() options. // @@ -216,7 +477,7 @@ type SetMicrosoftTeamsNotificationsOptions struct { func (s *IntegrationsService) SetGroupMicrosoftTeamsNotifications(gid any, opt *SetMicrosoftTeamsNotificationsOptions, options ...RequestOptionFunc) (*Integration, *Response, error) { return do[*Integration]( s.client, - withPath("groups/%s/integrations/microsoft_teams", GroupID{gid}), + withPath("groups/%s/integrations/microsoft-teams", GroupID{gid}), withMethod(http.MethodPut), withAPIOpts(opt), withRequestOpts(options...), @@ -226,7 +487,7 @@ func (s *IntegrationsService) SetGroupMicrosoftTeamsNotifications(gid any, opt * func (s *IntegrationsService) DisableGroupMicrosoftTeamsNotifications(gid any, options ...RequestOptionFunc) (*Response, error) { _, resp, err := do[none]( s.client, - withPath("groups/%s/integrations/microsoft_teams", GroupID{gid}), + withPath("groups/%s/integrations/microsoft-teams", GroupID{gid}), withMethod(http.MethodDelete), withRequestOpts(options...), ) @@ -236,7 +497,7 @@ func (s *IntegrationsService) DisableGroupMicrosoftTeamsNotifications(gid any, o func (s *IntegrationsService) GetGroupMicrosoftTeamsNotifications(gid any, options ...RequestOptionFunc) (*Integration, *Response, error) { return do[*Integration]( s.client, - withPath("groups/%s/integrations/microsoft_teams", GroupID{gid}), + withPath("groups/%s/integrations/microsoft-teams", GroupID{gid}), withMethod(http.MethodGet), withRequestOpts(options...), ) @@ -293,3 +554,134 @@ func (s *IntegrationsService) GetGroupJiraSettings(gid any, options ...RequestOp withRequestOpts(options...), ) } + +// SetGroupSlackOptions represents the available SetGroupSlackSettings() options. +// +// GitLab API docs: +// https://docs.gitlab.com/api/group_integrations/#set-up-slack +type SetGroupSlackOptions struct { + Webhook *string `url:"webhook,omitempty" json:"webhook,omitempty"` + Username *string `url:"username,omitempty" json:"username,omitempty"` + Channel *string `url:"channel,omitempty" json:"channel,omitempty"` + NotifyOnlyBrokenPipelines *bool `url:"notify_only_broken_pipelines,omitempty" json:"notify_only_broken_pipelines,omitempty"` + BranchesToBeNotified *string `url:"branches_to_be_notified,omitempty" json:"branches_to_be_notified,omitempty"` + LabelsToBeNotified *string `url:"labels_to_be_notified,omitempty" json:"labels_to_be_notified,omitempty"` + LabelsToBeNotifiedBehavior *string `url:"labels_to_be_notified_behavior,omitempty" json:"labels_to_be_notified_behavior,omitempty"` + PushChannel *string `url:"push_channel,omitempty" json:"push_channel,omitempty"` + IssueChannel *string `url:"issue_channel,omitempty" json:"issue_channel,omitempty"` + ConfidentialIssueChannel *string `url:"confidential_issue_channel,omitempty" json:"confidential_issue_channel,omitempty"` + MergeRequestChannel *string `url:"merge_request_channel,omitempty" json:"merge_request_channel,omitempty"` + NoteChannel *string `url:"note_channel,omitempty" json:"note_channel,omitempty"` + ConfidentialNoteChannel *string `url:"confidential_note_channel,omitempty" json:"confidential_note_channel,omitempty"` + TagPushChannel *string `url:"tag_push_channel,omitempty" json:"tag_push_channel,omitempty"` + PipelineChannel *string `url:"pipeline_channel,omitempty" json:"pipeline_channel,omitempty"` + WikiPageChannel *string `url:"wiki_page_channel,omitempty" json:"wiki_page_channel,omitempty"` + DeploymentChannel *string `url:"deployment_channel,omitempty" json:"deployment_channel,omitempty"` + IncidentChannel *string `url:"incident_channel,omitempty" json:"incident_channel,omitempty"` + AlertChannel *string `url:"alert_channel,omitempty" json:"alert_channel,omitempty"` + GroupMentionChannel *string `url:"group_mention_channel,omitempty" json:"group_mention_channel,omitempty"` + GroupConfidentialMentionChannel *string `url:"group_confidential_mention_channel,omitempty" json:"group_confidential_mention_channel,omitempty"` +} + +func (s *IntegrationsService) SetGroupSlackSettings(gid any, opt *SetGroupSlackOptions, options ...RequestOptionFunc) (*SlackIntegration, *Response, error) { + return do[*SlackIntegration]( + s.client, + withPath("groups/%s/integrations/slack", GroupID{gid}), + withMethod(http.MethodPut), + withAPIOpts(opt), + withRequestOpts(options...), + ) +} + +func (s *IntegrationsService) DisableGroupSlack(gid any, options ...RequestOptionFunc) (*Response, error) { + _, resp, err := do[none]( + s.client, + withPath("groups/%s/integrations/slack", GroupID{gid}), + withMethod(http.MethodDelete), + withRequestOpts(options...), + ) + return resp, err +} + +func (s *IntegrationsService) GetGroupSlackSettings(gid any, options ...RequestOptionFunc) (*SlackIntegration, *Response, error) { + return do[*SlackIntegration]( + s.client, + withPath("groups/%s/integrations/slack", GroupID{gid}), + withMethod(http.MethodGet), + withRequestOpts(options...), + ) +} + +func (s *IntegrationsService) GetGroupDiscordSettings(gid any, options ...RequestOptionFunc) (*DiscordIntegration, *Response, error) { + return do[*DiscordIntegration]( + s.client, + withPath("groups/%s/integrations/discord", GroupID{gid}), + withMethod(http.MethodGet), + withRequestOpts(options...), + ) +} + +func (s *IntegrationsService) GetGroupTelegramSettings(gid any, options ...RequestOptionFunc) (*TelegramIntegration, *Response, error) { + return do[*TelegramIntegration]( + s.client, + withPath("groups/%s/integrations/telegram", GroupID{gid}), + withMethod(http.MethodGet), + withRequestOpts(options...), + ) +} + +func (s *IntegrationsService) GetGroupMattermostSettings(gid any, options ...RequestOptionFunc) (*MattermostIntegration, *Response, error) { + return do[*MattermostIntegration]( + s.client, + withPath("groups/%s/integrations/mattermost", GroupID{gid}), + withMethod(http.MethodGet), + withRequestOpts(options...), + ) +} + +func (s *IntegrationsService) GetGroupMatrixSettings(gid any, options ...RequestOptionFunc) (*MatrixIntegration, *Response, error) { + return do[*MatrixIntegration]( + s.client, + withPath("groups/%s/integrations/matrix", GroupID{gid}), + withMethod(http.MethodGet), + withRequestOpts(options...), + ) +} + +func (s *IntegrationsService) GetGroupGoogleChatSettings(gid any, options ...RequestOptionFunc) (*GoogleChatIntegration, *Response, error) { + return do[*GoogleChatIntegration]( + s.client, + withPath("groups/%s/integrations/hangouts-chat", GroupID{gid}), + withMethod(http.MethodGet), + withRequestOpts(options...), + ) +} + +func (s *IntegrationsService) GetGroupWebexTeamsSettings(gid any, options ...RequestOptionFunc) (*WebexTeamsIntegration, *Response, error) { + return do[*WebexTeamsIntegration]( + s.client, + withPath("groups/%s/integrations/webex-teams", GroupID{gid}), + withMethod(http.MethodGet), + withRequestOpts(options...), + ) +} + +func (s *IntegrationsService) SetGroupWebexTeamsSettings(gid any, opt *SetGroupWebexTeamsOptions, options ...RequestOptionFunc) (*WebexTeamsIntegration, *Response, error) { + return do[*WebexTeamsIntegration]( + s.client, + withPath("groups/%s/integrations/webex-teams", GroupID{gid}), + withMethod(http.MethodPut), + withAPIOpts(opt), + withRequestOpts(options...), + ) +} + +func (s *IntegrationsService) DisableGroupWebexTeams(gid any, options ...RequestOptionFunc) (*Response, error) { + _, resp, err := do[none]( + s.client, + withPath("groups/%s/integrations/webex-teams", GroupID{gid}), + withMethod(http.MethodDelete), + withRequestOpts(options...), + ) + return resp, err +} diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/invites.go b/vendor/gitlab.com/gitlab-org/api/client-go/invites.go index e8ef7bde..5be8babe 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/invites.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/invites.go @@ -17,7 +17,6 @@ package gitlab import ( - "fmt" "net/http" "time" ) @@ -69,24 +68,11 @@ type ListPendingInvitationsOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/invitations/#list-all-invitations-pending-for-a-group-or-project func (s *InvitesService) ListPendingGroupInvitations(gid any, opt *ListPendingInvitationsOptions, options ...RequestOptionFunc) ([]*PendingInvite, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/invitations", PathEscape(group)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var pis []*PendingInvite - resp, err := s.client.Do(req, &pis) - if err != nil { - return nil, resp, err - } - - return pis, resp, nil + return do[[]*PendingInvite](s.client, + withPath("groups/%s/invitations", GroupID{gid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // ListPendingProjectInvitations gets a list of invited project members. @@ -94,24 +80,11 @@ func (s *InvitesService) ListPendingGroupInvitations(gid any, opt *ListPendingIn // GitLab API docs: // https://docs.gitlab.com/api/invitations/#list-all-invitations-pending-for-a-group-or-project func (s *InvitesService) ListPendingProjectInvitations(pid any, opt *ListPendingInvitationsOptions, options ...RequestOptionFunc) ([]*PendingInvite, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/invitations", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var pis []*PendingInvite - resp, err := s.client.Do(req, &pis) - if err != nil { - return nil, resp, err - } - - return pis, resp, nil + return do[[]*PendingInvite](s.client, + withPath("projects/%s/invitations", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // InvitesOptions represents the available GroupInvites() and ProjectInvites() @@ -141,24 +114,12 @@ type InvitesResult struct { // GitLab API docs: // https://docs.gitlab.com/api/invitations/#add-a-member-to-a-group-or-project func (s *InvitesService) GroupInvites(gid any, opt *InvitesOptions, options ...RequestOptionFunc) (*InvitesResult, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/invitations", PathEscape(group)) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - ir := new(InvitesResult) - resp, err := s.client.Do(req, ir) - if err != nil { - return nil, resp, err - } - - return ir, resp, nil + return do[*InvitesResult](s.client, + withMethod(http.MethodPost), + withPath("groups/%s/invitations", GroupID{gid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // ProjectInvites invites new users by email to join a project. @@ -166,22 +127,10 @@ func (s *InvitesService) GroupInvites(gid any, opt *InvitesOptions, options ...R // GitLab API docs: // https://docs.gitlab.com/api/invitations/#add-a-member-to-a-group-or-project func (s *InvitesService) ProjectInvites(pid any, opt *InvitesOptions, options ...RequestOptionFunc) (*InvitesResult, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/invitations", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - ir := new(InvitesResult) - resp, err := s.client.Do(req, ir) - if err != nil { - return nil, resp, err - } - - return ir, resp, nil + return do[*InvitesResult](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/invitations", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/issue_links.go b/vendor/gitlab.com/gitlab-org/api/client-go/issue_links.go index 1562e7c2..2cf4ce4b 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/issue_links.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/issue_links.go @@ -44,6 +44,7 @@ var _ IssueLinksServiceInterface = (*IssueLinksService)(nil) // // GitLab API docs: https://docs.gitlab.com/api/issue_links/ type IssueLink struct { + ID int64 `json:"id"` SourceIssue *Issue `json:"source_issue"` TargetIssue *Issue `json:"target_issue"` LinkType string `json:"link_type"` diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/issues.go b/vendor/gitlab.com/gitlab-org/api/client-go/issues.go index 63b3f01f..71aa93be 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/issues.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/issues.go @@ -389,10 +389,13 @@ func (s *IssuesService) GetIssue(pid any, issue int64, options ...RequestOptionF // // GitLab API docs: https://docs.gitlab.com/api/issues/#new-issue type CreateIssueOptions struct { - IID *int64 `url:"iid,omitempty" json:"iid,omitempty"` - Title *string `url:"title,omitempty" json:"title,omitempty"` - Description *string `url:"description,omitempty" json:"description,omitempty"` - Confidential *bool `url:"confidential,omitempty" json:"confidential,omitempty"` + IID *int64 `url:"iid,omitempty" json:"iid,omitempty"` + Title *string `url:"title,omitempty" json:"title,omitempty"` + Description *string `url:"description,omitempty" json:"description,omitempty"` + Confidential *bool `url:"confidential,omitempty" json:"confidential,omitempty"` + // AssigneeID is a CE-only attribute. For EE, use AssigneeIDs instead. + AssigneeID *int64 `url:"assignee_id,omitempty" json:"assignee_id,omitempty"` + // AssigneeIDs is a EE-only attribute. For CE, use AssigneeID instead. AssigneeIDs *[]int64 `url:"assignee_ids,omitempty" json:"assignee_ids,omitempty"` MilestoneID *int64 `url:"milestone_id,omitempty" json:"milestone_id,omitempty"` Labels *LabelOptions `url:"labels,comma,omitempty" json:"labels,omitempty"` @@ -424,9 +427,12 @@ func (s *IssuesService) CreateIssue(pid any, opt *CreateIssueOptions, options .. // // GitLab API docs: https://docs.gitlab.com/api/issues/#edit-an-issue type UpdateIssueOptions struct { - Title *string `url:"title,omitempty" json:"title,omitempty"` - Description *string `url:"description,omitempty" json:"description,omitempty"` - Confidential *bool `url:"confidential,omitempty" json:"confidential,omitempty"` + Title *string `url:"title,omitempty" json:"title,omitempty"` + Description *string `url:"description,omitempty" json:"description,omitempty"` + Confidential *bool `url:"confidential,omitempty" json:"confidential,omitempty"` + // AssigneeID is a CE-only attribute. For EE, use AssigneeIDs instead. + AssigneeID *int64 `url:"assignee_id,omitempty" json:"assignee_id,omitempty"` + // AssigneeIDs is a EE-only attribute. For CE, use AssigneeID instead. AssigneeIDs *[]int64 `url:"assignee_ids,omitempty" json:"assignee_ids,omitempty"` MilestoneID *int64 `url:"milestone_id,omitempty" json:"milestone_id,omitempty"` Labels *LabelOptions `url:"labels,comma,omitempty" json:"labels,omitempty"` diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/issues_statistics.go b/vendor/gitlab.com/gitlab-org/api/client-go/issues_statistics.go index 5a2df7b6..b3d13b18 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/issues_statistics.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/issues_statistics.go @@ -22,8 +22,21 @@ import ( type ( IssuesStatisticsServiceInterface interface { + // GetIssuesStatistics gets issues statistics on all issues the authenticated + // user has access to. + // + // GitLab API docs: + // https://docs.gitlab.com/api/issues_statistics/#get-issues-statistics GetIssuesStatistics(opt *GetIssuesStatisticsOptions, options ...RequestOptionFunc) (*IssuesStatistics, *Response, error) + // GetGroupIssuesStatistics gets issues count statistics for given group. + // + // GitLab API docs: + // https://docs.gitlab.com/api/issues_statistics/#get-group-issues-statistics GetGroupIssuesStatistics(gid any, opt *GetGroupIssuesStatisticsOptions, options ...RequestOptionFunc) (*IssuesStatistics, *Response, error) + // GetProjectIssuesStatistics gets issues count statistics for given project. + // + // GitLab API docs: + // https://docs.gitlab.com/api/issues_statistics/#get-project-issues-statistics GetProjectIssuesStatistics(pid any, opt *GetProjectIssuesStatisticsOptions, options ...RequestOptionFunc) (*IssuesStatistics, *Response, error) } @@ -88,11 +101,6 @@ type GetIssuesStatisticsOptions struct { Confidential *bool `url:"confidential,omitempty" json:"confidential,omitempty"` } -// GetIssuesStatistics gets issues statistics on all issues the authenticated -// user has access to. -// -// GitLab API docs: -// https://docs.gitlab.com/api/issues_statistics/#get-issues-statistics func (s *IssuesStatisticsService) GetIssuesStatistics(opt *GetIssuesStatisticsOptions, options ...RequestOptionFunc) (*IssuesStatistics, *Response, error) { return do[*IssuesStatistics](s.client, withPath("issues_statistics"), @@ -124,10 +132,6 @@ type GetGroupIssuesStatisticsOptions struct { Confidential *bool `url:"confidential,omitempty" json:"confidential,omitempty"` } -// GetGroupIssuesStatistics gets issues count statistics for given group. -// -// GitLab API docs: -// https://docs.gitlab.com/api/issues_statistics/#get-group-issues-statistics func (s *IssuesStatisticsService) GetGroupIssuesStatistics(gid any, opt *GetGroupIssuesStatisticsOptions, options ...RequestOptionFunc) (*IssuesStatistics, *Response, error) { return do[*IssuesStatistics](s.client, withPath("groups/%s/issues_statistics", GroupID{gid}), @@ -159,10 +163,6 @@ type GetProjectIssuesStatisticsOptions struct { Confidential *bool `url:"confidential,omitempty" json:"confidential,omitempty"` } -// GetProjectIssuesStatistics gets issues count statistics for given project. -// -// GitLab API docs: -// https://docs.gitlab.com/api/issues_statistics/#get-project-issues-statistics func (s *IssuesStatisticsService) GetProjectIssuesStatistics(pid any, opt *GetProjectIssuesStatisticsOptions, options ...RequestOptionFunc) (*IssuesStatistics, *Response, error) { return do[*IssuesStatistics](s.client, withPath("projects/%s/issues_statistics", ProjectID{pid}), diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/job_token_scope.go b/vendor/gitlab.com/gitlab-org/api/client-go/job_token_scope.go index e4ae3705..7d418a67 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/job_token_scope.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/job_token_scope.go @@ -14,10 +14,7 @@ package gitlab -import ( - "fmt" - "net/http" -) +import "net/http" type ( JobTokenScopeServiceInterface interface { @@ -54,24 +51,10 @@ type JobTokenAccessSettings struct { // GitLab API docs: // https://docs.gitlab.com/api/project_job_token_scopes/#get-a-projects-cicd-job-token-access-settings func (j *JobTokenScopeService) GetProjectJobTokenAccessSettings(pid any, options ...RequestOptionFunc) (*JobTokenAccessSettings, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf(`projects/%s/job_token_scope`, PathEscape(project)) - - req, err := j.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - jt := new(JobTokenAccessSettings) - resp, err := j.client.Do(req, jt) - if err != nil { - return nil, resp, err - } - - return jt, resp, err + return do[*JobTokenAccessSettings](j.client, + withPath("projects/%s/job_token_scope", ProjectID{pid}), + withRequestOpts(options...), + ) } // PatchProjectJobTokenAccessSettingsOptions represents the available @@ -88,18 +71,13 @@ type PatchProjectJobTokenAccessSettingsOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/project_job_token_scopes/#patch-a-projects-cicd-job-token-access-settings func (j *JobTokenScopeService) PatchProjectJobTokenAccessSettings(pid any, opt *PatchProjectJobTokenAccessSettingsOptions, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf(`projects/%s/job_token_scope`, PathEscape(project)) - - req, err := j.client.NewRequest(http.MethodPatch, u, opt, options) - if err != nil { - return nil, err - } - - return j.client.Do(req, nil) + _, resp, err := do[none](j.client, + withMethod(http.MethodPatch), + withPath("projects/%s/job_token_scope", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) + return resp, err } // JobTokenInboundAllowItem represents a single job token inbound allowlist item. @@ -125,24 +103,11 @@ type GetJobTokenInboundAllowListOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/project_job_token_scopes/#get-a-projects-cicd-job-token-inbound-allowlist func (j *JobTokenScopeService) GetProjectJobTokenInboundAllowList(pid any, opt *GetJobTokenInboundAllowListOptions, options ...RequestOptionFunc) ([]*Project, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf(`projects/%s/job_token_scope/allowlist`, PathEscape(project)) - - req, err := j.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var ps []*Project - resp, err := j.client.Do(req, &ps) - if err != nil { - return nil, resp, err - } - - return ps, resp, nil + return do[[]*Project](j.client, + withPath("projects/%s/job_token_scope/allowlist", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // JobTokenInboundAllowOptions represents the available @@ -160,24 +125,12 @@ type JobTokenInboundAllowOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/project_job_token_scopes/#add-a-project-to-a-cicd-job-token-inbound-allowlist func (j *JobTokenScopeService) AddProjectToJobScopeAllowList(pid any, opt *JobTokenInboundAllowOptions, options ...RequestOptionFunc) (*JobTokenInboundAllowItem, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf(`projects/%s/job_token_scope/allowlist`, PathEscape(project)) - - req, err := j.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - jt := new(JobTokenInboundAllowItem) - resp, err := j.client.Do(req, jt) - if err != nil { - return nil, resp, err - } - - return jt, resp, nil + return do[*JobTokenInboundAllowItem](j.client, + withMethod(http.MethodPost), + withPath("projects/%s/job_token_scope/allowlist", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // RemoveProjectFromJobScopeAllowList removes a project from a project's job @@ -186,18 +139,12 @@ func (j *JobTokenScopeService) AddProjectToJobScopeAllowList(pid any, opt *JobTo // GitLab API docs: // https://docs.gitlab.com/api/project_job_token_scopes/#remove-a-project-from-a-cicd-job-token-inbound-allowlist func (j *JobTokenScopeService) RemoveProjectFromJobScopeAllowList(pid any, targetProject int64, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf(`projects/%s/job_token_scope/allowlist/%d`, PathEscape(project), targetProject) - - req, err := j.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return j.client.Do(req, nil) + _, resp, err := do[none](j.client, + withMethod(http.MethodDelete), + withPath("projects/%s/job_token_scope/allowlist/%d", ProjectID{pid}, targetProject), + withRequestOpts(options...), + ) + return resp, err } // JobTokenAllowlistItem represents a single job token allowlist item. @@ -223,24 +170,11 @@ type GetJobTokenAllowlistGroupsOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/project_job_token_scopes/#get-a-projects-cicd-job-token-allowlist-of-groups func (j *JobTokenScopeService) GetJobTokenAllowlistGroups(pid any, opt *GetJobTokenAllowlistGroupsOptions, options ...RequestOptionFunc) ([]*Group, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf(`projects/%s/job_token_scope/groups_allowlist`, PathEscape(project)) - - req, err := j.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var ps []*Group - resp, err := j.client.Do(req, &ps) - if err != nil { - return nil, resp, err - } - - return ps, resp, nil + return do[[]*Group](j.client, + withPath("projects/%s/job_token_scope/groups_allowlist", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // AddGroupToJobTokenAllowlistOptions represents the available @@ -258,24 +192,12 @@ type AddGroupToJobTokenAllowlistOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/project_job_token_scopes/#add-a-group-to-a-cicd-job-token-allowlist func (j *JobTokenScopeService) AddGroupToJobTokenAllowlist(pid any, opt *AddGroupToJobTokenAllowlistOptions, options ...RequestOptionFunc) (*JobTokenAllowlistItem, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf(`projects/%s/job_token_scope/groups_allowlist`, PathEscape(project)) - - req, err := j.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - jt := new(JobTokenAllowlistItem) - resp, err := j.client.Do(req, jt) - if err != nil { - return nil, resp, err - } - - return jt, resp, nil + return do[*JobTokenAllowlistItem](j.client, + withMethod(http.MethodPost), + withPath("projects/%s/job_token_scope/groups_allowlist", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // RemoveGroupFromJobTokenAllowlist removes a group from a project's job @@ -284,16 +206,10 @@ func (j *JobTokenScopeService) AddGroupToJobTokenAllowlist(pid any, opt *AddGrou // GitLab API docs: // https://docs.gitlab.com/api/project_job_token_scopes/#remove-a-group-from-a-cicd-job-token-allowlist func (j *JobTokenScopeService) RemoveGroupFromJobTokenAllowlist(pid any, targetGroup int64, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf(`projects/%s/job_token_scope/groups_allowlist/%d`, PathEscape(project), targetGroup) - - req, err := j.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return j.client.Do(req, nil) + _, resp, err := do[none](j.client, + withMethod(http.MethodDelete), + withPath("projects/%s/job_token_scope/groups_allowlist/%d", ProjectID{pid}, targetGroup), + withRequestOpts(options...), + ) + return resp, err } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/jobs.go b/vendor/gitlab.com/gitlab-org/api/client-go/jobs.go index f7d5f015..de69815d 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/jobs.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/jobs.go @@ -24,22 +24,102 @@ import ( type ( JobsServiceInterface interface { + // ListProjectJobs gets a list of jobs in a project. + // + // The scope of jobs to show, one or array of: created, pending, running, + // failed, success, canceled, skipped; showing all jobs if none provided + // + // GitLab API docs: + // https://docs.gitlab.com/api/jobs/#list-project-jobs ListProjectJobs(pid any, opts *ListJobsOptions, options ...RequestOptionFunc) ([]*Job, *Response, error) + // ListPipelineJobs gets a list of jobs for specific pipeline in a + // project. If the pipeline ID is not found, it will respond with 404. + // + // GitLab API docs: + // https://docs.gitlab.com/api/jobs/#list-pipeline-jobs ListPipelineJobs(pid any, pipelineID int64, opts *ListJobsOptions, options ...RequestOptionFunc) ([]*Job, *Response, error) + // ListPipelineBridges gets a list of bridges for specific pipeline in a + // project. + // + // GitLab API docs: + // https://docs.gitlab.com/api/jobs/#list-pipeline-trigger-jobs ListPipelineBridges(pid any, pipelineID int64, opts *ListJobsOptions, options ...RequestOptionFunc) ([]*Bridge, *Response, error) + // GetJobTokensJob retrieves the job that generated a job token. + // + // GitLab API docs: https://docs.gitlab.com/api/jobs/#get-job-tokens-job GetJobTokensJob(opts *GetJobTokensJobOptions, options ...RequestOptionFunc) (*Job, *Response, error) + // GetJob gets a single job of a project. + // + // GitLab API docs: + // https://docs.gitlab.com/api/jobs/#get-a-single-job GetJob(pid any, jobID int64, options ...RequestOptionFunc) (*Job, *Response, error) + // GetJobArtifacts gets jobs artifacts of a project + // + // GitLab API docs: + // https://docs.gitlab.com/api/job_artifacts/#get-job-artifacts GetJobArtifacts(pid any, jobID int64, options ...RequestOptionFunc) (*bytes.Reader, *Response, error) + // DownloadArtifactsFile downloads the artifacts file from the given + // reference name and job provided the job finished successfully. + // + // GitLab API docs: + // https://docs.gitlab.com/api/job_artifacts/#download-the-artifacts-archive DownloadArtifactsFile(pid any, refName string, opt *DownloadArtifactsFileOptions, options ...RequestOptionFunc) (*bytes.Reader, *Response, error) + // DownloadSingleArtifactsFile downloads a file from the artifacts from the + // given reference name and job provided the job finished successfully. + // Only a single file is going to be extracted from the archive and streamed + // to a client. + // + // GitLab API docs: + // https://docs.gitlab.com/api/job_artifacts/#download-a-single-artifact-file-by-job-id DownloadSingleArtifactsFile(pid any, jobID int64, artifactPath string, options ...RequestOptionFunc) (*bytes.Reader, *Response, error) + // DownloadSingleArtifactsFileByTagOrBranch downloads a single file from + // a job's artifacts in the latest successful pipeline using the reference name. + // The file is extracted from the archive and streamed to the client. + // + // GitLab API docs: + // https://docs.gitlab.com/api/job_artifacts/#download-a-single-artifact-file-from-specific-tag-or-branch DownloadSingleArtifactsFileByTagOrBranch(pid any, refName string, artifactPath string, opt *DownloadArtifactsFileOptions, options ...RequestOptionFunc) (*bytes.Reader, *Response, error) + // GetTraceFile gets a trace of a specific job of a project + // + // GitLab API docs: + // https://docs.gitlab.com/api/jobs/#get-a-log-file GetTraceFile(pid any, jobID int64, options ...RequestOptionFunc) (*bytes.Reader, *Response, error) + // CancelJob cancels a single job of a project. + // + // GitLab API docs: + // https://docs.gitlab.com/api/jobs/#cancel-a-job CancelJob(pid any, jobID int64, options ...RequestOptionFunc) (*Job, *Response, error) + // RetryJob retries a single job of a project + // + // GitLab API docs: + // https://docs.gitlab.com/api/jobs/#retry-a-job RetryJob(pid any, jobID int64, options ...RequestOptionFunc) (*Job, *Response, error) + // EraseJob erases a single job of a project, removes a job + // artifacts and a job trace. + // + // GitLab API docs: + // https://docs.gitlab.com/api/jobs/#erase-a-job EraseJob(pid any, jobID int64, options ...RequestOptionFunc) (*Job, *Response, error) + // KeepArtifacts prevents artifacts from being deleted when + // expiration is set. + // + // GitLab API docs: + // https://docs.gitlab.com/api/job_artifacts/#keep-artifacts KeepArtifacts(pid any, jobID int64, options ...RequestOptionFunc) (*Job, *Response, error) + // PlayJob triggers a manual action to start a job. + // + // GitLab API docs: + // https://docs.gitlab.com/api/jobs/#run-a-job PlayJob(pid any, jobID int64, opt *PlayJobOptions, options ...RequestOptionFunc) (*Job, *Response, error) + // DeleteArtifacts deletes artifacts of a job + // + // GitLab API docs: + // https://docs.gitlab.com/api/job_artifacts/#delete-job-artifacts DeleteArtifacts(pid any, jobID int64, options ...RequestOptionFunc) (*Response, error) + // DeleteProjectArtifacts deletes artifacts eligible for deletion in a project + // + // GitLab API docs: + // https://docs.gitlab.com/api/job_artifacts/#delete-job-artifacts DeleteProjectArtifacts(pid any, options ...RequestOptionFunc) (*Response, error) } @@ -161,13 +241,6 @@ type ListJobsOptions struct { IncludeRetried *bool `url:"include_retried,omitempty" json:"include_retried,omitempty"` } -// ListProjectJobs gets a list of jobs in a project. -// -// The scope of jobs to show, one or array of: created, pending, running, -// failed, success, canceled, skipped; showing all jobs if none provided -// -// GitLab API docs: -// https://docs.gitlab.com/api/jobs/#list-project-jobs func (s *JobsService) ListProjectJobs(pid any, opts *ListJobsOptions, options ...RequestOptionFunc) ([]*Job, *Response, error) { return do[[]*Job](s.client, withMethod(http.MethodGet), @@ -177,11 +250,6 @@ func (s *JobsService) ListProjectJobs(pid any, opts *ListJobsOptions, options .. ) } -// ListPipelineJobs gets a list of jobs for specific pipeline in a -// project. If the pipeline ID is not found, it will respond with 404. -// -// GitLab API docs: -// https://docs.gitlab.com/api/jobs/#list-pipeline-jobs func (s *JobsService) ListPipelineJobs(pid any, pipelineID int64, opts *ListJobsOptions, options ...RequestOptionFunc) ([]*Job, *Response, error) { return do[[]*Job](s.client, withMethod(http.MethodGet), @@ -191,11 +259,6 @@ func (s *JobsService) ListPipelineJobs(pid any, pipelineID int64, opts *ListJobs ) } -// ListPipelineBridges gets a list of bridges for specific pipeline in a -// project. -// -// GitLab API docs: -// https://docs.gitlab.com/api/jobs/#list-pipeline-trigger-jobs func (s *JobsService) ListPipelineBridges(pid any, pipelineID int64, opts *ListJobsOptions, options ...RequestOptionFunc) ([]*Bridge, *Response, error) { return do[[]*Bridge](s.client, withMethod(http.MethodGet), @@ -212,9 +275,6 @@ type GetJobTokensJobOptions struct { JobToken *string `url:"job_token,omitempty" json:"job_token,omitempty"` } -// GetJobTokensJob retrieves the job that generated a job token. -// -// GitLab API docs: https://docs.gitlab.com/api/jobs/#get-job-tokens-job func (s *JobsService) GetJobTokensJob(opts *GetJobTokensJobOptions, options ...RequestOptionFunc) (*Job, *Response, error) { return do[*Job](s.client, withMethod(http.MethodGet), @@ -224,10 +284,6 @@ func (s *JobsService) GetJobTokensJob(opts *GetJobTokensJobOptions, options ...R ) } -// GetJob gets a single job of a project. -// -// GitLab API docs: -// https://docs.gitlab.com/api/jobs/#get-a-single-job func (s *JobsService) GetJob(pid any, jobID int64, options ...RequestOptionFunc) (*Job, *Response, error) { return do[*Job](s.client, withMethod(http.MethodGet), @@ -237,10 +293,6 @@ func (s *JobsService) GetJob(pid any, jobID int64, options ...RequestOptionFunc) ) } -// GetJobArtifacts get jobs artifacts of a project -// -// GitLab API docs: -// https://docs.gitlab.com/api/job_artifacts/#get-job-artifacts func (s *JobsService) GetJobArtifacts(pid any, jobID int64, options ...RequestOptionFunc) (*bytes.Reader, *Response, error) { b, resp, err := do[bytes.Buffer](s.client, withPath("projects/%s/jobs/%d/artifacts", ProjectID{pid}, jobID), @@ -259,11 +311,6 @@ type DownloadArtifactsFileOptions struct { Job *string `url:"job" json:"job"` } -// DownloadArtifactsFile download the artifacts file from the given -// reference name and job provided the job finished successfully. -// -// GitLab API docs: -// https://docs.gitlab.com/api/job_artifacts/#download-the-artifacts-archive func (s *JobsService) DownloadArtifactsFile(pid any, refName string, opt *DownloadArtifactsFileOptions, options ...RequestOptionFunc) (*bytes.Reader, *Response, error) { b, resp, err := do[bytes.Buffer](s.client, withPath("projects/%s/jobs/artifacts/%s/download", ProjectID{pid}, NoEscape{refName}), @@ -274,13 +321,6 @@ func (s *JobsService) DownloadArtifactsFile(pid any, refName string, opt *Downlo return bytes.NewReader(b.Bytes()), resp, err } -// DownloadSingleArtifactsFile download a file from the artifacts from the -// given reference name and job provided the job finished successfully. -// Only a single file is going to be extracted from the archive and streamed -// to a client. -// -// GitLab API docs: -// https://docs.gitlab.com/api/job_artifacts/#download-a-single-artifact-file-by-job-id func (s *JobsService) DownloadSingleArtifactsFile(pid any, jobID int64, artifactPath string, options ...RequestOptionFunc) (*bytes.Reader, *Response, error) { b, resp, err := do[bytes.Buffer](s.client, withPath("projects/%s/jobs/%d/artifacts/%s", ProjectID{pid}, jobID, NoEscape{artifactPath}), @@ -290,12 +330,6 @@ func (s *JobsService) DownloadSingleArtifactsFile(pid any, jobID int64, artifact return bytes.NewReader(b.Bytes()), resp, err } -// DownloadSingleArtifactsFileByTagOrBranch downloads a single file from -// a jobโ€™s artifacts in the latest successful pipeline using the reference name. -// The file is extracted from the archive and streamed to the client. -// -// GitLab API docs: -// https://docs.gitlab.com/api/job_artifacts/#download-a-single-artifact-file-from-specific-tag-or-branch func (s *JobsService) DownloadSingleArtifactsFileByTagOrBranch(pid any, refName string, artifactPath string, opt *DownloadArtifactsFileOptions, options ...RequestOptionFunc) (*bytes.Reader, *Response, error) { b, resp, err := do[bytes.Buffer](s.client, withPath("projects/%s/jobs/artifacts/%s/raw/%s", ProjectID{pid}, refName, NoEscape{artifactPath}), @@ -306,10 +340,6 @@ func (s *JobsService) DownloadSingleArtifactsFileByTagOrBranch(pid any, refName return bytes.NewReader(b.Bytes()), resp, err } -// GetTraceFile gets a trace of a specific job of a project -// -// GitLab API docs: -// https://docs.gitlab.com/api/jobs/#get-a-log-file func (s *JobsService) GetTraceFile(pid any, jobID int64, options ...RequestOptionFunc) (*bytes.Reader, *Response, error) { b, resp, err := do[bytes.Buffer](s.client, withPath("projects/%s/jobs/%d/trace", ProjectID{pid}, jobID), @@ -319,10 +349,6 @@ func (s *JobsService) GetTraceFile(pid any, jobID int64, options ...RequestOptio return bytes.NewReader(b.Bytes()), resp, err } -// CancelJob cancels a single job of a project. -// -// GitLab API docs: -// https://docs.gitlab.com/api/jobs/#cancel-a-job func (s *JobsService) CancelJob(pid any, jobID int64, options ...RequestOptionFunc) (*Job, *Response, error) { return do[*Job](s.client, withMethod(http.MethodPost), @@ -332,10 +358,6 @@ func (s *JobsService) CancelJob(pid any, jobID int64, options ...RequestOptionFu ) } -// RetryJob retries a single job of a project -// -// GitLab API docs: -// https://docs.gitlab.com/api/jobs/#retry-a-job func (s *JobsService) RetryJob(pid any, jobID int64, options ...RequestOptionFunc) (*Job, *Response, error) { return do[*Job](s.client, withMethod(http.MethodPost), @@ -345,11 +367,6 @@ func (s *JobsService) RetryJob(pid any, jobID int64, options ...RequestOptionFun ) } -// EraseJob erases a single job of a project, removes a job -// artifacts and a job trace. -// -// GitLab API docs: -// https://docs.gitlab.com/api/jobs/#erase-a-job func (s *JobsService) EraseJob(pid any, jobID int64, options ...RequestOptionFunc) (*Job, *Response, error) { return do[*Job](s.client, withMethod(http.MethodPost), @@ -359,11 +376,6 @@ func (s *JobsService) EraseJob(pid any, jobID int64, options ...RequestOptionFun ) } -// KeepArtifacts prevents artifacts from being deleted when -// expiration is set. -// -// GitLab API docs: -// https://docs.gitlab.com/api/job_artifacts/#keep-artifacts func (s *JobsService) KeepArtifacts(pid any, jobID int64, options ...RequestOptionFunc) (*Job, *Response, error) { return do[*Job](s.client, withMethod(http.MethodPost), @@ -391,10 +403,6 @@ type JobVariableOptions struct { VariableType *VariableTypeValue `url:"variable_type,omitempty" json:"variable_type,omitempty"` } -// PlayJob triggers a manual action to start a job. -// -// GitLab API docs: -// https://docs.gitlab.com/api/jobs/#run-a-job func (s *JobsService) PlayJob(pid any, jobID int64, opt *PlayJobOptions, options ...RequestOptionFunc) (*Job, *Response, error) { return do[*Job](s.client, withMethod(http.MethodPost), @@ -404,10 +412,6 @@ func (s *JobsService) PlayJob(pid any, jobID int64, opt *PlayJobOptions, options ) } -// DeleteArtifacts delete artifacts of a job -// -// GitLab API docs: -// https://docs.gitlab.com/api/job_artifacts/#delete-job-artifacts func (s *JobsService) DeleteArtifacts(pid any, jobID int64, options ...RequestOptionFunc) (*Response, error) { _, resp, err := do[none](s.client, withMethod(http.MethodDelete), @@ -418,10 +422,6 @@ func (s *JobsService) DeleteArtifacts(pid any, jobID int64, options ...RequestOp return resp, err } -// DeleteProjectArtifacts delete artifacts eligible for deletion in a project -// -// GitLab API docs: -// https://docs.gitlab.com/api/job_artifacts/#delete-job-artifacts func (s *JobsService) DeleteProjectArtifacts(pid any, options ...RequestOptionFunc) (*Response, error) { _, resp, err := do[none](s.client, withMethod(http.MethodDelete), diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/keys.go b/vendor/gitlab.com/gitlab-org/api/client-go/keys.go index 8d76a22b..2fde4860 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/keys.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/keys.go @@ -16,11 +16,7 @@ package gitlab -import ( - "fmt" - "net/http" - "time" -) +import "time" type ( KeysServiceInterface interface { @@ -58,20 +54,10 @@ type Key struct { // GitLab API docs: // https://docs.gitlab.com/api/keys/#get-ssh-key-with-user-by-id-of-an-ssh-key func (s *KeysService) GetKeyWithUser(key int64, options ...RequestOptionFunc) (*Key, *Response, error) { - u := fmt.Sprintf("keys/%d", key) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - k := new(Key) - resp, err := s.client.Do(req, k) - if err != nil { - return nil, resp, err - } - - return k, resp, nil + return do[*Key](s.client, + withPath("keys/%d", key), + withRequestOpts(options...), + ) } // GetKeyByFingerprintOptions represents the available GetKeyByFingerprint() @@ -91,16 +77,9 @@ type GetKeyByFingerprintOptions struct { // https://docs.gitlab.com/api/keys/#get-user-by-fingerprint-of-ssh-key // https://docs.gitlab.com/api/keys/#get-user-by-deploy-key-fingerprint func (s *KeysService) GetKeyByFingerprint(opt *GetKeyByFingerprintOptions, options ...RequestOptionFunc) (*Key, *Response, error) { - req, err := s.client.NewRequest(http.MethodGet, "keys", opt, options) - if err != nil { - return nil, nil, err - } - - k := new(Key) - resp, err := s.client.Do(req, k) - if err != nil { - return nil, resp, err - } - - return k, resp, nil + return do[*Key](s.client, + withPath("keys"), + withAPIOpts(opt), + withRequestOpts(options...), + ) } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/labels.go b/vendor/gitlab.com/gitlab-org/api/client-go/labels.go index 3a78a14e..a91a316a 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/labels.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/labels.go @@ -18,7 +18,6 @@ package gitlab import ( "encoding/json" - "fmt" "net/http" ) @@ -100,52 +99,21 @@ type ListLabelsOptions struct { // // GitLab API docs: https://docs.gitlab.com/api/labels/#list-labels func (s *LabelsService) ListLabels(pid any, opt *ListLabelsOptions, options ...RequestOptionFunc) ([]*Label, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/labels", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var l []*Label - resp, err := s.client.Do(req, &l) - if err != nil { - return nil, resp, err - } - - return l, resp, nil + return do[[]*Label](s.client, + withPath("projects/%s/labels", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // GetLabel get a single label for a given project. // // GitLab API docs: https://docs.gitlab.com/api/labels/#get-a-single-project-label func (s *LabelsService) GetLabel(pid any, lid any, options ...RequestOptionFunc) (*Label, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - label, err := parseID(lid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/labels/%s", PathEscape(project), PathEscape(label)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - var l *Label - resp, err := s.client.Do(req, &l) - if err != nil { - return nil, resp, err - } - - return l, resp, nil + return do[*Label](s.client, + withPath("projects/%s/labels/%s", ProjectID{pid}, LabelID{lid}), + withRequestOpts(options...), + ) } // CreateLabelOptions represents the available CreateLabel() options. @@ -163,24 +131,12 @@ type CreateLabelOptions struct { // // GitLab API docs: https://docs.gitlab.com/api/labels/#create-a-new-label func (s *LabelsService) CreateLabel(pid any, opt *CreateLabelOptions, options ...RequestOptionFunc) (*Label, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/labels", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - l := new(Label) - resp, err := s.client.Do(req, l) - if err != nil { - return nil, resp, err - } - - return l, resp, nil + return do[*Label](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/labels", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // DeleteLabelOptions represents the available DeleteLabel() options. @@ -194,26 +150,21 @@ type DeleteLabelOptions struct { // // GitLab API docs: https://docs.gitlab.com/api/labels/#delete-a-label func (s *LabelsService) DeleteLabel(pid any, lid any, opt *DeleteLabelOptions, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/labels", PathEscape(project)) + reqOpts := make([]doOption, 0, 4) + reqOpts = append(reqOpts, + withMethod(http.MethodDelete), + withAPIOpts(opt), + withRequestOpts(options...), + ) if lid != nil { - label, err := parseID(lid) - if err != nil { - return nil, err - } - u = fmt.Sprintf("projects/%s/labels/%s", PathEscape(project), PathEscape(label)) - } - - req, err := s.client.NewRequest(http.MethodDelete, u, opt, options) - if err != nil { - return nil, err + reqOpts = append(reqOpts, withPath("projects/%s/labels/%s", ProjectID{pid}, LabelID{lid})) + } else { + reqOpts = append(reqOpts, withPath("projects/%s/labels", ProjectID{pid})) } - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, reqOpts...) + return resp, err } // UpdateLabelOptions represents the available UpdateLabel() options. @@ -232,32 +183,20 @@ type UpdateLabelOptions struct { // // GitLab API docs: https://docs.gitlab.com/api/labels/#edit-an-existing-label func (s *LabelsService) UpdateLabel(pid any, lid any, opt *UpdateLabelOptions, options ...RequestOptionFunc) (*Label, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/labels", PathEscape(project)) + reqOpts := make([]doOption, 0, 4) + reqOpts = append(reqOpts, + withMethod(http.MethodPut), + withAPIOpts(opt), + withRequestOpts(options...), + ) if lid != nil { - label, err := parseID(lid) - if err != nil { - return nil, nil, err - } - u = fmt.Sprintf("projects/%s/labels/%s", PathEscape(project), PathEscape(label)) - } - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - l := new(Label) - resp, err := s.client.Do(req, l) - if err != nil { - return nil, resp, err + reqOpts = append(reqOpts, withPath("projects/%s/labels/%s", ProjectID{pid}, LabelID{lid})) + } else { + reqOpts = append(reqOpts, withPath("projects/%s/labels", ProjectID{pid})) } - return l, resp, nil + return do[*Label](s.client, reqOpts...) } // SubscribeToLabel subscribes the authenticated user to a label to receive @@ -267,28 +206,11 @@ func (s *LabelsService) UpdateLabel(pid any, lid any, opt *UpdateLabelOptions, o // GitLab API docs: // https://docs.gitlab.com/api/labels/#subscribe-to-a-label func (s *LabelsService) SubscribeToLabel(pid any, lid any, options ...RequestOptionFunc) (*Label, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - label, err := parseID(lid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/labels/%s/subscribe", PathEscape(project), PathEscape(label)) - - req, err := s.client.NewRequest(http.MethodPost, u, nil, options) - if err != nil { - return nil, nil, err - } - - l := new(Label) - resp, err := s.client.Do(req, l) - if err != nil { - return nil, resp, err - } - - return l, resp, nil + return do[*Label](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/labels/%s/subscribe", ProjectID{pid}, LabelID{lid}), + withRequestOpts(options...), + ) } // UnsubscribeFromLabel unsubscribes the authenticated user from a label to not @@ -298,22 +220,12 @@ func (s *LabelsService) SubscribeToLabel(pid any, lid any, options ...RequestOpt // GitLab API docs: // https://docs.gitlab.com/api/labels/#unsubscribe-from-a-label func (s *LabelsService) UnsubscribeFromLabel(pid any, lid any, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - label, err := parseID(lid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/labels/%s/unsubscribe", PathEscape(project), PathEscape(label)) - - req, err := s.client.NewRequest(http.MethodPost, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/labels/%s/unsubscribe", ProjectID{pid}, LabelID{lid}), + withRequestOpts(options...), + ) + return resp, err } // PromoteLabel Promotes a project label to a group label. @@ -321,20 +233,10 @@ func (s *LabelsService) UnsubscribeFromLabel(pid any, lid any, options ...Reques // GitLab API docs: // https://docs.gitlab.com/api/labels/#promote-a-project-label-to-a-group-label func (s *LabelsService) PromoteLabel(pid any, lid any, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - label, err := parseID(lid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/labels/%s/promote", PathEscape(project), PathEscape(label)) - - req, err := s.client.NewRequest(http.MethodPut, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/labels/%s/promote", ProjectID{pid}, LabelID{lid}), + withRequestOpts(options...), + ) + return resp, err } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/license.go b/vendor/gitlab.com/gitlab-org/api/client-go/license.go index 89418fb9..762454aa 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/license.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/license.go @@ -17,7 +17,6 @@ package gitlab import ( - "fmt" "net/http" "time" ) @@ -102,18 +101,10 @@ func (a LicenseAddOns) String() string { // GitLab API docs: // https://docs.gitlab.com/api/license/#retrieve-information-about-the-current-license func (s *LicenseService) GetLicense(options ...RequestOptionFunc) (*License, *Response, error) { - req, err := s.client.NewRequest(http.MethodGet, "license", nil, options) - if err != nil { - return nil, nil, err - } - - l := new(License) - resp, err := s.client.Do(req, l) - if err != nil { - return nil, resp, err - } - - return l, resp, nil + return do[*License](s.client, + withPath("license"), + withRequestOpts(options...), + ) } // AddLicenseOptions represents the available AddLicense() options. @@ -128,18 +119,12 @@ type AddLicenseOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/license/#add-a-new-license func (s *LicenseService) AddLicense(opt *AddLicenseOptions, options ...RequestOptionFunc) (*License, *Response, error) { - req, err := s.client.NewRequest(http.MethodPost, "license", opt, options) - if err != nil { - return nil, nil, err - } - - l := new(License) - resp, err := s.client.Do(req, l) - if err != nil { - return nil, resp, err - } - - return l, resp, nil + return do[*License](s.client, + withMethod(http.MethodPost), + withPath("license"), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // DeleteLicense deletes an existing license. @@ -147,12 +132,10 @@ func (s *LicenseService) AddLicense(opt *AddLicenseOptions, options ...RequestOp // GitLab API docs: // https://docs.gitlab.com/api/license/#delete-a-license func (s *LicenseService) DeleteLicense(licenseID int64, options ...RequestOptionFunc) (*Response, error) { - u := fmt.Sprintf("license/%d", licenseID) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("license/%d", licenseID), + withRequestOpts(options...), + ) + return resp, err } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/license_templates.go b/vendor/gitlab.com/gitlab-org/api/client-go/license_templates.go index 8808f56b..bdcb1930 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/license_templates.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/license_templates.go @@ -16,11 +16,6 @@ package gitlab -import ( - "fmt" - "net/http" -) - // LicenseTemplate represents a license template. // // GitLab API docs: @@ -71,18 +66,11 @@ type ListLicenseTemplatesOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/templates/licenses/#list-license-templates func (s *LicenseTemplatesService) ListLicenseTemplates(opt *ListLicenseTemplatesOptions, options ...RequestOptionFunc) ([]*LicenseTemplate, *Response, error) { - req, err := s.client.NewRequest(http.MethodGet, "templates/licenses", opt, options) - if err != nil { - return nil, nil, err - } - - var lts []*LicenseTemplate - resp, err := s.client.Do(req, <s) - if err != nil { - return nil, resp, err - } - - return lts, resp, nil + return do[[]*LicenseTemplate](s.client, + withPath("templates/licenses"), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // GetLicenseTemplateOptions represents the available @@ -101,18 +89,9 @@ type GetLicenseTemplateOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/templates/licenses/#single-license-template func (s *LicenseTemplatesService) GetLicenseTemplate(template string, opt *GetLicenseTemplateOptions, options ...RequestOptionFunc) (*LicenseTemplate, *Response, error) { - u := fmt.Sprintf("templates/licenses/%s", template) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - lt := new(LicenseTemplate) - resp, err := s.client.Do(req, lt) - if err != nil { - return nil, resp, err - } - - return lt, resp, nil + return do[*LicenseTemplate](s.client, + withPath("templates/licenses/%s", template), + withAPIOpts(opt), + withRequestOpts(options...), + ) } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/markdown.go b/vendor/gitlab.com/gitlab-org/api/client-go/markdown.go index af02391e..cf92f1c3 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/markdown.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/markdown.go @@ -40,16 +40,10 @@ type RenderOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/markdown/#render-an-arbitrary-markdown-document func (s *MarkdownService) Render(opt *RenderOptions, options ...RequestOptionFunc) (*Markdown, *Response, error) { - req, err := s.client.NewRequest(http.MethodPost, "markdown", opt, options) - if err != nil { - return nil, nil, err - } - - md := new(Markdown) - response, err := s.client.Do(req, md) - if err != nil { - return nil, response, err - } - - return md, response, nil + return do[*Markdown](s.client, + withMethod(http.MethodPost), + withPath("markdown"), + withAPIOpts(opt), + withRequestOpts(options...), + ) } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/merge_request_approval_settings.go b/vendor/gitlab.com/gitlab-org/api/client-go/merge_request_approval_settings.go index 6d183a64..4c182063 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/merge_request_approval_settings.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/merge_request_approval_settings.go @@ -15,7 +15,6 @@ package gitlab import ( - "fmt" "net/http" ) @@ -70,24 +69,10 @@ type MergeRequestApprovalSetting struct { // GitLab API docs: // https://docs.gitlab.com/api/merge_request_approval_settings/#get-group-mr-approval-settings func (s *MergeRequestApprovalSettingsService) GetGroupMergeRequestApprovalSettings(gid any, options ...RequestOptionFunc) (*MergeRequestApprovalSettings, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/merge_request_approval_setting", PathEscape(group)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - settings := new(MergeRequestApprovalSettings) - resp, err := s.client.Do(req, settings) - if err != nil { - return nil, resp, err - } - - return settings, resp, nil + return do[*MergeRequestApprovalSettings](s.client, + withPath("groups/%s/merge_request_approval_setting", GroupID{gid}), + withRequestOpts(options...), + ) } // UpdateProjectMergeRequestApprovalSettingsOptions represents the available @@ -125,24 +110,12 @@ type UpdateGroupMergeRequestApprovalSettingsOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/merge_request_approval_settings/#update-group-mr-approval-settings func (s *MergeRequestApprovalSettingsService) UpdateGroupMergeRequestApprovalSettings(gid any, opt *UpdateGroupMergeRequestApprovalSettingsOptions, options ...RequestOptionFunc) (*MergeRequestApprovalSettings, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/merge_request_approval_setting", PathEscape(group)) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - settings := new(MergeRequestApprovalSettings) - resp, err := s.client.Do(req, settings) - if err != nil { - return nil, resp, err - } - - return settings, resp, nil + return do[*MergeRequestApprovalSettings](s.client, + withMethod(http.MethodPut), + withPath("groups/%s/merge_request_approval_setting", GroupID{gid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // GetProjectMergeRequestApprovalSettings gets the merge request approval settings @@ -151,24 +124,10 @@ func (s *MergeRequestApprovalSettingsService) UpdateGroupMergeRequestApprovalSet // GitLab API docs: // https://docs.gitlab.com/api/merge_request_approval_settings/#get-project-mr-approval-settings func (s *MergeRequestApprovalSettingsService) GetProjectMergeRequestApprovalSettings(pid any, options ...RequestOptionFunc) (*MergeRequestApprovalSettings, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/merge_request_approval_setting", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - settings := new(MergeRequestApprovalSettings) - resp, err := s.client.Do(req, settings) - if err != nil { - return nil, resp, err - } - - return settings, resp, nil + return do[*MergeRequestApprovalSettings](s.client, + withPath("projects/%s/merge_request_approval_setting", ProjectID{pid}), + withRequestOpts(options...), + ) } // UpdateProjectMergeRequestApprovalSettings updates the merge request approval @@ -177,22 +136,10 @@ func (s *MergeRequestApprovalSettingsService) GetProjectMergeRequestApprovalSett // GitLab API docs: // https://docs.gitlab.com/api/merge_request_approval_settings/#update-project-mr-approval-settings func (s *MergeRequestApprovalSettingsService) UpdateProjectMergeRequestApprovalSettings(pid any, opt *UpdateProjectMergeRequestApprovalSettingsOptions, options ...RequestOptionFunc) (*MergeRequestApprovalSettings, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/merge_request_approval_setting", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - settings := new(MergeRequestApprovalSettings) - resp, err := s.client.Do(req, settings) - if err != nil { - return nil, resp, err - } - - return settings, resp, nil + return do[*MergeRequestApprovalSettings](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/merge_request_approval_setting", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/merge_request_approvals.go b/vendor/gitlab.com/gitlab-org/api/client-go/merge_request_approvals.go index 12263ac9..2cdc06c6 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/merge_request_approvals.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/merge_request_approvals.go @@ -17,7 +17,6 @@ package gitlab import ( - "fmt" "net/http" "time" ) @@ -161,24 +160,12 @@ type ApproveMergeRequestOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/merge_request_approvals/#approve-merge-request func (s *MergeRequestApprovalsService) ApproveMergeRequest(pid any, mr int64, opt *ApproveMergeRequestOptions, options ...RequestOptionFunc) (*MergeRequestApprovals, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/merge_requests/%d/approve", PathEscape(project), mr) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - m := new(MergeRequestApprovals) - resp, err := s.client.Do(req, m) - if err != nil { - return nil, resp, err - } - - return m, resp, nil + return do[*MergeRequestApprovals](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/merge_requests/%d/approve", ProjectID{pid}, mr), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // UnapproveMergeRequest unapproves a previously approved merge request on GitLab. @@ -186,18 +173,12 @@ func (s *MergeRequestApprovalsService) ApproveMergeRequest(pid any, mr int64, op // GitLab API docs: // https://docs.gitlab.com/api/merge_request_approvals/#unapprove-merge-request func (s *MergeRequestApprovalsService) UnapproveMergeRequest(pid any, mr int64, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/merge_requests/%d/unapprove", PathEscape(project), mr) - - req, err := s.client.NewRequest(http.MethodPost, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/merge_requests/%d/unapprove", ProjectID{pid}, mr), + withRequestOpts(options...), + ) + return resp, err } // ResetApprovalsOfMergeRequest clear all approvals of merge request on GitLab. @@ -206,18 +187,12 @@ func (s *MergeRequestApprovalsService) UnapproveMergeRequest(pid any, mr int64, // GitLab API docs: // https://docs.gitlab.com/api/merge_request_approvals/#reset-approvals-of-a-merge-request func (s *MergeRequestApprovalsService) ResetApprovalsOfMergeRequest(pid any, mr int64, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/merge_requests/%d/reset_approvals", PathEscape(project), mr) - - req, err := s.client.NewRequest(http.MethodPut, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/merge_requests/%d/reset_approvals", ProjectID{pid}, mr), + withRequestOpts(options...), + ) + return resp, err } // GetConfiguration shows information about single merge request approvals @@ -225,24 +200,10 @@ func (s *MergeRequestApprovalsService) ResetApprovalsOfMergeRequest(pid any, mr // GitLab API docs: // https://docs.gitlab.com/api/merge_request_approvals/#single-merge-request-approval func (s *MergeRequestApprovalsService) GetConfiguration(pid any, mr int64, options ...RequestOptionFunc) (*MergeRequestApprovals, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/merge_requests/%d/approvals", PathEscape(project), mr) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - m := new(MergeRequestApprovals) - resp, err := s.client.Do(req, m) - if err != nil { - return nil, resp, err - } - - return m, resp, nil + return do[*MergeRequestApprovals](s.client, + withPath("projects/%s/merge_requests/%d/approvals", ProjectID{pid}, mr), + withRequestOpts(options...), + ) } // ChangeMergeRequestApprovalConfigurationOptions represents the available @@ -257,74 +218,34 @@ type ChangeMergeRequestApprovalConfigurationOptions struct { // // Deprecated: in GitLab 16.0 func (s *MergeRequestApprovalsService) ChangeApprovalConfiguration(pid any, mergeRequest int64, opt *ChangeMergeRequestApprovalConfigurationOptions, options ...RequestOptionFunc) (*MergeRequest, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/merge_requests/%d/approvals", PathEscape(project), mergeRequest) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - m := new(MergeRequest) - resp, err := s.client.Do(req, m) - if err != nil { - return nil, resp, err - } - - return m, resp, nil + return do[*MergeRequest](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/merge_requests/%d/approvals", ProjectID{pid}, mergeRequest), + withAPIOpts(opt), + withRequestOpts(options...), + ) } -// GetApprovalRules requests information about a merge requestโ€™s approval rules +// GetApprovalRules requests information about a merge request's approval rules // // GitLab API docs: // https://docs.gitlab.com/api/merge_request_approvals/#get-merge-request-approval-rules func (s *MergeRequestApprovalsService) GetApprovalRules(pid any, mergeRequest int64, options ...RequestOptionFunc) ([]*MergeRequestApprovalRule, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/merge_requests/%d/approval_rules", PathEscape(project), mergeRequest) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - var par []*MergeRequestApprovalRule - resp, err := s.client.Do(req, &par) - if err != nil { - return nil, resp, err - } - - return par, resp, nil + return do[[]*MergeRequestApprovalRule](s.client, + withPath("projects/%s/merge_requests/%d/approval_rules", ProjectID{pid}, mergeRequest), + withRequestOpts(options...), + ) } -// GetApprovalState requests information about a merge requestโ€™s approval state +// GetApprovalState requests information about a merge request's approval state // // GitLab API docs: // https://docs.gitlab.com/api/merge_request_approvals/#get-the-approval-state-of-merge-requests func (s *MergeRequestApprovalsService) GetApprovalState(pid any, mergeRequest int64, options ...RequestOptionFunc) (*MergeRequestApprovalState, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/merge_requests/%d/approval_state", PathEscape(project), mergeRequest) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - var pas *MergeRequestApprovalState - resp, err := s.client.Do(req, &pas) - if err != nil { - return nil, resp, err - } - - return pas, resp, nil + return do[*MergeRequestApprovalState](s.client, + withPath("projects/%s/merge_requests/%d/approval_state", ProjectID{pid}, mergeRequest), + withRequestOpts(options...), + ) } // CreateMergeRequestApprovalRuleOptions represents the available CreateApprovalRule() @@ -345,24 +266,12 @@ type CreateMergeRequestApprovalRuleOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/merge_request_approvals/#create-merge-request-rule func (s *MergeRequestApprovalsService) CreateApprovalRule(pid any, mergeRequest int64, opt *CreateMergeRequestApprovalRuleOptions, options ...RequestOptionFunc) (*MergeRequestApprovalRule, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/merge_requests/%d/approval_rules", PathEscape(project), mergeRequest) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - par := new(MergeRequestApprovalRule) - resp, err := s.client.Do(req, &par) - if err != nil { - return nil, resp, err - } - - return par, resp, nil + return do[*MergeRequestApprovalRule](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/merge_requests/%d/approval_rules", ProjectID{pid}, mergeRequest), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // UpdateMergeRequestApprovalRuleOptions represents the available UpdateApprovalRule() @@ -382,24 +291,12 @@ type UpdateMergeRequestApprovalRuleOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/merge_request_approvals/#update-merge-request-rule func (s *MergeRequestApprovalsService) UpdateApprovalRule(pid any, mergeRequest int64, approvalRule int64, opt *UpdateMergeRequestApprovalRuleOptions, options ...RequestOptionFunc) (*MergeRequestApprovalRule, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/merge_requests/%d/approval_rules/%d", PathEscape(project), mergeRequest, approvalRule) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - par := new(MergeRequestApprovalRule) - resp, err := s.client.Do(req, &par) - if err != nil { - return nil, resp, err - } - - return par, resp, nil + return do[*MergeRequestApprovalRule](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/merge_requests/%d/approval_rules/%d", ProjectID{pid}, mergeRequest, approvalRule), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // DeleteApprovalRule deletes a mr level approval rule. @@ -407,16 +304,10 @@ func (s *MergeRequestApprovalsService) UpdateApprovalRule(pid any, mergeRequest // GitLab API docs: // https://docs.gitlab.com/api/merge_request_approvals/#delete-merge-request-rule func (s *MergeRequestApprovalsService) DeleteApprovalRule(pid any, mergeRequest int64, approvalRule int64, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/merge_requests/%d/approval_rules/%d", PathEscape(project), mergeRequest, approvalRule) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/merge_requests/%d/approval_rules/%d", ProjectID{pid}, mergeRequest, approvalRule), + withRequestOpts(options...), + ) + return resp, err } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/merge_request_context_commits.go b/vendor/gitlab.com/gitlab-org/api/client-go/merge_request_context_commits.go index 08819fcd..f2240f41 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/merge_request_context_commits.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/merge_request_context_commits.go @@ -1,7 +1,6 @@ package gitlab import ( - "fmt" "net/http" ) @@ -41,24 +40,10 @@ type ( var _ MergeRequestContextCommitsServiceInterface = (*MergeRequestContextCommitsService)(nil) func (s *MergeRequestContextCommitsService) ListMergeRequestContextCommits(pid any, mergeRequest int64, options ...RequestOptionFunc) ([]*Commit, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/merge_requests/%d/context_commits", PathEscape(project), mergeRequest) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - var c []*Commit - resp, err := s.client.Do(req, &c) - if err != nil { - return nil, resp, err - } - - return c, resp, nil + return do[[]*Commit](s.client, + withPath("projects/%s/merge_requests/%d/context_commits", ProjectID{pid}, mergeRequest), + withRequestOpts(options...), + ) } // CreateMergeRequestContextCommitsOptions represents the available @@ -71,24 +56,12 @@ type CreateMergeRequestContextCommitsOptions struct { } func (s *MergeRequestContextCommitsService) CreateMergeRequestContextCommits(pid any, mergeRequest int64, opt *CreateMergeRequestContextCommitsOptions, options ...RequestOptionFunc) ([]*Commit, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/merge_requests/%d/context_commits", PathEscape(project), mergeRequest) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - var c []*Commit - resp, err := s.client.Do(req, &c) - if err != nil { - return nil, resp, err - } - - return c, resp, nil + return do[[]*Commit](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/merge_requests/%d/context_commits", ProjectID{pid}, mergeRequest), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // DeleteMergeRequestContextCommitsOptions represents the available @@ -101,16 +74,11 @@ type DeleteMergeRequestContextCommitsOptions struct { } func (s *MergeRequestContextCommitsService) DeleteMergeRequestContextCommits(pid any, mergeRequest int64, opt *DeleteMergeRequestContextCommitsOptions, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/merge_requests/%d/context_commits", PathEscape(project), mergeRequest) - - req, err := s.client.NewRequest(http.MethodDelete, u, opt, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/merge_requests/%d/context_commits", ProjectID{pid}, mergeRequest), + withAPIOpts(opt), + withRequestOpts(options...), + ) + return resp, err } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/merge_requests.go b/vendor/gitlab.com/gitlab-org/api/client-go/merge_requests.go index 220d4dae..1b498fea 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/merge_requests.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/merge_requests.go @@ -340,6 +340,7 @@ type ListProjectMergeRequestsOptions struct { Sort *string `url:"sort,omitempty" json:"sort,omitempty"` Milestone *string `url:"milestone,omitempty" json:"milestone,omitempty"` View *string `url:"view,omitempty" json:"view,omitempty"` + Environment *string `url:"environment,omitempty" json:"environment,omitempty"` Labels *LabelOptions `url:"labels,comma,omitempty" json:"labels,omitempty"` NotLabels *LabelOptions `url:"not[labels],comma,omitempty" json:"not[labels],omitempty"` WithLabelsDetails *bool `url:"with_labels_details,omitempty" json:"with_labels_details,omitempty"` @@ -348,6 +349,8 @@ type ListProjectMergeRequestsOptions struct { CreatedBefore *time.Time `url:"created_before,omitempty" json:"created_before,omitempty"` UpdatedAfter *time.Time `url:"updated_after,omitempty" json:"updated_after,omitempty"` UpdatedBefore *time.Time `url:"updated_before,omitempty" json:"updated_before,omitempty"` + DeployedBefore *time.Time `url:"deployed_before,omitempty" json:"deployed_before,omitempty"` + DeployedAfter *time.Time `url:"deployed_after,omitempty" json:"deployed_after,omitempty"` Scope *string `url:"scope,omitempty" json:"scope,omitempty"` AuthorID *int64 `url:"author_id,omitempty" json:"author_id,omitempty"` AuthorUsername *string `url:"author_username,omitempty" json:"author_username,omitempty"` diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/metadata.go b/vendor/gitlab.com/gitlab-org/api/client-go/metadata.go index 5c9f7170..8a79cd39 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/metadata.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/metadata.go @@ -16,8 +16,6 @@ package gitlab -import "net/http" - type ( MetadataServiceInterface interface { GetMetadata(options ...RequestOptionFunc) (*Metadata, *Response, error) @@ -66,16 +64,8 @@ func (k MetadataKAS) String() string { // // GitLab API docs: https://docs.gitlab.com/api/metadata/ func (s *MetadataService) GetMetadata(options ...RequestOptionFunc) (*Metadata, *Response, error) { - req, err := s.client.NewRequest(http.MethodGet, "metadata", nil, options) - if err != nil { - return nil, nil, err - } - - v := new(Metadata) - resp, err := s.client.Do(req, v) - if err != nil { - return nil, resp, err - } - - return v, resp, nil + return do[*Metadata](s.client, + withPath("metadata"), + withRequestOpts(options...), + ) } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/milestones.go b/vendor/gitlab.com/gitlab-org/api/client-go/milestones.go index 024101ef..f416c677 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/milestones.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/milestones.go @@ -17,19 +17,47 @@ package gitlab import ( - "fmt" "net/http" "time" ) type ( MilestonesServiceInterface interface { + // ListMilestones returns a list of project milestones. + // + // GitLab API docs: + // https://docs.gitlab.com/api/milestones/#list-project-milestones ListMilestones(pid any, opt *ListMilestonesOptions, options ...RequestOptionFunc) ([]*Milestone, *Response, error) + // GetMilestone gets a single project milestone. + // + // GitLab API docs: + // https://docs.gitlab.com/api/milestones/#get-single-milestone GetMilestone(pid any, milestone int64, options ...RequestOptionFunc) (*Milestone, *Response, error) + // CreateMilestone creates a new project milestone. + // + // GitLab API docs: + // https://docs.gitlab.com/api/milestones/#create-new-milestone CreateMilestone(pid any, opt *CreateMilestoneOptions, options ...RequestOptionFunc) (*Milestone, *Response, error) + // UpdateMilestone updates an existing project milestone. + // + // GitLab API docs: + // https://docs.gitlab.com/api/milestones/#edit-milestone UpdateMilestone(pid any, milestone int64, opt *UpdateMilestoneOptions, options ...RequestOptionFunc) (*Milestone, *Response, error) + // DeleteMilestone deletes a specified project milestone. + // + // GitLab API docs: + // https://docs.gitlab.com/api/milestones/#delete-project-milestone DeleteMilestone(pid any, milestone int64, options ...RequestOptionFunc) (*Response, error) + // GetMilestoneIssues gets all issues assigned to a single project milestone. + // + // GitLab API docs: + // https://docs.gitlab.com/api/milestones/#get-all-issues-assigned-to-a-single-milestone GetMilestoneIssues(pid any, milestone int64, opt *GetMilestoneIssuesOptions, options ...RequestOptionFunc) ([]*Issue, *Response, error) + // GetMilestoneMergeRequests gets all merge requests assigned to a single + // project milestone. + // + // GitLab API docs: + // https://docs.gitlab.com/api/milestones/#get-all-merge-requests-assigned-to-a-single-milestone GetMilestoneMergeRequests(pid any, milestone int64, opt *GetMilestoneMergeRequestsOptions, options ...RequestOptionFunc) ([]*BasicMergeRequest, *Response, error) } @@ -83,54 +111,19 @@ type ListMilestonesOptions struct { IncludeParentMilestones *bool `url:"include_parent_milestones,omitempty" json:"include_parent_milestones,omitempty"` } -// ListMilestones returns a list of project milestones. -// -// GitLab API docs: -// https://docs.gitlab.com/api/milestones/#list-project-milestones func (s *MilestonesService) ListMilestones(pid any, opt *ListMilestonesOptions, options ...RequestOptionFunc) ([]*Milestone, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/milestones", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var m []*Milestone - resp, err := s.client.Do(req, &m) - if err != nil { - return nil, resp, err - } - - return m, resp, nil + return do[[]*Milestone](s.client, + withPath("projects/%s/milestones", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } -// GetMilestone gets a single project milestone. -// -// GitLab API docs: -// https://docs.gitlab.com/api/milestones/#get-single-milestone func (s *MilestonesService) GetMilestone(pid any, milestone int64, options ...RequestOptionFunc) (*Milestone, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/milestones/%d", PathEscape(project), milestone) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - m := new(Milestone) - resp, err := s.client.Do(req, m) - if err != nil { - return nil, resp, err - } - - return m, resp, nil + return do[*Milestone](s.client, + withPath("projects/%s/milestones/%d", ProjectID{pid}, milestone), + withRequestOpts(options...), + ) } // CreateMilestoneOptions represents the available CreateMilestone() options. @@ -144,29 +137,13 @@ type CreateMilestoneOptions struct { DueDate *ISOTime `url:"due_date,omitempty" json:"due_date,omitempty"` } -// CreateMilestone creates a new project milestone. -// -// GitLab API docs: -// https://docs.gitlab.com/api/milestones/#create-new-milestone func (s *MilestonesService) CreateMilestone(pid any, opt *CreateMilestoneOptions, options ...RequestOptionFunc) (*Milestone, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/milestones", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - m := new(Milestone) - resp, err := s.client.Do(req, m) - if err != nil { - return nil, resp, err - } - - return m, resp, nil + return do[*Milestone](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/milestones", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // UpdateMilestoneOptions represents the available UpdateMilestone() options. @@ -181,47 +158,22 @@ type UpdateMilestoneOptions struct { StateEvent *string `url:"state_event,omitempty" json:"state_event,omitempty"` } -// UpdateMilestone updates an existing project milestone. -// -// GitLab API docs: -// https://docs.gitlab.com/api/milestones/#edit-milestone func (s *MilestonesService) UpdateMilestone(pid any, milestone int64, opt *UpdateMilestoneOptions, options ...RequestOptionFunc) (*Milestone, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/milestones/%d", PathEscape(project), milestone) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - m := new(Milestone) - resp, err := s.client.Do(req, m) - if err != nil { - return nil, resp, err - } - - return m, resp, nil + return do[*Milestone](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/milestones/%d", ProjectID{pid}, milestone), + withAPIOpts(opt), + withRequestOpts(options...), + ) } -// DeleteMilestone deletes a specified project milestone. -// -// GitLab API docs: -// https://docs.gitlab.com/api/milestones/#delete-project-milestone func (s *MilestonesService) DeleteMilestone(pid any, milestone int64, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/milestones/%d", PathEscape(project), milestone) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/milestones/%d", ProjectID{pid}, milestone), + withRequestOpts(options...), + ) + return resp, err } // GetMilestoneIssuesOptions represents the available GetMilestoneIssues() options. @@ -232,29 +184,12 @@ type GetMilestoneIssuesOptions struct { ListOptions } -// GetMilestoneIssues gets all issues assigned to a single project milestone. -// -// GitLab API docs: -// https://docs.gitlab.com/api/milestones/#get-all-issues-assigned-to-a-single-milestone func (s *MilestonesService) GetMilestoneIssues(pid any, milestone int64, opt *GetMilestoneIssuesOptions, options ...RequestOptionFunc) ([]*Issue, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/milestones/%d/issues", PathEscape(project), milestone) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var i []*Issue - resp, err := s.client.Do(req, &i) - if err != nil { - return nil, resp, err - } - - return i, resp, nil + return do[[]*Issue](s.client, + withPath("projects/%s/milestones/%d/issues", ProjectID{pid}, milestone), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // GetMilestoneMergeRequestsOptions represents the available @@ -266,28 +201,10 @@ type GetMilestoneMergeRequestsOptions struct { ListOptions } -// GetMilestoneMergeRequests gets all merge requests assigned to a single -// project milestone. -// -// GitLab API docs: -// https://docs.gitlab.com/api/milestones/#get-all-merge-requests-assigned-to-a-single-milestone func (s *MilestonesService) GetMilestoneMergeRequests(pid any, milestone int64, opt *GetMilestoneMergeRequestsOptions, options ...RequestOptionFunc) ([]*BasicMergeRequest, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/milestones/%d/merge_requests", PathEscape(project), milestone) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var mr []*BasicMergeRequest - resp, err := s.client.Do(req, &mr) - if err != nil { - return nil, resp, err - } - - return mr, resp, nil + return do[[]*BasicMergeRequest](s.client, + withPath("projects/%s/milestones/%d/merge_requests", ProjectID{pid}, milestone), + withAPIOpts(opt), + withRequestOpts(options...), + ) } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/model_registry.go b/vendor/gitlab.com/gitlab-org/api/client-go/model_registry.go index 9611e885..876512b6 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/model_registry.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/model_registry.go @@ -2,8 +2,6 @@ package gitlab import ( "bytes" - "fmt" - "net/http" "net/url" ) @@ -27,11 +25,6 @@ var _ ModelRegistryServiceInterface = (*ModelRegistryService)(nil) // // GitLab API docs: https://docs.gitlab.com/api/model_registry/#download-a-model-package-file func (s *ModelRegistryService) DownloadMachineLearningModelPackage(pid, modelVersionID any, path string, filename string, options ...RequestOptionFunc) (*bytes.Reader, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - // The modelVersionID can be an int or a string like "candidate:5", // so we convert it to a string for the URL. mvid, err := parseID(modelVersionID) @@ -39,23 +32,19 @@ func (s *ModelRegistryService) DownloadMachineLearningModelPackage(pid, modelVer return nil, nil, err } - u := fmt.Sprintf("projects/%s/packages/ml_models/%s/files/%s/%s", - PathEscape(project), - url.PathEscape(mvid), - url.PathEscape(path), - url.PathEscape(filename), + buf, resp, err := do[bytes.Buffer](s.client, + withPath("projects/%s/packages/ml_models/%s/files/%s/%s", + ProjectID{pid}, + // the following URI components must not escape `.` which is what withPath does by default + // without NoEscape. + NoEscape{url.PathEscape(mvid)}, + NoEscape{url.PathEscape(path)}, + NoEscape{url.PathEscape(filename)}, + ), + withRequestOpts(options...), ) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - registryDownload := new(bytes.Buffer) - resp, err := s.client.Do(req, registryDownload) if err != nil { return nil, resp, err } - - return bytes.NewReader(registryDownload.Bytes()), resp, err + return bytes.NewReader(buf.Bytes()), resp, nil } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/namespaces.go b/vendor/gitlab.com/gitlab-org/api/client-go/namespaces.go index c69f6a1d..e9760bc1 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/namespaces.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/namespaces.go @@ -16,11 +16,6 @@ package gitlab -import ( - "fmt" - "net/http" -) - type ( NamespacesServiceInterface interface { ListNamespaces(opt *ListNamespacesOptions, options ...RequestOptionFunc) ([]*Namespace, *Response, error) @@ -79,18 +74,11 @@ type ListNamespacesOptions struct { // // GitLab API docs: https://docs.gitlab.com/api/namespaces/#list-all-namespaces func (s *NamespacesService) ListNamespaces(opt *ListNamespacesOptions, options ...RequestOptionFunc) ([]*Namespace, *Response, error) { - req, err := s.client.NewRequest(http.MethodGet, "namespaces", opt, options) - if err != nil { - return nil, nil, err - } - - var n []*Namespace - resp, err := s.client.Do(req, &n) - if err != nil { - return nil, resp, err - } - - return n, resp, nil + return do[[]*Namespace](s.client, + withPath("namespaces"), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // SearchNamespace gets all namespaces that match your string in their name @@ -104,18 +92,11 @@ func (s *NamespacesService) SearchNamespace(query string, options ...RequestOpti } q.Search = query - req, err := s.client.NewRequest(http.MethodGet, "namespaces", &q, options) - if err != nil { - return nil, nil, err - } - - var n []*Namespace - resp, err := s.client.Do(req, &n) - if err != nil { - return nil, resp, err - } - - return n, resp, nil + return do[[]*Namespace](s.client, + withPath("namespaces"), + withAPIOpts(&q), + withRequestOpts(options...), + ) } // GetNamespace gets a namespace by id. @@ -127,20 +108,10 @@ func (s *NamespacesService) GetNamespace(id any, options ...RequestOptionFunc) ( if err != nil { return nil, nil, err } - u := fmt.Sprintf("namespaces/%s", PathEscape(namespace)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - n := new(Namespace) - resp, err := s.client.Do(req, n) - if err != nil { - return nil, resp, err - } - - return n, resp, nil + return do[*Namespace](s.client, + withPath("namespaces/%s", namespace), + withRequestOpts(options...), + ) } // NamespaceExistance represents a namespace exists result. @@ -169,18 +140,9 @@ func (s *NamespacesService) NamespaceExists(id any, opt *NamespaceExistsOptions, if err != nil { return nil, nil, err } - u := fmt.Sprintf("namespaces/%s/exists", namespace) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - n := new(NamespaceExistance) - resp, err := s.client.Do(req, n) - if err != nil { - return nil, resp, err - } - - return n, resp, nil + return do[*NamespaceExistance](s.client, + withPath("namespaces/%s/exists", namespace), + withAPIOpts(opt), + withRequestOpts(options...), + ) } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/notes.go b/vendor/gitlab.com/gitlab-org/api/client-go/notes.go index 1dc08499..e4dc2f0d 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/notes.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/notes.go @@ -17,7 +17,6 @@ package gitlab import ( - "fmt" "net/http" "time" ) @@ -161,24 +160,11 @@ type ListIssueNotesOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/notes/#list-project-issue-notes func (s *NotesService) ListIssueNotes(pid any, issue int64, opt *ListIssueNotesOptions, options ...RequestOptionFunc) ([]*Note, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/issues/%d/notes", PathEscape(project), issue) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var n []*Note - resp, err := s.client.Do(req, &n) - if err != nil { - return nil, resp, err - } - - return n, resp, nil + return do[[]*Note](s.client, + withPath("projects/%s/issues/%d/notes", ProjectID{pid}, issue), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // GetIssueNote returns a single note for a specific project issue. @@ -186,24 +172,10 @@ func (s *NotesService) ListIssueNotes(pid any, issue int64, opt *ListIssueNotesO // GitLab API docs: // https://docs.gitlab.com/api/notes/#get-single-issue-note func (s *NotesService) GetIssueNote(pid any, issue, note int64, options ...RequestOptionFunc) (*Note, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/issues/%d/notes/%d", PathEscape(project), issue, note) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - n := new(Note) - resp, err := s.client.Do(req, n) - if err != nil { - return nil, resp, err - } - - return n, resp, nil + return do[*Note](s.client, + withPath("projects/%s/issues/%d/notes/%d", ProjectID{pid}, issue, note), + withRequestOpts(options...), + ) } // CreateIssueNoteOptions represents the available CreateIssueNote() @@ -222,24 +194,12 @@ type CreateIssueNoteOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/notes/#create-new-issue-note func (s *NotesService) CreateIssueNote(pid any, issue int64, opt *CreateIssueNoteOptions, options ...RequestOptionFunc) (*Note, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/issues/%d/notes", PathEscape(project), issue) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - n := new(Note) - resp, err := s.client.Do(req, n) - if err != nil { - return nil, resp, err - } - - return n, resp, nil + return do[*Note](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/issues/%d/notes", ProjectID{pid}, issue), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // UpdateIssueNoteOptions represents the available UpdateIssueNote() @@ -256,24 +216,12 @@ type UpdateIssueNoteOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/notes/#modify-existing-issue-note func (s *NotesService) UpdateIssueNote(pid any, issue, note int64, opt *UpdateIssueNoteOptions, options ...RequestOptionFunc) (*Note, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/issues/%d/notes/%d", PathEscape(project), issue, note) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - n := new(Note) - resp, err := s.client.Do(req, n) - if err != nil { - return nil, resp, err - } - - return n, resp, nil + return do[*Note](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/issues/%d/notes/%d", ProjectID{pid}, issue, note), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // DeleteIssueNote deletes an existing note of an issue. @@ -281,18 +229,12 @@ func (s *NotesService) UpdateIssueNote(pid any, issue, note int64, opt *UpdateIs // GitLab API docs: // https://docs.gitlab.com/api/notes/#delete-an-issue-note func (s *NotesService) DeleteIssueNote(pid any, issue, note int64, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/issues/%d/notes/%d", PathEscape(project), issue, note) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/issues/%d/notes/%d", ProjectID{pid}, issue, note), + withRequestOpts(options...), + ) + return resp, err } // ListSnippetNotesOptions represents the available ListSnippetNotes() options. @@ -311,24 +253,11 @@ type ListSnippetNotesOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/notes/#list-all-snippet-notes func (s *NotesService) ListSnippetNotes(pid any, snippet int64, opt *ListSnippetNotesOptions, options ...RequestOptionFunc) ([]*Note, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/snippets/%d/notes", PathEscape(project), snippet) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var n []*Note - resp, err := s.client.Do(req, &n) - if err != nil { - return nil, resp, err - } - - return n, resp, nil + return do[[]*Note](s.client, + withPath("projects/%s/snippets/%d/notes", ProjectID{pid}, snippet), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // GetSnippetNote returns a single note for a given snippet. @@ -336,24 +265,10 @@ func (s *NotesService) ListSnippetNotes(pid any, snippet int64, opt *ListSnippet // GitLab API docs: // https://docs.gitlab.com/api/notes/#get-single-snippet-note func (s *NotesService) GetSnippetNote(pid any, snippet, note int64, options ...RequestOptionFunc) (*Note, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/snippets/%d/notes/%d", PathEscape(project), snippet, note) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - n := new(Note) - resp, err := s.client.Do(req, n) - if err != nil { - return nil, resp, err - } - - return n, resp, nil + return do[*Note](s.client, + withPath("projects/%s/snippets/%d/notes/%d", ProjectID{pid}, snippet, note), + withRequestOpts(options...), + ) } // CreateSnippetNoteOptions represents the available CreateSnippetNote() @@ -372,24 +287,12 @@ type CreateSnippetNoteOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/notes/#create-new-snippet-note func (s *NotesService) CreateSnippetNote(pid any, snippet int64, opt *CreateSnippetNoteOptions, options ...RequestOptionFunc) (*Note, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/snippets/%d/notes", PathEscape(project), snippet) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - n := new(Note) - resp, err := s.client.Do(req, n) - if err != nil { - return nil, resp, err - } - - return n, resp, nil + return do[*Note](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/snippets/%d/notes", ProjectID{pid}, snippet), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // UpdateSnippetNoteOptions represents the available UpdateSnippetNote() @@ -406,24 +309,12 @@ type UpdateSnippetNoteOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/notes/#modify-existing-snippet-note func (s *NotesService) UpdateSnippetNote(pid any, snippet, note int64, opt *UpdateSnippetNoteOptions, options ...RequestOptionFunc) (*Note, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/snippets/%d/notes/%d", PathEscape(project), snippet, note) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - n := new(Note) - resp, err := s.client.Do(req, n) - if err != nil { - return nil, resp, err - } - - return n, resp, nil + return do[*Note](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/snippets/%d/notes/%d", ProjectID{pid}, snippet, note), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // DeleteSnippetNote deletes an existing note of a snippet. @@ -431,18 +322,12 @@ func (s *NotesService) UpdateSnippetNote(pid any, snippet, note int64, opt *Upda // GitLab API docs: // https://docs.gitlab.com/api/notes/#delete-a-snippet-note func (s *NotesService) DeleteSnippetNote(pid any, snippet, note int64, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/snippets/%d/notes/%d", PathEscape(project), snippet, note) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/snippets/%d/notes/%d", ProjectID{pid}, snippet, note), + withRequestOpts(options...), + ) + return resp, err } // ListMergeRequestNotesOptions represents the available ListMergeRequestNotes() @@ -461,24 +346,11 @@ type ListMergeRequestNotesOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/notes/#list-all-merge-request-notes func (s *NotesService) ListMergeRequestNotes(pid any, mergeRequest int64, opt *ListMergeRequestNotesOptions, options ...RequestOptionFunc) ([]*Note, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/merge_requests/%d/notes", PathEscape(project), mergeRequest) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var n []*Note - resp, err := s.client.Do(req, &n) - if err != nil { - return nil, resp, err - } - - return n, resp, nil + return do[[]*Note](s.client, + withPath("projects/%s/merge_requests/%d/notes", ProjectID{pid}, mergeRequest), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // GetMergeRequestNote returns a single note for a given merge request. @@ -486,24 +358,10 @@ func (s *NotesService) ListMergeRequestNotes(pid any, mergeRequest int64, opt *L // GitLab API docs: // https://docs.gitlab.com/api/notes/#get-single-merge-request-note func (s *NotesService) GetMergeRequestNote(pid any, mergeRequest, note int64, options ...RequestOptionFunc) (*Note, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/merge_requests/%d/notes/%d", PathEscape(project), mergeRequest, note) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - n := new(Note) - resp, err := s.client.Do(req, n) - if err != nil { - return nil, resp, err - } - - return n, resp, nil + return do[*Note](s.client, + withPath("projects/%s/merge_requests/%d/notes/%d", ProjectID{pid}, mergeRequest, note), + withRequestOpts(options...), + ) } // CreateMergeRequestNoteOptions represents the available @@ -523,24 +381,12 @@ type CreateMergeRequestNoteOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/notes/#create-new-merge-request-note func (s *NotesService) CreateMergeRequestNote(pid any, mergeRequest int64, opt *CreateMergeRequestNoteOptions, options ...RequestOptionFunc) (*Note, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/merge_requests/%d/notes", PathEscape(project), mergeRequest) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - n := new(Note) - resp, err := s.client.Do(req, n) - if err != nil { - return nil, resp, err - } - - return n, resp, nil + return do[*Note](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/merge_requests/%d/notes", ProjectID{pid}, mergeRequest), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // UpdateMergeRequestNoteOptions represents the available @@ -557,24 +403,12 @@ type UpdateMergeRequestNoteOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/notes/#modify-existing-merge-request-note func (s *NotesService) UpdateMergeRequestNote(pid any, mergeRequest, note int64, opt *UpdateMergeRequestNoteOptions, options ...RequestOptionFunc) (*Note, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf( - "projects/%s/merge_requests/%d/notes/%d", PathEscape(project), mergeRequest, note) - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - n := new(Note) - resp, err := s.client.Do(req, n) - if err != nil { - return nil, resp, err - } - - return n, resp, nil + return do[*Note](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/merge_requests/%d/notes/%d", ProjectID{pid}, mergeRequest, note), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // DeleteMergeRequestNote deletes an existing note of a merge request. @@ -582,19 +416,12 @@ func (s *NotesService) UpdateMergeRequestNote(pid any, mergeRequest, note int64, // GitLab API docs: // https://docs.gitlab.com/api/notes/#delete-a-merge-request-note func (s *NotesService) DeleteMergeRequestNote(pid any, mergeRequest, note int64, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf( - "projects/%s/merge_requests/%d/notes/%d", PathEscape(project), mergeRequest, note) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/merge_requests/%d/notes/%d", ProjectID{pid}, mergeRequest, note), + withRequestOpts(options...), + ) + return resp, err } // ListEpicNotesOptions represents the available ListEpicNotes() options. @@ -614,24 +441,11 @@ type ListEpicNotesOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/notes/#list-all-epic-notes func (s *NotesService) ListEpicNotes(gid any, epic int64, opt *ListEpicNotesOptions, options ...RequestOptionFunc) ([]*Note, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/epics/%d/notes", PathEscape(group), epic) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var n []*Note - resp, err := s.client.Do(req, &n) - if err != nil { - return nil, resp, err - } - - return n, resp, nil + return do[[]*Note](s.client, + withPath("groups/%s/epics/%d/notes", GroupID{gid}, epic), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // GetEpicNote returns a single note for an epic. @@ -640,24 +454,10 @@ func (s *NotesService) ListEpicNotes(gid any, epic int64, opt *ListEpicNotesOpti // GitLab API docs: // https://docs.gitlab.com/api/notes/#get-single-epic-note func (s *NotesService) GetEpicNote(gid any, epic, note int64, options ...RequestOptionFunc) (*Note, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/epics/%d/notes/%d", PathEscape(group), epic, note) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - n := new(Note) - resp, err := s.client.Do(req, n) - if err != nil { - return nil, resp, err - } - - return n, resp, nil + return do[*Note](s.client, + withPath("groups/%s/epics/%d/notes/%d", GroupID{gid}, epic, note), + withRequestOpts(options...), + ) } // CreateEpicNoteOptions represents the available CreateEpicNote() options. @@ -675,24 +475,12 @@ type CreateEpicNoteOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/notes/#create-new-epic-note func (s *NotesService) CreateEpicNote(gid any, epic int64, opt *CreateEpicNoteOptions, options ...RequestOptionFunc) (*Note, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/epics/%d/notes", PathEscape(group), epic) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - n := new(Note) - resp, err := s.client.Do(req, n) - if err != nil { - return nil, resp, err - } - - return n, resp, nil + return do[*Note](s.client, + withMethod(http.MethodPost), + withPath("groups/%s/epics/%d/notes", GroupID{gid}, epic), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // UpdateEpicNoteOptions represents the available UpdateEpicNote() options. @@ -709,24 +497,12 @@ type UpdateEpicNoteOptions struct { // // https://docs.gitlab.com/api/notes/#modify-existing-epic-note func (s *NotesService) UpdateEpicNote(gid any, epic, note int64, opt *UpdateEpicNoteOptions, options ...RequestOptionFunc) (*Note, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/epics/%d/notes/%d", PathEscape(group), epic, note) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - n := new(Note) - resp, err := s.client.Do(req, n) - if err != nil { - return nil, resp, err - } - - return n, resp, nil + return do[*Note](s.client, + withMethod(http.MethodPut), + withPath("groups/%s/epics/%d/notes/%d", GroupID{gid}, epic, note), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // DeleteEpicNote deletes an existing note of a merge request. @@ -734,16 +510,10 @@ func (s *NotesService) UpdateEpicNote(gid any, epic, note int64, opt *UpdateEpic // // https://docs.gitlab.com/api/notes/#delete-an-epic-note func (s *NotesService) DeleteEpicNote(gid any, epic, note int64, options ...RequestOptionFunc) (*Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("groups/%s/epics/%d/notes/%d", PathEscape(group), epic, note) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("groups/%s/epics/%d/notes/%d", GroupID{gid}, epic, note), + withRequestOpts(options...), + ) + return resp, err } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/notifications.go b/vendor/gitlab.com/gitlab-org/api/client-go/notifications.go index fab7089c..5f95f6cb 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/notifications.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/notifications.go @@ -18,17 +18,40 @@ package gitlab import ( "errors" - "fmt" "net/http" ) type ( NotificationSettingsServiceInterface interface { + // GetGlobalSettings returns current notification settings and email address. + // + // GitLab API docs: + // https://docs.gitlab.com/api/notification_settings/#global-notification-settings GetGlobalSettings(options ...RequestOptionFunc) (*NotificationSettings, *Response, error) + // UpdateGlobalSettings updates current notification settings and email address. + // + // GitLab API docs: + // https://docs.gitlab.com/api/notification_settings/#update-global-notification-settings UpdateGlobalSettings(opt *NotificationSettingsOptions, options ...RequestOptionFunc) (*NotificationSettings, *Response, error) + // GetSettingsForGroup returns current group notification settings. + // + // GitLab API docs: + // https://docs.gitlab.com/api/notification_settings/#group--project-level-notification-settings GetSettingsForGroup(gid any, options ...RequestOptionFunc) (*NotificationSettings, *Response, error) + // GetSettingsForProject returns current project notification settings. + // + // GitLab API docs: + // https://docs.gitlab.com/api/notification_settings/#group--project-level-notification-settings GetSettingsForProject(pid any, options ...RequestOptionFunc) (*NotificationSettings, *Response, error) + // UpdateSettingsForGroup updates current group notification settings. + // + // GitLab API docs: + // https://docs.gitlab.com/api/notification_settings/#update-groupproject-level-notification-settings UpdateSettingsForGroup(gid any, opt *NotificationSettingsOptions, options ...RequestOptionFunc) (*NotificationSettings, *Response, error) + // UpdateSettingsForProject updates current project notification settings. + // + // GitLab API docs: + // https://docs.gitlab.com/api/notification_settings/#update-groupproject-level-notification-settings UpdateSettingsForProject(pid any, opt *NotificationSettingsOptions, options ...RequestOptionFunc) (*NotificationSettings, *Response, error) } @@ -82,25 +105,11 @@ func (ns NotificationSettings) String() string { return Stringify(ns) } -// GetGlobalSettings returns current notification settings and email address. -// -// GitLab API docs: -// https://docs.gitlab.com/api/notification_settings/#global-notification-settings func (s *NotificationSettingsService) GetGlobalSettings(options ...RequestOptionFunc) (*NotificationSettings, *Response, error) { - u := "notification_settings" - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - ns := new(NotificationSettings) - resp, err := s.client.Do(req, ns) - if err != nil { - return nil, resp, err - } - - return ns, resp, nil + return do[*NotificationSettings](s.client, + withPath("notification_settings"), + withRequestOpts(options...), + ) } // NotificationSettingsOptions represents the available options that can be passed @@ -128,128 +137,48 @@ type NotificationSettingsOptions struct { SuccessPipeline *bool `url:"success_pipeline,omitempty" json:"success_pipeline,omitempty"` } -// UpdateGlobalSettings updates current notification settings and email address. -// -// GitLab API docs: -// https://docs.gitlab.com/api/notification_settings/#update-global-notification-settings func (s *NotificationSettingsService) UpdateGlobalSettings(opt *NotificationSettingsOptions, options ...RequestOptionFunc) (*NotificationSettings, *Response, error) { if opt.Level != nil && *opt.Level == GlobalNotificationLevel { return nil, nil, errors.New( "notification level 'global' is not valid for global notification settings") } - u := "notification_settings" - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - ns := new(NotificationSettings) - resp, err := s.client.Do(req, ns) - if err != nil { - return nil, resp, err - } - - return ns, resp, nil + return do[*NotificationSettings](s.client, + withMethod(http.MethodPut), + withPath("notification_settings"), + withAPIOpts(opt), + withRequestOpts(options...), + ) } -// GetSettingsForGroup returns current group notification settings. -// -// GitLab API docs: -// https://docs.gitlab.com/api/notification_settings/#group--project-level-notification-settings func (s *NotificationSettingsService) GetSettingsForGroup(gid any, options ...RequestOptionFunc) (*NotificationSettings, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/notification_settings", PathEscape(group)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - ns := new(NotificationSettings) - resp, err := s.client.Do(req, ns) - if err != nil { - return nil, resp, err - } - - return ns, resp, nil + return do[*NotificationSettings](s.client, + withPath("groups/%s/notification_settings", GroupID{gid}), + withRequestOpts(options...), + ) } -// GetSettingsForProject returns current project notification settings. -// -// GitLab API docs: -// https://docs.gitlab.com/api/notification_settings/#group--project-level-notification-settings func (s *NotificationSettingsService) GetSettingsForProject(pid any, options ...RequestOptionFunc) (*NotificationSettings, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/notification_settings", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - ns := new(NotificationSettings) - resp, err := s.client.Do(req, ns) - if err != nil { - return nil, resp, err - } - - return ns, resp, nil + return do[*NotificationSettings](s.client, + withPath("projects/%s/notification_settings", ProjectID{pid}), + withRequestOpts(options...), + ) } -// UpdateSettingsForGroup updates current group notification settings. -// -// GitLab API docs: -// https://docs.gitlab.com/api/notification_settings/#update-groupproject-level-notification-settings func (s *NotificationSettingsService) UpdateSettingsForGroup(gid any, opt *NotificationSettingsOptions, options ...RequestOptionFunc) (*NotificationSettings, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/notification_settings", PathEscape(group)) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - ns := new(NotificationSettings) - resp, err := s.client.Do(req, ns) - if err != nil { - return nil, resp, err - } - - return ns, resp, nil + return do[*NotificationSettings](s.client, + withMethod(http.MethodPut), + withPath("groups/%s/notification_settings", GroupID{gid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } -// UpdateSettingsForProject updates current project notification settings. -// -// GitLab API docs: -// https://docs.gitlab.com/api/notification_settings/#update-groupproject-level-notification-settings func (s *NotificationSettingsService) UpdateSettingsForProject(pid any, opt *NotificationSettingsOptions, options ...RequestOptionFunc) (*NotificationSettings, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/notification_settings", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - ns := new(NotificationSettings) - resp, err := s.client.Do(req, ns) - if err != nil { - return nil, resp, err - } - - return ns, resp, nil + return do[*NotificationSettings](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/notification_settings", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/packages.go b/vendor/gitlab.com/gitlab-org/api/client-go/packages.go index 7a08072f..57e8eee1 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/packages.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/packages.go @@ -17,7 +17,6 @@ package gitlab import ( - "fmt" "net/http" "time" ) @@ -137,24 +136,11 @@ type ListProjectPackagesOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/packages/#for-a-project func (s *PackagesService) ListProjectPackages(pid any, opt *ListProjectPackagesOptions, options ...RequestOptionFunc) ([]*Package, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/packages", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var ps []*Package - resp, err := s.client.Do(req, &ps) - if err != nil { - return nil, resp, err - } - - return ps, resp, nil + return do[[]*Package](s.client, + withPath("projects/%s/packages", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // ListGroupPackagesOptions represents the available ListGroupPackages() @@ -178,24 +164,11 @@ type ListGroupPackagesOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/packages/#for-a-group func (s *PackagesService) ListGroupPackages(gid any, opt *ListGroupPackagesOptions, options ...RequestOptionFunc) ([]*GroupPackage, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/packages", PathEscape(group)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var ps []*GroupPackage - resp, err := s.client.Do(req, &ps) - if err != nil { - return nil, resp, err - } - - return ps, resp, nil + return do[[]*GroupPackage](s.client, + withPath("groups/%s/packages", GroupID{gid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // ListPackageFilesOptions represents the available ListPackageFiles() @@ -212,28 +185,11 @@ type ListPackageFilesOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/packages/#list-package-files func (s *PackagesService) ListPackageFiles(pid any, pkg int64, opt *ListPackageFilesOptions, options ...RequestOptionFunc) ([]*PackageFile, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf( - "projects/%s/packages/%d/package_files", - PathEscape(project), - pkg, + return do[[]*PackageFile](s.client, + withPath("projects/%s/packages/%d/package_files", ProjectID{pid}, pkg), + withAPIOpts(opt), + withRequestOpts(options...), ) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var pfs []*PackageFile - resp, err := s.client.Do(req, &pfs) - if err != nil { - return nil, resp, err - } - - return pfs, resp, nil } // DeleteProjectPackage deletes a package in a project. @@ -241,18 +197,12 @@ func (s *PackagesService) ListPackageFiles(pid any, pkg int64, opt *ListPackageF // GitLab API docs: // https://docs.gitlab.com/api/packages/#delete-a-project-package func (s *PackagesService) DeleteProjectPackage(pid any, pkg int64, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/packages/%d", PathEscape(project), pkg) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/packages/%d", ProjectID{pid}, pkg), + withRequestOpts(options...), + ) + return resp, err } // DeletePackageFile deletes a file in project package @@ -260,16 +210,10 @@ func (s *PackagesService) DeleteProjectPackage(pid any, pkg int64, options ...Re // GitLab API docs: // https://docs.gitlab.com/api/packages/#delete-a-package-file func (s *PackagesService) DeletePackageFile(pid any, pkg, file int64, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/packages/%d/package_files/%d", PathEscape(project), pkg, file) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/packages/%d/package_files/%d", ProjectID{pid}, pkg, file), + withRequestOpts(options...), + ) + return resp, err } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/pages.go b/vendor/gitlab.com/gitlab-org/api/client-go/pages.go index baffb255..dc6bb5a3 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/pages.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/pages.go @@ -17,15 +17,28 @@ package gitlab import ( - "fmt" "net/http" "time" ) type ( PagesServiceInterface interface { + // UnpublishPages unpublishes pages. The user must have admin privileges. + // + // GitLab API docs: + // https://docs.gitlab.com/api/pages/#unpublish-pages UnpublishPages(gid any, options ...RequestOptionFunc) (*Response, error) + // GetPages lists Pages settings for a project. The user must have at least + // maintainer privileges. + // + // GitLab API Docs: + // https://docs.gitlab.com/api/pages/#get-pages-settings-for-a-project GetPages(gid any, options ...RequestOptionFunc) (*Pages, *Response, error) + // UpdatePages updates Pages settings for a project. The user must have + // administrator privileges. + // + // GitLab API Docs: + // https://docs.gitlab.com/api/pages/#update-pages-settings-for-a-project UpdatePages(pid any, opt UpdatePagesOptions, options ...RequestOptionFunc) (*Pages, *Response, error) } @@ -60,49 +73,20 @@ type PagesDeployment struct { RootDirectory string `json:"root_directory"` } -// UnpublishPages unpublished pages. The user must have admin privileges. -// -// GitLab API docs: -// https://docs.gitlab.com/api/pages/#unpublish-pages func (s *PagesService) UnpublishPages(gid any, options ...RequestOptionFunc) (*Response, error) { - page, err := parseID(gid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/pages", PathEscape(page)) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/pages", ProjectID{gid}), + withRequestOpts(options...), + ) + return resp, err } -// GetPages lists Pages settings for a project. The user must have at least -// maintainer privileges. -// -// GitLab API Docs: -// https://docs.gitlab.com/api/pages/#get-pages-settings-for-a-project func (s *PagesService) GetPages(gid any, options ...RequestOptionFunc) (*Pages, *Response, error) { - project, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/pages", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - p := new(Pages) - resp, err := s.client.Do(req, p) - if err != nil { - return nil, resp, err - } - - return p, resp, nil + return do[*Pages](s.client, + withPath("projects/%s/pages", ProjectID{gid}), + withRequestOpts(options...), + ) } // UpdatePagesOptions represents the available UpdatePages() options. @@ -114,28 +98,11 @@ type UpdatePagesOptions struct { PagesHTTPSOnly *bool `url:"pages_https_only,omitempty" json:"pages_https_only,omitempty"` } -// UpdatePages updates Pages settings for a project. The user must have -// administrator privileges. -// -// GitLab API Docs: -// https://docs.gitlab.com/api/pages/#update-pages-settings-for-a-project func (s *PagesService) UpdatePages(pid any, opt UpdatePagesOptions, options ...RequestOptionFunc) (*Pages, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/pages", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPatch, u, opt, options) - if err != nil { - return nil, nil, err - } - - p := new(Pages) - resp, err := s.client.Do(req, p) - if err != nil { - return nil, resp, err - } - - return p, resp, nil + return do[*Pages](s.client, + withMethod(http.MethodPatch), + withPath("projects/%s/pages", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/pages_domains.go b/vendor/gitlab.com/gitlab-org/api/client-go/pages_domains.go index 6d18c5f8..745dd3d0 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/pages_domains.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/pages_domains.go @@ -17,7 +17,6 @@ package gitlab import ( - "fmt" "net/http" "time" ) @@ -81,24 +80,11 @@ type ListPagesDomainsOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/pages_domains/#list-pages-domains func (s *PagesDomainsService) ListPagesDomains(pid any, opt *ListPagesDomainsOptions, options ...RequestOptionFunc) ([]*PagesDomain, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/pages/domains", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var pd []*PagesDomain - resp, err := s.client.Do(req, &pd) - if err != nil { - return nil, resp, err - } - - return pd, resp, nil + return do[[]*PagesDomain](s.client, + withPath("projects/%s/pages/domains", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // ListAllPagesDomains gets a list of all pages domains. @@ -106,18 +92,10 @@ func (s *PagesDomainsService) ListPagesDomains(pid any, opt *ListPagesDomainsOpt // GitLab API docs: // https://docs.gitlab.com/api/pages_domains/#list-all-pages-domains func (s *PagesDomainsService) ListAllPagesDomains(options ...RequestOptionFunc) ([]*PagesDomain, *Response, error) { - req, err := s.client.NewRequest(http.MethodGet, "pages/domains", nil, options) - if err != nil { - return nil, nil, err - } - - var pd []*PagesDomain - resp, err := s.client.Do(req, &pd) - if err != nil { - return nil, resp, err - } - - return pd, resp, nil + return do[[]*PagesDomain](s.client, + withPath("pages/domains"), + withRequestOpts(options...), + ) } // GetPagesDomain get a specific pages domain for a project. @@ -125,24 +103,10 @@ func (s *PagesDomainsService) ListAllPagesDomains(options ...RequestOptionFunc) // GitLab API docs: // https://docs.gitlab.com/api/pages_domains/#single-pages-domain func (s *PagesDomainsService) GetPagesDomain(pid any, domain string, options ...RequestOptionFunc) (*PagesDomain, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/pages/domains/%s", PathEscape(project), domain) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - pd := new(PagesDomain) - resp, err := s.client.Do(req, pd) - if err != nil { - return nil, resp, err - } - - return pd, resp, nil + return do[*PagesDomain](s.client, + withPath("projects/%s/pages/domains/%s", ProjectID{pid}, domain), + withRequestOpts(options...), + ) } // CreatePagesDomainOptions represents the available CreatePagesDomain() options. @@ -161,24 +125,12 @@ type CreatePagesDomainOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/pages_domains/#create-new-pages-domain func (s *PagesDomainsService) CreatePagesDomain(pid any, opt *CreatePagesDomainOptions, options ...RequestOptionFunc) (*PagesDomain, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/pages/domains", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - pd := new(PagesDomain) - resp, err := s.client.Do(req, pd) - if err != nil { - return nil, resp, err - } - - return pd, resp, nil + return do[*PagesDomain](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/pages/domains", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // UpdatePagesDomainOptions represents the available UpdatePagesDomain() options. @@ -196,24 +148,12 @@ type UpdatePagesDomainOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/pages_domains/#update-pages-domain func (s *PagesDomainsService) UpdatePagesDomain(pid any, domain string, opt *UpdatePagesDomainOptions, options ...RequestOptionFunc) (*PagesDomain, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/pages/domains/%s", PathEscape(project), domain) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - pd := new(PagesDomain) - resp, err := s.client.Do(req, pd) - if err != nil { - return nil, resp, err - } - - return pd, resp, nil + return do[*PagesDomain](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/pages/domains/%s", ProjectID{pid}, domain), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // DeletePagesDomain deletes an existing project pages domain. @@ -221,16 +161,10 @@ func (s *PagesDomainsService) UpdatePagesDomain(pid any, domain string, opt *Upd // GitLab API docs: // https://docs.gitlab.com/api/pages_domains/#delete-pages-domain func (s *PagesDomainsService) DeletePagesDomain(pid any, domain string, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/pages/domains/%s", PathEscape(project), domain) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/pages/domains/%s", ProjectID{pid}, domain), + withRequestOpts(options...), + ) + return resp, err } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/pagination.go b/vendor/gitlab.com/gitlab-org/api/client-go/pagination.go index 1549f15f..51c93935 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/pagination.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/pagination.go @@ -1,5 +1,3 @@ -//go:build go1.23 - package gitlab import ( diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/personal_access_tokens.go b/vendor/gitlab.com/gitlab-org/api/client-go/personal_access_tokens.go index c87fd342..f840773e 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/personal_access_tokens.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/personal_access_tokens.go @@ -17,7 +17,6 @@ package gitlab import ( - "fmt" "net/http" "time" ) @@ -101,18 +100,11 @@ type ListPersonalAccessTokensOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/personal_access_tokens/#list-all-personal-access-tokens func (s *PersonalAccessTokensService) ListPersonalAccessTokens(opt *ListPersonalAccessTokensOptions, options ...RequestOptionFunc) ([]*PersonalAccessToken, *Response, error) { - req, err := s.client.NewRequest(http.MethodGet, "personal_access_tokens", opt, options) - if err != nil { - return nil, nil, err - } - - var pats []*PersonalAccessToken - resp, err := s.client.Do(req, &pats) - if err != nil { - return nil, resp, err - } - - return pats, resp, nil + return do[[]*PersonalAccessToken](s.client, + withPath("personal_access_tokens"), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // GetSinglePersonalAccessTokenByID get a single personal access token by its ID. @@ -120,19 +112,10 @@ func (s *PersonalAccessTokensService) ListPersonalAccessTokens(opt *ListPersonal // GitLab API docs: // https://docs.gitlab.com/api/personal_access_tokens/#get-details-on-a-personal-access-token func (s *PersonalAccessTokensService) GetSinglePersonalAccessTokenByID(token int64, options ...RequestOptionFunc) (*PersonalAccessToken, *Response, error) { - u := fmt.Sprintf("personal_access_tokens/%d", token) - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - pat := new(PersonalAccessToken) - resp, err := s.client.Do(req, pat) - if err != nil { - return nil, resp, err - } - - return pat, resp, nil + return do[*PersonalAccessToken](s.client, + withPath("personal_access_tokens/%d", token), + withRequestOpts(options...), + ) } // GetSinglePersonalAccessToken get a single personal access token by using @@ -141,19 +124,10 @@ func (s *PersonalAccessTokensService) GetSinglePersonalAccessTokenByID(token int // GitLab API docs: // https://docs.gitlab.com/api/personal_access_tokens/#self-inform func (s *PersonalAccessTokensService) GetSinglePersonalAccessToken(options ...RequestOptionFunc) (*PersonalAccessToken, *Response, error) { - u := "personal_access_tokens/self" - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - pat := new(PersonalAccessToken) - resp, err := s.client.Do(req, pat) - if err != nil { - return nil, resp, err - } - - return pat, resp, nil + return do[*PersonalAccessToken](s.client, + withPath("personal_access_tokens/self"), + withRequestOpts(options...), + ) } // RotatePersonalAccessTokenOptions represents the available RotatePersonalAccessToken() @@ -176,20 +150,12 @@ func (s *PersonalAccessTokensService) RotatePersonalAccessToken(token int64, opt // GitLab API docs: // https://docs.gitlab.com/api/personal_access_tokens/#rotate-a-personal-access-token func (s *PersonalAccessTokensService) RotatePersonalAccessTokenByID(token int64, opt *RotatePersonalAccessTokenOptions, options ...RequestOptionFunc) (*PersonalAccessToken, *Response, error) { - u := fmt.Sprintf("personal_access_tokens/%d/rotate", token) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - pat := new(PersonalAccessToken) - resp, err := s.client.Do(req, pat) - if err != nil { - return nil, resp, err - } - - return pat, resp, nil + return do[*PersonalAccessToken](s.client, + withMethod(http.MethodPost), + withPath("personal_access_tokens/%d/rotate", token), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // RotatePersonalAccessTokenSelf revokes the currently authenticated token @@ -198,20 +164,12 @@ func (s *PersonalAccessTokensService) RotatePersonalAccessTokenByID(token int64, // GitLab API docs: // https://docs.gitlab.com/api/personal_access_tokens/#self-rotate func (s *PersonalAccessTokensService) RotatePersonalAccessTokenSelf(opt *RotatePersonalAccessTokenOptions, options ...RequestOptionFunc) (*PersonalAccessToken, *Response, error) { - u := "personal_access_tokens/self/rotate" - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - pat := new(PersonalAccessToken) - resp, err := s.client.Do(req, pat) - if err != nil { - return nil, resp, err - } - - return pat, resp, nil + return do[*PersonalAccessToken](s.client, + withMethod(http.MethodPost), + withPath("personal_access_tokens/self/rotate"), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // RevokePersonalAccessToken is a backwards-compat shim for RevokePersonalAccessTokenByID. @@ -225,14 +183,12 @@ func (s *PersonalAccessTokensService) RevokePersonalAccessToken(token int64, opt // GitLab API docs: // https://docs.gitlab.com/api/personal_access_tokens/#revoke-a-personal-access-token func (s *PersonalAccessTokensService) RevokePersonalAccessTokenByID(token int64, options ...RequestOptionFunc) (*Response, error) { - u := fmt.Sprintf("personal_access_tokens/%d", token) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("personal_access_tokens/%d", token), + withRequestOpts(options...), + ) + return resp, err } // RevokePersonalAccessTokenSelf revokes the currently authenticated @@ -241,12 +197,10 @@ func (s *PersonalAccessTokensService) RevokePersonalAccessTokenByID(token int64, // GitLab API docs: // https://docs.gitlab.com/api/personal_access_tokens/#self-revoke func (s *PersonalAccessTokensService) RevokePersonalAccessTokenSelf(options ...RequestOptionFunc) (*Response, error) { - u := "personal_access_tokens/self" - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("personal_access_tokens/self"), + withRequestOpts(options...), + ) + return resp, err } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/pipeline_schedules.go b/vendor/gitlab.com/gitlab-org/api/client-go/pipeline_schedules.go index a6541d4f..6b100e22 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/pipeline_schedules.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/pipeline_schedules.go @@ -17,7 +17,6 @@ package gitlab import ( - "fmt" "net/http" "time" ) @@ -92,24 +91,11 @@ type ListPipelineSchedulesOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/pipeline_schedules/#get-all-pipeline-schedules func (s *PipelineSchedulesService) ListPipelineSchedules(pid any, opt *ListPipelineSchedulesOptions, options ...RequestOptionFunc) ([]*PipelineSchedule, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/pipeline_schedules", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var ps []*PipelineSchedule - resp, err := s.client.Do(req, &ps) - if err != nil { - return nil, resp, err - } - - return ps, resp, nil + return do[[]*PipelineSchedule](s.client, + withPath("projects/%s/pipeline_schedules", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // GetPipelineSchedule gets a pipeline schedule. @@ -117,24 +103,10 @@ func (s *PipelineSchedulesService) ListPipelineSchedules(pid any, opt *ListPipel // GitLab API docs: // https://docs.gitlab.com/api/pipeline_schedules/#get-a-single-pipeline-schedule func (s *PipelineSchedulesService) GetPipelineSchedule(pid any, schedule int64, options ...RequestOptionFunc) (*PipelineSchedule, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/pipeline_schedules/%d", PathEscape(project), schedule) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - p := new(PipelineSchedule) - resp, err := s.client.Do(req, p) - if err != nil { - return nil, resp, err - } - - return p, resp, nil + return do[*PipelineSchedule](s.client, + withPath("projects/%s/pipeline_schedules/%d", ProjectID{pid}, schedule), + withRequestOpts(options...), + ) } // ListPipelinesTriggeredByScheduleOptions represents the available @@ -152,24 +124,11 @@ type ListPipelinesTriggeredByScheduleOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/pipeline_schedules/#get-all-pipelines-triggered-by-a-pipeline-schedule func (s *PipelineSchedulesService) ListPipelinesTriggeredBySchedule(pid any, schedule int64, opt *ListPipelinesTriggeredByScheduleOptions, options ...RequestOptionFunc) ([]*Pipeline, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/pipeline_schedules/%d/pipelines", PathEscape(project), schedule) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var p []*Pipeline - resp, err := s.client.Do(req, &p) - if err != nil { - return nil, resp, err - } - - return p, resp, nil + return do[[]*Pipeline](s.client, + withPath("projects/%s/pipeline_schedules/%d/pipelines", ProjectID{pid}, schedule), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // CreatePipelineScheduleOptions represents the available @@ -191,24 +150,12 @@ type CreatePipelineScheduleOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/pipeline_schedules/#create-a-new-pipeline-schedule func (s *PipelineSchedulesService) CreatePipelineSchedule(pid any, opt *CreatePipelineScheduleOptions, options ...RequestOptionFunc) (*PipelineSchedule, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/pipeline_schedules", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - p := new(PipelineSchedule) - resp, err := s.client.Do(req, p) - if err != nil { - return nil, resp, err - } - - return p, resp, nil + return do[*PipelineSchedule](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/pipeline_schedules", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // EditPipelineScheduleOptions represents the available @@ -230,24 +177,12 @@ type EditPipelineScheduleOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/pipeline_schedules/#edit-a-pipeline-schedule func (s *PipelineSchedulesService) EditPipelineSchedule(pid any, schedule int64, opt *EditPipelineScheduleOptions, options ...RequestOptionFunc) (*PipelineSchedule, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/pipeline_schedules/%d", PathEscape(project), schedule) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - p := new(PipelineSchedule) - resp, err := s.client.Do(req, p) - if err != nil { - return nil, resp, err - } - - return p, resp, nil + return do[*PipelineSchedule](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/pipeline_schedules/%d", ProjectID{pid}, schedule), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // TakeOwnershipOfPipelineSchedule sets the owner of the specified @@ -256,24 +191,11 @@ func (s *PipelineSchedulesService) EditPipelineSchedule(pid any, schedule int64, // GitLab API docs: // https://docs.gitlab.com/api/pipeline_schedules/#take-ownership-of-a-pipeline-schedule func (s *PipelineSchedulesService) TakeOwnershipOfPipelineSchedule(pid any, schedule int64, options ...RequestOptionFunc) (*PipelineSchedule, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/pipeline_schedules/%d/take_ownership", PathEscape(project), schedule) - - req, err := s.client.NewRequest(http.MethodPost, u, nil, options) - if err != nil { - return nil, nil, err - } - - p := new(PipelineSchedule) - resp, err := s.client.Do(req, p) - if err != nil { - return nil, resp, err - } - - return p, resp, nil + return do[*PipelineSchedule](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/pipeline_schedules/%d/take_ownership", ProjectID{pid}, schedule), + withRequestOpts(options...), + ) } // DeletePipelineSchedule deletes a pipeline schedule. @@ -281,18 +203,12 @@ func (s *PipelineSchedulesService) TakeOwnershipOfPipelineSchedule(pid any, sche // GitLab API docs: // https://docs.gitlab.com/api/pipeline_schedules/#delete-a-pipeline-schedule func (s *PipelineSchedulesService) DeletePipelineSchedule(pid any, schedule int64, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/pipeline_schedules/%d", PathEscape(project), schedule) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/pipeline_schedules/%d", ProjectID{pid}, schedule), + withRequestOpts(options...), + ) + return resp, err } // RunPipelineSchedule triggers a new scheduled pipeline to run immediately. @@ -300,18 +216,12 @@ func (s *PipelineSchedulesService) DeletePipelineSchedule(pid any, schedule int6 // GitLab API docs: // https://docs.gitlab.com/api/pipeline_schedules/#run-a-scheduled-pipeline-immediately func (s *PipelineSchedulesService) RunPipelineSchedule(pid any, schedule int64, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/pipeline_schedules/%d/play", PathEscape(project), schedule) - - req, err := s.client.NewRequest(http.MethodPost, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/pipeline_schedules/%d/play", ProjectID{pid}, schedule), + withRequestOpts(options...), + ) + return resp, err } // CreatePipelineScheduleVariableOptions represents the available @@ -330,24 +240,12 @@ type CreatePipelineScheduleVariableOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/pipeline_schedules/#create-a-new-pipeline-schedule func (s *PipelineSchedulesService) CreatePipelineScheduleVariable(pid any, schedule int64, opt *CreatePipelineScheduleVariableOptions, options ...RequestOptionFunc) (*PipelineVariable, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/pipeline_schedules/%d/variables", PathEscape(project), schedule) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - p := new(PipelineVariable) - resp, err := s.client.Do(req, p) - if err != nil { - return nil, resp, err - } - - return p, resp, nil + return do[*PipelineVariable](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/pipeline_schedules/%d/variables", ProjectID{pid}, schedule), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // EditPipelineScheduleVariableOptions represents the available @@ -365,24 +263,12 @@ type EditPipelineScheduleVariableOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/pipeline_schedules/#edit-a-pipeline-schedule-variable func (s *PipelineSchedulesService) EditPipelineScheduleVariable(pid any, schedule int64, key string, opt *EditPipelineScheduleVariableOptions, options ...RequestOptionFunc) (*PipelineVariable, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/pipeline_schedules/%d/variables/%s", PathEscape(project), schedule, key) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - p := new(PipelineVariable) - resp, err := s.client.Do(req, p) - if err != nil { - return nil, resp, err - } - - return p, resp, nil + return do[*PipelineVariable](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/pipeline_schedules/%d/variables/%s", ProjectID{pid}, schedule, key), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // DeletePipelineScheduleVariable creates a pipeline schedule variable. @@ -390,22 +276,9 @@ func (s *PipelineSchedulesService) EditPipelineScheduleVariable(pid any, schedul // GitLab API docs: // https://docs.gitlab.com/api/pipeline_schedules/#delete-a-pipeline-schedule-variable func (s *PipelineSchedulesService) DeletePipelineScheduleVariable(pid any, schedule int64, key string, options ...RequestOptionFunc) (*PipelineVariable, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/pipeline_schedules/%d/variables/%s", PathEscape(project), schedule, key) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, nil, err - } - - p := new(PipelineVariable) - resp, err := s.client.Do(req, p) - if err != nil { - return nil, resp, err - } - - return p, resp, nil + return do[*PipelineVariable](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/pipeline_schedules/%d/variables/%s", ProjectID{pid}, schedule, key), + withRequestOpts(options...), + ) } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/pipeline_triggers.go b/vendor/gitlab.com/gitlab-org/api/client-go/pipeline_triggers.go index a065cbc6..c540cf3b 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/pipeline_triggers.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/pipeline_triggers.go @@ -17,7 +17,6 @@ package gitlab import ( - "fmt" "net/http" "time" ) @@ -71,24 +70,11 @@ type ListPipelineTriggersOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/pipeline_triggers/#list-project-trigger-tokens func (s *PipelineTriggersService) ListPipelineTriggers(pid any, opt *ListPipelineTriggersOptions, options ...RequestOptionFunc) ([]*PipelineTrigger, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/triggers", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var pt []*PipelineTrigger - resp, err := s.client.Do(req, &pt) - if err != nil { - return nil, resp, err - } - - return pt, resp, nil + return do[[]*PipelineTrigger](s.client, + withPath("projects/%s/triggers", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // GetPipelineTrigger gets a specific pipeline trigger for a project. @@ -96,24 +82,10 @@ func (s *PipelineTriggersService) ListPipelineTriggers(pid any, opt *ListPipelin // GitLab API docs: // https://docs.gitlab.com/api/pipeline_triggers/#get-trigger-token-details func (s *PipelineTriggersService) GetPipelineTrigger(pid any, trigger int64, options ...RequestOptionFunc) (*PipelineTrigger, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/triggers/%d", PathEscape(project), trigger) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - pt := new(PipelineTrigger) - resp, err := s.client.Do(req, pt) - if err != nil { - return nil, resp, err - } - - return pt, resp, nil + return do[*PipelineTrigger](s.client, + withPath("projects/%s/triggers/%d", ProjectID{pid}, trigger), + withRequestOpts(options...), + ) } // AddPipelineTriggerOptions represents the available AddPipelineTrigger() options. @@ -129,24 +101,12 @@ type AddPipelineTriggerOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/pipeline_triggers/#create-a-trigger-token func (s *PipelineTriggersService) AddPipelineTrigger(pid any, opt *AddPipelineTriggerOptions, options ...RequestOptionFunc) (*PipelineTrigger, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/triggers", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - pt := new(PipelineTrigger) - resp, err := s.client.Do(req, pt) - if err != nil { - return nil, resp, err - } - - return pt, resp, nil + return do[*PipelineTrigger](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/triggers", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // EditPipelineTriggerOptions represents the available EditPipelineTrigger() options. @@ -162,24 +122,12 @@ type EditPipelineTriggerOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/pipeline_triggers/#update-a-pipeline-trigger-token func (s *PipelineTriggersService) EditPipelineTrigger(pid any, trigger int64, opt *EditPipelineTriggerOptions, options ...RequestOptionFunc) (*PipelineTrigger, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/triggers/%d", PathEscape(project), trigger) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - pt := new(PipelineTrigger) - resp, err := s.client.Do(req, pt) - if err != nil { - return nil, resp, err - } - - return pt, resp, nil + return do[*PipelineTrigger](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/triggers/%d", ProjectID{pid}, trigger), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // DeletePipelineTrigger removes a trigger from a project. @@ -187,18 +135,12 @@ func (s *PipelineTriggersService) EditPipelineTrigger(pid any, trigger int64, op // GitLab API docs: // https://docs.gitlab.com/api/pipeline_triggers/#remove-a-pipeline-trigger-token func (s *PipelineTriggersService) DeletePipelineTrigger(pid any, trigger int64, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/triggers/%d", PathEscape(project), trigger) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/triggers/%d", ProjectID{pid}, trigger), + withRequestOpts(options...), + ) + return resp, err } // RunPipelineTriggerOptions represents the available RunPipelineTrigger() options. @@ -220,22 +162,10 @@ type RunPipelineTriggerOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/pipeline_triggers/#trigger-a-pipeline-with-a-token func (s *PipelineTriggersService) RunPipelineTrigger(pid any, opt *RunPipelineTriggerOptions, options ...RequestOptionFunc) (*Pipeline, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/trigger/pipeline", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - pt := new(Pipeline) - resp, err := s.client.Do(req, pt) - if err != nil { - return nil, resp, err - } - - return pt, resp, nil + return do[*Pipeline](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/trigger/pipeline", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/pipelines.go b/vendor/gitlab.com/gitlab-org/api/client-go/pipelines.go index 6d076e43..437dcc9e 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/pipelines.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/pipelines.go @@ -18,7 +18,6 @@ package gitlab import ( "encoding/json" - "fmt" "net/http" "time" ) @@ -84,8 +83,9 @@ type PipelineVariable struct { // // GitLab API docs: https://docs.gitlab.com/api/pipelines/ type PipelineInput struct { - Name string `json:"name"` - Value any `json:"value"` + Name string `json:"name"` + Value any `json:"value"` + Destroy *bool `json:"destroy,omitempty"` } // Pipeline represents a GitLab pipeline. @@ -271,24 +271,11 @@ type ListProjectPipelinesOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/pipelines/#list-project-pipelines func (s *PipelinesService) ListProjectPipelines(pid any, opt *ListProjectPipelinesOptions, options ...RequestOptionFunc) ([]*PipelineInfo, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/pipelines", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var p []*PipelineInfo - resp, err := s.client.Do(req, &p) - if err != nil { - return nil, resp, err - } - - return p, resp, nil + return do[[]*PipelineInfo](s.client, + withPath("projects/%s/pipelines", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // GetPipeline gets a single project pipeline. @@ -296,24 +283,10 @@ func (s *PipelinesService) ListProjectPipelines(pid any, opt *ListProjectPipelin // GitLab API docs: // https://docs.gitlab.com/api/pipelines/#get-a-single-pipeline func (s *PipelinesService) GetPipeline(pid any, pipeline int64, options ...RequestOptionFunc) (*Pipeline, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/pipelines/%d", PathEscape(project), pipeline) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - p := new(Pipeline) - resp, err := s.client.Do(req, p) - if err != nil { - return nil, resp, err - } - - return p, resp, nil + return do[*Pipeline](s.client, + withPath("projects/%s/pipelines/%d", ProjectID{pid}, pipeline), + withRequestOpts(options...), + ) } // GetPipelineVariables gets the variables of a single project pipeline. @@ -321,24 +294,10 @@ func (s *PipelinesService) GetPipeline(pid any, pipeline int64, options ...Reque // GitLab API docs: // https://docs.gitlab.com/api/pipelines/#get-variables-of-a-pipeline func (s *PipelinesService) GetPipelineVariables(pid any, pipeline int64, options ...RequestOptionFunc) ([]*PipelineVariable, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/pipelines/%d/variables", PathEscape(project), pipeline) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - var p []*PipelineVariable - resp, err := s.client.Do(req, &p) - if err != nil { - return nil, resp, err - } - - return p, resp, nil + return do[[]*PipelineVariable](s.client, + withPath("projects/%s/pipelines/%d/variables", ProjectID{pid}, pipeline), + withRequestOpts(options...), + ) } // GetPipelineTestReport gets the test report of a single project pipeline. @@ -346,24 +305,10 @@ func (s *PipelinesService) GetPipelineVariables(pid any, pipeline int64, options // GitLab API docs: // https://docs.gitlab.com/api/pipelines/#get-a-pipelines-test-report func (s *PipelinesService) GetPipelineTestReport(pid any, pipeline int64, options ...RequestOptionFunc) (*PipelineTestReport, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/pipelines/%d/test_report", PathEscape(project), pipeline) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - p := new(PipelineTestReport) - resp, err := s.client.Do(req, p) - if err != nil { - return nil, resp, err - } - - return p, resp, nil + return do[*PipelineTestReport](s.client, + withPath("projects/%s/pipelines/%d/test_report", ProjectID{pid}, pipeline), + withRequestOpts(options...), + ) } // GetPipelineTestReportSummary gets the test report summary of a single project pipeline. @@ -371,24 +316,10 @@ func (s *PipelinesService) GetPipelineTestReport(pid any, pipeline int64, option // GitLab API docs: // https://docs.gitlab.com/api/pipelines/#get-a-test-report-summary-for-a-pipeline func (s *PipelinesService) GetPipelineTestReportSummary(pid any, pipeline int64, options ...RequestOptionFunc) (*PipelineTestReportSummary, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/pipelines/%d/test_report_summary", PathEscape(project), pipeline) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - p := new(PipelineTestReportSummary) - resp, err := s.client.Do(req, p) - if err != nil { - return nil, resp, err - } - - return p, resp, nil + return do[*PipelineTestReportSummary](s.client, + withPath("projects/%s/pipelines/%d/test_report_summary", ProjectID{pid}, pipeline), + withRequestOpts(options...), + ) } // GetLatestPipelineOptions represents the available GetLatestPipeline() options. @@ -404,24 +335,11 @@ type GetLatestPipelineOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/pipelines/#get-the-latest-pipeline func (s *PipelinesService) GetLatestPipeline(pid any, opt *GetLatestPipelineOptions, options ...RequestOptionFunc) (*Pipeline, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/pipelines/latest", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - p := new(Pipeline) - resp, err := s.client.Do(req, p) - if err != nil { - return nil, resp, err - } - - return p, resp, nil + return do[*Pipeline](s.client, + withPath("projects/%s/pipelines/latest", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // CreatePipelineOptions represents the available CreatePipeline() options. @@ -528,24 +446,12 @@ func NewPipelineInputValue[T PipelineInputValueType](value T) PipelineInputValue // GitLab API docs: // https://docs.gitlab.com/api/pipelines/#create-a-new-pipeline func (s *PipelinesService) CreatePipeline(pid any, opt *CreatePipelineOptions, options ...RequestOptionFunc) (*Pipeline, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/pipeline", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - p := new(Pipeline) - resp, err := s.client.Do(req, p) - if err != nil { - return nil, resp, err - } - - return p, resp, nil + return do[*Pipeline](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/pipeline", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // RetryPipelineBuild retries failed builds in a pipeline. @@ -553,24 +459,11 @@ func (s *PipelinesService) CreatePipeline(pid any, opt *CreatePipelineOptions, o // GitLab API docs: // https://docs.gitlab.com/api/pipelines/#retry-jobs-in-a-pipeline func (s *PipelinesService) RetryPipelineBuild(pid any, pipeline int64, options ...RequestOptionFunc) (*Pipeline, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/pipelines/%d/retry", PathEscape(project), pipeline) - - req, err := s.client.NewRequest(http.MethodPost, u, nil, options) - if err != nil { - return nil, nil, err - } - - p := new(Pipeline) - resp, err := s.client.Do(req, p) - if err != nil { - return nil, resp, err - } - - return p, resp, nil + return do[*Pipeline](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/pipelines/%d/retry", ProjectID{pid}, pipeline), + withRequestOpts(options...), + ) } // CancelPipelineBuild cancels a pipeline builds. @@ -578,24 +471,11 @@ func (s *PipelinesService) RetryPipelineBuild(pid any, pipeline int64, options . // GitLab API docs: // https://docs.gitlab.com/api/pipelines/#cancel-a-pipelines-jobs func (s *PipelinesService) CancelPipelineBuild(pid any, pipeline int64, options ...RequestOptionFunc) (*Pipeline, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/pipelines/%d/cancel", PathEscape(project), pipeline) - - req, err := s.client.NewRequest(http.MethodPost, u, nil, options) - if err != nil { - return nil, nil, err - } - - p := new(Pipeline) - resp, err := s.client.Do(req, p) - if err != nil { - return nil, resp, err - } - - return p, resp, nil + return do[*Pipeline](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/pipelines/%d/cancel", ProjectID{pid}, pipeline), + withRequestOpts(options...), + ) } // DeletePipeline deletes an existing pipeline. @@ -603,18 +483,12 @@ func (s *PipelinesService) CancelPipelineBuild(pid any, pipeline int64, options // GitLab API docs: // https://docs.gitlab.com/api/pipelines/#delete-a-pipeline func (s *PipelinesService) DeletePipeline(pid any, pipeline int64, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/pipelines/%d", PathEscape(project), pipeline) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/pipelines/%d", ProjectID{pid}, pipeline), + withRequestOpts(options...), + ) + return resp, err } // UpdatePipelineMetadataOptions represents the available UpdatePipelineMetadata() @@ -632,22 +506,10 @@ type UpdatePipelineMetadataOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/pipelines/#update-pipeline-metadata func (s *PipelinesService) UpdatePipelineMetadata(pid any, pipeline int64, opt *UpdatePipelineMetadataOptions, options ...RequestOptionFunc) (*Pipeline, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/pipelines/%d/metadata", PathEscape(project), pipeline) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - p := new(Pipeline) - resp, err := s.client.Do(req, p) - if err != nil { - return nil, resp, err - } - - return p, resp, nil + return do[*Pipeline](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/pipelines/%d/metadata", ProjectID{pid}, pipeline), + withAPIOpts(opt), + withRequestOpts(options...), + ) } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/plan_limits.go b/vendor/gitlab.com/gitlab-org/api/client-go/plan_limits.go index 018eff59..d7247fa5 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/plan_limits.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/plan_limits.go @@ -63,18 +63,11 @@ type GetCurrentPlanLimitsOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/plan_limits/#get-current-plan-limits func (s *PlanLimitsService) GetCurrentPlanLimits(opt *GetCurrentPlanLimitsOptions, options ...RequestOptionFunc) (*PlanLimit, *Response, error) { - req, err := s.client.NewRequest(http.MethodGet, "application/plan_limits", opt, options) - if err != nil { - return nil, nil, err - } - - pl := new(PlanLimit) - resp, err := s.client.Do(req, pl) - if err != nil { - return nil, resp, err - } - - return pl, resp, nil + return do[*PlanLimit](s.client, + withPath("application/plan_limits"), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // ChangePlanLimitOptions represents the available ChangePlanLimits() options. @@ -98,16 +91,10 @@ type ChangePlanLimitOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/plan_limits/#change-plan-limits func (s *PlanLimitsService) ChangePlanLimits(opt *ChangePlanLimitOptions, options ...RequestOptionFunc) (*PlanLimit, *Response, error) { - req, err := s.client.NewRequest(http.MethodPut, "application/plan_limits", opt, options) - if err != nil { - return nil, nil, err - } - - pl := new(PlanLimit) - resp, err := s.client.Do(req, pl) - if err != nil { - return nil, resp, err - } - - return pl, resp, nil + return do[*PlanLimit](s.client, + withMethod(http.MethodPut), + withPath("application/plan_limits"), + withAPIOpts(opt), + withRequestOpts(options...), + ) } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/project_access_tokens.go b/vendor/gitlab.com/gitlab-org/api/client-go/project_access_tokens.go index 41c3af62..4fae8ebf 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/project_access_tokens.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/project_access_tokens.go @@ -17,7 +17,6 @@ package gitlab import ( - "fmt" "net/http" ) @@ -69,24 +68,11 @@ type ListProjectAccessTokensOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/project_access_tokens/#list-all-project-access-tokens func (s *ProjectAccessTokensService) ListProjectAccessTokens(pid any, opt *ListProjectAccessTokensOptions, options ...RequestOptionFunc) ([]*ProjectAccessToken, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/access_tokens", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var pats []*ProjectAccessToken - resp, err := s.client.Do(req, &pats) - if err != nil { - return nil, resp, err - } - - return pats, resp, nil + return do[[]*ProjectAccessToken](s.client, + withPath("projects/%s/access_tokens", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // GetProjectAccessToken gets a single project access tokens in a project. @@ -94,24 +80,10 @@ func (s *ProjectAccessTokensService) ListProjectAccessTokens(pid any, opt *ListP // GitLab API docs: // https://docs.gitlab.com/api/project_access_tokens/#get-details-on-a-project-access-token func (s *ProjectAccessTokensService) GetProjectAccessToken(pid any, id int64, options ...RequestOptionFunc) (*ProjectAccessToken, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/access_tokens/%d", PathEscape(project), id) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - pat := new(ProjectAccessToken) - resp, err := s.client.Do(req, &pat) - if err != nil { - return nil, resp, err - } - - return pat, resp, nil + return do[*ProjectAccessToken](s.client, + withPath("projects/%s/access_tokens/%d", ProjectID{pid}, id), + withRequestOpts(options...), + ) } // CreateProjectAccessTokenOptions represents the available CreateVariable() @@ -132,24 +104,12 @@ type CreateProjectAccessTokenOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/project_access_tokens/#create-a-project-access-token func (s *ProjectAccessTokensService) CreateProjectAccessToken(pid any, opt *CreateProjectAccessTokenOptions, options ...RequestOptionFunc) (*ProjectAccessToken, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/access_tokens", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - pat := new(ProjectAccessToken) - resp, err := s.client.Do(req, pat) - if err != nil { - return nil, resp, err - } - - return pat, resp, nil + return do[*ProjectAccessToken](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/access_tokens", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // RotateProjectAccessTokenOptions represents the available RotateProjectAccessToken() @@ -167,23 +127,12 @@ type RotateProjectAccessTokenOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/project_access_tokens/#rotate-a-project-access-token func (s *ProjectAccessTokensService) RotateProjectAccessToken(pid any, id int64, opt *RotateProjectAccessTokenOptions, options ...RequestOptionFunc) (*ProjectAccessToken, *Response, error) { - projects, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/access_tokens/%d/rotate", PathEscape(projects), id) - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - pat := new(ProjectAccessToken) - resp, err := s.client.Do(req, pat) - if err != nil { - return nil, resp, err - } - - return pat, resp, nil + return do[*ProjectAccessToken](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/access_tokens/%d/rotate", ProjectID{pid}, id), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // RotateProjectAccessTokenSelf revokes the project access token used for the request @@ -192,23 +141,12 @@ func (s *ProjectAccessTokensService) RotateProjectAccessToken(pid any, id int64, // GitLab API docs: // https://docs.gitlab.com/api/project_access_tokens/#self-rotate func (s *ProjectAccessTokensService) RotateProjectAccessTokenSelf(pid any, opt *RotateProjectAccessTokenOptions, options ...RequestOptionFunc) (*ProjectAccessToken, *Response, error) { - projects, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/access_tokens/self/rotate", PathEscape(projects)) - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - pat := new(ProjectAccessToken) - resp, err := s.client.Do(req, pat) - if err != nil { - return nil, resp, err - } - - return pat, resp, nil + return do[*ProjectAccessToken](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/access_tokens/self/rotate", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // RevokeProjectAccessToken revokes a project access token. @@ -216,16 +154,10 @@ func (s *ProjectAccessTokensService) RotateProjectAccessTokenSelf(pid any, opt * // GitLab API docs: // https://docs.gitlab.com/api/project_access_tokens/#revoke-a-project-access-token func (s *ProjectAccessTokensService) RevokeProjectAccessToken(pid any, id int64, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/access_tokens/%d", PathEscape(project), id) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/access_tokens/%d", ProjectID{pid}, id), + withRequestOpts(options...), + ) + return resp, err } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/project_aliases.go b/vendor/gitlab.com/gitlab-org/api/client-go/project_aliases.go index c83230dd..9059abbc 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/project_aliases.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/project_aliases.go @@ -1,7 +1,6 @@ package gitlab import ( - "fmt" "net/http" ) @@ -47,20 +46,10 @@ type CreateProjectAliasOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/project_aliases/#list-all-project-aliases func (s *ProjectAliasesService) ListProjectAliases(options ...RequestOptionFunc) ([]*ProjectAlias, *Response, error) { - u := "project_aliases" - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - var aliases []*ProjectAlias - resp, err := s.client.Do(req, &aliases) - if err != nil { - return nil, resp, err - } - - return aliases, resp, nil + return do[[]*ProjectAlias](s.client, + withPath("project_aliases"), + withRequestOpts(options...), + ) } // GetProjectAlias gets details of a project alias. @@ -68,20 +57,10 @@ func (s *ProjectAliasesService) ListProjectAliases(options ...RequestOptionFunc) // GitLab API docs: // https://docs.gitlab.com/api/project_aliases/#get-project-alias-details func (s *ProjectAliasesService) GetProjectAlias(name string, options ...RequestOptionFunc) (*ProjectAlias, *Response, error) { - u := fmt.Sprintf("project_aliases/%s", PathEscape(name)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - aliasObj := new(ProjectAlias) - resp, err := s.client.Do(req, aliasObj) - if err != nil { - return nil, resp, err - } - - return aliasObj, resp, nil + return do[*ProjectAlias](s.client, + withPath("project_aliases/%s", name), + withRequestOpts(options...), + ) } // CreateProjectAlias creates a new project alias. @@ -89,20 +68,12 @@ func (s *ProjectAliasesService) GetProjectAlias(name string, options ...RequestO // GitLab API docs: // https://docs.gitlab.com/api/project_aliases/#create-a-project-alias func (s *ProjectAliasesService) CreateProjectAlias(opt *CreateProjectAliasOptions, options ...RequestOptionFunc) (*ProjectAlias, *Response, error) { - u := "project_aliases" - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - alias := new(ProjectAlias) - resp, err := s.client.Do(req, alias) - if err != nil { - return nil, resp, err - } - - return alias, resp, nil + return do[*ProjectAlias](s.client, + withMethod(http.MethodPost), + withPath("project_aliases"), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // DeleteProjectAlias deletes a project alias. @@ -110,12 +81,10 @@ func (s *ProjectAliasesService) CreateProjectAlias(opt *CreateProjectAliasOption // GitLab API docs: // https://docs.gitlab.com/api/project_aliases/#delete-a-project-alias func (s *ProjectAliasesService) DeleteProjectAlias(name string, options ...RequestOptionFunc) (*Response, error) { - u := fmt.Sprintf("project_aliases/%s", PathEscape(name)) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("project_aliases/%s", name), + withRequestOpts(options...), + ) + return resp, err } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/project_badges.go b/vendor/gitlab.com/gitlab-org/api/client-go/project_badges.go index 408426a9..e0b14c94 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/project_badges.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/project_badges.go @@ -17,7 +17,6 @@ package gitlab import ( - "fmt" "net/http" ) @@ -72,24 +71,11 @@ type ListProjectBadgesOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/project_badges/#list-all-badges-of-a-project func (s *ProjectBadgesService) ListProjectBadges(pid any, opt *ListProjectBadgesOptions, options ...RequestOptionFunc) ([]*ProjectBadge, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/badges", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var pb []*ProjectBadge - resp, err := s.client.Do(req, &pb) - if err != nil { - return nil, resp, err - } - - return pb, resp, nil + return do[[]*ProjectBadge](s.client, + withPath("projects/%s/badges", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // GetProjectBadge gets a project badge. @@ -97,24 +83,10 @@ func (s *ProjectBadgesService) ListProjectBadges(pid any, opt *ListProjectBadges // GitLab API docs: // https://docs.gitlab.com/api/project_badges/#get-a-badge-of-a-project func (s *ProjectBadgesService) GetProjectBadge(pid any, badge int64, options ...RequestOptionFunc) (*ProjectBadge, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/badges/%d", PathEscape(project), badge) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - pb := new(ProjectBadge) - resp, err := s.client.Do(req, pb) - if err != nil { - return nil, resp, err - } - - return pb, resp, nil + return do[*ProjectBadge](s.client, + withPath("projects/%s/badges/%d", ProjectID{pid}, badge), + withRequestOpts(options...), + ) } // AddProjectBadgeOptions represents the available AddProjectBadge() options. @@ -132,24 +104,12 @@ type AddProjectBadgeOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/project_badges/#add-a-badge-to-a-project func (s *ProjectBadgesService) AddProjectBadge(pid any, opt *AddProjectBadgeOptions, options ...RequestOptionFunc) (*ProjectBadge, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/badges", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - pb := new(ProjectBadge) - resp, err := s.client.Do(req, pb) - if err != nil { - return nil, resp, err - } - - return pb, resp, nil + return do[*ProjectBadge](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/badges", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // EditProjectBadgeOptions represents the available EditProjectBadge() options. @@ -167,24 +127,12 @@ type EditProjectBadgeOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/project_badges/#edit-a-badge-of-a-project func (s *ProjectBadgesService) EditProjectBadge(pid any, badge int64, opt *EditProjectBadgeOptions, options ...RequestOptionFunc) (*ProjectBadge, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/badges/%d", PathEscape(project), badge) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - pb := new(ProjectBadge) - resp, err := s.client.Do(req, pb) - if err != nil { - return nil, resp, err - } - - return pb, resp, nil + return do[*ProjectBadge](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/badges/%d", ProjectID{pid}, badge), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // DeleteProjectBadge removes a badge from a project. Only project's @@ -193,18 +141,12 @@ func (s *ProjectBadgesService) EditProjectBadge(pid any, badge int64, opt *EditP // GitLab API docs: // https://docs.gitlab.com/api/project_badges/#remove-a-badge-from-a-project func (s *ProjectBadgesService) DeleteProjectBadge(pid any, badge int64, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/badges/%d", PathEscape(project), badge) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/badges/%d", ProjectID{pid}, badge), + withRequestOpts(options...), + ) + return resp, err } // ProjectBadgePreviewOptions represents the available PreviewProjectBadge() options. @@ -222,22 +164,9 @@ type ProjectBadgePreviewOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/project_badges/#preview-a-badge-from-a-project func (s *ProjectBadgesService) PreviewProjectBadge(pid any, opt *ProjectBadgePreviewOptions, options ...RequestOptionFunc) (*ProjectBadge, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/badges/render", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - pb := new(ProjectBadge) - resp, err := s.client.Do(req, &pb) - if err != nil { - return nil, resp, err - } - - return pb, resp, nil + return do[*ProjectBadge](s.client, + withPath("projects/%s/badges/render", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/project_clusters.go b/vendor/gitlab.com/gitlab-org/api/client-go/project_clusters.go index b9a7ce8c..e62da758 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/project_clusters.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/project_clusters.go @@ -17,7 +17,6 @@ package gitlab import ( - "fmt" "net/http" "time" ) @@ -103,24 +102,10 @@ type ManagementProject struct { // GitLab API docs: // https://docs.gitlab.com/api/project_clusters/#list-project-clusters func (s *ProjectClustersService) ListClusters(pid any, options ...RequestOptionFunc) ([]*ProjectCluster, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/clusters", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - var pcs []*ProjectCluster - resp, err := s.client.Do(req, &pcs) - if err != nil { - return nil, resp, err - } - - return pcs, resp, nil + return do[[]*ProjectCluster](s.client, + withPath("projects/%s/clusters", ProjectID{pid}), + withRequestOpts(options...), + ) } // GetCluster gets a cluster. @@ -129,24 +114,10 @@ func (s *ProjectClustersService) ListClusters(pid any, options ...RequestOptionF // GitLab API docs: // https://docs.gitlab.com/api/project_clusters/#get-a-single-project-cluster func (s *ProjectClustersService) GetCluster(pid any, cluster int64, options ...RequestOptionFunc) (*ProjectCluster, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/clusters/%d", PathEscape(project), cluster) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - pc := new(ProjectCluster) - resp, err := s.client.Do(req, &pc) - if err != nil { - return nil, resp, err - } - - return pc, resp, nil + return do[*ProjectCluster](s.client, + withPath("projects/%s/clusters/%d", ProjectID{pid}, cluster), + withRequestOpts(options...), + ) } // AddClusterOptions represents the available AddCluster() options. @@ -180,24 +151,12 @@ type AddPlatformKubernetesOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/project_clusters/#add-existing-cluster-to-project func (s *ProjectClustersService) AddCluster(pid any, opt *AddClusterOptions, options ...RequestOptionFunc) (*ProjectCluster, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/clusters/user", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - pc := new(ProjectCluster) - resp, err := s.client.Do(req, pc) - if err != nil { - return nil, resp, err - } - - return pc, resp, nil + return do[*ProjectCluster](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/clusters/user", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // EditClusterOptions represents the available EditCluster() options. @@ -228,24 +187,12 @@ type EditPlatformKubernetesOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/project_clusters/#edit-project-cluster func (s *ProjectClustersService) EditCluster(pid any, cluster int64, opt *EditClusterOptions, options ...RequestOptionFunc) (*ProjectCluster, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/clusters/%d", PathEscape(project), cluster) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - pc := new(ProjectCluster) - resp, err := s.client.Do(req, pc) - if err != nil { - return nil, resp, err - } - - return pc, resp, nil + return do[*ProjectCluster](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/clusters/%d", ProjectID{pid}, cluster), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // DeleteCluster deletes an existing project cluster. @@ -254,16 +201,10 @@ func (s *ProjectClustersService) EditCluster(pid any, cluster int64, opt *EditCl // GitLab API docs: // https://docs.gitlab.com/api/project_clusters/#delete-project-cluster func (s *ProjectClustersService) DeleteCluster(pid any, cluster int64, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/clusters/%d", PathEscape(project), cluster) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/clusters/%d", ProjectID{pid}, cluster), + withRequestOpts(options...), + ) + return resp, err } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/project_feature_flags.go b/vendor/gitlab.com/gitlab-org/api/client-go/project_feature_flags.go index a0a7d1d1..af9c4136 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/project_feature_flags.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/project_feature_flags.go @@ -1,17 +1,36 @@ package gitlab import ( - "fmt" "net/http" "time" ) type ( ProjectFeatureFlagServiceInterface interface { + // ListProjectFeatureFlags returns a list with the feature flags of a project. + // + // GitLab API docs: + // https://docs.gitlab.com/api/feature_flags/#list-feature-flags-for-a-project ListProjectFeatureFlags(pid any, opt *ListProjectFeatureFlagOptions, options ...RequestOptionFunc) ([]*ProjectFeatureFlag, *Response, error) + // GetProjectFeatureFlag gets a single feature flag for the specified project. + // + // GitLab API docs: + // https://docs.gitlab.com/api/feature_flags/#get-a-single-feature-flag GetProjectFeatureFlag(pid any, name string, options ...RequestOptionFunc) (*ProjectFeatureFlag, *Response, error) + // CreateProjectFeatureFlag creates a feature flag. + // + // GitLab API docs: + // https://docs.gitlab.com/api/feature_flags/#create-a-feature-flag CreateProjectFeatureFlag(pid any, opt *CreateProjectFeatureFlagOptions, options ...RequestOptionFunc) (*ProjectFeatureFlag, *Response, error) + // UpdateProjectFeatureFlag updates a feature flag. + // + // GitLab API docs: + // https://docs.gitlab.com/api/feature_flags/#update-a-feature-flag UpdateProjectFeatureFlag(pid any, name string, opt *UpdateProjectFeatureFlagOptions, options ...RequestOptionFunc) (*ProjectFeatureFlag, *Response, error) + // DeleteProjectFeatureFlag deletes a feature flag. + // + // GitLab API docs: + // https://docs.gitlab.com/api/feature_flags/#delete-a-feature-flag DeleteProjectFeatureFlag(pid any, name string, options ...RequestOptionFunc) (*Response, error) } @@ -86,54 +105,19 @@ type ListProjectFeatureFlagOptions struct { Scope *string `url:"scope,omitempty" json:"scope,omitempty"` } -// ListProjectFeatureFlags returns a list with the feature flags of a project. -// -// GitLab API docs: -// https://docs.gitlab.com/api/feature_flags/#list-feature-flags-for-a-project func (s *ProjectFeatureFlagService) ListProjectFeatureFlags(pid any, opt *ListProjectFeatureFlagOptions, options ...RequestOptionFunc) ([]*ProjectFeatureFlag, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/feature_flags", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var pffs []*ProjectFeatureFlag - resp, err := s.client.Do(req, &pffs) - if err != nil { - return nil, resp, err - } - - return pffs, resp, nil + return do[[]*ProjectFeatureFlag](s.client, + withPath("projects/%s/feature_flags", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } -// GetProjectFeatureFlag gets a single feature flag for the specified project. -// -// GitLab API docs: -// https://docs.gitlab.com/api/feature_flags/#get-a-single-feature-flag func (s *ProjectFeatureFlagService) GetProjectFeatureFlag(pid any, name string, options ...RequestOptionFunc) (*ProjectFeatureFlag, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/feature_flags/%s", PathEscape(project), name) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - flag := new(ProjectFeatureFlag) - resp, err := s.client.Do(req, flag) - if err != nil { - return nil, resp, err - } - - return flag, resp, nil + return do[*ProjectFeatureFlag](s.client, + withPath("projects/%s/feature_flags/%s", ProjectID{pid}, name), + withRequestOpts(options...), + ) } // CreateProjectFeatureFlagOptions represents the available @@ -171,31 +155,13 @@ type ProjectFeatureFlagScopeOptions struct { EnvironmentScope *string `url:"id,omitempty" json:"environment_scope,omitempty"` } -// CreateProjectFeatureFlag creates a feature flag -// -// GitLab API docs: -// https://docs.gitlab.com/api/feature_flags/#create-a-feature-flag func (s *ProjectFeatureFlagService) CreateProjectFeatureFlag(pid any, opt *CreateProjectFeatureFlagOptions, options ...RequestOptionFunc) (*ProjectFeatureFlag, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/feature_flags", - PathEscape(project), + return do[*ProjectFeatureFlag](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/feature_flags", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), ) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - flag := new(ProjectFeatureFlag) - resp, err := s.client.Do(req, flag) - if err != nil { - return flag, resp, err - } - - return flag, resp, nil } // UpdateProjectFeatureFlagOptions represents the available @@ -210,49 +176,20 @@ type UpdateProjectFeatureFlagOptions struct { Strategies *[]*FeatureFlagStrategyOptions `url:"strategies,omitempty" json:"strategies,omitempty"` } -// UpdateProjectFeatureFlag updates a feature flag -// -// GitLab API docs: -// https://docs.gitlab.com/api/feature_flags/#update-a-feature-flag func (s *ProjectFeatureFlagService) UpdateProjectFeatureFlag(pid any, name string, opt *UpdateProjectFeatureFlagOptions, options ...RequestOptionFunc) (*ProjectFeatureFlag, *Response, error) { - group, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/feature_flags/%s", - PathEscape(group), - name, + return do[*ProjectFeatureFlag](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/feature_flags/%s", ProjectID{pid}, name), + withAPIOpts(opt), + withRequestOpts(options...), ) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - flag := new(ProjectFeatureFlag) - resp, err := s.client.Do(req, flag) - if err != nil { - return flag, resp, err - } - - return flag, resp, nil } -// DeleteProjectFeatureFlag deletes a feature flag -// -// GitLab API docs: -// https://docs.gitlab.com/api/feature_flags/#delete-a-feature-flag func (s *ProjectFeatureFlagService) DeleteProjectFeatureFlag(pid any, name string, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/feature_flags/%s", PathEscape(project), name) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/feature_flags/%s", ProjectID{pid}, name), + withRequestOpts(options...), + ) + return resp, err } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/project_import_export.go b/vendor/gitlab.com/gitlab-org/api/client-go/project_import_export.go index 6a4df5f0..671804a5 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/project_import_export.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/project_import_export.go @@ -18,7 +18,6 @@ package gitlab import ( "bytes" - "fmt" "io" "net/http" "time" @@ -26,10 +25,30 @@ import ( type ( ProjectImportExportServiceInterface interface { + // ScheduleExport schedules a project export. + // + // GitLab API docs: + // https://docs.gitlab.com/api/project_import_export/#schedule-an-export ScheduleExport(pid any, opt *ScheduleExportOptions, options ...RequestOptionFunc) (*Response, error) + // ExportStatus gets the status of export. + // + // GitLab API docs: + // https://docs.gitlab.com/api/project_import_export/#export-status ExportStatus(pid any, options ...RequestOptionFunc) (*ExportStatus, *Response, error) + // ExportDownload downloads the finished export. + // + // GitLab API docs: + // https://docs.gitlab.com/api/project_import_export/#export-download ExportDownload(pid any, options ...RequestOptionFunc) ([]byte, *Response, error) + // ImportFromFile imports a project from an archive file. + // + // GitLab API docs: + // https://docs.gitlab.com/api/project_import_export/#import-a-file ImportFromFile(archive io.Reader, opt *ImportFileOptions, options ...RequestOptionFunc) (*ImportStatus, *Response, error) + // ImportStatus gets the status of an import. + // + // GitLab API docs: + // https://docs.gitlab.com/api/project_import_export/#import-status ImportStatus(pid any, options ...RequestOptionFunc) (*ImportStatus, *Response, error) } @@ -115,73 +134,32 @@ type ScheduleExportUploadOptions struct { HTTPMethod *string `url:"http_method,omitempty" json:"http_method,omitempty"` } -// ScheduleExport schedules a project export. -// -// GitLab API docs: -// https://docs.gitlab.com/api/project_import_export/#schedule-an-export func (s *ProjectImportExportService) ScheduleExport(pid any, opt *ScheduleExportOptions, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/export", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/export", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) + return resp, err } -// ExportStatus get the status of export. -// -// GitLab API docs: -// https://docs.gitlab.com/api/project_import_export/#export-status func (s *ProjectImportExportService) ExportStatus(pid any, options ...RequestOptionFunc) (*ExportStatus, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/export", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - es := new(ExportStatus) - resp, err := s.client.Do(req, es) - if err != nil { - return nil, resp, err - } - - return es, resp, nil + return do[*ExportStatus](s.client, + withPath("projects/%s/export", ProjectID{pid}), + withRequestOpts(options...), + ) } -// ExportDownload download the finished export. -// -// GitLab API docs: -// https://docs.gitlab.com/api/project_import_export/#export-download func (s *ProjectImportExportService) ExportDownload(pid any, options ...RequestOptionFunc) ([]byte, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/export/download", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - var b bytes.Buffer - resp, err := s.client.Do(req, &b) + buf, resp, err := do[bytes.Buffer](s.client, + withPath("projects/%s/export/download", ProjectID{pid}), + withRequestOpts(options...), + ) if err != nil { return nil, resp, err } - - return b.Bytes(), resp, err + return buf.Bytes(), resp, nil } // ImportFileOptions represents the available ImportFile() options. @@ -196,54 +174,19 @@ type ImportFileOptions struct { OverrideParams *CreateProjectOptions `url:"override_params,omitempty" json:"override_params,omitempty"` } -// ImportFromFile imports a project from an archive file. -// -// GitLab API docs: -// https://docs.gitlab.com/api/project_import_export/#import-a-file func (s *ProjectImportExportService) ImportFromFile(archive io.Reader, opt *ImportFileOptions, options ...RequestOptionFunc) (*ImportStatus, *Response, error) { - req, err := s.client.UploadRequest( - http.MethodPost, - "projects/import", - archive, - "archive.tar.gz", - UploadFile, - opt, - options, + return do[*ImportStatus](s.client, + withMethod(http.MethodPost), + withPath("projects/import"), + withUpload(archive, "archive.tar.gz", UploadFile), + withAPIOpts(opt), + withRequestOpts(options...), ) - if err != nil { - return nil, nil, err - } - - is := new(ImportStatus) - resp, err := s.client.Do(req, is) - if err != nil { - return nil, resp, err - } - - return is, resp, nil } -// ImportStatus get the status of an import. -// -// GitLab API docs: -// https://docs.gitlab.com/api/project_import_export/#import-status func (s *ProjectImportExportService) ImportStatus(pid any, options ...RequestOptionFunc) (*ImportStatus, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/import", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - is := new(ImportStatus) - resp, err := s.client.Do(req, is) - if err != nil { - return nil, resp, err - } - - return is, resp, nil + return do[*ImportStatus](s.client, + withPath("projects/%s/import", ProjectID{pid}), + withRequestOpts(options...), + ) } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/project_iterations.go b/vendor/gitlab.com/gitlab-org/api/client-go/project_iterations.go index 0fdaf3a4..5f33c6cd 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/project_iterations.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/project_iterations.go @@ -16,11 +16,7 @@ package gitlab -import ( - "fmt" - "net/http" - "time" -) +import "time" type ( ProjectIterationsServiceInterface interface { @@ -77,22 +73,9 @@ type ListProjectIterationsOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/iterations/#list-project-iterations func (i *ProjectIterationsService) ListProjectIterations(pid any, opt *ListProjectIterationsOptions, options ...RequestOptionFunc) ([]*ProjectIteration, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/iterations", PathEscape(project)) - - req, err := i.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var pis []*ProjectIteration - resp, err := i.client.Do(req, &pis) - if err != nil { - return nil, resp, err - } - - return pis, resp, nil + return do[[]*ProjectIteration](i.client, + withPath("projects/%s/iterations", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/project_markdown_uploads.go b/vendor/gitlab.com/gitlab-org/api/client-go/project_markdown_uploads.go index 312226df..67e23fe9 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/project_markdown_uploads.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/project_markdown_uploads.go @@ -17,18 +17,43 @@ package gitlab import ( - "fmt" "io" "net/http" ) type ( ProjectMarkdownUploadsServiceInterface interface { + // UploadProjectMarkdown uploads a markdown file to a project. + // + // GitLab API docs: + // https://docs.gitlab.com/api/project_markdown_uploads/#upload-a-file UploadProjectMarkdown(pid any, content io.Reader, filename string, options ...RequestOptionFunc) (*ProjectMarkdownUploadedFile, *Response, error) + // ListProjectMarkdownUploads gets all markdown uploads for a project. + // + // GitLab API Docs: + // https://docs.gitlab.com/api/project_markdown_uploads/#list-uploads ListProjectMarkdownUploads(pid any, options ...RequestOptionFunc) ([]*ProjectMarkdownUpload, *Response, error) + // DownloadProjectMarkdownUploadByID downloads a specific upload by ID. + // + // GitLab API Docs: + // https://docs.gitlab.com/api/project_markdown_uploads/#download-an-uploaded-file-by-id DownloadProjectMarkdownUploadByID(pid any, uploadID int64, options ...RequestOptionFunc) ([]byte, *Response, error) + // DownloadProjectMarkdownUploadBySecretAndFilename downloads a specific upload + // by secret and filename. + // + // GitLab API Docs: + // https://docs.gitlab.com/api/project_markdown_uploads/#download-an-uploaded-file-by-secret-and-filename DownloadProjectMarkdownUploadBySecretAndFilename(pid any, secret string, filename string, options ...RequestOptionFunc) ([]byte, *Response, error) + // DeleteProjectMarkdownUploadByID deletes an upload by ID. + // + // GitLab API Docs: + // https://docs.gitlab.com/api/project_markdown_uploads/#delete-an-uploaded-file-by-id DeleteProjectMarkdownUploadByID(pid any, uploadID int64, options ...RequestOptionFunc) (*Response, error) + // DeleteProjectMarkdownUploadBySecretAndFilename deletes an upload + // by secret and filename. + // + // GitLab API Docs: + // https://docs.gitlab.com/api/project_markdown_uploads/#delete-an-uploaded-file-by-secret-and-filename DeleteProjectMarkdownUploadBySecretAndFilename(pid any, secret string, filename string, options ...RequestOptionFunc) (*Response, error) } @@ -50,51 +75,19 @@ type ( ProjectMarkdownUploadedFile = MarkdownUploadedFile ) -// UploadProjectMarkdown uploads a markdown file to a project. -// -// GitLab docs: -// https://docs.gitlab.com/api/project_markdown_uploads/#upload-a-file func (s *ProjectMarkdownUploadsService) UploadProjectMarkdown(pid any, content io.Reader, filename string, options ...RequestOptionFunc) (*ProjectMarkdownUploadedFile, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/uploads", PathEscape(project)) - - req, err := s.client.UploadRequest( - http.MethodPost, - u, - content, - filename, - UploadFile, - nil, - options, + return do[*ProjectMarkdownUploadedFile](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/uploads", ProjectID{pid}), + withUpload(content, filename, UploadFile), + withRequestOpts(options...), ) - if err != nil { - return nil, nil, err - } - - f := new(ProjectMarkdownUploadedFile) - resp, err := s.client.Do(req, f) - if err != nil { - return nil, resp, err - } - - return f, resp, nil } -// ListProjectMarkdownUploads gets all markdown uploads for a project. -// -// GitLab API Docs: -// https://docs.gitlab.com/api/project_markdown_uploads/#list-uploads func (s *ProjectMarkdownUploadsService) ListProjectMarkdownUploads(pid any, options ...RequestOptionFunc) ([]*ProjectMarkdownUpload, *Response, error) { return listMarkdownUploads[ProjectMarkdownUpload](s.client, ProjectResource, ProjectID{pid}, nil, options) } -// DownloadProjectMarkdownUploadByID downloads a specific upload by ID. -// -// GitLab API Docs: -// https://docs.gitlab.com/api/project_markdown_uploads/#download-an-uploaded-file-by-id func (s *ProjectMarkdownUploadsService) DownloadProjectMarkdownUploadByID(pid any, uploadID int64, options ...RequestOptionFunc) ([]byte, *Response, error) { buffer, resp, err := downloadMarkdownUploadByID(s.client, ProjectResource, ProjectID{pid}, uploadID, options) if err != nil { @@ -103,11 +96,6 @@ func (s *ProjectMarkdownUploadsService) DownloadProjectMarkdownUploadByID(pid an return buffer.Bytes(), resp, nil } -// DownloadProjectMarkdownUploadBySecretAndFilename downloads a specific upload -// by secret and filename. -// -// GitLab API Docs: -// https://docs.gitlab.com/api/project_markdown_uploads/#download-an-uploaded-file-by-secret-and-filename func (s *ProjectMarkdownUploadsService) DownloadProjectMarkdownUploadBySecretAndFilename(pid any, secret string, filename string, options ...RequestOptionFunc) ([]byte, *Response, error) { buffer, resp, err := downloadMarkdownUploadBySecretAndFilename(s.client, ProjectResource, ProjectID{pid}, secret, filename, options) if err != nil { @@ -116,19 +104,10 @@ func (s *ProjectMarkdownUploadsService) DownloadProjectMarkdownUploadBySecretAnd return buffer.Bytes(), resp, nil } -// DeleteProjectMarkdownUploadByID deletes an upload by ID. -// -// GitLab API Docs: -// https://docs.gitlab.com/api/project_markdown_uploads/#delete-an-uploaded-file-by-id func (s *ProjectMarkdownUploadsService) DeleteProjectMarkdownUploadByID(pid any, uploadID int64, options ...RequestOptionFunc) (*Response, error) { return deleteMarkdownUploadByID(s.client, ProjectResource, ProjectID{pid}, uploadID, options) } -// DeleteProjectMarkdownUploadBySecretAndFilename deletes an upload -// by secret and filename. -// -// GitLab API Docs: -// https://docs.gitlab.com/api/project_markdown_uploads/#delete-an-uploaded-file-by-secret-and-filename func (s *ProjectMarkdownUploadsService) DeleteProjectMarkdownUploadBySecretAndFilename(pid any, secret string, filename string, options ...RequestOptionFunc) (*Response, error) { return deleteMarkdownUploadBySecretAndFilename(s.client, ProjectResource, ProjectID{pid}, secret, filename, options) } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/project_members.go b/vendor/gitlab.com/gitlab-org/api/client-go/project_members.go index 92907048..1d2b6a55 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/project_members.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/project_members.go @@ -17,7 +17,6 @@ package gitlab import ( - "fmt" "net/http" "time" ) @@ -92,24 +91,11 @@ type ListProjectMembersOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/members/#list-all-members-of-a-group-or-project func (s *ProjectMembersService) ListProjectMembers(pid any, opt *ListProjectMembersOptions, options ...RequestOptionFunc) ([]*ProjectMember, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/members", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var pm []*ProjectMember - resp, err := s.client.Do(req, &pm) - if err != nil { - return nil, resp, err - } - - return pm, resp, nil + return do[[]*ProjectMember](s.client, + withPath("projects/%s/members", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // ListAllProjectMembers gets a list of a project's team members viewable by the @@ -119,24 +105,11 @@ func (s *ProjectMembersService) ListProjectMembers(pid any, opt *ListProjectMemb // GitLab API docs: // https://docs.gitlab.com/api/members/#list-all-members-of-a-group-or-project-including-inherited-and-invited-members func (s *ProjectMembersService) ListAllProjectMembers(pid any, opt *ListProjectMembersOptions, options ...RequestOptionFunc) ([]*ProjectMember, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/members/all", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var pm []*ProjectMember - resp, err := s.client.Do(req, &pm) - if err != nil { - return nil, resp, err - } - - return pm, resp, nil + return do[[]*ProjectMember](s.client, + withPath("projects/%s/members/all", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // GetProjectMember gets a project team member. @@ -144,24 +117,10 @@ func (s *ProjectMembersService) ListAllProjectMembers(pid any, opt *ListProjectM // GitLab API docs: // https://docs.gitlab.com/api/members/#get-a-member-of-a-group-or-project func (s *ProjectMembersService) GetProjectMember(pid any, user int64, options ...RequestOptionFunc) (*ProjectMember, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/members/%d", PathEscape(project), user) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - pm := new(ProjectMember) - resp, err := s.client.Do(req, pm) - if err != nil { - return nil, resp, err - } - - return pm, resp, nil + return do[*ProjectMember](s.client, + withPath("projects/%s/members/%d", ProjectID{pid}, user), + withRequestOpts(options...), + ) } // GetInheritedProjectMember gets a project team member, including inherited @@ -169,24 +128,10 @@ func (s *ProjectMembersService) GetProjectMember(pid any, user int64, options .. // GitLab API docs: // https://docs.gitlab.com/api/members/#get-a-member-of-a-group-or-project-including-inherited-and-invited-members func (s *ProjectMembersService) GetInheritedProjectMember(pid any, user int64, options ...RequestOptionFunc) (*ProjectMember, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/members/all/%d", PathEscape(project), user) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - pm := new(ProjectMember) - resp, err := s.client.Do(req, pm) - if err != nil { - return nil, resp, err - } - - return pm, resp, nil + return do[*ProjectMember](s.client, + withPath("projects/%s/members/all/%d", ProjectID{pid}, user), + withRequestOpts(options...), + ) } // AddProjectMemberOptions represents the available AddProjectMember() options. @@ -209,24 +154,12 @@ type AddProjectMemberOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/members/#add-a-member-to-a-group-or-project func (s *ProjectMembersService) AddProjectMember(pid any, opt *AddProjectMemberOptions, options ...RequestOptionFunc) (*ProjectMember, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/members", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - pm := new(ProjectMember) - resp, err := s.client.Do(req, pm) - if err != nil { - return nil, resp, err - } - - return pm, resp, nil + return do[*ProjectMember](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/members", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // EditProjectMemberOptions represents the available EditProjectMember() options. @@ -244,24 +177,12 @@ type EditProjectMemberOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/members/#edit-a-member-of-a-group-or-project func (s *ProjectMembersService) EditProjectMember(pid any, user int64, opt *EditProjectMemberOptions, options ...RequestOptionFunc) (*ProjectMember, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/members/%d", PathEscape(project), user) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - pm := new(ProjectMember) - resp, err := s.client.Do(req, pm) - if err != nil { - return nil, resp, err - } - - return pm, resp, nil + return do[*ProjectMember](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/members/%d", ProjectID{pid}, user), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // DeleteProjectMember removes a user from a project team. @@ -269,16 +190,10 @@ func (s *ProjectMembersService) EditProjectMember(pid any, user int64, opt *Edit // GitLab API docs: // https://docs.gitlab.com/api/members/#remove-a-member-from-a-group-or-project func (s *ProjectMembersService) DeleteProjectMember(pid any, user int64, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/members/%d", PathEscape(project), user) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/members/%d", ProjectID{pid}, user), + withRequestOpts(options...), + ) + return resp, err } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/project_mirror.go b/vendor/gitlab.com/gitlab-org/api/client-go/project_mirror.go index 258c5a62..51cf3eaa 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/project_mirror.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/project_mirror.go @@ -17,19 +17,47 @@ package gitlab import ( - "fmt" "net/http" "time" ) type ( ProjectMirrorServiceInterface interface { + // ListProjectMirror gets a list of mirrors configured on the project. + // + // GitLab API docs: + // https://docs.gitlab.com/api/remote_mirrors/#list-a-projects-remote-mirrors ListProjectMirror(pid any, opt *ListProjectMirrorOptions, options ...RequestOptionFunc) ([]*ProjectMirror, *Response, error) + // GetProjectMirror gets a single mirror configured on the project. + // + // GitLab API docs: + // https://docs.gitlab.com/api/remote_mirrors/#get-a-single-projects-remote-mirror GetProjectMirror(pid any, mirror int64, options ...RequestOptionFunc) (*ProjectMirror, *Response, error) + // GetProjectMirrorPublicKey gets the SSH public key for a single mirror configured on the project. + // + // GitLab API docs: + // https://docs.gitlab.com/api/remote_mirrors/#get-a-single-projects-remote-mirror-public-key GetProjectMirrorPublicKey(pid any, mirror int64, options ...RequestOptionFunc) (*ProjectMirrorPublicKey, *Response, error) + // AddProjectMirror creates a new mirror on the project. + // + // GitLab API docs: + // https://docs.gitlab.com/api/remote_mirrors/#create-a-push-mirror AddProjectMirror(pid any, opt *AddProjectMirrorOptions, options ...RequestOptionFunc) (*ProjectMirror, *Response, error) + // EditProjectMirror updates a remote mirror's attributes. + // + // GitLab API docs: + // https://docs.gitlab.com/api/remote_mirrors/#update-a-remote-mirrors-attributes EditProjectMirror(pid any, mirror int64, opt *EditProjectMirrorOptions, options ...RequestOptionFunc) (*ProjectMirror, *Response, error) + // DeleteProjectMirror deletes a project mirror. + // + // GitLab API docs: + // https://docs.gitlab.com/api/remote_mirrors/#delete-a-remote-mirror DeleteProjectMirror(pid any, mirror int64, options ...RequestOptionFunc) (*Response, error) + // ForcePushMirrorUpdate triggers a manual update for a project mirror. + // + // GitLab API docs: + // https://docs.gitlab.com/api/remote_mirrors/#force-push-mirror-update + ForcePushMirrorUpdate(pid any, mirror int64, options ...RequestOptionFunc) (*Response, error) } // ProjectMirrorService handles communication with the project mirror @@ -70,79 +98,26 @@ type ListProjectMirrorOptions struct { ListOptions } -// ListProjectMirror gets a list of mirrors configured on the project. -// -// GitLab API docs: -// https://docs.gitlab.com/api/remote_mirrors/#list-a-projects-remote-mirrors func (s *ProjectMirrorService) ListProjectMirror(pid any, opt *ListProjectMirrorOptions, options ...RequestOptionFunc) ([]*ProjectMirror, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/remote_mirrors", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var pm []*ProjectMirror - resp, err := s.client.Do(req, &pm) - if err != nil { - return nil, resp, err - } - - return pm, resp, nil + return do[[]*ProjectMirror](s.client, + withPath("projects/%s/remote_mirrors", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } -// GetProjectMirror gets a single mirror configured on the project. -// -// GitLab API docs: -// https://docs.gitlab.com/api/remote_mirrors/#get-a-single-projects-remote-mirror func (s *ProjectMirrorService) GetProjectMirror(pid any, mirror int64, options ...RequestOptionFunc) (*ProjectMirror, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/remote_mirrors/%d", PathEscape(project), mirror) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - pm := new(ProjectMirror) - resp, err := s.client.Do(req, &pm) - if err != nil { - return nil, resp, err - } - - return pm, resp, nil + return do[*ProjectMirror](s.client, + withPath("projects/%s/remote_mirrors/%d", ProjectID{pid}, mirror), + withRequestOpts(options...), + ) } -// GetProjectMirrorPublicKey gets the SSH public key for a single mirror configured on the project. -// -// GitLab API docs: -// https://docs.gitlab.com/api/remote_mirrors/#get-a-single-projects-remote-mirror-public-key func (s *ProjectMirrorService) GetProjectMirrorPublicKey(pid any, mirror int64, options ...RequestOptionFunc) (*ProjectMirrorPublicKey, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/remote_mirrors/%d/public_key", PathEscape(project), mirror) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - pmpk := new(ProjectMirrorPublicKey) - resp, err := s.client.Do(req, &pmpk) - if err != nil { - return nil, resp, err - } - - return pmpk, resp, nil + return do[*ProjectMirrorPublicKey](s.client, + withPath("projects/%s/remote_mirrors/%d/public_key", ProjectID{pid}, mirror), + withRequestOpts(options...), + ) } // AddProjectMirrorOptions contains the properties requires to create @@ -159,29 +134,13 @@ type AddProjectMirrorOptions struct { AuthMethod *string `url:"auth_method,omitempty" json:"auth_method,omitempty"` } -// AddProjectMirror creates a new mirror on the project. -// -// GitLab API docs: -// https://docs.gitlab.com/api/remote_mirrors/#create-a-push-mirror func (s *ProjectMirrorService) AddProjectMirror(pid any, opt *AddProjectMirrorOptions, options ...RequestOptionFunc) (*ProjectMirror, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/remote_mirrors", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - pm := new(ProjectMirror) - resp, err := s.client.Do(req, pm) - if err != nil { - return nil, resp, err - } - - return pm, resp, nil + return do[*ProjectMirror](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/remote_mirrors", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // EditProjectMirrorOptions contains the properties requires to edit @@ -197,46 +156,29 @@ type EditProjectMirrorOptions struct { AuthMethod *string `url:"auth_method,omitempty" json:"auth_method,omitempty"` } -// EditProjectMirror updates a project team member to a specified access level.. -// -// GitLab API docs: -// https://docs.gitlab.com/api/remote_mirrors/#update-a-remote-mirrors-attributes func (s *ProjectMirrorService) EditProjectMirror(pid any, mirror int64, opt *EditProjectMirrorOptions, options ...RequestOptionFunc) (*ProjectMirror, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/remote_mirrors/%d", PathEscape(project), mirror) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - pm := new(ProjectMirror) - resp, err := s.client.Do(req, pm) - if err != nil { - return nil, resp, err - } - - return pm, resp, nil + return do[*ProjectMirror](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/remote_mirrors/%d", ProjectID{pid}, mirror), + withAPIOpts(opt), + withRequestOpts(options...), + ) } -// DeleteProjectMirror deletes a project mirror. -// -// GitLab API docs: -// https://docs.gitlab.com/api/remote_mirrors/#delete-a-remote-mirror func (s *ProjectMirrorService) DeleteProjectMirror(pid any, mirror int64, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/remote_mirrors/%d", PathEscape(project), mirror) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/remote_mirrors/%d", ProjectID{pid}, mirror), + withRequestOpts(options...), + ) + return resp, err +} - return s.client.Do(req, nil) +func (s *ProjectMirrorService) ForcePushMirrorUpdate(pid any, mirror int64, options ...RequestOptionFunc) (*Response, error) { + _, resp, err := do[none](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/remote_mirrors/%d/sync", ProjectID{pid}, mirror), + withRequestOpts(options...), + ) + return resp, err } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/project_repository_storage_move.go b/vendor/gitlab.com/gitlab-org/api/client-go/project_repository_storage_move.go index 7a94ddce..a3411ed3 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/project_repository_storage_move.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/project_repository_storage_move.go @@ -17,18 +17,43 @@ package gitlab import ( - "fmt" "net/http" "time" ) type ( ProjectRepositoryStorageMoveServiceInterface interface { + // RetrieveAllStorageMoves retrieves all project repository storage moves + // accessible by the authenticated user. + // + // GitLab API docs: + // https://docs.gitlab.com/api/project_repository_storage_moves/#retrieve-all-project-repository-storage-moves RetrieveAllStorageMoves(opts RetrieveAllProjectStorageMovesOptions, options ...RequestOptionFunc) ([]*ProjectRepositoryStorageMove, *Response, error) + // RetrieveAllStorageMovesForProject retrieves all repository storage moves for + // a single project accessible by the authenticated user. + // + // GitLab API docs: + // https://docs.gitlab.com/api/project_repository_storage_moves/#retrieve-all-repository-storage-moves-for-a-project RetrieveAllStorageMovesForProject(project int64, opts RetrieveAllProjectStorageMovesOptions, options ...RequestOptionFunc) ([]*ProjectRepositoryStorageMove, *Response, error) + // GetStorageMove gets a single project repository storage move. + // + // GitLab API docs: + // https://docs.gitlab.com/api/project_repository_storage_moves/#get-a-single-project-repository-storage-move GetStorageMove(repositoryStorage int64, options ...RequestOptionFunc) (*ProjectRepositoryStorageMove, *Response, error) + // GetStorageMoveForProject gets a single repository storage move for a project. + // + // GitLab API docs: + // https://docs.gitlab.com/api/project_repository_storage_moves/#get-a-single-repository-storage-move-for-a-project GetStorageMoveForProject(project int64, repositoryStorage int64, options ...RequestOptionFunc) (*ProjectRepositoryStorageMove, *Response, error) + // ScheduleStorageMoveForProject schedule a repository to be moved for a project. + // + // GitLab API docs: + // https://docs.gitlab.com/api/project_repository_storage_moves/#schedule-a-repository-storage-move-for-a-project ScheduleStorageMoveForProject(project int64, opts ScheduleStorageMoveForProjectOptions, options ...RequestOptionFunc) (*ProjectRepositoryStorageMove, *Response, error) + // ScheduleAllStorageMoves schedules all repositories to be moved. + // + // GitLab API docs: + // https://docs.gitlab.com/api/project_repository_storage_moves/#schedule-repository-storage-moves-for-all-projects-on-a-storage-shard ScheduleAllStorageMoves(opts ScheduleAllProjectStorageMovesOptions, options ...RequestOptionFunc) (*Response, error) } @@ -76,88 +101,34 @@ type RetrieveAllProjectStorageMovesOptions struct { ListOptions } -// RetrieveAllStorageMoves retrieves all project repository storage moves -// accessible by the authenticated user. -// -// GitLab API docs: -// https://docs.gitlab.com/api/project_repository_storage_moves/#retrieve-all-project-repository-storage-moves func (p ProjectRepositoryStorageMoveService) RetrieveAllStorageMoves(opts RetrieveAllProjectStorageMovesOptions, options ...RequestOptionFunc) ([]*ProjectRepositoryStorageMove, *Response, error) { - req, err := p.client.NewRequest(http.MethodGet, "project_repository_storage_moves", opts, options) - if err != nil { - return nil, nil, err - } - - var psms []*ProjectRepositoryStorageMove - resp, err := p.client.Do(req, &psms) - if err != nil { - return nil, resp, err - } - - return psms, resp, err + return do[[]*ProjectRepositoryStorageMove](p.client, + withPath("project_repository_storage_moves"), + withAPIOpts(opts), + withRequestOpts(options...), + ) } -// RetrieveAllStorageMovesForProject retrieves all repository storage moves for -// a single project accessible by the authenticated user. -// -// GitLab API docs: -// https://docs.gitlab.com/api/project_repository_storage_moves/#retrieve-all-repository-storage-moves-for-a-project func (p ProjectRepositoryStorageMoveService) RetrieveAllStorageMovesForProject(project int64, opts RetrieveAllProjectStorageMovesOptions, options ...RequestOptionFunc) ([]*ProjectRepositoryStorageMove, *Response, error) { - u := fmt.Sprintf("projects/%d/repository_storage_moves", project) - - req, err := p.client.NewRequest(http.MethodGet, u, opts, options) - if err != nil { - return nil, nil, err - } - - var psms []*ProjectRepositoryStorageMove - resp, err := p.client.Do(req, &psms) - if err != nil { - return nil, resp, err - } - - return psms, resp, err + return do[[]*ProjectRepositoryStorageMove](p.client, + withPath("projects/%d/repository_storage_moves", project), + withAPIOpts(opts), + withRequestOpts(options...), + ) } -// GetStorageMove gets a single project repository storage move. -// -// GitLab API docs: -// https://docs.gitlab.com/api/project_repository_storage_moves/#get-a-single-project-repository-storage-move func (p ProjectRepositoryStorageMoveService) GetStorageMove(repositoryStorage int64, options ...RequestOptionFunc) (*ProjectRepositoryStorageMove, *Response, error) { - u := fmt.Sprintf("project_repository_storage_moves/%d", repositoryStorage) - - req, err := p.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - psm := new(ProjectRepositoryStorageMove) - resp, err := p.client.Do(req, psm) - if err != nil { - return nil, resp, err - } - - return psm, resp, err + return do[*ProjectRepositoryStorageMove](p.client, + withPath("project_repository_storage_moves/%d", repositoryStorage), + withRequestOpts(options...), + ) } -// GetStorageMoveForProject gets a single repository storage move for a project. -// -// GitLab API docs: -// https://docs.gitlab.com/api/project_repository_storage_moves/#get-a-single-repository-storage-move-for-a-project func (p ProjectRepositoryStorageMoveService) GetStorageMoveForProject(project int64, repositoryStorage int64, options ...RequestOptionFunc) (*ProjectRepositoryStorageMove, *Response, error) { - u := fmt.Sprintf("projects/%d/repository_storage_moves/%d", project, repositoryStorage) - - req, err := p.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - psm := new(ProjectRepositoryStorageMove) - resp, err := p.client.Do(req, psm) - if err != nil { - return nil, resp, err - } - - return psm, resp, err + return do[*ProjectRepositoryStorageMove](p.client, + withPath("projects/%d/repository_storage_moves/%d", project, repositoryStorage), + withRequestOpts(options...), + ) } // ScheduleStorageMoveForProjectOptions represents the available @@ -169,25 +140,13 @@ type ScheduleStorageMoveForProjectOptions struct { DestinationStorageName *string `url:"destination_storage_name,omitempty" json:"destination_storage_name,omitempty"` } -// ScheduleStorageMoveForProject schedule a repository to be moved for a project. -// -// GitLab API docs: -// https://docs.gitlab.com/api/project_repository_storage_moves/#schedule-a-repository-storage-move-for-a-project func (p ProjectRepositoryStorageMoveService) ScheduleStorageMoveForProject(project int64, opts ScheduleStorageMoveForProjectOptions, options ...RequestOptionFunc) (*ProjectRepositoryStorageMove, *Response, error) { - u := fmt.Sprintf("projects/%d/repository_storage_moves", project) - - req, err := p.client.NewRequest(http.MethodPost, u, opts, options) - if err != nil { - return nil, nil, err - } - - psm := new(ProjectRepositoryStorageMove) - resp, err := p.client.Do(req, psm) - if err != nil { - return nil, resp, err - } - - return psm, resp, err + return do[*ProjectRepositoryStorageMove](p.client, + withMethod(http.MethodPost), + withPath("projects/%d/repository_storage_moves", project), + withAPIOpts(opts), + withRequestOpts(options...), + ) } // ScheduleAllProjectStorageMovesOptions represents the available @@ -200,15 +159,12 @@ type ScheduleAllProjectStorageMovesOptions struct { DestinationStorageName *string `url:"destination_storage_name,omitempty" json:"destination_storage_name,omitempty"` } -// ScheduleAllStorageMoves schedules all repositories to be moved. -// -// GitLab API docs: -// https://docs.gitlab.com/api/project_repository_storage_moves/#schedule-repository-storage-moves-for-all-projects-on-a-storage-shard func (p ProjectRepositoryStorageMoveService) ScheduleAllStorageMoves(opts ScheduleAllProjectStorageMovesOptions, options ...RequestOptionFunc) (*Response, error) { - req, err := p.client.NewRequest(http.MethodPost, "project_repository_storage_moves", opts, options) - if err != nil { - return nil, err - } - - return p.client.Do(req, nil) + _, resp, err := do[none](p.client, + withMethod(http.MethodPost), + withPath("project_repository_storage_moves"), + withAPIOpts(opts), + withRequestOpts(options...), + ) + return resp, err } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/project_security_settings.go b/vendor/gitlab.com/gitlab-org/api/client-go/project_security_settings.go index 52eb64d1..d200c576 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/project_security_settings.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/project_security_settings.go @@ -16,14 +16,22 @@ package gitlab import ( - "fmt" "net/http" "time" ) type ( ProjectSecuritySettingsServiceInterface interface { + // ListProjectSecuritySettings lists all of a project's security settings. + // + // GitLab API Docs: + // https://docs.gitlab.com/api/project_security_settings/#list-project-security-settings ListProjectSecuritySettings(pid any, options ...RequestOptionFunc) (*ProjectSecuritySettings, *Response, error) + // UpdateSecretPushProtectionEnabledSetting updates the secret_push_protection_enabled + // setting for a project to the provided value. + // + // GitLab API Docs: + // https://docs.gitlab.com/api/project_security_settings/#update-secret_push_protection_enabled-setting UpdateSecretPushProtectionEnabledSetting(pid any, opt UpdateProjectSecuritySettingsOptions, options ...RequestOptionFunc) (*ProjectSecuritySettings, *Response, error) } @@ -64,28 +72,11 @@ func (s ProjectSecuritySettings) String() string { return Stringify(s) } -// ListProjectSecuritySettings lists all of a project's security settings. -// -// GitLab API Docs: -// https://docs.gitlab.com/api/project_security_settings/#list-project-security-settings func (s *ProjectSecuritySettingsService) ListProjectSecuritySettings(pid any, options ...RequestOptionFunc) (*ProjectSecuritySettings, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/security_settings", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - settings := new(ProjectSecuritySettings) - resp, err := s.client.Do(req, &settings) - if err != nil { - return nil, resp, err - } - - return settings, resp, err + return do[*ProjectSecuritySettings](s.client, + withPath("projects/%s/security_settings", ProjectID{pid}), + withRequestOpts(options...), + ) } // UpdateProjectSecuritySettingsOptions represent the request options for updating @@ -97,27 +88,11 @@ type UpdateProjectSecuritySettingsOptions struct { SecretPushProtectionEnabled *bool `url:"secret_push_protection_enabled,omitempty" json:"secret_push_protection_enabled,omitempty"` } -// UpdateSecretPushProtectionEnabledSetting updates the secret_push_protection_enabled -// setting for the all projects in a project to the provided value. -// -// GitLab API Docs: -// https://docs.gitlab.com/api/project_security_settings/#update-secret_push_protection_enabled-setting func (s *ProjectSecuritySettingsService) UpdateSecretPushProtectionEnabledSetting(pid any, opt UpdateProjectSecuritySettingsOptions, options ...RequestOptionFunc) (*ProjectSecuritySettings, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/security_settings", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - settings := new(ProjectSecuritySettings) - resp, err := s.client.Do(req, &settings) - if err != nil { - return nil, resp, err - } - - return settings, resp, err + return do[*ProjectSecuritySettings](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/security_settings", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/project_snippets.go b/vendor/gitlab.com/gitlab-org/api/client-go/project_snippets.go index 8ba3cb3f..b35e2a7c 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/project_snippets.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/project_snippets.go @@ -18,7 +18,6 @@ package gitlab import ( "bytes" - "fmt" "net/http" ) @@ -54,24 +53,11 @@ type ListProjectSnippetsOptions struct { // // GitLab API docs: https://docs.gitlab.com/api/project_snippets/#list-snippets func (s *ProjectSnippetsService) ListSnippets(pid any, opt *ListProjectSnippetsOptions, options ...RequestOptionFunc) ([]*Snippet, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/snippets", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var ps []*Snippet - resp, err := s.client.Do(req, &ps) - if err != nil { - return nil, resp, err - } - - return ps, resp, nil + return do[[]*Snippet](s.client, + withPath("projects/%s/snippets", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // GetSnippet gets a single project snippet @@ -79,24 +65,10 @@ func (s *ProjectSnippetsService) ListSnippets(pid any, opt *ListProjectSnippetsO // GitLab API docs: // https://docs.gitlab.com/api/project_snippets/#single-snippet func (s *ProjectSnippetsService) GetSnippet(pid any, snippet int64, options ...RequestOptionFunc) (*Snippet, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/snippets/%d", PathEscape(project), snippet) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - ps := new(Snippet) - resp, err := s.client.Do(req, ps) - if err != nil { - return nil, resp, err - } - - return ps, resp, nil + return do[*Snippet](s.client, + withPath("projects/%s/snippets/%d", ProjectID{pid}, snippet), + withRequestOpts(options...), + ) } // CreateProjectSnippetOptions represents the available CreateSnippet() options. @@ -121,24 +93,12 @@ type CreateProjectSnippetOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/project_snippets/#create-new-snippet func (s *ProjectSnippetsService) CreateSnippet(pid any, opt *CreateProjectSnippetOptions, options ...RequestOptionFunc) (*Snippet, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/snippets", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - ps := new(Snippet) - resp, err := s.client.Do(req, ps) - if err != nil { - return nil, resp, err - } - - return ps, resp, nil + return do[*Snippet](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/snippets", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // UpdateProjectSnippetOptions represents the available UpdateSnippet() options. @@ -163,24 +123,12 @@ type UpdateProjectSnippetOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/project_snippets/#update-snippet func (s *ProjectSnippetsService) UpdateSnippet(pid any, snippet int64, opt *UpdateProjectSnippetOptions, options ...RequestOptionFunc) (*Snippet, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/snippets/%d", PathEscape(project), snippet) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - ps := new(Snippet) - resp, err := s.client.Do(req, ps) - if err != nil { - return nil, resp, err - } - - return ps, resp, nil + return do[*Snippet](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/snippets/%d", ProjectID{pid}, snippet), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // DeleteSnippet deletes an existing project snippet. This is an idempotent @@ -190,18 +138,12 @@ func (s *ProjectSnippetsService) UpdateSnippet(pid any, snippet int64, opt *Upda // GitLab API docs: // https://docs.gitlab.com/api/project_snippets/#delete-snippet func (s *ProjectSnippetsService) DeleteSnippet(pid any, snippet int64, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/snippets/%d", PathEscape(project), snippet) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/snippets/%d", ProjectID{pid}, snippet), + withRequestOpts(options...), + ) + return resp, err } // SnippetContent returns the raw project snippet as plain text. @@ -209,22 +151,12 @@ func (s *ProjectSnippetsService) DeleteSnippet(pid any, snippet int64, options . // GitLab API docs: // https://docs.gitlab.com/api/project_snippets/#snippet-content func (s *ProjectSnippetsService) SnippetContent(pid any, snippet int64, options ...RequestOptionFunc) ([]byte, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/snippets/%d/raw", PathEscape(project), snippet) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - var b bytes.Buffer - resp, err := s.client.Do(req, &b) + buf, resp, err := do[bytes.Buffer](s.client, + withPath("projects/%s/snippets/%d/raw", ProjectID{pid}, snippet), + withRequestOpts(options...), + ) if err != nil { return nil, resp, err } - - return b.Bytes(), resp, err + return buf.Bytes(), resp, nil } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/project_statistics.go b/vendor/gitlab.com/gitlab-org/api/client-go/project_statistics.go index 1ff9edf9..86dfd022 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/project_statistics.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/project_statistics.go @@ -1,10 +1,5 @@ package gitlab -import ( - "fmt" - "net/http" -) - type ( ProjectStatisticsServiceInterface interface { // Last30DaysStatistics gets the project statistics for the last 30 days. @@ -42,25 +37,8 @@ type DayStats struct { var _ ProjectStatisticsServiceInterface = (*ProjectStatisticsService)(nil) func (s *ProjectStatisticsService) Last30DaysStatistics(pid any, options ...RequestOptionFunc) (*ProjectStatistics, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - - u := fmt.Sprintf("projects/%s/statistics", - PathEscape(project), + return do[*ProjectStatistics](s.client, + withPath("projects/%s/statistics", ProjectID{pid}), + withRequestOpts(options...), ) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - projectStats := new(ProjectStatistics) - resp, err := s.client.Do(req, projectStats) - if err != nil { - return nil, resp, err - } - - return projectStats, resp, err } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/project_templates.go b/vendor/gitlab.com/gitlab-org/api/client-go/project_templates.go index ffafb257..706b258d 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/project_templates.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/project_templates.go @@ -16,14 +16,16 @@ package gitlab -import ( - "fmt" - "net/http" -) - type ( ProjectTemplatesServiceInterface interface { + // ListTemplates gets a list of project templates. + // + // GitLab API docs: https://docs.gitlab.com/api/project_templates/#get-all-templates-of-a-particular-type ListTemplates(pid any, templateType string, opt *ListProjectTemplatesOptions, options ...RequestOptionFunc) ([]*ProjectTemplate, *Response, error) + // GetProjectTemplate gets a single project template. + // + // GitLab API docs: + // https://docs.gitlab.com/api/project_templates/#get-one-template-of-a-particular-type GetProjectTemplate(pid any, templateType string, templateName string, options ...RequestOptionFunc) (*ProjectTemplate, *Response, error) } @@ -69,51 +71,17 @@ type ListProjectTemplatesOptions struct { Type *string `url:"type,omitempty" json:"type,omitempty"` } -// ListTemplates gets a list of project templates. -// -// GitLab API docs: https://docs.gitlab.com/api/project_templates/#get-all-templates-of-a-particular-type func (s *ProjectTemplatesService) ListTemplates(pid any, templateType string, opt *ListProjectTemplatesOptions, options ...RequestOptionFunc) ([]*ProjectTemplate, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/templates/%s", PathEscape(project), templateType) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var pt []*ProjectTemplate - resp, err := s.client.Do(req, &pt) - if err != nil { - return nil, resp, err - } - - return pt, resp, nil + return do[[]*ProjectTemplate](s.client, + withPath("projects/%s/templates/%s", ProjectID{pid}, templateType), + withAPIOpts(opt), + withRequestOpts(options...), + ) } -// GetProjectTemplate gets a single project template. -// -// GitLab API docs: -// https://docs.gitlab.com/api/project_templates/#get-one-template-of-a-particular-type func (s *ProjectTemplatesService) GetProjectTemplate(pid any, templateType string, templateName string, options ...RequestOptionFunc) (*ProjectTemplate, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/templates/%s/%s", PathEscape(project), templateType, templateName) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - ptd := new(ProjectTemplate) - resp, err := s.client.Do(req, ptd) - if err != nil { - return nil, resp, err - } - - return ptd, resp, nil + return do[*ProjectTemplate](s.client, + withPath("projects/%s/templates/%s/%s", ProjectID{pid}, templateType, templateName), + withRequestOpts(options...), + ) } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/project_variables.go b/vendor/gitlab.com/gitlab-org/api/client-go/project_variables.go index ee85aa78..d2b356e3 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/project_variables.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/project_variables.go @@ -17,17 +17,36 @@ package gitlab import ( - "fmt" "net/http" "net/url" ) type ( ProjectVariablesServiceInterface interface { + // ListVariables gets a list of all variables in a project. + // + // GitLab API docs: + // https://docs.gitlab.com/api/project_level_variables/#list-project-variables ListVariables(pid any, opt *ListProjectVariablesOptions, options ...RequestOptionFunc) ([]*ProjectVariable, *Response, error) + // GetVariable gets a variable. + // + // GitLab API docs: + // https://docs.gitlab.com/api/project_level_variables/#get-a-single-variable GetVariable(pid any, key string, opt *GetProjectVariableOptions, options ...RequestOptionFunc) (*ProjectVariable, *Response, error) + // CreateVariable creates a new project variable. + // + // GitLab API docs: + // https://docs.gitlab.com/api/project_level_variables/#create-a-variable CreateVariable(pid any, opt *CreateProjectVariableOptions, options ...RequestOptionFunc) (*ProjectVariable, *Response, error) + // UpdateVariable updates a project's variable. + // + // GitLab API docs: + // https://docs.gitlab.com/api/project_level_variables/#update-a-variable UpdateVariable(pid any, key string, opt *UpdateProjectVariableOptions, options ...RequestOptionFunc) (*ProjectVariable, *Response, error) + // RemoveVariable removes a project's variable. + // + // GitLab API docs: + // https://docs.gitlab.com/api/project_level_variables/#delete-a-variable RemoveVariable(pid any, key string, opt *RemoveProjectVariableOptions, options ...RequestOptionFunc) (*Response, error) } @@ -77,29 +96,12 @@ type ListProjectVariablesOptions struct { ListOptions } -// ListVariables gets a list of all variables in a project. -// -// GitLab API docs: -// https://docs.gitlab.com/api/project_level_variables/#list-project-variables func (s *ProjectVariablesService) ListVariables(pid any, opt *ListProjectVariablesOptions, options ...RequestOptionFunc) ([]*ProjectVariable, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/variables", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var vs []*ProjectVariable - resp, err := s.client.Do(req, &vs) - if err != nil { - return nil, resp, err - } - - return vs, resp, nil + return do[[]*ProjectVariable](s.client, + withPath("projects/%s/variables", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // GetProjectVariableOptions represents the available GetVariable() @@ -111,29 +113,12 @@ type GetProjectVariableOptions struct { Filter *VariableFilter `url:"filter,omitempty" json:"filter,omitempty"` } -// GetVariable gets a variable. -// -// GitLab API docs: -// https://docs.gitlab.com/api/project_level_variables/#get-a-single-variable func (s *ProjectVariablesService) GetVariable(pid any, key string, opt *GetProjectVariableOptions, options ...RequestOptionFunc) (*ProjectVariable, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/variables/%s", PathEscape(project), url.PathEscape(key)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - v := new(ProjectVariable) - resp, err := s.client.Do(req, v) - if err != nil { - return nil, resp, err - } - - return v, resp, nil + return do[*ProjectVariable](s.client, + withPath("projects/%s/variables/%s", ProjectID{pid}, url.PathEscape(key)), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // CreateProjectVariableOptions represents the available CreateVariable() @@ -153,29 +138,13 @@ type CreateProjectVariableOptions struct { VariableType *VariableTypeValue `url:"variable_type,omitempty" json:"variable_type,omitempty"` } -// CreateVariable creates a new project variable. -// -// GitLab API docs: -// https://docs.gitlab.com/api/project_level_variables/#create-a-variable func (s *ProjectVariablesService) CreateVariable(pid any, opt *CreateProjectVariableOptions, options ...RequestOptionFunc) (*ProjectVariable, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/variables", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - v := new(ProjectVariable) - resp, err := s.client.Do(req, v) - if err != nil { - return nil, resp, err - } - - return v, resp, nil + return do[*ProjectVariable](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/variables", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // UpdateProjectVariableOptions represents the available UpdateVariable() @@ -194,29 +163,13 @@ type UpdateProjectVariableOptions struct { VariableType *VariableTypeValue `url:"variable_type,omitempty" json:"variable_type,omitempty"` } -// UpdateVariable updates a project's variable. -// -// GitLab API docs: -// https://docs.gitlab.com/api/project_level_variables/#update-a-variable func (s *ProjectVariablesService) UpdateVariable(pid any, key string, opt *UpdateProjectVariableOptions, options ...RequestOptionFunc) (*ProjectVariable, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/variables/%s", PathEscape(project), url.PathEscape(key)) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - v := new(ProjectVariable) - resp, err := s.client.Do(req, v) - if err != nil { - return nil, resp, err - } - - return v, resp, nil + return do[*ProjectVariable](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/variables/%s", ProjectID{pid}, url.PathEscape(key)), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // RemoveProjectVariableOptions represents the available RemoveVariable() @@ -228,21 +181,12 @@ type RemoveProjectVariableOptions struct { Filter *VariableFilter `url:"filter,omitempty" json:"filter,omitempty"` } -// RemoveVariable removes a project's variable. -// -// GitLab API docs: -// https://docs.gitlab.com/api/project_level_variables/#delete-a-variable func (s *ProjectVariablesService) RemoveVariable(pid any, key string, opt *RemoveProjectVariableOptions, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/variables/%s", PathEscape(project), url.PathEscape(key)) - - req, err := s.client.NewRequest(http.MethodDelete, u, opt, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/variables/%s", ProjectID{pid}, url.PathEscape(key)), + withAPIOpts(opt), + withRequestOpts(options...), + ) + return resp, err } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/project_vulnerabilities.go b/vendor/gitlab.com/gitlab-org/api/client-go/project_vulnerabilities.go index b55130e1..783adf6c 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/project_vulnerabilities.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/project_vulnerabilities.go @@ -17,7 +17,6 @@ package gitlab import ( - "fmt" "net/http" "time" ) @@ -113,24 +112,11 @@ type ListProjectVulnerabilitiesOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/project_vulnerabilities/#list-project-vulnerabilities func (s *ProjectVulnerabilitiesService) ListProjectVulnerabilities(pid any, opt *ListProjectVulnerabilitiesOptions, options ...RequestOptionFunc) ([]*ProjectVulnerability, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/vulnerabilities", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var p []*ProjectVulnerability - resp, err := s.client.Do(req, &p) - if err != nil { - return nil, resp, err - } - - return p, resp, nil + return do[[]*ProjectVulnerability](s.client, + withPath("projects/%s/vulnerabilities", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // CreateVulnerabilityOptions represents the available CreateVulnerability() @@ -149,22 +135,10 @@ type CreateVulnerabilityOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/project_vulnerabilities/#new-vulnerability func (s *ProjectVulnerabilitiesService) CreateVulnerability(pid any, opt *CreateVulnerabilityOptions, options ...RequestOptionFunc) (*ProjectVulnerability, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/vulnerabilities", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - p := new(ProjectVulnerability) - resp, err := s.client.Do(req, p) - if err != nil { - return nil, resp, err - } - - return p, resp, nil + return do[*ProjectVulnerability](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/vulnerabilities", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/projects.go b/vendor/gitlab.com/gitlab-org/api/client-go/projects.go index 2dfbfbeb..27c5af9a 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/projects.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/projects.go @@ -19,12 +19,9 @@ package gitlab import ( "bytes" "encoding/json" - "fmt" "io" "net/http" "time" - - "github.com/hashicorp/go-retryablehttp" ) type ( @@ -33,59 +30,295 @@ type ( // // GitLab API docs: https://docs.gitlab.com/api/projects/ ProjectsServiceInterface interface { + // ListProjects gets a list of projects accessible by the authenticated user. + // + // GitLab API docs: https://docs.gitlab.com/api/projects/#list-all-projects ListProjects(opt *ListProjectsOptions, options ...RequestOptionFunc) ([]*Project, *Response, error) + // ListUserProjects gets a list of projects for the given user. + // + // uid can be either a user ID (int) or a username (string). If a username + // is provided with a leading "@" (e.g., "@johndoe"), it will be trimmed. + // GitLab API docs: + // https://docs.gitlab.com/api/projects/#list-a-users-projects ListUserProjects(uid any, opt *ListProjectsOptions, options ...RequestOptionFunc) ([]*Project, *Response, error) + // ListUserContributedProjects gets a list of visible projects a given user + // has contributed to. + // + // uid can be either a user ID (int) or a username (string). If a username + // is provided with a leading "@" (e.g., "@johndoe"), it will be trimmed. + // GitLab API docs: + // https://docs.gitlab.com/api/projects/#list-projects-a-user-has-contributed-to ListUserContributedProjects(uid any, opt *ListProjectsOptions, options ...RequestOptionFunc) ([]*Project, *Response, error) + // ListUserStarredProjects gets a list of projects starred by the given user. + // + // uid can be either a user ID (int) or a username (string). If a username + // is provided with a leading "@" (e.g., "@johndoe"), it will be trimmed. + // GitLab API docs: + // https://docs.gitlab.com/api/project_starring/#list-projects-starred-by-a-user ListUserStarredProjects(uid any, opt *ListProjectsOptions, options ...RequestOptionFunc) ([]*Project, *Response, error) + // ListProjectsUsers gets a list of users for the given project. + // + // GitLab API docs: + // https://docs.gitlab.com/api/projects/#list-users ListProjectsUsers(pid any, opt *ListProjectUserOptions, options ...RequestOptionFunc) ([]*ProjectUser, *Response, error) + // ListProjectsGroups gets a list of groups for the given project. + // + // GitLab API docs: + // https://docs.gitlab.com/api/projects/#list-groups ListProjectsGroups(pid any, opt *ListProjectGroupOptions, options ...RequestOptionFunc) ([]*ProjectGroup, *Response, error) + // GetProjectLanguages gets a list of languages used by the project. + // + // GitLab API docs: + // https://docs.gitlab.com/api/projects/#list-programming-languages-used GetProjectLanguages(pid any, options ...RequestOptionFunc) (*ProjectLanguages, *Response, error) + // GetProject gets a specific project, identified by project ID or + // NAMESPACE/PROJECT_NAME, which is owned by the authenticated user. + // + // GitLab API docs: + // https://docs.gitlab.com/api/projects/#get-a-single-project GetProject(pid any, opt *GetProjectOptions, options ...RequestOptionFunc) (*Project, *Response, error) + // CreateProject creates a new project owned by the authenticated user. + // + // GitLab API docs: https://docs.gitlab.com/api/projects/#create-a-project CreateProject(opt *CreateProjectOptions, options ...RequestOptionFunc) (*Project, *Response, error) + // CreateProjectForUser creates a new project owned by the specified user. + // Available only for admins. + // + // GitLab API docs: + // https://docs.gitlab.com/api/projects/#create-a-project-for-a-user CreateProjectForUser(user int64, opt *CreateProjectForUserOptions, options ...RequestOptionFunc) (*Project, *Response, error) + // EditProject updates an existing project. + // + // GitLab API docs: https://docs.gitlab.com/api/projects/#edit-a-project EditProject(pid any, opt *EditProjectOptions, options ...RequestOptionFunc) (*Project, *Response, error) + // ForkProject forks a project into the user namespace of the authenticated + // user. + // + // GitLab API docs: + // https://docs.gitlab.com/api/project_forks/#fork-a-project ForkProject(pid any, opt *ForkProjectOptions, options ...RequestOptionFunc) (*Project, *Response, error) + // StarProject stars a given project. + // + // GitLab API docs: + // https://docs.gitlab.com/api/project_starring/#star-a-project StarProject(pid any, options ...RequestOptionFunc) (*Project, *Response, error) + // ListProjectsInvitedGroups lists invited groups of a project + // + // GitLab API docs: + // https://docs.gitlab.com/api/projects/#list-a-projects-invited-groups ListProjectsInvitedGroups(pid any, opt *ListProjectInvitedGroupOptions, options ...RequestOptionFunc) ([]*ProjectGroup, *Response, error) + // UnstarProject unstars a given project. + // + // GitLab API docs: + // https://docs.gitlab.com/api/project_starring/#unstar-a-project UnstarProject(pid any, options ...RequestOptionFunc) (*Project, *Response, error) + // ArchiveProject archives the project if the user is either admin or the + // project owner of this project. + // + // GitLab API docs: + // https://docs.gitlab.com/api/projects/#archive-a-project ArchiveProject(pid any, options ...RequestOptionFunc) (*Project, *Response, error) + // UnarchiveProject unarchives the project if the user is either admin or + // the project owner of this project. + // + // GitLab API docs: + // https://docs.gitlab.com/api/projects/#unarchive-a-project UnarchiveProject(pid any, options ...RequestOptionFunc) (*Project, *Response, error) + // RestoreProject restores a project that is marked for deletion. + // + // GitLab API docs: + // https://docs.gitlab.com/api/projects/#restore-a-project-marked-for-deletion RestoreProject(pid any, options ...RequestOptionFunc) (*Project, *Response, error) + // DeleteProject removes a project including all associated resources + // (issues, merge requests etc.) + // + // GitLab API docs: + // https://docs.gitlab.com/api/projects/#delete-a-project DeleteProject(pid any, opt *DeleteProjectOptions, options ...RequestOptionFunc) (*Response, error) + // ShareProjectWithGroup allows to share a project with a group. + // + // GitLab API docs: https://docs.gitlab.com/api/projects/#share-a-project-with-a-group ShareProjectWithGroup(pid any, opt *ShareWithGroupOptions, options ...RequestOptionFunc) (*Response, error) + // DeleteSharedProjectFromGroup allows to unshare a project from a group. + // + // GitLab API docs: + // https://docs.gitlab.com/api/projects/#delete-a-shared-project-link-in-a-group DeleteSharedProjectFromGroup(pid any, groupID int64, options ...RequestOptionFunc) (*Response, error) + // ListProjectHooks gets a list of project hooks. + // + // GitLab API docs: + // https://docs.gitlab.com/api/project_webhooks/#list-webhooks-for-a-project ListProjectHooks(pid any, opt *ListProjectHooksOptions, options ...RequestOptionFunc) ([]*ProjectHook, *Response, error) + // GetProjectHook gets a specific hook for a project. + // + // GitLab API docs: + // https://docs.gitlab.com/api/project_webhooks/#get-a-project-webhook GetProjectHook(pid any, hook int64, options ...RequestOptionFunc) (*ProjectHook, *Response, error) + // AddProjectHook adds a hook to a specified project. + // + // GitLab API docs: + // https://docs.gitlab.com/api/project_webhooks/#add-a-webhook-to-a-project AddProjectHook(pid any, opt *AddProjectHookOptions, options ...RequestOptionFunc) (*ProjectHook, *Response, error) + // EditProjectHook edits a hook for a specified project. + // + // GitLab API docs: + // https://docs.gitlab.com/api/project_webhooks/#edit-a-project-webhook EditProjectHook(pid any, hook int64, opt *EditProjectHookOptions, options ...RequestOptionFunc) (*ProjectHook, *Response, error) + // DeleteProjectHook removes a hook from a project. This is an idempotent + // method and can be called multiple times. Either the hook is available or not. + // + // GitLab API docs: + // https://docs.gitlab.com/api/project_webhooks/#delete-project-webhook DeleteProjectHook(pid any, hook int64, options ...RequestOptionFunc) (*Response, error) + // TriggerTestProjectHook Trigger a test hook for a specified project. + // + // In GitLab 17.0 and later, this endpoint has a special rate limit. + // In GitLab 17.0 the rate was three requests per minute for each project hook. + // In GitLab 17.1 this was changed to five requests per minute for each project + // and authenticated user. + // + // To disable this limit on self-managed GitLab and GitLab Dedicated, + // an administrator can disable the feature flag named web_hook_test_api_endpoint_rate_limit. + // + // GitLab API docs: + // https://docs.gitlab.com/api/project_webhooks/#trigger-a-test-project-webhook TriggerTestProjectHook(pid any, hook int64, event ProjectHookEvent, options ...RequestOptionFunc) (*Response, error) + // SetProjectCustomHeader creates or updates a project custom webhook header. + // + // GitLab API docs: + // https://docs.gitlab.com/api/project_webhooks/#set-a-custom-header SetProjectCustomHeader(pid any, hook int64, key string, opt *SetHookCustomHeaderOptions, options ...RequestOptionFunc) (*Response, error) + // DeleteProjectCustomHeader deletes a project custom webhook header. + // + // GitLab API docs: + // https://docs.gitlab.com/api/project_webhooks/#delete-a-custom-header DeleteProjectCustomHeader(pid any, hook int64, key string, options ...RequestOptionFunc) (*Response, error) + // SetProjectWebhookURLVariable creates or updates a project webhook URL variable. + // + // GitLab API docs: + // https://docs.gitlab.com/api/project_webhooks/#set-a-url-variable SetProjectWebhookURLVariable(pid any, hook int64, key string, opt *SetProjectWebhookURLVariableOptions, options ...RequestOptionFunc) (*Response, error) + // DeleteProjectWebhookURLVariable deletes a project webhook URL variable. + // + // GitLab API docs: + // https://docs.gitlab.com/api/project_webhooks/#delete-a-url-variable DeleteProjectWebhookURLVariable(pid any, hook int64, key string, options ...RequestOptionFunc) (*Response, error) + // CreateProjectForkRelation creates a forked from/to relation between + // existing projects. + // + // GitLab API docs: + // https://docs.gitlab.com/api/project_forks/#create-a-fork-relationship-between-projects CreateProjectForkRelation(pid any, fork int64, options ...RequestOptionFunc) (*ProjectForkRelation, *Response, error) + // DeleteProjectForkRelation deletes an existing forked from relationship. + // + // GitLab API docs: + // https://docs.gitlab.com/api/project_forks/#delete-a-fork-relationship-between-projects DeleteProjectForkRelation(pid any, options ...RequestOptionFunc) (*Response, error) + // UploadAvatar uploads an avatar. + // + // GitLab API docs: + // https://docs.gitlab.com/api/projects/#upload-a-project-avatar UploadAvatar(pid any, avatar io.Reader, filename string, options ...RequestOptionFunc) (*Project, *Response, error) + // DownloadAvatar downloads an avatar. + // + // GitLab API docs: + // https://docs.gitlab.com/api/projects/#download-a-project-avatar DownloadAvatar(pid any, options ...RequestOptionFunc) (*bytes.Reader, *Response, error) + // ListProjectForks gets a list of project forks. + // + // GitLab API docs: + // https://docs.gitlab.com/api/project_forks/#list-forks-of-a-project ListProjectForks(pid any, opt *ListProjectsOptions, options ...RequestOptionFunc) ([]*Project, *Response, error) + // GetProjectPushRules gets the push rules of a project. + // + // GitLab API docs: + // https://docs.gitlab.com/api/project_push_rules/#get-project-push-rules GetProjectPushRules(pid any, options ...RequestOptionFunc) (*ProjectPushRules, *Response, error) + // AddProjectPushRule adds a push rule to a specified project. + // + // GitLab API docs: + // https://docs.gitlab.com/api/project_push_rules/#add-a-project-push-rule AddProjectPushRule(pid any, opt *AddProjectPushRuleOptions, options ...RequestOptionFunc) (*ProjectPushRules, *Response, error) + // EditProjectPushRule edits a push rule for a specified project. + // + // GitLab API docs: + // https://docs.gitlab.com/api/project_push_rules/#edit-project-push-rule EditProjectPushRule(pid any, opt *EditProjectPushRuleOptions, options ...RequestOptionFunc) (*ProjectPushRules, *Response, error) + // DeleteProjectPushRule removes a push rule from a project. This is an + // idempotent method and can be called multiple times. Either the push rule is + // available or not. + // + // GitLab API docs: + // https://docs.gitlab.com/api/project_push_rules/#delete-project-push-rule DeleteProjectPushRule(pid any, options ...RequestOptionFunc) (*Response, error) + // GetApprovalConfiguration get the approval configuration for a project. + // + // GitLab API docs: + // https://docs.gitlab.com/api/merge_request_approvals/#project-approval-rules GetApprovalConfiguration(pid any, options ...RequestOptionFunc) (*ProjectApprovals, *Response, error) + // ChangeApprovalConfiguration updates the approval configuration for a project. + // + // GitLab API docs: + // https://docs.gitlab.com/api/merge_request_approvals/#change-configuration ChangeApprovalConfiguration(pid any, opt *ChangeApprovalConfigurationOptions, options ...RequestOptionFunc) (*ProjectApprovals, *Response, error) + // GetProjectApprovalRules looks up the list of project level approver rules. + // + // GitLab API docs: + // https://docs.gitlab.com/api/merge_request_approvals/#get-all-approval-rules-for-project GetProjectApprovalRules(pid any, opt *GetProjectApprovalRulesListsOptions, options ...RequestOptionFunc) ([]*ProjectApprovalRule, *Response, error) + // GetProjectApprovalRule gets the project level approvers. + // + // GitLab API docs: + // https://docs.gitlab.com/api/merge_request_approvals/#get-single-approval-rule-for-project GetProjectApprovalRule(pid any, ruleID int64, options ...RequestOptionFunc) (*ProjectApprovalRule, *Response, error) + // CreateProjectApprovalRule creates a new project-level approval rule. + // + // GitLab API docs: + // https://docs.gitlab.com/api/merge_request_approvals/#create-project-approval-rule CreateProjectApprovalRule(pid any, opt *CreateProjectLevelRuleOptions, options ...RequestOptionFunc) (*ProjectApprovalRule, *Response, error) + // UpdateProjectApprovalRule updates an existing approval rule with new options. + // + // GitLab API docs: + // https://docs.gitlab.com/api/merge_request_approvals/#update-project-approval-rule UpdateProjectApprovalRule(pid any, approvalRule int64, opt *UpdateProjectLevelRuleOptions, options ...RequestOptionFunc) (*ProjectApprovalRule, *Response, error) + // DeleteProjectApprovalRule deletes a project-level approval rule. + // + // GitLab API docs: + // https://docs.gitlab.com/api/merge_request_approvals/#delete-project-approval-rule DeleteProjectApprovalRule(pid any, approvalRule int64, options ...RequestOptionFunc) (*Response, error) + // GetProjectPullMirrorDetails returns the pull mirror details. + // + // GitLab API docs: + // https://docs.gitlab.com/api/project_pull_mirroring/#get-a-projects-pull-mirror-details GetProjectPullMirrorDetails(pid any, options ...RequestOptionFunc) (*ProjectPullMirrorDetails, *Response, error) + // ConfigureProjectPullMirror configures pull mirroring settings. + // + // GitLab API docs: + // https://docs.gitlab.com/api/project_pull_mirroring/#configure-pull-mirroring-for-a-project ConfigureProjectPullMirror(pid any, opt *ConfigureProjectPullMirrorOptions, options ...RequestOptionFunc) (*ProjectPullMirrorDetails, *Response, error) + // StartMirroringProject start the pull mirroring process for a project. + // + // GitLab API docs: + // https://docs.gitlab.com/api/project_pull_mirroring/#start-the-pull-mirroring-process-for-a-project StartMirroringProject(pid any, options ...RequestOptionFunc) (*Response, error) + // TransferProject transfer a project into the specified namespace + // + // GitLab API docs: https://docs.gitlab.com/api/projects/#transfer-a-project-to-a-new-namespace TransferProject(pid any, opt *TransferProjectOptions, options ...RequestOptionFunc) (*Project, *Response, error) + // StartHousekeepingProject start the Housekeeping task for a project. + // + // GitLab API docs: + // https://docs.gitlab.com/api/projects/#start-the-housekeeping-task-for-a-project StartHousekeepingProject(pid any, options ...RequestOptionFunc) (*Response, error) + // GetRepositoryStorage Get the path to repository storage. + // + // GitLab API docs: + // https://docs.gitlab.com/api/projects/#get-the-path-to-repository-storage GetRepositoryStorage(pid any, options ...RequestOptionFunc) (*ProjectRepositoryStorage, *Response, error) + // ListProjectStarrers gets users who starred a project. + // + // GitLab API docs: + // https://docs.gitlab.com/api/project_starring/#list-users-who-starred-a-project ListProjectStarrers(pid any, opts *ListProjectStarrersOptions, options ...RequestOptionFunc) ([]*ProjectStarrer, *Response, error) } @@ -150,6 +383,7 @@ type Project struct { PreventMergeWithoutJiraIssue bool `json:"prevent_merge_without_jira_issue"` PrintingMergeRequestLinkEnabled bool `json:"printing_merge_request_link_enabled"` LFSEnabled bool `json:"lfs_enabled"` + MaxArtifactsSize int64 `json:"max_artifacts_size"` RepositoryStorage string `json:"repository_storage"` RequestAccessEnabled bool `json:"request_access_enabled"` MergeMethod MergeMethodValue `json:"merge_method"` @@ -262,10 +496,11 @@ type Project struct { // // GitLab API docs: https://docs.gitlab.com/api/projects/ type ProjectSharedWithGroup struct { - GroupID int64 `json:"group_id"` - GroupName string `json:"group_name"` - GroupFullPath string `json:"group_full_path"` - GroupAccessLevel int64 `json:"group_access_level"` + GroupID int64 `json:"group_id"` + GroupName string `json:"group_name"` + GroupFullPath string `json:"group_full_path"` + GroupAccessLevel int64 `json:"group_access_level"` + ExpiresAt *ISOTime `json:"expires_at"` } // BasicProject included in other service responses (such as todos). @@ -451,97 +686,44 @@ type ListProjectsOptions struct { WithProgrammingLanguage *string `url:"with_programming_language,omitempty" json:"with_programming_language,omitempty"` } -// ListProjects gets a list of projects accessible by the authenticated user. -// -// GitLab API docs: https://docs.gitlab.com/api/projects/#list-all-projects func (s *ProjectsService) ListProjects(opt *ListProjectsOptions, options ...RequestOptionFunc) ([]*Project, *Response, error) { - req, err := s.client.NewRequest(http.MethodGet, "projects", opt, options) - if err != nil { - return nil, nil, err - } - - var p []*Project - resp, err := s.client.Do(req, &p) - if err != nil { - return nil, resp, err - } - - return p, resp, nil + return do[[]*Project](s.client, + withPath("projects"), + withAPIOpts(opt), + withRequestOpts(options...), + ) } -// ListUserProjects gets a list of projects for the given user. -// -// GitLab API docs: -// https://docs.gitlab.com/api/projects/#list-a-users-projects func (s *ProjectsService) ListUserProjects(uid any, opt *ListProjectsOptions, options ...RequestOptionFunc) ([]*Project, *Response, error) { - user, err := parseID(uid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("users/%s/projects", user) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var p []*Project - resp, err := s.client.Do(req, &p) - if err != nil { - return nil, resp, err - } - - return p, resp, nil + return do[[]*Project](s.client, + withPath("users/%s/projects", UserID{uid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } -// ListUserContributedProjects gets a list of visible projects a given user has contributed to. +// ListUserContributedProjects gets a list of visible projects a given user has +// contributed to. +// +// uid can be either a user ID (int) or a username (string). If a username +// is provided with a leading "@" (e.g., "@johndoe"), it will be trimmed. // // GitLab API docs: // https://docs.gitlab.com/api/projects/#list-projects-a-user-has-contributed-to func (s *ProjectsService) ListUserContributedProjects(uid any, opt *ListProjectsOptions, options ...RequestOptionFunc) ([]*Project, *Response, error) { - user, err := parseID(uid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("users/%s/contributed_projects", user) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var p []*Project - resp, err := s.client.Do(req, &p) - if err != nil { - return nil, resp, err - } - - return p, resp, nil + return do[[]*Project](s.client, + withPath("users/%s/contributed_projects", UserID{uid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } -// ListUserStarredProjects gets a list of projects starred by the given user. -// -// GitLab API docs: -// https://docs.gitlab.com/api/project_starring/#list-projects-starred-by-a-user func (s *ProjectsService) ListUserStarredProjects(uid any, opt *ListProjectsOptions, options ...RequestOptionFunc) ([]*Project, *Response, error) { - user, err := parseID(uid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("users/%s/starred_projects", user) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var p []*Project - resp, err := s.client.Do(req, &p) - if err != nil { - return nil, resp, err - } - - return p, resp, nil + return do[[]*Project](s.client, + withPath("users/%s/starred_projects", UserID{uid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // ProjectUser represents a GitLab project user. @@ -562,29 +744,12 @@ type ListProjectUserOptions struct { Search *string `url:"search,omitempty" json:"search,omitempty"` } -// ListProjectsUsers gets a list of users for the given project. -// -// GitLab API docs: -// https://docs.gitlab.com/api/projects/#list-users func (s *ProjectsService) ListProjectsUsers(pid any, opt *ListProjectUserOptions, options ...RequestOptionFunc) ([]*ProjectUser, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/users", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var p []*ProjectUser - resp, err := s.client.Do(req, &p) - if err != nil { - return nil, resp, err - } - - return p, resp, nil + return do[[]*ProjectUser](s.client, + withPath("projects/%s/users", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // ProjectGroup represents a GitLab project group. @@ -610,29 +775,12 @@ type ListProjectGroupOptions struct { WithShared *bool `url:"with_shared,omitempty" json:"with_shared,omitempty"` } -// ListProjectsGroups gets a list of groups for the given project. -// -// GitLab API docs: -// https://docs.gitlab.com/api/projects/#list-groups func (s *ProjectsService) ListProjectsGroups(pid any, opt *ListProjectGroupOptions, options ...RequestOptionFunc) ([]*ProjectGroup, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/groups", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var p []*ProjectGroup - resp, err := s.client.Do(req, &p) - if err != nil { - return nil, resp, err - } - - return p, resp, nil + return do[[]*ProjectGroup](s.client, + withPath("projects/%s/groups", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // ProjectLanguages is a map of strings because the response is arbitrary @@ -641,29 +789,11 @@ func (s *ProjectsService) ListProjectsGroups(pid any, opt *ListProjectGroupOptio // https://docs.gitlab.com/api/projects/#list-programming-languages-used type ProjectLanguages map[string]float32 -// GetProjectLanguages gets a list of languages used by the project -// -// GitLab API docs: -// https://docs.gitlab.com/api/projects/#list-programming-languages-used func (s *ProjectsService) GetProjectLanguages(pid any, options ...RequestOptionFunc) (*ProjectLanguages, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/languages", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - p := new(ProjectLanguages) - resp, err := s.client.Do(req, p) - if err != nil { - return nil, resp, err - } - - return p, resp, nil + return do[*ProjectLanguages](s.client, + withPath("projects/%s/languages", ProjectID{pid}), + withRequestOpts(options...), + ) } // GetProjectOptions represents the available GetProject() options. @@ -675,30 +805,12 @@ type GetProjectOptions struct { WithCustomAttributes *bool `url:"with_custom_attributes,omitempty" json:"with_custom_attributes,omitempty"` } -// GetProject gets a specific project, identified by project ID or -// NAMESPACE/PROJECT_NAME, which is owned by the authenticated user. -// -// GitLab API docs: -// https://docs.gitlab.com/api/projects/#get-a-single-project func (s *ProjectsService) GetProject(pid any, opt *GetProjectOptions, options ...RequestOptionFunc) (*Project, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - p := new(Project) - resp, err := s.client.Do(req, p) - if err != nil { - return nil, resp, err - } - - return p, resp, nil + return do[*Project](s.client, + withPath("projects/%s", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // CreateProjectOptions represents the available CreateProject() options. @@ -841,9 +953,6 @@ func (a *ProjectAvatar) MarshalJSON() ([]byte, error) { return json.Marshal((*alias)(a)) } -// CreateProject creates a new project owned by the authenticated user. -// -// GitLab API docs: https://docs.gitlab.com/api/projects/#create-a-project func (s *ProjectsService) CreateProject(opt *CreateProjectOptions, options ...RequestOptionFunc) (*Project, *Response, error) { if opt.ContainerExpirationPolicyAttributes != nil { // This is needed to satisfy the API. Should be deleted @@ -851,33 +960,16 @@ func (s *ProjectsService) CreateProject(opt *CreateProjectOptions, options ...Re opt.ContainerExpirationPolicyAttributes.NameRegex = opt.ContainerExpirationPolicyAttributes.NameRegexDelete } - var err error - var req *retryablehttp.Request - - if opt.Avatar == nil { - req, err = s.client.NewRequest(http.MethodPost, "projects", opt, options) - } else { - req, err = s.client.UploadRequest( - http.MethodPost, - "projects", - opt.Avatar.Image, - opt.Avatar.Filename, - UploadAvatar, - opt, - options, - ) + reqOpts := []doOption{ + withMethod(http.MethodPost), + withPath("projects"), + withAPIOpts(opt), + withRequestOpts(options...), } - if err != nil { - return nil, nil, err - } - - p := new(Project) - resp, err := s.client.Do(req, p) - if err != nil { - return nil, resp, err + if opt.Avatar != nil { + reqOpts = append(reqOpts, withUpload(opt.Avatar.Image, opt.Avatar.Filename, UploadAvatar)) } - - return p, resp, nil + return do[*Project](s.client, reqOpts...) } // CreateProjectForUserOptions represents the available CreateProjectForUser() @@ -887,11 +979,6 @@ func (s *ProjectsService) CreateProject(opt *CreateProjectOptions, options ...Re // https://docs.gitlab.com/api/projects/#create-a-project-for-a-user type CreateProjectForUserOptions CreateProjectOptions -// CreateProjectForUser creates a new project owned by the specified user. -// Available only for admins. -// -// GitLab API docs: -// https://docs.gitlab.com/api/projects/#create-a-project-for-a-user func (s *ProjectsService) CreateProjectForUser(user int64, opt *CreateProjectForUserOptions, options ...RequestOptionFunc) (*Project, *Response, error) { if opt.ContainerExpirationPolicyAttributes != nil { // This is needed to satisfy the API. Should be deleted @@ -899,34 +986,16 @@ func (s *ProjectsService) CreateProjectForUser(user int64, opt *CreateProjectFor opt.ContainerExpirationPolicyAttributes.NameRegex = opt.ContainerExpirationPolicyAttributes.NameRegexDelete } - var err error - var req *retryablehttp.Request - u := fmt.Sprintf("projects/user/%d", user) - - if opt.Avatar == nil { - req, err = s.client.NewRequest(http.MethodPost, u, opt, options) - } else { - req, err = s.client.UploadRequest( - http.MethodPost, - u, - opt.Avatar.Image, - opt.Avatar.Filename, - UploadAvatar, - opt, - options, - ) - } - if err != nil { - return nil, nil, err + reqOpts := []doOption{ + withMethod(http.MethodPost), + withPath("projects/user/%d", user), + withAPIOpts(opt), + withRequestOpts(options...), } - - p := new(Project) - resp, err := s.client.Do(req, p) - if err != nil { - return nil, resp, err + if opt.Avatar != nil { + reqOpts = append(reqOpts, withUpload(opt.Avatar.Image, opt.Avatar.Filename, UploadAvatar)) } - - return p, resp, nil + return do[*Project](s.client, reqOpts...) } // EditProjectOptions represents the available EditProject() options. @@ -971,6 +1040,7 @@ type EditProjectOptions struct { IssuesTemplate *string `url:"issues_template,omitempty" json:"issues_template,omitempty"` KeepLatestArtifact *bool `url:"keep_latest_artifact,omitempty" json:"keep_latest_artifact,omitempty"` LFSEnabled *bool `url:"lfs_enabled,omitempty" json:"lfs_enabled,omitempty"` + MaxArtifactsSize *int64 `url:"max_artifacts_size,omitempty" json:"max_artifacts_size,omitempty"` MergeCommitTemplate *string `url:"merge_commit_template,omitempty" json:"merge_commit_template,omitempty"` MergeRequestDefaultTargetSelf *bool `url:"mr_default_target_self,omitempty" json:"mr_default_target_self,omitempty"` MergeMethod *MergeMethodValue `url:"merge_method,omitempty" json:"merge_method,omitempty"` @@ -1046,9 +1116,6 @@ type EditProjectOptions struct { WikiEnabled *bool `url:"wiki_enabled,omitempty" json:"wiki_enabled,omitempty"` } -// EditProject updates an existing project. -// -// GitLab API docs: https://docs.gitlab.com/api/projects/#edit-a-project func (s *ProjectsService) EditProject(pid any, opt *EditProjectOptions, options ...RequestOptionFunc) (*Project, *Response, error) { if opt.ContainerExpirationPolicyAttributes != nil { // This is needed to satisfy the API. Should be deleted @@ -1056,38 +1123,16 @@ func (s *ProjectsService) EditProject(pid any, opt *EditProjectOptions, options opt.ContainerExpirationPolicyAttributes.NameRegex = opt.ContainerExpirationPolicyAttributes.NameRegexDelete } - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s", PathEscape(project)) - - var req *retryablehttp.Request - - if opt.Avatar == nil || (opt.Avatar.Filename == "" && opt.Avatar.Image == nil) { - req, err = s.client.NewRequest(http.MethodPut, u, opt, options) - } else { - req, err = s.client.UploadRequest( - http.MethodPut, - u, - opt.Avatar.Image, - opt.Avatar.Filename, - UploadAvatar, - opt, - options, - ) - } - if err != nil { - return nil, nil, err + reqOpts := []doOption{ + withMethod(http.MethodPut), + withPath("projects/%s", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), } - - p := new(Project) - resp, err := s.client.Do(req, p) - if err != nil { - return nil, resp, err + if opt.Avatar != nil && (opt.Avatar.Filename != "" || opt.Avatar.Image != nil) { + reqOpts = append(reqOpts, withUpload(opt.Avatar.Image, opt.Avatar.Filename, UploadAvatar)) } - - return p, resp, nil + return do[*Project](s.client, reqOpts...) } // ForkProjectOptions represents the available ForkProject() options. @@ -1108,55 +1153,21 @@ type ForkProjectOptions struct { Namespace *string `url:"namespace,omitempty" json:"namespace,omitempty"` } -// ForkProject forks a project into the user namespace of the authenticated -// user. -// -// GitLab API docs: -// https://docs.gitlab.com/api/project_forks/#fork-a-project func (s *ProjectsService) ForkProject(pid any, opt *ForkProjectOptions, options ...RequestOptionFunc) (*Project, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/fork", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - p := new(Project) - resp, err := s.client.Do(req, p) - if err != nil { - return nil, resp, err - } - - return p, resp, nil + return do[*Project](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/fork", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } -// StarProject stars a given the project. -// -// GitLab API docs: -// https://docs.gitlab.com/api/project_starring/#star-a-project func (s *ProjectsService) StarProject(pid any, options ...RequestOptionFunc) (*Project, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/star", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPost, u, nil, options) - if err != nil { - return nil, nil, err - } - - p := new(Project) - resp, err := s.client.Do(req, p) - if err != nil { - return nil, resp, err - } - - return p, resp, nil + return do[*Project](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/star", ProjectID{pid}), + withRequestOpts(options...), + ) } // ListProjectInvitedGroupOptions represents the available @@ -1172,131 +1183,44 @@ type ListProjectInvitedGroupOptions struct { WithCustomAttributes *bool `url:"with_custom_attributes,omitempty" json:"with_custom_attributes,omitempty"` } -// ListProjectsInvitedGroups lists invited groups of a project -// -// GitLab API docs: -// https://docs.gitlab.com/api/projects/#list-a-projects-invited-groups func (s *ProjectsService) ListProjectsInvitedGroups(pid any, opt *ListProjectInvitedGroupOptions, options ...RequestOptionFunc) ([]*ProjectGroup, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/invited_groups", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var pg []*ProjectGroup - resp, err := s.client.Do(req, &pg) - if err != nil { - return nil, resp, err - } - - return pg, resp, nil + return do[[]*ProjectGroup](s.client, + withPath("projects/%s/invited_groups", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } -// UnstarProject unstars a given project. -// -// GitLab API docs: -// https://docs.gitlab.com/api/project_starring/#unstar-a-project func (s *ProjectsService) UnstarProject(pid any, options ...RequestOptionFunc) (*Project, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/unstar", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPost, u, nil, options) - if err != nil { - return nil, nil, err - } - - p := new(Project) - resp, err := s.client.Do(req, p) - if err != nil { - return nil, resp, err - } - - return p, resp, nil + return do[*Project](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/unstar", ProjectID{pid}), + withRequestOpts(options...), + ) } -// ArchiveProject archives the project if the user is either admin or the -// project owner of this project. -// -// GitLab API docs: -// https://docs.gitlab.com/api/projects/#archive-a-project func (s *ProjectsService) ArchiveProject(pid any, options ...RequestOptionFunc) (*Project, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/archive", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPost, u, nil, options) - if err != nil { - return nil, nil, err - } - - p := new(Project) - resp, err := s.client.Do(req, p) - if err != nil { - return nil, resp, err - } - - return p, resp, nil + return do[*Project](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/archive", ProjectID{pid}), + withRequestOpts(options...), + ) } -// UnarchiveProject unarchives the project if the user is either admin or -// the project owner of this project. -// -// GitLab API docs: -// https://docs.gitlab.com/api/projects/#unarchive-a-project func (s *ProjectsService) UnarchiveProject(pid any, options ...RequestOptionFunc) (*Project, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/unarchive", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPost, u, nil, options) - if err != nil { - return nil, nil, err - } - - p := new(Project) - resp, err := s.client.Do(req, p) - if err != nil { - return nil, resp, err - } - - return p, resp, nil + return do[*Project](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/unarchive", ProjectID{pid}), + withRequestOpts(options...), + ) } -// RestoreProject restores a project that is marked for deletion. -// -// GitLab API docs: -// https://docs.gitlab.com/api/projects/#restore-a-project-marked-for-deletion func (s *ProjectsService) RestoreProject(pid any, options ...RequestOptionFunc) (*Project, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/restore", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPost, u, nil, options) - if err != nil { - return nil, nil, err - } - - p := new(Project) - resp, err := s.client.Do(req, p) - if err != nil { - return nil, resp, err - } - - return p, resp, nil + return do[*Project](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/restore", ProjectID{pid}), + withRequestOpts(options...), + ) } // DeleteProjectOptions represents the available DeleteProject() options. @@ -1308,24 +1232,14 @@ type DeleteProjectOptions struct { PermanentlyRemove *bool `url:"permanently_remove" json:"permanently_remove"` } -// DeleteProject removes a project including all associated resources -// (issues, merge requests etc.) -// -// GitLab API docs: -// https://docs.gitlab.com/api/projects/#delete-a-project func (s *ProjectsService) DeleteProject(pid any, opt *DeleteProjectOptions, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodDelete, u, opt, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) + return resp, err } // ShareWithGroupOptions represents the available SharedWithGroup() options. @@ -1337,41 +1251,23 @@ type ShareWithGroupOptions struct { GroupID *int64 `url:"group_id" json:"group_id"` } -// ShareProjectWithGroup allows to share a project with a group. -// -// GitLab API docs: https://docs.gitlab.com/api/projects/#share-a-project-with-a-group func (s *ProjectsService) ShareProjectWithGroup(pid any, opt *ShareWithGroupOptions, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/share", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/share", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) + return resp, err } -// DeleteSharedProjectFromGroup allows to unshare a project from a group. -// -// GitLab API docs: -// https://docs.gitlab.com/api/projects/#delete-a-shared-project-link-in-a-group func (s *ProjectsService) DeleteSharedProjectFromGroup(pid any, groupID int64, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/share/%d", PathEscape(project), groupID) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/share/%d", ProjectID{pid}, groupID), + withRequestOpts(options...), + ) + return resp, err } // HookCustomHeader represents a project or group hook custom header @@ -1414,6 +1310,7 @@ type ProjectHook struct { ReleasesEvents bool `json:"releases_events"` MilestoneEvents bool `json:"milestone_events"` FeatureFlagEvents bool `json:"feature_flag_events"` + EmojiEvents bool `json:"emoji_events"` EnableSSLVerification bool `json:"enable_ssl_verification"` RepositoryUpdateEvents bool `json:"repository_update_events"` AlertStatus string `json:"alert_status"` @@ -1423,6 +1320,8 @@ type ProjectHook struct { ResourceAccessTokenEvents bool `json:"resource_access_token_events"` CustomWebhookTemplate string `json:"custom_webhook_template"` CustomHeaders []*HookCustomHeader `json:"custom_headers"` + VulnerabilityEvents bool `json:"vulnerability_events"` + BranchFilterStrategy string `json:"branch_filter_strategy"` } // ListProjectHooksOptions represents the available ListProjectHooks() options. @@ -1433,54 +1332,19 @@ type ListProjectHooksOptions struct { ListOptions } -// ListProjectHooks gets a list of project hooks. -// -// GitLab API docs: -// https://docs.gitlab.com/api/project_webhooks/#list-webhooks-for-a-project func (s *ProjectsService) ListProjectHooks(pid any, opt *ListProjectHooksOptions, options ...RequestOptionFunc) ([]*ProjectHook, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/hooks", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var ph []*ProjectHook - resp, err := s.client.Do(req, &ph) - if err != nil { - return nil, resp, err - } - - return ph, resp, nil + return do[[]*ProjectHook](s.client, + withPath("projects/%s/hooks", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } -// GetProjectHook gets a specific hook for a project. -// -// GitLab API docs: -// https://docs.gitlab.com/api/project_webhooks/#get-a-project-webhook func (s *ProjectsService) GetProjectHook(pid any, hook int64, options ...RequestOptionFunc) (*ProjectHook, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/hooks/%d", PathEscape(project), hook) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - ph := new(ProjectHook) - resp, err := s.client.Do(req, ph) - if err != nil { - return nil, resp, err - } - - return ph, resp, nil + return do[*ProjectHook](s.client, + withPath("projects/%s/hooks/%d", ProjectID{pid}, hook), + withRequestOpts(options...), + ) } // AddProjectHookOptions represents the available AddProjectHook() options. @@ -1502,6 +1366,7 @@ type AddProjectHookOptions struct { PushEvents *bool `url:"push_events,omitempty" json:"push_events,omitempty"` PushEventsBranchFilter *string `url:"push_events_branch_filter,omitempty" json:"push_events_branch_filter,omitempty"` ReleasesEvents *bool `url:"releases_events,omitempty" json:"releases_events,omitempty"` + EmojiEvents *bool `url:"emoji_events,omitempty" json:"emoji_events,omitempty"` TagPushEvents *bool `url:"tag_push_events,omitempty" json:"tag_push_events,omitempty"` Token *string `url:"token,omitempty" json:"token,omitempty"` URL *string `url:"url,omitempty" json:"url,omitempty"` @@ -1509,31 +1374,17 @@ type AddProjectHookOptions struct { ResourceAccessTokenEvents *bool `url:"resource_access_token_events,omitempty" json:"resource_access_token_events,omitempty"` CustomWebhookTemplate *string `url:"custom_webhook_template,omitempty" json:"custom_webhook_template,omitempty"` CustomHeaders *[]*HookCustomHeader `url:"custom_headers,omitempty" json:"custom_headers,omitempty"` + VulnerabilityEvents *bool `url:"vulnerability_events,omitempty" json:"vulnerability_events,omitempty"` + BranchFilterStrategy *string `url:"branch_filter_strategy,omitempty" json:"branch_filter_strategy,omitempty"` } -// AddProjectHook adds a hook to a specified project. -// -// GitLab API docs: -// https://docs.gitlab.com/api/project_webhooks/#add-a-webhook-to-a-project func (s *ProjectsService) AddProjectHook(pid any, opt *AddProjectHookOptions, options ...RequestOptionFunc) (*ProjectHook, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/hooks", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - ph := new(ProjectHook) - resp, err := s.client.Do(req, ph) - if err != nil { - return nil, resp, err - } - - return ph, resp, nil + return do[*ProjectHook](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/hooks", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // EditProjectHookOptions represents the available EditProjectHook() options. @@ -1555,6 +1406,7 @@ type EditProjectHookOptions struct { PushEvents *bool `url:"push_events,omitempty" json:"push_events,omitempty"` PushEventsBranchFilter *string `url:"push_events_branch_filter,omitempty" json:"push_events_branch_filter,omitempty"` ReleasesEvents *bool `url:"releases_events,omitempty" json:"releases_events,omitempty"` + EmojiEvents *bool `url:"emoji_events,omitempty" json:"emoji_events,omitempty"` TagPushEvents *bool `url:"tag_push_events,omitempty" json:"tag_push_events,omitempty"` Token *string `url:"token,omitempty" json:"token,omitempty"` URL *string `url:"url,omitempty" json:"url,omitempty"` @@ -1562,51 +1414,26 @@ type EditProjectHookOptions struct { ResourceAccessTokenEvents *bool `url:"resource_access_token_events,omitempty" json:"resource_access_token_events,omitempty"` CustomWebhookTemplate *string `url:"custom_webhook_template,omitempty" json:"custom_webhook_template,omitempty"` CustomHeaders *[]*HookCustomHeader `url:"custom_headers,omitempty" json:"custom_headers,omitempty"` + VulnerabilityEvents *bool `url:"vulnerability_events,omitempty" json:"vulnerability_events,omitempty"` + BranchFilterStrategy *string `url:"branch_filter_strategy,omitempty" json:"branch_filter_strategy,omitempty"` } -// EditProjectHook edits a hook for a specified project. -// -// GitLab API docs: -// https://docs.gitlab.com/api/project_webhooks/#edit-a-project-webhook func (s *ProjectsService) EditProjectHook(pid any, hook int64, opt *EditProjectHookOptions, options ...RequestOptionFunc) (*ProjectHook, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/hooks/%d", PathEscape(project), hook) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - ph := new(ProjectHook) - resp, err := s.client.Do(req, ph) - if err != nil { - return nil, resp, err - } - - return ph, resp, nil + return do[*ProjectHook](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/hooks/%d", ProjectID{pid}, hook), + withAPIOpts(opt), + withRequestOpts(options...), + ) } -// DeleteProjectHook removes a hook from a project. This is an idempotent -// method and can be called multiple times. Either the hook is available or not. -// -// GitLab API docs: -// https://docs.gitlab.com/api/project_webhooks/#delete-project-webhook func (s *ProjectsService) DeleteProjectHook(pid any, hook int64, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/hooks/%d", PathEscape(project), hook) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/hooks/%d", ProjectID{pid}, hook), + withRequestOpts(options...), + ) + return resp, err } // TriggerTestProjectHook Trigger a test hook for a specified project. @@ -1622,18 +1449,12 @@ func (s *ProjectsService) DeleteProjectHook(pid any, hook int64, options ...Requ // GitLab API docs: // https://docs.gitlab.com/api/project_webhooks/#trigger-a-test-project-webhook func (s *ProjectsService) TriggerTestProjectHook(pid any, hook int64, event ProjectHookEvent, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/hooks/%d/test/%s", PathEscape(project), hook, string(event)) - - req, err := s.client.NewRequest(http.MethodPost, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/hooks/%d/test/%s", ProjectID{pid}, hook, string(event)), + withRequestOpts(options...), + ) + return resp, err } // SetHookCustomHeaderOptions represents the available SetProjectCustomHeader() @@ -1645,42 +1466,23 @@ type SetHookCustomHeaderOptions struct { Value *string `json:"value,omitempty"` } -// SetProjectCustomHeader creates or updates a project custom webhook header. -// -// GitLab API docs: -// https://docs.gitlab.com/api/project_webhooks/#set-a-custom-header func (s *ProjectsService) SetProjectCustomHeader(pid any, hook int64, key string, opt *SetHookCustomHeaderOptions, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/hooks/%d/custom_headers/%s", PathEscape(project), hook, key) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/hooks/%d/custom_headers/%s", ProjectID{pid}, hook, key), + withAPIOpts(opt), + withRequestOpts(options...), + ) + return resp, err } -// DeleteProjectCustomHeader deletes a project custom webhook header. -// -// GitLab API docs: -// https://docs.gitlab.com/api/project_webhooks/#delete-a-custom-header func (s *ProjectsService) DeleteProjectCustomHeader(pid any, hook int64, key string, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/hooks/%d/custom_headers/%s", PathEscape(project), hook, key) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/hooks/%d/custom_headers/%s", ProjectID{pid}, hook, key), + withRequestOpts(options...), + ) + return resp, err } // SetProjectWebhookURLVariableOptions represents the available @@ -1692,42 +1494,23 @@ type SetProjectWebhookURLVariableOptions struct { Value *string `json:"value,omitempty"` } -// SetProjectWebhookURLVariable creates or updates a project webhook URL variable. -// -// GitLab API docs: -// https://docs.gitlab.com/api/project_webhooks/#set-a-url-variable func (s *ProjectsService) SetProjectWebhookURLVariable(pid any, hook int64, key string, opt *SetProjectWebhookURLVariableOptions, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/hooks/%d/url_variables/%s", PathEscape(project), hook, PathEscape(key)) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/hooks/%d/url_variables/%s", ProjectID{pid}, hook, key), + withAPIOpts(opt), + withRequestOpts(options...), + ) + return resp, err } -// DeleteProjectWebhookURLVariable deletes a project webhook URL variable. -// -// GitLab API docs: -// https://docs.gitlab.com/api/project_webhooks/#delete-a-url-variable func (s *ProjectsService) DeleteProjectWebhookURLVariable(pid any, hook int64, key string, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/hooks/%d/url_variables/%s", PathEscape(project), hook, PathEscape(key)) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/hooks/%d/url_variables/%s", ProjectID{pid}, hook, key), + withRequestOpts(options...), + ) + return resp, err } // ProjectForkRelation represents a project fork relationship. @@ -1742,132 +1525,49 @@ type ProjectForkRelation struct { UpdatedAt *time.Time `json:"updated_at"` } -// CreateProjectForkRelation creates a forked from/to relation between -// existing projects. -// -// GitLab API docs: -// https://docs.gitlab.com/api/project_forks/#create-a-fork-relationship-between-projects func (s *ProjectsService) CreateProjectForkRelation(pid any, fork int64, options ...RequestOptionFunc) (*ProjectForkRelation, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/fork/%d", PathEscape(project), fork) - - req, err := s.client.NewRequest(http.MethodPost, u, nil, options) - if err != nil { - return nil, nil, err - } - - pfr := new(ProjectForkRelation) - resp, err := s.client.Do(req, pfr) - if err != nil { - return nil, resp, err - } - - return pfr, resp, nil + return do[*ProjectForkRelation](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/fork/%d", ProjectID{pid}, fork), + withRequestOpts(options...), + ) } -// DeleteProjectForkRelation deletes an existing forked from relationship. -// -// GitLab API docs: -// https://docs.gitlab.com/api/project_forks/#delete-a-fork-relationship-between-projects func (s *ProjectsService) DeleteProjectForkRelation(pid any, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/fork", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/fork", ProjectID{pid}), + withRequestOpts(options...), + ) + return resp, err } -// UploadAvatar uploads an avatar. -// -// GitLab API docs: -// https://docs.gitlab.com/api/projects/#upload-a-project-avatar func (s *ProjectsService) UploadAvatar(pid any, avatar io.Reader, filename string, options ...RequestOptionFunc) (*Project, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s", PathEscape(project)) - - req, err := s.client.UploadRequest( - http.MethodPut, - u, - avatar, - filename, - UploadAvatar, - nil, - options, + return do[*Project](s.client, + withMethod(http.MethodPut), + withPath("projects/%s", ProjectID{pid}), + withUpload(avatar, filename, UploadAvatar), + withRequestOpts(options...), ) - if err != nil { - return nil, nil, err - } - - p := new(Project) - resp, err := s.client.Do(req, p) - if err != nil { - return nil, resp, err - } - - return p, resp, nil } -// DownloadAvatar downloads an avatar. -// -// GitLab API docs: -// https://docs.gitlab.com/api/projects/#download-a-project-avatar func (s *ProjectsService) DownloadAvatar(pid any, options ...RequestOptionFunc) (*bytes.Reader, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/avatar", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - avatar := new(bytes.Buffer) - resp, err := s.client.Do(req, avatar) + buf, resp, err := do[bytes.Buffer](s.client, + withPath("projects/%s/avatar", ProjectID{pid}), + withRequestOpts(options...), + ) if err != nil { return nil, resp, err } - - return bytes.NewReader(avatar.Bytes()), resp, err + return bytes.NewReader(buf.Bytes()), resp, nil } -// ListProjectForks gets a list of project forks. -// -// GitLab API docs: -// https://docs.gitlab.com/api/project_forks/#list-forks-of-a-project func (s *ProjectsService) ListProjectForks(pid any, opt *ListProjectsOptions, options ...RequestOptionFunc) ([]*Project, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/forks", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var forks []*Project - resp, err := s.client.Do(req, &forks) - if err != nil { - return nil, resp, err - } - - return forks, resp, nil + return do[[]*Project](s.client, + withPath("projects/%s/forks", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // ProjectPushRules represents a project push rule. @@ -1893,29 +1593,11 @@ type ProjectPushRules struct { RejectNonDCOCommits bool `json:"reject_non_dco_commits"` } -// GetProjectPushRules gets the push rules of a project. -// -// GitLab API docs: -// https://docs.gitlab.com/api/project_push_rules/#get-project-push-rules func (s *ProjectsService) GetProjectPushRules(pid any, options ...RequestOptionFunc) (*ProjectPushRules, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/push_rule", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - ppr := new(ProjectPushRules) - resp, err := s.client.Do(req, ppr) - if err != nil { - return nil, resp, err - } - - return ppr, resp, nil + return do[*ProjectPushRules](s.client, + withPath("projects/%s/push_rule", ProjectID{pid}), + withRequestOpts(options...), + ) } // AddProjectPushRuleOptions represents the available AddProjectPushRule() @@ -1939,29 +1621,13 @@ type AddProjectPushRuleOptions struct { RejectNonDCOCommits *bool `url:"reject_non_dco_commits,omitempty" json:"reject_non_dco_commits,omitempty"` } -// AddProjectPushRule adds a push rule to a specified project. -// -// GitLab API docs: -// https://docs.gitlab.com/api/project_push_rules/#add-a-project-push-rule func (s *ProjectsService) AddProjectPushRule(pid any, opt *AddProjectPushRuleOptions, options ...RequestOptionFunc) (*ProjectPushRules, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/push_rule", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - ppr := new(ProjectPushRules) - resp, err := s.client.Do(req, ppr) - if err != nil { - return nil, resp, err - } - - return ppr, resp, nil + return do[*ProjectPushRules](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/push_rule", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // EditProjectPushRuleOptions represents the available EditProjectPushRule() @@ -1985,50 +1651,22 @@ type EditProjectPushRuleOptions struct { RejectNonDCOCommits *bool `url:"reject_non_dco_commits,omitempty" json:"reject_non_dco_commits,omitempty"` } -// EditProjectPushRule edits a push rule for a specified project. -// -// GitLab API docs: -// https://docs.gitlab.com/api/project_push_rules/#edit-project-push-rule func (s *ProjectsService) EditProjectPushRule(pid any, opt *EditProjectPushRuleOptions, options ...RequestOptionFunc) (*ProjectPushRules, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/push_rule", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - ppr := new(ProjectPushRules) - resp, err := s.client.Do(req, ppr) - if err != nil { - return nil, resp, err - } - - return ppr, resp, nil + return do[*ProjectPushRules](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/push_rule", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } -// DeleteProjectPushRule removes a push rule from a project. This is an -// idempotent method and can be called multiple times. Either the push rule is -// available or not. -// -// GitLab API docs: -// https://docs.gitlab.com/api/project_push_rules/#delete-project-push-rule func (s *ProjectsService) DeleteProjectPushRule(pid any, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/push_rule", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/push_rule", ProjectID{pid}), + withRequestOpts(options...), + ) + return resp, err } // ProjectApprovals represents GitLab project level merge request approvals. @@ -2049,29 +1687,11 @@ type ProjectApprovals struct { ApprovalsBeforeMerge int64 `json:"approvals_before_merge"` } -// GetApprovalConfiguration get the approval configuration for a project. -// -// GitLab API docs: -// https://docs.gitlab.com/api/merge_request_approvals/#project-approval-rules func (s *ProjectsService) GetApprovalConfiguration(pid any, options ...RequestOptionFunc) (*ProjectApprovals, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/approvals", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - pa := new(ProjectApprovals) - resp, err := s.client.Do(req, pa) - if err != nil { - return nil, resp, err - } - - return pa, resp, nil + return do[*ProjectApprovals](s.client, + withPath("projects/%s/approvals", ProjectID{pid}), + withRequestOpts(options...), + ) } // ChangeApprovalConfigurationOptions represents the available @@ -2091,29 +1711,13 @@ type ChangeApprovalConfigurationOptions struct { ApprovalsBeforeMerge *int64 `url:"approvals_before_merge,omitempty" json:"approvals_before_merge,omitempty"` } -// ChangeApprovalConfiguration updates the approval configuration for a project. -// -// GitLab API docs: -// https://docs.gitlab.com/api/merge_request_approvals/#change-configuration func (s *ProjectsService) ChangeApprovalConfiguration(pid any, opt *ChangeApprovalConfigurationOptions, options ...RequestOptionFunc) (*ProjectApprovals, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/approvals", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - pa := new(ProjectApprovals) - resp, err := s.client.Do(req, pa) - if err != nil { - return nil, resp, err - } - - return pa, resp, nil + return do[*ProjectApprovals](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/approvals", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // GetProjectApprovalRulesListsOptions represents the available @@ -2125,54 +1729,19 @@ type GetProjectApprovalRulesListsOptions struct { ListOptions } -// GetProjectApprovalRules looks up the list of project level approver rules. -// -// GitLab API docs: -// https://docs.gitlab.com/api/merge_request_approvals/#get-all-approval-rules-for-project func (s *ProjectsService) GetProjectApprovalRules(pid any, opt *GetProjectApprovalRulesListsOptions, options ...RequestOptionFunc) ([]*ProjectApprovalRule, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/approval_rules", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var par []*ProjectApprovalRule - resp, err := s.client.Do(req, &par) - if err != nil { - return nil, resp, err - } - - return par, resp, nil + return do[[]*ProjectApprovalRule](s.client, + withPath("projects/%s/approval_rules", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } -// GetProjectApprovalRule gets the project level approvers. -// -// GitLab API docs: -// https://docs.gitlab.com/api/merge_request_approvals/#get-single-approval-rule-for-project func (s *ProjectsService) GetProjectApprovalRule(pid any, ruleID int64, options ...RequestOptionFunc) (*ProjectApprovalRule, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/approval_rules/%d", PathEscape(project), ruleID) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - par := new(ProjectApprovalRule) - resp, err := s.client.Do(req, &par) - if err != nil { - return nil, resp, err - } - - return par, resp, nil + return do[*ProjectApprovalRule](s.client, + withPath("projects/%s/approval_rules/%d", ProjectID{pid}, ruleID), + withRequestOpts(options...), + ) } // CreateProjectLevelRuleOptions represents the available CreateProjectApprovalRule() @@ -2192,29 +1761,13 @@ type CreateProjectLevelRuleOptions struct { Usernames *[]string `url:"usernames,omitempty" json:"usernames,omitempty"` } -// CreateProjectApprovalRule creates a new project-level approval rule. -// -// GitLab API docs: -// https://docs.gitlab.com/api/merge_request_approvals/#create-project-approval-rule func (s *ProjectsService) CreateProjectApprovalRule(pid any, opt *CreateProjectLevelRuleOptions, options ...RequestOptionFunc) (*ProjectApprovalRule, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/approval_rules", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - par := new(ProjectApprovalRule) - resp, err := s.client.Do(req, &par) - if err != nil { - return nil, resp, err - } - - return par, resp, nil + return do[*ProjectApprovalRule](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/approval_rules", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // UpdateProjectLevelRuleOptions represents the available UpdateProjectApprovalRule() @@ -2232,48 +1785,22 @@ type UpdateProjectLevelRuleOptions struct { Usernames *[]string `url:"usernames,omitempty" json:"usernames,omitempty"` } -// UpdateProjectApprovalRule updates an existing approval rule with new options. -// -// GitLab API docs: -// https://docs.gitlab.com/api/merge_request_approvals/#update-project-approval-rule func (s *ProjectsService) UpdateProjectApprovalRule(pid any, approvalRule int64, opt *UpdateProjectLevelRuleOptions, options ...RequestOptionFunc) (*ProjectApprovalRule, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/approval_rules/%d", PathEscape(project), approvalRule) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - par := new(ProjectApprovalRule) - resp, err := s.client.Do(req, &par) - if err != nil { - return nil, resp, err - } - - return par, resp, nil + return do[*ProjectApprovalRule](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/approval_rules/%d", ProjectID{pid}, approvalRule), + withAPIOpts(opt), + withRequestOpts(options...), + ) } -// DeleteProjectApprovalRule deletes a project-level approval rule. -// -// GitLab API docs: -// https://docs.gitlab.com/api/merge_request_approvals/#delete-project-approval-rule func (s *ProjectsService) DeleteProjectApprovalRule(pid any, approvalRule int64, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/approval_rules/%d", PathEscape(project), approvalRule) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/approval_rules/%d", ProjectID{pid}, approvalRule), + withRequestOpts(options...), + ) + return resp, err } // ProjectPullMirrorDetails represent the details of the configuration pull @@ -2296,29 +1823,11 @@ type ProjectPullMirrorDetails struct { MirrorBranchRegex string `json:"mirror_branch_regex"` } -// GetProjectPullMirrorDetails returns the pull mirror details. -// -// GitLab API docs: -// https://docs.gitlab.com/api/project_pull_mirroring/#get-a-projects-pull-mirror-details func (s *ProjectsService) GetProjectPullMirrorDetails(pid any, options ...RequestOptionFunc) (*ProjectPullMirrorDetails, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/mirror/pull", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - pmd := new(ProjectPullMirrorDetails) - resp, err := s.client.Do(req, pmd) - if err != nil { - return nil, resp, err - } - - return pmd, resp, nil + return do[*ProjectPullMirrorDetails](s.client, + withPath("projects/%s/mirror/pull", ProjectID{pid}), + withRequestOpts(options...), + ) } // ConfigureProjectPullMirrorOptions represents the available ConfigureProjectPullMirror() options. @@ -2336,48 +1845,22 @@ type ConfigureProjectPullMirrorOptions struct { MirrorBranchRegex *string `url:"mirror_branch_regex,omitempty" json:"mirror_branch_regex,omitempty"` } -// ConfigureProjectPullMirror configures pull mirroring settings. -// -// GitLab API docs: -// https://docs.gitlab.com/api/project_pull_mirroring/#configure-pull-mirroring-for-a-project func (s *ProjectsService) ConfigureProjectPullMirror(pid any, opt *ConfigureProjectPullMirrorOptions, options ...RequestOptionFunc) (*ProjectPullMirrorDetails, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/mirror/pull", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - pmd := new(ProjectPullMirrorDetails) - resp, err := s.client.Do(req, pmd) - if err != nil { - return nil, resp, err - } - - return pmd, resp, nil + return do[*ProjectPullMirrorDetails](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/mirror/pull", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } -// StartMirroringProject start the pull mirroring process for a project. -// -// GitLab API docs: -// https://docs.gitlab.com/api/project_pull_mirroring/#start-the-pull-mirroring-process-for-a-project func (s *ProjectsService) StartMirroringProject(pid any, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/mirror/pull", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPost, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/mirror/pull", ProjectID{pid}), + withRequestOpts(options...), + ) + return resp, err } // TransferProjectOptions represents the available TransferProject() options. @@ -2388,47 +1871,22 @@ type TransferProjectOptions struct { Namespace any `url:"namespace,omitempty" json:"namespace,omitempty"` } -// TransferProject transfer a project into the specified namespace -// -// GitLab API docs: https://docs.gitlab.com/api/projects/#transfer-a-project-to-a-new-namespace func (s *ProjectsService) TransferProject(pid any, opt *TransferProjectOptions, options ...RequestOptionFunc) (*Project, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/transfer", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - p := new(Project) - resp, err := s.client.Do(req, p) - if err != nil { - return nil, resp, err - } - - return p, resp, nil + return do[*Project](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/transfer", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } -// StartHousekeepingProject start the Housekeeping task for a project. -// -// GitLab API docs: -// https://docs.gitlab.com/api/projects/#start-the-housekeeping-task-for-a-project func (s *ProjectsService) StartHousekeepingProject(pid any, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/housekeeping", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPost, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/housekeeping", ProjectID{pid}), + withRequestOpts(options...), + ) + return resp, err } // ProjectRepositoryStorage represents the repository storage information for a project. @@ -2442,29 +1900,11 @@ type ProjectRepositoryStorage struct { RepositoryStorage string `json:"repository_storage"` } -// GetRepositoryStorage Get the path to repository storage. -// -// GitLab API docs: -// https://docs.gitlab.com/api/projects/#get-the-path-to-repository-storage func (s *ProjectsService) GetRepositoryStorage(pid any, options ...RequestOptionFunc) (*ProjectRepositoryStorage, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/storage", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - prs := new(ProjectRepositoryStorage) - resp, err := s.client.Do(req, prs) - if err != nil { - return nil, resp, err - } - - return prs, resp, nil + return do[*ProjectRepositoryStorage](s.client, + withPath("projects/%s/storage", ProjectID{pid}), + withRequestOpts(options...), + ) } // ProjectStarrer represents a user who starred a project. @@ -2485,28 +1925,10 @@ type ListProjectStarrersOptions struct { Search *string `url:"search,omitempty" json:"search,omitempty"` } -// ListProjectStarrers gets users who starred a project. -// -// GitLab API docs: -// https://docs.gitlab.com/api/project_starring/#list-users-who-starred-a-project func (s *ProjectsService) ListProjectStarrers(pid any, opts *ListProjectStarrersOptions, options ...RequestOptionFunc) ([]*ProjectStarrer, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - - u := fmt.Sprintf("projects/%s/starrers", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, opts, options) - if err != nil { - return nil, nil, err - } - - var starrers []*ProjectStarrer - resp, err := s.client.Do(req, &starrers) - if err != nil { - return nil, resp, err - } - - return starrers, resp, nil + return do[[]*ProjectStarrer](s.client, + withPath("projects/%s/starrers", ProjectID{pid}), + withAPIOpts(opts), + withRequestOpts(options...), + ) } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/protected_branches.go b/vendor/gitlab.com/gitlab-org/api/client-go/protected_branches.go index bae532cc..0fd162ff 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/protected_branches.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/protected_branches.go @@ -16,11 +16,7 @@ package gitlab -import ( - "fmt" - "net/http" - "net/url" -) +import "net/http" type ( ProtectedBranchesServiceInterface interface { @@ -86,24 +82,11 @@ type ListProtectedBranchesOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/protected_branches/#list-protected-branches func (s *ProtectedBranchesService) ListProtectedBranches(pid any, opt *ListProtectedBranchesOptions, options ...RequestOptionFunc) ([]*ProtectedBranch, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/protected_branches", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var p []*ProtectedBranch - resp, err := s.client.Do(req, &p) - if err != nil { - return nil, resp, err - } - - return p, resp, nil + return do[[]*ProtectedBranch](s.client, + withPath("projects/%s/protected_branches", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // GetProtectedBranch gets a single protected branch or wildcard protected branch. @@ -111,24 +94,10 @@ func (s *ProtectedBranchesService) ListProtectedBranches(pid any, opt *ListProte // GitLab API docs: // https://docs.gitlab.com/api/protected_branches/#get-a-single-protected-branch-or-wildcard-protected-branch func (s *ProtectedBranchesService) GetProtectedBranch(pid any, branch string, options ...RequestOptionFunc) (*ProtectedBranch, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/protected_branches/%s", PathEscape(project), url.PathEscape(branch)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - p := new(ProtectedBranch) - resp, err := s.client.Do(req, p) - if err != nil { - return nil, resp, err - } - - return p, resp, nil + return do[*ProtectedBranch](s.client, + withPath("projects/%s/protected_branches/%s", ProjectID{pid}, branch), + withRequestOpts(options...), + ) } // ProtectRepositoryBranchesOptions represents the available @@ -167,24 +136,12 @@ type BranchPermissionOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/protected_branches/#protect-repository-branches func (s *ProtectedBranchesService) ProtectRepositoryBranches(pid any, opt *ProtectRepositoryBranchesOptions, options ...RequestOptionFunc) (*ProtectedBranch, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/protected_branches", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - p := new(ProtectedBranch) - resp, err := s.client.Do(req, p) - if err != nil { - return nil, resp, err - } - - return p, resp, nil + return do[*ProtectedBranch](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/protected_branches", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // UnprotectRepositoryBranches unprotects the given protected branch or wildcard @@ -193,18 +150,12 @@ func (s *ProtectedBranchesService) ProtectRepositoryBranches(pid any, opt *Prote // GitLab API docs: // https://docs.gitlab.com/api/protected_branches/#unprotect-repository-branches func (s *ProtectedBranchesService) UnprotectRepositoryBranches(pid any, branch string, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/protected_branches/%s", PathEscape(project), url.PathEscape(branch)) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/protected_branches/%s", ProjectID{pid}, branch), + withRequestOpts(options...), + ) + return resp, err } // UpdateProtectedBranchOptions represents the available @@ -226,22 +177,10 @@ type UpdateProtectedBranchOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/protected_branches/#update-a-protected-branch func (s *ProtectedBranchesService) UpdateProtectedBranch(pid any, branch string, opt *UpdateProtectedBranchOptions, options ...RequestOptionFunc) (*ProtectedBranch, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/protected_branches/%s", PathEscape(project), url.PathEscape(branch)) - - req, err := s.client.NewRequest(http.MethodPatch, u, opt, options) - if err != nil { - return nil, nil, err - } - - p := new(ProtectedBranch) - resp, err := s.client.Do(req, p) - if err != nil { - return nil, resp, err - } - - return p, resp, nil + return do[*ProtectedBranch](s.client, + withMethod(http.MethodPatch), + withPath("projects/%s/protected_branches/%s", ProjectID{pid}, branch), + withAPIOpts(opt), + withRequestOpts(options...), + ) } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/protected_environments.go b/vendor/gitlab.com/gitlab-org/api/client-go/protected_environments.go index 3ca4b457..57363ef0 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/protected_environments.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/protected_environments.go @@ -17,7 +17,6 @@ package gitlab import ( - "fmt" "net/http" ) @@ -97,24 +96,11 @@ type ListProtectedEnvironmentsOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/protected_environments/#list-protected-environments func (s *ProtectedEnvironmentsService) ListProtectedEnvironments(pid any, opt *ListProtectedEnvironmentsOptions, options ...RequestOptionFunc) ([]*ProtectedEnvironment, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/protected_environments", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var pes []*ProtectedEnvironment - resp, err := s.client.Do(req, &pes) - if err != nil { - return nil, resp, err - } - - return pes, resp, nil + return do[[]*ProtectedEnvironment](s.client, + withPath("projects/%s/protected_environments", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // GetProtectedEnvironment returns a single protected environment or wildcard @@ -123,24 +109,10 @@ func (s *ProtectedEnvironmentsService) ListProtectedEnvironments(pid any, opt *L // GitLab API docs: // https://docs.gitlab.com/api/protected_environments/#get-a-single-protected-environment func (s *ProtectedEnvironmentsService) GetProtectedEnvironment(pid any, environment string, options ...RequestOptionFunc) (*ProtectedEnvironment, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/protected_environments/%s", PathEscape(project), PathEscape(environment)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - pe := new(ProtectedEnvironment) - resp, err := s.client.Do(req, pe) - if err != nil { - return nil, resp, err - } - - return pe, resp, nil + return do[*ProtectedEnvironment](s.client, + withPath("projects/%s/protected_environments/%s", ProjectID{pid}, environment), + withRequestOpts(options...), + ) } // ProtectRepositoryEnvironmentsOptions represents the available @@ -187,24 +159,12 @@ type EnvironmentApprovalRuleOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/protected_environments/#protect-a-single-environment func (s *ProtectedEnvironmentsService) ProtectRepositoryEnvironments(pid any, opt *ProtectRepositoryEnvironmentsOptions, options ...RequestOptionFunc) (*ProtectedEnvironment, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/protected_environments", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - pe := new(ProtectedEnvironment) - resp, err := s.client.Do(req, pe) - if err != nil { - return nil, resp, err - } - - return pe, resp, nil + return do[*ProtectedEnvironment](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/protected_environments", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // UpdateProtectedEnvironmentsOptions represents the available @@ -255,24 +215,12 @@ type UpdateEnvironmentApprovalRuleOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/protected_environments/#update-a-protected-environment func (s *ProtectedEnvironmentsService) UpdateProtectedEnvironments(pid any, environment string, opt *UpdateProtectedEnvironmentsOptions, options ...RequestOptionFunc) (*ProtectedEnvironment, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/protected_environments/%s", PathEscape(project), PathEscape(environment)) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - pe := new(ProtectedEnvironment) - resp, err := s.client.Do(req, pe) - if err != nil { - return nil, resp, err - } - - return pe, resp, nil + return do[*ProtectedEnvironment](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/protected_environments/%s", ProjectID{pid}, environment), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // UnprotectEnvironment unprotects the given protected environment or wildcard @@ -281,16 +229,10 @@ func (s *ProtectedEnvironmentsService) UpdateProtectedEnvironments(pid any, envi // GitLab API docs: // https://docs.gitlab.com/api/protected_environments/#unprotect-a-single-environment func (s *ProtectedEnvironmentsService) UnprotectEnvironment(pid any, environment string, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/protected_environments/%s", PathEscape(project), PathEscape(environment)) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/protected_environments/%s", ProjectID{pid}, environment), + withRequestOpts(options...), + ) + return resp, err } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/protected_packages.go b/vendor/gitlab.com/gitlab-org/api/client-go/protected_packages.go index 711427c8..bca13f1b 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/protected_packages.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/protected_packages.go @@ -1,7 +1,6 @@ package gitlab import ( - "fmt" "net/http" ) @@ -86,80 +85,36 @@ type UpdatePackageProtectionRulesOptions struct { } func (s *ProtectedPackagesService) ListPackageProtectionRules(pid any, opts *ListPackageProtectionRulesOptions, options ...RequestOptionFunc) ([]*PackageProtectionRule, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - - u := fmt.Sprintf("projects/%s/packages/protection/rules", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, opts, options) - if err != nil { - return nil, nil, err - } - - var b []*PackageProtectionRule - resp, err := s.client.Do(req, &b) - if err != nil { - return nil, resp, err - } - - return b, resp, nil + return do[[]*PackageProtectionRule](s.client, + withPath("projects/%s/packages/protection/rules", ProjectID{pid}), + withAPIOpts(opts), + withRequestOpts(options...), + ) } func (s *ProtectedPackagesService) CreatePackageProtectionRules(pid any, opt *CreatePackageProtectionRulesOptions, options ...RequestOptionFunc) (*PackageProtectionRule, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/packages/protection/rules", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - p := new(PackageProtectionRule) - resp, err := s.client.Do(req, p) - if err != nil { - return nil, resp, err - } - - return p, resp, nil + return do[*PackageProtectionRule](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/packages/protection/rules", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } func (s *ProtectedPackagesService) DeletePackageProtectionRules(pid any, packageProtectionRule int64, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/packages/protection/rules/%d", PathEscape(project), packageProtectionRule) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/packages/protection/rules/%d", ProjectID{pid}, packageProtectionRule), + withRequestOpts(options...), + ) + return resp, err } func (s *ProtectedPackagesService) UpdatePackageProtectionRules(pid any, packageProtectionRule int64, opt *UpdatePackageProtectionRulesOptions, options ...RequestOptionFunc) (*PackageProtectionRule, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/packages/protection/rules/%d", PathEscape(project), packageProtectionRule) - - req, err := s.client.NewRequest(http.MethodPatch, u, opt, options) - if err != nil { - return nil, nil, err - } - - p := new(PackageProtectionRule) - resp, err := s.client.Do(req, p) - if err != nil { - return nil, resp, err - } - - return p, resp, nil + return do[*PackageProtectionRule](s.client, + withMethod(http.MethodPatch), + withPath("projects/%s/packages/protection/rules/%d", ProjectID{pid}, packageProtectionRule), + withAPIOpts(opt), + withRequestOpts(options...), + ) } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/protected_tags.go b/vendor/gitlab.com/gitlab-org/api/client-go/protected_tags.go index 51328219..78d0be82 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/protected_tags.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/protected_tags.go @@ -17,7 +17,6 @@ package gitlab import ( - "fmt" "net/http" ) @@ -77,24 +76,11 @@ type ListProtectedTagsOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/protected_tags/#list-protected-tags func (s *ProtectedTagsService) ListProtectedTags(pid any, opt *ListProtectedTagsOptions, options ...RequestOptionFunc) ([]*ProtectedTag, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/protected_tags", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var pts []*ProtectedTag - resp, err := s.client.Do(req, &pts) - if err != nil { - return nil, resp, err - } - - return pts, resp, nil + return do[[]*ProtectedTag](s.client, + withPath("projects/%s/protected_tags", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // GetProtectedTag returns a single protected tag or wildcard protected tag. @@ -102,24 +88,10 @@ func (s *ProtectedTagsService) ListProtectedTags(pid any, opt *ListProtectedTags // GitLab API docs: // https://docs.gitlab.com/api/protected_tags/#get-a-single-protected-tag-or-wildcard-protected-tag func (s *ProtectedTagsService) GetProtectedTag(pid any, tag string, options ...RequestOptionFunc) (*ProtectedTag, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/protected_tags/%s", PathEscape(project), PathEscape(tag)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - pt := new(ProtectedTag) - resp, err := s.client.Do(req, pt) - if err != nil { - return nil, resp, err - } - - return pt, resp, nil + return do[*ProtectedTag](s.client, + withPath("projects/%s/protected_tags/%s", ProjectID{pid}, tag), + withRequestOpts(options...), + ) } // ProtectRepositoryTagsOptions represents the available ProtectRepositoryTags() @@ -150,24 +122,12 @@ type TagsPermissionOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/protected_tags/#protect-repository-tags func (s *ProtectedTagsService) ProtectRepositoryTags(pid any, opt *ProtectRepositoryTagsOptions, options ...RequestOptionFunc) (*ProtectedTag, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/protected_tags", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - pt := new(ProtectedTag) - resp, err := s.client.Do(req, pt) - if err != nil { - return nil, resp, err - } - - return pt, resp, nil + return do[*ProtectedTag](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/protected_tags", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // UnprotectRepositoryTags unprotects the given protected tag or wildcard @@ -176,16 +136,10 @@ func (s *ProtectedTagsService) ProtectRepositoryTags(pid any, opt *ProtectReposi // GitLab API docs: // https://docs.gitlab.com/api/protected_tags/#unprotect-repository-tags func (s *ProtectedTagsService) UnprotectRepositoryTags(pid any, tag string, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/protected_tags/%s", PathEscape(project), PathEscape(tag)) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/protected_tags/%s", ProjectID{pid}, tag), + withRequestOpts(options...), + ) + return resp, err } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/releaselinks.go b/vendor/gitlab.com/gitlab-org/api/client-go/releaselinks.go index 00fb33dc..dce9cd3b 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/releaselinks.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/releaselinks.go @@ -16,10 +16,7 @@ package gitlab -import ( - "fmt" - "net/http" -) +import "net/http" type ( ReleaseLinksServiceInterface interface { @@ -64,51 +61,21 @@ type ListReleaseLinksOptions struct { // // GitLab API docs: https://docs.gitlab.com/api/releases/links/#list-links-of-a-release func (s *ReleaseLinksService) ListReleaseLinks(pid any, tagName string, opt *ListReleaseLinksOptions, options ...RequestOptionFunc) ([]*ReleaseLink, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/releases/%s/assets/links", PathEscape(project), PathEscape(tagName)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var rls []*ReleaseLink - resp, err := s.client.Do(req, &rls) - if err != nil { - return nil, resp, err - } - - return rls, resp, nil + return do[[]*ReleaseLink](s.client, + withPath("projects/%s/releases/%s/assets/links", ProjectID{pid}, tagName), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // GetReleaseLink returns a link from release assets. // // GitLab API docs: https://docs.gitlab.com/api/releases/links/#get-a-release-link func (s *ReleaseLinksService) GetReleaseLink(pid any, tagName string, link int64, options ...RequestOptionFunc) (*ReleaseLink, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/releases/%s/assets/links/%d", - PathEscape(project), - PathEscape(tagName), - link) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - rl := new(ReleaseLink) - resp, err := s.client.Do(req, rl) - if err != nil { - return nil, resp, err - } - - return rl, resp, nil + return do[*ReleaseLink](s.client, + withPath("projects/%s/releases/%s/assets/links/%d", ProjectID{pid}, tagName, link), + withRequestOpts(options...), + ) } // CreateReleaseLinkOptions represents CreateReleaseLink() options. @@ -126,24 +93,12 @@ type CreateReleaseLinkOptions struct { // // GitLab API docs: https://docs.gitlab.com/api/releases/links/#create-a-release-link func (s *ReleaseLinksService) CreateReleaseLink(pid any, tagName string, opt *CreateReleaseLinkOptions, options ...RequestOptionFunc) (*ReleaseLink, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/releases/%s/assets/links", PathEscape(project), PathEscape(tagName)) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - rl := new(ReleaseLink) - resp, err := s.client.Do(req, rl) - if err != nil { - return nil, resp, err - } - - return rl, resp, nil + return do[*ReleaseLink](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/releases/%s/assets/links", ProjectID{pid}, tagName), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // UpdateReleaseLinkOptions represents UpdateReleaseLink() options. @@ -163,53 +118,21 @@ type UpdateReleaseLinkOptions struct { // // GitLab API docs: https://docs.gitlab.com/api/releases/links/#update-a-release-link func (s *ReleaseLinksService) UpdateReleaseLink(pid any, tagName string, link int64, opt *UpdateReleaseLinkOptions, options ...RequestOptionFunc) (*ReleaseLink, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/releases/%s/assets/links/%d", - PathEscape(project), - PathEscape(tagName), - link) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - rl := new(ReleaseLink) - resp, err := s.client.Do(req, rl) - if err != nil { - return nil, resp, err - } - - return rl, resp, nil + return do[*ReleaseLink](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/releases/%s/assets/links/%d", ProjectID{pid}, tagName, link), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // DeleteReleaseLink deletes a link from release. // // GitLab API docs: https://docs.gitlab.com/api/releases/links/#delete-a-release-link func (s *ReleaseLinksService) DeleteReleaseLink(pid any, tagName string, link int64, options ...RequestOptionFunc) (*ReleaseLink, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/releases/%s/assets/links/%d", - PathEscape(project), - PathEscape(tagName), - link, + return do[*ReleaseLink](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/releases/%s/assets/links/%d", ProjectID{pid}, tagName, link), + withRequestOpts(options...), ) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, nil, err - } - - rl := new(ReleaseLink) - resp, err := s.client.Do(req, rl) - if err != nil { - return nil, resp, err - } - - return rl, resp, nil } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/releases.go b/vendor/gitlab.com/gitlab-org/api/client-go/releases.go index be400d30..801e890f 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/releases.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/releases.go @@ -17,7 +17,6 @@ package gitlab import ( - "fmt" "net/http" "time" ) @@ -154,24 +153,11 @@ type ListReleasesOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/releases/#list-releases func (s *ReleasesService) ListReleases(pid any, opt *ListReleasesOptions, options ...RequestOptionFunc) ([]*Release, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/releases", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var rs []*Release - resp, err := s.client.Do(req, &rs) - if err != nil { - return nil, resp, err - } - - return rs, resp, nil + return do[[]*Release](s.client, + withPath("projects/%s/releases", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // GetRelease returns a single release, identified by a tag name. @@ -179,24 +165,10 @@ func (s *ReleasesService) ListReleases(pid any, opt *ListReleasesOptions, option // GitLab API docs: // https://docs.gitlab.com/api/releases/#get-a-release-by-a-tag-name func (s *ReleasesService) GetRelease(pid any, tagName string, options ...RequestOptionFunc) (*Release, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/releases/%s", PathEscape(project), PathEscape(tagName)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - r := new(Release) - resp, err := s.client.Do(req, r) - if err != nil { - return nil, resp, err - } - - return r, resp, nil + return do[*Release](s.client, + withPath("projects/%s/releases/%s", ProjectID{pid}, tagName), + withRequestOpts(options...), + ) } // GetLatestRelease returns the latest release for the project. @@ -204,24 +176,10 @@ func (s *ReleasesService) GetRelease(pid any, tagName string, options ...Request // GitLab API docs: // https://docs.gitlab.com/api/releases/#get-the-latest-release func (s *ReleasesService) GetLatestRelease(pid any, options ...RequestOptionFunc) (*Release, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/releases/permalink/latest", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - r := new(Release) - resp, err := s.client.Do(req, r) - if err != nil { - return nil, resp, err - } - - return r, resp, err + return do[*Release](s.client, + withPath("projects/%s/releases/permalink/latest", ProjectID{pid}), + withRequestOpts(options...), + ) } // CreateReleaseOptions represents CreateRelease() options. @@ -265,24 +223,12 @@ type ReleaseAssetLinkOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/releases/#create-a-release func (s *ReleasesService) CreateRelease(pid any, opts *CreateReleaseOptions, options ...RequestOptionFunc) (*Release, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/releases", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPost, u, opts, options) - if err != nil { - return nil, nil, err - } - - r := new(Release) - resp, err := s.client.Do(req, r) - if err != nil { - return nil, resp, err - } - - return r, resp, nil + return do[*Release](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/releases", ProjectID{pid}), + withAPIOpts(opts), + withRequestOpts(options...), + ) } // UpdateReleaseOptions represents UpdateRelease() options. @@ -301,24 +247,12 @@ type UpdateReleaseOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/releases/#update-a-release func (s *ReleasesService) UpdateRelease(pid any, tagName string, opts *UpdateReleaseOptions, options ...RequestOptionFunc) (*Release, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/releases/%s", PathEscape(project), PathEscape(tagName)) - - req, err := s.client.NewRequest(http.MethodPut, u, opts, options) - if err != nil { - return nil, nil, err - } - - r := new(Release) - resp, err := s.client.Do(req, &r) - if err != nil { - return nil, resp, err - } - - return r, resp, nil + return do[*Release](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/releases/%s", ProjectID{pid}, tagName), + withAPIOpts(opts), + withRequestOpts(options...), + ) } // DeleteRelease deletes a release. @@ -326,22 +260,9 @@ func (s *ReleasesService) UpdateRelease(pid any, tagName string, opts *UpdateRel // GitLab API docs: // https://docs.gitlab.com/api/releases/#delete-a-release func (s *ReleasesService) DeleteRelease(pid any, tagName string, options ...RequestOptionFunc) (*Release, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/releases/%s", PathEscape(project), PathEscape(tagName)) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, nil, err - } - - r := new(Release) - resp, err := s.client.Do(req, r) - if err != nil { - return nil, resp, err - } - - return r, resp, nil + return do[*Release](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/releases/%s", ProjectID{pid}, tagName), + withRequestOpts(options...), + ) } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/repositories.go b/vendor/gitlab.com/gitlab-org/api/client-go/repositories.go index 5d21e577..dafbe57d 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/repositories.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/repositories.go @@ -21,20 +21,62 @@ import ( "fmt" "io" "net/http" - "net/url" ) type ( RepositoriesServiceInterface interface { + // ListTree gets a list of repository files and directories in a project. + // + // GitLab API docs: + // https://docs.gitlab.com/api/repositories/#list-repository-tree ListTree(pid any, opt *ListTreeOptions, options ...RequestOptionFunc) ([]*TreeNode, *Response, error) + // Blob gets information about blob in repository like size and content. Note + // that blob content is Base64 encoded. + // + // GitLab API docs: + // https://docs.gitlab.com/api/repositories/#get-a-blob-from-repository Blob(pid any, sha string, options ...RequestOptionFunc) ([]byte, *Response, error) + // RawBlobContent gets the raw file contents for a blob by blob SHA. + // + // GitLab API docs: + // https://docs.gitlab.com/api/repositories/#raw-blob-content RawBlobContent(pid any, sha string, options ...RequestOptionFunc) ([]byte, *Response, error) + // Archive gets an archive of the repository. + // + // GitLab API docs: + // https://docs.gitlab.com/api/repositories/#get-file-archive Archive(pid any, opt *ArchiveOptions, options ...RequestOptionFunc) ([]byte, *Response, error) + // StreamArchive streams an archive of the repository to the provided + // io.Writer. + // + // GitLab API docs: + // https://docs.gitlab.com/api/repositories/#get-file-archive StreamArchive(pid any, w io.Writer, opt *ArchiveOptions, options ...RequestOptionFunc) (*Response, error) + // Compare compares branches, tags or commits. + // + // GitLab API docs: + // https://docs.gitlab.com/api/repositories/#compare-branches-tags-or-commits Compare(pid any, opt *CompareOptions, options ...RequestOptionFunc) (*Compare, *Response, error) + // Contributors gets the repository contributors list. + // + // GitLab API docs: https://docs.gitlab.com/api/repositories/#contributors Contributors(pid any, opt *ListContributorsOptions, options ...RequestOptionFunc) ([]*Contributor, *Response, error) + // MergeBase gets the common ancestor for 2 refs (commit SHAs, branch + // names or tags). + // + // GitLab API docs: + // https://docs.gitlab.com/api/repositories/#merge-base MergeBase(pid any, opt *MergeBaseOptions, options ...RequestOptionFunc) (*Commit, *Response, error) + // AddChangelog generates changelog data based on commits in a repository. + // + // GitLab API docs: + // https://docs.gitlab.com/api/repositories/#add-changelog-data-to-a-changelog-file AddChangelog(pid any, opt *AddChangelogOptions, options ...RequestOptionFunc) (*Response, error) + // GenerateChangelogData generates changelog data based on commits in a + // repository, without committing them to a changelog file. + // + // GitLab API docs: + // https://docs.gitlab.com/api/repositories/#generate-changelog-data GenerateChangelogData(pid any, opt GenerateChangelogDataOptions, options ...RequestOptionFunc) (*ChangelogData, *Response, error) } @@ -75,80 +117,34 @@ type ListTreeOptions struct { Recursive *bool `url:"recursive,omitempty" json:"recursive,omitempty"` } -// ListTree gets a list of repository files and directories in a project. -// -// GitLab API docs: -// https://docs.gitlab.com/api/repositories/#list-repository-tree func (s *RepositoriesService) ListTree(pid any, opt *ListTreeOptions, options ...RequestOptionFunc) ([]*TreeNode, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/repository/tree", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var t []*TreeNode - resp, err := s.client.Do(req, &t) - if err != nil { - return nil, resp, err - } - - return t, resp, nil + return do[[]*TreeNode](s.client, + withPath("projects/%s/repository/tree", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } -// Blob gets information about blob in repository like size and content. Note -// that blob content is Base64 encoded. -// -// GitLab API docs: -// https://docs.gitlab.com/api/repositories/#get-a-blob-from-repository func (s *RepositoriesService) Blob(pid any, sha string, options ...RequestOptionFunc) ([]byte, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/repository/blobs/%s", PathEscape(project), url.PathEscape(sha)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - var b bytes.Buffer - resp, err := s.client.Do(req, &b) + buf, resp, err := do[bytes.Buffer](s.client, + withPath("projects/%s/repository/blobs/%s", ProjectID{pid}, sha), + withRequestOpts(options...), + ) if err != nil { return nil, resp, err } - - return b.Bytes(), resp, err + return buf.Bytes(), resp, nil } -// RawBlobContent gets the raw file contents for a blob by blob SHA. -// -// GitLab API docs: -// https://docs.gitlab.com/api/repositories/#raw-blob-content func (s *RepositoriesService) RawBlobContent(pid any, sha string, options ...RequestOptionFunc) ([]byte, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/repository/blobs/%s/raw", PathEscape(project), url.PathEscape(sha)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - var b bytes.Buffer - resp, err := s.client.Do(req, &b) + buf, resp, err := do[bytes.Buffer](s.client, + withPath("projects/%s/repository/blobs/%s/raw", ProjectID{pid}, sha), + withRequestOpts(options...), + ) if err != nil { return nil, resp, err } - - return b.Bytes(), resp, err + return buf.Bytes(), resp, nil } // ArchiveOptions represents the available Archive() options. @@ -161,41 +157,23 @@ type ArchiveOptions struct { SHA *string `url:"sha,omitempty" json:"sha,omitempty"` } -// Archive gets an archive of the repository. -// -// GitLab API docs: -// https://docs.gitlab.com/api/repositories/#get-file-archive func (s *RepositoriesService) Archive(pid any, opt *ArchiveOptions, options ...RequestOptionFunc) ([]byte, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/repository/archive", PathEscape(project)) - - // Set an optional format for the archive. + suffix := "" if opt != nil && opt.Format != nil { - u = fmt.Sprintf("%s.%s", u, *opt.Format) + suffix = "." + *opt.Format } - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var b bytes.Buffer - resp, err := s.client.Do(req, &b) + buf, resp, err := do[bytes.Buffer](s.client, + withPath("projects/%s/repository/archive%s", ProjectID{pid}, NoEscape{suffix}), + withAPIOpts(opt), + withRequestOpts(options...), + ) if err != nil { return nil, resp, err } - - return b.Bytes(), resp, err + return buf.Bytes(), resp, nil } -// StreamArchive streams an archive of the repository to the provided -// io.Writer. -// -// GitLab API docs: -// https://docs.gitlab.com/api/repositories/#get-file-archive func (s *RepositoriesService) StreamArchive(pid any, w io.Writer, opt *ArchiveOptions, options ...RequestOptionFunc) (*Response, error) { project, err := parseID(pid) if err != nil { @@ -244,29 +222,12 @@ type CompareOptions struct { Unidiff *bool `url:"unidiff,omitempty" json:"unidiff,omitempty"` } -// Compare compares branches, tags or commits. -// -// GitLab API docs: -// https://docs.gitlab.com/api/repositories/#compare-branches-tags-or-commits func (s *RepositoriesService) Compare(pid any, opt *CompareOptions, options ...RequestOptionFunc) (*Compare, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/repository/compare", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - c := new(Compare) - resp, err := s.client.Do(req, c) - if err != nil { - return nil, resp, err - } - - return c, resp, nil + return do[*Compare](s.client, + withPath("projects/%s/repository/compare", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // Contributor represents a GitLab contributor. @@ -293,28 +254,12 @@ type ListContributorsOptions struct { Sort *string `url:"sort,omitempty" json:"sort,omitempty"` } -// Contributors gets the repository contributors list. -// -// GitLab API docs: https://docs.gitlab.com/api/repositories/#contributors func (s *RepositoriesService) Contributors(pid any, opt *ListContributorsOptions, options ...RequestOptionFunc) ([]*Contributor, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/repository/contributors", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var c []*Contributor - resp, err := s.client.Do(req, &c) - if err != nil { - return nil, resp, err - } - - return c, resp, nil + return do[[]*Contributor](s.client, + withPath("projects/%s/repository/contributors", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // MergeBaseOptions represents the available MergeBase() options. @@ -325,30 +270,12 @@ type MergeBaseOptions struct { Ref *[]string `url:"refs[],omitempty" json:"refs,omitempty"` } -// MergeBase gets the common ancestor for 2 refs (commit SHAs, branch -// names or tags). -// -// GitLab API docs: -// https://docs.gitlab.com/api/repositories/#merge-base func (s *RepositoriesService) MergeBase(pid any, opt *MergeBaseOptions, options ...RequestOptionFunc) (*Commit, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/repository/merge_base", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - c := new(Commit) - resp, err := s.client.Do(req, c) - if err != nil { - return nil, resp, err - } - - return c, resp, nil + return do[*Commit](s.client, + withPath("projects/%s/repository/merge_base", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // AddChangelogOptions represents the available AddChangelog() options. @@ -367,23 +294,14 @@ type AddChangelogOptions struct { Trailer *string `url:"trailer,omitempty" json:"trailer,omitempty"` } -// AddChangelog generates changelog data based on commits in a repository. -// -// GitLab API docs: -// https://docs.gitlab.com/api/repositories/#add-changelog-data-to-a-changelog-file func (s *RepositoriesService) AddChangelog(pid any, opt *AddChangelogOptions, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/repository/changelog", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/repository/changelog", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) + return resp, err } // ChangelogData represents the generated changelog data. @@ -412,28 +330,10 @@ type GenerateChangelogDataOptions struct { Trailer *string `url:"trailer,omitempty" json:"trailer,omitempty"` } -// GenerateChangelogData generates changelog data based on commits in a -// repository, without committing them to a changelog file. -// -// GitLab API docs: -// https://docs.gitlab.com/api/repositories/#generate-changelog-data func (s *RepositoriesService) GenerateChangelogData(pid any, opt GenerateChangelogDataOptions, options ...RequestOptionFunc) (*ChangelogData, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/repository/changelog", project) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - cd := new(ChangelogData) - resp, err := s.client.Do(req, cd) - if err != nil { - return nil, resp, err - } - - return cd, resp, nil + return do[*ChangelogData](s.client, + withPath("projects/%s/repository/changelog", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/repository_files.go b/vendor/gitlab.com/gitlab-org/api/client-go/repository_files.go index 5290b467..69a022bd 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/repository_files.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/repository_files.go @@ -18,7 +18,6 @@ package gitlab import ( "bytes" - "fmt" "net/http" "strconv" "time" @@ -82,28 +81,11 @@ type GetFileOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/repository_files/#get-file-from-repository func (s *RepositoryFilesService) GetFile(pid any, fileName string, opt *GetFileOptions, options ...RequestOptionFunc) (*File, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf( - "projects/%s/repository/files/%s", - PathEscape(project), - PathEscape(fileName), + return do[*File](s.client, + withPath("projects/%s/repository/files/%s", ProjectID{pid}, fileName), + withAPIOpts(opt), + withRequestOpts(options...), ) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - f := new(File) - resp, err := s.client.Do(req, f) - if err != nil { - return nil, resp, err - } - - return f, resp, nil } // GetFileMetaDataOptions represents the available GetFileMetaData() options. @@ -120,22 +102,12 @@ type GetFileMetaDataOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/repository_files/#get-file-from-repository func (s *RepositoryFilesService) GetFileMetaData(pid any, fileName string, opt *GetFileMetaDataOptions, options ...RequestOptionFunc) (*File, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf( - "projects/%s/repository/files/%s", - PathEscape(project), - PathEscape(fileName), + _, resp, err := do[none](s.client, + withMethod(http.MethodHead), + withPath("projects/%s/repository/files/%s", ProjectID{pid}, fileName), + withAPIOpts(opt), + withRequestOpts(options...), ) - - req, err := s.client.NewRequest(http.MethodHead, u, opt, options) - if err != nil { - return nil, nil, err - } - - resp, err := s.client.Do(req, nil) if err != nil { return nil, resp, err } @@ -223,28 +195,11 @@ type GetFileBlameOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/repository_files/#get-file-blame-from-repository func (s *RepositoryFilesService) GetFileBlame(pid any, file string, opt *GetFileBlameOptions, options ...RequestOptionFunc) ([]*FileBlameRange, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf( - "projects/%s/repository/files/%s/blame", - PathEscape(project), - PathEscape(file), + return do[[]*FileBlameRange](s.client, + withPath("projects/%s/repository/files/%s/blame", ProjectID{pid}, file), + withAPIOpts(opt), + withRequestOpts(options...), ) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var br []*FileBlameRange - resp, err := s.client.Do(req, &br) - if err != nil { - return nil, resp, err - } - - return br, resp, nil } // GetRawFileOptions represents the available GetRawFile() options. @@ -261,28 +216,15 @@ type GetRawFileOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/repository_files/#get-raw-file-from-repository func (s *RepositoryFilesService) GetRawFile(pid any, fileName string, opt *GetRawFileOptions, options ...RequestOptionFunc) ([]byte, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf( - "projects/%s/repository/files/%s/raw", - PathEscape(project), - PathEscape(fileName), + buf, resp, err := do[bytes.Buffer](s.client, + withPath("projects/%s/repository/files/%s/raw", ProjectID{pid}, fileName), + withAPIOpts(opt), + withRequestOpts(options...), ) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var f bytes.Buffer - resp, err := s.client.Do(req, &f) if err != nil { return nil, resp, err } - - return f.Bytes(), resp, err + return buf.Bytes(), resp, nil } // GetRawFileMetaData gets the metadata of a raw file from a repository. @@ -290,22 +232,12 @@ func (s *RepositoryFilesService) GetRawFile(pid any, fileName string, opt *GetRa // GitLab API docs: // https://docs.gitlab.com/api/repository_files/#get-raw-file-from-repository func (s *RepositoryFilesService) GetRawFileMetaData(pid any, fileName string, opt *GetRawFileOptions, options ...RequestOptionFunc) (*File, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf( - "projects/%s/repository/files/%s/raw", - PathEscape(project), - PathEscape(fileName), + _, resp, err := do[none](s.client, + withMethod(http.MethodHead), + withPath("projects/%s/repository/files/%s/raw", ProjectID{pid}, fileName), + withAPIOpts(opt), + withRequestOpts(options...), ) - - req, err := s.client.NewRequest(http.MethodHead, u, opt, options) - if err != nil { - return nil, nil, err - } - - resp, err := s.client.Do(req, nil) if err != nil { return nil, resp, err } @@ -350,28 +282,12 @@ type CreateFileOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/repository_files/#create-new-file-in-repository func (s *RepositoryFilesService) CreateFile(pid any, fileName string, opt *CreateFileOptions, options ...RequestOptionFunc) (*FileInfo, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf( - "projects/%s/repository/files/%s", - PathEscape(project), - PathEscape(fileName), + return do[*FileInfo](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/repository/files/%s", ProjectID{pid}, fileName), + withAPIOpts(opt), + withRequestOpts(options...), ) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - f := new(FileInfo) - resp, err := s.client.Do(req, f) - if err != nil { - return nil, resp, err - } - - return f, resp, nil } // UpdateFileOptions represents the available UpdateFile() options. @@ -395,28 +311,12 @@ type UpdateFileOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/repository_files/#update-existing-file-in-repository func (s *RepositoryFilesService) UpdateFile(pid any, fileName string, opt *UpdateFileOptions, options ...RequestOptionFunc) (*FileInfo, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf( - "projects/%s/repository/files/%s", - PathEscape(project), - PathEscape(fileName), + return do[*FileInfo](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/repository/files/%s", ProjectID{pid}, fileName), + withAPIOpts(opt), + withRequestOpts(options...), ) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - f := new(FileInfo) - resp, err := s.client.Do(req, f) - if err != nil { - return nil, resp, err - } - - return f, resp, nil } // DeleteFileOptions represents the available DeleteFile() options. @@ -437,20 +337,11 @@ type DeleteFileOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/repository_files/#delete-existing-file-in-repository func (s *RepositoryFilesService) DeleteFile(pid any, fileName string, opt *DeleteFileOptions, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf( - "projects/%s/repository/files/%s", - PathEscape(project), - PathEscape(fileName), + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/repository/files/%s", ProjectID{pid}, fileName), + withAPIOpts(opt), + withRequestOpts(options...), ) - - req, err := s.client.NewRequest(http.MethodDelete, u, opt, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + return resp, err } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/repository_submodules.go b/vendor/gitlab.com/gitlab-org/api/client-go/repository_submodules.go index 84a0491d..7f08fb6a 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/repository_submodules.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/repository_submodules.go @@ -17,7 +17,6 @@ package gitlab import ( - "fmt" "net/http" "time" ) @@ -76,26 +75,10 @@ type UpdateSubmoduleOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/repository_submodules/#update-existing-submodule-reference-in-repository func (s *RepositorySubmodulesService) UpdateSubmodule(pid any, submodule string, opt *UpdateSubmoduleOptions, options ...RequestOptionFunc) (*SubmoduleCommit, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf( - "projects/%s/repository/submodules/%s", - PathEscape(project), - PathEscape(submodule), + return do[*SubmoduleCommit](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/repository/submodules/%s", ProjectID{pid}, submodule), + withAPIOpts(opt), + withRequestOpts(options...), ) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - sc := new(SubmoduleCommit) - resp, err := s.client.Do(req, sc) - if err != nil { - return nil, resp, err - } - - return sc, resp, nil } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/request_handler.go b/vendor/gitlab.com/gitlab-org/api/client-go/request_handler.go index 09827350..7ee3b334 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/request_handler.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/request_handler.go @@ -2,8 +2,12 @@ package gitlab import ( "fmt" + "io" "net/http" "reflect" + "strings" + + "github.com/hashicorp/go-retryablehttp" ) type Pather interface { @@ -49,6 +53,9 @@ func (i RunnerID) forPath() (string, error) { return PathEscape(id), nil } +// UserID represents a user identifier for API paths. It accepts either a +// numeric user ID or a username string. If a username is provided with a +// leading "@" character (e.g., "@johndoe"), the "@" will be trimmed. type UserID struct { Value any } @@ -59,6 +66,19 @@ func (i UserID) forPath() (string, error) { return "", err } + return PathEscape(strings.TrimPrefix(id, "@")), nil +} + +type LabelID struct { + Value any +} + +func (i LabelID) forPath() (string, error) { + id, err := parseID(i.Value) + if err != nil { + return "", err + } + return PathEscape(id), nil } @@ -75,6 +95,13 @@ type doConfig struct { path string apiOpts any requestOpts []RequestOptionFunc + upload *uploadConfig +} + +type uploadConfig struct { + content io.Reader + filename string + uploadType UploadType } type doOption func(c *doConfig) error @@ -123,6 +150,17 @@ func withRequestOpts(o ...RequestOptionFunc) doOption { } } +func withUpload(content io.Reader, filename string, uploadType UploadType) doOption { + return func(c *doConfig) error { + c.upload = &uploadConfig{ + content: content, + filename: filename, + uploadType: uploadType, + } + return nil + } +} + // none is a sentinel type to signal that a request performed with do does not return a value. type none struct{} @@ -168,6 +206,17 @@ type none struct{} // withRequestOpts(options...), // // ) +// +// // Upload file Request: +// return do[*WikiAttachment](s.client, +// +// withMethod(http.MethodPost), +// withPath("projects/%s/wikis/attachments", project), +// withUpload(content, filename, UploadFile), +// withAPIOpts(opt), +// withRequestOpts(options...), +// +// ) func do[T any](client *Client, opts ...doOption) (T, *Response, error) { // default config config := &doConfig{ @@ -184,7 +233,25 @@ func do[T any](client *Client, opts ...doOption) (T, *Response, error) { } } - req, err := client.NewRequest(config.method, config.path, config.apiOpts, config.requestOpts) + var ( + req *retryablehttp.Request + err error + ) + switch { + case config.upload != nil: + req, err = client.UploadRequest( + config.method, + config.path, + config.upload.content, + config.upload.filename, + config.upload.uploadType, + config.apiOpts, + config.requestOpts, + ) + default: + req, err = client.NewRequest(config.method, config.path, config.apiOpts, config.requestOpts) + } + if err != nil { var z T return z, nil, err diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/resource_group.go b/vendor/gitlab.com/gitlab-org/api/client-go/resource_group.go index d3b8a76b..b6c3c979 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/resource_group.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/resource_group.go @@ -17,7 +17,6 @@ package gitlab import ( - "fmt" "net/http" "time" ) @@ -68,24 +67,10 @@ func (rg ResourceGroup) String() string { // GitLab API docs: // https://docs.gitlab.com/api/resource_groups/#get-all-resource-groups-for-a-project func (s *ResourceGroupService) GetAllResourceGroupsForAProject(pid any, options ...RequestOptionFunc) ([]*ResourceGroup, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/resource_groups", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - var rgs []*ResourceGroup - resp, err := s.client.Do(req, &rgs) - if err != nil { - return nil, resp, err - } - - return rgs, resp, nil + return do[[]*ResourceGroup](s.client, + withPath("projects/%s/resource_groups", ProjectID{pid}), + withRequestOpts(options...), + ) } // GetASpecificResourceGroup allows you to get a specific @@ -94,24 +79,10 @@ func (s *ResourceGroupService) GetAllResourceGroupsForAProject(pid any, options // GitLab API docs: // https://docs.gitlab.com/api/resource_groups/#get-a-specific-resource-group func (s *ResourceGroupService) GetASpecificResourceGroup(pid any, key string, options ...RequestOptionFunc) (*ResourceGroup, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/resource_groups/%s", PathEscape(project), key) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - rg := new(ResourceGroup) - resp, err := s.client.Do(req, rg) - if err != nil { - return nil, resp, err - } - - return rg, resp, nil + return do[*ResourceGroup](s.client, + withPath("projects/%s/resource_groups/%s", ProjectID{pid}, key), + withRequestOpts(options...), + ) } // ListUpcomingJobsForASpecificResourceGroup allows you to get all @@ -120,24 +91,10 @@ func (s *ResourceGroupService) GetASpecificResourceGroup(pid any, key string, op // GitLab API docs: // https://docs.gitlab.com/api/resource_groups/#list-upcoming-jobs-for-a-specific-resource-group func (s *ResourceGroupService) ListUpcomingJobsForASpecificResourceGroup(pid any, key string, options ...RequestOptionFunc) ([]*Job, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/resource_groups/%s/upcoming_jobs", PathEscape(project), key) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - var js []*Job - resp, err := s.client.Do(req, &js) - if err != nil { - return nil, resp, err - } - - return js, resp, nil + return do[[]*Job](s.client, + withPath("projects/%s/resource_groups/%s/upcoming_jobs", ProjectID{pid}, key), + withRequestOpts(options...), + ) } // EditAnExistingResourceGroupOptions represents the available @@ -155,22 +112,10 @@ type EditAnExistingResourceGroupOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/resource_groups/#edit-an-existing-resource-group func (s *ResourceGroupService) EditAnExistingResourceGroup(pid any, key string, opts *EditAnExistingResourceGroupOptions, options ...RequestOptionFunc) (*ResourceGroup, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/resource_groups/%s", PathEscape(project), key) - - req, err := s.client.NewRequest(http.MethodPut, u, opts, options) - if err != nil { - return nil, nil, err - } - - rg := new(ResourceGroup) - resp, err := s.client.Do(req, rg) - if err != nil { - return nil, resp, err - } - - return rg, resp, nil + return do[*ResourceGroup](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/resource_groups/%s", ProjectID{pid}, key), + withAPIOpts(opts), + withRequestOpts(options...), + ) } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/resource_iteration_events.go b/vendor/gitlab.com/gitlab-org/api/client-go/resource_iteration_events.go index d460ad4c..85499efc 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/resource_iteration_events.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/resource_iteration_events.go @@ -17,8 +17,6 @@ package gitlab import ( - "fmt" - "net/http" "time" ) @@ -85,24 +83,11 @@ type ListIterationEventsOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/resource_iteration_events/#list-project-issue-iteration-events func (s *ResourceIterationEventsService) ListIssueIterationEvents(pid any, issue int64, opt *ListIterationEventsOptions, options ...RequestOptionFunc) ([]*IterationEvent, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/issues/%d/resource_iteration_events", PathEscape(project), issue) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var ies []*IterationEvent - resp, err := s.client.Do(req, &ies) - if err != nil { - return nil, resp, err - } - - return ies, resp, nil + return do[[]*IterationEvent](s.client, + withPath("projects/%s/issues/%d/resource_iteration_events", ProjectID{pid}, issue), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // GetIssueIterationEvent gets a single issue iteration event. @@ -110,22 +95,8 @@ func (s *ResourceIterationEventsService) ListIssueIterationEvents(pid any, issue // GitLab API docs: // https://docs.gitlab.com/api/resource_iteration_events/#get-single-issue-iteration-event func (s *ResourceIterationEventsService) GetIssueIterationEvent(pid any, issue int64, event int64, options ...RequestOptionFunc) (*IterationEvent, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/issues/%d/resource_iteration_events/%d", PathEscape(project), issue, event) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - ie := new(IterationEvent) - resp, err := s.client.Do(req, ie) - if err != nil { - return nil, resp, err - } - - return ie, resp, nil + return do[*IterationEvent](s.client, + withPath("projects/%s/issues/%d/resource_iteration_events/%d", ProjectID{pid}, issue, event), + withRequestOpts(options...), + ) } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/resource_label_events.go b/vendor/gitlab.com/gitlab-org/api/client-go/resource_label_events.go index cd8e9bf0..4a36332d 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/resource_label_events.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/resource_label_events.go @@ -17,8 +17,6 @@ package gitlab import ( - "fmt" - "net/http" "time" ) @@ -87,24 +85,11 @@ type ListLabelEventsOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/resource_label_events/#list-project-issue-label-events func (s *ResourceLabelEventsService) ListIssueLabelEvents(pid any, issue int64, opt *ListLabelEventsOptions, options ...RequestOptionFunc) ([]*LabelEvent, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/issues/%d/resource_label_events", PathEscape(project), issue) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var ls []*LabelEvent - resp, err := s.client.Do(req, &ls) - if err != nil { - return nil, resp, err - } - - return ls, resp, nil + return do[[]*LabelEvent](s.client, + withPath("projects/%s/issues/%d/resource_label_events", ProjectID{pid}, issue), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // GetIssueLabelEvent gets a single issue-label-event. @@ -112,24 +97,10 @@ func (s *ResourceLabelEventsService) ListIssueLabelEvents(pid any, issue int64, // GitLab API docs: // https://docs.gitlab.com/api/resource_label_events/#get-single-issue-label-event func (s *ResourceLabelEventsService) GetIssueLabelEvent(pid any, issue int64, event int64, options ...RequestOptionFunc) (*LabelEvent, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/issues/%d/resource_label_events/%d", PathEscape(project), issue, event) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - l := new(LabelEvent) - resp, err := s.client.Do(req, l) - if err != nil { - return nil, resp, err - } - - return l, resp, nil + return do[*LabelEvent](s.client, + withPath("projects/%s/issues/%d/resource_label_events/%d", ProjectID{pid}, issue, event), + withRequestOpts(options...), + ) } // ListGroupEpicLabelEvents retrieves resource label events for the specified @@ -139,24 +110,11 @@ func (s *ResourceLabelEventsService) GetIssueLabelEvent(pid any, issue int64, ev // GitLab API docs: // https://docs.gitlab.com/api/resource_label_events/#list-group-epic-label-events func (s *ResourceLabelEventsService) ListGroupEpicLabelEvents(gid any, epic int64, opt *ListLabelEventsOptions, options ...RequestOptionFunc) ([]*LabelEvent, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/epics/%d/resource_label_events", PathEscape(group), epic) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var ls []*LabelEvent - resp, err := s.client.Do(req, &ls) - if err != nil { - return nil, resp, err - } - - return ls, resp, nil + return do[[]*LabelEvent](s.client, + withPath("groups/%s/epics/%d/resource_label_events", GroupID{gid}, epic), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // GetGroupEpicLabelEvent gets a single group epic label event. @@ -165,24 +123,10 @@ func (s *ResourceLabelEventsService) ListGroupEpicLabelEvents(gid any, epic int6 // GitLab API docs: // https://docs.gitlab.com/api/resource_label_events/#get-single-epic-label-event func (s *ResourceLabelEventsService) GetGroupEpicLabelEvent(gid any, epic int64, event int64, options ...RequestOptionFunc) (*LabelEvent, *Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("groups/%s/epics/%d/resource_label_events/%d", PathEscape(group), epic, event) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - l := new(LabelEvent) - resp, err := s.client.Do(req, l) - if err != nil { - return nil, resp, err - } - - return l, resp, nil + return do[*LabelEvent](s.client, + withPath("groups/%s/epics/%d/resource_label_events/%d", GroupID{gid}, epic, event), + withRequestOpts(options...), + ) } // ListMergeRequestsLabelEvents retrieves resource label events for the specified @@ -191,24 +135,11 @@ func (s *ResourceLabelEventsService) GetGroupEpicLabelEvent(gid any, epic int64, // GitLab API docs: // https://docs.gitlab.com/api/resource_label_events/#list-project-merge-request-label-events func (s *ResourceLabelEventsService) ListMergeRequestsLabelEvents(pid any, request int64, opt *ListLabelEventsOptions, options ...RequestOptionFunc) ([]*LabelEvent, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/merge_requests/%d/resource_label_events", PathEscape(project), request) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var ls []*LabelEvent - resp, err := s.client.Do(req, &ls) - if err != nil { - return nil, resp, err - } - - return ls, resp, nil + return do[[]*LabelEvent](s.client, + withPath("projects/%s/merge_requests/%d/resource_label_events", ProjectID{pid}, request), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // GetMergeRequestLabelEvent gets a single merge request label event. @@ -216,22 +147,8 @@ func (s *ResourceLabelEventsService) ListMergeRequestsLabelEvents(pid any, reque // GitLab API docs: // https://docs.gitlab.com/api/resource_label_events/#get-single-merge-request-label-event func (s *ResourceLabelEventsService) GetMergeRequestLabelEvent(pid any, request int64, event int64, options ...RequestOptionFunc) (*LabelEvent, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/merge_requests/%d/resource_label_events/%d", PathEscape(project), request, event) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - l := new(LabelEvent) - resp, err := s.client.Do(req, l) - if err != nil { - return nil, resp, err - } - - return l, resp, nil + return do[*LabelEvent](s.client, + withPath("projects/%s/merge_requests/%d/resource_label_events/%d", ProjectID{pid}, request, event), + withRequestOpts(options...), + ) } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/resource_milestone_events.go b/vendor/gitlab.com/gitlab-org/api/client-go/resource_milestone_events.go index ed4e03a0..063bbdcf 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/resource_milestone_events.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/resource_milestone_events.go @@ -17,8 +17,6 @@ package gitlab import ( - "fmt" - "net/http" "time" ) @@ -69,24 +67,11 @@ type ListMilestoneEventsOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/resource_milestone_events/#list-project-issue-milestone-events func (s *ResourceMilestoneEventsService) ListIssueMilestoneEvents(pid any, issue int64, opt *ListMilestoneEventsOptions, options ...RequestOptionFunc) ([]*MilestoneEvent, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/issues/%d/resource_milestone_events", PathEscape(project), issue) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var mes []*MilestoneEvent - resp, err := s.client.Do(req, &mes) - if err != nil { - return nil, resp, err - } - - return mes, resp, nil + return do[[]*MilestoneEvent](s.client, + withPath("projects/%s/issues/%d/resource_milestone_events", ProjectID{pid}, issue), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // GetIssueMilestoneEvent gets a single issue milestone event. @@ -94,24 +79,10 @@ func (s *ResourceMilestoneEventsService) ListIssueMilestoneEvents(pid any, issue // GitLab API docs: // https://docs.gitlab.com/api/resource_milestone_events/#get-single-issue-milestone-event func (s *ResourceMilestoneEventsService) GetIssueMilestoneEvent(pid any, issue int64, event int64, options ...RequestOptionFunc) (*MilestoneEvent, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/issues/%d/resource_milestone_events/%d", PathEscape(project), issue, event) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - me := new(MilestoneEvent) - resp, err := s.client.Do(req, me) - if err != nil { - return nil, resp, err - } - - return me, resp, nil + return do[*MilestoneEvent](s.client, + withPath("projects/%s/issues/%d/resource_milestone_events/%d", ProjectID{pid}, issue, event), + withRequestOpts(options...), + ) } // ListMergeMilestoneEvents retrieves resource milestone events for the specified @@ -120,24 +91,11 @@ func (s *ResourceMilestoneEventsService) GetIssueMilestoneEvent(pid any, issue i // GitLab API docs: // https://docs.gitlab.com/api/resource_milestone_events/#list-project-merge-request-milestone-events func (s *ResourceMilestoneEventsService) ListMergeMilestoneEvents(pid any, request int64, opt *ListMilestoneEventsOptions, options ...RequestOptionFunc) ([]*MilestoneEvent, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/merge_requests/%d/resource_milestone_events", PathEscape(project), request) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var mes []*MilestoneEvent - resp, err := s.client.Do(req, &mes) - if err != nil { - return nil, resp, err - } - - return mes, resp, nil + return do[[]*MilestoneEvent](s.client, + withPath("projects/%s/merge_requests/%d/resource_milestone_events", ProjectID{pid}, request), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // GetMergeRequestMilestoneEvent gets a single merge request milestone event. @@ -145,22 +103,8 @@ func (s *ResourceMilestoneEventsService) ListMergeMilestoneEvents(pid any, reque // GitLab API docs: // https://docs.gitlab.com/api/resource_milestone_events/#get-single-merge-request-milestone-event func (s *ResourceMilestoneEventsService) GetMergeRequestMilestoneEvent(pid any, request int64, event int64, options ...RequestOptionFunc) (*MilestoneEvent, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/merge_requests/%d/resource_milestone_events/%d", PathEscape(project), request, event) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - me := new(MilestoneEvent) - resp, err := s.client.Do(req, me) - if err != nil { - return nil, resp, err - } - - return me, resp, nil + return do[*MilestoneEvent](s.client, + withPath("projects/%s/merge_requests/%d/resource_milestone_events/%d", ProjectID{pid}, request, event), + withRequestOpts(options...), + ) } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/resource_state_events.go b/vendor/gitlab.com/gitlab-org/api/client-go/resource_state_events.go index ba0e5152..318c5f15 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/resource_state_events.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/resource_state_events.go @@ -17,8 +17,6 @@ package gitlab import ( - "fmt" - "net/http" "time" ) @@ -68,24 +66,11 @@ type ListStateEventsOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/resource_state_events/#list-project-issue-state-events func (s *ResourceStateEventsService) ListIssueStateEvents(pid any, issue int64, opt *ListStateEventsOptions, options ...RequestOptionFunc) ([]*StateEvent, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/issues/%d/resource_state_events", PathEscape(project), issue) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var ses []*StateEvent - resp, err := s.client.Do(req, &ses) - if err != nil { - return nil, resp, err - } - - return ses, resp, nil + return do[[]*StateEvent](s.client, + withPath("projects/%s/issues/%d/resource_state_events", ProjectID{pid}, issue), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // GetIssueStateEvent gets a single issue-state-event. @@ -93,24 +78,10 @@ func (s *ResourceStateEventsService) ListIssueStateEvents(pid any, issue int64, // GitLab API docs: // https://docs.gitlab.com/api/resource_state_events/#get-single-issue-state-event func (s *ResourceStateEventsService) GetIssueStateEvent(pid any, issue int64, event int64, options ...RequestOptionFunc) (*StateEvent, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/issues/%d/resource_state_events/%d", PathEscape(project), issue, event) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - se := new(StateEvent) - resp, err := s.client.Do(req, se) - if err != nil { - return nil, resp, err - } - - return se, resp, nil + return do[*StateEvent](s.client, + withPath("projects/%s/issues/%d/resource_state_events/%d", ProjectID{pid}, issue, event), + withRequestOpts(options...), + ) } // ListMergeStateEvents retrieves resource state events for the specified @@ -119,24 +90,11 @@ func (s *ResourceStateEventsService) GetIssueStateEvent(pid any, issue int64, ev // GitLab API docs: // https://docs.gitlab.com/api/resource_state_events/#list-project-merge-request-state-events func (s *ResourceStateEventsService) ListMergeStateEvents(pid any, request int64, opt *ListStateEventsOptions, options ...RequestOptionFunc) ([]*StateEvent, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/merge_requests/%d/resource_state_events", PathEscape(project), request) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var ses []*StateEvent - resp, err := s.client.Do(req, &ses) - if err != nil { - return nil, resp, err - } - - return ses, resp, nil + return do[[]*StateEvent](s.client, + withPath("projects/%s/merge_requests/%d/resource_state_events", ProjectID{pid}, request), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // GetMergeRequestStateEvent gets a single merge request state event. @@ -144,22 +102,8 @@ func (s *ResourceStateEventsService) ListMergeStateEvents(pid any, request int64 // GitLab API docs: // https://docs.gitlab.com/api/resource_state_events/#get-single-merge-request-state-event func (s *ResourceStateEventsService) GetMergeRequestStateEvent(pid any, request int64, event int64, options ...RequestOptionFunc) (*StateEvent, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/merge_requests/%d/resource_state_events/%d", PathEscape(project), request, event) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - se := new(StateEvent) - resp, err := s.client.Do(req, se) - if err != nil { - return nil, resp, err - } - - return se, resp, nil + return do[*StateEvent](s.client, + withPath("projects/%s/merge_requests/%d/resource_state_events/%d", ProjectID{pid}, request, event), + withRequestOpts(options...), + ) } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/resource_weight_events.go b/vendor/gitlab.com/gitlab-org/api/client-go/resource_weight_events.go index 4bf9a121..7d6d8b53 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/resource_weight_events.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/resource_weight_events.go @@ -17,8 +17,6 @@ package gitlab import ( - "fmt" - "net/http" "time" ) @@ -67,22 +65,9 @@ type ListWeightEventsOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/resource_weight_events/#list-project-issue-weight-events func (s *ResourceWeightEventsService) ListIssueWeightEvents(pid any, issue int64, opt *ListWeightEventsOptions, options ...RequestOptionFunc) ([]*WeightEvent, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/issues/%d/resource_weight_events", PathEscape(project), issue) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var wes []*WeightEvent - resp, err := s.client.Do(req, &wes) - if err != nil { - return nil, resp, err - } - - return wes, resp, nil + return do[[]*WeightEvent](s.client, + withPath("projects/%s/issues/%d/resource_weight_events", ProjectID{pid}, issue), + withAPIOpts(opt), + withRequestOpts(options...), + ) } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/runner_controller_tokens.go b/vendor/gitlab.com/gitlab-org/api/client-go/runner_controller_tokens.go new file mode 100644 index 00000000..efbc91f2 --- /dev/null +++ b/vendor/gitlab.com/gitlab-org/api/client-go/runner_controller_tokens.go @@ -0,0 +1,125 @@ +package gitlab + +import ( + "net/http" + "time" +) + +type ( + // RunnerControllerTokensServiceInterface handles communication with the runner + // controller token related methods of the GitLab API. This is an admin-only + // endpoint. + // + // Note: This API is experimental and may change or be removed in future versions. + // + // GitLab API docs: https://docs.gitlab.com/api/runner_controller_tokens/ + RunnerControllerTokensServiceInterface interface { + // ListRunnerControllerTokens lists all runner controller tokens. This is an + // admin-only endpoint. + // + // GitLab API docs: https://docs.gitlab.com/api/runner_controller_tokens/#list-all-runner-controller-tokens + ListRunnerControllerTokens(rid int64, opt *ListRunnerControllerTokensOptions, options ...RequestOptionFunc) ([]*RunnerControllerToken, *Response, error) + // GetRunnerControllerToken retrieves a single runner controller token. This + // is an admin-only endpoint. + // + // GitLab API docs: https://docs.gitlab.com/api/runner_controller_tokens/#retrieve-a-single-runner-controller-token + GetRunnerControllerToken(rid int64, tokenID int64, options ...RequestOptionFunc) (*RunnerControllerToken, *Response, error) + // CreateRunnerControllerToken creates a new runner controller token. This is + // an admin-only endpoint. + // + // GitLab API docs: https://docs.gitlab.com/api/runner_controller_tokens/#create-a-runner-controller-token + CreateRunnerControllerToken(rid int64, opt *CreateRunnerControllerTokenOptions, options ...RequestOptionFunc) (*RunnerControllerToken, *Response, error) + // RotateRunnerControllerToken rotates an existing runner controller token. + // This is an admin-only endpoint. + // + // GitLab API docs: https://docs.gitlab.com/api/runner_controller_tokens/#rotate-a-runner-controller-token + RotateRunnerControllerToken(rid int64, tokenID int64, options ...RequestOptionFunc) (*RunnerControllerToken, *Response, error) + // RevokeRunnerControllerToken revokes a runner controller token. This is an + // admin-only endpoint. + // + // GitLab API docs: https://docs.gitlab.com/api/runner_controller_tokens/#revoke-a-runner-controller-token + RevokeRunnerControllerToken(rid int64, tokenID int64, options ...RequestOptionFunc) (*Response, error) + } + + // RunnerControllerTokensService handles communication with the runner + // controller token related methods of the GitLab API. This is an admin-only + // endpoint. + // + // Note: This API is experimental and may change or be removed in future versions. + // + // GitLab API docs: https://docs.gitlab.com/api/runner_controller_tokens/ + RunnerControllerTokensService struct { + client *Client + } +) + +var _ RunnerControllerTokensServiceInterface = (*RunnerControllerTokensService)(nil) + +// RunnerControllerToken represents a GitLab runner controller token. +// +// GitLab API docs: https://docs.gitlab.com/api/runner_controller_tokens/ +type RunnerControllerToken struct { + ID int64 `json:"id"` + RunnerControllerID int64 `json:"runner_controller_id"` + Description string `json:"description"` + Token string `json:"token,omitempty"` + CreatedAt *time.Time `json:"created_at"` + UpdatedAt *time.Time `json:"updated_at"` +} + +// ListRunnerControllerTokensOptions represents the available +// ListRunnerControllerTokens() options. +// +// GitLab API docs: https://docs.gitlab.com/api/runner_controller_tokens/#list-all-runner-controller-tokens +type ListRunnerControllerTokensOptions struct { + ListOptions +} + +func (s *RunnerControllerTokensService) ListRunnerControllerTokens(rid int64, opt *ListRunnerControllerTokensOptions, options ...RequestOptionFunc) ([]*RunnerControllerToken, *Response, error) { + return do[[]*RunnerControllerToken](s.client, + withPath("runner_controllers/%d/tokens", rid), + withAPIOpts(opt), + withRequestOpts(options...), + ) +} + +func (s *RunnerControllerTokensService) GetRunnerControllerToken(rid int64, tokenID int64, options ...RequestOptionFunc) (*RunnerControllerToken, *Response, error) { + return do[*RunnerControllerToken](s.client, + withPath("runner_controllers/%d/tokens/%d", rid, tokenID), + withRequestOpts(options...), + ) +} + +// CreateRunnerControllerTokenOptions represents the available +// CreateRunnerControllerToken() options. +// +// GitLab API docs: https://docs.gitlab.com/api/runner_controller_tokens/#create-a-runner-controller-token +type CreateRunnerControllerTokenOptions struct { + Description *string `url:"description,omitempty" json:"description,omitempty"` +} + +func (s *RunnerControllerTokensService) CreateRunnerControllerToken(rid int64, opt *CreateRunnerControllerTokenOptions, options ...RequestOptionFunc) (*RunnerControllerToken, *Response, error) { + return do[*RunnerControllerToken](s.client, + withMethod(http.MethodPost), + withPath("runner_controllers/%d/tokens", rid), + withAPIOpts(opt), + withRequestOpts(options...), + ) +} + +func (s *RunnerControllerTokensService) RotateRunnerControllerToken(rid int64, tokenID int64, options ...RequestOptionFunc) (*RunnerControllerToken, *Response, error) { + return do[*RunnerControllerToken](s.client, + withMethod(http.MethodPost), + withPath("runner_controllers/%d/tokens/%d/rotate", rid, tokenID), + withRequestOpts(options...), + ) +} + +func (s *RunnerControllerTokensService) RevokeRunnerControllerToken(rid int64, tokenID int64, options ...RequestOptionFunc) (*Response, error) { + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("runner_controllers/%d/tokens/%d", rid, tokenID), + withRequestOpts(options...), + ) + return resp, err +} diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/runner_controllers.go b/vendor/gitlab.com/gitlab-org/api/client-go/runner_controllers.go new file mode 100644 index 00000000..5732857b --- /dev/null +++ b/vendor/gitlab.com/gitlab-org/api/client-go/runner_controllers.go @@ -0,0 +1,145 @@ +package gitlab + +import ( + "net/http" + "time" +) + +type ( + // RunnerControllersServiceInterface handles communication with the runner + // controller related methods of the GitLab API. This is an admin-only endpoint. + // + // Note: This API is experimental and may change or be removed in future versions. + // + // GitLab API docs: https://docs.gitlab.com/api/runner_controllers/ + RunnerControllersServiceInterface interface { + // ListRunnerControllers gets a list of runner controllers. This is an + // admin-only endpoint. + // + // GitLab API docs: https://docs.gitlab.com/api/runner_controllers/#list-all-runner-controllers + ListRunnerControllers(opt *ListRunnerControllersOptions, options ...RequestOptionFunc) ([]*RunnerController, *Response, error) + // GetRunnerController retrieves a single runner controller. This is an + // admin-only endpoint. + // + // GitLab API docs: https://docs.gitlab.com/api/runner_controllers/#retrieve-a-single-runner-controller + GetRunnerController(rid int64, options ...RequestOptionFunc) (*RunnerController, *Response, error) + // CreateRunnerController registers a new runner controller. This is an + // admin-only endpoint. + // + // GitLab API docs: https://docs.gitlab.com/api/runner_controllers/#register-a-runner-controller + CreateRunnerController(opt *CreateRunnerControllerOptions, options ...RequestOptionFunc) (*RunnerController, *Response, error) + // UpdateRunnerController updates a runner controller. This is an admin-only + // endpoint. + // + // GitLab API docs: https://docs.gitlab.com/api/runner_controllers/#update-a-runner-controller + UpdateRunnerController(rid int64, opt *UpdateRunnerControllerOptions, options ...RequestOptionFunc) (*RunnerController, *Response, error) + // DeleteRunnerController deletes a runner controller. This is an admin-only + // endpoint. + // + // GitLab API docs: https://docs.gitlab.com/api/runner_controllers/#delete-a-runner-controller + DeleteRunnerController(rid int64, options ...RequestOptionFunc) (*Response, error) + } + + // RunnerControllersService handles communication with the runner controller + // related methods of the GitLab API. This is an admin-only endpoint. + // + // Note: This API is experimental and may change or be removed in future versions. + // + // GitLab API docs: https://docs.gitlab.com/api/runner_controllers/ + RunnerControllersService struct { + client *Client + } +) + +var _ RunnerControllersServiceInterface = (*RunnerControllersService)(nil) + +// RunnerControllerStateValue represents the state of a runner controller. +// +// GitLab API docs: https://docs.gitlab.com/api/runner_controllers/ +type RunnerControllerStateValue string + +// These constants represent all valid runner controller states. +const ( + RunnerControllerStateDisabled RunnerControllerStateValue = "disabled" + RunnerControllerStateEnabled RunnerControllerStateValue = "enabled" + RunnerControllerStateDryRun RunnerControllerStateValue = "dry_run" +) + +// RunnerController represents a GitLab runner controller. +// +// GitLab API docs: https://docs.gitlab.com/api/runner_controllers/ +type RunnerController struct { + ID int64 `json:"id"` + Description string `json:"description"` + State RunnerControllerStateValue `json:"state"` + CreatedAt *time.Time `json:"created_at"` + UpdatedAt *time.Time `json:"updated_at"` +} + +// ListRunnerControllersOptions represents the available +// ListRunnerControllers() options. +// +// GitLab API docs: https://docs.gitlab.com/api/runner_controllers/#list-all-runner-controllers +type ListRunnerControllersOptions struct { + ListOptions +} + +func (s *RunnerControllersService) ListRunnerControllers(opt *ListRunnerControllersOptions, options ...RequestOptionFunc) ([]*RunnerController, *Response, error) { + return do[[]*RunnerController](s.client, + withPath("runner_controllers"), + withAPIOpts(opt), + withRequestOpts(options...), + ) +} + +func (s *RunnerControllersService) GetRunnerController(rid int64, options ...RequestOptionFunc) (*RunnerController, *Response, error) { + return do[*RunnerController](s.client, + withPath("runner_controllers/%d", rid), + withRequestOpts(options...), + ) +} + +// CreateRunnerControllerOptions represents the available +// CreateRunnerController() options. +// +// GitLab API docs: https://docs.gitlab.com/api/runner_controllers/#register-a-runner-controller +type CreateRunnerControllerOptions struct { + Description *string `url:"description,omitempty" json:"description,omitempty"` + State *RunnerControllerStateValue `url:"state,omitempty" json:"state,omitempty"` +} + +func (s *RunnerControllersService) CreateRunnerController(opt *CreateRunnerControllerOptions, options ...RequestOptionFunc) (*RunnerController, *Response, error) { + return do[*RunnerController](s.client, + withMethod(http.MethodPost), + withPath("runner_controllers"), + withAPIOpts(opt), + withRequestOpts(options...), + ) +} + +// UpdateRunnerControllerOptions represents the available +// UpdateRunnerController() options. +// +// GitLab API docs: https://docs.gitlab.com/api/runner_controllers/#update-a-runner-controller +type UpdateRunnerControllerOptions struct { + Description *string `url:"description,omitempty" json:"description,omitempty"` + State *RunnerControllerStateValue `url:"state,omitempty" json:"state,omitempty"` +} + +func (s *RunnerControllersService) UpdateRunnerController(rid int64, opt *UpdateRunnerControllerOptions, options ...RequestOptionFunc) (*RunnerController, *Response, error) { + return do[*RunnerController](s.client, + withMethod(http.MethodPut), + withPath("runner_controllers/%d", rid), + withAPIOpts(opt), + withRequestOpts(options...), + ) +} + +func (s *RunnerControllersService) DeleteRunnerController(rid int64, options ...RequestOptionFunc) (*Response, error) { + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("runner_controllers/%d", rid), + withRequestOpts(options...), + ) + return resp, err +} diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/runners.go b/vendor/gitlab.com/gitlab-org/api/client-go/runners.go index 69399a7e..0edf46f0 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/runners.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/runners.go @@ -24,20 +24,83 @@ import ( type ( RunnersServiceInterface interface { + // ListRunners gets a list of runners accessible by the authenticated user. + // + // GitLab API docs: + // https://docs.gitlab.com/api/runners/#list-owned-runners ListRunners(opt *ListRunnersOptions, options ...RequestOptionFunc) ([]*Runner, *Response, error) + // ListAllRunners gets a list of all runners in the GitLab instance. Access is + // restricted to users with admin privileges. + // + // GitLab API docs: + // https://docs.gitlab.com/api/runners/#list-all-runners ListAllRunners(opt *ListRunnersOptions, options ...RequestOptionFunc) ([]*Runner, *Response, error) + // GetRunnerDetails returns details for given runner. + // + // GitLab API docs: + // https://docs.gitlab.com/api/runners/#get-runners-details GetRunnerDetails(rid any, options ...RequestOptionFunc) (*RunnerDetails, *Response, error) + // UpdateRunnerDetails updates details for a given runner. + // + // GitLab API docs: + // https://docs.gitlab.com/api/runners/#update-runners-details UpdateRunnerDetails(rid any, opt *UpdateRunnerDetailsOptions, options ...RequestOptionFunc) (*RunnerDetails, *Response, error) + // RemoveRunner removes a runner. + // + // GitLab API docs: + // https://docs.gitlab.com/api/runners/#delete-a-runner RemoveRunner(rid any, options ...RequestOptionFunc) (*Response, error) + // ListRunnerJobs gets a list of jobs that are being processed or were processed by specified Runner. + // + // GitLab API docs: + // https://docs.gitlab.com/api/runners/#list-jobs-processed-by-a-runner ListRunnerJobs(rid any, opt *ListRunnerJobsOptions, options ...RequestOptionFunc) ([]*Job, *Response, error) + // ListProjectRunners gets a list of runners accessible by the authenticated user. + // + // GitLab API docs: + // https://docs.gitlab.com/api/runners/#list-projects-runners ListProjectRunners(pid any, opt *ListProjectRunnersOptions, options ...RequestOptionFunc) ([]*Runner, *Response, error) + // EnableProjectRunner enables an available specific runner in the project. + // + // GitLab API docs: + // https://docs.gitlab.com/api/runners/#assign-a-runner-to-project EnableProjectRunner(pid any, opt *EnableProjectRunnerOptions, options ...RequestOptionFunc) (*Runner, *Response, error) + // DisableProjectRunner disables a specific runner from project. + // + // GitLab API docs: + // https://docs.gitlab.com/api/runners/#unassign-a-runner-from-project DisableProjectRunner(pid any, runner int64, options ...RequestOptionFunc) (*Response, error) + // ListGroupsRunners lists all runners (specific and shared) available in the + // group as well it's ancestor groups. Shared runners are listed if at least one + // shared runner is defined. + // + // GitLab API docs: + // https://docs.gitlab.com/api/runners/#list-groups-runners ListGroupsRunners(gid any, opt *ListGroupsRunnersOptions, options ...RequestOptionFunc) ([]*Runner, *Response, error) + // RegisterNewRunner registers a new Runner for the instance. + // + // GitLab API docs: + // https://docs.gitlab.com/api/runners/#create-a-runner RegisterNewRunner(opt *RegisterNewRunnerOptions, options ...RequestOptionFunc) (*Runner, *Response, error) + // DeleteRegisteredRunner deletes a Runner by Token. + // + // GitLab API docs: + // https://docs.gitlab.com/api/runners/#delete-a-runner-by-authentication-token DeleteRegisteredRunner(opt *DeleteRegisteredRunnerOptions, options ...RequestOptionFunc) (*Response, error) + // DeleteRegisteredRunnerByID deletes a runner by ID. + // + // GitLab API docs: + // https://docs.gitlab.com/api/runners/#delete-a-runner-by-id DeleteRegisteredRunnerByID(rid int64, options ...RequestOptionFunc) (*Response, error) + // VerifyRegisteredRunner registers a new runner for the instance. + // + // GitLab API docs: + // https://docs.gitlab.com/api/runners/#verify-authentication-for-a-registered-runner VerifyRegisteredRunner(opt *VerifyRegisteredRunnerOptions, options ...RequestOptionFunc) (*Response, error) + // ResetRunnerAuthenticationToken resets a runner's authentication token. + // + // GitLab API docs: + // https://docs.gitlab.com/api/runners/#reset-runners-authentication-token-by-using-the-runner-id ResetRunnerAuthenticationToken(rid int64, options ...RequestOptionFunc) (*RunnerAuthenticationToken, *Response, error) // Deprecated: for removal in GitLab 20.0, see https://docs.gitlab.com/ci/runners/new_creation_workflow/ instead @@ -160,10 +223,6 @@ type ListRunnersOptions struct { Scope *string `url:"scope,omitempty" json:"scope,omitempty"` } -// ListRunners gets a list of runners accessible by the authenticated user. -// -// GitLab API docs: -// https://docs.gitlab.com/api/runners/#list-owned-runners func (s *RunnersService) ListRunners(opt *ListRunnersOptions, options ...RequestOptionFunc) ([]*Runner, *Response, error) { res, resp, err := do[[]*Runner](s.client, withMethod(http.MethodGet), @@ -177,11 +236,6 @@ func (s *RunnersService) ListRunners(opt *ListRunnersOptions, options ...Request return res, resp, nil } -// ListAllRunners gets a list of all runners in the GitLab instance. Access is -// restricted to users with admin privileges. -// -// GitLab API docs: -// https://docs.gitlab.com/api/runners/#list-all-runners func (s *RunnersService) ListAllRunners(opt *ListRunnersOptions, options ...RequestOptionFunc) ([]*Runner, *Response, error) { res, resp, err := do[[]*Runner](s.client, withMethod(http.MethodGet), @@ -195,10 +249,6 @@ func (s *RunnersService) ListAllRunners(opt *ListRunnersOptions, options ...Requ return res, resp, nil } -// GetRunnerDetails returns details for given runner. -// -// GitLab API docs: -// https://docs.gitlab.com/api/runners/#get-runners-details func (s *RunnersService) GetRunnerDetails(rid any, options ...RequestOptionFunc) (*RunnerDetails, *Response, error) { res, resp, err := do[*RunnerDetails](s.client, withMethod(http.MethodGet), @@ -230,10 +280,6 @@ type UpdateRunnerDetailsOptions struct { Active *bool `url:"active,omitempty" json:"active,omitempty"` } -// UpdateRunnerDetails updates details for a given runner. -// -// GitLab API docs: -// https://docs.gitlab.com/api/runners/#update-runners-details func (s *RunnersService) UpdateRunnerDetails(rid any, opt *UpdateRunnerDetailsOptions, options ...RequestOptionFunc) (*RunnerDetails, *Response, error) { res, resp, err := do[*RunnerDetails](s.client, withMethod(http.MethodPut), @@ -247,10 +293,6 @@ func (s *RunnersService) UpdateRunnerDetails(rid any, opt *UpdateRunnerDetailsOp return res, resp, nil } -// RemoveRunner removes a runner. -// -// GitLab API docs: -// https://docs.gitlab.com/api/runners/#delete-a-runner func (s *RunnersService) RemoveRunner(rid any, options ...RequestOptionFunc) (*Response, error) { _, resp, err := do[none](s.client, withMethod(http.MethodDelete), @@ -273,10 +315,6 @@ type ListRunnerJobsOptions struct { Sort *string `url:"sort,omitempty" json:"sort,omitempty"` } -// ListRunnerJobs gets a list of jobs that are being processed or were processed by specified Runner. -// -// GitLab API docs: -// https://docs.gitlab.com/api/runners/#list-jobs-processed-by-a-runner func (s *RunnersService) ListRunnerJobs(rid any, opt *ListRunnerJobsOptions, options ...RequestOptionFunc) ([]*Job, *Response, error) { res, resp, err := do[[]*Job](s.client, withMethod(http.MethodGet), @@ -297,10 +335,6 @@ func (s *RunnersService) ListRunnerJobs(rid any, opt *ListRunnerJobsOptions, opt // https://docs.gitlab.com/api/runners/#list-projects-runners type ListProjectRunnersOptions ListRunnersOptions -// ListProjectRunners gets a list of runners accessible by the authenticated user. -// -// GitLab API docs: -// https://docs.gitlab.com/api/runners/#list-projects-runners func (s *RunnersService) ListProjectRunners(pid any, opt *ListProjectRunnersOptions, options ...RequestOptionFunc) ([]*Runner, *Response, error) { res, resp, err := do[[]*Runner](s.client, withMethod(http.MethodGet), @@ -323,10 +357,6 @@ type EnableProjectRunnerOptions struct { RunnerID int64 `json:"runner_id"` } -// EnableProjectRunner enables an available specific runner in the project. -// -// GitLab API docs: -// https://docs.gitlab.com/api/runners/#assign-a-runner-to-project func (s *RunnersService) EnableProjectRunner(pid any, opt *EnableProjectRunnerOptions, options ...RequestOptionFunc) (*Runner, *Response, error) { res, resp, err := do[*Runner](s.client, withMethod(http.MethodPost), @@ -340,10 +370,6 @@ func (s *RunnersService) EnableProjectRunner(pid any, opt *EnableProjectRunnerOp return res, resp, nil } -// DisableProjectRunner disables a specific runner from project. -// -// GitLab API docs: -// https://docs.gitlab.com/api/runners/#unassign-a-runner-from-project func (s *RunnersService) DisableProjectRunner(pid any, runner int64, options ...RequestOptionFunc) (*Response, error) { _, resp, err := do[none](s.client, withMethod(http.MethodDelete), @@ -365,12 +391,6 @@ type ListGroupsRunnersOptions struct { TagList *[]string `url:"tag_list,comma,omitempty" json:"tag_list,omitempty"` } -// ListGroupsRunners lists all runners (specific and shared) available in the -// group as well it's ancestor groups. Shared runners are listed if at least one -// shared runner is defined. -// -// GitLab API docs: -// https://docs.gitlab.com/api/runners/#list-groups-runners func (s *RunnersService) ListGroupsRunners(gid any, opt *ListGroupsRunnersOptions, options ...RequestOptionFunc) ([]*Runner, *Response, error) { res, resp, err := do[[]*Runner](s.client, withMethod(http.MethodGet), @@ -418,10 +438,6 @@ type RegisterNewRunnerInfoOptions struct { Architecture *string `url:"architecture,omitempty" json:"architecture,omitempty"` } -// RegisterNewRunner registers a new Runner for the instance. -// -// GitLab API docs: -// https://docs.gitlab.com/api/runners/#create-a-runner func (s *RunnersService) RegisterNewRunner(opt *RegisterNewRunnerOptions, options ...RequestOptionFunc) (*Runner, *Response, error) { res, resp, err := do[*Runner](s.client, withMethod(http.MethodPost), @@ -444,10 +460,6 @@ type DeleteRegisteredRunnerOptions struct { Token *string `url:"token" json:"token"` } -// DeleteRegisteredRunner deletes a Runner by Token. -// -// GitLab API docs: -// https://docs.gitlab.com/api/runners/#delete-a-runner-by-authentication-token func (s *RunnersService) DeleteRegisteredRunner(opt *DeleteRegisteredRunnerOptions, options ...RequestOptionFunc) (*Response, error) { _, resp, err := do[none](s.client, withMethod(http.MethodDelete), @@ -458,10 +470,6 @@ func (s *RunnersService) DeleteRegisteredRunner(opt *DeleteRegisteredRunnerOptio return resp, err } -// DeleteRegisteredRunnerByID deletes a runner by ID. -// -// GitLab API docs: -// https://docs.gitlab.com/api/runners/#delete-a-runner-by-id func (s *RunnersService) DeleteRegisteredRunnerByID(rid int64, options ...RequestOptionFunc) (*Response, error) { _, resp, err := do[none](s.client, withMethod(http.MethodDelete), @@ -481,10 +489,6 @@ type VerifyRegisteredRunnerOptions struct { Token *string `url:"token" json:"token"` } -// VerifyRegisteredRunner registers a new runner for the instance. -// -// GitLab API docs: -// https://docs.gitlab.com/api/runners/#verify-authentication-for-a-registered-runner func (s *RunnersService) VerifyRegisteredRunner(opt *VerifyRegisteredRunnerOptions, options ...RequestOptionFunc) (*Response, error) { _, resp, err := do[none](s.client, withMethod(http.MethodPost), @@ -560,10 +564,6 @@ type RunnerAuthenticationToken struct { TokenExpiresAt *time.Time `url:"token_expires_at" json:"token_expires_at"` } -// ResetRunnerAuthenticationToken resets a runner's authentication token. -// -// GitLab API docs: -// https://docs.gitlab.com/api/runners/#reset-runners-authentication-token-by-using-the-runner-id func (s *RunnersService) ResetRunnerAuthenticationToken(rid int64, options ...RequestOptionFunc) (*RunnerAuthenticationToken, *Response, error) { res, resp, err := do[*RunnerAuthenticationToken](s.client, withMethod(http.MethodPost), diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/search.go b/vendor/gitlab.com/gitlab-org/api/client-go/search.go index 33276d59..baec55b6 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/search.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/search.go @@ -16,11 +16,6 @@ package gitlab -import ( - "fmt" - "net/http" -) - type ( SearchServiceInterface interface { Projects(query string, opt *SearchOptions, options ...RequestOptionFunc) ([]*Project, *Response, error) @@ -79,9 +74,11 @@ type searchOptions struct { // // GitLab API docs: https://docs.gitlab.com/api/search/#scope-projects func (s *SearchService) Projects(query string, opt *SearchOptions, options ...RequestOptionFunc) ([]*Project, *Response, error) { - var ps []*Project - resp, err := s.search("projects", query, &ps, opt, options...) - return ps, resp, err + return do[[]*Project](s.client, + withPath("search"), + withAPIOpts(&searchOptions{SearchOptions: *opt, Scope: "projects", Search: query}), + withRequestOpts(options...), + ) } // ProjectsByGroup searches the expression within projects for @@ -89,18 +86,22 @@ func (s *SearchService) Projects(query string, opt *SearchOptions, options ...Re // // GitLab API docs: https://docs.gitlab.com/api/search/#group-search-api func (s *SearchService) ProjectsByGroup(gid any, query string, opt *SearchOptions, options ...RequestOptionFunc) ([]*Project, *Response, error) { - var ps []*Project - resp, err := s.searchByGroup(gid, "projects", query, &ps, opt, options...) - return ps, resp, err + return do[[]*Project](s.client, + withPath("groups/%s/-/search", GroupID{gid}), + withAPIOpts(&searchOptions{SearchOptions: *opt, Scope: "projects", Search: query}), + withRequestOpts(options...), + ) } // Issues searches the expression within issues // // GitLab API docs: https://docs.gitlab.com/api/search/#scope-issues func (s *SearchService) Issues(query string, opt *SearchOptions, options ...RequestOptionFunc) ([]*Issue, *Response, error) { - var is []*Issue - resp, err := s.search("issues", query, &is, opt, options...) - return is, resp, err + return do[[]*Issue](s.client, + withPath("search"), + withAPIOpts(&searchOptions{SearchOptions: *opt, Scope: "issues", Search: query}), + withRequestOpts(options...), + ) } // IssuesByGroup searches the expression within issues for @@ -108,9 +109,11 @@ func (s *SearchService) Issues(query string, opt *SearchOptions, options ...Requ // // GitLab API docs: https://docs.gitlab.com/api/search/#scope-issues-1 func (s *SearchService) IssuesByGroup(gid any, query string, opt *SearchOptions, options ...RequestOptionFunc) ([]*Issue, *Response, error) { - var is []*Issue - resp, err := s.searchByGroup(gid, "issues", query, &is, opt, options...) - return is, resp, err + return do[[]*Issue](s.client, + withPath("groups/%s/-/search", GroupID{gid}), + withAPIOpts(&searchOptions{SearchOptions: *opt, Scope: "issues", Search: query}), + withRequestOpts(options...), + ) } // IssuesByProject searches the expression within issues for @@ -118,9 +121,11 @@ func (s *SearchService) IssuesByGroup(gid any, query string, opt *SearchOptions, // // GitLab API docs: https://docs.gitlab.com/api/search/#scope-issues-2 func (s *SearchService) IssuesByProject(pid any, query string, opt *SearchOptions, options ...RequestOptionFunc) ([]*Issue, *Response, error) { - var is []*Issue - resp, err := s.searchByProject(pid, "issues", query, &is, opt, options...) - return is, resp, err + return do[[]*Issue](s.client, + withPath("projects/%s/-/search", ProjectID{pid}), + withAPIOpts(&searchOptions{SearchOptions: *opt, Scope: "issues", Search: query}), + withRequestOpts(options...), + ) } // MergeRequests searches the expression within merge requests @@ -128,9 +133,11 @@ func (s *SearchService) IssuesByProject(pid any, query string, opt *SearchOption // GitLab API docs: // https://docs.gitlab.com/api/search/#scope-merge_requests func (s *SearchService) MergeRequests(query string, opt *SearchOptions, options ...RequestOptionFunc) ([]*MergeRequest, *Response, error) { - var ms []*MergeRequest - resp, err := s.search("merge_requests", query, &ms, opt, options...) - return ms, resp, err + return do[[]*MergeRequest](s.client, + withPath("search"), + withAPIOpts(&searchOptions{SearchOptions: *opt, Scope: "merge_requests", Search: query}), + withRequestOpts(options...), + ) } // MergeRequestsByGroup searches the expression within merge requests for @@ -139,9 +146,11 @@ func (s *SearchService) MergeRequests(query string, opt *SearchOptions, options // GitLab API docs: // https://docs.gitlab.com/api/search/#scope-merge_requests-1 func (s *SearchService) MergeRequestsByGroup(gid any, query string, opt *SearchOptions, options ...RequestOptionFunc) ([]*MergeRequest, *Response, error) { - var ms []*MergeRequest - resp, err := s.searchByGroup(gid, "merge_requests", query, &ms, opt, options...) - return ms, resp, err + return do[[]*MergeRequest](s.client, + withPath("groups/%s/-/search", GroupID{gid}), + withAPIOpts(&searchOptions{SearchOptions: *opt, Scope: "merge_requests", Search: query}), + withRequestOpts(options...), + ) } // MergeRequestsByProject searches the expression within merge requests for @@ -150,18 +159,22 @@ func (s *SearchService) MergeRequestsByGroup(gid any, query string, opt *SearchO // GitLab API docs: // https://docs.gitlab.com/api/search/#scope-merge_requests-2 func (s *SearchService) MergeRequestsByProject(pid any, query string, opt *SearchOptions, options ...RequestOptionFunc) ([]*MergeRequest, *Response, error) { - var ms []*MergeRequest - resp, err := s.searchByProject(pid, "merge_requests", query, &ms, opt, options...) - return ms, resp, err + return do[[]*MergeRequest](s.client, + withPath("projects/%s/-/search", ProjectID{pid}), + withAPIOpts(&searchOptions{SearchOptions: *opt, Scope: "merge_requests", Search: query}), + withRequestOpts(options...), + ) } // Milestones searches the expression within milestones // // GitLab API docs: https://docs.gitlab.com/api/search/#scope-milestones func (s *SearchService) Milestones(query string, opt *SearchOptions, options ...RequestOptionFunc) ([]*Milestone, *Response, error) { - var ms []*Milestone - resp, err := s.search("milestones", query, &ms, opt, options...) - return ms, resp, err + return do[[]*Milestone](s.client, + withPath("search"), + withAPIOpts(&searchOptions{SearchOptions: *opt, Scope: "milestones", Search: query}), + withRequestOpts(options...), + ) } // MilestonesByGroup searches the expression within milestones for @@ -169,9 +182,11 @@ func (s *SearchService) Milestones(query string, opt *SearchOptions, options ... // // GitLab API docs: https://docs.gitlab.com/api/search/#scope-milestones-1 func (s *SearchService) MilestonesByGroup(gid any, query string, opt *SearchOptions, options ...RequestOptionFunc) ([]*Milestone, *Response, error) { - var ms []*Milestone - resp, err := s.searchByGroup(gid, "milestones", query, &ms, opt, options...) - return ms, resp, err + return do[[]*Milestone](s.client, + withPath("groups/%s/-/search", GroupID{gid}), + withAPIOpts(&searchOptions{SearchOptions: *opt, Scope: "milestones", Search: query}), + withRequestOpts(options...), + ) } // MilestonesByProject searches the expression within milestones for @@ -179,9 +194,11 @@ func (s *SearchService) MilestonesByGroup(gid any, query string, opt *SearchOpti // // GitLab API docs: https://docs.gitlab.com/api/search/#scope-milestones-2 func (s *SearchService) MilestonesByProject(pid any, query string, opt *SearchOptions, options ...RequestOptionFunc) ([]*Milestone, *Response, error) { - var ms []*Milestone - resp, err := s.searchByProject(pid, "milestones", query, &ms, opt, options...) - return ms, resp, err + return do[[]*Milestone](s.client, + withPath("projects/%s/-/search", ProjectID{pid}), + withAPIOpts(&searchOptions{SearchOptions: *opt, Scope: "milestones", Search: query}), + withRequestOpts(options...), + ) } // SnippetTitles searches the expression within snippet titles @@ -189,9 +206,11 @@ func (s *SearchService) MilestonesByProject(pid any, query string, opt *SearchOp // GitLab API docs: // https://docs.gitlab.com/api/search/#scope-snippet_titles func (s *SearchService) SnippetTitles(query string, opt *SearchOptions, options ...RequestOptionFunc) ([]*Snippet, *Response, error) { - var ss []*Snippet - resp, err := s.search("snippet_titles", query, &ss, opt, options...) - return ss, resp, err + return do[[]*Snippet](s.client, + withPath("search"), + withAPIOpts(&searchOptions{SearchOptions: *opt, Scope: "snippet_titles", Search: query}), + withRequestOpts(options...), + ) } // NotesByProject searches the expression within notes for the specified @@ -199,9 +218,11 @@ func (s *SearchService) SnippetTitles(query string, opt *SearchOptions, options // // GitLab API docs: // https://docs.gitlab.com/api/search/#scope-notes func (s *SearchService) NotesByProject(pid any, query string, opt *SearchOptions, options ...RequestOptionFunc) ([]*Note, *Response, error) { - var ns []*Note - resp, err := s.searchByProject(pid, "notes", query, &ns, opt, options...) - return ns, resp, err + return do[[]*Note](s.client, + withPath("projects/%s/-/search", ProjectID{pid}), + withAPIOpts(&searchOptions{SearchOptions: *opt, Scope: "notes", Search: query}), + withRequestOpts(options...), + ) } // WikiBlobs searches the expression within all wiki blobs @@ -209,9 +230,11 @@ func (s *SearchService) NotesByProject(pid any, query string, opt *SearchOptions // GitLab API docs: // https://docs.gitlab.com/api/search/#scope-wiki_blobs func (s *SearchService) WikiBlobs(query string, opt *SearchOptions, options ...RequestOptionFunc) ([]*Wiki, *Response, error) { - var ws []*Wiki - resp, err := s.search("wiki_blobs", query, &ws, opt, options...) - return ws, resp, err + return do[[]*Wiki](s.client, + withPath("search"), + withAPIOpts(&searchOptions{SearchOptions: *opt, Scope: "wiki_blobs", Search: query}), + withRequestOpts(options...), + ) } // WikiBlobsByGroup searches the expression within wiki blobs for @@ -220,9 +243,11 @@ func (s *SearchService) WikiBlobs(query string, opt *SearchOptions, options ...R // GitLab API docs: // https://docs.gitlab.com/api/search/#scope-wiki_blobs-1 func (s *SearchService) WikiBlobsByGroup(gid any, query string, opt *SearchOptions, options ...RequestOptionFunc) ([]*Wiki, *Response, error) { - var ws []*Wiki - resp, err := s.searchByGroup(gid, "wiki_blobs", query, &ws, opt, options...) - return ws, resp, err + return do[[]*Wiki](s.client, + withPath("groups/%s/-/search", GroupID{gid}), + withAPIOpts(&searchOptions{SearchOptions: *opt, Scope: "wiki_blobs", Search: query}), + withRequestOpts(options...), + ) } // WikiBlobsByProject searches the expression within wiki blobs for @@ -231,18 +256,22 @@ func (s *SearchService) WikiBlobsByGroup(gid any, query string, opt *SearchOptio // GitLab API docs: // https://docs.gitlab.com/api/search/#scope-wiki_blobs-2 func (s *SearchService) WikiBlobsByProject(pid any, query string, opt *SearchOptions, options ...RequestOptionFunc) ([]*Wiki, *Response, error) { - var ws []*Wiki - resp, err := s.searchByProject(pid, "wiki_blobs", query, &ws, opt, options...) - return ws, resp, err + return do[[]*Wiki](s.client, + withPath("projects/%s/-/search", ProjectID{pid}), + withAPIOpts(&searchOptions{SearchOptions: *opt, Scope: "wiki_blobs", Search: query}), + withRequestOpts(options...), + ) } // Commits searches the expression within all commits // // GitLab API docs: https://docs.gitlab.com/api/search/#scope-commits func (s *SearchService) Commits(query string, opt *SearchOptions, options ...RequestOptionFunc) ([]*Commit, *Response, error) { - var cs []*Commit - resp, err := s.search("commits", query, &cs, opt, options...) - return cs, resp, err + return do[[]*Commit](s.client, + withPath("search"), + withAPIOpts(&searchOptions{SearchOptions: *opt, Scope: "commits", Search: query}), + withRequestOpts(options...), + ) } // CommitsByGroup searches the expression within commits for the specified @@ -250,9 +279,11 @@ func (s *SearchService) Commits(query string, opt *SearchOptions, options ...Req // // GitLab API docs: https://docs.gitlab.com/api/search/#scope-commits-1 func (s *SearchService) CommitsByGroup(gid any, query string, opt *SearchOptions, options ...RequestOptionFunc) ([]*Commit, *Response, error) { - var cs []*Commit - resp, err := s.searchByGroup(gid, "commits", query, &cs, opt, options...) - return cs, resp, err + return do[[]*Commit](s.client, + withPath("groups/%s/-/search", GroupID{gid}), + withAPIOpts(&searchOptions{SearchOptions: *opt, Scope: "commits", Search: query}), + withRequestOpts(options...), + ) } // CommitsByProject searches the expression within commits for the @@ -260,9 +291,11 @@ func (s *SearchService) CommitsByGroup(gid any, query string, opt *SearchOptions // // GitLab API docs: https://docs.gitlab.com/api/search/#scope-commits-2 func (s *SearchService) CommitsByProject(pid any, query string, opt *SearchOptions, options ...RequestOptionFunc) ([]*Commit, *Response, error) { - var cs []*Commit - resp, err := s.searchByProject(pid, "commits", query, &cs, opt, options...) - return cs, resp, err + return do[[]*Commit](s.client, + withPath("projects/%s/-/search", ProjectID{pid}), + withAPIOpts(&searchOptions{SearchOptions: *opt, Scope: "commits", Search: query}), + withRequestOpts(options...), + ) } // Blob represents a single blob. @@ -281,9 +314,11 @@ type Blob struct { // // GitLab API docs: https://docs.gitlab.com/api/search/#scope-blobs func (s *SearchService) Blobs(query string, opt *SearchOptions, options ...RequestOptionFunc) ([]*Blob, *Response, error) { - var bs []*Blob - resp, err := s.search("blobs", query, &bs, opt, options...) - return bs, resp, err + return do[[]*Blob](s.client, + withPath("search"), + withAPIOpts(&searchOptions{SearchOptions: *opt, Scope: "blobs", Search: query}), + withRequestOpts(options...), + ) } // BlobsByGroup searches the expression within blobs for the specified @@ -291,9 +326,11 @@ func (s *SearchService) Blobs(query string, opt *SearchOptions, options ...Reque // // GitLab API docs: https://docs.gitlab.com/api/search/#scope-blobs-1 func (s *SearchService) BlobsByGroup(gid any, query string, opt *SearchOptions, options ...RequestOptionFunc) ([]*Blob, *Response, error) { - var bs []*Blob - resp, err := s.searchByGroup(gid, "blobs", query, &bs, opt, options...) - return bs, resp, err + return do[[]*Blob](s.client, + withPath("groups/%s/-/search", GroupID{gid}), + withAPIOpts(&searchOptions{SearchOptions: *opt, Scope: "blobs", Search: query}), + withRequestOpts(options...), + ) } // BlobsByProject searches the expression within blobs for the specified @@ -301,18 +338,22 @@ func (s *SearchService) BlobsByGroup(gid any, query string, opt *SearchOptions, // // GitLab API docs: https://docs.gitlab.com/api/search/#scope-blobs-2 func (s *SearchService) BlobsByProject(pid any, query string, opt *SearchOptions, options ...RequestOptionFunc) ([]*Blob, *Response, error) { - var bs []*Blob - resp, err := s.searchByProject(pid, "blobs", query, &bs, opt, options...) - return bs, resp, err + return do[[]*Blob](s.client, + withPath("projects/%s/-/search", ProjectID{pid}), + withAPIOpts(&searchOptions{SearchOptions: *opt, Scope: "blobs", Search: query}), + withRequestOpts(options...), + ) } // Users searches the expression within all users // // GitLab API docs: https://docs.gitlab.com/api/search/#scope-users func (s *SearchService) Users(query string, opt *SearchOptions, options ...RequestOptionFunc) ([]*User, *Response, error) { - var ret []*User - resp, err := s.search("users", query, &ret, opt, options...) - return ret, resp, err + return do[[]*User](s.client, + withPath("search"), + withAPIOpts(&searchOptions{SearchOptions: *opt, Scope: "users", Search: query}), + withRequestOpts(options...), + ) } // UsersByGroup searches the expression within users for the specified @@ -323,9 +364,11 @@ func (s *SearchService) UsersByGroup(gid any, query string, opt *SearchOptions, if opt == nil { opt = &SearchOptions{} } - var ret []*User - resp, err := s.searchByGroup(gid, "users", query, &ret, opt, options...) - return ret, resp, err + return do[[]*User](s.client, + withPath("groups/%s/-/search", GroupID{gid}), + withAPIOpts(&searchOptions{SearchOptions: *opt, Scope: "users", Search: query}), + withRequestOpts(options...), + ) } // UsersByProject searches the expression within users for the @@ -333,52 +376,9 @@ func (s *SearchService) UsersByGroup(gid any, query string, opt *SearchOptions, // // GitLab API docs: https://docs.gitlab.com/api/search/#scope-users-2 func (s *SearchService) UsersByProject(pid any, query string, opt *SearchOptions, options ...RequestOptionFunc) ([]*User, *Response, error) { - var ret []*User - resp, err := s.searchByProject(pid, "users", query, &ret, opt, options...) - return ret, resp, err -} - -func (s *SearchService) search(scope, query string, result any, opt *SearchOptions, options ...RequestOptionFunc) (*Response, error) { - opts := &searchOptions{SearchOptions: *opt, Scope: scope, Search: query} - - req, err := s.client.NewRequest(http.MethodGet, "search", opts, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, result) -} - -func (s *SearchService) searchByGroup(gid any, scope, query string, result any, opt *SearchOptions, options ...RequestOptionFunc) (*Response, error) { - group, err := parseID(gid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("groups/%s/-/search", PathEscape(group)) - - opts := &searchOptions{SearchOptions: *opt, Scope: scope, Search: query} - - req, err := s.client.NewRequest(http.MethodGet, u, opts, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, result) -} - -func (s *SearchService) searchByProject(pid any, scope, query string, result any, opt *SearchOptions, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/-/search", PathEscape(project)) - - opts := &searchOptions{SearchOptions: *opt, Scope: scope, Search: query} - - req, err := s.client.NewRequest(http.MethodGet, u, opts, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, result) + return do[[]*User](s.client, + withPath("projects/%s/-/search", ProjectID{pid}), + withAPIOpts(&searchOptions{SearchOptions: *opt, Scope: "users", Search: query}), + withRequestOpts(options...), + ) } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/secure_files.go b/vendor/gitlab.com/gitlab-org/api/client-go/secure_files.go index a0f96d1a..1371333c 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/secure_files.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/secure_files.go @@ -15,7 +15,6 @@ package gitlab import ( "bytes" - "fmt" "io" "net/http" "time" @@ -112,23 +111,11 @@ type ListProjectSecureFilesOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/secure_files/#list-project-secure-files func (s SecureFilesService) ListProjectSecureFiles(pid any, opt *ListProjectSecureFilesOptions, options ...RequestOptionFunc) ([]*SecureFile, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/secure_files", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var files []*SecureFile - resp, err := s.client.Do(req, &files) - if err != nil { - return nil, resp, err - } - return files, resp, nil + return do[[]*SecureFile](s.client, + withPath("projects/%s/secure_files", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // ShowSecureFileDetails gets the details of a specific secure file in a project. @@ -136,24 +123,10 @@ func (s SecureFilesService) ListProjectSecureFiles(pid any, opt *ListProjectSecu // GitLab API docs: // https://docs.gitlab.com/api/secure_files/#show-secure-file-details func (s SecureFilesService) ShowSecureFileDetails(pid any, id int64, options ...RequestOptionFunc) (*SecureFile, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/secure_files/%d", PathEscape(project), id) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - file := new(SecureFile) - resp, err := s.client.Do(req, file) - if err != nil { - return nil, resp, err - } - - return file, resp, nil + return do[*SecureFile](s.client, + withPath("projects/%s/secure_files/%d", ProjectID{pid}, id), + withRequestOpts(options...), + ) } // CreateSecureFileOptions represents the available @@ -170,24 +143,13 @@ type CreateSecureFileOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/secure_files/#create-secure-file func (s SecureFilesService) CreateSecureFile(pid any, content io.Reader, opt *CreateSecureFileOptions, options ...RequestOptionFunc) (*SecureFile, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/secure_files", PathEscape(project)) - - req, err := s.client.UploadRequest(http.MethodPost, u, content, *opt.Name, UploadFile, opt, options) - if err != nil { - return nil, nil, err - } - - file := new(SecureFile) - resp, err := s.client.Do(req, file) - if err != nil { - return nil, resp, err - } - - return file, resp, nil + return do[*SecureFile](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/secure_files", ProjectID{pid}), + withUpload(content, *opt.Name, UploadFile), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // DownloadSecureFile downloads the contents of a project's secure file. @@ -195,24 +157,14 @@ func (s SecureFilesService) CreateSecureFile(pid any, content io.Reader, opt *Cr // GitLab API docs: // https://docs.gitlab.com/api/secure_files/#download-secure-file func (s SecureFilesService) DownloadSecureFile(pid any, id int64, options ...RequestOptionFunc) (io.Reader, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/secure_files/%d/download", PathEscape(project), id) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - var file bytes.Buffer - resp, err := s.client.Do(req, &file) + buf, resp, err := do[bytes.Buffer](s.client, + withPath("projects/%s/secure_files/%d/download", ProjectID{pid}, id), + withRequestOpts(options...), + ) if err != nil { return nil, resp, err } - - return &file, resp, err + return &buf, resp, nil } // RemoveSecureFile removes a project's secure file. @@ -220,16 +172,10 @@ func (s SecureFilesService) DownloadSecureFile(pid any, id int64, options ...Req // GitLab API docs: // https://docs.gitlab.com/api/secure_files/#remove-secure-file func (s SecureFilesService) RemoveSecureFile(pid any, id int64, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/secure_files/%d", PathEscape(project), id) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/secure_files/%d", ProjectID{pid}, id), + withRequestOpts(options...), + ) + return resp, err } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/services.go b/vendor/gitlab.com/gitlab-org/api/client-go/services.go index 53a34add..c8eeb0d7 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/services.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/services.go @@ -111,24 +111,10 @@ type Service = Integration // // GitLab API docs: https://docs.gitlab.com/api/project_integrations/#list-all-active-integrations func (s *ServicesService) ListServices(pid any, options ...RequestOptionFunc) ([]*Service, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/services", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - var svcs []*Service - resp, err := s.client.Do(req, &svcs) - if err != nil { - return nil, resp, err - } - - return svcs, resp, nil + return do[[]*Service](s.client, + withPath("projects/%s/services", ProjectID{pid}), + withRequestOpts(options...), + ) } // CustomIssueTrackerService represents Custom Issue Tracker service settings. @@ -155,24 +141,10 @@ type CustomIssueTrackerServiceProperties struct { // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#get-custom-issue-tracker-settings func (s *ServicesService) GetCustomIssueTrackerService(pid any, options ...RequestOptionFunc) (*CustomIssueTrackerService, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/services/custom-issue-tracker", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - svc := new(CustomIssueTrackerService) - resp, err := s.client.Do(req, svc) - if err != nil { - return nil, resp, err - } - - return svc, resp, nil + return do[*CustomIssueTrackerService](s.client, + withPath("projects/%s/services/custom-issue-tracker", ProjectID{pid}), + withRequestOpts(options...), + ) } // SetCustomIssueTrackerServiceOptions represents the available SetCustomIssueTrackerService() @@ -191,24 +163,12 @@ type SetCustomIssueTrackerServiceOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#set-up-a-custom-issue-tracker func (s *ServicesService) SetCustomIssueTrackerService(pid any, opt *SetCustomIssueTrackerServiceOptions, options ...RequestOptionFunc) (*CustomIssueTrackerService, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/services/custom-issue-tracker", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - svc := new(CustomIssueTrackerService) - resp, err := s.client.Do(req, svc) - if err != nil { - return nil, nil, err - } - - return svc, resp, nil + return do[*CustomIssueTrackerService](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/services/custom-issue-tracker", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // DeleteCustomIssueTrackerService deletes Custom Issue Tracker service settings for a project. @@ -216,18 +176,12 @@ func (s *ServicesService) SetCustomIssueTrackerService(pid any, opt *SetCustomIs // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#disable-a-custom-issue-tracker func (s *ServicesService) DeleteCustomIssueTrackerService(pid any, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/services/custom-issue-tracker", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/services/custom-issue-tracker", ProjectID{pid}), + withRequestOpts(options...), + ) + return resp, err } // DataDogService represents DataDog service settings. @@ -259,24 +213,10 @@ type DataDogServiceProperties struct { // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#get-datadog-settings func (s *ServicesService) GetDataDogService(pid any, options ...RequestOptionFunc) (*DataDogService, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/integrations/datadog", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - svc := new(DataDogService) - resp, err := s.client.Do(req, svc) - if err != nil { - return nil, resp, err - } - - return svc, resp, nil + return do[*DataDogService](s.client, + withPath("projects/%s/integrations/datadog", ProjectID{pid}), + withRequestOpts(options...), + ) } // SetDataDogServiceOptions represents the available SetDataDogService() @@ -301,24 +241,12 @@ type SetDataDogServiceOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#set-up-datadog func (s *ServicesService) SetDataDogService(pid any, opt *SetDataDogServiceOptions, options ...RequestOptionFunc) (*DataDogService, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/integrations/datadog", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - svc := new(DataDogService) - resp, err := s.client.Do(req, svc) - if err != nil { - return nil, nil, err - } - - return svc, resp, nil + return do[*DataDogService](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/integrations/datadog", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // DeleteDataDogService deletes the DataDog service settings for a project. @@ -326,18 +254,12 @@ func (s *ServicesService) SetDataDogService(pid any, opt *SetDataDogServiceOptio // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#disable-datadog func (s *ServicesService) DeleteDataDogService(pid any, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/integrations/datadog", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/integrations/datadog", ProjectID{pid}), + withRequestOpts(options...), + ) + return resp, err } // DiscordService represents Discord service settings. @@ -363,24 +285,10 @@ type DiscordServiceProperties struct { // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#get-discord-notifications-settings func (s *ServicesService) GetDiscordService(pid any, options ...RequestOptionFunc) (*DiscordService, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/services/discord", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - svc := new(DiscordService) - resp, err := s.client.Do(req, svc) - if err != nil { - return nil, resp, err - } - - return svc, resp, nil + return do[*DiscordService](s.client, + withPath("projects/%s/services/discord", ProjectID{pid}), + withRequestOpts(options...), + ) } // SetDiscordServiceOptions represents the available SetDiscordService() @@ -423,24 +331,12 @@ type SetDiscordServiceOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#set-up-discord-notifications func (s *ServicesService) SetDiscordService(pid any, opt *SetDiscordServiceOptions, options ...RequestOptionFunc) (*DiscordService, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/services/discord", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - svc := new(DiscordService) - resp, err := s.client.Do(req, svc) - if err != nil { - return nil, resp, err - } - - return svc, resp, nil + return do[*DiscordService](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/services/discord", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // DeleteDiscordService deletes Discord service settings for a project. @@ -448,18 +344,12 @@ func (s *ServicesService) SetDiscordService(pid any, opt *SetDiscordServiceOptio // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#disable-discord-notifications func (s *ServicesService) DeleteDiscordService(pid any, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/services/discord", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/services/discord", ProjectID{pid}), + withRequestOpts(options...), + ) + return resp, err } // DroneCIService represents Drone CI service settings. @@ -485,24 +375,10 @@ type DroneCIServiceProperties struct { // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#get-drone-settings func (s *ServicesService) GetDroneCIService(pid any, options ...RequestOptionFunc) (*DroneCIService, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/services/drone-ci", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - svc := new(DroneCIService) - resp, err := s.client.Do(req, svc) - if err != nil { - return nil, resp, err - } - - return svc, resp, nil + return do[*DroneCIService](s.client, + withPath("projects/%s/services/drone-ci", ProjectID{pid}), + withRequestOpts(options...), + ) } // SetDroneCIServiceOptions represents the available SetDroneCIService() @@ -524,24 +400,12 @@ type SetDroneCIServiceOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#set-up-drone func (s *ServicesService) SetDroneCIService(pid any, opt *SetDroneCIServiceOptions, options ...RequestOptionFunc) (*DroneCIService, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/services/drone-ci", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - svc := new(DroneCIService) - resp, err := s.client.Do(req, svc) - if err != nil { - return nil, nil, err - } - - return svc, resp, nil + return do[*DroneCIService](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/services/drone-ci", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // DeleteDroneCIService deletes Drone CI service settings for a project. @@ -549,18 +413,12 @@ func (s *ServicesService) SetDroneCIService(pid any, opt *SetDroneCIServiceOptio // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#disable-drone func (s *ServicesService) DeleteDroneCIService(pid any, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/services/drone-ci", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/services/drone-ci", ProjectID{pid}), + withRequestOpts(options...), + ) + return resp, err } // EmailsOnPushService represents Emails on Push service settings. @@ -580,9 +438,12 @@ type EmailsOnPushServiceProperties struct { Recipients string `json:"recipients"` DisableDiffs bool `json:"disable_diffs"` SendFromCommitterEmail bool `json:"send_from_committer_email"` - PushEvents bool `json:"push_events"` - TagPushEvents bool `json:"tag_push_events"` BranchesToBeNotified string `json:"branches_to_be_notified"` + + // Deprecated: to be removed in 2.0 - use EmailsOnPushService.PushEvents instead. + PushEvents bool `json:"push_events"` + // Deprecated: to be removed in 2.0 - use EmailsOnPushService.TagPushEvents instead. + TagPushEvents bool `json:"tag_push_events"` } // GetEmailsOnPushService gets Emails on Push service settings for a project. @@ -590,24 +451,10 @@ type EmailsOnPushServiceProperties struct { // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#get-emails-on-push-settings func (s *ServicesService) GetEmailsOnPushService(pid any, options ...RequestOptionFunc) (*EmailsOnPushService, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/integrations/emails-on-push", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - svc := new(EmailsOnPushService) - resp, err := s.client.Do(req, svc) - if err != nil { - return nil, resp, err - } - - return svc, resp, nil + return do[*EmailsOnPushService](s.client, + withPath("projects/%s/integrations/emails-on-push", ProjectID{pid}), + withRequestOpts(options...), + ) } // SetEmailsOnPushServiceOptions represents the available SetEmailsOnPushService() @@ -629,24 +476,12 @@ type SetEmailsOnPushServiceOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#set-up-emails-on-push func (s *ServicesService) SetEmailsOnPushService(pid any, opt *SetEmailsOnPushServiceOptions, options ...RequestOptionFunc) (*EmailsOnPushService, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/integrations/emails-on-push", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - svc := new(EmailsOnPushService) - resp, err := s.client.Do(req, svc) - if err != nil { - return nil, nil, err - } - - return svc, resp, nil + return do[*EmailsOnPushService](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/integrations/emails-on-push", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // DeleteEmailsOnPushService deletes Emails on Push service settings for a project. @@ -654,18 +489,12 @@ func (s *ServicesService) SetEmailsOnPushService(pid any, opt *SetEmailsOnPushSe // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#disable-emails-on-push func (s *ServicesService) DeleteEmailsOnPushService(pid any, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/integrations/emails-on-push", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/integrations/emails-on-push", ProjectID{pid}), + withRequestOpts(options...), + ) + return resp, err } // ExternalWikiService represents External Wiki service settings. @@ -690,24 +519,10 @@ type ExternalWikiServiceProperties struct { // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#get-external-wiki-settings func (s *ServicesService) GetExternalWikiService(pid any, options ...RequestOptionFunc) (*ExternalWikiService, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/services/external-wiki", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - svc := new(ExternalWikiService) - resp, err := s.client.Do(req, svc) - if err != nil { - return nil, resp, err - } - - return svc, resp, nil + return do[*ExternalWikiService](s.client, + withPath("projects/%s/services/external-wiki", ProjectID{pid}), + withRequestOpts(options...), + ) } // SetExternalWikiServiceOptions represents the available SetExternalWikiService() @@ -724,24 +539,12 @@ type SetExternalWikiServiceOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#set-up-an-external-wiki func (s *ServicesService) SetExternalWikiService(pid any, opt *SetExternalWikiServiceOptions, options ...RequestOptionFunc) (*ExternalWikiService, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/services/external-wiki", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - svc := new(ExternalWikiService) - resp, err := s.client.Do(req, svc) - if err != nil { - return nil, nil, err - } - - return svc, resp, nil + return do[*ExternalWikiService](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/services/external-wiki", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // DeleteExternalWikiService deletes External Wiki service for project. @@ -749,18 +552,12 @@ func (s *ServicesService) SetExternalWikiService(pid any, opt *SetExternalWikiSe // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#disable-an-external-wiki func (s *ServicesService) DeleteExternalWikiService(pid any, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/services/external-wiki", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/services/external-wiki", ProjectID{pid}), + withRequestOpts(options...), + ) + return resp, err } // GithubService represents Github service settings. @@ -786,24 +583,10 @@ type GithubServiceProperties struct { // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#get-github-settings func (s *ServicesService) GetGithubService(pid any, options ...RequestOptionFunc) (*GithubService, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/services/github", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - svc := new(GithubService) - resp, err := s.client.Do(req, svc) - if err != nil { - return nil, resp, err - } - - return svc, resp, nil + return do[*GithubService](s.client, + withPath("projects/%s/services/github", ProjectID{pid}), + withRequestOpts(options...), + ) } // SetGithubServiceOptions represents the available SetGithubService() @@ -822,24 +605,12 @@ type SetGithubServiceOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#set-up-github func (s *ServicesService) SetGithubService(pid any, opt *SetGithubServiceOptions, options ...RequestOptionFunc) (*GithubService, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/services/github", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - svc := new(GithubService) - resp, err := s.client.Do(req, svc) - if err != nil { - return nil, nil, err - } - - return svc, resp, nil + return do[*GithubService](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/services/github", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // DeleteGithubService deletes Github service for a project @@ -847,18 +618,12 @@ func (s *ServicesService) SetGithubService(pid any, opt *SetGithubServiceOptions // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#disable-github func (s *ServicesService) DeleteGithubService(pid any, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/services/github", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/services/github", ProjectID{pid}), + withRequestOpts(options...), + ) + return resp, err } // HarborService represents the Harbor service settings. @@ -887,24 +652,10 @@ type HarborServiceProperties struct { // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#get-harbor-settings func (s *ServicesService) GetHarborService(pid any, options ...RequestOptionFunc) (*HarborService, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/integrations/harbor", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - svc := new(HarborService) - resp, err := s.client.Do(req, svc) - if err != nil { - return nil, resp, err - } - - return svc, resp, nil + return do[*HarborService](s.client, + withPath("projects/%s/integrations/harbor", ProjectID{pid}), + withRequestOpts(options...), + ) } // SetHarborServiceOptions represents the available SetHarborService() @@ -919,24 +670,12 @@ type SetHarborServiceOptions = SetUpHarborOptions // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#set-up-harbor func (s *ServicesService) SetHarborService(pid any, opt *SetHarborServiceOptions, options ...RequestOptionFunc) (*HarborService, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/integrations/harbor", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - svc := new(HarborService) - resp, err := s.client.Do(req, svc) - if err != nil { - return nil, nil, err - } - - return svc, resp, nil + return do[*HarborService](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/integrations/harbor", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // DeleteHarborService deletes Harbor service for a project. @@ -944,18 +683,12 @@ func (s *ServicesService) SetHarborService(pid any, opt *SetHarborServiceOptions // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#disable-harbor func (s *ServicesService) DeleteHarborService(pid any, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/integrations/harbor", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/integrations/harbor", ProjectID{pid}), + withRequestOpts(options...), + ) + return resp, err } // SlackApplication represents GitLab for slack application settings. @@ -1001,24 +734,10 @@ type SlackApplicationProperties struct { // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#get-gitlab-for-slack-app-settings func (s *ServicesService) GetSlackApplication(pid any, options ...RequestOptionFunc) (*SlackApplication, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/integrations/gitlab-slack-application", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - svc := new(SlackApplication) - resp, err := s.client.Do(req, svc) - if err != nil { - return nil, resp, err - } - - return svc, resp, nil + return do[*SlackApplication](s.client, + withPath("projects/%s/integrations/gitlab-slack-application", ProjectID{pid}), + withRequestOpts(options...), + ) } // SetSlackApplicationOptions represents the available SetSlackApplication() @@ -1069,24 +788,12 @@ type SetSlackApplicationOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#set-up-gitlab-for-slack-app func (s *ServicesService) SetSlackApplication(pid any, opt *SetSlackApplicationOptions, options ...RequestOptionFunc) (*SlackApplication, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/integrations/gitlab-slack-application", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - svc := new(SlackApplication) - resp, err := s.client.Do(req, svc) - if err != nil { - return nil, nil, err - } - - return svc, resp, nil + return do[*SlackApplication](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/integrations/gitlab-slack-application", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // DisableSlackApplication disable the GitLab for Slack app integration for a project. @@ -1094,18 +801,12 @@ func (s *ServicesService) SetSlackApplication(pid any, opt *SetSlackApplicationO // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#disable-gitlab-for-slack-app func (s *ServicesService) DisableSlackApplication(pid any, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/integrations/gitlab-slack-application", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/integrations/gitlab-slack-application", ProjectID{pid}), + withRequestOpts(options...), + ) + return resp, err } // JenkinsCIService represents Jenkins CI service settings. @@ -1133,24 +834,10 @@ type JenkinsCIServiceProperties struct { // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#get-jenkins-settings func (s *ServicesService) GetJenkinsCIService(pid any, options ...RequestOptionFunc) (*JenkinsCIService, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/services/jenkins", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - svc := new(JenkinsCIService) - resp, err := s.client.Do(req, svc) - if err != nil { - return nil, resp, err - } - - return svc, resp, nil + return do[*JenkinsCIService](s.client, + withPath("projects/%s/services/jenkins", ProjectID{pid}), + withRequestOpts(options...), + ) } // SetJenkinsCIServiceOptions represents the available SetJenkinsCIService() @@ -1174,24 +861,12 @@ type SetJenkinsCIServiceOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#set-up-jenkins func (s *ServicesService) SetJenkinsCIService(pid any, opt *SetJenkinsCIServiceOptions, options ...RequestOptionFunc) (*JenkinsCIService, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/services/jenkins", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - svc := new(JenkinsCIService) - resp, err := s.client.Do(req, svc) - if err != nil { - return nil, nil, err - } - - return svc, resp, nil + return do[*JenkinsCIService](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/services/jenkins", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // DeleteJenkinsCIService deletes Jenkins CI service for project. @@ -1199,18 +874,12 @@ func (s *ServicesService) SetJenkinsCIService(pid any, opt *SetJenkinsCIServiceO // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#disable-jenkins func (s *ServicesService) DeleteJenkinsCIService(pid any, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/services/jenkins", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/services/jenkins", ProjectID{pid}), + withRequestOpts(options...), + ) + return resp, err } // JiraService represents Jira service settings. @@ -1280,24 +949,10 @@ func (p *JiraServiceProperties) UnmarshalJSON(b []byte) error { // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#get-jira-settings func (s *ServicesService) GetJiraService(pid any, options ...RequestOptionFunc) (*JiraService, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/integrations/jira", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - svc := new(JiraService) - resp, err := s.client.Do(req, svc) - if err != nil { - return nil, resp, err - } - - return svc, resp, nil + return do[*JiraService](s.client, + withPath("projects/%s/integrations/jira", ProjectID{pid}), + withRequestOpts(options...), + ) } // SetJiraServiceOptions represents the available SetJiraService() @@ -1329,24 +984,12 @@ type SetJiraServiceOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#set-up-jira-issues func (s *ServicesService) SetJiraService(pid any, opt *SetJiraServiceOptions, options ...RequestOptionFunc) (*JiraService, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/integrations/jira", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - svc := new(JiraService) - resp, err := s.client.Do(req, svc) - if err != nil { - return nil, nil, err - } - - return svc, resp, nil + return do[*JiraService](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/integrations/jira", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // DeleteJiraService deletes Jira service for project. @@ -1354,18 +997,12 @@ func (s *ServicesService) SetJiraService(pid any, opt *SetJiraServiceOptions, op // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#disable-jira func (s *ServicesService) DeleteJiraService(pid any, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/integrations/jira", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/integrations/jira", ProjectID{pid}), + withRequestOpts(options...), + ) + return resp, err } // MatrixService represents Matrix service settings. @@ -1487,24 +1124,10 @@ type MattermostServiceProperties struct { // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#get-mattermost-notifications-settings func (s *ServicesService) GetMattermostService(pid any, options ...RequestOptionFunc) (*MattermostService, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/services/mattermost", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - svc := new(MattermostService) - resp, err := s.client.Do(req, svc) - if err != nil { - return nil, resp, err - } - - return svc, resp, nil + return do[*MattermostService](s.client, + withPath("projects/%s/services/mattermost", ProjectID{pid}), + withRequestOpts(options...), + ) } // SetMattermostServiceOptions represents the available SetMattermostService() @@ -1543,24 +1166,12 @@ type SetMattermostServiceOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#set-up-mattermost-notifications func (s *ServicesService) SetMattermostService(pid any, opt *SetMattermostServiceOptions, options ...RequestOptionFunc) (*MattermostService, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/services/mattermost", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - svc := new(MattermostService) - resp, err := s.client.Do(req, svc) - if err != nil { - return nil, nil, err - } - - return svc, resp, nil + return do[*MattermostService](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/services/mattermost", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // DeleteMattermostService deletes Mattermost service for project. @@ -1568,18 +1179,12 @@ func (s *ServicesService) SetMattermostService(pid any, opt *SetMattermostServic // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#disable-mattermost-notifications func (s *ServicesService) DeleteMattermostService(pid any, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/services/mattermost", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/services/mattermost", ProjectID{pid}), + withRequestOpts(options...), + ) + return resp, err } // MattermostSlashCommandsService represents Mattermost slash commands settings. @@ -1605,24 +1210,10 @@ type MattermostSlashCommandsProperties struct { // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#get-mattermost-slash-commands-settings func (s *ServicesService) GetMattermostSlashCommandsService(pid any, options ...RequestOptionFunc) (*MattermostSlashCommandsService, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/services/mattermost-slash-commands", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - svc := new(MattermostSlashCommandsService) - resp, err := s.client.Do(req, svc) - if err != nil { - return nil, resp, err - } - - return svc, resp, nil + return do[*MattermostSlashCommandsService](s.client, + withPath("projects/%s/services/mattermost-slash-commands", ProjectID{pid}), + withRequestOpts(options...), + ) } // SetMattermostSlashCommandsServiceOptions represents the available SetSlackSlashCommandsService() @@ -1640,24 +1231,12 @@ type SetMattermostSlashCommandsServiceOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#set-up-mattermost-slash-commands func (s *ServicesService) SetMattermostSlashCommandsService(pid any, opt *SetMattermostSlashCommandsServiceOptions, options ...RequestOptionFunc) (*MattermostSlashCommandsService, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/services/mattermost-slash-commands", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - svc := new(MattermostSlashCommandsService) - resp, err := s.client.Do(req, svc) - if err != nil { - return nil, nil, err - } - - return svc, resp, nil + return do[*MattermostSlashCommandsService](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/services/mattermost-slash-commands", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // DeleteMattermostSlashCommandsService deletes Mattermost slash commands service for project. @@ -1665,18 +1244,12 @@ func (s *ServicesService) SetMattermostSlashCommandsService(pid any, opt *SetMat // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#disable-mattermost-slash-commands func (s *ServicesService) DeleteMattermostSlashCommandsService(pid any, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/services/mattermost-slash-commands", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/services/mattermost-slash-commands", ProjectID{pid}), + withRequestOpts(options...), + ) + return resp, err } // MicrosoftTeamsService represents Microsoft Teams service settings. @@ -1711,24 +1284,10 @@ type MicrosoftTeamsServiceProperties struct { // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#get-microsoft-teams-notifications-settings func (s *ServicesService) GetMicrosoftTeamsService(pid any, options ...RequestOptionFunc) (*MicrosoftTeamsService, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/services/microsoft-teams", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - svc := new(MicrosoftTeamsService) - resp, err := s.client.Do(req, svc) - if err != nil { - return nil, resp, err - } - - return svc, resp, nil + return do[*MicrosoftTeamsService](s.client, + withPath("projects/%s/services/microsoft-teams", ProjectID{pid}), + withRequestOpts(options...), + ) } // SetMicrosoftTeamsServiceOptions represents the available SetMicrosoftTeamsService() @@ -1756,24 +1315,12 @@ type SetMicrosoftTeamsServiceOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#set-up-microsoft-teams-notifications func (s *ServicesService) SetMicrosoftTeamsService(pid any, opt *SetMicrosoftTeamsServiceOptions, options ...RequestOptionFunc) (*MicrosoftTeamsService, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/services/microsoft-teams", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - svc := new(MicrosoftTeamsService) - resp, err := s.client.Do(req, svc) - if err != nil { - return nil, nil, err - } - - return svc, resp, nil + return do[*MicrosoftTeamsService](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/services/microsoft-teams", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // DeleteMicrosoftTeamsService deletes Microsoft Teams service for project. @@ -1781,18 +1328,12 @@ func (s *ServicesService) SetMicrosoftTeamsService(pid any, opt *SetMicrosoftTea // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#disable-microsoft-teams-notifications func (s *ServicesService) DeleteMicrosoftTeamsService(pid any, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/services/microsoft-teams", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/services/microsoft-teams", ProjectID{pid}), + withRequestOpts(options...), + ) + return resp, err } // PipelinesEmailService represents Pipelines Email service settings. @@ -1820,24 +1361,10 @@ type PipelinesEmailProperties struct { // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#get-pipeline-status-emails-settings func (s *ServicesService) GetPipelinesEmailService(pid any, options ...RequestOptionFunc) (*PipelinesEmailService, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/services/pipelines-email", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - svc := new(PipelinesEmailService) - resp, err := s.client.Do(req, svc) - if err != nil { - return nil, resp, err - } - - return svc, resp, nil + return do[*PipelinesEmailService](s.client, + withPath("projects/%s/services/pipelines-email", ProjectID{pid}), + withRequestOpts(options...), + ) } // SetPipelinesEmailServiceOptions represents the available @@ -1859,24 +1386,12 @@ type SetPipelinesEmailServiceOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#set-up-pipeline-status-emails func (s *ServicesService) SetPipelinesEmailService(pid any, opt *SetPipelinesEmailServiceOptions, options ...RequestOptionFunc) (*PipelinesEmailService, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/services/pipelines-email", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - svc := new(PipelinesEmailService) - resp, err := s.client.Do(req, svc) - if err != nil { - return nil, nil, err - } - - return svc, resp, nil + return do[*PipelinesEmailService](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/services/pipelines-email", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // DeletePipelinesEmailService deletes Pipelines Email service settings for a project. @@ -1884,18 +1399,12 @@ func (s *ServicesService) SetPipelinesEmailService(pid any, opt *SetPipelinesEma // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#disable-pipeline-status-emails func (s *ServicesService) DeletePipelinesEmailService(pid any, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/services/pipelines-email", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/services/pipelines-email", ProjectID{pid}), + withRequestOpts(options...), + ) + return resp, err } // RedmineService represents the Redmine service settings. @@ -1923,24 +1432,10 @@ type RedmineServiceProperties struct { // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#get-redmine-settings func (s *ServicesService) GetRedmineService(pid any, options ...RequestOptionFunc) (*RedmineService, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/integrations/redmine", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - svc := new(RedmineService) - resp, err := s.client.Do(req, svc) - if err != nil { - return nil, resp, err - } - - return svc, resp, nil + return do[*RedmineService](s.client, + withPath("projects/%s/integrations/redmine", ProjectID{pid}), + withRequestOpts(options...), + ) } // SetRedmineServiceOptions represents the available SetRedmineService(). @@ -1960,24 +1455,12 @@ type SetRedmineServiceOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#set-up-redmine func (s *ServicesService) SetRedmineService(pid any, opt *SetRedmineServiceOptions, options ...RequestOptionFunc) (*RedmineService, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/integrations/redmine", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - svc := new(RedmineService) - resp, err := s.client.Do(req, svc) - if err != nil { - return nil, nil, err - } - - return svc, resp, nil + return do[*RedmineService](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/integrations/redmine", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // DeleteRedmineService deletes Redmine service for project. @@ -1985,18 +1468,12 @@ func (s *ServicesService) SetRedmineService(pid any, opt *SetRedmineServiceOptio // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#disable-redmine func (s *ServicesService) DeleteRedmineService(pid any, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/integrations/redmine", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/integrations/redmine", ProjectID{pid}), + withRequestOpts(options...), + ) + return resp, err } // SlackService represents Slack service settings. @@ -2038,24 +1515,10 @@ type SlackServiceProperties struct { // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#get-slack-notifications-settings func (s *ServicesService) GetSlackService(pid any, options ...RequestOptionFunc) (*SlackService, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/services/slack", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - svc := new(SlackService) - resp, err := s.client.Do(req, svc) - if err != nil { - return nil, resp, err - } - - return svc, resp, nil + return do[*SlackService](s.client, + withPath("projects/%s/services/slack", ProjectID{pid}), + withRequestOpts(options...), + ) } // SetSlackServiceOptions represents the available SetSlackService() @@ -2099,24 +1562,12 @@ type SetSlackServiceOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#set-up-slack-notifications func (s *ServicesService) SetSlackService(pid any, opt *SetSlackServiceOptions, options ...RequestOptionFunc) (*SlackService, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/services/slack", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - svc := new(SlackService) - resp, err := s.client.Do(req, svc) - if err != nil { - return nil, nil, err - } - - return svc, resp, nil + return do[*SlackService](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/services/slack", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // DeleteSlackService deletes Slack service for project. @@ -2124,18 +1575,12 @@ func (s *ServicesService) SetSlackService(pid any, opt *SetSlackServiceOptions, // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#disable-slack-notifications func (s *ServicesService) DeleteSlackService(pid any, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/services/slack", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/services/slack", ProjectID{pid}), + withRequestOpts(options...), + ) + return resp, err } // SlackSlashCommandsService represents Slack slash commands settings. @@ -2160,24 +1605,10 @@ type SlackSlashCommandsProperties struct { // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#get-slack-slash-commands-settings func (s *ServicesService) GetSlackSlashCommandsService(pid any, options ...RequestOptionFunc) (*SlackSlashCommandsService, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/services/slack-slash-commands", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - svc := new(SlackSlashCommandsService) - resp, err := s.client.Do(req, svc) - if err != nil { - return nil, resp, err - } - - return svc, resp, nil + return do[*SlackSlashCommandsService](s.client, + withPath("projects/%s/services/slack-slash-commands", ProjectID{pid}), + withRequestOpts(options...), + ) } // SetSlackSlashCommandsServiceOptions represents the available SetSlackSlashCommandsService() @@ -2194,24 +1625,12 @@ type SetSlackSlashCommandsServiceOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#set-up-slack-slash-commands func (s *ServicesService) SetSlackSlashCommandsService(pid any, opt *SetSlackSlashCommandsServiceOptions, options ...RequestOptionFunc) (*SlackSlashCommandsService, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/services/slack-slash-commands", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - svc := new(SlackSlashCommandsService) - resp, err := s.client.Do(req, svc) - if err != nil { - return nil, nil, err - } - - return svc, resp, nil + return do[*SlackSlashCommandsService](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/services/slack-slash-commands", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // DeleteSlackSlashCommandsService deletes Slack slash commands service for project. @@ -2219,18 +1638,12 @@ func (s *ServicesService) SetSlackSlashCommandsService(pid any, opt *SetSlackSla // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#disable-slack-slash-commands func (s *ServicesService) DeleteSlackSlashCommandsService(pid any, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/services/slack-slash-commands", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/services/slack-slash-commands", ProjectID{pid}), + withRequestOpts(options...), + ) + return resp, err } // TelegramService represents Telegram service settings. @@ -2257,24 +1670,10 @@ type TelegramServiceProperties struct { // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#get-telegram-settings func (s *ServicesService) GetTelegramService(pid any, options ...RequestOptionFunc) (*TelegramService, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/services/telegram", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - svc := new(TelegramService) - resp, err := s.client.Do(req, svc) - if err != nil { - return nil, resp, err - } - - return svc, resp, nil + return do[*TelegramService](s.client, + withPath("projects/%s/services/telegram", ProjectID{pid}), + withRequestOpts(options...), + ) } // SetTelegramServiceOptions represents the available SetTelegramService() @@ -2303,24 +1702,12 @@ type SetTelegramServiceOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#set-up-telegram func (s *ServicesService) SetTelegramService(pid any, opt *SetTelegramServiceOptions, options ...RequestOptionFunc) (*TelegramService, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/services/telegram", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - svc := new(TelegramService) - resp, err := s.client.Do(req, svc) - if err != nil { - return nil, nil, err - } - - return svc, resp, nil + return do[*TelegramService](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/services/telegram", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // DeleteTelegramService deletes Telegram service for project. @@ -2328,18 +1715,12 @@ func (s *ServicesService) SetTelegramService(pid any, opt *SetTelegramServiceOpt // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#disable-telegram func (s *ServicesService) DeleteTelegramService(pid any, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/services/telegram", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/services/telegram", ProjectID{pid}), + withRequestOpts(options...), + ) + return resp, err } // YouTrackService represents YouTrack service settings. @@ -2367,24 +1748,10 @@ type YouTrackServiceProperties struct { // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#get-youtrack-settings func (s *ServicesService) GetYouTrackService(pid any, options ...RequestOptionFunc) (*YouTrackService, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/services/youtrack", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - svc := new(YouTrackService) - resp, err := s.client.Do(req, svc) - if err != nil { - return nil, resp, err - } - - return svc, resp, nil + return do[*YouTrackService](s.client, + withPath("projects/%s/services/youtrack", ProjectID{pid}), + withRequestOpts(options...), + ) } // SetYouTrackServiceOptions represents the available SetYouTrackService() @@ -2404,24 +1771,12 @@ type SetYouTrackServiceOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#set-up-youtrack func (s *ServicesService) SetYouTrackService(pid any, opt *SetYouTrackServiceOptions, options ...RequestOptionFunc) (*YouTrackService, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/services/youtrack", PathEscape(project)) - - svc := new(YouTrackService) - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - resp, err := s.client.Do(req, svc) - if err != nil { - return nil, nil, err - } - - return svc, resp, nil + return do[*YouTrackService](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/services/youtrack", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // DeleteYouTrackService deletes YouTrack service settings for a project. @@ -2429,16 +1784,10 @@ func (s *ServicesService) SetYouTrackService(pid any, opt *SetYouTrackServiceOpt // GitLab API docs: // https://docs.gitlab.com/api/project_integrations/#disable-youtrack func (s *ServicesService) DeleteYouTrackService(pid any, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/services/youtrack", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/services/youtrack", ProjectID{pid}), + withRequestOpts(options...), + ) + return resp, err } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/settings.go b/vendor/gitlab.com/gitlab-org/api/client-go/settings.go index ef3d769f..e61775a9 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/settings.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/settings.go @@ -67,6 +67,7 @@ type Settings struct { AllowLocalRequestsFromWebHooksAndServices bool `json:"allow_local_requests_from_web_hooks_and_services"` AllowProjectCreationForGuestAndBelow bool `json:"allow_project_creation_for_guest_and_below"` AllowRunnerRegistrationToken bool `json:"allow_runner_registration_token"` + AnonymousSearchesAllowed bool `json:"anonymous_searches_allowed"` ArchiveBuildsInHumanReadable string `json:"archive_builds_in_human_readable"` ASCIIDocMaxIncludes int64 `json:"asciidoc_max_includes"` AssetProxyAllowlist []string `json:"asset_proxy_allowlist"` @@ -243,6 +244,7 @@ type Settings struct { InactiveProjectsDeleteAfterMonths int64 `json:"inactive_projects_delete_after_months"` InactiveProjectsMinSizeMB int64 `json:"inactive_projects_min_size_mb"` InactiveProjectsSendWarningEmailAfterMonths int64 `json:"inactive_projects_send_warning_email_after_months"` + InactiveResourceAccessTokensDeleteAfterDays int64 `json:"inactive_resource_access_tokens_delete_after_days"` IncludeOptionalMetricsInServicePing bool `json:"include_optional_metrics_in_service_ping"` InProductMarketingEmailsEnabled bool `json:"in_product_marketing_emails_enabled"` InvisibleCaptchaEnabled bool `json:"invisible_captcha_enabled"` @@ -521,18 +523,10 @@ func (s Settings) String() string { // GitLab API docs: // https://docs.gitlab.com/api/settings/#get-details-on-current-application-settings func (s *SettingsService) GetSettings(options ...RequestOptionFunc) (*Settings, *Response, error) { - req, err := s.client.NewRequest(http.MethodGet, "application/settings", nil, options) - if err != nil { - return nil, nil, err - } - - as := new(Settings) - resp, err := s.client.Do(req, as) - if err != nil { - return nil, resp, err - } - - return as, resp, nil + return do[*Settings](s.client, + withPath("application/settings"), + withRequestOpts(options...), + ) } // UpdateSettingsOptions represents the available UpdateSettings() options. @@ -554,6 +548,7 @@ type UpdateSettingsOptions struct { AllowLocalRequestsFromWebHooksAndServices *bool `url:"allow_local_requests_from_web_hooks_and_services,omitempty" json:"allow_local_requests_from_web_hooks_and_services,omitempty"` AllowProjectCreationForGuestAndBelow *bool `url:"allow_project_creation_for_guest_and_below,omitempty" json:"allow_project_creation_for_guest_and_below,omitempty"` AllowRunnerRegistrationToken *bool `url:"allow_runner_registration_token,omitempty" json:"allow_runner_registration_token,omitempty"` + AnonymousSearchesAllowed *bool `url:"anonymous_searches_allowed,omitempty" json:"anonymous_searches_allowed,omitempty"` ArchiveBuildsInHumanReadable *string `url:"archive_builds_in_human_readable,omitempty" json:"archive_builds_in_human_readable,omitempty"` ASCIIDocMaxIncludes *int64 `url:"asciidoc_max_includes,omitempty" json:"asciidoc_max_includes,omitempty"` AssetProxyAllowlist *[]string `url:"asset_proxy_allowlist,omitempty" json:"asset_proxy_allowlist,omitempty"` @@ -730,6 +725,7 @@ type UpdateSettingsOptions struct { InactiveProjectsDeleteAfterMonths *int64 `url:"inactive_projects_delete_after_months,omitempty" json:"inactive_projects_delete_after_months,omitempty"` InactiveProjectsMinSizeMB *int64 `url:"inactive_projects_min_size_mb,omitempty" json:"inactive_projects_min_size_mb,omitempty"` InactiveProjectsSendWarningEmailAfterMonths *int64 `url:"inactive_projects_send_warning_email_after_months,omitempty" json:"inactive_projects_send_warning_email_after_months,omitempty"` + InactiveResourceAccessTokensDeleteAfterDays *int64 `url:"inactive_resource_access_tokens_delete_after_days,omitempty" json:"inactive_resource_access_tokens_delete_after_days,omitempty"` IncludeOptionalMetricsInServicePing *bool `url:"include_optional_metrics_in_service_ping,omitempty" json:"include_optional_metrics_in_service_ping,omitempty"` InProductMarketingEmailsEnabled *bool `url:"in_product_marketing_emails_enabled,omitempty" json:"in_product_marketing_emails_enabled,omitempty"` InvisibleCaptchaEnabled *bool `url:"invisible_captcha_enabled,omitempty" json:"invisible_captcha_enabled,omitempty"` @@ -839,7 +835,7 @@ type UpdateSettingsOptions struct { SendUserConfirmationEmail *bool `url:"send_user_confirmation_email,omitempty" json:"send_user_confirmation_email,omitempty"` SentryClientsideDSN *string `url:"sentry_clientside_dsn,omitempty" json:"sentry_clientside_dsn,omitempty"` SentryDSN *string `url:"sentry_dsn,omitempty" json:"sentry_dsn,omitempty"` - SentryEnabled *string `url:"sentry_enabled,omitempty" json:"sentry_enabled,omitempty"` + SentryEnabled *bool `url:"sentry_enabled,omitempty" json:"sentry_enabled,omitempty"` SentryEnvironment *string `url:"sentry_environment,omitempty" json:"sentry_environment,omitempty"` ServiceAccessTokensExpirationEnforced *bool `url:"service_access_tokens_expiration_enforced,omitempty" json:"service_access_tokens_expiration_enforced,omitempty"` SessionExpireDelay *int64 `url:"session_expire_delay,omitempty" json:"session_expire_delay,omitempty"` @@ -896,9 +892,9 @@ type UpdateSettingsOptions struct { ThrottleIncidentManagementNotificationEnabled *bool `url:"throttle_incident_management_notification_enabled,omitempty" json:"throttle_incident_management_notification_enabled,omitempty"` ThrottleIncidentManagementNotificationPerPeriod *int64 `url:"throttle_incident_management_notification_per_period,omitempty" json:"throttle_incident_management_notification_per_period,omitempty"` ThrottleIncidentManagementNotificationPeriodInSeconds *int64 `url:"throttle_incident_management_notification_period_in_seconds,omitempty" json:"throttle_incident_management_notification_period_in_seconds,omitempty"` - ThrottleProtectedPathsEnabled *bool `url:"throttle_protected_paths_enabled_enabled,omitempty" json:"throttle_protected_paths_enabled,omitempty"` - ThrottleProtectedPathsPeriodInSeconds *int64 `url:"throttle_protected_paths_enabled_period_in_seconds,omitempty" json:"throttle_protected_paths_period_in_seconds,omitempty"` - ThrottleProtectedPathsRequestsPerPeriod *int64 `url:"throttle_protected_paths_enabled_requests_per_period,omitempty" json:"throttle_protected_paths_per_period,omitempty"` + ThrottleProtectedPathsEnabled *bool `url:"throttle_protected_paths_enabled,omitempty" json:"throttle_protected_paths_enabled,omitempty"` + ThrottleProtectedPathsPeriodInSeconds *int64 `url:"throttle_protected_paths_period_in_seconds,omitempty" json:"throttle_protected_paths_period_in_seconds,omitempty"` + ThrottleProtectedPathsRequestsPerPeriod *int64 `url:"throttle_protected_paths_requests_per_period,omitempty" json:"throttle_protected_paths_requests_per_period,omitempty"` ThrottleUnauthenticatedAPIEnabled *bool `url:"throttle_unauthenticated_api_enabled,omitempty" json:"throttle_unauthenticated_api_enabled,omitempty"` ThrottleUnauthenticatedAPIPeriodInSeconds *int64 `url:"throttle_unauthenticated_api_period_in_seconds,omitempty" json:"throttle_unauthenticated_api_period_in_seconds,omitempty"` ThrottleUnauthenticatedAPIRequestsPerPeriod *int64 `url:"throttle_unauthenticated_api_requests_per_period,omitempty" json:"throttle_unauthenticated_api_requests_per_period,omitempty"` @@ -987,16 +983,10 @@ type BranchProtectionDefaultsOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/settings/#update-application-settings func (s *SettingsService) UpdateSettings(opt *UpdateSettingsOptions, options ...RequestOptionFunc) (*Settings, *Response, error) { - req, err := s.client.NewRequest(http.MethodPut, "application/settings", opt, options) - if err != nil { - return nil, nil, err - } - - as := new(Settings) - resp, err := s.client.Do(req, as) - if err != nil { - return nil, resp, err - } - - return as, resp, nil + return do[*Settings](s.client, + withMethod(http.MethodPut), + withPath("application/settings"), + withAPIOpts(opt), + withRequestOpts(options...), + ) } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/sidekiq_metrics.go b/vendor/gitlab.com/gitlab-org/api/client-go/sidekiq_metrics.go index cc7296f1..0eb6a29a 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/sidekiq_metrics.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/sidekiq_metrics.go @@ -17,7 +17,6 @@ package gitlab import ( - "net/http" "time" ) @@ -62,18 +61,10 @@ type QueueMetricsQueue struct { // GitLab API docs: // https://docs.gitlab.com/api/sidekiq_metrics/#get-the-current-queue-metrics func (s *SidekiqService) GetQueueMetrics(options ...RequestOptionFunc) (*QueueMetrics, *Response, error) { - req, err := s.client.NewRequest(http.MethodGet, "/sidekiq/queue_metrics", nil, options) - if err != nil { - return nil, nil, err - } - - q := new(QueueMetrics) - resp, err := s.client.Do(req, q) - if err != nil { - return nil, resp, err - } - - return q, resp, nil + return do[*QueueMetrics](s.client, + withPath("/sidekiq/queue_metrics"), + withRequestOpts(options...), + ) } // ProcessMetrics represents the GitLab sidekiq process metrics. @@ -105,18 +96,10 @@ type ProcessMetricsProcess struct { // GitLab API docs: // https://docs.gitlab.com/api/sidekiq_metrics/#get-the-current-process-metrics func (s *SidekiqService) GetProcessMetrics(options ...RequestOptionFunc) (*ProcessMetrics, *Response, error) { - req, err := s.client.NewRequest(http.MethodGet, "/sidekiq/process_metrics", nil, options) - if err != nil { - return nil, nil, err - } - - p := new(ProcessMetrics) - resp, err := s.client.Do(req, p) - if err != nil { - return nil, resp, err - } - - return p, resp, nil + return do[*ProcessMetrics](s.client, + withPath("/sidekiq/process_metrics"), + withRequestOpts(options...), + ) } // JobStats represents the GitLab sidekiq job stats. @@ -142,18 +125,10 @@ type JobStatsJobs struct { // GitLab API docs: // https://docs.gitlab.com/api/sidekiq_metrics/#get-the-current-job-statistics func (s *SidekiqService) GetJobStats(options ...RequestOptionFunc) (*JobStats, *Response, error) { - req, err := s.client.NewRequest(http.MethodGet, "/sidekiq/job_stats", nil, options) - if err != nil { - return nil, nil, err - } - - j := new(JobStats) - resp, err := s.client.Do(req, j) - if err != nil { - return nil, resp, err - } - - return j, resp, nil + return do[*JobStats](s.client, + withPath("/sidekiq/job_stats"), + withRequestOpts(options...), + ) } // CompoundMetrics represents the GitLab sidekiq compounded stats. @@ -172,16 +147,8 @@ type CompoundMetrics struct { // GitLab API docs: // https://docs.gitlab.com/api/sidekiq_metrics/#get-a-compound-response-of-all-the-previously-mentioned-metrics func (s *SidekiqService) GetCompoundMetrics(options ...RequestOptionFunc) (*CompoundMetrics, *Response, error) { - req, err := s.client.NewRequest(http.MethodGet, "/sidekiq/compound_metrics", nil, options) - if err != nil { - return nil, nil, err - } - - c := new(CompoundMetrics) - resp, err := s.client.Do(req, c) - if err != nil { - return nil, resp, err - } - - return c, resp, nil + return do[*CompoundMetrics](s.client, + withPath("/sidekiq/compound_metrics"), + withRequestOpts(options...), + ) } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/snippet_repository_storage_move.go b/vendor/gitlab.com/gitlab-org/api/client-go/snippet_repository_storage_move.go index aa2eba69..ee20002a 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/snippet_repository_storage_move.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/snippet_repository_storage_move.go @@ -17,7 +17,6 @@ package gitlab import ( - "fmt" "net/http" "time" ) @@ -87,18 +86,11 @@ type RetrieveAllSnippetStorageMovesOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/snippet_repository_storage_moves/#retrieve-all-snippet-repository-storage-moves func (s SnippetRepositoryStorageMoveService) RetrieveAllStorageMoves(opts RetrieveAllSnippetStorageMovesOptions, options ...RequestOptionFunc) ([]*SnippetRepositoryStorageMove, *Response, error) { - req, err := s.client.NewRequest(http.MethodGet, "snippet_repository_storage_moves", opts, options) - if err != nil { - return nil, nil, err - } - - var ssms []*SnippetRepositoryStorageMove - resp, err := s.client.Do(req, &ssms) - if err != nil { - return nil, resp, err - } - - return ssms, resp, err + return do[[]*SnippetRepositoryStorageMove](s.client, + withPath("snippet_repository_storage_moves"), + withAPIOpts(opts), + withRequestOpts(options...), + ) } // RetrieveAllStorageMovesForSnippet retrieves all repository storage moves for @@ -107,20 +99,11 @@ func (s SnippetRepositoryStorageMoveService) RetrieveAllStorageMoves(opts Retrie // GitLab API docs: // https://docs.gitlab.com/api/snippet_repository_storage_moves/#retrieve-all-repository-storage-moves-for-a-snippet func (s SnippetRepositoryStorageMoveService) RetrieveAllStorageMovesForSnippet(snippet int64, opts RetrieveAllSnippetStorageMovesOptions, options ...RequestOptionFunc) ([]*SnippetRepositoryStorageMove, *Response, error) { - u := fmt.Sprintf("snippets/%d/repository_storage_moves", snippet) - - req, err := s.client.NewRequest(http.MethodGet, u, opts, options) - if err != nil { - return nil, nil, err - } - - var ssms []*SnippetRepositoryStorageMove - resp, err := s.client.Do(req, &ssms) - if err != nil { - return nil, resp, err - } - - return ssms, resp, err + return do[[]*SnippetRepositoryStorageMove](s.client, + withPath("snippets/%d/repository_storage_moves", snippet), + withAPIOpts(opts), + withRequestOpts(options...), + ) } // GetStorageMove gets a single snippet repository storage move. @@ -128,20 +111,10 @@ func (s SnippetRepositoryStorageMoveService) RetrieveAllStorageMovesForSnippet(s // GitLab API docs: // https://docs.gitlab.com/api/snippet_repository_storage_moves/#get-a-single-snippet-repository-storage-move func (s SnippetRepositoryStorageMoveService) GetStorageMove(repositoryStorage int64, options ...RequestOptionFunc) (*SnippetRepositoryStorageMove, *Response, error) { - u := fmt.Sprintf("snippet_repository_storage_moves/%d", repositoryStorage) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - ssm := new(SnippetRepositoryStorageMove) - resp, err := s.client.Do(req, ssm) - if err != nil { - return nil, resp, err - } - - return ssm, resp, err + return do[*SnippetRepositoryStorageMove](s.client, + withPath("snippet_repository_storage_moves/%d", repositoryStorage), + withRequestOpts(options...), + ) } // GetStorageMoveForSnippet gets a single repository storage move for a snippet. @@ -149,20 +122,10 @@ func (s SnippetRepositoryStorageMoveService) GetStorageMove(repositoryStorage in // GitLab API docs: // https://docs.gitlab.com/api/snippet_repository_storage_moves/#get-a-single-repository-storage-move-for-a-snippet func (s SnippetRepositoryStorageMoveService) GetStorageMoveForSnippet(snippet int64, repositoryStorage int64, options ...RequestOptionFunc) (*SnippetRepositoryStorageMove, *Response, error) { - u := fmt.Sprintf("snippets/%d/repository_storage_moves/%d", snippet, repositoryStorage) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - ssm := new(SnippetRepositoryStorageMove) - resp, err := s.client.Do(req, ssm) - if err != nil { - return nil, resp, err - } - - return ssm, resp, err + return do[*SnippetRepositoryStorageMove](s.client, + withPath("snippets/%d/repository_storage_moves/%d", snippet, repositoryStorage), + withRequestOpts(options...), + ) } // ScheduleStorageMoveForSnippetOptions represents the available @@ -179,20 +142,12 @@ type ScheduleStorageMoveForSnippetOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/snippet_repository_storage_moves/#schedule-a-repository-storage-move-for-a-snippet func (s SnippetRepositoryStorageMoveService) ScheduleStorageMoveForSnippet(snippet int64, opts ScheduleStorageMoveForSnippetOptions, options ...RequestOptionFunc) (*SnippetRepositoryStorageMove, *Response, error) { - u := fmt.Sprintf("snippets/%d/repository_storage_moves", snippet) - - req, err := s.client.NewRequest(http.MethodPost, u, opts, options) - if err != nil { - return nil, nil, err - } - - ssm := new(SnippetRepositoryStorageMove) - resp, err := s.client.Do(req, ssm) - if err != nil { - return nil, resp, err - } - - return ssm, resp, err + return do[*SnippetRepositoryStorageMove](s.client, + withMethod(http.MethodPost), + withPath("snippets/%d/repository_storage_moves", snippet), + withAPIOpts(opts), + withRequestOpts(options...), + ) } // ScheduleAllSnippetStorageMovesOptions represents the available @@ -210,10 +165,11 @@ type ScheduleAllSnippetStorageMovesOptions struct { // GitLab API docs: // https://docs.gitlab.com/api/snippet_repository_storage_moves/#schedule-repository-storage-moves-for-all-snippets-on-a-storage-shard func (s SnippetRepositoryStorageMoveService) ScheduleAllStorageMoves(opts ScheduleAllSnippetStorageMovesOptions, options ...RequestOptionFunc) (*Response, error) { - req, err := s.client.NewRequest(http.MethodPost, "snippet_repository_storage_moves", opts, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodPost), + withPath("snippet_repository_storage_moves"), + withAPIOpts(opts), + withRequestOpts(options...), + ) + return resp, err } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/snippets.go b/vendor/gitlab.com/gitlab-org/api/client-go/snippets.go index 899fba68..4c7cd150 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/snippets.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/snippets.go @@ -18,7 +18,6 @@ package gitlab import ( "bytes" - "fmt" "net/http" "time" ) @@ -145,20 +144,14 @@ func (s *SnippetsService) GetSnippet(snippet int64, options ...RequestOptionFunc // GitLab API docs: // https://docs.gitlab.com/api/snippets/#single-snippet-contents func (s *SnippetsService) SnippetContent(snippet int64, options ...RequestOptionFunc) ([]byte, *Response, error) { - u := fmt.Sprintf("snippets/%d/raw", snippet) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - var b bytes.Buffer - resp, err := s.client.Do(req, &b) + buf, resp, err := do[bytes.Buffer](s.client, + withPath("snippets/%d/raw", snippet), + withRequestOpts(options...), + ) if err != nil { return nil, resp, err } - - return b.Bytes(), resp, err + return buf.Bytes(), resp, nil } // SnippetFileContent returns the raw file content as plain text. @@ -166,21 +159,14 @@ func (s *SnippetsService) SnippetContent(snippet int64, options ...RequestOption // GitLab API docs: // https://docs.gitlab.com/api/snippets/#snippet-repository-file-content func (s *SnippetsService) SnippetFileContent(snippet int64, ref, filename string, options ...RequestOptionFunc) ([]byte, *Response, error) { - filepath := PathEscape(filename) - u := fmt.Sprintf("snippets/%d/files/%s/%s/raw", snippet, ref, filepath) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - var b bytes.Buffer - resp, err := s.client.Do(req, &b) + buf, resp, err := do[bytes.Buffer](s.client, + withPath("snippets/%d/files/%s/%s/raw", snippet, ref, filename), + withRequestOpts(options...), + ) if err != nil { return nil, resp, err } - - return b.Bytes(), resp, err + return buf.Bytes(), resp, nil } // CreateSnippetFileOptions represents the create snippet file options. diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/system_hooks.go b/vendor/gitlab.com/gitlab-org/api/client-go/system_hooks.go index a74914f9..d337ddf9 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/system_hooks.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/system_hooks.go @@ -17,17 +17,38 @@ package gitlab import ( - "fmt" "net/http" "time" ) type ( SystemHooksServiceInterface interface { + // ListHooks gets a list of system hooks. + // + // GitLab API docs: + // https://docs.gitlab.com/api/system_hooks/#list-system-hooks ListHooks(options ...RequestOptionFunc) ([]*Hook, *Response, error) + // GetHook gets a single system hook. + // + // GitLab API docs: + // https://docs.gitlab.com/api/system_hooks/#get-system-hook GetHook(hook int64, options ...RequestOptionFunc) (*Hook, *Response, error) + // AddHook adds a new system hook. + // + // GitLab API docs: + // https://docs.gitlab.com/api/system_hooks/#add-new-system-hook AddHook(opt *AddHookOptions, options ...RequestOptionFunc) (*Hook, *Response, error) + // TestHook tests a system hook. + // + // GitLab API docs: + // https://docs.gitlab.com/api/system_hooks/#test-system-hook TestHook(hook int64, options ...RequestOptionFunc) (*HookEvent, *Response, error) + // DeleteHook deletes a system hook. This is an idempotent API function and + // returns 200 OK even if the hook is not available. If the hook is deleted it + // is also returned as JSON. + // + // GitLab API docs: + // https://docs.gitlab.com/api/system_hooks/#delete-system-hook DeleteHook(hook int64, options ...RequestOptionFunc) (*Response, error) } @@ -60,44 +81,18 @@ func (h Hook) String() string { return Stringify(h) } -// ListHooks gets a list of system hooks. -// -// GitLab API docs: -// https://docs.gitlab.com/api/system_hooks/#list-system-hooks func (s *SystemHooksService) ListHooks(options ...RequestOptionFunc) ([]*Hook, *Response, error) { - req, err := s.client.NewRequest(http.MethodGet, "hooks", nil, options) - if err != nil { - return nil, nil, err - } - - var h []*Hook - resp, err := s.client.Do(req, &h) - if err != nil { - return nil, resp, err - } - - return h, resp, nil + return do[[]*Hook](s.client, + withPath("hooks"), + withRequestOpts(options...), + ) } -// GetHook get a single system hook. -// -// GitLab API docs: -// https://docs.gitlab.com/api/system_hooks/#get-system-hook func (s *SystemHooksService) GetHook(hook int64, options ...RequestOptionFunc) (*Hook, *Response, error) { - u := fmt.Sprintf("hooks/%d", hook) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - var h *Hook - resp, err := s.client.Do(req, &h) - if err != nil { - return nil, resp, err - } - - return h, resp, nil + return do[*Hook](s.client, + withPath("hooks/%d", hook), + withRequestOpts(options...), + ) } // AddHookOptions represents the available AddHook() options. @@ -114,23 +109,13 @@ type AddHookOptions struct { EnableSSLVerification *bool `url:"enable_ssl_verification,omitempty" json:"enable_ssl_verification,omitempty"` } -// AddHook adds a new system hook hook. -// -// GitLab API docs: -// https://docs.gitlab.com/api/system_hooks/#add-new-system-hook func (s *SystemHooksService) AddHook(opt *AddHookOptions, options ...RequestOptionFunc) (*Hook, *Response, error) { - req, err := s.client.NewRequest(http.MethodPost, "hooks", opt, options) - if err != nil { - return nil, nil, err - } - - h := new(Hook) - resp, err := s.client.Do(req, h) - if err != nil { - return nil, resp, err - } - - return h, resp, nil + return do[*Hook](s.client, + withMethod(http.MethodPost), + withPath("hooks"), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // HookEvent represents an event trigger by a GitLab system hook. @@ -149,40 +134,18 @@ func (h HookEvent) String() string { return Stringify(h) } -// TestHook tests a system hook. -// -// GitLab API docs: -// https://docs.gitlab.com/api/system_hooks/#test-system-hook func (s *SystemHooksService) TestHook(hook int64, options ...RequestOptionFunc) (*HookEvent, *Response, error) { - u := fmt.Sprintf("hooks/%d", hook) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - h := new(HookEvent) - resp, err := s.client.Do(req, h) - if err != nil { - return nil, resp, err - } - - return h, resp, nil + return do[*HookEvent](s.client, + withPath("hooks/%d", hook), + withRequestOpts(options...), + ) } -// DeleteHook deletes a system hook. This is an idempotent API function and -// returns 200 OK even if the hook is not available. If the hook is deleted it -// is also returned as JSON. -// -// GitLab API docs: -// https://docs.gitlab.com/api/system_hooks/#delete-system-hook func (s *SystemHooksService) DeleteHook(hook int64, options ...RequestOptionFunc) (*Response, error) { - u := fmt.Sprintf("hooks/%d", hook) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("hooks/%d", hook), + withRequestOpts(options...), + ) + return resp, err } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/tags.go b/vendor/gitlab.com/gitlab-org/api/client-go/tags.go index 5df51a3e..333dbfe4 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/tags.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/tags.go @@ -17,19 +17,40 @@ package gitlab import ( - "fmt" "math/big" "net/http" - "net/url" "time" ) type ( TagsServiceInterface interface { + // ListTags gets a list of tags from a project, sorted by name in reverse + // alphabetical order. + // + // GitLab API docs: + // https://docs.gitlab.com/api/tags/#list-project-repository-tags ListTags(pid any, opt *ListTagsOptions, options ...RequestOptionFunc) ([]*Tag, *Response, error) + // GetTag a specific repository tag determined by its name. It returns 200 together + // with the tag information if the tag exists. It returns 404 if the tag does not exist. + // + // GitLab API docs: + // https://docs.gitlab.com/api/tags/#get-a-single-repository-tag GetTag(pid any, tag string, options ...RequestOptionFunc) (*Tag, *Response, error) + // GetTagSignature a specific repository tag determined by its name. It returns 200 together + // with the signature if the tag exists. It returns 404 if the tag does not exist. + // + // GitLab API docs: + // https://docs.gitlab.com/api/tags/#get-x509-signature-of-a-tag GetTagSignature(pid any, tag string, options ...RequestOptionFunc) (*X509Signature, *Response, error) + // CreateTag creates a new tag in the repository that points to the supplied ref. + // + // GitLab API docs: + // https://docs.gitlab.com/api/tags/#create-a-new-tag CreateTag(pid any, opt *CreateTagOptions, options ...RequestOptionFunc) (*Tag, *Response, error) + // DeleteTag deletes a tag of a repository with given name. + // + // GitLab API docs: + // https://docs.gitlab.com/api/tags/#delete-a-tag DeleteTag(pid any, tag string, options ...RequestOptionFunc) (*Response, error) } @@ -106,82 +127,26 @@ type ListTagsOptions struct { Sort *string `url:"sort,omitempty" json:"sort,omitempty"` } -// ListTags gets a list of tags from a project, sorted by name in reverse -// alphabetical order. -// -// GitLab API docs: -// https://docs.gitlab.com/api/tags/#list-project-repository-tags func (s *TagsService) ListTags(pid any, opt *ListTagsOptions, options ...RequestOptionFunc) ([]*Tag, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/repository/tags", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var t []*Tag - resp, err := s.client.Do(req, &t) - if err != nil { - return nil, resp, err - } - - return t, resp, nil + return do[[]*Tag](s.client, + withPath("projects/%s/repository/tags", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } -// GetTag a specific repository tag determined by its name. It returns 200 together -// with the tag information if the tag exists. It returns 404 if the tag does not exist. -// -// GitLab API docs: -// https://docs.gitlab.com/api/tags/#get-a-single-repository-tag func (s *TagsService) GetTag(pid any, tag string, options ...RequestOptionFunc) (*Tag, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/repository/tags/%s", PathEscape(project), url.PathEscape(tag)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - var t *Tag - resp, err := s.client.Do(req, &t) - if err != nil { - return nil, resp, err - } - - return t, resp, nil + return do[*Tag](s.client, + withPath("projects/%s/repository/tags/%s", ProjectID{pid}, tag), + withRequestOpts(options...), + ) } -// GetTagSignature a specific repository tag determined by its name. It returns 200 together -// with the signature if the tag exists. It returns 404 if the tag does not exist. -// -// GitLab API docs: -// https://docs.gitlab.com/api/tags/#get-x509-signature-of-a-tag func (s *TagsService) GetTagSignature(pid any, tag string, options ...RequestOptionFunc) (*X509Signature, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/repository/tags/%s/signature", PathEscape(project), url.PathEscape(tag)) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - var sig *X509Signature - resp, err := s.client.Do(req, &sig) - if err != nil { - return nil, resp, err - } - - return sig, resp, nil + return do[*X509Signature](s.client, + withPath("projects/%s/repository/tags/%s/signature", ProjectID{pid}, tag), + withRequestOpts(options...), + ) } // CreateTagOptions represents the available CreateTag() options. @@ -194,46 +159,20 @@ type CreateTagOptions struct { Message *string `url:"message,omitempty" json:"message,omitempty"` } -// CreateTag creates a new tag in the repository that points to the supplied ref. -// -// GitLab API docs: -// https://docs.gitlab.com/api/tags/#create-a-new-tag func (s *TagsService) CreateTag(pid any, opt *CreateTagOptions, options ...RequestOptionFunc) (*Tag, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/repository/tags", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - t := new(Tag) - resp, err := s.client.Do(req, t) - if err != nil { - return nil, resp, err - } - - return t, resp, nil + return do[*Tag](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/repository/tags", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } -// DeleteTag deletes a tag of a repository with given name. -// -// GitLab API docs: -// https://docs.gitlab.com/api/tags/#delete-a-tag func (s *TagsService) DeleteTag(pid any, tag string, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/repository/tags/%s", PathEscape(project), url.PathEscape(tag)) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/repository/tags/%s", ProjectID{pid}, tag), + withRequestOpts(options...), + ) + return resp, err } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/terraform_states.go b/vendor/gitlab.com/gitlab-org/api/client-go/terraform_states.go index 6ca64d25..34b30d46 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/terraform_states.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/terraform_states.go @@ -141,115 +141,71 @@ func (s *TerraformStatesService) Get(projectFullPath string, name string, option } func (s *TerraformStatesService) DownloadLatest(pid any, name string, options ...RequestOptionFunc) (io.Reader, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - uri := fmt.Sprintf("projects/%s/terraform/state/%s", PathEscape(project), PathEscape(name)) - - req, err := s.client.NewRequest(http.MethodGet, uri, nil, options) - if err != nil { - return nil, nil, err - } - - var b bytes.Buffer - resp, err := s.client.Do(req, &b) + buf, resp, err := do[bytes.Buffer](s.client, + withPath("projects/%s/terraform/state/%s", ProjectID{pid}, name), + withRequestOpts(options...), + ) if err != nil { return nil, resp, err } - - return &b, resp, nil + return &buf, resp, nil } func (s *TerraformStatesService) Download(pid any, name string, serial uint64, options ...RequestOptionFunc) (io.Reader, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - uri := fmt.Sprintf("projects/%s/terraform/state/%s/versions/%d", PathEscape(project), PathEscape(name), serial) - - req, err := s.client.NewRequest(http.MethodGet, uri, nil, options) - if err != nil { - return nil, nil, err - } - - var b bytes.Buffer - resp, err := s.client.Do(req, &b) + buf, resp, err := do[bytes.Buffer](s.client, + withPath("projects/%s/terraform/state/%s/versions/%d", ProjectID{pid}, name, serial), + withRequestOpts(options...), + ) if err != nil { return nil, resp, err } - - return &b, resp, nil + return &buf, resp, nil } // Delete deletes a single Terraform state // // GitLab API docs: https://docs.gitlab.com/user/infrastructure/iac/terraform_state/ func (s *TerraformStatesService) Delete(pid any, name string, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - uri := fmt.Sprintf("projects/%s/terraform/state/%s", PathEscape(project), PathEscape(name)) - - req, err := s.client.NewRequest(http.MethodDelete, uri, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/terraform/state/%s", ProjectID{pid}, name), + withRequestOpts(options...), + ) + return resp, err } // DeleteVersion deletes a single Terraform state version // // GitLab API docs: https://docs.gitlab.com/user/infrastructure/iac/terraform_state/ func (s *TerraformStatesService) DeleteVersion(pid any, name string, serial uint64, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - uri := fmt.Sprintf("projects/%s/terraform/state/%s/versions/%d", PathEscape(project), PathEscape(name), serial) - - req, err := s.client.NewRequest(http.MethodDelete, uri, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/terraform/state/%s/versions/%d", ProjectID{pid}, name, serial), + withRequestOpts(options...), + ) + return resp, err } // Lock locks a single Terraform state // // GitLab API docs: https://docs.gitlab.com/user/infrastructure/iac/terraform_state/ func (s *TerraformStatesService) Lock(pid any, name string, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - uri := fmt.Sprintf("projects/%s/terraform/state/%s/lock", PathEscape(project), PathEscape(name)) - - req, err := s.client.NewRequest(http.MethodPost, uri, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/terraform/state/%s/lock", ProjectID{pid}, name), + withRequestOpts(options...), + ) + return resp, err } // Unlock unlocks a single Terraform state // // GitLab API docs: https://docs.gitlab.com/user/infrastructure/iac/terraform_state/ func (s *TerraformStatesService) Unlock(pid any, name string, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - uri := fmt.Sprintf("projects/%s/terraform/state/%s/lock", PathEscape(project), PathEscape(name)) - - req, err := s.client.NewRequest(http.MethodDelete, uri, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/terraform/state/%s/lock", ProjectID{pid}, name), + withRequestOpts(options...), + ) + return resp, err } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/time_stats.go b/vendor/gitlab.com/gitlab-org/api/client-go/time_stats.go index 9b0c9846..035a88d1 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/time_stats.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/time_stats.go @@ -17,7 +17,6 @@ package gitlab import ( - "fmt" "net/http" ) @@ -55,48 +54,23 @@ type SetTimeEstimateOptions struct { // // GitLab docs: https://docs.gitlab.com/api/issues/#set-a-time-estimate-for-an-issue func (s *timeStatsService) setTimeEstimate(pid any, entity string, issue int64, opt *SetTimeEstimateOptions, options ...RequestOptionFunc) (*TimeStats, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/%s/%d/time_estimate", PathEscape(project), entity, issue) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - t := new(TimeStats) - resp, err := s.client.Do(req, t) - if err != nil { - return nil, resp, err - } - - return t, resp, nil + return do[*TimeStats](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/%s/%d/time_estimate", ProjectID{pid}, entity, issue), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // resetTimeEstimate resets the time estimate for a single project issue. // // GitLab docs: https://docs.gitlab.com/api/issues/#reset-the-time-estimate-for-an-issue func (s *timeStatsService) resetTimeEstimate(pid any, entity string, issue int64, options ...RequestOptionFunc) (*TimeStats, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/%s/%d/reset_time_estimate", PathEscape(project), entity, issue) - - req, err := s.client.NewRequest(http.MethodPost, u, nil, options) - if err != nil { - return nil, nil, err - } - - t := new(TimeStats) - resp, err := s.client.Do(req, t) - if err != nil { - return nil, resp, err - } - - return t, resp, nil + return do[*TimeStats](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/%s/%d/reset_time_estimate", ProjectID{pid}, entity, issue), + withRequestOpts(options...), + ) } // AddSpentTimeOptions represents the available AddSpentTime() options. @@ -111,70 +85,31 @@ type AddSpentTimeOptions struct { // // GitLab docs: https://docs.gitlab.com/api/issues/#add-spent-time-for-an-issue func (s *timeStatsService) addSpentTime(pid any, entity string, issue int64, opt *AddSpentTimeOptions, options ...RequestOptionFunc) (*TimeStats, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/%s/%d/add_spent_time", PathEscape(project), entity, issue) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - t := new(TimeStats) - resp, err := s.client.Do(req, t) - if err != nil { - return nil, resp, err - } - - return t, resp, nil + return do[*TimeStats](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/%s/%d/add_spent_time", ProjectID{pid}, entity, issue), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // resetSpentTime resets the spent time for a single project issue. // // GitLab docs: https://docs.gitlab.com/api/issues/#reset-spent-time-for-an-issue func (s *timeStatsService) resetSpentTime(pid any, entity string, issue int64, options ...RequestOptionFunc) (*TimeStats, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/%s/%d/reset_spent_time", PathEscape(project), entity, issue) - - req, err := s.client.NewRequest(http.MethodPost, u, nil, options) - if err != nil { - return nil, nil, err - } - - t := new(TimeStats) - resp, err := s.client.Do(req, t) - if err != nil { - return nil, resp, err - } - - return t, resp, nil + return do[*TimeStats](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/%s/%d/reset_spent_time", ProjectID{pid}, entity, issue), + withRequestOpts(options...), + ) } // getTimeSpent gets the spent time for a single project issue. // // GitLab docs: https://docs.gitlab.com/api/issues/#get-time-tracking-stats func (s *timeStatsService) getTimeSpent(pid any, entity string, issue int64, options ...RequestOptionFunc) (*TimeStats, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/%s/%d/time_stats", PathEscape(project), entity, issue) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - t := new(TimeStats) - resp, err := s.client.Do(req, t) - if err != nil { - return nil, resp, err - } - - return t, resp, nil + return do[*TimeStats](s.client, + withPath("projects/%s/%s/%d/time_stats", ProjectID{pid}, entity, issue), + withRequestOpts(options...), + ) } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/todos.go b/vendor/gitlab.com/gitlab-org/api/client-go/todos.go index e0949e69..ab47c78c 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/todos.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/todos.go @@ -17,7 +17,6 @@ package gitlab import ( - "fmt" "net/http" "time" ) @@ -139,36 +138,27 @@ type ListTodosOptions struct { } func (s *TodosService) ListTodos(opt *ListTodosOptions, options ...RequestOptionFunc) ([]*Todo, *Response, error) { - req, err := s.client.NewRequest(http.MethodGet, "todos", opt, options) - if err != nil { - return nil, nil, err - } - - var t []*Todo - resp, err := s.client.Do(req, &t) - if err != nil { - return nil, resp, err - } - - return t, resp, nil + return do[[]*Todo](s.client, + withPath("todos"), + withAPIOpts(opt), + withRequestOpts(options...), + ) } func (s *TodosService) MarkTodoAsDone(id int64, options ...RequestOptionFunc) (*Response, error) { - u := fmt.Sprintf("todos/%d/mark_as_done", id) - - req, err := s.client.NewRequest(http.MethodPost, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodPost), + withPath("todos/%d/mark_as_done", id), + withRequestOpts(options...), + ) + return resp, err } func (s *TodosService) MarkAllTodosAsDone(options ...RequestOptionFunc) (*Response, error) { - req, err := s.client.NewRequest(http.MethodPost, "todos/mark_as_done", nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodPost), + withPath("todos/mark_as_done"), + withRequestOpts(options...), + ) + return resp, err } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/topics.go b/vendor/gitlab.com/gitlab-org/api/client-go/topics.go index e10555ef..e2cca41e 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/topics.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/topics.go @@ -18,11 +18,8 @@ package gitlab import ( "encoding/json" - "fmt" "io" "net/http" - - retryablehttp "github.com/hashicorp/go-retryablehttp" ) type ( @@ -144,33 +141,16 @@ func (a *TopicAvatar) MarshalJSON() ([]byte, error) { } func (s *TopicsService) CreateTopic(opt *CreateTopicOptions, options ...RequestOptionFunc) (*Topic, *Response, error) { - var err error - var req *retryablehttp.Request - - if opt.Avatar == nil { - req, err = s.client.NewRequest(http.MethodPost, "topics", opt, options) - } else { - req, err = s.client.UploadRequest( - http.MethodPost, - "topics", - opt.Avatar.Image, - opt.Avatar.Filename, - UploadAvatar, - opt, - options, - ) - } - if err != nil { - return nil, nil, err + reqOpts := []doOption{ + withMethod(http.MethodPost), + withPath("topics"), + withAPIOpts(opt), + withRequestOpts(options...), } - - t := new(Topic) - resp, err := s.client.Do(req, t) - if err != nil { - return nil, resp, err + if opt.Avatar != nil { + reqOpts = append(reqOpts, withUpload(opt.Avatar.Image, opt.Avatar.Filename, UploadAvatar)) } - - return t, resp, nil + return do[*Topic](s.client, reqOpts...) } // UpdateTopicOptions represents the available UpdateTopic() options. @@ -185,33 +165,16 @@ type UpdateTopicOptions struct { } func (s *TopicsService) UpdateTopic(topic int64, opt *UpdateTopicOptions, options ...RequestOptionFunc) (*Topic, *Response, error) { - var err error - var req *retryablehttp.Request - - if opt.Avatar == nil || (opt.Avatar.Filename == "" && opt.Avatar.Image == nil) { - req, err = s.client.NewRequest(http.MethodPut, fmt.Sprintf("topics/%d", topic), opt, options) - } else { - req, err = s.client.UploadRequest( - http.MethodPut, - fmt.Sprintf("topics/%d", topic), - opt.Avatar.Image, - opt.Avatar.Filename, - UploadAvatar, - opt, - options, - ) + reqOpts := []doOption{ + withMethod(http.MethodPut), + withPath("topics/%d", topic), + withAPIOpts(opt), + withRequestOpts(options...), } - if err != nil { - return nil, nil, err + if opt.Avatar != nil && (opt.Avatar.Filename != "" || opt.Avatar.Image != nil) { + reqOpts = append(reqOpts, withUpload(opt.Avatar.Image, opt.Avatar.Filename, UploadAvatar)) } - - t := new(Topic) - resp, err := s.client.Do(req, t) - if err != nil { - return nil, resp, err - } - - return t, resp, nil + return do[*Topic](s.client, reqOpts...) } func (s *TopicsService) DeleteTopic(topic int64, options ...RequestOptionFunc) (*Response, error) { diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/types.go b/vendor/gitlab.com/gitlab-org/api/client-go/types.go index 45326182..d7cb4bd2 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/types.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/types.go @@ -877,16 +877,10 @@ type BoolValue bool // https://github.com/gitlabhq/terraform-provider-gitlab/issues/348 func (t *BoolValue) UnmarshalJSON(b []byte) error { switch string(b) { - case `"1"`: + case `"1"`, `"true"`: *t = true return nil - case `"0"`: - *t = false - return nil - case `"true"`: - *t = true - return nil - case `"false"`: + case `"0"`, `"false"`: *t = false return nil default: diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/usage_data.go b/vendor/gitlab.com/gitlab-org/api/client-go/usage_data.go index 2bf73d92..737f72c6 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/usage_data.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/usage_data.go @@ -58,34 +58,20 @@ type ServicePingData struct { } func (s *UsageDataService) GetServicePing(options ...RequestOptionFunc) (*ServicePingData, *Response, error) { - req, err := s.client.NewRequest(http.MethodGet, "usage_data/service_ping", nil, options) - if err != nil { - return nil, nil, err - } - - sp := new(ServicePingData) - resp, err := s.client.Do(req, sp) - if err != nil { - return nil, resp, err - } - - return sp, resp, nil + return do[*ServicePingData](s.client, + withPath("usage_data/service_ping"), + withRequestOpts(options...), + ) } func (s *UsageDataService) GetMetricDefinitionsAsYAML(options ...RequestOptionFunc) (io.Reader, *Response, error) { - req, err := s.client.NewRequest(http.MethodGet, "usage_data/metric_definitions", nil, options) - if err != nil { - return nil, nil, err - } - - req.Header.Set("Accept", "text/yaml") - - var buf bytes.Buffer - resp, err := s.client.Do(req, &buf) + buf, resp, err := do[bytes.Buffer](s.client, + withPath("usage_data/metric_definitions"), + withRequestOpts(append([]RequestOptionFunc{WithHeader("Accept", "text/yaml")}, options...)...), + ) if err != nil { return nil, resp, err } - return &buf, resp, nil } @@ -116,18 +102,10 @@ type ServicePingQueries struct { } func (s *UsageDataService) GetQueries(options ...RequestOptionFunc) (*ServicePingQueries, *Response, error) { - req, err := s.client.NewRequest(http.MethodGet, "usage_data/queries", nil, options) - if err != nil { - return nil, nil, err - } - - sq := new(ServicePingQueries) - resp, err := s.client.Do(req, sq) - if err != nil { - return nil, resp, err - } - - return sq, resp, nil + return do[*ServicePingQueries](s.client, + withPath("usage_data/queries"), + withRequestOpts(options...), + ) } // ServicePingNonSQLMetrics represents the non-SQL metrics used in service ping. @@ -156,18 +134,10 @@ type ServicePingNonSQLMetrics struct { } func (s *UsageDataService) GetNonSQLMetrics(options ...RequestOptionFunc) (*ServicePingNonSQLMetrics, *Response, error) { - req, err := s.client.NewRequest(http.MethodGet, "usage_data/non_sql_metrics", nil, options) - if err != nil { - return nil, nil, err - } - - nsm := new(ServicePingNonSQLMetrics) - resp, err := s.client.Do(req, nsm) - if err != nil { - return nil, resp, err - } - - return nsm, resp, nil + return do[*ServicePingNonSQLMetrics](s.client, + withPath("usage_data/non_sql_metrics"), + withRequestOpts(options...), + ) } // TrackEventOptions represents the available options for tracking events. @@ -180,12 +150,13 @@ type TrackEventOptions struct { } func (s *UsageDataService) TrackEvent(opt *TrackEventOptions, options ...RequestOptionFunc) (*Response, error) { - req, err := s.client.NewRequest(http.MethodPost, "usage_data/track_event", opt, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodPost), + withPath("usage_data/track_event"), + withAPIOpts(opt), + withRequestOpts(options...), + ) + return resp, err } // TrackEventsOptions represents the available options for tracking multiple events. @@ -194,10 +165,11 @@ type TrackEventsOptions struct { } func (s *UsageDataService) TrackEvents(opt *TrackEventsOptions, options ...RequestOptionFunc) (*Response, error) { - req, err := s.client.NewRequest(http.MethodPost, "usage_data/track_events", opt, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodPost), + withPath("usage_data/track_events"), + withAPIOpts(opt), + withRequestOpts(options...), + ) + return resp, err } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/users.go b/vendor/gitlab.com/gitlab-org/api/client-go/users.go index f20992b4..da92c2d1 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/users.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/users.go @@ -23,10 +23,7 @@ import ( "io" "net" "net/http" - "strings" "time" - - "github.com/hashicorp/go-retryablehttp" ) type ( @@ -89,6 +86,9 @@ type ( ListSSHKeys(opt *ListSSHKeysOptions, options ...RequestOptionFunc) ([]*SSHKey, *Response, error) // ListSSHKeysForUser gets a list of a specified user's SSH keys. // + // uid can be either a user ID (int) or a username (string). If a username + // is provided with a leading "@" (e.g., "@johndoe"), it will be trimmed. + // // GitLab API docs: // https://docs.gitlab.com/api/user_keys/#list-all-ssh-keys-for-a-user ListSSHKeysForUser(uid any, opt *ListSSHKeysForUserOptions, options ...RequestOptionFunc) ([]*SSHKey, *Response, error) @@ -334,11 +334,24 @@ var ( // BasicUser included in other service responses (such as merge requests, pipelines, etc). type BasicUser struct { - ID int64 `json:"id"` - Username string `json:"username"` - Name string `json:"name"` - State string `json:"state"` - Locked bool `json:"locked"` + ID int64 `json:"id"` + Username string `json:"username"` + Name string `json:"name"` + + // State represents the administrative status of the user account. + // Common values: "active", "blocked", "deactivated", "banned", + // "ldap_blocked", "blocked_pending_approval". + // + // This is independent from the Locked field: State tracks permanent + // administrative actions, while Locked handles temporary login failures. + State string `json:"state"` + + // Locked indicates whether the user account is temporarily locked due to + // excessive failed login attempts. This is separate from administrative + // blocking (the State field). Locks automatically expire after a configured + // time period (default: 10 minutes). + Locked bool `json:"locked"` + CreatedAt *time.Time `json:"created_at"` AvatarURL string `json:"avatar_url"` WebURL string `json:"web_url"` @@ -461,18 +474,11 @@ type ListUsersOptions struct { } func (s *UsersService) ListUsers(opt *ListUsersOptions, options ...RequestOptionFunc) ([]*User, *Response, error) { - req, err := s.client.NewRequest(http.MethodGet, "users", opt, options) - if err != nil { - return nil, nil, err - } - - var usr []*User - resp, err := s.client.Do(req, &usr) - if err != nil { - return nil, resp, err - } - - return usr, resp, nil + return do[[]*User](s.client, + withPath("users"), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // GetUsersOptions represents the available GetUser() options. @@ -483,20 +489,11 @@ type GetUsersOptions struct { } func (s *UsersService) GetUser(user int64, opt GetUsersOptions, options ...RequestOptionFunc) (*User, *Response, error) { - u := fmt.Sprintf("users/%d", user) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - usr := new(User) - resp, err := s.client.Do(req, usr) - if err != nil { - return nil, resp, err - } - - return usr, resp, nil + return do[*User](s.client, + withPath("users/%d", user), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // CreateUserOptions represents the available CreateUser() options. @@ -532,33 +529,16 @@ type CreateUserOptions struct { } func (s *UsersService) CreateUser(opt *CreateUserOptions, options ...RequestOptionFunc) (*User, *Response, error) { - var err error - var req *retryablehttp.Request - - if opt.Avatar == nil { - req, err = s.client.NewRequest(http.MethodPost, "users", opt, options) - } else { - req, err = s.client.UploadRequest( - http.MethodPost, - "users", - opt.Avatar.Image, - opt.Avatar.Filename, - UploadAvatar, - opt, - options, - ) + reqOpts := []doOption{ + withMethod(http.MethodPost), + withPath("users"), + withAPIOpts(opt), + withRequestOpts(options...), } - if err != nil { - return nil, nil, err + if opt.Avatar != nil { + reqOpts = append(reqOpts, withUpload(opt.Avatar.Image, opt.Avatar.Filename, UploadAvatar)) } - - usr := new(User) - resp, err := s.client.Do(req, usr) - if err != nil { - return nil, resp, err - } - - return usr, resp, nil + return do[*User](s.client, reqOpts...) } // ModifyUserOptions represents the available ModifyUser() options. @@ -594,60 +574,32 @@ type ModifyUserOptions struct { } func (s *UsersService) ModifyUser(user int64, opt *ModifyUserOptions, options ...RequestOptionFunc) (*User, *Response, error) { - var err error - var req *retryablehttp.Request - u := fmt.Sprintf("users/%d", user) - - if opt.Avatar == nil || (opt.Avatar.Filename == "" && opt.Avatar.Image == nil) { - req, err = s.client.NewRequest(http.MethodPut, u, opt, options) - } else { - req, err = s.client.UploadRequest( - http.MethodPut, - u, - opt.Avatar.Image, - opt.Avatar.Filename, - UploadAvatar, - opt, - options, - ) + reqOpts := []doOption{ + withMethod(http.MethodPut), + withPath("users/%d", user), + withAPIOpts(opt), + withRequestOpts(options...), } - if err != nil { - return nil, nil, err + if opt.Avatar != nil && (opt.Avatar.Filename != "" || opt.Avatar.Image != nil) { + reqOpts = append(reqOpts, withUpload(opt.Avatar.Image, opt.Avatar.Filename, UploadAvatar)) } - - usr := new(User) - resp, err := s.client.Do(req, usr) - if err != nil { - return nil, resp, err - } - - return usr, resp, nil + return do[*User](s.client, reqOpts...) } func (s *UsersService) DeleteUser(user int64, options ...RequestOptionFunc) (*Response, error) { - u := fmt.Sprintf("users/%d", user) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("users/%d", user), + withRequestOpts(options...), + ) + return resp, err } func (s *UsersService) CurrentUser(options ...RequestOptionFunc) (*User, *Response, error) { - req, err := s.client.NewRequest(http.MethodGet, "user", nil, options) - if err != nil { - return nil, nil, err - } - - usr := new(User) - resp, err := s.client.Do(req, usr) - if err != nil { - return nil, resp, err - } - - return usr, resp, nil + return do[*User](s.client, + withPath("user"), + withRequestOpts(options...), + ) } // UserStatus represents the current status of a user @@ -663,40 +615,24 @@ type UserStatus struct { } func (s *UsersService) CurrentUserStatus(options ...RequestOptionFunc) (*UserStatus, *Response, error) { - req, err := s.client.NewRequest(http.MethodGet, "user/status", nil, options) - if err != nil { - return nil, nil, err - } - - status := new(UserStatus) - resp, err := s.client.Do(req, status) - if err != nil { - return nil, resp, err - } - - return status, resp, nil + return do[*UserStatus](s.client, + withPath("user/status"), + withRequestOpts(options...), + ) } +// GetUserStatus retrieves a user's status. +// +// uid can be either a user ID (int) or a username (string). If a username +// is provided with a leading "@" (e.g., "@johndoe"), it will be trimmed. +// +// GitLab API docs: +// https://docs.gitlab.com/api/users/#get-the-status-of-a-user func (s *UsersService) GetUserStatus(uid any, options ...RequestOptionFunc) (*UserStatus, *Response, error) { - user, err := parseID(uid) - if err != nil { - return nil, nil, err - } - - u := fmt.Sprintf("users/%s/status", strings.TrimPrefix(user, "@")) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - status := new(UserStatus) - resp, err := s.client.Do(req, status) - if err != nil { - return nil, resp, err - } - - return status, resp, nil + return do[*UserStatus](s.client, + withPath("users/%s/status", UserID{uid}), + withRequestOpts(options...), + ) } // UserStatusOptions represents the options required to set the status @@ -711,18 +647,12 @@ type UserStatusOptions struct { } func (s *UsersService) SetUserStatus(opt *UserStatusOptions, options ...RequestOptionFunc) (*UserStatus, *Response, error) { - req, err := s.client.NewRequest(http.MethodPut, "user/status", opt, options) - if err != nil { - return nil, nil, err - } - - status := new(UserStatus) - resp, err := s.client.Do(req, status) - if err != nil { - return nil, resp, err - } - - return status, resp, nil + return do[*UserStatus](s.client, + withMethod(http.MethodPut), + withPath("user/status"), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // UserAssociationsCount represents the user associations count. @@ -741,20 +671,10 @@ type UserAssociationsCount struct { // GitLab API docs: // https://docs.gitlab.com/api/users/#get-a-count-of-a-users-projects-groups-issues-and-merge-requests func (s *UsersService) GetUserAssociationsCount(user int64, options ...RequestOptionFunc) (*UserAssociationsCount, *Response, error) { - u := fmt.Sprintf("users/%d/associations_count", user) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - uac := new(UserAssociationsCount) - resp, err := s.client.Do(req, uac) - if err != nil { - return nil, resp, err - } - - return uac, resp, nil + return do[*UserAssociationsCount](s.client, + withPath("users/%d/associations_count", user), + withRequestOpts(options...), + ) } // SSHKey represents a SSH key. @@ -777,18 +697,11 @@ type ListSSHKeysOptions struct { } func (s *UsersService) ListSSHKeys(opt *ListSSHKeysOptions, options ...RequestOptionFunc) ([]*SSHKey, *Response, error) { - req, err := s.client.NewRequest(http.MethodGet, "user/keys", opt, options) - if err != nil { - return nil, nil, err - } - - var k []*SSHKey - resp, err := s.client.Do(req, &k) - if err != nil { - return nil, resp, err - } - - return k, resp, nil + return do[[]*SSHKey](s.client, + withPath("user/keys"), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // ListSSHKeysForUserOptions represents the available ListSSHKeysForUser() options. @@ -799,59 +712,33 @@ type ListSSHKeysForUserOptions struct { ListOptions } +// ListSSHKeysForUser gets a list of a specified user's SSH keys. +// +// uid can be either a user ID (int) or a username (string). If a username +// is provided with a leading "@" (e.g., "@johndoe"), it will be trimmed. +// +// GitLab API docs: +// https://docs.gitlab.com/api/user_keys/#list-all-ssh-keys-for-a-user func (s *UsersService) ListSSHKeysForUser(uid any, opt *ListSSHKeysForUserOptions, options ...RequestOptionFunc) ([]*SSHKey, *Response, error) { - user, err := parseID(uid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("users/%s/keys", user) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var k []*SSHKey - resp, err := s.client.Do(req, &k) - if err != nil { - return nil, resp, err - } - - return k, resp, nil + return do[[]*SSHKey](s.client, + withPath("users/%s/keys", UserID{uid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } func (s *UsersService) GetSSHKey(key int64, options ...RequestOptionFunc) (*SSHKey, *Response, error) { - u := fmt.Sprintf("user/keys/%d", key) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - k := new(SSHKey) - resp, err := s.client.Do(req, k) - if err != nil { - return nil, resp, err - } - - return k, resp, nil + return do[*SSHKey](s.client, + withPath("user/keys/%d", key), + withRequestOpts(options...), + ) } func (s *UsersService) GetSSHKeyForUser(user int64, key int64, options ...RequestOptionFunc) (*SSHKey, *Response, error) { - u := fmt.Sprintf("users/%d/keys/%d", user, key) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - k := new(SSHKey) - resp, err := s.client.Do(req, k) - if err != nil { - return nil, resp, err - } - - return k, resp, nil + return do[*SSHKey](s.client, + withPath("users/%d/keys/%d", user, key), + withRequestOpts(options...), + ) } // AddSSHKeyOptions represents the available AddSSHKey() options. @@ -865,57 +752,39 @@ type AddSSHKeyOptions struct { } func (s *UsersService) AddSSHKey(opt *AddSSHKeyOptions, options ...RequestOptionFunc) (*SSHKey, *Response, error) { - req, err := s.client.NewRequest(http.MethodPost, "user/keys", opt, options) - if err != nil { - return nil, nil, err - } - - k := new(SSHKey) - resp, err := s.client.Do(req, k) - if err != nil { - return nil, resp, err - } - - return k, resp, nil + return do[*SSHKey](s.client, + withMethod(http.MethodPost), + withPath("user/keys"), + withAPIOpts(opt), + withRequestOpts(options...), + ) } func (s *UsersService) AddSSHKeyForUser(user int64, opt *AddSSHKeyOptions, options ...RequestOptionFunc) (*SSHKey, *Response, error) { - u := fmt.Sprintf("users/%d/keys", user) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - k := new(SSHKey) - resp, err := s.client.Do(req, k) - if err != nil { - return nil, resp, err - } - - return k, resp, nil + return do[*SSHKey](s.client, + withMethod(http.MethodPost), + withPath("users/%d/keys", user), + withAPIOpts(opt), + withRequestOpts(options...), + ) } func (s *UsersService) DeleteSSHKey(key int64, options ...RequestOptionFunc) (*Response, error) { - u := fmt.Sprintf("user/keys/%d", key) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("user/keys/%d", key), + withRequestOpts(options...), + ) + return resp, err } func (s *UsersService) DeleteSSHKeyForUser(user, key int64, options ...RequestOptionFunc) (*Response, error) { - u := fmt.Sprintf("users/%d/keys/%d", user, key) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("users/%d/keys/%d", user, key), + withRequestOpts(options...), + ) + return resp, err } // GPGKey represents a GPG key. @@ -928,35 +797,17 @@ type GPGKey struct { } func (s *UsersService) ListGPGKeys(options ...RequestOptionFunc) ([]*GPGKey, *Response, error) { - req, err := s.client.NewRequest(http.MethodGet, "user/gpg_keys", nil, options) - if err != nil { - return nil, nil, err - } - - var ks []*GPGKey - resp, err := s.client.Do(req, &ks) - if err != nil { - return nil, resp, err - } - - return ks, resp, nil + return do[[]*GPGKey](s.client, + withPath("user/gpg_keys"), + withRequestOpts(options...), + ) } func (s *UsersService) GetGPGKey(key int64, options ...RequestOptionFunc) (*GPGKey, *Response, error) { - u := fmt.Sprintf("user/gpg_keys/%d", key) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - k := new(GPGKey) - resp, err := s.client.Do(req, k) - if err != nil { - return nil, resp, err - } - - return k, resp, nil + return do[*GPGKey](s.client, + withPath("user/gpg_keys/%d", key), + withRequestOpts(options...), + ) } // AddGPGKeyOptions represents the available AddGPGKey() options. @@ -967,91 +818,53 @@ type AddGPGKeyOptions struct { } func (s *UsersService) AddGPGKey(opt *AddGPGKeyOptions, options ...RequestOptionFunc) (*GPGKey, *Response, error) { - req, err := s.client.NewRequest(http.MethodPost, "user/gpg_keys", opt, options) - if err != nil { - return nil, nil, err - } - - k := new(GPGKey) - resp, err := s.client.Do(req, k) - if err != nil { - return nil, resp, err - } - - return k, resp, nil + return do[*GPGKey](s.client, + withMethod(http.MethodPost), + withPath("user/gpg_keys"), + withAPIOpts(opt), + withRequestOpts(options...), + ) } func (s *UsersService) DeleteGPGKey(key int64, options ...RequestOptionFunc) (*Response, error) { - u := fmt.Sprintf("user/gpg_keys/%d", key) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("user/gpg_keys/%d", key), + withRequestOpts(options...), + ) + return resp, err } func (s *UsersService) ListGPGKeysForUser(user int64, options ...RequestOptionFunc) ([]*GPGKey, *Response, error) { - u := fmt.Sprintf("users/%d/gpg_keys", user) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - var ks []*GPGKey - resp, err := s.client.Do(req, &ks) - if err != nil { - return nil, resp, err - } - - return ks, resp, nil + return do[[]*GPGKey](s.client, + withPath("users/%d/gpg_keys", user), + withRequestOpts(options...), + ) } func (s *UsersService) GetGPGKeyForUser(user, key int64, options ...RequestOptionFunc) (*GPGKey, *Response, error) { - u := fmt.Sprintf("users/%d/gpg_keys/%d", user, key) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - k := new(GPGKey) - resp, err := s.client.Do(req, k) - if err != nil { - return nil, resp, err - } - - return k, resp, nil + return do[*GPGKey](s.client, + withPath("users/%d/gpg_keys/%d", user, key), + withRequestOpts(options...), + ) } func (s *UsersService) AddGPGKeyForUser(user int64, opt *AddGPGKeyOptions, options ...RequestOptionFunc) (*GPGKey, *Response, error) { - u := fmt.Sprintf("users/%d/gpg_keys", user) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - k := new(GPGKey) - resp, err := s.client.Do(req, k) - if err != nil { - return nil, resp, err - } - - return k, resp, nil + return do[*GPGKey](s.client, + withMethod(http.MethodPost), + withPath("users/%d/gpg_keys", user), + withAPIOpts(opt), + withRequestOpts(options...), + ) } func (s *UsersService) DeleteGPGKeyForUser(user, key int64, options ...RequestOptionFunc) (*Response, error) { - u := fmt.Sprintf("users/%d/gpg_keys/%d", user, key) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("users/%d/gpg_keys/%d", user, key), + withRequestOpts(options...), + ) + return resp, err } // Email represents an Email. @@ -1065,18 +878,10 @@ type Email struct { } func (s *UsersService) ListEmails(options ...RequestOptionFunc) ([]*Email, *Response, error) { - req, err := s.client.NewRequest(http.MethodGet, "user/emails", nil, options) - if err != nil { - return nil, nil, err - } - - var e []*Email - resp, err := s.client.Do(req, &e) - if err != nil { - return nil, resp, err - } - - return e, resp, nil + return do[[]*Email](s.client, + withPath("user/emails"), + withRequestOpts(options...), + ) } // ListEmailsForUserOptions represents the available ListEmailsForUser() options. @@ -1088,37 +893,18 @@ type ListEmailsForUserOptions struct { } func (s *UsersService) ListEmailsForUser(user int64, opt *ListEmailsForUserOptions, options ...RequestOptionFunc) ([]*Email, *Response, error) { - u := fmt.Sprintf("users/%d/emails", user) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var e []*Email - resp, err := s.client.Do(req, &e) - if err != nil { - return nil, resp, err - } - - return e, resp, nil + return do[[]*Email](s.client, + withPath("users/%d/emails", user), + withAPIOpts(opt), + withRequestOpts(options...), + ) } func (s *UsersService) GetEmail(email int64, options ...RequestOptionFunc) (*Email, *Response, error) { - u := fmt.Sprintf("user/emails/%d", email) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - e := new(Email) - resp, err := s.client.Do(req, e) - if err != nil { - return nil, resp, err - } - - return e, resp, nil + return do[*Email](s.client, + withPath("user/emails/%d", email), + withRequestOpts(options...), + ) } // AddEmailOptions represents the available AddEmail() options. @@ -1131,94 +917,66 @@ type AddEmailOptions struct { } func (s *UsersService) AddEmail(opt *AddEmailOptions, options ...RequestOptionFunc) (*Email, *Response, error) { - req, err := s.client.NewRequest(http.MethodPost, "user/emails", opt, options) - if err != nil { - return nil, nil, err - } - - e := new(Email) - resp, err := s.client.Do(req, e) - if err != nil { - return nil, resp, err - } - - return e, resp, nil + return do[*Email](s.client, + withMethod(http.MethodPost), + withPath("user/emails"), + withAPIOpts(opt), + withRequestOpts(options...), + ) } func (s *UsersService) AddEmailForUser(user int64, opt *AddEmailOptions, options ...RequestOptionFunc) (*Email, *Response, error) { - u := fmt.Sprintf("users/%d/emails", user) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - e := new(Email) - resp, err := s.client.Do(req, e) - if err != nil { - return nil, resp, err - } - - return e, resp, nil + return do[*Email](s.client, + withMethod(http.MethodPost), + withPath("users/%d/emails", user), + withAPIOpts(opt), + withRequestOpts(options...), + ) } func (s *UsersService) DeleteEmail(email int64, options ...RequestOptionFunc) (*Response, error) { - u := fmt.Sprintf("user/emails/%d", email) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("user/emails/%d", email), + withRequestOpts(options...), + ) + return resp, err } func (s *UsersService) DeleteEmailForUser(user, email int64, options ...RequestOptionFunc) (*Response, error) { - u := fmt.Sprintf("users/%d/emails/%d", user, email) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("users/%d/emails/%d", user, email), + withRequestOpts(options...), + ) + return resp, err } func (s *UsersService) BlockUser(user int64, options ...RequestOptionFunc) error { - u := fmt.Sprintf("users/%d/block", user) - - req, err := s.client.NewRequest(http.MethodPost, u, nil, options) - if err != nil { - return err - } - - _, doErr := s.client.Do(req, nil) - if doErr != nil { - return doErr - } - - return nil + _, _, err := do[none](s.client, + withMethod(http.MethodPost), + withPath("users/%d/block", user), + withRequestOpts(options...), + ) + return err } func (s *UsersService) UnblockUser(user int64, options ...RequestOptionFunc) error { - u := fmt.Sprintf("users/%d/unblock", user) - - req, err := s.client.NewRequest(http.MethodPost, u, nil, options) - if err != nil { - return err - } - - resp, err := s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodPost), + withPath("users/%d/unblock", user), + withRequestOpts(options...), + ) if err != nil && resp == nil { return err } switch resp.StatusCode { - case 201: + case http.StatusCreated: return nil - case 403: + case http.StatusForbidden: return ErrUserUnblockPrevented - case 404: + case http.StatusNotFound: return ErrUserNotFound default: return fmt.Errorf("%w: %d", errUnexpectedResultCode, resp.StatusCode) @@ -1226,22 +984,19 @@ func (s *UsersService) UnblockUser(user int64, options ...RequestOptionFunc) err } func (s *UsersService) BanUser(user int64, options ...RequestOptionFunc) error { - u := fmt.Sprintf("users/%d/ban", user) - - req, err := s.client.NewRequest(http.MethodPost, u, nil, options) - if err != nil { - return err - } - - resp, err := s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodPost), + withPath("users/%d/ban", user), + withRequestOpts(options...), + ) if err != nil && resp == nil { return err } switch resp.StatusCode { - case 201: + case http.StatusCreated: return nil - case 404: + case http.StatusNotFound: return ErrUserNotFound default: return fmt.Errorf("%w: %d", errUnexpectedResultCode, resp.StatusCode) @@ -1249,22 +1004,19 @@ func (s *UsersService) BanUser(user int64, options ...RequestOptionFunc) error { } func (s *UsersService) UnbanUser(user int64, options ...RequestOptionFunc) error { - u := fmt.Sprintf("users/%d/unban", user) - - req, err := s.client.NewRequest(http.MethodPost, u, nil, options) - if err != nil { - return err - } - - resp, err := s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodPost), + withPath("users/%d/unban", user), + withRequestOpts(options...), + ) if err != nil && resp == nil { return err } switch resp.StatusCode { - case 201: + case http.StatusCreated: return nil - case 404: + case http.StatusNotFound: return ErrUserNotFound default: return fmt.Errorf("%w: %d", errUnexpectedResultCode, resp.StatusCode) @@ -1272,24 +1024,21 @@ func (s *UsersService) UnbanUser(user int64, options ...RequestOptionFunc) error } func (s *UsersService) DeactivateUser(user int64, options ...RequestOptionFunc) error { - u := fmt.Sprintf("users/%d/deactivate", user) - - req, err := s.client.NewRequest(http.MethodPost, u, nil, options) - if err != nil { - return err - } - - resp, err := s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodPost), + withPath("users/%d/deactivate", user), + withRequestOpts(options...), + ) if err != nil && resp == nil { return err } switch resp.StatusCode { - case 201: + case http.StatusCreated: return nil - case 403: + case http.StatusForbidden: return ErrUserDeactivatePrevented - case 404: + case http.StatusNotFound: return ErrUserNotFound default: return fmt.Errorf("%w: %d", errUnexpectedResultCode, resp.StatusCode) @@ -1297,24 +1046,21 @@ func (s *UsersService) DeactivateUser(user int64, options ...RequestOptionFunc) } func (s *UsersService) ActivateUser(user int64, options ...RequestOptionFunc) error { - u := fmt.Sprintf("users/%d/activate", user) - - req, err := s.client.NewRequest(http.MethodPost, u, nil, options) - if err != nil { - return err - } - - resp, err := s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodPost), + withPath("users/%d/activate", user), + withRequestOpts(options...), + ) if err != nil && resp == nil { return err } switch resp.StatusCode { - case 201: + case http.StatusCreated: return nil - case 403: + case http.StatusForbidden: return ErrUserActivatePrevented - case 404: + case http.StatusNotFound: return ErrUserNotFound default: return fmt.Errorf("%w: %d", errUnexpectedResultCode, resp.StatusCode) @@ -1322,24 +1068,21 @@ func (s *UsersService) ActivateUser(user int64, options ...RequestOptionFunc) er } func (s *UsersService) ApproveUser(user int64, options ...RequestOptionFunc) error { - u := fmt.Sprintf("users/%d/approve", user) - - req, err := s.client.NewRequest(http.MethodPost, u, nil, options) - if err != nil { - return err - } - - resp, err := s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodPost), + withPath("users/%d/approve", user), + withRequestOpts(options...), + ) if err != nil && resp == nil { return err } switch resp.StatusCode { - case 201: + case http.StatusCreated: return nil - case 403: + case http.StatusForbidden: return ErrUserApprovePrevented - case 404: + case http.StatusNotFound: return ErrUserNotFound default: return fmt.Errorf("%w: %d", errUnexpectedResultCode, resp.StatusCode) @@ -1347,26 +1090,23 @@ func (s *UsersService) ApproveUser(user int64, options ...RequestOptionFunc) err } func (s *UsersService) RejectUser(user int64, options ...RequestOptionFunc) error { - u := fmt.Sprintf("users/%d/reject", user) - - req, err := s.client.NewRequest(http.MethodPost, u, nil, options) - if err != nil { - return err - } - - resp, err := s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodPost), + withPath("users/%d/reject", user), + withRequestOpts(options...), + ) if err != nil && resp == nil { return err } switch resp.StatusCode { - case 200: + case http.StatusOK: return nil - case 403: + case http.StatusForbidden: return ErrUserRejectPrevented - case 404: + case http.StatusNotFound: return ErrUserNotFound - case 409: + case http.StatusConflict: return ErrUserConflict default: return fmt.Errorf("%w: %d", errUnexpectedResultCode, resp.StatusCode) @@ -1400,37 +1140,18 @@ type GetAllImpersonationTokensOptions struct { } func (s *UsersService) GetAllImpersonationTokens(user int64, opt *GetAllImpersonationTokensOptions, options ...RequestOptionFunc) ([]*ImpersonationToken, *Response, error) { - u := fmt.Sprintf("users/%d/impersonation_tokens", user) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var ts []*ImpersonationToken - resp, err := s.client.Do(req, &ts) - if err != nil { - return nil, resp, err - } - - return ts, resp, nil + return do[[]*ImpersonationToken](s.client, + withPath("users/%d/impersonation_tokens", user), + withAPIOpts(opt), + withRequestOpts(options...), + ) } func (s *UsersService) GetImpersonationToken(user, token int64, options ...RequestOptionFunc) (*ImpersonationToken, *Response, error) { - u := fmt.Sprintf("users/%d/impersonation_tokens/%d", user, token) - - req, err := s.client.NewRequest(http.MethodGet, u, nil, options) - if err != nil { - return nil, nil, err - } - - t := new(ImpersonationToken) - resp, err := s.client.Do(req, &t) - if err != nil { - return nil, resp, err - } - - return t, resp, nil + return do[*ImpersonationToken](s.client, + withPath("users/%d/impersonation_tokens/%d", user, token), + withRequestOpts(options...), + ) } // CreateImpersonationTokenOptions represents the available @@ -1445,31 +1166,21 @@ type CreateImpersonationTokenOptions struct { } func (s *UsersService) CreateImpersonationToken(user int64, opt *CreateImpersonationTokenOptions, options ...RequestOptionFunc) (*ImpersonationToken, *Response, error) { - u := fmt.Sprintf("users/%d/impersonation_tokens", user) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - t := new(ImpersonationToken) - resp, err := s.client.Do(req, &t) - if err != nil { - return nil, resp, err - } - - return t, resp, nil + return do[*ImpersonationToken](s.client, + withMethod(http.MethodPost), + withPath("users/%d/impersonation_tokens", user), + withAPIOpts(opt), + withRequestOpts(options...), + ) } func (s *UsersService) RevokeImpersonationToken(user, token int64, options ...RequestOptionFunc) (*Response, error) { - u := fmt.Sprintf("users/%d/impersonation_tokens/%d", user, token) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("users/%d/impersonation_tokens/%d", user, token), + withRequestOpts(options...), + ) + return resp, err } // CreatePersonalAccessTokenOptions represents the available @@ -1485,20 +1196,12 @@ type CreatePersonalAccessTokenOptions struct { } func (s *UsersService) CreatePersonalAccessToken(user int64, opt *CreatePersonalAccessTokenOptions, options ...RequestOptionFunc) (*PersonalAccessToken, *Response, error) { - u := fmt.Sprintf("users/%d/personal_access_tokens", user) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - t := new(PersonalAccessToken) - resp, err := s.client.Do(req, &t) - if err != nil { - return nil, resp, err - } - - return t, resp, nil + return do[*PersonalAccessToken](s.client, + withMethod(http.MethodPost), + withPath("users/%d/personal_access_tokens", user), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // CreatePersonalAccessTokenForCurrentUserOptions represents the available @@ -1514,20 +1217,12 @@ type CreatePersonalAccessTokenForCurrentUserOptions struct { } func (s *UsersService) CreatePersonalAccessTokenForCurrentUser(opt *CreatePersonalAccessTokenForCurrentUserOptions, options ...RequestOptionFunc) (*PersonalAccessToken, *Response, error) { - u := "user/personal_access_tokens" - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - t := new(PersonalAccessToken) - resp, err := s.client.Do(req, &t) - if err != nil { - return nil, resp, err - } - - return t, resp, nil + return do[*PersonalAccessToken](s.client, + withMethod(http.MethodPost), + withPath("user/personal_access_tokens"), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // UserActivity represents an entry in the user/activities response @@ -1549,18 +1244,11 @@ type GetUserActivitiesOptions struct { } func (s *UsersService) GetUserActivities(opt *GetUserActivitiesOptions, options ...RequestOptionFunc) ([]*UserActivity, *Response, error) { - req, err := s.client.NewRequest(http.MethodGet, "user/activities", opt, options) - if err != nil { - return nil, nil, err - } - - var t []*UserActivity - resp, err := s.client.Do(req, &t) - if err != nil { - return nil, resp, err - } - - return t, resp, nil + return do[[]*UserActivity](s.client, + withPath("user/activities"), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // UserMembership represents a membership of the user in a namespace or project. @@ -1584,43 +1272,31 @@ type GetUserMembershipOptions struct { } func (s *UsersService) GetUserMemberships(user int64, opt *GetUserMembershipOptions, options ...RequestOptionFunc) ([]*UserMembership, *Response, error) { - u := fmt.Sprintf("users/%d/memberships", user) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var m []*UserMembership - resp, err := s.client.Do(req, &m) - if err != nil { - return nil, resp, err - } - - return m, resp, nil + return do[[]*UserMembership](s.client, + withPath("users/%d/memberships", user), + withAPIOpts(opt), + withRequestOpts(options...), + ) } func (s *UsersService) DisableTwoFactor(user int64, options ...RequestOptionFunc) error { - u := fmt.Sprintf("users/%d/disable_two_factor", user) - - req, err := s.client.NewRequest(http.MethodPatch, u, nil, options) - if err != nil { - return err - } - - resp, err := s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodPatch), + withPath("users/%d/disable_two_factor", user), + withRequestOpts(options...), + ) if err != nil && resp == nil { return err } switch resp.StatusCode { - case 204: + case http.StatusNoContent: return nil - case 400: + case http.StatusBadRequest: return ErrUserTwoFactorNotEnabled - case 403: + case http.StatusForbidden: return ErrUserDisableTwoFactorPrevented - case 404: + case http.StatusNotFound: return ErrUserNotFound default: return fmt.Errorf("%w: %d", errUnexpectedResultCode, resp.StatusCode) @@ -1656,18 +1332,12 @@ type CreateUserRunnerOptions struct { } func (s *UsersService) CreateUserRunner(opts *CreateUserRunnerOptions, options ...RequestOptionFunc) (*UserRunner, *Response, error) { - req, err := s.client.NewRequest(http.MethodPost, "user/runners", opts, options) - if err != nil { - return nil, nil, err - } - - r := new(UserRunner) - resp, err := s.client.Do(req, r) - if err != nil { - return nil, resp, err - } - - return r, resp, nil + return do[*UserRunner](s.client, + withMethod(http.MethodPost), + withPath("user/runners"), + withAPIOpts(opts), + withRequestOpts(options...), + ) } // CreateServiceAccountUserOptions represents the available CreateServiceAccountUser() options. @@ -1681,67 +1351,36 @@ type CreateServiceAccountUserOptions struct { } func (s *UsersService) CreateServiceAccountUser(opts *CreateServiceAccountUserOptions, options ...RequestOptionFunc) (*User, *Response, error) { - req, err := s.client.NewRequest(http.MethodPost, "service_accounts", opts, options) - if err != nil { - return nil, nil, err - } - - usr := new(User) - resp, err := s.client.Do(req, usr) - if err != nil { - return nil, resp, err - } - - return usr, resp, nil + return do[*User](s.client, + withMethod(http.MethodPost), + withPath("service_accounts"), + withAPIOpts(opts), + withRequestOpts(options...), + ) } func (s *UsersService) ListServiceAccounts(opt *ListServiceAccountsOptions, options ...RequestOptionFunc) ([]*ServiceAccount, *Response, error) { - req, err := s.client.NewRequest(http.MethodGet, "service_accounts", opt, options) - if err != nil { - return nil, nil, err - } - - var sas []*ServiceAccount - resp, err := s.client.Do(req, &sas) - if err != nil { - return nil, resp, err - } - - return sas, resp, nil + return do[[]*ServiceAccount](s.client, + withPath("service_accounts"), + withAPIOpts(opt), + withRequestOpts(options...), + ) } func (s *UsersService) UploadAvatar(avatar io.Reader, filename string, options ...RequestOptionFunc) (*User, *Response, error) { - u := "user/avatar" - - req, err := s.client.UploadRequest( - http.MethodPut, - u, - avatar, - filename, - UploadAvatar, - nil, - options, + return do[*User](s.client, + withMethod(http.MethodPut), + withPath("user/avatar"), + withUpload(avatar, filename, UploadAvatar), + withRequestOpts(options...), ) - if err != nil { - return nil, nil, err - } - - usr := new(User) - resp, err := s.client.Do(req, usr) - if err != nil { - return nil, resp, err - } - - return usr, resp, nil } func (s *UsersService) DeleteUserIdentity(user int64, provider string, options ...RequestOptionFunc) (*Response, error) { - u := fmt.Sprintf("users/%d/identities/%s", user, provider) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("users/%d/identities/%s", user, provider), + withRequestOpts(options...), + ) + return resp, err } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/validate.go b/vendor/gitlab.com/gitlab-org/api/client-go/validate.go index ee1906b3..0aa6e587 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/validate.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/validate.go @@ -16,10 +16,7 @@ package gitlab -import ( - "fmt" - "net/http" -) +import "net/http" type ( ValidateServiceInterface interface { @@ -95,24 +92,12 @@ type ProjectNamespaceLintOptions struct { } func (s *ValidateService) ProjectNamespaceLint(pid any, opt *ProjectNamespaceLintOptions, options ...RequestOptionFunc) (*ProjectLintResult, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/ci/lint", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPost, u, &opt, options) - if err != nil { - return nil, nil, err - } - - l := new(ProjectLintResult) - resp, err := s.client.Do(req, l) - if err != nil { - return nil, resp, err - } - - return l, resp, nil + return do[*ProjectLintResult](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/ci/lint", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // ProjectLintOptions represents the available ProjectLint() options. @@ -128,22 +113,9 @@ type ProjectLintOptions struct { } func (s *ValidateService) ProjectLint(pid any, opt *ProjectLintOptions, options ...RequestOptionFunc) (*ProjectLintResult, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/ci/lint", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, &opt, options) - if err != nil { - return nil, nil, err - } - - l := new(ProjectLintResult) - resp, err := s.client.Do(req, l) - if err != nil { - return nil, resp, err - } - - return l, resp, nil + return do[*ProjectLintResult](s.client, + withPath("projects/%s/ci/lint", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/version.go b/vendor/gitlab.com/gitlab-org/api/client-go/version.go index 90bd2552..c548f1c7 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/version.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/version.go @@ -16,8 +16,6 @@ package gitlab -import "net/http" - type ( VersionServiceInterface interface { GetVersion(options ...RequestOptionFunc) (*Version, *Response, error) @@ -51,16 +49,8 @@ func (s Version) String() string { // // GitLab API docs: https://docs.gitlab.com/api/version/ func (s *VersionService) GetVersion(options ...RequestOptionFunc) (*Version, *Response, error) { - req, err := s.client.NewRequest(http.MethodGet, "version", nil, options) - if err != nil { - return nil, nil, err - } - - v := new(Version) - resp, err := s.client.Do(req, v) - if err != nil { - return nil, resp, err - } - - return v, resp, nil + return do[*Version](s.client, + withPath("version"), + withRequestOpts(options...), + ) } diff --git a/vendor/gitlab.com/gitlab-org/api/client-go/wikis.go b/vendor/gitlab.com/gitlab-org/api/client-go/wikis.go index 63faccdf..65b3d85d 100644 --- a/vendor/gitlab.com/gitlab-org/api/client-go/wikis.go +++ b/vendor/gitlab.com/gitlab-org/api/client-go/wikis.go @@ -16,10 +16,8 @@ package gitlab import ( - "fmt" "io" "net/http" - "net/url" ) type ( @@ -28,24 +26,24 @@ type ( // When with_content is set, it also returns the content of the pages. // // GitLab API docs: - // https://docs.gitlab.com/api/wikis/#list-wiki-pages + // https://docs.gitlab.com/api/wikis/#list-all-wiki-pages ListWikis(pid any, opt *ListWikisOptions, options ...RequestOptionFunc) ([]*Wiki, *Response, error) // GetWikiPage gets a wiki page for a given project. // // GitLab API docs: - // https://docs.gitlab.com/api/wikis/#get-a-wiki-page + // https://docs.gitlab.com/api/wikis/#retrieve-a-wiki-page GetWikiPage(pid any, slug string, opt *GetWikiPageOptions, options ...RequestOptionFunc) (*Wiki, *Response, error) // CreateWikiPage creates a new wiki page for the given repository with // the given title, slug, and content. // // GitLab API docs: - // https://docs.gitlab.com/api/wikis/#create-a-new-wiki-page + // https://docs.gitlab.com/api/wikis/#create-a-wiki-page CreateWikiPage(pid any, opt *CreateWikiPageOptions, options ...RequestOptionFunc) (*Wiki, *Response, error) // EditWikiPage Updates an existing wiki page. At least one parameter is // required to update the wiki page. // // GitLab API docs: - // https://docs.gitlab.com/api/wikis/#edit-an-existing-wiki-page + // https://docs.gitlab.com/api/wikis/#update-a-wiki-page EditWikiPage(pid any, slug string, opt *EditWikiPageOptions, options ...RequestOptionFunc) (*Wiki, *Response, error) // DeleteWikiPage deletes a wiki page with a given slug. // @@ -120,24 +118,11 @@ type ListWikisOptions struct { } func (s *WikisService) ListWikis(pid any, opt *ListWikisOptions, options ...RequestOptionFunc) ([]*Wiki, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/wikis", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - var ws []*Wiki - resp, err := s.client.Do(req, &ws) - if err != nil { - return nil, resp, err - } - - return ws, resp, nil + return do[[]*Wiki](s.client, + withPath("projects/%s/wikis", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // GetWikiPageOptions represents options to GetWikiPage @@ -150,24 +135,11 @@ type GetWikiPageOptions struct { } func (s *WikisService) GetWikiPage(pid any, slug string, opt *GetWikiPageOptions, options ...RequestOptionFunc) (*Wiki, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/wikis/%s", PathEscape(project), url.PathEscape(slug)) - - req, err := s.client.NewRequest(http.MethodGet, u, opt, options) - if err != nil { - return nil, nil, err - } - - w := new(Wiki) - resp, err := s.client.Do(req, w) - if err != nil { - return nil, resp, err - } - - return w, resp, nil + return do[*Wiki](s.client, + withPath("projects/%s/wikis/%s", ProjectID{pid}, slug), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // CreateWikiPageOptions represents options to CreateWikiPage. @@ -181,24 +153,12 @@ type CreateWikiPageOptions struct { } func (s *WikisService) CreateWikiPage(pid any, opt *CreateWikiPageOptions, options ...RequestOptionFunc) (*Wiki, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/wikis", PathEscape(project)) - - req, err := s.client.NewRequest(http.MethodPost, u, opt, options) - if err != nil { - return nil, nil, err - } - - w := new(Wiki) - resp, err := s.client.Do(req, w) - if err != nil { - return nil, resp, err - } - - return w, resp, nil + return do[*Wiki](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/wikis", ProjectID{pid}), + withAPIOpts(opt), + withRequestOpts(options...), + ) } // EditWikiPageOptions represents options to EditWikiPage. @@ -212,39 +172,21 @@ type EditWikiPageOptions struct { } func (s *WikisService) EditWikiPage(pid any, slug string, opt *EditWikiPageOptions, options ...RequestOptionFunc) (*Wiki, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/wikis/%s", PathEscape(project), url.PathEscape(slug)) - - req, err := s.client.NewRequest(http.MethodPut, u, opt, options) - if err != nil { - return nil, nil, err - } - - w := new(Wiki) - resp, err := s.client.Do(req, w) - if err != nil { - return nil, resp, err - } - - return w, resp, nil + return do[*Wiki](s.client, + withMethod(http.MethodPut), + withPath("projects/%s/wikis/%s", ProjectID{pid}, slug), + withAPIOpts(opt), + withRequestOpts(options...), + ) } func (s *WikisService) DeleteWikiPage(pid any, slug string, options ...RequestOptionFunc) (*Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, err - } - u := fmt.Sprintf("projects/%s/wikis/%s", PathEscape(project), url.PathEscape(slug)) - - req, err := s.client.NewRequest(http.MethodDelete, u, nil, options) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) + _, resp, err := do[none](s.client, + withMethod(http.MethodDelete), + withPath("projects/%s/wikis/%s", ProjectID{pid}, slug), + withRequestOpts(options...), + ) + return resp, err } // UploadWikiAttachmentOptions represents options to UploadWikiAttachment. @@ -256,22 +198,11 @@ type UploadWikiAttachmentOptions struct { } func (s *WikisService) UploadWikiAttachment(pid any, content io.Reader, filename string, opt *UploadWikiAttachmentOptions, options ...RequestOptionFunc) (*WikiAttachment, *Response, error) { - project, err := parseID(pid) - if err != nil { - return nil, nil, err - } - u := fmt.Sprintf("projects/%s/wikis/attachments", PathEscape(project)) - - req, err := s.client.UploadRequest(http.MethodPost, u, content, filename, UploadFile, opt, options) - if err != nil { - return nil, nil, err - } - - attachment := new(WikiAttachment) - resp, err := s.client.Do(req, attachment) - if err != nil { - return nil, resp, err - } - - return attachment, resp, nil + return do[*WikiAttachment](s.client, + withMethod(http.MethodPost), + withPath("projects/%s/wikis/attachments", ProjectID{pid}), + withUpload(content, filename, UploadFile), + withAPIOpts(opt), + withRequestOpts(options...), + ) } diff --git a/vendor/modules.txt b/vendor/modules.txt index 4fdc56f5..33e30a29 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -12,8 +12,8 @@ github.com/google/go-cmp/cmp/internal/diff github.com/google/go-cmp/cmp/internal/flags github.com/google/go-cmp/cmp/internal/function github.com/google/go-cmp/cmp/internal/value -# github.com/google/go-querystring v1.1.0 -## explicit; go 1.10 +# github.com/google/go-querystring v1.2.0 +## explicit; go 1.13 github.com/google/go-querystring/query # github.com/hashicorp/go-cleanhttp v0.5.2 ## explicit; go 1.13 @@ -67,7 +67,7 @@ github.com/onsi/gomega/matchers/support/goraph/edge github.com/onsi/gomega/matchers/support/goraph/node github.com/onsi/gomega/matchers/support/goraph/util github.com/onsi/gomega/types -# gitlab.com/gitlab-org/api/client-go v1.9.1 +# gitlab.com/gitlab-org/api/client-go v1.31.0 ## explicit; go 1.24.0 gitlab.com/gitlab-org/api/client-go # go.yaml.in/yaml/v3 v3.0.4