Bump github.com/xanzy/go-gitlab from 0.79.1 to 0.80.2 (#284)

Bumps [github.com/xanzy/go-gitlab](https://github.com/xanzy/go-gitlab) from 0.79.1 to 0.80.2.
- [Release notes](https://github.com/xanzy/go-gitlab/releases)
- [Changelog](https://github.com/xanzy/go-gitlab/blob/master/releases_test.go)
- [Commits](https://github.com/xanzy/go-gitlab/compare/v0.79.1...v0.80.2)

---
updated-dependencies:
- dependency-name: github.com/xanzy/go-gitlab
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This commit is contained in:
dependabot[bot] 2023-03-01 07:39:12 -08:00 committed by GitHub
parent c755241aec
commit e470b44967
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 285 additions and 86 deletions

2
go.mod
View File

@ -12,7 +12,7 @@ require (
github.com/mitchellh/go-homedir v1.1.0
github.com/spf13/cobra v1.6.1
github.com/spf13/viper v1.15.0
github.com/xanzy/go-gitlab v0.79.1
github.com/xanzy/go-gitlab v0.80.2
golang.org/x/oauth2 v0.5.0
gopkg.in/yaml.v2 v2.4.0
)

4
go.sum
View File

@ -215,8 +215,8 @@ github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKs
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/subosito/gotenv v1.4.2 h1:X1TuBLAMDFbaTAChgCBLu3DU3UPyELpnF2jjJ2cz/S8=
github.com/subosito/gotenv v1.4.2/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0=
github.com/xanzy/go-gitlab v0.79.1 h1:ZmEei8RZYlqk4D7nYrWWZqywmKBOd7vmPMlJbueZXUU=
github.com/xanzy/go-gitlab v0.79.1/go.mod h1:DlByVTSXhPsJMYL6+cm8e8fTJjeBmhrXdC/yvkKKt6M=
github.com/xanzy/go-gitlab v0.80.2 h1:CH1Q7NDklqZllox4ICVF4PwlhQGfPtE+w08Jsb74ZX0=
github.com/xanzy/go-gitlab v0.80.2/go.mod h1:DlByVTSXhPsJMYL6+cm8e8fTJjeBmhrXdC/yvkKKt6M=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=

View File

@ -122,6 +122,9 @@ type ProtectBranchOptions struct {
// idempotent function, protecting an already protected repository branch
// still returns a 200 OK status code.
//
// Deprecated: This endpoint has been replaced by
// ProtectedBranchesService.ProtectRepositoryBranches()
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/branches.html#protect-repository-branch
func (s *BranchesService) ProtectBranch(pid interface{}, branch string, opts *ProtectBranchOptions, options ...RequestOptionFunc) (*Branch, *Response, error) {
@ -149,6 +152,9 @@ func (s *BranchesService) ProtectBranch(pid interface{}, branch string, opts *Pr
// idempotent function, unprotecting an already unprotected repository branch
// still returns a 200 OK status code.
//
// Deprecated: This endpoint has been replaced by
// ProtectedBranchesService.UnprotectRepositoryBranches()
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/branches.html#unprotect-repository-branch
func (s *BranchesService) UnprotectBranch(pid interface{}, branch string, options ...RequestOptionFunc) (*Branch, *Response, error) {

View File

@ -1,11 +1,10 @@
//
// Copyright 2022, Daniela Filipe Bento
//
// 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
// 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,

View File

@ -148,9 +148,7 @@ func ParseSystemhook(payload []byte) (event interface{}, err error) {
"group_destroy",
"group_rename":
event = &GroupSystemEvent{}
case
"key_create",
"key_destroy":
case "key_create", "key_destroy":
event = &KeySystemEvent{}
case
"user_create",

View File

@ -809,7 +809,7 @@ func (s *MergeRequestsService) GetSingleMergeRequestDiffVersion(pid interface{},
return nil, nil, err
}
var v = new(MergeRequestDiffVersion)
v := new(MergeRequestDiffVersion)
resp, err := s.client.Do(req, v)
if err != nil {
return nil, resp, err

View File

@ -89,12 +89,12 @@ func (s *ProjectSnippetsService) GetSnippet(pid interface{}, snippet int, option
// GitLab API docs:
// https://docs.gitlab.com/ee/api/project_snippets.html#create-new-snippet
type CreateProjectSnippetOptions struct {
Title *string `url:"title,omitempty" json:"title,omitempty"`
FileName *string `url:"file_name,omitempty" json:"file_name,omitempty"`
Description *string `url:"description,omitempty" json:"description,omitempty"`
Content *string `url:"content,omitempty" json:"content,omitempty"`
Visibility *VisibilityValue `url:"visibility,omitempty" json:"visibility,omitempty"`
Files *[]*SnippetFile `url:"files,omitempty" json:"files,omitempty"`
Title *string `url:"title,omitempty" json:"title,omitempty"`
FileName *string `url:"file_name,omitempty" json:"file_name,omitempty"`
Description *string `url:"description,omitempty" json:"description,omitempty"`
Content *string `url:"content,omitempty" json:"content,omitempty"`
Visibility *VisibilityValue `url:"visibility,omitempty" json:"visibility,omitempty"`
Files *[]*CreateSnippetFileOptions `url:"files,omitempty" json:"files,omitempty"`
}
// CreateSnippet creates a new project snippet. The user must have permission
@ -128,11 +128,12 @@ func (s *ProjectSnippetsService) CreateSnippet(pid interface{}, opt *CreateProje
// GitLab API docs:
// https://docs.gitlab.com/ee/api/project_snippets.html#update-snippet
type UpdateProjectSnippetOptions struct {
Title *string `url:"title,omitempty" json:"title,omitempty"`
FileName *string `url:"file_name,omitempty" json:"file_name,omitempty"`
Description *string `url:"description,omitempty" json:"description,omitempty"`
Content *string `url:"content,omitempty" json:"content,omitempty"`
Visibility *VisibilityValue `url:"visibility,omitempty" json:"visibility,omitempty"`
Title *string `url:"title,omitempty" json:"title,omitempty"`
FileName *string `url:"file_name,omitempty" json:"file_name,omitempty"`
Description *string `url:"description,omitempty" json:"description,omitempty"`
Content *string `url:"content,omitempty" json:"content,omitempty"`
Visibility *VisibilityValue `url:"visibility,omitempty" json:"visibility,omitempty"`
Files *[]*UpdateSnippetFileOptions `url:"files,omitempty" json:"files,omitempty"`
}
// UpdateSnippet updates an existing project snippet. The user must have

View File

@ -70,8 +70,6 @@ type Project struct {
LastActivityAt *time.Time `json:"last_activity_at,omitempty"`
CreatorID int `json:"creator_id"`
Namespace *ProjectNamespace `json:"namespace"`
ImportStatus string `json:"import_status"`
ImportError string `json:"import_error"`
Permissions *Permissions `json:"permissions"`
MarkedForDeletionAt *ISOTime `json:"marked_for_deletion_at"`
EmptyRepo bool `json:"empty_repo"`
@ -83,7 +81,6 @@ type Project struct {
ForksCount int `json:"forks_count"`
StarCount int `json:"star_count"`
RunnersToken string `json:"runners_token"`
PublicJobs bool `json:"public_jobs"`
AllowMergeOnSkippedPipeline bool `json:"allow_merge_on_skipped_pipeline"`
OnlyAllowMergeIfPipelineSucceeds bool `json:"only_allow_merge_if_pipeline_succeeds"`
OnlyAllowMergeIfAllDiscussionsAreResolved bool `json:"only_allow_merge_if_all_discussions_are_resolved"`
@ -115,8 +112,6 @@ type Project struct {
AnalyticsAccessLevel AccessControlValue `json:"analytics_access_level"`
AutocloseReferencedIssues bool `json:"autoclose_referenced_issues"`
SuggestionCommitMessage string `json:"suggestion_commit_message"`
AutoCancelPendingPipelines string `json:"auto_cancel_pending_pipelines"`
CIForwardDeploymentEnabled bool `json:"ci_forward_deployment_enabled"`
SquashOption SquashOptionValue `json:"squash_option"`
EnforceAuthChecksOnUploads bool `json:"enforce_auth_checks_on_uploads,omitempty"`
SharedWithGroups []struct {
@ -127,13 +122,20 @@ type Project struct {
} `json:"shared_with_groups"`
Statistics *Statistics `json:"statistics"`
Links *Links `json:"_links,omitempty"`
CIConfigPath string `json:"ci_config_path"`
ImportURL string `json:"import_url"`
ImportType string `json:"import_type"`
ImportStatus string `json:"import_status"`
ImportError string `json:"import_error"`
CIDefaultGitDepth int `json:"ci_default_git_depth"`
CIForwardDeploymentEnabled bool `json:"ci_forward_deployment_enabled"`
CISeperateCache bool `json:"ci_separated_caches"`
PublicJobs bool `json:"public_jobs"`
BuildTimeout int `json:"build_timeout"`
AutoCancelPendingPipelines string `json:"auto_cancel_pending_pipelines"`
CIConfigPath string `json:"ci_config_path"`
CustomAttributes []*CustomAttribute `json:"custom_attributes"`
ComplianceFrameworks []string `json:"compliance_frameworks"`
BuildCoverageRegex string `json:"build_coverage_regex"`
BuildTimeout int `json:"build_timeout"`
IssuesTemplate string `json:"issues_template"`
MergeRequestsTemplate string `json:"merge_requests_template"`
KeepLatestArtifact bool `json:"keep_latest_artifact"`
@ -171,6 +173,7 @@ type ContainerExpirationPolicy struct {
Cadence string `json:"cadence"`
KeepN int `json:"keep_n"`
OlderThan string `json:"older_than"`
NameRegex string `json:"name_regex"`
NameRegexDelete string `json:"name_regex_delete"`
NameRegexKeep string `json:"name_regex_keep"`
Enabled bool `json:"enabled"`
@ -742,8 +745,7 @@ func (s *ProjectsService) CreateProject(opt *CreateProjectOptions, options ...Re
if opt.ContainerExpirationPolicyAttributes != nil {
// This is needed to satisfy the API. Should be deleted
// when NameRegex is removed (it's now deprecated).
opt.ContainerExpirationPolicyAttributes.NameRegex =
opt.ContainerExpirationPolicyAttributes.NameRegexDelete
opt.ContainerExpirationPolicyAttributes.NameRegex = opt.ContainerExpirationPolicyAttributes.NameRegexDelete
}
var err error
@ -791,8 +793,7 @@ func (s *ProjectsService) CreateProjectForUser(user int, opt *CreateProjectForUs
if opt.ContainerExpirationPolicyAttributes != nil {
// This is needed to satisfy the API. Should be deleted
// when NameRegex is removed (it's now deprecated).
opt.ContainerExpirationPolicyAttributes.NameRegex =
opt.ContainerExpirationPolicyAttributes.NameRegexDelete
opt.ContainerExpirationPolicyAttributes.NameRegex = opt.ContainerExpirationPolicyAttributes.NameRegexDelete
}
var err error
@ -922,8 +923,7 @@ func (s *ProjectsService) EditProject(pid interface{}, opt *EditProjectOptions,
if opt.ContainerExpirationPolicyAttributes != nil {
// This is needed to satisfy the API. Should be deleted
// when NameRegex is removed (it's now deprecated).
opt.ContainerExpirationPolicyAttributes.NameRegex =
opt.ContainerExpirationPolicyAttributes.NameRegexDelete
opt.ContainerExpirationPolicyAttributes.NameRegex = opt.ContainerExpirationPolicyAttributes.NameRegexDelete
}
project, err := parseID(pid)
@ -1772,11 +1772,16 @@ func (s *ProjectsService) ChangeApprovalConfiguration(pid interface{}, opt *Chan
return pa, resp, err
}
// GetProjectApprovalRules looks up the list of project level approvers.
// GetProjectApprovalRulesListsOptions represents the available GetProjectApprovalRules() options.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/merge_request_approvals.html#get-project-level-rules
type GetProjectApprovalRulesListsOptions ListOptions
// GetProjectApprovalRules looks up the list of project level approver rules.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/merge_request_approvals.html#get-project-level-rules
func (s *ProjectsService) GetProjectApprovalRules(pid interface{}, options ...RequestOptionFunc) ([]*ProjectApprovalRule, *Response, error) {
func (s *ProjectsService) GetProjectApprovalRules(pid interface{}, opt *GetProjectApprovalRulesListsOptions, options ...RequestOptionFunc) ([]*ProjectApprovalRule, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err

View File

@ -51,6 +51,7 @@ type ProtectedBranch struct {
// GitLab API docs:
// https://docs.gitlab.com/ee/api/protected_branches.html#list-protected-branches
type BranchAccessDescription struct {
ID int `json:"id"`
AccessLevel AccessLevelValue `json:"access_level"`
AccessLevelDescription string `json:"access_level_description"`
UserID int `json:"user_id"`
@ -62,7 +63,10 @@ type BranchAccessDescription struct {
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/protected_branches.html#list-protected-branches
type ListProtectedBranchesOptions ListOptions
type ListProtectedBranchesOptions struct {
ListOptions
Search *string `url:"search,omitempty" json:"search,omitempty"`
}
// ListProtectedBranches gets a list of protected branches from a project.
//
@ -188,6 +192,45 @@ func (s *ProtectedBranchesService) UnprotectRepositoryBranches(pid interface{},
return s.client.Do(req, nil)
}
// UpdateProtectedBranchOptions represents the available
// UpdateProtectedBranch() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/protected_branches.html#update-a-protected-branch
type UpdateProtectedBranchOptions struct {
Name *string `url:"name,omitempty" json:"name,omitempty"`
AllowForcePush *bool `url:"allow_force_push,omitempty" json:"allow_force_push,omitempty"`
CodeOwnerApprovalRequired *bool `url:"code_owner_approval_required,omitempty" json:"code_owner_approval_required,omitempty"`
AllowedToPush *[]*BranchPermissionOptions `url:"allowed_to_push,omitempty" json:"allowed_to_push,omitempty"`
AllowedToMerge *[]*BranchPermissionOptions `url:"allowed_to_merge,omitempty" json:"allowed_to_merge,omitempty"`
AllowedToUnprotect *[]*BranchPermissionOptions `url:"allowed_to_unprotect,omitempty" json:"allowed_to_unprotect,omitempty"`
}
// UpdateProtectedBranch updates a protected branch.
//
// Gitlab API docs:
// https://docs.gitlab.com/ee/api/protected_branches.html#update-a-protected-branch
func (s *ProtectedBranchesService) UpdateProtectedBranch(pid interface{}, branch string, opt *UpdateProtectedBranchOptions, options ...RequestOptionFunc) (*ProtectedBranch, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/protected_branches/%s", PathEscape(project), url.PathEscape(branch))
req, err := s.client.NewRequest(http.MethodPatch, u, opt, options)
if err != nil {
return nil, nil, err
}
p := new(ProtectedBranch)
resp, err := s.client.Do(req, p)
if err != nil {
return nil, resp, err
}
return p, resp, err
}
// RequireCodeOwnerApprovalsOptions represents the available
// RequireCodeOwnerApprovals() options.
//
@ -199,19 +242,14 @@ type RequireCodeOwnerApprovalsOptions struct {
// RequireCodeOwnerApprovals updates the code owner approval option.
//
// Deprecated: Use UpdateProtectedBranch() instead.
//
// Gitlab API docs:
// https://docs.gitlab.com/ee/api/protected_branches.html#update-a-protected-branch
func (s *ProtectedBranchesService) RequireCodeOwnerApprovals(pid interface{}, branch string, opt *RequireCodeOwnerApprovalsOptions, options ...RequestOptionFunc) (*Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, err
updateOptions := &UpdateProtectedBranchOptions{
CodeOwnerApprovalRequired: opt.CodeOwnerApprovalRequired,
}
u := fmt.Sprintf("projects/%s/protected_branches/%s", PathEscape(project), url.PathEscape(branch))
req, err := s.client.NewRequest(http.MethodPatch, u, opt, options)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
_, req, err := s.UpdateProtectedBranch(pid, branch, updateOptions, options...)
return req, err
}

View File

@ -61,6 +61,15 @@ type Release struct {
} `json:"sources"`
Links []*ReleaseLink `json:"links"`
} `json:"assets"`
Links struct {
ClosedIssueURL string `json:"closed_issues_url"`
ClosedMergeRequest string `json:"closed_merge_requests_url"`
EditURL string `json:"edit_url"`
MergedMergeRequest string `json:"merged_merge_requests_url"`
OpenedIssues string `json:"opened_issues_url"`
OpenedMergeRequest string `json:"opened_merge_requests_url"`
Self string `json:"self"`
} `json:"_links"`
}
// ListReleasesOptions represents ListReleases() options.

View File

@ -330,3 +330,90 @@ func (s *RepositoriesService) MergeBase(pid interface{}, opt *MergeBaseOptions,
return c, resp, err
}
// AddChangelogOptions represents the available AddChangelog() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/repositories.html#add-changelog-data-to-a-changelog-file
type AddChangelogOptions struct {
Version *string `url:"version,omitempty" json:"version,omitempty"`
Branch *string `url:"branch,omitempty" json:"branch,omitempty"`
ConfigFile *string `url:"config_file,omitempty" json:"config_file,omitempty"`
Date *ISOTime `url:"date,omitempty" json:"date,omitempty"`
File *string `url:"file,omitempty" json:"file,omitempty"`
From *string `url:"from,omitempty" json:"from,omitempty"`
Message *string `url:"message,omitempty" json:"message,omitempty"`
To *string `url:"to,omitempty" json:"to,omitempty"`
Trailer *string `url:"trailer,omitempty" json:"trailer,omitempty"`
}
// AddChangelog generates changelog data based on commits in a repository.
//
// Gitlab API docs:
// https://docs.gitlab.com/ee/api/repositories.html#add-changelog-data-to-a-changelog-file
func (s *RepositoriesService) AddChangelog(pid interface{}, opt *AddChangelogOptions, options ...RequestOptionFunc) (*Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("projects/%s/repository/changelog", PathEscape(project))
req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}
// ChangelogData represents the generated changelog data.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/repositories.html#generate-changelog-data
type ChangelogData struct {
Notes string `json:"notes"`
}
func (c ChangelogData) String() string {
return Stringify(c)
}
// GenerateChangelogDataOptions represents the available GenerateChangelogData()
// options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/repositories.html#generate-changelog-data
type GenerateChangelogDataOptions struct {
Version *string `url:"version,omitempty" json:"version,omitempty"`
ConfigFile *string `url:"config_file,omitempty" json:"config_file,omitempty"`
Date *ISOTime `url:"date,omitempty" json:"date,omitempty"`
From *string `url:"from,omitempty" json:"from,omitempty"`
To *string `url:"to,omitempty" json:"to,omitempty"`
Trailer *string `url:"trailer,omitempty" json:"trailer,omitempty"`
}
// GenerateChangelogData generates changelog data based on commits in a
// repository, without committing them to a changelog file.
//
// Gitlab API docs:
// https://docs.gitlab.com/ee/api/repositories.html#generate-changelog-data
func (s *RepositoriesService) GenerateChangelogData(pid interface{}, opt GenerateChangelogDataOptions, options ...RequestOptionFunc) (*ChangelogData, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/repository/changelog", project)
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
cd := new(ChangelogData)
resp, err := s.client.Do(req, cd)
if err != nil {
return nil, resp, err
}
return cd, resp, err
}

View File

@ -33,6 +33,25 @@ func WithContext(ctx context.Context) RequestOptionFunc {
}
}
// WithHeader takes a header name and value and appends it to the request headers.
func WithHeader(name, value string) RequestOptionFunc {
return func(req *retryablehttp.Request) error {
req.Header.Set(name, value)
return nil
}
}
// WithHeaders takes a map of header name/value pairs and appends them to the
// request headers.
func WithHeaders(headers map[string]string) RequestOptionFunc {
return func(req *retryablehttp.Request) error {
for k, v := range headers {
req.Header.Set(k, v)
}
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 {

View File

@ -1373,7 +1373,7 @@ type SetSlackServiceOptions struct {
// TODO: Currently, GitLab ignores this option (not implemented yet?), so
// there is no way to set it. Uncomment when this is fixed.
// See: https://gitlab.com/gitlab-org/gitlab-ce/issues/49730
//ConfidentialNoteChannel *string `json:"confidential_note_channel,omitempty"`
// ConfidentialNoteChannel *string `json:"confidential_note_channel,omitempty"`
ConfidentialNoteEvents *bool `url:"confidential_note_events,omitempty" json:"confidential_note_events,omitempty"`
DeploymentChannel *string `url:"deployment_channel,omitempty" json:"deployment_channel,omitempty"`
DeploymentEvents *bool `url:"deployment_events,omitempty" json:"deployment_events,omitempty"`

View File

@ -20,6 +20,7 @@ import (
"bytes"
"fmt"
"net/http"
"net/url"
"time"
)
@ -39,6 +40,7 @@ type Snippet struct {
Title string `json:"title"`
FileName string `json:"file_name"`
Description string `json:"description"`
Visibility string `json:"visibility"`
Author struct {
ID int `json:"id"`
Username string `json:"username"`
@ -63,12 +65,14 @@ func (s Snippet) String() string {
// ListSnippetsOptions represents the available ListSnippets() options.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/snippets.html#list-all-snippets-for-a-user
// GitLab API docs:
// https://docs.gitlab.com/ee/api/snippets.html#list-all-snippets-for-a-user
type ListSnippetsOptions ListOptions
// ListSnippets gets a list of snippets.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/snippets.html#list-all-snippets-for-a-user
// GitLab API docs:
// https://docs.gitlab.com/ee/api/snippets.html#list-all-snippets-for-a-user
func (s *SnippetsService) ListSnippets(opt *ListSnippetsOptions, options ...RequestOptionFunc) ([]*Snippet, *Response, error) {
req, err := s.client.NewRequest(http.MethodGet, "snippets", opt, options)
if err != nil {
@ -105,11 +109,54 @@ func (s *SnippetsService) GetSnippet(snippet int, options ...RequestOptionFunc)
return ps, resp, err
}
// SnippetFile represents the object that is used to create snippets
// SnippetContent gets a single snippets raw contents.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/snippets.html#single-snippet-contents
func (s *SnippetsService) SnippetContent(snippet int, options ...RequestOptionFunc) ([]byte, *Response, error) {
u := fmt.Sprintf("snippets/%d/raw", snippet)
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}
var b bytes.Buffer
resp, err := s.client.Do(req, &b)
if err != nil {
return nil, resp, err
}
return b.Bytes(), resp, err
}
// SnippetFileContent returns the raw file content as plain text.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/snippets.html#snippet-repository-file-content
func (s *SnippetsService) SnippetFileContent(snippet int, ref, filename string, options ...RequestOptionFunc) ([]byte, *Response, error) {
filepath := url.QueryEscape(filename)
u := fmt.Sprintf("snippets/%d/files/%s/%s/raw", snippet, ref, filepath)
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}
var b bytes.Buffer
resp, err := s.client.Do(req, &b)
if err != nil {
return nil, resp, err
}
return b.Bytes(), resp, err
}
// CreateSnippetFileOptions represents the create snippet file options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/snippets.html#create-new-snippet
type SnippetFile struct {
type CreateSnippetFileOptions struct {
FilePath *string `url:"file_path,omitempty" json:"file_path,omitempty"`
Content *string `url:"content,omitempty" json:"content,omitempty"`
}
@ -119,12 +166,12 @@ type SnippetFile struct {
// GitLab API docs:
// https://docs.gitlab.com/ee/api/snippets.html#create-new-snippet
type CreateSnippetOptions struct {
Title *string `url:"title,omitempty" json:"title,omitempty"`
FileName *string `url:"file_name,omitempty" json:"file_name,omitempty"`
Description *string `url:"description,omitempty" json:"description,omitempty"`
Content *string `url:"content,omitempty" json:"content,omitempty"`
Visibility *VisibilityValue `url:"visibility,omitempty" json:"visibility,omitempty"`
Files *[]*SnippetFile `url:"files,omitempty" json:"files,omitempty"`
Title *string `url:"title,omitempty" json:"title,omitempty"`
FileName *string `url:"file_name,omitempty" json:"file_name,omitempty"`
Description *string `url:"description,omitempty" json:"description,omitempty"`
Content *string `url:"content,omitempty" json:"content,omitempty"`
Visibility *VisibilityValue `url:"visibility,omitempty" json:"visibility,omitempty"`
Files *[]*CreateSnippetFileOptions `url:"files,omitempty" json:"files,omitempty"`
}
// CreateSnippet creates a new snippet. The user must have permission
@ -147,16 +194,28 @@ func (s *SnippetsService) CreateSnippet(opt *CreateSnippetOptions, options ...Re
return ps, resp, err
}
// UpdateSnippetFileOptions represents the update snippet file options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/snippets.html#update-snippet
type UpdateSnippetFileOptions struct {
Action *string `url:"action,omitempty" json:"action,omitempty"`
FilePath *string `url:"file_path,omitempty" json:"file_path,omitempty"`
Content *string `url:"content,omitempty" json:"content,omitempty"`
PreviousPath *string `url:"previous_path,omitempty" json:"previous_path,omitempty"`
}
// UpdateSnippetOptions represents the available UpdateSnippet() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/snippets.html#update-snippet
type UpdateSnippetOptions struct {
Title *string `url:"title,omitempty" json:"title,omitempty"`
FileName *string `url:"file_name,omitempty" json:"file_name,omitempty"`
Description *string `url:"description,omitempty" json:"description,omitempty"`
Content *string `url:"content,omitempty" json:"content,omitempty"`
Visibility *VisibilityValue `url:"visibility,omitempty" json:"visibility,omitempty"`
Title *string `url:"title,omitempty" json:"title,omitempty"`
FileName *string `url:"file_name,omitempty" json:"file_name,omitempty"`
Description *string `url:"description,omitempty" json:"description,omitempty"`
Content *string `url:"content,omitempty" json:"content,omitempty"`
Visibility *VisibilityValue `url:"visibility,omitempty" json:"visibility,omitempty"`
Files *[]*UpdateSnippetFileOptions `url:"files,omitempty" json:"files,omitempty"`
}
// UpdateSnippet updates an existing snippet. The user must have
@ -198,27 +257,6 @@ func (s *SnippetsService) DeleteSnippet(snippet int, options ...RequestOptionFun
return s.client.Do(req, nil)
}
// SnippetContent returns the raw snippet as plain text.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/snippets.html#single-snippet-contents
func (s *SnippetsService) SnippetContent(snippet int, options ...RequestOptionFunc) ([]byte, *Response, error) {
u := fmt.Sprintf("snippets/%d/raw", snippet)
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}
var b bytes.Buffer
resp, err := s.client.Do(req, &b)
if err != nil {
return nil, resp, err
}
return b.Bytes(), resp, err
}
// ExploreSnippetsOptions represents the available ExploreSnippets() options.
//
// GitLab API docs:

View File

@ -19,7 +19,6 @@ package gitlab
import (
"bytes"
"fmt"
"reflect"
)

2
vendor/modules.txt vendored
View File

@ -102,7 +102,7 @@ github.com/spf13/viper/internal/encoding/yaml
# github.com/subosito/gotenv v1.4.2
## explicit; go 1.18
github.com/subosito/gotenv
# github.com/xanzy/go-gitlab v0.79.1
# github.com/xanzy/go-gitlab v0.80.2
## explicit; go 1.18
github.com/xanzy/go-gitlab
# golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa