Update github.com/xanzy/go-gitlab v0.51.1 -> v0.52.2 (#599)

This commit is contained in:
6543 2021-12-12 16:39:25 +01:00 committed by GitHub
parent fe6c999160
commit 70fcc173b9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
32 changed files with 1431 additions and 345 deletions

9
go.mod
View file

@ -26,6 +26,7 @@ require (
github.com/google/go-github/v39 v39.2.0
github.com/gorilla/securecookie v1.1.1
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-retryablehttp v0.7.0 // indirect
github.com/joho/godotenv v1.4.0
github.com/lib/pq v1.10.3
github.com/mattn/go-sqlite3 v1.14.9
@ -42,15 +43,15 @@ require (
github.com/ugorji/go v1.2.6 // indirect
github.com/urfave/cli/v2 v2.3.0
github.com/woodpecker-ci/expr v0.0.0-20210628233344-164b8b3d0915
github.com/xanzy/go-gitlab v0.51.1
github.com/xanzy/go-gitlab v0.52.2
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
github.com/xeipuuv/gojsonschema v1.2.0
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519
golang.org/x/net v0.0.0-20211020060615-d418f374d309
golang.org/x/oauth2 v0.0.0-20211005180243-6b3c2da341f1
golang.org/x/net v0.0.0-20211209124913-491a49abca63
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359 // indirect
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
golang.org/x/time v0.0.0-20211116232009-f0f3c7e86c11 // indirect
google.golang.org/genproto v0.0.0-20211027162914-98a5263abeca // indirect
google.golang.org/grpc v1.41.0
google.golang.org/protobuf v1.27.1

19
go.sum
View file

@ -694,8 +694,9 @@ github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHh
github.com/hashicorp/go-multierror v1.1.0/go.mod h1:spPvp8C1qA32ftKqdAHm4hHTbPw+vmowP0z+KUhOZdA=
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/hashicorp/go-retryablehttp v0.6.8 h1:92lWxgpa+fF3FozM4B3UZtHZMJX8T5XT+TFdCxsPyWs=
github.com/hashicorp/go-retryablehttp v0.6.8/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY=
github.com/hashicorp/go-retryablehttp v0.7.0 h1:eu1EI/mbirUgP5C8hVsTNaGZreBDlYiwC1FZWkvQPQ4=
github.com/hashicorp/go-retryablehttp v0.7.0/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY=
github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU=
github.com/hashicorp/go-rootcerts v1.0.2/go.mod h1:pqUvnprVnM5bf7AOirdbb01K4ccR319Vf4pU3K5EGc8=
github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU=
@ -1342,8 +1343,8 @@ github.com/willf/bitset v1.1.11-0.20200630133818-d5bec3311243/go.mod h1:RjeCKbqT
github.com/willf/bitset v1.1.11/go.mod h1:83CECat5yLh5zVOf4P1ErAgKA5UDvKtgyUABdr3+MjI=
github.com/woodpecker-ci/expr v0.0.0-20210628233344-164b8b3d0915 h1:9zBOoKSR9CBeYoKQv6LFIuImg8lorCjh8XzK72bJMRg=
github.com/woodpecker-ci/expr v0.0.0-20210628233344-164b8b3d0915/go.mod h1:PbzlZ93HrA1cf16OUP1vckAPq57gtF+ccnwZeDkmC9s=
github.com/xanzy/go-gitlab v0.51.1 h1:wWKLalwx4omxFoHh3PLs9zDgAD4GXDP/uoxwMRCSiWM=
github.com/xanzy/go-gitlab v0.51.1/go.mod h1:Q+hQhV508bDPoBijv7YjK/Lvlb4PhVhJdKqXVQrUoAE=
github.com/xanzy/go-gitlab v0.52.2 h1:gkgg1z4ON70sphibtD86Bfmt1qV3mZ0pU0CBBCFAEvQ=
github.com/xanzy/go-gitlab v0.52.2/go.mod h1:Q+hQhV508bDPoBijv7YjK/Lvlb4PhVhJdKqXVQrUoAE=
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb h1:zGWFAtiMcyryUHoUjUJX0/lt1H2+i2Ka2n+D3DImSNo=
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
@ -1533,8 +1534,8 @@ golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT
golang.org/x/net v0.0.0-20210503060351-7fd8e65b6420/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20210510120150-4163338589ed/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211020060615-d418f374d309 h1:A0lJIi+hcTR6aajJH4YqKWwohY4aW9RO7oRMcdv+HKI=
golang.org/x/net v0.0.0-20211020060615-d418f374d309/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211209124913-491a49abca63 h1:iocB37TsdFuN6IBRZ+ry36wrkoV51/tl5vOWqkcPGvY=
golang.org/x/net v0.0.0-20211209124913-491a49abca63/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20181106182150-f42d05182288/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
@ -1552,8 +1553,8 @@ golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c/go.mod h1:KelEdhl1UZF7XfJ
golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
golang.org/x/oauth2 v0.0.0-20210805134026-6f1e6394065a/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
golang.org/x/oauth2 v0.0.0-20211005180243-6b3c2da341f1 h1:B333XXssMuKQeBwiNODx4TupZy7bf4sxFZnN2ZOcvUE=
golang.org/x/oauth2 v0.0.0-20211005180243-6b3c2da341f1/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 h1:RerP+noqYHUQ8CMRcPlC2nvTa4dcBIjegkuWdcUDuqg=
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@ -1694,8 +1695,8 @@ golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxb
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac h1:7zkz7BUtwNFFqcowJ+RIgu2MaV/MapERkDIy+mwPyjs=
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20211116232009-f0f3c7e86c11 h1:GZokNIeuVkl3aZHJchRrr13WCsols02MLUcz1U9is6M=
golang.org/x/time v0.0.0-20211116232009-f0f3c7e86c11/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20180525024113-a5b4c53f6e8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=

View file

@ -471,7 +471,7 @@ func baseRetryPolicy(resp *http.Response, err error) (bool, error) {
// seconds the server states it may be ready to process more requests from this client.
func DefaultBackoff(min, max time.Duration, attemptNum int, resp *http.Response) time.Duration {
if resp != nil {
if resp.StatusCode == http.StatusTooManyRequests {
if resp.StatusCode == http.StatusTooManyRequests || resp.StatusCode == http.StatusServiceUnavailable {
if s, ok := resp.Header["Retry-After"]; ok {
if sleep, err := strconv.ParseInt(s[0], 10, 64); err == nil {
return time.Second * time.Duration(sleep)

View file

@ -34,6 +34,7 @@ to add new and/or missing endpoints. Currently the following services are suppor
- [x] Events
- [x] Feature Flags
- [ ] Geo Nodes
- [x] Generic Packages
- [x] GitLab CI Config Templates
- [x] Gitignores Templates
- [x] Group Access Requests
@ -57,12 +58,14 @@ to add new and/or missing endpoints. Currently the following services are suppor
- [x] Notes (comments)
- [x] Notification Settings
- [x] Open Source License Templates
- [x] Packages
- [x] Pages
- [x] Pages Domains
- [x] Personal Access Tokens
- [x] Pipeline Schedules
- [x] Pipeline Triggers
- [x] Pipelines
- [x] Plan limits
- [x] Project Access Requests
- [x] Project Badges
- [x] Project Clusters

View file

@ -225,7 +225,7 @@ func (s *AwardEmojiService) createAwardEmoji(pid interface{}, resource string, r
// GitLab API docs:
// https://docs.gitlab.com/ce/api/award_emoji.html#award-a-new-emoji-on-a-note
func (s *AwardEmojiService) DeleteIssueAwardEmoji(pid interface{}, issueIID, awardID int, options ...RequestOptionFunc) (*Response, error) {
return s.deleteAwardEmoji(pid, awardMergeRequest, issueIID, awardID, options...)
return s.deleteAwardEmoji(pid, awardIssue, issueIID, awardID, options...)
}
// DeleteMergeRequestAwardEmoji delete award emoji on a merge request.
@ -241,7 +241,7 @@ func (s *AwardEmojiService) DeleteMergeRequestAwardEmoji(pid interface{}, mergeR
// GitLab API docs:
// https://docs.gitlab.com/ce/api/award_emoji.html#award-a-new-emoji-on-a-note
func (s *AwardEmojiService) DeleteSnippetAwardEmoji(pid interface{}, snippetID, awardID int, options ...RequestOptionFunc) (*Response, error) {
return s.deleteAwardEmoji(pid, awardMergeRequest, snippetID, awardID, options...)
return s.deleteAwardEmoji(pid, awardSnippets, snippetID, awardID, options...)
}
// DeleteAwardEmoji Delete an award emoji on the specified resource.

View file

@ -466,11 +466,11 @@ func (s *CommitsService) SetCommitStatus(pid interface{}, sha string, opt *SetCo
return cs, resp, err
}
// GetMergeRequestsByCommit gets merge request associated with a commit.
// ListMergeRequestsByCommit gets merge request associated with a commit.
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/commits.html#list-merge-requests-associated-with-a-commit
func (s *CommitsService) GetMergeRequestsByCommit(pid interface{}, sha string, options ...RequestOptionFunc) ([]*MergeRequest, *Response, error) {
func (s *CommitsService) ListMergeRequestsByCommit(pid interface{}, sha string, options ...RequestOptionFunc) ([]*MergeRequest, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err

View file

@ -917,12 +917,12 @@ type ListCommitDiscussionsOptions ListOptions
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/discussions.html#list-project-commit-discussion-items
func (s *DiscussionsService) ListCommitDiscussions(pid interface{}, commit string, opt *ListCommitDiscussionsOptions, options ...RequestOptionFunc) ([]*Discussion, *Response, error) {
func (s *DiscussionsService) ListCommitDiscussions(pid interface{}, commit int, 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",
u := fmt.Sprintf("projects/%s/repository/commits/%d/discussions",
pathEscape(project),
commit,
)
@ -946,12 +946,12 @@ func (s *DiscussionsService) ListCommitDiscussions(pid interface{}, commit strin
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/discussions.html#get-single-commit-discussion-item
func (s *DiscussionsService) GetCommitDiscussion(pid interface{}, commit string, discussion string, options ...RequestOptionFunc) (*Discussion, *Response, error) {
func (s *DiscussionsService) GetCommitDiscussion(pid interface{}, commit int, 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",
u := fmt.Sprintf("projects/%s/repository/commits/%d/discussions/%s",
pathEscape(project),
commit,
discussion,
@ -986,12 +986,12 @@ type CreateCommitDiscussionOptions struct {
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/discussions.html#create-new-commit-thread
func (s *DiscussionsService) CreateCommitDiscussion(pid interface{}, commit string, opt *CreateCommitDiscussionOptions, options ...RequestOptionFunc) (*Discussion, *Response, error) {
func (s *DiscussionsService) CreateCommitDiscussion(pid interface{}, commit int, 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",
u := fmt.Sprintf("projects/%s/repository/commits/%d/discussions",
pathEscape(project),
commit,
)
@ -1024,12 +1024,12 @@ type AddCommitDiscussionNoteOptions struct {
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/discussions.html#add-note-to-existing-commit-thread
func (s *DiscussionsService) AddCommitDiscussionNote(pid interface{}, commit string, discussion string, opt *AddCommitDiscussionNoteOptions, options ...RequestOptionFunc) (*Note, *Response, error) {
func (s *DiscussionsService) AddCommitDiscussionNote(pid interface{}, commit int, 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",
u := fmt.Sprintf("projects/%s/repository/commits/%d/discussions/%s/notes",
pathEscape(project),
commit,
discussion,
@ -1063,12 +1063,12 @@ type UpdateCommitDiscussionNoteOptions struct {
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/discussions.html#modify-an-existing-commit-thread-note
func (s *DiscussionsService) UpdateCommitDiscussionNote(pid interface{}, commit string, discussion string, note int, opt *UpdateCommitDiscussionNoteOptions, options ...RequestOptionFunc) (*Note, *Response, error) {
func (s *DiscussionsService) UpdateCommitDiscussionNote(pid interface{}, commit int, discussion string, note int, 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",
u := fmt.Sprintf("projects/%s/repository/commits/%d/discussions/%s/notes/%d",
pathEscape(project),
commit,
discussion,
@ -1093,12 +1093,12 @@ func (s *DiscussionsService) UpdateCommitDiscussionNote(pid interface{}, commit
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/discussions.html#delete-a-commit-thread-note
func (s *DiscussionsService) DeleteCommitDiscussionNote(pid interface{}, commit string, discussion string, note int, options ...RequestOptionFunc) (*Response, error) {
func (s *DiscussionsService) DeleteCommitDiscussionNote(pid interface{}, commit int, discussion string, note int, 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",
u := fmt.Sprintf("projects/%s/repository/commits/%d/discussions/%s/notes/%d",
pathEscape(project),
commit,
discussion,

View file

@ -27,26 +27,33 @@ type EventType string
// List of available event types.
const (
EventConfidentialIssue EventType = "Confidential Issue Hook"
EventConfidentialNote EventType = "Confidential Note Hook"
EventTypeBuild EventType = "Build Hook"
EventTypeDeployment EventType = "Deployment Hook"
EventTypeIssue EventType = "Issue Hook"
EventConfidentialIssue EventType = "Confidential Issue Hook"
EventTypeJob EventType = "Job Hook"
EventTypeMergeRequest EventType = "Merge Request Hook"
EventTypeNote EventType = "Note Hook"
EventConfidentialNote EventType = "Confidential Note Hook"
EventTypePipeline EventType = "Pipeline Hook"
EventTypePush EventType = "Push Hook"
EventTypeRelease EventType = "Release Hook"
EventTypeServiceHook EventType = "Service Hook"
EventTypeSystemHook EventType = "System Hook"
EventTypeTagPush EventType = "Tag Push Hook"
EventTypeWikiPage EventType = "Wiki Page Hook"
)
const (
eventObjectKindPush = "push"
eventObjectKindTagPush = "tag_push"
eventObjectKindMergeRequest = "merge_request"
)
const (
noteableTypeCommit = "Commit"
noteableTypeMergeRequest = "MergeRequest"
noteableTypeIssue = "Issue"
noteableTypeMergeRequest = "MergeRequest"
noteableTypeSnippet = "Snippet"
)
@ -57,6 +64,10 @@ type noteEvent struct {
} `json:"object_attributes"`
}
type serviceEvent struct {
ObjectKind string `json:"object_kind"`
}
const eventTypeHeader = "X-Gitlab-Event"
// HookEventType returns the event type for the given request.
@ -119,9 +130,9 @@ func ParseSystemhook(payload []byte) (event interface{}, err error) {
}
switch e.EventName {
case "push":
case eventObjectKindPush:
event = &PushSystemEvent{}
case "tag_push":
case eventObjectKindTagPush:
event = &TagPushSystemEvent{}
case "repository_update":
event = &RepositoryUpdateSystemEvent{}
@ -209,16 +220,6 @@ func ParseWebhook(eventType EventType, payload []byte) (event interface{}, err e
event = &JobEvent{}
case EventTypeMergeRequest:
event = &MergeEvent{}
case EventTypePipeline:
event = &PipelineEvent{}
case EventTypePush:
event = &PushEvent{}
case EventTypeRelease:
event = &ReleaseEvent{}
case EventTypeTagPush:
event = &TagEvent{}
case EventTypeWikiPage:
event = &WikiPageEvent{}
case EventTypeNote, EventConfidentialNote:
note := &noteEvent{}
err := json.Unmarshal(payload, note)
@ -242,7 +243,32 @@ func ParseWebhook(eventType EventType, payload []byte) (event interface{}, err e
default:
return nil, fmt.Errorf("unexpected noteable type %s", note.ObjectAttributes.NoteableType)
}
case EventTypePipeline:
event = &PipelineEvent{}
case EventTypePush:
event = &PushEvent{}
case EventTypeRelease:
event = &ReleaseEvent{}
case EventTypeServiceHook:
service := &serviceEvent{}
err := json.Unmarshal(payload, service)
if err != nil {
return nil, err
}
switch service.ObjectKind {
case eventObjectKindPush:
event = &PushEvent{}
case eventObjectKindTagPush:
event = &TagEvent{}
case eventObjectKindMergeRequest:
event = &MergeEvent{}
default:
return nil, fmt.Errorf("unexpected service type %s", service.ObjectKind)
}
case EventTypeTagPush:
event = &TagEvent{}
case EventTypeWikiPage:
event = &WikiPageEvent{}
default:
return nil, fmt.Errorf("unexpected event type: %s", eventType)
}

View file

@ -640,6 +640,10 @@ type PipelineEvent struct {
FinishedAt string `json:"finished_at"`
Duration int `json:"duration"`
QueuedDuration int `json:"queued_duration"`
Variables []struct {
Key string `json:"key"`
Value string `json:"value"`
} `json:"variables"`
} `json:"object_attributes"`
MergeRequest struct {
ID int `json:"id"`
@ -694,15 +698,22 @@ type PipelineEvent struct {
AllowFailure bool `json:"allow_failure"`
User *EventUser `json:"user"`
Runner struct {
ID int `json:"id"`
Description string `json:"description"`
Active bool `json:"active"`
IsShared bool `json:"is_shared"`
ID int `json:"id"`
Description string `json:"description"`
Active bool `json:"active"`
IsShared bool `json:"is_shared"`
RunnerType string `json:"runner_type"`
Tags []string `json:"tags"`
} `json:"runner"`
ArtifactsFile struct {
Filename string `json:"filename"`
Size int `json:"size"`
} `json:"artifacts_file"`
Environment struct {
Name string `json:"name"`
Action string `json:"action"`
DeploymentTier string `json:"deployment_tier"`
} `json:"environment"`
} `json:"builds"`
}
@ -742,6 +753,7 @@ type PushEvent struct {
Commits []*struct {
ID string `json:"id"`
Message string `json:"message"`
Title string `json:"title"`
Timestamp *time.Time `json:"timestamp"`
URL string `json:"url"`
Author struct {
@ -896,6 +908,7 @@ type TagEvent struct {
Commits []*struct {
ID string `json:"id"`
Message string `json:"message"`
Title string `json:"title"`
Timestamp *time.Time `json:"timestamp"`
URL string `json:"url"`
Author struct {

View file

@ -0,0 +1,90 @@
package gitlab
import (
"fmt"
"net/http"
"time"
)
// ExternalStatusChecksService handles communication with the external
// status check related methods of the GitLab API.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/status_checks.html
type ExternalStatusChecksService struct {
client *Client
}
type MergeStatusCheck struct {
ID int `json:"id"`
Name string `json:"name"`
ExternalURL string `json:"external_url"`
Status string `json:"status"`
}
type ProjectStatusCheck struct {
ID int `json:"id"`
Name string `json:"name"`
ProjectID int `json:"project_id"`
ExternalURL string `json:"external_url"`
ProtectedBranches []StatusCheckProtectedBranch `json:"protected_branches"`
}
type StatusCheckProtectedBranch struct {
ID int `json:"id"`
ProjectID int `json:"project_id"`
Name string `json:"name"`
CreatedAt *time.Time `json:"created_at"`
UpdatedAt *time.Time `json:"updated_at"`
CodeOwnerApprovalRequired bool `json:"code_owner_approval_required"`
}
// ListMergeStatusChecks lists the external status checks that apply to it
// and their status for a single merge request.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/status_checks.html#list-status-checks-for-a-merge-request
func (s *ExternalStatusChecksService) ListMergeStatusChecks(pid interface{}, mr int, 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, err
}
// ListProjectStatusChecks lists the project external status checks.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/status_checks.html#get-project-external-status-checks
func (s *ExternalStatusChecksService) ListProjectStatusChecks(pid interface{}, 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, err
}

158
vendor/github.com/xanzy/go-gitlab/generic_packages.go generated vendored Normal file
View file

@ -0,0 +1,158 @@
//
// Copyright 2021, Sune Keller
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package gitlab
import (
"bytes"
"fmt"
"io"
"net/http"
"time"
)
// GenericPackagesService handles communication with the packages related
// methods of the GitLab API.
//
// GitLab docs:
// https://docs.gitlab.com/ee/user/packages/generic_packages/index.html
type GenericPackagesService struct {
client *Client
}
// GenericPackagesFile represents a GitLab generic package file.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/user/packages/generic_packages/index.html#publish-a-package-file
type GenericPackagesFile struct {
ID int `json:"id"`
PackageID int `json:"package_id"`
CreatedAt *time.Time `json:"created_at"`
UpdatedAt *time.Time `json:"updated_at"`
Size int `json:"size"`
FileStore int `json:"file_store"`
FileMD5 string `json:"file_md5"`
FileSHA1 string `json:"file_sha1"`
FileName string `json:"file_name"`
File struct {
URL string `json:"url"`
} `json:"file"`
FileSHA256 string `json:"file_sha256"`
VerificationRetryAt *time.Time `json:"verification_retry_at"`
VerifiedAt *time.Time `json:"verified_at"`
VerificationFailure bool `json:"verification_failure"`
VerificationRetryCount int `json:"verification_retry_count"`
VerificationChecksum string `json:"verification_checksum"`
VerificationState int `json:"verification_state"`
VerificationStartedAt *time.Time `json:"verification_started_at"`
NewFilePath string `json:"new_file_path"`
}
// FormatPackageURL returns the GitLab Package Registry URL for the given artifact metadata, without the BaseURL.
// This does not make a GitLab API request, but rather computes it based on their documentation.
func (s *GenericPackagesService) FormatPackageURL(pid interface{}, packageName, packageVersion, fileName string) (string, error) {
project, err := parseID(pid)
if err != nil {
return "", err
}
u := fmt.Sprintf(
"projects/%s/packages/generic/%s/%s/%s",
pathEscape(project),
pathEscape(packageName),
pathEscape(packageVersion),
pathEscape(fileName),
)
return u, nil
}
// PublishPackageFileOptions represents the available PublishPackageFile()
// options.
//
// GitLab docs:
// https://docs.gitlab.com/ee/user/packages/generic_packages/index.html#publish-a-package-file
type PublishPackageFileOptions struct {
Status *GenericPackageStatusValue `url:"status,omitempty" json:"status,omitempty"`
Select *GenericPackageSelectValue `url:"select,omitempty" json:"select,omitempty"`
}
// PublishPackageFile uploads a file to a project's package registry.
//
// GitLab docs:
// https://docs.gitlab.com/ee/user/packages/generic_packages/index.html#publish-a-package-file
func (s *GenericPackagesService) PublishPackageFile(pid interface{}, packageName, packageVersion, fileName string, content io.Reader, opt *PublishPackageFileOptions, options ...RequestOptionFunc) (*GenericPackagesFile, *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),
)
// We need to create the request as a GET request to make sure the options
// are set correctly. After the request is created we will overwrite both
// the method and the body.
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
// Overwrite the method and body.
req.Method = http.MethodPut
req.SetBody(content)
f := new(GenericPackagesFile)
resp, err := s.client.Do(req, f)
if err != nil {
return nil, resp, err
}
return f, resp, err
}
// DownloadPackageFile allows you to download the package file.
//
// GitLab docs:
// https://docs.gitlab.com/ee/user/packages/generic_packages/index.html#download-package-file
func (s *GenericPackagesService) DownloadPackageFile(pid interface{}, 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),
)
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
}

433
vendor/github.com/xanzy/go-gitlab/geo_nodes.go generated vendored Normal file
View file

@ -0,0 +1,433 @@
//
// Copyright 2021, Sander van Harmelen
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package gitlab
import (
"fmt"
"net/http"
)
// GeoNode represents a GitLab Geo Node.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/geo_nodes.html
type GeoNode struct {
ID int `json:"id"`
Name string `json:"name"`
URL string `json:"url"`
InternalURL string `json:"internal_url"`
Primary bool `json:"primary"`
Enabled bool `json:"enabled"`
Current bool `json:"current"`
FilesMaxCapacity int `json:"files_max_capacity"`
ReposMaxCapacity int `json:"repos_max_capacity"`
VerificationMaxCapacity int `json:"verification_max_capacity"`
SelectiveSyncType string `json:"selective_sync_type"`
SelectiveSyncShards []string `json:"selective_sync_shards"`
SelectiveSyncNamespaceIds []int `json:"selective_sync_namespace_ids"`
MinimumReverificationInterval int `json:"minimum_reverification_interval"`
ContainerRepositoriesMaxCapacity int `json:"container_repositories_max_capacity"`
SyncObjectStorage bool `json:"sync_object_storage"`
CloneProtocol string `json:"clone_protocol"`
WebEditURL string `json:"web_edit_url"`
WebGeoProjectsURL string `json:"web_geo_projects_url"`
Links GeoNodeLinks `json:"_links"`
}
// GeoNodeLinks represents links for GitLab GeoNode.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/geo_nodes.html
type GeoNodeLinks struct {
Self string `json:"self"`
Status string `json:"status"`
Repair string `json:"repair"`
}
// GeoNodesService handles communication with Geo Nodes related methods
// of GitLab API.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/geo_nodes.html
type GeoNodesService struct {
client *Client
}
// CreateGeoNodesOptions represents the available CreateGeoNode() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/geo_nodes.html#create-a-new-geo-node
type CreateGeoNodesOptions struct {
Primary *bool `url:"primary,omitempty" json:"primary,omitempty"`
Enabled *bool `url:"enabled,omitempty" json:"enabled,omitempty"`
Name *string `url:"name,omitempty" json:"name,omitempty"`
URL *string `url:"url,omitempty" json:"url,omitempty"`
InternalURL *string `url:"internal_url,omitempty" json:"internal_url,omitempty"`
FilesMaxCapacity *int `url:"files_max_capacity,omitempty" json:"files_max_capacity,omitempty"`
ReposMaxCapacity *int `url:"repos_max_capacity,omitempty" json:"repos_max_capacity,omitempty"`
VerificationMaxCapacity *int `url:"verification_max_capacity,omitempty" json:"verification_max_capacity,omitempty"`
ContainerRepositoriesMaxCapacity *int `url:"container_repositories_max_capacity,omitempty" json:"container_repositories_max_capacity,omitempty"`
SyncObjectStorage *bool `url:"sync_object_storage,omitempty" json:"sync_object_storage,omitempty"`
SelectiveSyncType *string `url:"selective_sync_type,omitempty" json:"selective_sync_type,omitempty"`
SelectiveSyncShards []string `url:"selective_sync_shards,omitempty" json:"selective_sync_shards,omitempty"`
SelectiveSyncNamespaceIds []int `url:"selective_sync_namespace_ids,omitempty" json:"selective_sync_namespace_ids,omitempty"`
MinimumReverificationInterval *int `url:"minimum_reverification_interval,omitempty" json:"minimum_reverification_interval,omitempty"`
}
// CreateGeoNode creates a new Geo Node.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/geo_nodes.html#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, err
}
// ListGeoNodesOptions represents the available ListGeoNodes() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/geo_nodes.html#retrieve-configuration-about-all-geo-nodes
type ListGeoNodesOptions ListOptions
// ListGeoNodes gets a list of geo nodes.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/geo_nodes.html#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, err
}
// GetGeoNode gets a specific geo node.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/geo_nodes.html#retrieve-configuration-about-a-specific-geo-node
func (s *GeoNodesService) GetGeoNode(id int, 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, err
}
// UpdateGeoNodesOptions represents the available EditGeoNode() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/geo_nodes.html#edit-a-geo-node
type UpdateGeoNodesOptions struct {
ID *int `url:"primary,omitempty" json:"primary,omitempty"`
Enabled *bool `url:"enabled,omitempty" json:"enabled,omitempty"`
Name *string `url:"name,omitempty" json:"name,omitempty"`
URL *string `url:"url,omitempty" json:"url,omitempty"`
InternalURL *string `url:"internal_url,omitempty" json:"internal_url,omitempty"`
FilesMaxCapacity *int `url:"files_max_capacity,omitempty" json:"files_max_capacity,omitempty"`
ReposMaxCapacity *int `url:"repos_max_capacity,omitempty" json:"repos_max_capacity,omitempty"`
VerificationMaxCapacity *int `url:"verification_max_capacity,omitempty" json:"verification_max_capacity,omitempty"`
ContainerRepositoriesMaxCapacity *int `url:"container_repositories_max_capacity,omitempty" json:"container_repositories_max_capacity,omitempty"`
SyncObjectStorage *bool `url:"sync_object_storage,omitempty" json:"sync_object_storage,omitempty"`
SelectiveSyncType *string `url:"selective_sync_type,omitempty" json:"selective_sync_type,omitempty"`
SelectiveSyncShards []string `url:"selective_sync_shards,omitempty" json:"selective_sync_shards,omitempty"`
SelectiveSyncNamespaceIds []int `url:"selective_sync_namespace_ids,omitempty" json:"selective_sync_namespace_ids,omitempty"`
MinimumReverificationInterval *int `url:"minimum_reverification_interval,omitempty" json:"minimum_reverification_interval,omitempty"`
}
// EditGeoNode updates settings of an existing Geo node.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/geo_nodes.html#edit-a-geo-node
func (s *GeoNodesService) EditGeoNode(id int, 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, err
}
// DeleteGeoNode removes the Geo node.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/geo_nodes.html#delete-a-geo-node
func (s *GeoNodesService) DeleteGeoNode(id int, 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)
}
// RepairGeoNode to repair the OAuth authentication of a Geo node.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/geo_nodes.html#repair-a-geo-node
func (s *GeoNodesService) RepairGeoNode(id int, 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, err
}
// GeoNodeStatus represents the status of Geo Node.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/geo_nodes.html#retrieve-status-about-all-geo-nodes
type GeoNodeStatus struct {
GeoNodeID int `json:"geo_node_id"`
Healthy bool `json:"healthy"`
Health string `json:"health"`
HealthStatus string `json:"health_status"`
MissingOauthApplication bool `json:"missing_oauth_application"`
AttachmentsCount int `json:"attachments_count"`
AttachmentsSyncedCount int `json:"attachments_synced_count"`
AttachmentsFailedCount int `json:"attachments_failed_count"`
AttachmentsSyncedMissingOnPrimaryCount int `json:"attachments_synced_missing_on_primary_count"`
AttachmentsSyncedInPercentage string `json:"attachments_synced_in_percentage"`
DbReplicationLagSeconds int `json:"db_replication_lag_seconds"`
LfsObjectsCount int `json:"lfs_objects_count"`
LfsObjectsSyncedCount int `json:"lfs_objects_synced_count"`
LfsObjectsFailedCount int `json:"lfs_objects_failed_count"`
LfsObjectsSyncedMissingOnPrimaryCount int `json:"lfs_objects_synced_missing_on_primary_count"`
LfsObjectsSyncedInPercentage string `json:"lfs_objects_synced_in_percentage"`
JobArtifactsCount int `json:"job_artifacts_count"`
JobArtifactsSyncedCount int `json:"job_artifacts_synced_count"`
JobArtifactsFailedCount int `json:"job_artifacts_failed_count"`
JobArtifactsSyncedMissingOnPrimaryCount int `json:"job_artifacts_synced_missing_on_primary_count"`
JobArtifactsSyncedInPercentage string `json:"job_artifacts_synced_in_percentage"`
ContainerRepositoriesCount int `json:"container_repositories_count"`
ContainerRepositoriesSyncedCount int `json:"container_repositories_synced_count"`
ContainerRepositoriesFailedCount int `json:"container_repositories_failed_count"`
ContainerRepositoriesSyncedInPercentage string `json:"container_repositories_synced_in_percentage"`
DesignRepositoriesCount int `json:"design_repositories_count"`
DesignRepositoriesSyncedCount int `json:"design_repositories_synced_count"`
DesignRepositoriesFailedCount int `json:"design_repositories_failed_count"`
DesignRepositoriesSyncedInPercentage string `json:"design_repositories_synced_in_percentage"`
ProjectsCount int `json:"projects_count"`
RepositoriesCount int `json:"repositories_count"`
RepositoriesFailedCount int `json:"repositories_failed_count"`
RepositoriesSyncedCount int `json:"repositories_synced_count"`
RepositoriesSyncedInPercentage string `json:"repositories_synced_in_percentage"`
WikisCount int `json:"wikis_count"`
WikisFailedCount int `json:"wikis_failed_count"`
WikisSyncedCount int `json:"wikis_synced_count"`
WikisSyncedInPercentage string `json:"wikis_synced_in_percentage"`
ReplicationSlotsCount int `json:"replication_slots_count"`
ReplicationSlotsUsedCount int `json:"replication_slots_used_count"`
ReplicationSlotsUsedInPercentage string `json:"replication_slots_used_in_percentage"`
ReplicationSlotsMaxRetainedWalBytes int `json:"replication_slots_max_retained_wal_bytes"`
RepositoriesCheckedCount int `json:"repositories_checked_count"`
RepositoriesCheckedFailedCount int `json:"repositories_checked_failed_count"`
RepositoriesCheckedInPercentage string `json:"repositories_checked_in_percentage"`
RepositoriesChecksummedCount int `json:"repositories_checksummed_count"`
RepositoriesChecksumFailedCount int `json:"repositories_checksum_failed_count"`
RepositoriesChecksummedInPercentage string `json:"repositories_checksummed_in_percentage"`
WikisChecksummedCount int `json:"wikis_checksummed_count"`
WikisChecksumFailedCount int `json:"wikis_checksum_failed_count"`
WikisChecksummedInPercentage string `json:"wikis_checksummed_in_percentage"`
RepositoriesVerifiedCount int `json:"repositories_verified_count"`
RepositoriesVerificationFailedCount int `json:"repositories_verification_failed_count"`
RepositoriesVerifiedInPercentage string `json:"repositories_verified_in_percentage"`
RepositoriesChecksumMismatchCount int `json:"repositories_checksum_mismatch_count"`
WikisVerifiedCount int `json:"wikis_verified_count"`
WikisVerificationFailedCount int `json:"wikis_verification_failed_count"`
WikisVerifiedInPercentage string `json:"wikis_verified_in_percentage"`
WikisChecksumMismatchCount int `json:"wikis_checksum_mismatch_count"`
RepositoriesRetryingVerificationCount int `json:"repositories_retrying_verification_count"`
WikisRetryingVerificationCount int `json:"wikis_retrying_verification_count"`
LastEventID int `json:"last_event_id"`
LastEventTimestamp int `json:"last_event_timestamp"`
CursorLastEventID int `json:"cursor_last_event_id"`
CursorLastEventTimestamp int `json:"cursor_last_event_timestamp"`
LastSuccessfulStatusCheckTimestamp int `json:"last_successful_status_check_timestamp"`
Version string `json:"version"`
Revision string `json:"revision"`
MergeRequestDiffsCount int `json:"merge_request_diffs_count"`
MergeRequestDiffsChecksumTotalCount int `json:"merge_request_diffs_checksum_total_count"`
MergeRequestDiffsChecksummedCount int `json:"merge_request_diffs_checksummed_count"`
MergeRequestDiffsChecksumFailedCount int `json:"merge_request_diffs_checksum_failed_count"`
MergeRequestDiffsSyncedCount int `json:"merge_request_diffs_synced_count"`
MergeRequestDiffsFailedCount int `json:"merge_request_diffs_failed_count"`
MergeRequestDiffsRegistryCount int `json:"merge_request_diffs_registry_count"`
MergeRequestDiffsVerificationTotalCount int `json:"merge_request_diffs_verification_total_count"`
MergeRequestDiffsVerifiedCount int `json:"merge_request_diffs_verified_count"`
MergeRequestDiffsVerificationFailedCount int `json:"merge_request_diffs_verification_failed_count"`
MergeRequestDiffsSyncedInPercentage string `json:"merge_request_diffs_synced_in_percentage"`
MergeRequestDiffsVerifiedInPercentage string `json:"merge_request_diffs_verified_in_percentage"`
PackageFilesCount int `json:"package_files_count"`
PackageFilesChecksumTotalCount int `json:"package_files_checksum_total_count"`
PackageFilesChecksummedCount int `json:"package_files_checksummed_count"`
PackageFilesChecksumFailedCount int `json:"package_files_checksum_failed_count"`
PackageFilesSyncedCount int `json:"package_files_synced_count"`
PackageFilesFailedCount int `json:"package_files_failed_count"`
PackageFilesRegistryCount int `json:"package_files_registry_count"`
PackageFilesVerificationTotalCount int `json:"package_files_verification_total_count"`
PackageFilesVerifiedCount int `json:"package_files_verified_count"`
PackageFilesVerificationFailedCount int `json:"package_files_verification_failed_count"`
PackageFilesSyncedInPercentage string `json:"package_files_synced_in_percentage"`
PackageFilesVerifiedInPercentage string `json:"package_files_verified_in_percentage"`
PagesDeploymentsCount int `json:"pages_deployments_count"`
PagesDeploymentsChecksumTotalCount int `json:"pages_deployments_checksum_total_count"`
PagesDeploymentsChecksummedCount int `json:"pages_deployments_checksummed_count"`
PagesDeploymentsChecksumFailedCount int `json:"pages_deployments_checksum_failed_count"`
PagesDeploymentsSyncedCount int `json:"pages_deployments_synced_count"`
PagesDeploymentsFailedCount int `json:"pages_deployments_failed_count"`
PagesDeploymentsRegistryCount int `json:"pages_deployments_registry_count"`
PagesDeploymentsVerificationTotalCount int `json:"pages_deployments_verification_total_count"`
PagesDeploymentsVerifiedCount int `json:"pages_deployments_verified_count"`
PagesDeploymentsVerificationFailedCount int `json:"pages_deployments_verification_failed_count"`
PagesDeploymentsSyncedInPercentage string `json:"pages_deployments_synced_in_percentage"`
PagesDeploymentsVerifiedInPercentage string `json:"pages_deployments_verified_in_percentage"`
TerraformStateVersionsCount int `json:"terraform_state_versions_count"`
TerraformStateVersionsChecksumTotalCount int `json:"terraform_state_versions_checksum_total_count"`
TerraformStateVersionsChecksummedCount int `json:"terraform_state_versions_checksummed_count"`
TerraformStateVersionsChecksumFailedCount int `json:"terraform_state_versions_checksum_failed_count"`
TerraformStateVersionsSyncedCount int `json:"terraform_state_versions_synced_count"`
TerraformStateVersionsFailedCount int `json:"terraform_state_versions_failed_count"`
TerraformStateVersionsRegistryCount int `json:"terraform_state_versions_registry_count"`
TerraformStateVersionsVerificationTotalCount int `json:"terraform_state_versions_verification_total_count"`
TerraformStateVersionsVerifiedCount int `json:"terraform_state_versions_verified_count"`
TerraformStateVersionsVerificationFailedCount int `json:"terraform_state_versions_verification_failed_count"`
TerraformStateVersionsSyncedInPercentage string `json:"terraform_state_versions_synced_in_percentage"`
TerraformStateVersionsVerifiedInPercentage string `json:"terraform_state_versions_verified_in_percentage"`
SnippetRepositoriesCount int `json:"snippet_repositories_count"`
SnippetRepositoriesChecksumTotalCount int `json:"snippet_repositories_checksum_total_count"`
SnippetRepositoriesChecksummedCount int `json:"snippet_repositories_checksummed_count"`
SnippetRepositoriesChecksumFailedCount int `json:"snippet_repositories_checksum_failed_count"`
SnippetRepositoriesSyncedCount int `json:"snippet_repositories_synced_count"`
SnippetRepositoriesFailedCount int `json:"snippet_repositories_failed_count"`
SnippetRepositoriesRegistryCount int `json:"snippet_repositories_registry_count"`
SnippetRepositoriesVerificationTotalCount int `json:"snippet_repositories_verification_total_count"`
SnippetRepositoriesVerifiedCount int `json:"snippet_repositories_verified_count"`
SnippetRepositoriesVerificationFailedCount int `json:"snippet_repositories_verification_failed_count"`
SnippetRepositoriesSyncedInPercentage string `json:"snippet_repositories_synced_in_percentage"`
SnippetRepositoriesVerifiedInPercentage string `json:"snippet_repositories_verified_in_percentage"`
GroupWikiRepositoriesCount int `json:"group_wiki_repositories_count"`
GroupWikiRepositoriesChecksumTotalCount int `json:"group_wiki_repositories_checksum_total_count"`
GroupWikiRepositoriesChecksummedCount int `json:"group_wiki_repositories_checksummed_count"`
GroupWikiRepositoriesChecksumFailedCount int `json:"group_wiki_repositories_checksum_failed_count"`
GroupWikiRepositoriesSyncedCount int `json:"group_wiki_repositories_synced_count"`
GroupWikiRepositoriesFailedCount int `json:"group_wiki_repositories_failed_count"`
GroupWikiRepositoriesRegistryCount int `json:"group_wiki_repositories_registry_count"`
GroupWikiRepositoriesVerificationTotalCount int `json:"group_wiki_repositories_verification_total_count"`
GroupWikiRepositoriesVerifiedCount int `json:"group_wiki_repositories_verified_count"`
GroupWikiRepositoriesVerificationFailedCount int `json:"group_wiki_repositories_verification_failed_count"`
GroupWikiRepositoriesSyncedInPercentage string `json:"group_wiki_repositories_synced_in_percentage"`
GroupWikiRepositoriesVerifiedInPercentage string `json:"group_wiki_repositories_verified_in_percentage"`
PipelineArtifactsCount int `json:"pipeline_artifacts_count"`
PipelineArtifactsChecksumTotalCount int `json:"pipeline_artifacts_checksum_total_count"`
PipelineArtifactsChecksummedCount int `json:"pipeline_artifacts_checksummed_count"`
PipelineArtifactsChecksumFailedCount int `json:"pipeline_artifacts_checksum_failed_count"`
PipelineArtifactsSyncedCount int `json:"pipeline_artifacts_synced_count"`
PipelineArtifactsFailedCount int `json:"pipeline_artifacts_failed_count"`
PipelineArtifactsRegistryCount int `json:"pipeline_artifacts_registry_count"`
PipelineArtifactsVerificationTotalCount int `json:"pipeline_artifacts_verification_total_count"`
PipelineArtifactsVerifiedCount int `json:"pipeline_artifacts_verified_count"`
PipelineArtifactsVerificationFailedCount int `json:"pipeline_artifacts_verification_failed_count"`
PipelineArtifactsSyncedInPercentage string `json:"pipeline_artifacts_synced_in_percentage"`
PipelineArtifactsVerifiedInPercentage string `json:"pipeline_artifacts_verified_in_percentage"`
UploadsCount int `json:"uploads_count"`
UploadsSyncedCount int `json:"uploads_synced_count"`
UploadsFailedCount int `json:"uploads_failed_count"`
UploadsRegistryCount int `json:"uploads_registry_count"`
UploadsSyncedInPercentage string `json:"uploads_synced_in_percentage"`
}
// RetrieveStatusOfAllGeoNodes get the list of status of all Geo Nodes.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/geo_nodes.html#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, err
}
// RetrieveStatusOfGeoNode get the of status of a specific Geo Nodes.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/geo_nodes.html#retrieve-status-about-a-specific-geo-node
func (s *GeoNodesService) RetrieveStatusOfGeoNode(id int, 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, err
}

View file

@ -48,19 +48,19 @@ const (
headerRateReset = "RateLimit-Reset"
)
// authType represents an authentication type within GitLab.
// AuthType represents an authentication type within GitLab.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/
type authType int
type AuthType int
// List of available authentication types.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/
const (
basicAuth authType = iota
jobToken
oAuthToken
privateToken
BasicAuth AuthType = iota
JobToken
OAuthToken
PrivateToken
)
// A Client manages communication with the GitLab API.
@ -84,7 +84,7 @@ type Client struct {
limiter RateLimiter
// Token type used to make authenticated API calls.
authType authType
authType AuthType
// Username and password used for basix authentication.
username, password string
@ -119,8 +119,11 @@ type Client struct {
EpicIssues *EpicIssuesService
Epics *EpicsService
Events *EventsService
ExternalStatusChecks *ExternalStatusChecksService
Features *FeaturesService
FreezePeriods *FreezePeriodsService
GenericPackages *GenericPackagesService
GeoNodes *GeoNodesService
GitIgnoreTemplates *GitIgnoreTemplatesService
GroupBadges *GroupBadgesService
GroupCluster *GroupClustersService
@ -156,6 +159,7 @@ type Client struct {
PipelineSchedules *PipelineSchedulesService
PipelineTriggers *PipelineTriggersService
Pipelines *PipelinesService
PlanLimits *PlanLimitsService
ProjectBadges *ProjectBadgesService
ProjectAccessTokens *ProjectAccessTokensService
ProjectCluster *ProjectClustersService
@ -211,7 +215,7 @@ func NewClient(token string, options ...ClientOptionFunc) (*Client, error) {
if err != nil {
return nil, err
}
client.authType = privateToken
client.authType = PrivateToken
client.token = token
return client, nil
}
@ -224,7 +228,7 @@ func NewBasicAuthClient(username, password string, options ...ClientOptionFunc)
return nil, err
}
client.authType = basicAuth
client.authType = BasicAuth
client.username = username
client.password = password
@ -238,7 +242,7 @@ func NewJobClient(token string, options ...ClientOptionFunc) (*Client, error) {
if err != nil {
return nil, err
}
client.authType = jobToken
client.authType = JobToken
client.token = token
return client, nil
}
@ -250,7 +254,7 @@ func NewOAuthClient(token string, options ...ClientOptionFunc) (*Client, error)
if err != nil {
return nil, err
}
client.authType = oAuthToken
client.authType = OAuthToken
client.token = token
return client, nil
}
@ -306,8 +310,11 @@ func newClient(options ...ClientOptionFunc) (*Client, error) {
c.EpicIssues = &EpicIssuesService{client: c}
c.Epics = &EpicsService{client: c}
c.Events = &EventsService{client: c}
c.ExternalStatusChecks = &ExternalStatusChecksService{client: c}
c.Features = &FeaturesService{client: c}
c.FreezePeriods = &FreezePeriodsService{client: c}
c.GenericPackages = &GenericPackagesService{client: c}
c.GeoNodes = &GeoNodesService{client: c}
c.GitIgnoreTemplates = &GitIgnoreTemplatesService{client: c}
c.GroupBadges = &GroupBadgesService{client: c}
c.GroupCluster = &GroupClustersService{client: c}
@ -343,6 +350,7 @@ func newClient(options ...ClientOptionFunc) (*Client, error) {
c.PipelineSchedules = &PipelineSchedulesService{client: c}
c.PipelineTriggers = &PipelineTriggersService{client: c}
c.Pipelines = &PipelinesService{client: c}
c.PlanLimits = &PlanLimitsService{client: c}
c.ProjectBadges = &ProjectBadgesService{client: c}
c.ProjectAccessTokens = &ProjectAccessTokensService{client: c}
c.ProjectCluster = &ProjectClustersService{client: c}
@ -608,22 +616,22 @@ const (
// populatePageValues parses the HTTP Link response headers and populates the
// various pagination link values in the Response.
func (r *Response) populatePageValues() {
if totalItems := r.Response.Header.Get(xTotal); totalItems != "" {
if totalItems := r.Header.Get(xTotal); totalItems != "" {
r.TotalItems, _ = strconv.Atoi(totalItems)
}
if totalPages := r.Response.Header.Get(xTotalPages); totalPages != "" {
if totalPages := r.Header.Get(xTotalPages); totalPages != "" {
r.TotalPages, _ = strconv.Atoi(totalPages)
}
if itemsPerPage := r.Response.Header.Get(xPerPage); itemsPerPage != "" {
if itemsPerPage := r.Header.Get(xPerPage); itemsPerPage != "" {
r.ItemsPerPage, _ = strconv.Atoi(itemsPerPage)
}
if currentPage := r.Response.Header.Get(xPage); currentPage != "" {
if currentPage := r.Header.Get(xPage); currentPage != "" {
r.CurrentPage, _ = strconv.Atoi(currentPage)
}
if nextPage := r.Response.Header.Get(xNextPage); nextPage != "" {
if nextPage := r.Header.Get(xNextPage); nextPage != "" {
r.NextPage, _ = strconv.Atoi(nextPage)
}
if previousPage := r.Response.Header.Get(xPrevPage); previousPage != "" {
if previousPage := r.Header.Get(xPrevPage); previousPage != "" {
r.PreviousPage, _ = strconv.Atoi(previousPage)
}
}
@ -648,7 +656,7 @@ func (c *Client) Do(req *retryablehttp.Request, v interface{}) (*Response, error
// if we already have a token and if not first authenticate and get one.
var basicAuthToken string
switch c.authType {
case basicAuth:
case BasicAuth:
c.tokenLock.RLock()
basicAuthToken = c.token
c.tokenLock.RUnlock()
@ -660,12 +668,18 @@ func (c *Client) Do(req *retryablehttp.Request, v interface{}) (*Response, error
}
}
req.Header.Set("Authorization", "Bearer "+basicAuthToken)
case jobToken:
req.Header.Set("JOB-TOKEN", c.token)
case oAuthToken:
req.Header.Set("Authorization", "Bearer "+c.token)
case privateToken:
req.Header.Set("PRIVATE-TOKEN", c.token)
case JobToken:
if values := req.Header.Values("JOB-TOKEN"); len(values) == 0 {
req.Header.Set("JOB-TOKEN", c.token)
}
case OAuthToken:
if values := req.Header.Values("Authorization"); len(values) == 0 {
req.Header.Set("Authorization", "Bearer "+c.token)
}
case PrivateToken:
if values := req.Header.Values("PRIVATE-TOKEN"); len(values) == 0 {
req.Header.Set("PRIVATE-TOKEN", c.token)
}
}
resp, err := c.client.Do(req)
@ -673,7 +687,7 @@ func (c *Client) Do(req *retryablehttp.Request, v interface{}) (*Response, error
return nil, err
}
if resp.StatusCode == http.StatusUnauthorized && c.authType == basicAuth {
if resp.StatusCode == http.StatusUnauthorized && c.authType == BasicAuth {
resp.Body.Close()
// The token most likely expired, so we need to request a new one and try again.
if _, err := c.requestOAuthToken(req.Context(), basicAuthToken); err != nil {
@ -744,7 +758,7 @@ func parseID(id interface{}) (string, error) {
// Helper function to escape a project identifier.
func pathEscape(s string) string {
return strings.Replace(url.PathEscape(s), ".", "%2E", -1)
return strings.ReplaceAll(url.PathEscape(s), ".", "%2E")
}
// An ErrorResponse reports one or more errors caused by an API request.

View file

@ -319,7 +319,7 @@ func (s *GroupIssueBoardsService) UpdateIssueBoardList(gid interface{}, board, l
}
var gbl []*BoardList
resp, err := s.client.Do(req, gbl)
resp, err := s.client.Do(req, &gbl)
if err != nil {
return nil, resp, err
}

View file

@ -154,6 +154,7 @@ type ListMergeRequestsOptions struct {
UpdatedBefore *time.Time `url:"updated_before,omitempty" json:"updated_before,omitempty"`
Scope *string `url:"scope,omitempty" json:"scope,omitempty"`
AuthorID *int `url:"author_id,omitempty" json:"author_id,omitempty"`
AuthorUsername *string `url:"author_username,omitempty" json:"author_username,omitempty"`
AssigneeID *int `url:"assignee_id,omitempty" json:"assignee_id,omitempty"`
ReviewerID *int `url:"reviewer_id,omitempty" json:"reviewer_id,omitempty"`
ReviewerUsername *string `url:"reviewer_username,omitempty" json:"reviewer_username,omitempty"`
@ -162,6 +163,7 @@ type ListMergeRequestsOptions struct {
TargetBranch *string `url:"target_branch,omitempty" json:"target_branch,omitempty"`
Search *string `url:"search,omitempty" json:"search,omitempty"`
In *string `url:"in,omitempty" json:"in,omitempty"`
Draft *bool `url:"draft,omitempty" json:"draft,omitempty"`
WIP *string `url:"wip,omitempty" json:"wip,omitempty"`
}
@ -209,6 +211,7 @@ type ListGroupMergeRequestsOptions struct {
UpdatedBefore *time.Time `url:"updated_before,omitempty" json:"updated_before,omitempty"`
Scope *string `url:"scope,omitempty" json:"scope,omitempty"`
AuthorID *int `url:"author_id,omitempty" json:"author_id,omitempty"`
AuthorUsername *string `url:"author_username,omitempty" json:"author_username,omitempty"`
AssigneeID *int `url:"assignee_id,omitempty" json:"assignee_id,omitempty"`
ReviewerID *int `url:"reviewer_id,omitempty" json:"reviewer_id,omitempty"`
ReviewerUsername *string `url:"reviewer_username,omitempty" json:"reviewer_username,omitempty"`
@ -217,6 +220,7 @@ type ListGroupMergeRequestsOptions struct {
TargetBranch *string `url:"target_branch,omitempty" json:"target_branch,omitempty"`
Search *string `url:"search,omitempty" json:"search,omitempty"`
In *string `url:"in,omitempty" json:"in,omitempty"`
Draft *bool `url:"draft,omitempty" json:"draft,omitempty"`
WIP *string `url:"wip,omitempty" json:"wip,omitempty"`
}
@ -268,6 +272,7 @@ type ListProjectMergeRequestsOptions struct {
UpdatedBefore *time.Time `url:"updated_before,omitempty" json:"updated_before,omitempty"`
Scope *string `url:"scope,omitempty" json:"scope,omitempty"`
AuthorID *int `url:"author_id,omitempty" json:"author_id,omitempty"`
AuthorUsername *string `url:"author_username,omitempty" json:"author_username,omitempty"`
AssigneeID *int `url:"assignee_id,omitempty" json:"assignee_id,omitempty"`
ReviewerID *int `url:"reviewer_id,omitempty" json:"reviewer_id,omitempty"`
ReviewerUsername *string `url:"reviewer_username,omitempty" json:"reviewer_username,omitempty"`
@ -275,6 +280,7 @@ type ListProjectMergeRequestsOptions struct {
SourceBranch *string `url:"source_branch,omitempty" json:"source_branch,omitempty"`
TargetBranch *string `url:"target_branch,omitempty" json:"target_branch,omitempty"`
Search *string `url:"search,omitempty" json:"search,omitempty"`
Draft *bool `url:"draft,omitempty" json:"draft,omitempty"`
WIP *string `url:"wip,omitempty" json:"wip,omitempty"`
}

104
vendor/github.com/xanzy/go-gitlab/plan_limits.go generated vendored Normal file
View file

@ -0,0 +1,104 @@
//
// Copyright 2021, Igor Varavko
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package gitlab
import "net/http"
// PlanLimitsService handles communication with the repositories related
// methods of the GitLab API.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/plan_limits.html
type PlanLimitsService struct {
client *Client
}
// PlanLimit represents a GitLab pipeline.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/plan_limits.html
type PlanLimit struct {
ConanMaxFileSize int `json:"conan_max_file_size,omitempty"`
GenericPackagesMaxFileSize int `json:"generic_packages_max_file_size,omitempty"`
HelmMaxFileSize int `json:"helm_max_file_size,omitempty"`
MavenMaxFileSize int `json:"maven_max_file_size,omitempty"`
NPMMaxFileSize int `json:"npm_max_file_size,omitempty"`
NugetMaxFileSize int `json:"nuget_max_file_size,omitempty"`
PyPiMaxFileSize int `json:"pypi_max_file_size,omitempty"`
TerraformModuleMaxFileSize int `json:"terraform_module_max_file_size,omitempty"`
}
// GetCurrentPlanLimitsOptions represents the available GetCurrentPlanLimits()
// options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/plan_limits.html#get-current-plan-limits
type GetCurrentPlanLimitsOptions struct {
PlanName *string `url:"plan_name,omitempty" json:"plan_name,omitempty"`
}
// List the current limits of a plan on the GitLab instance.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/plan_limits.html#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, err
}
// ChangePlanLimitOptions represents the available ChangePlanLimits() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/plan_limits.html#change-plan-limits
type ChangePlanLimitOptions struct {
PlanName *string `url:"plan_name,omitempty" json:"plan_name,omitempty"`
ConanMaxFileSize *int `url:"conan_max_file_size,omitempty" json:"conan_max_file_size,omitempty"`
GenericPackagesMaxFileSize *int `url:"generic_packages_max_file_size,omitempty" json:"generic_packages_max_file_size,omitempty"`
HelmMaxFileSize *int `url:"helm_max_file_size,omitempty" json:"helm_max_file_size,omitempty"`
MavenMaxFileSize *int `url:"maven_max_file_size,omitempty" json:"maven_max_file_size,omitempty"`
NPMMaxFileSize *int `url:"npm_max_file_size,omitempty" json:"npm_max_file_size,omitempty"`
NugetMaxFileSize *int `url:"nuget_max_file_size,omitempty" json:"nuget_max_file_size,omitempty"`
PyPiMaxFileSize *int `url:"pypi_max_file_size,omitempty" json:"pypi_max_file_size,omitempty"`
TerraformModuleMaxFileSize *int `url:"terraform_module_max_file_size,omitempty" json:"terraform_module_max_file_size,omitempty"`
}
// ChangePlanLimits modifies the limits of a plan on the GitLab instance.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/plan_limits.html#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, err
}

View file

@ -88,6 +88,7 @@ type Project struct {
OnlyAllowMergeIfAllDiscussionsAreResolved bool `json:"only_allow_merge_if_all_discussions_are_resolved"`
RemoveSourceBranchAfterMerge bool `json:"remove_source_branch_after_merge"`
LFSEnabled bool `json:"lfs_enabled"`
RepositoryStorage string `json:"repository_storage"`
RequestAccessEnabled bool `json:"request_access_enabled"`
MergeMethod MergeMethodValue `json:"merge_method"`
ForkedFromProject *ForkParent `json:"forked_from_project"`
@ -282,6 +283,7 @@ type ListProjectsOptions struct {
OrderBy *string `url:"order_by,omitempty" json:"order_by,omitempty"`
Owned *bool `url:"owned,omitempty" json:"owned,omitempty"`
RepositoryChecksumFailed *bool `url:"repository_checksum_failed,omitempty" json:"repository_checksum_failed,omitempty"`
RepositoryStorage *string `url:"repository_storage,omitempty" json:"repository_storage,omitempty"`
Search *string `url:"search,omitempty" json:"search,omitempty"`
SearchNamespaces *bool `url:"search_namespaces,omitempty" json:"search_namespaces,omitempty"`
Simple *bool `url:"simple,omitempty" json:"simple,omitempty"`
@ -598,6 +600,7 @@ type CreateProjectOptions struct {
PublicBuilds *bool `url:"public_builds,omitempty" json:"public_builds,omitempty"`
RemoveSourceBranchAfterMerge *bool `url:"remove_source_branch_after_merge,omitempty" json:"remove_source_branch_after_merge,omitempty"`
RepositoryAccessLevel *AccessControlValue `url:"repository_access_level,omitempty" json:"repository_access_level,omitempty"`
RepositoryStorage *string `url:"repository_storage,omitempty" json:"repository_storage,omitempty"`
RequestAccessEnabled *bool `url:"request_access_enabled,omitempty" json:"request_access_enabled,omitempty"`
RequirementsAccessLevel *AccessControlValue `url:"requirements_access_level,omitempty" json:"requirements_access_level,omitempty"`
ResolveOutdatedDiffDiscussions *bool `url:"resolve_outdated_diff_discussions,omitempty" json:"resolve_outdated_diff_discussions,omitempty"`
@ -746,6 +749,7 @@ type EditProjectOptions struct {
PublicBuilds *bool `url:"public_builds,omitempty" json:"public_builds,omitempty"`
RemoveSourceBranchAfterMerge *bool `url:"remove_source_branch_after_merge,omitempty" json:"remove_source_branch_after_merge,omitempty"`
RepositoryAccessLevel *AccessControlValue `url:"repository_access_level,omitempty" json:"repository_access_level,omitempty"`
RepositoryStorage *string `url:"repository_storage,omitempty" json:"repository_storage,omitempty"`
RequestAccessEnabled *bool `url:"request_access_enabled,omitempty" json:"request_access_enabled,omitempty"`
RequirementsAccessLevel *AccessControlValue `url:"requirements_access_level,omitempty" json:"requirements_access_level,omitempty"`
ResolveOutdatedDiffDiscussions *bool `url:"resolve_outdated_diff_discussions,omitempty" json:"resolve_outdated_diff_discussions,omitempty"`

View file

@ -25,7 +25,15 @@ import (
// RequestOptionFunc can be passed to all API requests to customize the API request.
type RequestOptionFunc func(*retryablehttp.Request) error
// WithSudo takes either a username or user ID and sets the SUDO request header
// WithContext runs the request with the provided context
func WithContext(ctx context.Context) RequestOptionFunc {
return func(req *retryablehttp.Request) error {
*req = *req.WithContext(ctx)
return nil
}
}
// WithSudo takes either a username or user ID and sets the SUDO request header.
func WithSudo(uid interface{}) RequestOptionFunc {
return func(req *retryablehttp.Request) error {
user, err := parseID(uid)
@ -37,10 +45,17 @@ func WithSudo(uid interface{}) RequestOptionFunc {
}
}
// WithContext runs the request with the provided context
func WithContext(ctx context.Context) RequestOptionFunc {
// WithToken takes a token which is then used when making this one request.
func WithToken(authType AuthType, token string) RequestOptionFunc {
return func(req *retryablehttp.Request) error {
*req = *req.WithContext(ctx)
switch authType {
case JobToken:
req.Header.Set("JOB-TOKEN", token)
case OAuthToken:
req.Header.Set("Authorization", "Bearer "+token)
case PrivateToken:
req.Header.Set("PRIVATE-TOKEN", token)
}
return nil
}
}

View file

@ -199,6 +199,39 @@ func FileAction(v FileActionValue) *FileActionValue {
return p
}
// GenericPackageSelectValue represents a generic package select value.
type GenericPackageSelectValue string
// The available generic package select values.
const (
SelectPackageFile GenericPackageSelectValue = "package_file"
)
// GenericPackageSelect is a helper routine that allocates a new
// GenericPackageSelectValue value to store v and returns a pointer to it.
func GenericPackageSelect(v GenericPackageSelectValue) *GenericPackageSelectValue {
p := new(GenericPackageSelectValue)
*p = v
return p
}
// GenericPackageStatusValue represents a generic package status.
type GenericPackageStatusValue string
// The available generic package statuses.
const (
PackageDefault GenericPackageStatusValue = "default"
PackageHidden GenericPackageStatusValue = "hidden"
)
// GenericPackageStatus is a helper routine that allocates a new
// GenericPackageStatusValue value to store v and returns a pointer to it.
func GenericPackageStatus(v GenericPackageStatusValue) *GenericPackageStatusValue {
p := new(GenericPackageStatusValue)
*p = v
return p
}
// ISOTime represents an ISO 8601 formatted date
type ISOTime time.Time

View file

@ -26,9 +26,12 @@ import (
// List a couple of standard errors.
var (
ErrUserActivatePrevented = errors.New("Cannot activate a user that is blocked by admin or by LDAP synchronization")
ErrUserApprovePrevented = errors.New("Cannot approve a user that is blocked by admin or by LDAP synchronization")
ErrUserBlockPrevented = errors.New("Cannot block a user that is already blocked by LDAP synchronization")
ErrUserDeactivatePrevented = errors.New("Cannot deactivate a user that is blocked by admin or by LDAP synchronization, or that has any activity in past 180 days")
ErrUserConflict = errors.New("User does not have a pending request")
ErrUserDeactivatePrevented = errors.New("Cannot deactivate a user that is blocked by admin or by LDAP synchronization")
ErrUserNotFound = errors.New("User does not exist")
ErrUserRejectPrevented = errors.New("Cannot reject a user if not authenticated as administrator")
ErrUserUnblockPrevented = errors.New("Cannot unblock a user that is blocked by LDAP synchronization")
)
@ -70,6 +73,7 @@ type User struct {
Twitter string `json:"twitter"`
WebsiteURL string `json:"website_url"`
Organization string `json:"organization"`
JobTitle string `json:"job_title"`
ExternUID string `json:"extern_uid"`
Provider string `json:"provider"`
ThemeID int `json:"theme_id"`
@ -185,6 +189,7 @@ type CreateUserOptions struct {
Twitter *string `url:"twitter,omitempty" json:"twitter,omitempty"`
WebsiteURL *string `url:"website_url,omitempty" json:"website_url,omitempty"`
Organization *string `url:"organization,omitempty" json:"organization,omitempty"`
JobTitle *string `url:"job_title,omitempty" json:"job_title,omitempty"`
ProjectsLimit *int `url:"projects_limit,omitempty" json:"projects_limit,omitempty"`
ExternUID *string `url:"extern_uid,omitempty" json:"extern_uid,omitempty"`
Provider *string `url:"provider,omitempty" json:"provider,omitempty"`
@ -229,6 +234,7 @@ type ModifyUserOptions struct {
Twitter *string `url:"twitter,omitempty" json:"twitter,omitempty"`
WebsiteURL *string `url:"website_url,omitempty" json:"website_url,omitempty"`
Organization *string `url:"organization,omitempty" json:"organization,omitempty"`
JobTitle *string `url:"job_title,omitempty" json:"job_title,omitempty"`
ProjectsLimit *int `url:"projects_limit,omitempty" json:"projects_limit,omitempty"`
ExternUID *string `url:"extern_uid,omitempty" json:"extern_uid,omitempty"`
Provider *string `url:"provider,omitempty" json:"provider,omitempty"`
@ -299,6 +305,86 @@ func (s *UsersService) CurrentUser(options ...RequestOptionFunc) (*User, *Respon
return usr, resp, err
}
// UserStatus represents the current status of a user
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/users.html#user-status
type UserStatus struct {
Emoji string `json:"emoji"`
Availability AvailabilityValue `json:"availability"`
Message string `json:"message"`
MessageHTML string `json:"message_html"`
}
// CurrentUserStatus retrieves the user status
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/users.html#user-status
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, err
}
// GetUserStatus retrieves a user's status
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/users.html#get-the-status-of-a-user
func (s *UsersService) GetUserStatus(user int, options ...RequestOptionFunc) (*UserStatus, *Response, error) {
u := fmt.Sprintf("users/%d/status", 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, err
}
// UserStatusOptions represents the options required to set the status
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/users.html#set-user-status
type UserStatusOptions struct {
Emoji *string `url:"emoji,omitempty" json:"emoji,omitempty"`
Availability *AvailabilityValue `url:"availability,omitempty" json:"availability,omitempty"`
Message *string `url:"message,omitempty" json:"message,omitempty"`
}
// SetUserStatus sets the user's status
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/users.html#set-user-status
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, err
}
// SSHKey represents a SSH key.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/users.html#list-ssh-keys
@ -456,118 +542,6 @@ func (s *UsersService) DeleteSSHKeyForUser(user, key int, options ...RequestOpti
return s.client.Do(req, nil)
}
// BlockUser blocks the specified user. Available only for admin.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/users.html#block-user
func (s *UsersService) BlockUser(user int, 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
}
resp, err := s.client.Do(req, nil)
if err != nil && resp == nil {
return err
}
switch resp.StatusCode {
case 201:
return nil
case 403:
return ErrUserBlockPrevented
case 404:
return ErrUserNotFound
default:
return fmt.Errorf("Received unexpected result code: %d", resp.StatusCode)
}
}
// UnblockUser unblocks the specified user. Available only for admin.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/users.html#unblock-user
func (s *UsersService) UnblockUser(user int, 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)
if err != nil && resp == nil {
return err
}
switch resp.StatusCode {
case 201:
return nil
case 403:
return ErrUserUnblockPrevented
case 404:
return ErrUserNotFound
default:
return fmt.Errorf("Received unexpected result code: %d", resp.StatusCode)
}
}
// DeactivateUser deactivate the specified user. Available only for admin.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/users.html#deactivate-user
func (s *UsersService) DeactivateUser(user int, 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)
if err != nil && resp == nil {
return err
}
switch resp.StatusCode {
case 201:
return nil
case 403:
return ErrUserDeactivatePrevented
case 404:
return ErrUserNotFound
default:
return fmt.Errorf("Received unexpected result code: %d", resp.StatusCode)
}
}
// ActivateUser activate the specified user. Available only for admin.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/users.html#activate-user
func (s *UsersService) ActivateUser(user int, 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)
if err != nil && resp == nil {
return err
}
switch resp.StatusCode {
case 201:
return nil
case 403:
return ErrUserActivatePrevented
case 404:
return ErrUserNotFound
default:
return fmt.Errorf("Received unexpected result code: %d", resp.StatusCode)
}
}
// Email represents an Email.
//
// GitLab API docs: https://doc.gitlab.com/ce/api/users.html#list-emails
@ -721,6 +695,176 @@ func (s *UsersService) DeleteEmailForUser(user, email int, options ...RequestOpt
return s.client.Do(req, nil)
}
// BlockUser blocks the specified user. Available only for admin.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/users.html#block-user
func (s *UsersService) BlockUser(user int, 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
}
resp, err := s.client.Do(req, nil)
if err != nil && resp == nil {
return err
}
switch resp.StatusCode {
case 201:
return nil
case 403:
return ErrUserBlockPrevented
case 404:
return ErrUserNotFound
default:
return fmt.Errorf("Received unexpected result code: %d", resp.StatusCode)
}
}
// UnblockUser unblocks the specified user. Available only for admin.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/users.html#unblock-user
func (s *UsersService) UnblockUser(user int, 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)
if err != nil && resp == nil {
return err
}
switch resp.StatusCode {
case 201:
return nil
case 403:
return ErrUserUnblockPrevented
case 404:
return ErrUserNotFound
default:
return fmt.Errorf("Received unexpected result code: %d", resp.StatusCode)
}
}
// DeactivateUser deactivate the specified user. Available only for admin.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/users.html#deactivate-user
func (s *UsersService) DeactivateUser(user int, 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)
if err != nil && resp == nil {
return err
}
switch resp.StatusCode {
case 201:
return nil
case 403:
return ErrUserDeactivatePrevented
case 404:
return ErrUserNotFound
default:
return fmt.Errorf("Received unexpected result code: %d", resp.StatusCode)
}
}
// ActivateUser activate the specified user. Available only for admin.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/users.html#activate-user
func (s *UsersService) ActivateUser(user int, 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)
if err != nil && resp == nil {
return err
}
switch resp.StatusCode {
case 201:
return nil
case 403:
return ErrUserActivatePrevented
case 404:
return ErrUserNotFound
default:
return fmt.Errorf("Received unexpected result code: %d", resp.StatusCode)
}
}
// ApproveUser approve the specified user. Available only for admin.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/users.html#approve-user
func (s *UsersService) ApproveUser(user int, 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)
if err != nil && resp == nil {
return err
}
switch resp.StatusCode {
case 201:
return nil
case 403:
return ErrUserApprovePrevented
case 404:
return ErrUserNotFound
default:
return fmt.Errorf("Received unexpected result code: %d", resp.StatusCode)
}
}
// RejectUser reject the specified user. Available only for admin.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/users.html#reject-user
func (s *UsersService) RejectUser(user int, 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)
if err != nil && resp == nil {
return err
}
switch resp.StatusCode {
case 200:
return nil
case 403:
return ErrUserRejectPrevented
case 404:
return ErrUserNotFound
case 409:
return ErrUserConflict
default:
return fmt.Errorf("Received unexpected result code: %d", resp.StatusCode)
}
}
// ImpersonationToken represents an impersonation token.
//
// GitLab API docs:
@ -920,86 +1064,6 @@ func (s *UsersService) GetUserActivities(opt *GetUserActivitiesOptions, options
return t, resp, err
}
// UserStatus represents the current status of a user
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/users.html#user-status
type UserStatus struct {
Emoji string `json:"emoji"`
Availability AvailabilityValue `json:"availability"`
Message string `json:"message"`
MessageHTML string `json:"message_html"`
}
// CurrentUserStatus retrieves the user status
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/users.html#user-status
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, err
}
// GetUserStatus retrieves a user's status
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/users.html#get-the-status-of-a-user
func (s *UsersService) GetUserStatus(user int, options ...RequestOptionFunc) (*UserStatus, *Response, error) {
u := fmt.Sprintf("users/%d/status", 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, err
}
// UserStatusOptions represents the options required to set the status
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/users.html#set-user-status
type UserStatusOptions struct {
Emoji *string `url:"emoji,omitempty" json:"emoji,omitempty"`
Availability *AvailabilityValue `url:"availability,omitempty" json:"availability,omitempty"`
Message *string `url:"message,omitempty" json:"message,omitempty"`
}
// SetUserStatus sets the user's status
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/users.html#set-user-status
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, err
}
// UserMembership represents a membership of the user in a namespace or project.
//
// GitLab API docs:

View file

@ -33,9 +33,10 @@ type ValidateService struct {
//
// GitLab API docs: https://docs.gitlab.com/ce/api/lint.html
type LintResult struct {
Status string `json:"status"`
Errors []string `json:"errors"`
Warnings []string `json:"warnings"`
Status string `json:"status"`
Errors []string `json:"errors"`
Warnings []string `json:"warnings"`
MergedYaml string `json:"merged_yaml"`
}
// ProjectLintResult represents the linting results by project.

View file

@ -719,7 +719,15 @@ func (sc *serverConn) canonicalHeader(v string) string {
sc.canonHeader = make(map[string]string)
}
cv = http.CanonicalHeaderKey(v)
sc.canonHeader[v] = cv
// maxCachedCanonicalHeaders is an arbitrarily-chosen limit on the number of
// entries in the canonHeader cache. This should be larger than the number
// of unique, uncommon header keys likely to be sent by the peer, while not
// so high as to permit unreaasonable memory usage if the peer sends an unbounded
// number of unique header keys.
const maxCachedCanonicalHeaders = 32
if len(sc.canonHeader) < maxCachedCanonicalHeaders {
sc.canonHeader[v] = cv
}
return cv
}

View file

@ -24,6 +24,7 @@ import (
"net/http"
"net/http/httptrace"
"net/textproto"
"os"
"sort"
"strconv"
"strings"
@ -130,6 +131,11 @@ type Transport struct {
// Defaults to 15s.
PingTimeout time.Duration
// WriteByteTimeout is the timeout after which the connection will be
// closed no data can be written to it. The timeout begins when data is
// available to write, and is extended whenever any bytes are written.
WriteByteTimeout time.Duration
// CountError, if non-nil, is called on HTTP/2 transport errors.
// It's intended to increment a metric for monitoring, such
// as an expvar or Prometheus metric.
@ -393,17 +399,31 @@ func (cs *clientStream) abortRequestBodyWrite() {
}
type stickyErrWriter struct {
w io.Writer
err *error
conn net.Conn
timeout time.Duration
err *error
}
func (sew stickyErrWriter) Write(p []byte) (n int, err error) {
if *sew.err != nil {
return 0, *sew.err
}
n, err = sew.w.Write(p)
*sew.err = err
return
for {
if sew.timeout != 0 {
sew.conn.SetWriteDeadline(time.Now().Add(sew.timeout))
}
nn, err := sew.conn.Write(p[n:])
n += nn
if n < len(p) && nn > 0 && errors.Is(err, os.ErrDeadlineExceeded) {
// Keep extending the deadline so long as we're making progress.
continue
}
if sew.timeout != 0 {
sew.conn.SetWriteDeadline(time.Time{})
}
*sew.err = err
return n, err
}
}
// noCachedConnError is the concrete type of ErrNoCachedConn, which
@ -658,7 +678,11 @@ func (t *Transport) newClientConn(c net.Conn, singleUse bool) (*ClientConn, erro
// TODO: adjust this writer size to account for frame size +
// MTU + crypto/tls record padding.
cc.bw = bufio.NewWriter(stickyErrWriter{c, &cc.werr})
cc.bw = bufio.NewWriter(stickyErrWriter{
conn: c,
timeout: t.WriteByteTimeout,
err: &cc.werr,
})
cc.br = bufio.NewReader(c)
cc.fr = NewFramer(cc.bw, cc.br)
if t.CountError != nil {
@ -1100,36 +1124,49 @@ func (cc *ClientConn) RoundTrip(req *http.Request) (*http.Response, error) {
}
}
handleResponseHeaders := func() (*http.Response, error) {
res := cs.res
if res.StatusCode > 299 {
// On error or status code 3xx, 4xx, 5xx, etc abort any
// ongoing write, assuming that the server doesn't care
// about our request body. If the server replied with 1xx or
// 2xx, however, then assume the server DOES potentially
// want our body (e.g. full-duplex streaming:
// golang.org/issue/13444). If it turns out the server
// doesn't, they'll RST_STREAM us soon enough. This is a
// heuristic to avoid adding knobs to Transport. Hopefully
// we can keep it.
cs.abortRequestBodyWrite()
}
res.Request = req
res.TLS = cc.tlsState
if res.Body == noBody && actualContentLength(req) == 0 {
// If there isn't a request or response body still being
// written, then wait for the stream to be closed before
// RoundTrip returns.
if err := waitDone(); err != nil {
return nil, err
}
}
return res, nil
}
for {
select {
case <-cs.respHeaderRecv:
res := cs.res
if res.StatusCode > 299 {
// On error or status code 3xx, 4xx, 5xx, etc abort any
// ongoing write, assuming that the server doesn't care
// about our request body. If the server replied with 1xx or
// 2xx, however, then assume the server DOES potentially
// want our body (e.g. full-duplex streaming:
// golang.org/issue/13444). If it turns out the server
// doesn't, they'll RST_STREAM us soon enough. This is a
// heuristic to avoid adding knobs to Transport. Hopefully
// we can keep it.
cs.abortRequestBodyWrite()
}
res.Request = req
res.TLS = cc.tlsState
if res.Body == noBody && actualContentLength(req) == 0 {
// If there isn't a request or response body still being
// written, then wait for the stream to be closed before
// RoundTrip returns.
if err := waitDone(); err != nil {
return nil, err
}
}
return res, nil
return handleResponseHeaders()
case <-cs.abort:
waitDone()
return nil, cs.abortErr
select {
case <-cs.respHeaderRecv:
// If both cs.respHeaderRecv and cs.abort are signaling,
// pick respHeaderRecv. The server probably wrote the
// response and immediately reset the stream.
// golang.org/issue/49645
return handleResponseHeaders()
default:
waitDone()
return nil, cs.abortErr
}
case <-ctx.Done():
err := ctx.Err()
cs.abortStream(err)
@ -1189,6 +1226,9 @@ func (cs *clientStream) writeRequest(req *http.Request) (err error) {
return err
}
cc.addStreamLocked(cs) // assigns stream ID
if isConnectionCloseRequest(req) {
cc.doNotReuse = true
}
cc.mu.Unlock()
// TODO(bradfitz): this is a copy of the logic in net/http. Unify somewhere?
@ -1212,12 +1252,12 @@ func (cs *clientStream) writeRequest(req *http.Request) (err error) {
}
continueTimeout := cc.t.expectContinueTimeout()
if continueTimeout != 0 &&
!httpguts.HeaderValuesContainsToken(
req.Header["Expect"],
"100-continue") {
continueTimeout = 0
cs.on100 = make(chan struct{}, 1)
if continueTimeout != 0 {
if !httpguts.HeaderValuesContainsToken(req.Header["Expect"], "100-continue") {
continueTimeout = 0
} else {
cs.on100 = make(chan struct{}, 1)
}
}
// Past this point (where we send request headers), it is possible for
@ -1286,6 +1326,7 @@ func (cs *clientStream) writeRequest(req *http.Request) (err error) {
case <-respHeaderTimer:
return errTimeout
case <-respHeaderRecv:
respHeaderRecv = nil
respHeaderTimer = nil // keep waiting for END_STREAM
case <-cs.abort:
return cs.abortErr
@ -2267,6 +2308,8 @@ func (rl *clientConnReadLoop) handleResponse(cs *clientStream, f *MetaHeadersFra
} else if len(clens) > 1 {
// TODO: care? unlike http/1, it won't mess up our framing, so it's
// more safe smuggling-wise to ignore.
} else if f.StreamEnded() && !cs.isHead {
res.ContentLength = 0
}
if cs.isHead {
@ -2287,7 +2330,7 @@ func (rl *clientConnReadLoop) handleResponse(cs *clientStream, f *MetaHeadersFra
cs.bytesRemain = res.ContentLength
res.Body = transportResponseBody{cs}
if cs.requestedGzip && res.Header.Get("Content-Encoding") == "gzip" {
if cs.requestedGzip && asciiEqualFold(res.Header.Get("Content-Encoding"), "gzip") {
res.Header.Del("Content-Encoding")
res.Header.Del("Content-Length")
res.ContentLength = -1
@ -2426,7 +2469,10 @@ func (b transportResponseBody) Close() error {
select {
case <-cs.donec:
case <-cs.ctx.Done():
return cs.ctx.Err()
// See golang/go#49366: The net/http package can cancel the
// request context after the response body is fully read.
// Don't treat this as an error.
return nil
case <-cs.reqCancel:
return errRequestCanceled
}
@ -2550,6 +2596,12 @@ func (rl *clientConnReadLoop) endStream(cs *clientStream) {
// server.go's (*stream).endStream method.
if !cs.readClosed {
cs.readClosed = true
// Close cs.bufPipe and cs.peerClosed with cc.mu held to avoid a
// race condition: The caller can read io.EOF from Response.Body
// and close the body before we close cs.peerClosed, causing
// cleanupWriteRequest to send a RST_STREAM.
rl.cc.mu.Lock()
defer rl.cc.mu.Unlock()
cs.bufPipe.closeWithErrorAndCode(io.EOF, cs.copyTrailers)
close(cs.peerClosed)
}

View file

@ -32,7 +32,8 @@ type WriteScheduler interface {
// Pop dequeues the next frame to write. Returns false if no frames can
// be written. Frames with a given wr.StreamID() are Pop'd in the same
// order they are Push'd. No frames should be discarded except by CloseStream.
// order they are Push'd, except RST_STREAM frames. No frames should be
// discarded except by CloseStream.
Pop() (wr FrameWriteRequest, ok bool)
}
@ -52,6 +53,7 @@ type FrameWriteRequest struct {
// stream is the stream on which this frame will be written.
// nil for non-stream frames like PING and SETTINGS.
// nil for RST_STREAM streams, which use the StreamError.StreamID field instead.
stream *stream
// done, if non-nil, must be a buffered channel with space for

View file

@ -45,11 +45,11 @@ func (ws *randomWriteScheduler) AdjustStream(streamID uint32, priority PriorityP
}
func (ws *randomWriteScheduler) Push(wr FrameWriteRequest) {
id := wr.StreamID()
if id == 0 {
if wr.isControl() {
ws.zero.push(wr)
return
}
id := wr.StreamID()
q, ok := ws.sq[id]
if !ok {
q = ws.queuePool.get()
@ -59,7 +59,7 @@ func (ws *randomWriteScheduler) Push(wr FrameWriteRequest) {
}
func (ws *randomWriteScheduler) Pop() (FrameWriteRequest, bool) {
// Control frames first.
// Control and RST_STREAM frames first.
if !ws.zero.empty() {
return ws.zero.shift(), true
}

14
vendor/golang.org/x/net/idna/go118.go generated vendored Normal file
View file

@ -0,0 +1,14 @@
// Code generated by running "go generate" in golang.org/x/text. DO NOT EDIT.
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build go1.18
// +build go1.18
package idna
// Transitional processing is disabled by default in Go 1.18.
// https://golang.org/issue/47510
const transitionalLookup = false

View file

@ -59,10 +59,10 @@ type Option func(*options)
// Transitional sets a Profile to use the Transitional mapping as defined in UTS
// #46. This will cause, for example, "ß" to be mapped to "ss". Using the
// transitional mapping provides a compromise between IDNA2003 and IDNA2008
// compatibility. It is used by most browsers when resolving domain names. This
// compatibility. It is used by some browsers when resolving domain names. This
// option is only meaningful if combined with MapForLookup.
func Transitional(transitional bool) Option {
return func(o *options) { o.transitional = true }
return func(o *options) { o.transitional = transitional }
}
// VerifyDNSLength sets whether a Profile should fail if any of the IDN parts
@ -284,7 +284,7 @@ var (
punycode = &Profile{}
lookup = &Profile{options{
transitional: true,
transitional: transitionalLookup,
useSTD3Rules: true,
checkHyphens: true,
checkJoiners: true,

View file

@ -58,10 +58,10 @@ type Option func(*options)
// Transitional sets a Profile to use the Transitional mapping as defined in UTS
// #46. This will cause, for example, "ß" to be mapped to "ss". Using the
// transitional mapping provides a compromise between IDNA2003 and IDNA2008
// compatibility. It is used by most browsers when resolving domain names. This
// compatibility. It is used by some browsers when resolving domain names. This
// option is only meaningful if combined with MapForLookup.
func Transitional(transitional bool) Option {
return func(o *options) { o.transitional = true }
return func(o *options) { o.transitional = transitional }
}
// VerifyDNSLength sets whether a Profile should fail if any of the IDN parts

12
vendor/golang.org/x/net/idna/pre_go118.go generated vendored Normal file
View file

@ -0,0 +1,12 @@
// Code generated by running "go generate" in golang.org/x/text. DO NOT EDIT.
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !go1.18
// +build !go1.18
package idna
const transitionalLookup = true

View file

@ -49,6 +49,7 @@ func decode(encoded string) (string, error) {
}
}
i, n, bias := int32(0), initialN, initialBias
overflow := false
for pos < len(encoded) {
oldI, w := i, int32(1)
for k := base; ; k += base {
@ -60,29 +61,32 @@ func decode(encoded string) (string, error) {
return "", punyError(encoded)
}
pos++
i += digit * w
if i < 0 {
i, overflow = madd(i, digit, w)
if overflow {
return "", punyError(encoded)
}
t := k - bias
if t < tmin {
if k <= bias {
t = tmin
} else if t > tmax {
} else if k >= bias+tmax {
t = tmax
}
if digit < t {
break
}
w *= base - t
if w >= math.MaxInt32/base {
w, overflow = madd(0, w, base-t)
if overflow {
return "", punyError(encoded)
}
}
if len(output) >= 1024 {
return "", punyError(encoded)
}
x := int32(len(output) + 1)
bias = adapt(i-oldI, x, oldI == 0)
n += i / x
i %= x
if n > utf8.MaxRune || len(output) >= 1024 {
if n < 0 || n > utf8.MaxRune {
return "", punyError(encoded)
}
output = append(output, 0)
@ -115,6 +119,7 @@ func encode(prefix, s string) (string, error) {
if b > 0 {
output = append(output, '-')
}
overflow := false
for remaining != 0 {
m := int32(0x7fffffff)
for _, r := range s {
@ -122,8 +127,8 @@ func encode(prefix, s string) (string, error) {
m = r
}
}
delta += (m - n) * (h + 1)
if delta < 0 {
delta, overflow = madd(delta, m-n, h+1)
if overflow {
return "", punyError(s)
}
n = m
@ -141,9 +146,9 @@ func encode(prefix, s string) (string, error) {
q := delta
for k := base; ; k += base {
t := k - bias
if t < tmin {
if k <= bias {
t = tmin
} else if t > tmax {
} else if k >= bias+tmax {
t = tmax
}
if q < t {
@ -164,6 +169,15 @@ func encode(prefix, s string) (string, error) {
return string(output), nil
}
// madd computes a + (b * c), detecting overflow.
func madd(a, b, c int32) (next int32, overflow bool) {
p := int64(b) * int64(c)
if p > math.MaxInt32-int64(a) {
return 0, true
}
return a + int32(p), false
}
func decodeDigit(x byte) (digit int32, ok bool) {
switch {
case '0' <= x && x <= '9':

View file

@ -306,15 +306,27 @@ func (lim *Limiter) SetBurstAt(now time.Time, newBurst int) {
// reserveN returns Reservation, not *Reservation, to avoid allocation in AllowN and WaitN.
func (lim *Limiter) reserveN(now time.Time, n int, maxFutureReserve time.Duration) Reservation {
lim.mu.Lock()
defer lim.mu.Unlock()
if lim.limit == Inf {
lim.mu.Unlock()
return Reservation{
ok: true,
lim: lim,
tokens: n,
timeToAct: now,
}
} else if lim.limit == 0 {
var ok bool
if lim.burst >= n {
ok = true
lim.burst -= n
}
return Reservation{
ok: ok,
lim: lim,
tokens: lim.burst,
timeToAct: now,
}
}
now, last, tokens := lim.advance(now)
@ -351,7 +363,6 @@ func (lim *Limiter) reserveN(now time.Time, n int, maxFutureReserve time.Duratio
lim.last = last
}
lim.mu.Unlock()
return r
}
@ -377,6 +388,9 @@ func (lim *Limiter) advance(now time.Time) (newNow time.Time, newLast time.Time,
// durationFromTokens is a unit conversion function from the number of tokens to the duration
// of time it takes to accumulate them at a rate of limit tokens per second.
func (limit Limit) durationFromTokens(tokens float64) time.Duration {
if limit <= 0 {
return InfDuration
}
seconds := tokens / float64(limit)
return time.Duration(float64(time.Second) * seconds)
}
@ -384,5 +398,8 @@ func (limit Limit) durationFromTokens(tokens float64) time.Duration {
// tokensFromDuration is a unit conversion function from a time duration to the number of tokens
// which could be accumulated during that duration at a rate of limit tokens per second.
func (limit Limit) tokensFromDuration(d time.Duration) float64 {
if limit <= 0 {
return 0
}
return d.Seconds() * float64(limit)
}

11
vendor/modules.txt vendored
View file

@ -294,7 +294,8 @@ github.com/hashicorp/errwrap
github.com/hashicorp/go-cleanhttp
# github.com/hashicorp/go-multierror v1.1.1
github.com/hashicorp/go-multierror
# github.com/hashicorp/go-retryablehttp v0.6.8
# github.com/hashicorp/go-retryablehttp v0.7.0
## explicit
github.com/hashicorp/go-retryablehttp
# github.com/hashicorp/go-version v1.2.1
github.com/hashicorp/go-version
@ -575,7 +576,7 @@ github.com/uudashr/gocognit
## explicit
github.com/woodpecker-ci/expr
github.com/woodpecker-ci/expr/parse
# github.com/xanzy/go-gitlab v0.51.1
# github.com/xanzy/go-gitlab v0.52.2
## explicit
github.com/xanzy/go-gitlab
# github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb
@ -605,7 +606,7 @@ golang.org/x/mod/internal/lazyregexp
golang.org/x/mod/modfile
golang.org/x/mod/module
golang.org/x/mod/semver
# golang.org/x/net v0.0.0-20211020060615-d418f374d309
# golang.org/x/net v0.0.0-20211209124913-491a49abca63
## explicit
golang.org/x/net/context
golang.org/x/net/context/ctxhttp
@ -617,7 +618,7 @@ golang.org/x/net/internal/socks
golang.org/x/net/internal/timeseries
golang.org/x/net/proxy
golang.org/x/net/trace
# golang.org/x/oauth2 v0.0.0-20211005180243-6b3c2da341f1
# golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8
## explicit
golang.org/x/oauth2
golang.org/x/oauth2/bitbucket
@ -642,7 +643,7 @@ golang.org/x/text/transform
golang.org/x/text/unicode/bidi
golang.org/x/text/unicode/norm
golang.org/x/text/width
# golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac
# golang.org/x/time v0.0.0-20211116232009-f0f3c7e86c11
## explicit
golang.org/x/time/rate
# golang.org/x/tools v0.1.7