Pipeline as Code integration for GitLab (#1769)

* feat: PaC for Gitlab

Signed-off-by: Matej Vasek <mvasek@redhat.com>

* fixup: different approach to hostname resolution

Resolve '[*.]127.0.0.1.sslip.io' to cluster node IP.

Signed-off-by: Matej Vasek <mvasek@redhat.com>

* fixup: error handling

Signed-off-by: Matej Vasek <mvasek@redhat.com>

* fixup: added TODO

Signed-off-by: Matej Vasek <mvasek@redhat.com>

* fixup: small refactor

Signed-off-by: Matej Vasek <mvasek@redhat.com>

---------

Signed-off-by: Matej Vasek <mvasek@redhat.com>
This commit is contained in:
Matej Vasek 2023-06-05 21:48:26 +02:00 committed by GitHub
parent d3e33738b9
commit 4e743684e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
173 changed files with 50263 additions and 25 deletions

View File

@ -15,12 +15,26 @@ jobs:
- uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go }}
- uses: imjasonh/setup-ko@v0.6
- name: Install Binaries
run: ./hack/binaries.sh
- name: Allocate Cluster
run: ./hack/allocate.sh
- name: Setup testing func image
run: ./hack/create-testing-func-image.sh
- name: Local Registry
run: ./hack/registry.sh
- name: Allocate Cluster
run: ./hack/allocate.sh
- name: Install Tekton
run: ./hack/tekton.sh
- name: Install Pipelines as Code
run: ./hack/install-pac.sh
- name: Install Gitlab
run: |
export GITLAB_ROOT_PASSWORD=nbusr123
echo "GITLAB_ROOT_PASSWORD=${GITLAB_ROOT_PASSWORD}" >> "$GITHUB_ENV"
./hack/install-gitlab.sh
- name: Patch Hosts
run: ./hack/patch-hosts.sh
- name: Integration Test
run: make test-integration
- uses: codecov/codecov-action@v3

5
go.mod
View File

@ -37,7 +37,9 @@ require (
github.com/tektoncd/cli v0.31.0
github.com/tektoncd/pipeline v0.47.0
github.com/whilp/git-urls v1.0.0
github.com/xanzy/go-gitlab v0.83.0
golang.org/x/crypto v0.8.0
golang.org/x/net v0.9.0
golang.org/x/oauth2 v0.7.0
golang.org/x/sync v0.1.0
golang.org/x/term v0.8.0
@ -142,7 +144,9 @@ require (
github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.2 // indirect
github.com/hako/durafmt v0.0.0-20210608085754-5c1018a4e16b // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-retryablehttp v0.7.2 // indirect
github.com/hashicorp/golang-lru v0.6.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/iancoleman/orderedmap v0.0.0-20190318233801-ac98e3ecb4b0 // indirect
@ -220,7 +224,6 @@ require (
go.uber.org/zap v1.24.0 // indirect
golang.org/x/exp v0.0.0-20230307190834-24139beb5833 // indirect
golang.org/x/mod v0.9.0 // indirect
golang.org/x/net v0.9.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/time v0.3.0 // indirect

6
go.sum
View File

@ -955,10 +955,12 @@ github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ=
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
github.com/hashicorp/go-hclog v0.12.0/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ=
github.com/hashicorp/go-hclog v1.0.0/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ=
github.com/hashicorp/go-hclog v1.3.1 h1:vDwF1DFNZhntP4DAjuTpOw3uEgMUpXh1pB5fW9DqHpo=
github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
github.com/hashicorp/go-immutable-radix v1.3.1/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM=
@ -970,6 +972,8 @@ github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9
github.com/hashicorp/go-retryablehttp v0.5.3/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs=
github.com/hashicorp/go-retryablehttp v0.6.4/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY=
github.com/hashicorp/go-retryablehttp v0.6.6/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY=
github.com/hashicorp/go-retryablehttp v0.7.2 h1:AcYqCvkpalPnPF2pn0KamgwamS42TqUDDYFRKq/RAd0=
github.com/hashicorp/go-retryablehttp v0.7.2/go.mod h1:Jy/gPYAdjqffZ/yFGCFV2doI5wjtH1ewM9u8iYVjtX8=
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=
@ -1644,6 +1648,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/xanzy/go-gitlab v0.31.0/go.mod h1:sPLojNBn68fMUWSxIJtdVVIP8uSBYqesTfDUseX11Ug=
github.com/xanzy/go-gitlab v0.32.0/go.mod h1:sPLojNBn68fMUWSxIJtdVVIP8uSBYqesTfDUseX11Ug=
github.com/xanzy/go-gitlab v0.83.0 h1:37p0MpTPNbsTMKX/JnmJtY8Ch1sFiJzVF342+RvZEGw=
github.com/xanzy/go-gitlab v0.83.0/go.mod h1:5ryv+MnpZStBH8I/77HuQBsMbBGANtVpLWC15qOjWAw=
github.com/xanzy/ssh-agent v0.3.0/go.mod h1:3s9xbODqPuuhK9JV1R321M/FlMZSBvE5aY6eAcqrDh0=
github.com/xanzy/ssh-agent v0.3.1/go.mod h1:QIE4lCeL7nkC25x+yA3LBIYfwCc1TFziCtG7cBAac6w=
github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM=

View File

@ -64,6 +64,9 @@ nodes:
- containerPort: 433
hostPort: 443
listenAddress: "127.0.0.1"
- containerPort: 30022
hostPort: 30022
listenAddress: "127.0.0.1"
containerdConfigPatches:
- |-
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."localhost:50000"]

169
hack/install-gitlab.sh Executable file
View File

@ -0,0 +1,169 @@
#!/usr/bin/env bash
function install_gitlab() {
local -r gitlab_host="gitlab.127.0.0.1.sslip.io"
kubectl apply -f - <<EOF
kind: Namespace
apiVersion: v1
metadata:
name: gitlab
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: gitlab
namespace: gitlab
labels:
app: gitlab
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
---
apiVersion: v1
kind: Pod
metadata:
name: gitlab
namespace: gitlab
labels:
app.kubernetes.io/name: gitlab
spec:
containers:
- name: gitlab
image: gitlab/gitlab-ce:latest
volumeMounts:
- name: gitlab
subPath: config
mountPath: /etc/gitlab
- name: gitlab
subPath: logs
mountPath: /var/log/gitlab
- name: gitlab
subPath: data
mountPath: /var/opt/gitlab
env:
- name: GITLAB_ROOT_PASSWORD
value: ${GITLAB_ROOT_PASSWORD}
- name: GITLAB_OMNIBUS_CONFIG
value: |
external_url 'http://${gitlab_host}'
gitlab_rails['gitlab_shell_ssh_port'] = 30022
gitlab_rails['gitlab_email_enabled'] = false
puma['worker_processes'] = 0
sidekiq['max_concurrency'] = 1
prometheus_monitoring['enable'] = false
gitlab_rails['env'] = {
'MALLOC_CONF' => 'dirty_decay_ms:1000,muzzy_decay_ms:1000'
}
gitaly['configuration'] = {
ruby_max_rss: 200_000_000,
concurrency: [
{
rpc: "/gitaly.SmartHTTPService/PostReceivePack",
max_per_repo: 1
}, {
rpc: "/gitaly.SSHService/SSHUploadPack",
max_per_repo: 1
}
]
}
gitaly['env'] = {
'MALLOC_CONF' => 'dirty_decay_ms:1000,muzzy_decay_ms:1000',
'GITALY_COMMAND_SPAWN_MAX_PARALLEL' => '1'
}
ports:
- containerPort: 80
name: http
- containerPort: 22
name: ssh
resources:
requests:
memory: "1024Mi"
limits:
memory: "2048Mi"
volumes:
- name: gitlab
persistentVolumeClaim:
claimName: gitlab
---
apiVersion: v1
kind: Service
metadata:
name: gitlab-internal
namespace: gitlab
spec:
selector:
app.kubernetes.io/name: gitlab
ports:
- name: http
protocol: TCP
port: 80
targetPort: http
- name: ssh
protocol: TCP
port: 30022
targetPort: ssh
type: ClusterIP
---
apiVersion: v1
kind: Service
metadata:
name: gitlab-external-ssh
namespace: gitlab
spec:
selector:
app.kubernetes.io/name: gitlab
ports:
- name: ssh
protocol: TCP
port: 30022
targetPort: ssh
nodePort: 30022
type: NodePort
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: gitlab
namespace: gitlab
spec:
ingressClassName: contour-external
rules:
- host: ${gitlab_host}
http:
paths:
- backend:
service:
name: gitlab-internal
port:
number: 80
pathType: Prefix
path: /
EOF
sleep 1
kubectl wait pod --for=condition=Ready -l '!job-name' -n gitlab --timeout=5m
echo '::group::Waiting for Gitlab'
if ! curl --retry 120 -f --retry-all-errors --retry-delay 5 "${gitlab_host}"; then
kubectl logs pod/gitlab -n gitlab
echo '::endgroup::'
return 1
fi
echo '::endgroup::'
}
if [ "$0" = "${BASH_SOURCE[0]}" ]; then
set -o errexit
set -o nounset
set -o pipefail
function main() {
install_gitlab
}
main "$@"
fi

44
hack/install-pac.sh Executable file
View File

@ -0,0 +1,44 @@
#!/usr/bin/env bash
function install_pac() {
local -r pac_ctr_host="pac-ctr.127.0.0.1.sslip.io"
local -r pac_version="v0.17.1"
# Install Pipelines as Code
kubectl apply -f "https://raw.githubusercontent.com/openshift-pipelines/pipelines-as-code/release-${pac_version}/release.k8s.yaml"
sleep 5
kubectl wait pod --for=condition=Ready -l '!job-name' -n pipelines-as-code --timeout=5m
# Install ingress for the PaC controller. This is used by VCS Webhooks.
kubectl apply -f - << EOF
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: pipelines-as-code
namespace: pipelines-as-code
spec:
ingressClassName: contour-external
rules:
- host: ${pac_ctr_host}
http:
paths:
- backend:
service:
name: pipelines-as-code-controller
port:
number: 8080
pathType: Prefix
path: /
EOF
}
if [ "$0" = "${BASH_SOURCE[0]}" ]; then
set -o errexit
set -o nounset
set -o pipefail
function main() {
install_pac
}
main "$@"
fi

68
hack/patch-hosts.sh Executable file
View File

@ -0,0 +1,68 @@
#!/usr/bin/env bash
# This script creates a DNS A records for '127.0.0.1.sslip.io' and '*.127.0.0.1.sslip.io' pointing to the cluster node.
function patch_hosts() {
local cluster_node_addr
cluster_node_addr="$(docker container inspect func-control-plane | jq ".[0].NetworkSettings.Networks.kind.IPAddress" -r)"
kubectl patch cm/coredns -n kube-system --patch-file /dev/stdin <<EOF
{
"data": {
"Corefile": ".:53 {\n errors\n health {\n lameduck 5s\n }\n ready\n kubernetes cluster.local in-addr.arpa ip6.arpa {\n pods insecure\n fallthrough in-addr.arpa ip6.arpa\n ttl 30\n }\n file /etc/coredns/example.db 127.0.0.1.sslip.io\n prometheus :9153\n forward . /etc/resolv.conf {\n max_concurrent 1000\n }\n cache 30\n loop\n reload\n loadbalance\n}\n",
"example.db": "; 127.0.0.1.sslip.io test file\n127.0.0.1.sslip.io. IN SOA sns.dns.icann.org. noc.dns.icann.org. 2015082541 7200 3600 1209600 3600\n127.0.0.1.sslip.io. IN A ${cluster_node_addr}\n*.127.0.0.1.sslip.io. IN A ${cluster_node_addr}\n"
}
}
EOF
kubectl patch deploy/coredns -n kube-system --patch-file /dev/stdin <<EOF
{
"spec": {
"template": {
"spec": {
"\$setElementOrder/volumes": [
{
"name": "config-volume"
}
],
"volumes": [
{
"\$retainKeys": [
"configMap",
"name"
],
"configMap": {
"items": [
{
"key": "Corefile",
"path": "Corefile"
},
{
"key": "example.db",
"path": "example.db"
}
]
},
"name": "config-volume"
}
]
}
}
}
}
EOF
sleep 1
kubectl wait pod --for=condition=Ready -l '!job-name' -n kube-system --timeout=15s
}
if [ "$0" = "${BASH_SOURCE[0]}" ]; then
set -o errexit
set -o nounset
set -o pipefail
function main() {
patch_hosts
}
main "$@"
fi

View File

@ -1,11 +1,16 @@
package git
import (
"context"
"fmt"
"net/url"
"strconv"
"strings"
"github.com/openshift-pipelines/pipelines-as-code/pkg/formatting"
"knative.dev/func/pkg/git/github"
"knative.dev/func/pkg/git/gitlab"
)
const (
@ -16,7 +21,7 @@ const (
type SupportedProviders []string
var SupportedProvidersList = SupportedProviders{GitHubProvider}
var SupportedProvidersList = SupportedProviders{GitHubProvider, GitLabProvider}
func (sp SupportedProviders) PrettyString() string {
var b strings.Builder
@ -37,7 +42,7 @@ func GitProviderName(url string) (string, error) {
case strings.Contains(url, "github"):
return GitHubProvider, nil
case strings.Contains(url, "gitlab"):
//return GitLabProvider, nil
return GitLabProvider, nil
case strings.Contains(url, "bitbucket-cloud"):
//return BitBucketProvider, nil
}
@ -65,3 +70,43 @@ func RepoOwnerAndNameFromUrl(url string) (string, string, error) {
return repoOwner, repoName, nil
}
func CreateWebHook(ctx context.Context, gitRepoURL, webHookTarget, webHookSecret, personalAccessToken string) error {
providerName, err := GitProviderName(gitRepoURL)
if err != nil {
return err
}
u, err := url.Parse(gitRepoURL)
if err != nil {
return fmt.Errorf("cannot parse git repo url: %w", err)
}
var cli providerClient
switch providerName {
case GitHubProvider:
cli = github.Client{
PersonalAccessToken: personalAccessToken,
}
case GitLabProvider:
cli = gitlab.Client{
BaseURL: u.Scheme + "://" + u.Host,
PersonalAccessToken: personalAccessToken,
}
}
repoOwner, repoName, err := RepoOwnerAndNameFromUrl(gitRepoURL)
if err != nil {
return err
}
err = cli.CreateWebHook(ctx, repoOwner, repoName, webHookTarget, webHookSecret)
if err != nil {
return fmt.Errorf("cannot create web hook: %w", err)
}
return nil
}
type providerClient interface {
CreateWebHook(ctx context.Context, repoOwner, repoName, payloadURL, webhookSecret string) error
}

View File

@ -68,14 +68,14 @@ func TestGitProviderName(t *testing.T) {
wantErr: false,
},
{
name: "GitLab - not supported",
url: "https://gitlab.com/foo/bar",
//wantProvider: GitLabProvider,
wantErr: true,
name: "GitLab",
url: "https://gitlab.com/foo/bar",
wantProvider: GitLabProvider,
wantErr: false,
},
{
name: "Bitbucket Cloud - not supported",
url: "https://gitlab.com/foo/bar",
url: "https://bitbucket.com/foo/bar",
//wantProvider: BitBucketProvider,
wantErr: true,
},

View File

@ -10,7 +10,11 @@ import (
"golang.org/x/oauth2"
)
func CreateGitHubWebhook(ctx context.Context, repoOwner, repoName, payloadURL, webhookSecret, personalAccessToken string) error {
type Client struct {
PersonalAccessToken string
}
func (c Client) CreateWebHook(ctx context.Context, repoOwner, repoName, payloadURL, webhookSecret string) error {
hook := &github.Hook{
Name: github.String("web"),
Active: github.Bool(true),
@ -27,7 +31,7 @@ func CreateGitHubWebhook(ctx context.Context, repoOwner, repoName, payloadURL, w
},
}
ghClient, err := newGHClientByToken(ctx, personalAccessToken, "")
ghClient, err := newGHClientByToken(ctx, c.PersonalAccessToken, "")
if err != nil {
return err
}

36
pkg/git/gitlab/gitlab.go Normal file
View File

@ -0,0 +1,36 @@
package gitlab
import (
"context"
"fmt"
"github.com/xanzy/go-gitlab"
)
type Client struct {
BaseURL string
PersonalAccessToken string
}
func (c Client) CreateWebHook(ctx context.Context, repoOwner, repoName, payloadURL, webhookSecret string) error {
t := true
f := false
glabCli, err := gitlab.NewClient(c.PersonalAccessToken,
gitlab.WithBaseURL(c.BaseURL),
gitlab.WithRequestOptions(gitlab.WithContext(ctx)))
if err != nil {
return fmt.Errorf("cannot create GitLab client: %w", err)
}
webhook := &gitlab.AddProjectHookOptions{
EnableSSLVerification: &f,
PushEvents: &t,
Token: &webhookSecret,
URL: &payloadURL,
}
// TODO check if the WebHook already exists. GitLab doesn't name WebHooks so there is never 403.
_, _, err = glabCli.Projects.AddProjectHook(repoOwner+"/"+repoName, webhook)
if err != nil {
return fmt.Errorf("cannot create gitlab webhook: %w", err)
}
return nil
}

View File

@ -0,0 +1,579 @@
//go:build integration
// +build integration
package tekton_test
import (
"context"
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand"
"crypto/x509"
"encoding/json"
"encoding/pem"
"fmt"
"net/http"
"net/http/cookiejar"
"net/url"
"os"
"os/exec"
"os/signal"
"path/filepath"
"strings"
"testing"
"time"
"github.com/xanzy/go-gitlab"
"golang.org/x/crypto/ssh"
"golang.org/x/net/html"
pipelinev1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/uuid"
"knative.dev/pkg/apis"
"knative.dev/func/pkg/docker"
fn "knative.dev/func/pkg/functions"
"knative.dev/func/pkg/k8s"
"knative.dev/func/pkg/pipelines"
"knative.dev/func/pkg/pipelines/tekton"
"knative.dev/func/pkg/random"
)
const (
gitlabURL = "http://gitlab.127.0.0.1.sslip.io"
pacControllerURL = "http://pac-ctr.127.0.0.1.sslip.io"
)
func TestGitlab(t *testing.T) {
var err error
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
defer cancel()
rootPassword := os.Getenv("GITLAB_ROOT_PASSWORD")
if rootPassword == "" {
t.Skip("GITLAB_ROOT_PASSWORD not set")
}
glabEnv := setupGitlabEnv(ctx, t, gitlabURL, "root", rootPassword)
tempHome := t.TempDir()
projDir := filepath.Join(t.TempDir(), "fn")
err = os.MkdirAll(projDir, 0755)
if err != nil {
t.Fatal(err)
}
ns := usingNamespace(t)
t.Logf("testing in namespace: %q", ns)
funcImg := fmt.Sprintf("ttl.sh/func/fn-%s:5m", uuid.NewUUID())
f := fn.Function{
Root: projDir,
Name: glabEnv.ProjectName,
Runtime: "test-runtime",
Template: "test-template",
Image: funcImg,
Created: time.Now(),
Invoke: "none",
Build: fn.BuildSpec{
Git: fn.Git{
URL: strings.TrimSuffix(glabEnv.HTTPProjectURL, ".git"),
Revision: "devel",
},
BuilderImages: map[string]string{"pack": "docker.io/paketobuildpacks/builder:tiny"},
Builder: "pack",
PVCSize: "256Mi",
},
Deploy: fn.DeploySpec{
Remote: true,
Namespace: ns,
},
}
f = fn.NewFunctionWith(f)
err = f.Write()
if err != nil {
t.Fatal(err)
}
err = os.WriteFile(filepath.Join(projDir, "Procfile"), []byte("web: non-existent-app\n"), 0644)
if err != nil {
t.Fatal(err)
}
credentialsProvider := func(ctx context.Context, image string) (docker.Credentials, error) {
return docker.Credentials{
Username: "",
Password: "",
}, nil
}
pp := tekton.NewPipelinesProvider(
tekton.WithCredentialsProvider(credentialsProvider),
tekton.WithPacURLCallback(func() (string, error) {
return pacControllerURL, nil
}))
metadata := pipelines.PacMetadata{
PersonalAccessToken: glabEnv.UserToken,
ConfigureLocalResources: true,
ConfigureClusterResources: true,
ConfigureRemoteResources: true,
}
err = pp.ConfigurePAC(context.Background(), f, metadata)
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() {
_ = pp.RemovePAC(context.Background(), f, metadata)
})
buildDoneCh := awaitBuildCompletion(t, glabEnv.ProjectName)
gitCommands := `export GIT_TERMINAL_PROMPT=0 && \
cd "${PROJECT_DIR}" && \
git config --global user.name "John Doe" && \
git config --global user.email "jdoe@example.com" && \
git config --global core.sshCommand "ssh -i ${SSH_IDENTITY_FILE} -o UserKnownHostsFile=${HOME}/known_hosts -o StrictHostKeyChecking=no" && \
git init --initial-branch=devel && \
git remote add origin "${REPO_URL}" && \
git add . && \
git commit -m "commit message" && \
git push -u origin devel
`
cmd := exec.Command("sh", "-c", gitCommands)
cmd.Env = []string{
"PROJECT_DIR=" + projDir,
"SSH_IDENTITY_FILE=" + glabEnv.UserIdentityFile,
"REPO_URL=" + glabEnv.SSHProjectURL,
"HOME=" + tempHome,
}
out, err := cmd.CombinedOutput()
if err != nil {
t.Log(string(out))
t.Fatal(err)
}
select {
case <-buildDoneCh:
t.Log("build done on time")
case <-time.After(time.Minute * 10):
t.Error("build has not been done in time")
case <-ctx.Done():
t.Error("cancelled")
}
}
type gitlabEnv struct {
ProjectName string
HTTPProjectURL string
SSHProjectURL string
GroupName string
UserName string
UserToken string
UserIdentityFile string
}
func setupGitlabEnv(ctx context.Context, t *testing.T, baseURL, username, password string) gitlabEnv {
t.Log("setting up gitlab env")
randStr := strings.ToLower(random.AlphaString(5))
userName := "func_user_" + randStr
userPassword := "1ddqd1dkf@"
groupName := "func-grp-" + randStr
projectName := "func-project-" + randStr
//region Initialize Root's Gitlab client
rootToken, err := getAPIToken(baseURL, username, password)
if err != nil {
t.Fatal(err)
}
glabCli, err := gitlab.NewClient(rootToken, gitlab.WithBaseURL(baseURL))
if err != nil {
t.Fatal(err)
}
pat, _, err := glabCli.PersonalAccessTokens.GetSinglePersonalAccessToken()
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() {
_, _ = glabCli.PersonalAccessTokens.RevokePersonalAccessToken(pat.ID)
})
//endregion
//region Enable Webhooks to non-public IP.
newSettings := &gitlab.UpdateSettingsOptions{
AllowLocalRequestsFromWebHooksAndServices: p(true),
}
_, _, err = glabCli.Settings.UpdateSettings(newSettings)
if err != nil {
t.Fatal(err)
}
// For some reason the setting update does not kick in immediately.
select {
case <-ctx.Done():
t.Fatal("cancelled")
case <-time.After(time.Minute):
}
//endregion
//region Create test user
userOpts := &gitlab.CreateUserOptions{
Name: p("John Doe"),
Username: p(userName),
Password: p(userPassword),
ForceRandomPassword: p(false),
Email: p(fmt.Sprintf("%s@example.com", userName)),
}
u, _, err := glabCli.Users.CreateUser(userOpts)
if err != nil {
t.Fatal(err)
}
t.Logf("created user %q", u.Username)
t.Cleanup(func() {
_, _ = glabCli.Users.DeleteUser(u.ID)
})
//endregion
//region Create test group
groupOpts := &gitlab.CreateGroupOptions{
Name: p(groupName),
Path: p(groupName),
Description: p("group for `func` testing"),
Visibility: p(gitlab.PublicVisibility),
RequireTwoFactorAuth: p(false),
ProjectCreationLevel: p(gitlab.DeveloperProjectCreation),
LFSEnabled: p(true),
RequestAccessEnabled: p(true),
}
g, _, err := glabCli.Groups.CreateGroup(groupOpts)
if err != nil {
t.Fatal(err)
}
t.Logf("created group: %q", g.Name)
t.Cleanup(func() {
_, _ = glabCli.Groups.DeleteGroup(g.ID)
})
//endregion
//region Add test user to the test group
grpMemOpts := &gitlab.AddGroupMemberOptions{
UserID: p(u.ID),
AccessLevel: p(gitlab.MaintainerPermissions),
}
_, _, err = glabCli.GroupMembers.AddGroupMember(g.ID, grpMemOpts)
if err != nil {
t.Fatal(err)
}
//endregion
//region Create test project
creatProjOpts := &gitlab.CreateProjectOptions{
Name: p(projectName),
NamespaceID: p(g.ID),
Path: p(projectName),
Visibility: p(gitlab.PublicVisibility),
InitializeWithReadme: p(true),
DefaultBranch: p("main"),
}
project, _, err := glabCli.Projects.CreateProject(creatProjOpts)
if err != nil {
t.Fatal(err)
}
t.Logf("created project: %q", project.Name)
t.Cleanup(func() {
_, _ = glabCli.Projects.DeleteProject(project.ID)
})
//endregion
//region Add public SSK key for test user
sshPrivateKeyPath := generateSSHKeys(t)
sshPublicKeyBytes, err := os.ReadFile(sshPrivateKeyPath + ".pub")
if err != nil {
t.Fatal(err)
}
userToken, err := getAPIToken(baseURL, userName, userPassword)
if err != nil {
t.Fatal(err)
}
glabCliUser, err := gitlab.NewClient(userToken, gitlab.WithBaseURL(baseURL))
if err != nil {
t.Fatal(err)
}
addSshKeyOpts := &gitlab.AddSSHKeyOptions{
Title: p("func-ssh-key"),
Key: p(string(sshPublicKeyBytes)),
}
_, _, err = glabCliUser.Users.AddSSHKey(addSshKeyOpts)
if err != nil {
t.Fatal(err)
}
//endregion
return gitlabEnv{
ProjectName: projectName,
HTTPProjectURL: project.HTTPURLToRepo,
SSHProjectURL: project.SSHURLToRepo,
GroupName: groupName,
UserName: userName,
UserToken: userToken,
UserIdentityFile: sshPrivateKeyPath,
}
}
func getAPIToken(baseURL, username, password string) (string, error) {
jar, err := cookiejar.New(nil)
if err != nil {
return "", fmt.Errorf("cannot create a cookie jar: %w", err)
}
c := http.Client{
Jar: jar,
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
},
}
signInURL := baseURL + "/users/sign_in"
resp, err := c.Get(signInURL)
if err != nil {
return "", fmt.Errorf("cannot get sign in page: %w", err)
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
return "", fmt.Errorf("cannot get sign in page, unexpected status: %d", resp.StatusCode)
}
node, err := html.Parse(resp.Body)
if err != nil {
return "", fmt.Errorf("cannot parse sign in page: %w", err)
}
csrfToken := getCSRFToken(node)
form := url.Values{}
form.Add("authenticity_token", csrfToken)
form.Add("user[login]", username)
form.Add("user[password]", password)
form.Add("user[remember_me]", "0")
req, err := http.NewRequest("POST", signInURL, strings.NewReader(form.Encode()))
if err != nil {
return "", fmt.Errorf("cannot create sign in request: %w", err)
}
req.Header.Add("Origin", baseURL)
req.Header.Add("Referer", signInURL)
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
resp, err = c.Do(req)
if err != nil {
return "", fmt.Errorf("cannot sign in: %w", err)
}
defer resp.Body.Close()
if resp.StatusCode != 302 {
return "", fmt.Errorf("cannot sign in, unexpected status: %d", resp.StatusCode)
}
personalAccessTokensURL := baseURL + "/-/profile/personal_access_tokens"
resp, err = c.Get(personalAccessTokensURL)
if err != nil {
return "", fmt.Errorf("cannot get personal access tokens: %w", err)
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
return "", fmt.Errorf("cannot get personal access tokens, unexpected status: %d", resp.StatusCode)
}
node, err = html.Parse(resp.Body)
if err != nil {
return "", fmt.Errorf("cannot parse personal access tokens page: %w", err)
}
csrfToken = getCSRFToken(node)
form = url.Values{
"personal_access_token[name]": {"test-2"},
"personal_access_token[expires_at]": {time.Now().Add(time.Hour * 25).Format("2006-01-02")},
"personal_access_token[scopes][]": {"api", "read_api", "read_user", "read_repository", "write_repository", "sudo"},
}
req, err = http.NewRequest("POST", personalAccessTokensURL, strings.NewReader(form.Encode()))
if err != nil {
return "", fmt.Errorf("cannot create new personal access token request: %w", err)
}
req.Header.Add("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
req.Header.Add("X-CSRF-Token", csrfToken)
resp, err = c.Do(req)
if err != nil {
return "", fmt.Errorf("cannot create new personal access token: %w", err)
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
return "", fmt.Errorf("cannot create new personal access token, unexpected status: %d", resp.StatusCode)
}
data := struct {
NewToken string `json:"new_token,omitempty"`
}{}
e := json.NewDecoder(resp.Body)
err = e.Decode(&data)
if err != nil {
return "", fmt.Errorf("cannot parse token form a response: %w", err)
}
return data.NewToken, nil
}
func getCSRFToken(n *html.Node) string {
var match bool
var token string
for _, a := range n.Attr {
if a.Key == "name" && (a.Val == "authenticity_token" || a.Val == "csrf-token") {
match = true
}
if a.Key == "value" || a.Key == "content" {
token = a.Val
}
}
if match {
return token
}
for n = n.FirstChild; n != nil; n = n.NextSibling {
token = getCSRFToken(n)
if token != "" {
return token
}
}
return ""
}
func generateSSHKeys(t *testing.T) string {
tmp := t.TempDir()
privateKeyPath := filepath.Join(tmp, "id_ecdsa")
publicKeyPath := privateKeyPath + ".pub"
privateKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
if err != nil {
t.Fatal(err)
}
privateKeyBytes, err := x509.MarshalECPrivateKey(privateKey)
if err != nil {
t.Fatal(err)
}
privateKeyBlock := &pem.Block{
Type: "EC PRIVATE KEY",
Bytes: privateKeyBytes,
}
privateKeyFile, err := os.OpenFile(privateKeyPath, os.O_CREATE|os.O_WRONLY, 0400)
if err != nil {
t.Fatal(err)
}
err = pem.Encode(privateKeyFile, privateKeyBlock)
if err != nil {
t.Fatal(err)
}
publicKey, err := ssh.NewPublicKey(&privateKey.PublicKey)
if err != nil {
t.Fatal(err)
}
publicKeyBytes := ssh.MarshalAuthorizedKey(publicKey)
err = os.WriteFile(publicKeyPath, publicKeyBytes, 0444)
if err != nil {
t.Fatal(err)
}
return privateKeyPath
}
func usingNamespace(t *testing.T) string {
name := "gitlab-test-" + strings.ToLower(random.AlphaString(5))
k8sClient, err := k8s.NewKubernetesClientset()
if err != nil {
t.Fatal(err)
}
ns := &v1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: name,
},
}
createOpts := metav1.CreateOptions{}
ns, err = k8sClient.CoreV1().Namespaces().Create(context.Background(), ns, createOpts)
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() {
deleteOpts := metav1.DeleteOptions{}
_ = k8sClient.CoreV1().Namespaces().Delete(context.Background(), name, deleteOpts)
})
return name
}
func awaitBuildCompletion(t *testing.T, name string) <-chan struct{} {
defaultNS, err := k8s.GetNamespace("")
if err != nil {
t.Fatal(err)
}
clis, err := tekton.NewTektonClients()
if err != nil {
t.Fatal(err)
}
listOpts := metav1.ListOptions{
LabelSelector: "tekton.dev/pipelineTask=build",
Watch: true,
}
w, err := clis.Tekton.TektonV1().TaskRuns(defaultNS).Watch(context.Background(), listOpts)
if err != nil {
t.Fatal(err)
}
ch := make(chan struct{}, 1)
go func() {
defer w.Stop()
for event := range w.ResultChan() {
taskRun, ok := event.Object.(*pipelinev1.TaskRun)
if !ok {
continue
}
if !strings.HasPrefix(taskRun.Name, name) {
continue
}
for _, condition := range taskRun.Status.Conditions {
if condition.Type == apis.ConditionSucceeded && condition.IsTrue() {
ch <- struct{}{}
break
}
}
}
}()
return ch
}
func p[T any](t T) *T {
return &t
}

View File

@ -5,7 +5,6 @@ import (
"fmt"
"strings"
"github.com/AlecAivazis/survey/v2"
"github.com/google/go-containerregistry/pkg/authn"
"github.com/google/go-containerregistry/pkg/name"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
@ -13,7 +12,6 @@ import (
"knative.dev/func/pkg/docker"
fn "knative.dev/func/pkg/functions"
"knative.dev/func/pkg/git"
"knative.dev/func/pkg/git/github"
"knative.dev/func/pkg/k8s"
"knative.dev/func/pkg/pipelines"
"knative.dev/func/pkg/pipelines/tekton/pac"
@ -189,10 +187,6 @@ func (pp *PipelinesProvider) createClusterResources(ctx context.Context, f fn.Fu
// set up a webhook with secrets, access tokens and it tries to detec PAC installation
// together with PAC controller route url - needed for webhook payload trigger
func (pp *PipelinesProvider) createRemoteResources(ctx context.Context, f fn.Function, metadata pipelines.PacMetadata) error {
repoOwner, repoName, err := git.RepoOwnerAndNameFromUrl(f.Build.Git.URL)
if err != nil {
return err
}
// figure out pac installation namespace
installed, installationNS, err := pac.DetectPACInstallation(ctx, "")
@ -220,21 +214,19 @@ func (pp *PipelinesProvider) createRemoteResources(ctx context.Context, f fn.Fun
// we haven't been able to detect PAC controller public route, let's prompt:
if controllerURL == "" {
if err := survey.AskOne(&survey.Input{
Message: "Please enter your Pipelines As Code controller public route URL: ",
}, &controllerURL, survey.WithValidator(survey.Required)); err != nil {
if controllerURL, err = pp.getPacURL(); err != nil {
return err
}
}
if err := github.CreateGitHubWebhook(ctx, repoOwner, repoName, controllerURL, metadata.WebhookSecret, metadata.PersonalAccessToken); err != nil {
if err := git.CreateWebHook(ctx, f.Build.Git.URL, controllerURL, metadata.WebhookSecret, metadata.PersonalAccessToken); err != nil {
// Error: POST https://api.github.com/repos/foobar/test-function/hooks: 422 Validation Failed [{Resource:Hook Field: Code:custom Message:Hook already exists on this repository}]
if !strings.Contains(err.Error(), "Hook already exists") {
return err
}
fmt.Printf(" ✅ Webhook already exists on repository %v/%v\n", repoOwner, repoName)
fmt.Printf(" ✅ Webhook already exists on repository %v\n", f.Build.Git.URL)
} else {
fmt.Printf(" ✅ Webhook is created on repository %v/%v\n", repoOwner, repoName)
fmt.Printf(" ✅ Webhook is created on repository %v\n", f.Build.Git.URL)
}
return nil

View File

@ -15,6 +15,7 @@ import (
"k8s.io/apimachinery/pkg/api/resource"
"github.com/AlecAivazis/survey/v2"
"github.com/google/go-containerregistry/pkg/authn"
"github.com/google/go-containerregistry/pkg/name"
gitignore "github.com/sabhiram/go-gitignore"
@ -44,12 +45,15 @@ type PipelineDecorator interface {
type Opt func(*PipelinesProvider)
type pacURLCallback = func() (string, error)
type PipelinesProvider struct {
// namespace with which to override that set on the default configuration (such as the ~/.kube/config).
// If left blank, pipeline creation/run will commence to the configured namespace.
namespace string
verbose bool
progressListener fn.ProgressListener
getPacURL pacURLCallback
credentialsProvider docker.CredentialsProvider
decorator PipelineDecorator
}
@ -84,8 +88,22 @@ func WithPipelineDecorator(decorator PipelineDecorator) Opt {
}
}
func WithPacURLCallback(getPacURL pacURLCallback) Opt {
return func(pp *PipelinesProvider) {
pp.getPacURL = getPacURL
}
}
func NewPipelinesProvider(opts ...Opt) *PipelinesProvider {
pp := &PipelinesProvider{}
pp := &PipelinesProvider{
getPacURL: func() (string, error) {
var url string
e := survey.AskOne(&survey.Input{
Message: "Please enter your Pipelines As Code controller public route URL: ",
}, &url, survey.WithValidator(survey.Required))
return url, e
},
}
for _, opt := range opts {
opt(pp)

View File

@ -0,0 +1,363 @@
Mozilla Public License, version 2.0
1. Definitions
1.1. "Contributor"
means each individual or legal entity that creates, contributes to the
creation of, or owns Covered Software.
1.2. "Contributor Version"
means the combination of the Contributions of others (if any) used by a
Contributor and that particular Contributor's Contribution.
1.3. "Contribution"
means Covered Software of a particular Contributor.
1.4. "Covered Software"
means Source Code Form to which the initial Contributor has attached the
notice in Exhibit A, the Executable Form of such Source Code Form, and
Modifications of such Source Code Form, in each case including portions
thereof.
1.5. "Incompatible With Secondary Licenses"
means
a. that the initial Contributor has attached the notice described in
Exhibit B to the Covered Software; or
b. that the Covered Software was made available under the terms of
version 1.1 or earlier of the License, but not also under the terms of
a Secondary License.
1.6. "Executable Form"
means any form of the work other than Source Code Form.
1.7. "Larger Work"
means a work that combines Covered Software with other material, in a
separate file or files, that is not Covered Software.
1.8. "License"
means this document.
1.9. "Licensable"
means having the right to grant, to the maximum extent possible, whether
at the time of the initial grant or subsequently, any and all of the
rights conveyed by this License.
1.10. "Modifications"
means any of the following:
a. any file in Source Code Form that results from an addition to,
deletion from, or modification of the contents of Covered Software; or
b. any new file in Source Code Form that contains any Covered Software.
1.11. "Patent Claims" of a Contributor
means any patent claim(s), including without limitation, method,
process, and apparatus claims, in any patent Licensable by such
Contributor that would be infringed, but for the grant of the License,
by the making, using, selling, offering for sale, having made, import,
or transfer of either its Contributions or its Contributor Version.
1.12. "Secondary License"
means either the GNU General Public License, Version 2.0, the GNU Lesser
General Public License, Version 2.1, the GNU Affero General Public
License, Version 3.0, or any later versions of those licenses.
1.13. "Source Code Form"
means the form of the work preferred for making modifications.
1.14. "You" (or "Your")
means an individual or a legal entity exercising rights under this
License. For legal entities, "You" includes any entity that controls, is
controlled by, or is under common control with You. For purposes of this
definition, "control" means (a) the power, direct or indirect, to cause
the direction or management of such entity, whether by contract or
otherwise, or (b) ownership of more than fifty percent (50%) of the
outstanding shares or beneficial ownership of such entity.
2. License Grants and Conditions
2.1. Grants
Each Contributor hereby grants You a world-wide, royalty-free,
non-exclusive license:
a. under intellectual property rights (other than patent or trademark)
Licensable by such Contributor to use, reproduce, make available,
modify, display, perform, distribute, and otherwise exploit its
Contributions, either on an unmodified basis, with Modifications, or
as part of a Larger Work; and
b. under Patent Claims of such Contributor to make, use, sell, offer for
sale, have made, import, and otherwise transfer either its
Contributions or its Contributor Version.
2.2. Effective Date
The licenses granted in Section 2.1 with respect to any Contribution
become effective for each Contribution on the date the Contributor first
distributes such Contribution.
2.3. Limitations on Grant Scope
The licenses granted in this Section 2 are the only rights granted under
this License. No additional rights or licenses will be implied from the
distribution or licensing of Covered Software under this License.
Notwithstanding Section 2.1(b) above, no patent license is granted by a
Contributor:
a. for any code that a Contributor has removed from Covered Software; or
b. for infringements caused by: (i) Your and any other third party's
modifications of Covered Software, or (ii) the combination of its
Contributions with other software (except as part of its Contributor
Version); or
c. under Patent Claims infringed by Covered Software in the absence of
its Contributions.
This License does not grant any rights in the trademarks, service marks,
or logos of any Contributor (except as may be necessary to comply with
the notice requirements in Section 3.4).
2.4. Subsequent Licenses
No Contributor makes additional grants as a result of Your choice to
distribute the Covered Software under a subsequent version of this
License (see Section 10.2) or under the terms of a Secondary License (if
permitted under the terms of Section 3.3).
2.5. Representation
Each Contributor represents that the Contributor believes its
Contributions are its original creation(s) or it has sufficient rights to
grant the rights to its Contributions conveyed by this License.
2.6. Fair Use
This License is not intended to limit any rights You have under
applicable copyright doctrines of fair use, fair dealing, or other
equivalents.
2.7. Conditions
Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in
Section 2.1.
3. Responsibilities
3.1. Distribution of Source Form
All distribution of Covered Software in Source Code Form, including any
Modifications that You create or to which You contribute, must be under
the terms of this License. You must inform recipients that the Source
Code Form of the Covered Software is governed by the terms of this
License, and how they can obtain a copy of this License. You may not
attempt to alter or restrict the recipients' rights in the Source Code
Form.
3.2. Distribution of Executable Form
If You distribute Covered Software in Executable Form then:
a. such Covered Software must also be made available in Source Code Form,
as described in Section 3.1, and You must inform recipients of the
Executable Form how they can obtain a copy of such Source Code Form by
reasonable means in a timely manner, at a charge no more than the cost
of distribution to the recipient; and
b. You may distribute such Executable Form under the terms of this
License, or sublicense it under different terms, provided that the
license for the Executable Form does not attempt to limit or alter the
recipients' rights in the Source Code Form under this License.
3.3. Distribution of a Larger Work
You may create and distribute a Larger Work under terms of Your choice,
provided that You also comply with the requirements of this License for
the Covered Software. If the Larger Work is a combination of Covered
Software with a work governed by one or more Secondary Licenses, and the
Covered Software is not Incompatible With Secondary Licenses, this
License permits You to additionally distribute such Covered Software
under the terms of such Secondary License(s), so that the recipient of
the Larger Work may, at their option, further distribute the Covered
Software under the terms of either this License or such Secondary
License(s).
3.4. Notices
You may not remove or alter the substance of any license notices
(including copyright notices, patent notices, disclaimers of warranty, or
limitations of liability) contained within the Source Code Form of the
Covered Software, except that You may alter any license notices to the
extent required to remedy known factual inaccuracies.
3.5. Application of Additional Terms
You may choose to offer, and to charge a fee for, warranty, support,
indemnity or liability obligations to one or more recipients of Covered
Software. However, You may do so only on Your own behalf, and not on
behalf of any Contributor. You must make it absolutely clear that any
such warranty, support, indemnity, or liability obligation is offered by
You alone, and You hereby agree to indemnify every Contributor for any
liability incurred by such Contributor as a result of warranty, support,
indemnity or liability terms You offer. You may include additional
disclaimers of warranty and limitations of liability specific to any
jurisdiction.
4. Inability to Comply Due to Statute or Regulation
If it is impossible for You to comply with any of the terms of this License
with respect to some or all of the Covered Software due to statute,
judicial order, or regulation then You must: (a) comply with the terms of
this License to the maximum extent possible; and (b) describe the
limitations and the code they affect. Such description must be placed in a
text file included with all distributions of the Covered Software under
this License. Except to the extent prohibited by statute or regulation,
such description must be sufficiently detailed for a recipient of ordinary
skill to be able to understand it.
5. Termination
5.1. The rights granted under this License will terminate automatically if You
fail to comply with any of its terms. However, if You become compliant,
then the rights granted under this License from a particular Contributor
are reinstated (a) provisionally, unless and until such Contributor
explicitly and finally terminates Your grants, and (b) on an ongoing
basis, if such Contributor fails to notify You of the non-compliance by
some reasonable means prior to 60 days after You have come back into
compliance. Moreover, Your grants from a particular Contributor are
reinstated on an ongoing basis if such Contributor notifies You of the
non-compliance by some reasonable means, this is the first time You have
received notice of non-compliance with this License from such
Contributor, and You become compliant prior to 30 days after Your receipt
of the notice.
5.2. If You initiate litigation against any entity by asserting a patent
infringement claim (excluding declaratory judgment actions,
counter-claims, and cross-claims) alleging that a Contributor Version
directly or indirectly infringes any patent, then the rights granted to
You by any and all Contributors for the Covered Software under Section
2.1 of this License shall terminate.
5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user
license agreements (excluding distributors and resellers) which have been
validly granted by You or Your distributors under this License prior to
termination shall survive termination.
6. Disclaimer of Warranty
Covered Software is provided under this License on an "as is" basis,
without warranty of any kind, either expressed, implied, or statutory,
including, without limitation, warranties that the Covered Software is free
of defects, merchantable, fit for a particular purpose or non-infringing.
The entire risk as to the quality and performance of the Covered Software
is with You. Should any Covered Software prove defective in any respect,
You (not any Contributor) assume the cost of any necessary servicing,
repair, or correction. This disclaimer of warranty constitutes an essential
part of this License. No use of any Covered Software is authorized under
this License except under this disclaimer.
7. Limitation of Liability
Under no circumstances and under no legal theory, whether tort (including
negligence), contract, or otherwise, shall any Contributor, or anyone who
distributes Covered Software as permitted above, be liable to You for any
direct, indirect, special, incidental, or consequential damages of any
character including, without limitation, damages for lost profits, loss of
goodwill, work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses, even if such party shall have been
informed of the possibility of such damages. This limitation of liability
shall not apply to liability for death or personal injury resulting from
such party's negligence to the extent applicable law prohibits such
limitation. Some jurisdictions do not allow the exclusion or limitation of
incidental or consequential damages, so this exclusion and limitation may
not apply to You.
8. Litigation
Any litigation relating to this License may be brought only in the courts
of a jurisdiction where the defendant maintains its principal place of
business and such litigation shall be governed by laws of that
jurisdiction, without reference to its conflict-of-law provisions. Nothing
in this Section shall prevent a party's ability to bring cross-claims or
counter-claims.
9. Miscellaneous
This License represents the complete agreement concerning the subject
matter hereof. If any provision of this License is held to be
unenforceable, such provision shall be reformed only to the extent
necessary to make it enforceable. Any law or regulation which provides that
the language of a contract shall be construed against the drafter shall not
be used to construe this License against a Contributor.
10. Versions of the License
10.1. New Versions
Mozilla Foundation is the license steward. Except as provided in Section
10.3, no one other than the license steward has the right to modify or
publish new versions of this License. Each version will be given a
distinguishing version number.
10.2. Effect of New Versions
You may distribute the Covered Software under the terms of the version
of the License under which You originally received the Covered Software,
or under the terms of any subsequent version published by the license
steward.
10.3. Modified Versions
If you create software not governed by this License, and you want to
create a new license for such software, you may create and use a
modified version of this License if you rename the license and remove
any references to the name of the license steward (except to note that
such modified license differs from this License).
10.4. Distributing Source Code Form that is Incompatible With Secondary
Licenses If You choose to distribute Source Code Form that is
Incompatible With Secondary Licenses under the terms of this version of
the License, the notice described in Exhibit B of this License must be
attached.
Exhibit A - Source Code Form License Notice
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
If it is not possible or desirable to put the notice in a particular file,
then You may include the notice in a location (such as a LICENSE file in a
relevant directory) where a recipient would be likely to look for such a
notice.
You may add additional accurate notices of copyright ownership.
Exhibit B - "Incompatible With Secondary Licenses" Notice
This Source Code Form is "Incompatible
With Secondary Licenses", as defined by
the Mozilla Public License, v. 2.0.

View File

@ -0,0 +1,30 @@
# cleanhttp
Functions for accessing "clean" Go http.Client values
-------------
The Go standard library contains a default `http.Client` called
`http.DefaultClient`. It is a common idiom in Go code to start with
`http.DefaultClient` and tweak it as necessary, and in fact, this is
encouraged; from the `http` package documentation:
> The Client's Transport typically has internal state (cached TCP connections),
so Clients should be reused instead of created as needed. Clients are safe for
concurrent use by multiple goroutines.
Unfortunately, this is a shared value, and it is not uncommon for libraries to
assume that they are free to modify it at will. With enough dependencies, it
can be very easy to encounter strange problems and race conditions due to
manipulation of this shared value across libraries and goroutines (clients are
safe for concurrent use, but writing values to the client struct itself is not
protected).
Making things worse is the fact that a bare `http.Client` will use a default
`http.Transport` called `http.DefaultTransport`, which is another global value
that behaves the same way. So it is not simply enough to replace
`http.DefaultClient` with `&http.Client{}`.
This repository provides some simple functions to get a "clean" `http.Client`
-- one that uses the same default values as the Go standard library, but
returns a client that does not share any state with other clients.

View File

@ -0,0 +1,58 @@
package cleanhttp
import (
"net"
"net/http"
"runtime"
"time"
)
// DefaultTransport returns a new http.Transport with similar default values to
// http.DefaultTransport, but with idle connections and keepalives disabled.
func DefaultTransport() *http.Transport {
transport := DefaultPooledTransport()
transport.DisableKeepAlives = true
transport.MaxIdleConnsPerHost = -1
return transport
}
// DefaultPooledTransport returns a new http.Transport with similar default
// values to http.DefaultTransport. Do not use this for transient transports as
// it can leak file descriptors over time. Only use this for transports that
// will be re-used for the same host(s).
func DefaultPooledTransport() *http.Transport {
transport := &http.Transport{
Proxy: http.ProxyFromEnvironment,
DialContext: (&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
DualStack: true,
}).DialContext,
MaxIdleConns: 100,
IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
ForceAttemptHTTP2: true,
MaxIdleConnsPerHost: runtime.GOMAXPROCS(0) + 1,
}
return transport
}
// DefaultClient returns a new http.Client with similar default values to
// http.Client, but with a non-shared Transport, idle connections disabled, and
// keepalives disabled.
func DefaultClient() *http.Client {
return &http.Client{
Transport: DefaultTransport(),
}
}
// DefaultPooledClient returns a new http.Client with similar default values to
// http.Client, but with a shared Transport. Do not use this function for
// transient clients as it can leak file descriptors over time. Only use this
// for clients that will be re-used for the same host(s).
func DefaultPooledClient() *http.Client {
return &http.Client{
Transport: DefaultPooledTransport(),
}
}

View File

@ -0,0 +1,20 @@
// Package cleanhttp offers convenience utilities for acquiring "clean"
// http.Transport and http.Client structs.
//
// Values set on http.DefaultClient and http.DefaultTransport affect all
// callers. This can have detrimental effects, esepcially in TLS contexts,
// where client or root certificates set to talk to multiple endpoints can end
// up displacing each other, leading to hard-to-debug issues. This package
// provides non-shared http.Client and http.Transport structs to ensure that
// the configuration will not be overwritten by other parts of the application
// or dependencies.
//
// The DefaultClient and DefaultTransport functions disable idle connections
// and keepalives. Without ensuring that idle connections are closed before
// garbage collection, short-term clients/transports can leak file descriptors,
// eventually leading to "too many open files" errors. If you will be
// connecting to the same hosts repeatedly from the same client, you can use
// DefaultPooledClient to receive a client that has connection pooling
// semantics similar to http.DefaultClient.
//
package cleanhttp

View File

@ -0,0 +1,48 @@
package cleanhttp
import (
"net/http"
"strings"
"unicode"
)
// HandlerInput provides input options to cleanhttp's handlers
type HandlerInput struct {
ErrStatus int
}
// PrintablePathCheckHandler is a middleware that ensures the request path
// contains only printable runes.
func PrintablePathCheckHandler(next http.Handler, input *HandlerInput) http.Handler {
// Nil-check on input to make it optional
if input == nil {
input = &HandlerInput{
ErrStatus: http.StatusBadRequest,
}
}
// Default to http.StatusBadRequest on error
if input.ErrStatus == 0 {
input.ErrStatus = http.StatusBadRequest
}
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r != nil {
// Check URL path for non-printable characters
idx := strings.IndexFunc(r.URL.Path, func(c rune) bool {
return !unicode.IsPrint(c)
})
if idx != -1 {
w.WriteHeader(input.ErrStatus)
return
}
if next != nil {
next.ServeHTTP(w, r)
}
}
return
})
}

View File

@ -0,0 +1,4 @@
.idea/
*.iml
*.test
.vscode/

View File

@ -0,0 +1,363 @@
Mozilla Public License, version 2.0
1. Definitions
1.1. "Contributor"
means each individual or legal entity that creates, contributes to the
creation of, or owns Covered Software.
1.2. "Contributor Version"
means the combination of the Contributions of others (if any) used by a
Contributor and that particular Contributor's Contribution.
1.3. "Contribution"
means Covered Software of a particular Contributor.
1.4. "Covered Software"
means Source Code Form to which the initial Contributor has attached the
notice in Exhibit A, the Executable Form of such Source Code Form, and
Modifications of such Source Code Form, in each case including portions
thereof.
1.5. "Incompatible With Secondary Licenses"
means
a. that the initial Contributor has attached the notice described in
Exhibit B to the Covered Software; or
b. that the Covered Software was made available under the terms of
version 1.1 or earlier of the License, but not also under the terms of
a Secondary License.
1.6. "Executable Form"
means any form of the work other than Source Code Form.
1.7. "Larger Work"
means a work that combines Covered Software with other material, in a
separate file or files, that is not Covered Software.
1.8. "License"
means this document.
1.9. "Licensable"
means having the right to grant, to the maximum extent possible, whether
at the time of the initial grant or subsequently, any and all of the
rights conveyed by this License.
1.10. "Modifications"
means any of the following:
a. any file in Source Code Form that results from an addition to,
deletion from, or modification of the contents of Covered Software; or
b. any new file in Source Code Form that contains any Covered Software.
1.11. "Patent Claims" of a Contributor
means any patent claim(s), including without limitation, method,
process, and apparatus claims, in any patent Licensable by such
Contributor that would be infringed, but for the grant of the License,
by the making, using, selling, offering for sale, having made, import,
or transfer of either its Contributions or its Contributor Version.
1.12. "Secondary License"
means either the GNU General Public License, Version 2.0, the GNU Lesser
General Public License, Version 2.1, the GNU Affero General Public
License, Version 3.0, or any later versions of those licenses.
1.13. "Source Code Form"
means the form of the work preferred for making modifications.
1.14. "You" (or "Your")
means an individual or a legal entity exercising rights under this
License. For legal entities, "You" includes any entity that controls, is
controlled by, or is under common control with You. For purposes of this
definition, "control" means (a) the power, direct or indirect, to cause
the direction or management of such entity, whether by contract or
otherwise, or (b) ownership of more than fifty percent (50%) of the
outstanding shares or beneficial ownership of such entity.
2. License Grants and Conditions
2.1. Grants
Each Contributor hereby grants You a world-wide, royalty-free,
non-exclusive license:
a. under intellectual property rights (other than patent or trademark)
Licensable by such Contributor to use, reproduce, make available,
modify, display, perform, distribute, and otherwise exploit its
Contributions, either on an unmodified basis, with Modifications, or
as part of a Larger Work; and
b. under Patent Claims of such Contributor to make, use, sell, offer for
sale, have made, import, and otherwise transfer either its
Contributions or its Contributor Version.
2.2. Effective Date
The licenses granted in Section 2.1 with respect to any Contribution
become effective for each Contribution on the date the Contributor first
distributes such Contribution.
2.3. Limitations on Grant Scope
The licenses granted in this Section 2 are the only rights granted under
this License. No additional rights or licenses will be implied from the
distribution or licensing of Covered Software under this License.
Notwithstanding Section 2.1(b) above, no patent license is granted by a
Contributor:
a. for any code that a Contributor has removed from Covered Software; or
b. for infringements caused by: (i) Your and any other third party's
modifications of Covered Software, or (ii) the combination of its
Contributions with other software (except as part of its Contributor
Version); or
c. under Patent Claims infringed by Covered Software in the absence of
its Contributions.
This License does not grant any rights in the trademarks, service marks,
or logos of any Contributor (except as may be necessary to comply with
the notice requirements in Section 3.4).
2.4. Subsequent Licenses
No Contributor makes additional grants as a result of Your choice to
distribute the Covered Software under a subsequent version of this
License (see Section 10.2) or under the terms of a Secondary License (if
permitted under the terms of Section 3.3).
2.5. Representation
Each Contributor represents that the Contributor believes its
Contributions are its original creation(s) or it has sufficient rights to
grant the rights to its Contributions conveyed by this License.
2.6. Fair Use
This License is not intended to limit any rights You have under
applicable copyright doctrines of fair use, fair dealing, or other
equivalents.
2.7. Conditions
Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in
Section 2.1.
3. Responsibilities
3.1. Distribution of Source Form
All distribution of Covered Software in Source Code Form, including any
Modifications that You create or to which You contribute, must be under
the terms of this License. You must inform recipients that the Source
Code Form of the Covered Software is governed by the terms of this
License, and how they can obtain a copy of this License. You may not
attempt to alter or restrict the recipients' rights in the Source Code
Form.
3.2. Distribution of Executable Form
If You distribute Covered Software in Executable Form then:
a. such Covered Software must also be made available in Source Code Form,
as described in Section 3.1, and You must inform recipients of the
Executable Form how they can obtain a copy of such Source Code Form by
reasonable means in a timely manner, at a charge no more than the cost
of distribution to the recipient; and
b. You may distribute such Executable Form under the terms of this
License, or sublicense it under different terms, provided that the
license for the Executable Form does not attempt to limit or alter the
recipients' rights in the Source Code Form under this License.
3.3. Distribution of a Larger Work
You may create and distribute a Larger Work under terms of Your choice,
provided that You also comply with the requirements of this License for
the Covered Software. If the Larger Work is a combination of Covered
Software with a work governed by one or more Secondary Licenses, and the
Covered Software is not Incompatible With Secondary Licenses, this
License permits You to additionally distribute such Covered Software
under the terms of such Secondary License(s), so that the recipient of
the Larger Work may, at their option, further distribute the Covered
Software under the terms of either this License or such Secondary
License(s).
3.4. Notices
You may not remove or alter the substance of any license notices
(including copyright notices, patent notices, disclaimers of warranty, or
limitations of liability) contained within the Source Code Form of the
Covered Software, except that You may alter any license notices to the
extent required to remedy known factual inaccuracies.
3.5. Application of Additional Terms
You may choose to offer, and to charge a fee for, warranty, support,
indemnity or liability obligations to one or more recipients of Covered
Software. However, You may do so only on Your own behalf, and not on
behalf of any Contributor. You must make it absolutely clear that any
such warranty, support, indemnity, or liability obligation is offered by
You alone, and You hereby agree to indemnify every Contributor for any
liability incurred by such Contributor as a result of warranty, support,
indemnity or liability terms You offer. You may include additional
disclaimers of warranty and limitations of liability specific to any
jurisdiction.
4. Inability to Comply Due to Statute or Regulation
If it is impossible for You to comply with any of the terms of this License
with respect to some or all of the Covered Software due to statute,
judicial order, or regulation then You must: (a) comply with the terms of
this License to the maximum extent possible; and (b) describe the
limitations and the code they affect. Such description must be placed in a
text file included with all distributions of the Covered Software under
this License. Except to the extent prohibited by statute or regulation,
such description must be sufficiently detailed for a recipient of ordinary
skill to be able to understand it.
5. Termination
5.1. The rights granted under this License will terminate automatically if You
fail to comply with any of its terms. However, if You become compliant,
then the rights granted under this License from a particular Contributor
are reinstated (a) provisionally, unless and until such Contributor
explicitly and finally terminates Your grants, and (b) on an ongoing
basis, if such Contributor fails to notify You of the non-compliance by
some reasonable means prior to 60 days after You have come back into
compliance. Moreover, Your grants from a particular Contributor are
reinstated on an ongoing basis if such Contributor notifies You of the
non-compliance by some reasonable means, this is the first time You have
received notice of non-compliance with this License from such
Contributor, and You become compliant prior to 30 days after Your receipt
of the notice.
5.2. If You initiate litigation against any entity by asserting a patent
infringement claim (excluding declaratory judgment actions,
counter-claims, and cross-claims) alleging that a Contributor Version
directly or indirectly infringes any patent, then the rights granted to
You by any and all Contributors for the Covered Software under Section
2.1 of this License shall terminate.
5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user
license agreements (excluding distributors and resellers) which have been
validly granted by You or Your distributors under this License prior to
termination shall survive termination.
6. Disclaimer of Warranty
Covered Software is provided under this License on an "as is" basis,
without warranty of any kind, either expressed, implied, or statutory,
including, without limitation, warranties that the Covered Software is free
of defects, merchantable, fit for a particular purpose or non-infringing.
The entire risk as to the quality and performance of the Covered Software
is with You. Should any Covered Software prove defective in any respect,
You (not any Contributor) assume the cost of any necessary servicing,
repair, or correction. This disclaimer of warranty constitutes an essential
part of this License. No use of any Covered Software is authorized under
this License except under this disclaimer.
7. Limitation of Liability
Under no circumstances and under no legal theory, whether tort (including
negligence), contract, or otherwise, shall any Contributor, or anyone who
distributes Covered Software as permitted above, be liable to You for any
direct, indirect, special, incidental, or consequential damages of any
character including, without limitation, damages for lost profits, loss of
goodwill, work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses, even if such party shall have been
informed of the possibility of such damages. This limitation of liability
shall not apply to liability for death or personal injury resulting from
such party's negligence to the extent applicable law prohibits such
limitation. Some jurisdictions do not allow the exclusion or limitation of
incidental or consequential damages, so this exclusion and limitation may
not apply to You.
8. Litigation
Any litigation relating to this License may be brought only in the courts
of a jurisdiction where the defendant maintains its principal place of
business and such litigation shall be governed by laws of that
jurisdiction, without reference to its conflict-of-law provisions. Nothing
in this Section shall prevent a party's ability to bring cross-claims or
counter-claims.
9. Miscellaneous
This License represents the complete agreement concerning the subject
matter hereof. If any provision of this License is held to be
unenforceable, such provision shall be reformed only to the extent
necessary to make it enforceable. Any law or regulation which provides that
the language of a contract shall be construed against the drafter shall not
be used to construe this License against a Contributor.
10. Versions of the License
10.1. New Versions
Mozilla Foundation is the license steward. Except as provided in Section
10.3, no one other than the license steward has the right to modify or
publish new versions of this License. Each version will be given a
distinguishing version number.
10.2. Effect of New Versions
You may distribute the Covered Software under the terms of the version
of the License under which You originally received the Covered Software,
or under the terms of any subsequent version published by the license
steward.
10.3. Modified Versions
If you create software not governed by this License, and you want to
create a new license for such software, you may create and use a
modified version of this License if you rename the license and remove
any references to the name of the license steward (except to note that
such modified license differs from this License).
10.4. Distributing Source Code Form that is Incompatible With Secondary
Licenses If You choose to distribute Source Code Form that is
Incompatible With Secondary Licenses under the terms of this version of
the License, the notice described in Exhibit B of this License must be
attached.
Exhibit A - Source Code Form License Notice
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
If it is not possible or desirable to put the notice in a particular file,
then You may include the notice in a location (such as a LICENSE file in a
relevant directory) where a recipient would be likely to look for such a
notice.
You may add additional accurate notices of copyright ownership.
Exhibit B - "Incompatible With Secondary Licenses" Notice
This Source Code Form is "Incompatible
With Secondary Licenses", as defined by
the Mozilla Public License, v. 2.0.

View File

@ -0,0 +1,11 @@
default: test
test:
go vet ./...
go test -race ./...
updatedeps:
go get -f -t -u ./...
go get -f -u ./...
.PHONY: default test updatedeps

View File

@ -0,0 +1,62 @@
go-retryablehttp
================
[![Build Status](http://img.shields.io/travis/hashicorp/go-retryablehttp.svg?style=flat-square)][travis]
[![Go Documentation](http://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)][godocs]
[travis]: http://travis-ci.org/hashicorp/go-retryablehttp
[godocs]: http://godoc.org/github.com/hashicorp/go-retryablehttp
The `retryablehttp` package provides a familiar HTTP client interface with
automatic retries and exponential backoff. It is a thin wrapper over the
standard `net/http` client library and exposes nearly the same public API. This
makes `retryablehttp` very easy to drop into existing programs.
`retryablehttp` performs automatic retries under certain conditions. Mainly, if
an error is returned by the client (connection errors, etc.), or if a 500-range
response code is received (except 501), then a retry is invoked after a wait
period. Otherwise, the response is returned and left to the caller to
interpret.
The main difference from `net/http` is that requests which take a request body
(POST/PUT et. al) can have the body provided in a number of ways (some more or
less efficient) that allow "rewinding" the request body if the initial request
fails so that the full request can be attempted again. See the
[godoc](http://godoc.org/github.com/hashicorp/go-retryablehttp) for more
details.
Version 0.6.0 and before are compatible with Go prior to 1.12. From 0.6.1 onward, Go 1.12+ is required.
From 0.6.7 onward, Go 1.13+ is required.
Example Use
===========
Using this library should look almost identical to what you would do with
`net/http`. The most simple example of a GET request is shown below:
```go
resp, err := retryablehttp.Get("/foo")
if err != nil {
panic(err)
}
```
The returned response object is an `*http.Response`, the same thing you would
usually get from `net/http`. Had the request failed one or more times, the above
call would block and retry with exponential backoff.
## Getting a stdlib `*http.Client` with retries
It's possible to convert a `*retryablehttp.Client` directly to a `*http.Client`.
This makes use of retryablehttp broadly applicable with minimal effort. Simply
configure a `*retryablehttp.Client` as you wish, and then call `StandardClient()`:
```go
retryClient := retryablehttp.NewClient()
retryClient.RetryMax = 10
standardClient := retryClient.StandardClient() // *http.Client
```
For more usage and examples see the
[godoc](http://godoc.org/github.com/hashicorp/go-retryablehttp).

View File

@ -0,0 +1,822 @@
// Package retryablehttp provides a familiar HTTP client interface with
// automatic retries and exponential backoff. It is a thin wrapper over the
// standard net/http client library and exposes nearly the same public API.
// This makes retryablehttp very easy to drop into existing programs.
//
// retryablehttp performs automatic retries under certain conditions. Mainly, if
// an error is returned by the client (connection errors etc), or if a 500-range
// response is received, then a retry is invoked. Otherwise, the response is
// returned and left to the caller to interpret.
//
// Requests which take a request body should provide a non-nil function
// parameter. The best choice is to provide either a function satisfying
// ReaderFunc which provides multiple io.Readers in an efficient manner, a
// *bytes.Buffer (the underlying raw byte slice will be used) or a raw byte
// slice. As it is a reference type, and we will wrap it as needed by readers,
// we can efficiently re-use the request body without needing to copy it. If an
// io.Reader (such as a *bytes.Reader) is provided, the full body will be read
// prior to the first request, and will be efficiently re-used for any retries.
// ReadSeeker can be used, but some users have observed occasional data races
// between the net/http library and the Seek functionality of some
// implementations of ReadSeeker, so should be avoided if possible.
package retryablehttp
import (
"bytes"
"context"
"crypto/x509"
"fmt"
"io"
"io/ioutil"
"log"
"math"
"math/rand"
"net/http"
"net/url"
"os"
"regexp"
"strconv"
"strings"
"sync"
"time"
cleanhttp "github.com/hashicorp/go-cleanhttp"
)
var (
// Default retry configuration
defaultRetryWaitMin = 1 * time.Second
defaultRetryWaitMax = 30 * time.Second
defaultRetryMax = 4
// defaultLogger is the logger provided with defaultClient
defaultLogger = log.New(os.Stderr, "", log.LstdFlags)
// defaultClient is used for performing requests without explicitly making
// a new client. It is purposely private to avoid modifications.
defaultClient = NewClient()
// We need to consume response bodies to maintain http connections, but
// limit the size we consume to respReadLimit.
respReadLimit = int64(4096)
// A regular expression to match the error returned by net/http when the
// configured number of redirects is exhausted. This error isn't typed
// specifically so we resort to matching on the error string.
redirectsErrorRe = regexp.MustCompile(`stopped after \d+ redirects\z`)
// A regular expression to match the error returned by net/http when the
// scheme specified in the URL is invalid. This error isn't typed
// specifically so we resort to matching on the error string.
schemeErrorRe = regexp.MustCompile(`unsupported protocol scheme`)
// A regular expression to match the error returned by net/http when the
// TLS certificate is not trusted. This error isn't typed
// specifically so we resort to matching on the error string.
notTrustedErrorRe = regexp.MustCompile(`certificate is not trusted`)
)
// ReaderFunc is the type of function that can be given natively to NewRequest
type ReaderFunc func() (io.Reader, error)
// ResponseHandlerFunc is a type of function that takes in a Response, and does something with it.
// The ResponseHandlerFunc is called when the HTTP client successfully receives a response and the
// CheckRetry function indicates that a retry of the base request is not necessary.
// If an error is returned from this function, the CheckRetry policy will be used to determine
// whether to retry the whole request (including this handler).
//
// Make sure to check status codes! Even if the request was completed it may have a non-2xx status code.
//
// The response body is not automatically closed. It must be closed either by the ResponseHandlerFunc or
// by the caller out-of-band. Failure to do so will result in a memory leak.
type ResponseHandlerFunc func(*http.Response) error
// LenReader is an interface implemented by many in-memory io.Reader's. Used
// for automatically sending the right Content-Length header when possible.
type LenReader interface {
Len() int
}
// Request wraps the metadata needed to create HTTP requests.
type Request struct {
// body is a seekable reader over the request body payload. This is
// used to rewind the request data in between retries.
body ReaderFunc
responseHandler ResponseHandlerFunc
// Embed an HTTP request directly. This makes a *Request act exactly
// like an *http.Request so that all meta methods are supported.
*http.Request
}
// WithContext returns wrapped Request with a shallow copy of underlying *http.Request
// with its context changed to ctx. The provided ctx must be non-nil.
func (r *Request) WithContext(ctx context.Context) *Request {
return &Request{
body: r.body,
responseHandler: r.responseHandler,
Request: r.Request.WithContext(ctx),
}
}
// SetResponseHandler allows setting the response handler.
func (r *Request) SetResponseHandler(fn ResponseHandlerFunc) {
r.responseHandler = fn
}
// BodyBytes allows accessing the request body. It is an analogue to
// http.Request's Body variable, but it returns a copy of the underlying data
// rather than consuming it.
//
// This function is not thread-safe; do not call it at the same time as another
// call, or at the same time this request is being used with Client.Do.
func (r *Request) BodyBytes() ([]byte, error) {
if r.body == nil {
return nil, nil
}
body, err := r.body()
if err != nil {
return nil, err
}
buf := new(bytes.Buffer)
_, err = buf.ReadFrom(body)
if err != nil {
return nil, err
}
return buf.Bytes(), nil
}
// SetBody allows setting the request body.
//
// It is useful if a new body needs to be set without constructing a new Request.
func (r *Request) SetBody(rawBody interface{}) error {
bodyReader, contentLength, err := getBodyReaderAndContentLength(rawBody)
if err != nil {
return err
}
r.body = bodyReader
r.ContentLength = contentLength
return nil
}
// WriteTo allows copying the request body into a writer.
//
// It writes data to w until there's no more data to write or
// when an error occurs. The return int64 value is the number of bytes
// written. Any error encountered during the write is also returned.
// The signature matches io.WriterTo interface.
func (r *Request) WriteTo(w io.Writer) (int64, error) {
body, err := r.body()
if err != nil {
return 0, err
}
if c, ok := body.(io.Closer); ok {
defer c.Close()
}
return io.Copy(w, body)
}
func getBodyReaderAndContentLength(rawBody interface{}) (ReaderFunc, int64, error) {
var bodyReader ReaderFunc
var contentLength int64
switch body := rawBody.(type) {
// If they gave us a function already, great! Use it.
case ReaderFunc:
bodyReader = body
tmp, err := body()
if err != nil {
return nil, 0, err
}
if lr, ok := tmp.(LenReader); ok {
contentLength = int64(lr.Len())
}
if c, ok := tmp.(io.Closer); ok {
c.Close()
}
case func() (io.Reader, error):
bodyReader = body
tmp, err := body()
if err != nil {
return nil, 0, err
}
if lr, ok := tmp.(LenReader); ok {
contentLength = int64(lr.Len())
}
if c, ok := tmp.(io.Closer); ok {
c.Close()
}
// If a regular byte slice, we can read it over and over via new
// readers
case []byte:
buf := body
bodyReader = func() (io.Reader, error) {
return bytes.NewReader(buf), nil
}
contentLength = int64(len(buf))
// If a bytes.Buffer we can read the underlying byte slice over and
// over
case *bytes.Buffer:
buf := body
bodyReader = func() (io.Reader, error) {
return bytes.NewReader(buf.Bytes()), nil
}
contentLength = int64(buf.Len())
// We prioritize *bytes.Reader here because we don't really want to
// deal with it seeking so want it to match here instead of the
// io.ReadSeeker case.
case *bytes.Reader:
buf, err := ioutil.ReadAll(body)
if err != nil {
return nil, 0, err
}
bodyReader = func() (io.Reader, error) {
return bytes.NewReader(buf), nil
}
contentLength = int64(len(buf))
// Compat case
case io.ReadSeeker:
raw := body
bodyReader = func() (io.Reader, error) {
_, err := raw.Seek(0, 0)
return ioutil.NopCloser(raw), err
}
if lr, ok := raw.(LenReader); ok {
contentLength = int64(lr.Len())
}
// Read all in so we can reset
case io.Reader:
buf, err := ioutil.ReadAll(body)
if err != nil {
return nil, 0, err
}
bodyReader = func() (io.Reader, error) {
return bytes.NewReader(buf), nil
}
contentLength = int64(len(buf))
// No body provided, nothing to do
case nil:
// Unrecognized type
default:
return nil, 0, fmt.Errorf("cannot handle type %T", rawBody)
}
return bodyReader, contentLength, nil
}
// FromRequest wraps an http.Request in a retryablehttp.Request
func FromRequest(r *http.Request) (*Request, error) {
bodyReader, _, err := getBodyReaderAndContentLength(r.Body)
if err != nil {
return nil, err
}
// Could assert contentLength == r.ContentLength
return &Request{body: bodyReader, Request: r}, nil
}
// NewRequest creates a new wrapped request.
func NewRequest(method, url string, rawBody interface{}) (*Request, error) {
return NewRequestWithContext(context.Background(), method, url, rawBody)
}
// NewRequestWithContext creates a new wrapped request with the provided context.
//
// The context controls the entire lifetime of a request and its response:
// obtaining a connection, sending the request, and reading the response headers and body.
func NewRequestWithContext(ctx context.Context, method, url string, rawBody interface{}) (*Request, error) {
bodyReader, contentLength, err := getBodyReaderAndContentLength(rawBody)
if err != nil {
return nil, err
}
httpReq, err := http.NewRequestWithContext(ctx, method, url, nil)
if err != nil {
return nil, err
}
httpReq.ContentLength = contentLength
return &Request{body: bodyReader, Request: httpReq}, nil
}
// Logger interface allows to use other loggers than
// standard log.Logger.
type Logger interface {
Printf(string, ...interface{})
}
// LeveledLogger is an interface that can be implemented by any logger or a
// logger wrapper to provide leveled logging. The methods accept a message
// string and a variadic number of key-value pairs. For log.Printf style
// formatting where message string contains a format specifier, use Logger
// interface.
type LeveledLogger interface {
Error(msg string, keysAndValues ...interface{})
Info(msg string, keysAndValues ...interface{})
Debug(msg string, keysAndValues ...interface{})
Warn(msg string, keysAndValues ...interface{})
}
// hookLogger adapts an LeveledLogger to Logger for use by the existing hook functions
// without changing the API.
type hookLogger struct {
LeveledLogger
}
func (h hookLogger) Printf(s string, args ...interface{}) {
h.Info(fmt.Sprintf(s, args...))
}
// RequestLogHook allows a function to run before each retry. The HTTP
// request which will be made, and the retry number (0 for the initial
// request) are available to users. The internal logger is exposed to
// consumers.
type RequestLogHook func(Logger, *http.Request, int)
// ResponseLogHook is like RequestLogHook, but allows running a function
// on each HTTP response. This function will be invoked at the end of
// every HTTP request executed, regardless of whether a subsequent retry
// needs to be performed or not. If the response body is read or closed
// from this method, this will affect the response returned from Do().
type ResponseLogHook func(Logger, *http.Response)
// CheckRetry specifies a policy for handling retries. It is called
// following each request with the response and error values returned by
// the http.Client. If CheckRetry returns false, the Client stops retrying
// and returns the response to the caller. If CheckRetry returns an error,
// that error value is returned in lieu of the error from the request. The
// Client will close any response body when retrying, but if the retry is
// aborted it is up to the CheckRetry callback to properly close any
// response body before returning.
type CheckRetry func(ctx context.Context, resp *http.Response, err error) (bool, error)
// Backoff specifies a policy for how long to wait between retries.
// It is called after a failing request to determine the amount of time
// that should pass before trying again.
type Backoff func(min, max time.Duration, attemptNum int, resp *http.Response) time.Duration
// ErrorHandler is called if retries are expired, containing the last status
// from the http library. If not specified, default behavior for the library is
// to close the body and return an error indicating how many tries were
// attempted. If overriding this, be sure to close the body if needed.
type ErrorHandler func(resp *http.Response, err error, numTries int) (*http.Response, error)
// Client is used to make HTTP requests. It adds additional functionality
// like automatic retries to tolerate minor outages.
type Client struct {
HTTPClient *http.Client // Internal HTTP client.
Logger interface{} // Customer logger instance. Can be either Logger or LeveledLogger
RetryWaitMin time.Duration // Minimum time to wait
RetryWaitMax time.Duration // Maximum time to wait
RetryMax int // Maximum number of retries
// RequestLogHook allows a user-supplied function to be called
// before each retry.
RequestLogHook RequestLogHook
// ResponseLogHook allows a user-supplied function to be called
// with the response from each HTTP request executed.
ResponseLogHook ResponseLogHook
// CheckRetry specifies the policy for handling retries, and is called
// after each request. The default policy is DefaultRetryPolicy.
CheckRetry CheckRetry
// Backoff specifies the policy for how long to wait between retries
Backoff Backoff
// ErrorHandler specifies the custom error handler to use, if any
ErrorHandler ErrorHandler
loggerInit sync.Once
clientInit sync.Once
}
// NewClient creates a new Client with default settings.
func NewClient() *Client {
return &Client{
HTTPClient: cleanhttp.DefaultPooledClient(),
Logger: defaultLogger,
RetryWaitMin: defaultRetryWaitMin,
RetryWaitMax: defaultRetryWaitMax,
RetryMax: defaultRetryMax,
CheckRetry: DefaultRetryPolicy,
Backoff: DefaultBackoff,
}
}
func (c *Client) logger() interface{} {
c.loggerInit.Do(func() {
if c.Logger == nil {
return
}
switch c.Logger.(type) {
case Logger, LeveledLogger:
// ok
default:
// This should happen in dev when they are setting Logger and work on code, not in prod.
panic(fmt.Sprintf("invalid logger type passed, must be Logger or LeveledLogger, was %T", c.Logger))
}
})
return c.Logger
}
// DefaultRetryPolicy provides a default callback for Client.CheckRetry, which
// will retry on connection errors and server errors.
func DefaultRetryPolicy(ctx context.Context, resp *http.Response, err error) (bool, error) {
// do not retry on context.Canceled or context.DeadlineExceeded
if ctx.Err() != nil {
return false, ctx.Err()
}
// don't propagate other errors
shouldRetry, _ := baseRetryPolicy(resp, err)
return shouldRetry, nil
}
// ErrorPropagatedRetryPolicy is the same as DefaultRetryPolicy, except it
// propagates errors back instead of returning nil. This allows you to inspect
// why it decided to retry or not.
func ErrorPropagatedRetryPolicy(ctx context.Context, resp *http.Response, err error) (bool, error) {
// do not retry on context.Canceled or context.DeadlineExceeded
if ctx.Err() != nil {
return false, ctx.Err()
}
return baseRetryPolicy(resp, err)
}
func baseRetryPolicy(resp *http.Response, err error) (bool, error) {
if err != nil {
if v, ok := err.(*url.Error); ok {
// Don't retry if the error was due to too many redirects.
if redirectsErrorRe.MatchString(v.Error()) {
return false, v
}
// Don't retry if the error was due to an invalid protocol scheme.
if schemeErrorRe.MatchString(v.Error()) {
return false, v
}
// Don't retry if the error was due to TLS cert verification failure.
if notTrustedErrorRe.MatchString(v.Error()) {
return false, v
}
if _, ok := v.Err.(x509.UnknownAuthorityError); ok {
return false, v
}
}
// The error is likely recoverable so retry.
return true, nil
}
// 429 Too Many Requests is recoverable. Sometimes the server puts
// a Retry-After response header to indicate when the server is
// available to start processing request from client.
if resp.StatusCode == http.StatusTooManyRequests {
return true, nil
}
// Check the response code. We retry on 500-range responses to allow
// the server time to recover, as 500's are typically not permanent
// errors and may relate to outages on the server side. This will catch
// invalid response codes as well, like 0 and 999.
if resp.StatusCode == 0 || (resp.StatusCode >= 500 && resp.StatusCode != http.StatusNotImplemented) {
return true, fmt.Errorf("unexpected HTTP status %s", resp.Status)
}
return false, nil
}
// DefaultBackoff provides a default callback for Client.Backoff which
// will perform exponential backoff based on the attempt number and limited
// by the provided minimum and maximum durations.
//
// It also tries to parse Retry-After response header when a http.StatusTooManyRequests
// (HTTP Code 429) is found in the resp parameter. Hence it will return the number of
// 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 || 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)
}
}
}
}
mult := math.Pow(2, float64(attemptNum)) * float64(min)
sleep := time.Duration(mult)
if float64(sleep) != mult || sleep > max {
sleep = max
}
return sleep
}
// LinearJitterBackoff provides a callback for Client.Backoff which will
// perform linear backoff based on the attempt number and with jitter to
// prevent a thundering herd.
//
// min and max here are *not* absolute values. The number to be multiplied by
// the attempt number will be chosen at random from between them, thus they are
// bounding the jitter.
//
// For instance:
// * To get strictly linear backoff of one second increasing each retry, set
// both to one second (1s, 2s, 3s, 4s, ...)
// * To get a small amount of jitter centered around one second increasing each
// retry, set to around one second, such as a min of 800ms and max of 1200ms
// (892ms, 2102ms, 2945ms, 4312ms, ...)
// * To get extreme jitter, set to a very wide spread, such as a min of 100ms
// and a max of 20s (15382ms, 292ms, 51321ms, 35234ms, ...)
func LinearJitterBackoff(min, max time.Duration, attemptNum int, resp *http.Response) time.Duration {
// attemptNum always starts at zero but we want to start at 1 for multiplication
attemptNum++
if max <= min {
// Unclear what to do here, or they are the same, so return min *
// attemptNum
return min * time.Duration(attemptNum)
}
// Seed rand; doing this every time is fine
rand := rand.New(rand.NewSource(int64(time.Now().Nanosecond())))
// Pick a random number that lies somewhere between the min and max and
// multiply by the attemptNum. attemptNum starts at zero so we always
// increment here. We first get a random percentage, then apply that to the
// difference between min and max, and add to min.
jitter := rand.Float64() * float64(max-min)
jitterMin := int64(jitter) + int64(min)
return time.Duration(jitterMin * int64(attemptNum))
}
// PassthroughErrorHandler is an ErrorHandler that directly passes through the
// values from the net/http library for the final request. The body is not
// closed.
func PassthroughErrorHandler(resp *http.Response, err error, _ int) (*http.Response, error) {
return resp, err
}
// Do wraps calling an HTTP method with retries.
func (c *Client) Do(req *Request) (*http.Response, error) {
c.clientInit.Do(func() {
if c.HTTPClient == nil {
c.HTTPClient = cleanhttp.DefaultPooledClient()
}
})
logger := c.logger()
if logger != nil {
switch v := logger.(type) {
case LeveledLogger:
v.Debug("performing request", "method", req.Method, "url", req.URL)
case Logger:
v.Printf("[DEBUG] %s %s", req.Method, req.URL)
}
}
var resp *http.Response
var attempt int
var shouldRetry bool
var doErr, respErr, checkErr error
for i := 0; ; i++ {
doErr, respErr = nil, nil
attempt++
// Always rewind the request body when non-nil.
if req.body != nil {
body, err := req.body()
if err != nil {
c.HTTPClient.CloseIdleConnections()
return resp, err
}
if c, ok := body.(io.ReadCloser); ok {
req.Body = c
} else {
req.Body = ioutil.NopCloser(body)
}
}
if c.RequestLogHook != nil {
switch v := logger.(type) {
case LeveledLogger:
c.RequestLogHook(hookLogger{v}, req.Request, i)
case Logger:
c.RequestLogHook(v, req.Request, i)
default:
c.RequestLogHook(nil, req.Request, i)
}
}
// Attempt the request
resp, doErr = c.HTTPClient.Do(req.Request)
// Check if we should continue with retries.
shouldRetry, checkErr = c.CheckRetry(req.Context(), resp, doErr)
if !shouldRetry && doErr == nil && req.responseHandler != nil {
respErr = req.responseHandler(resp)
shouldRetry, checkErr = c.CheckRetry(req.Context(), resp, respErr)
}
err := doErr
if respErr != nil {
err = respErr
}
if err != nil {
switch v := logger.(type) {
case LeveledLogger:
v.Error("request failed", "error", err, "method", req.Method, "url", req.URL)
case Logger:
v.Printf("[ERR] %s %s request failed: %v", req.Method, req.URL, err)
}
} else {
// Call this here to maintain the behavior of logging all requests,
// even if CheckRetry signals to stop.
if c.ResponseLogHook != nil {
// Call the response logger function if provided.
switch v := logger.(type) {
case LeveledLogger:
c.ResponseLogHook(hookLogger{v}, resp)
case Logger:
c.ResponseLogHook(v, resp)
default:
c.ResponseLogHook(nil, resp)
}
}
}
if !shouldRetry {
break
}
// We do this before drainBody because there's no need for the I/O if
// we're breaking out
remain := c.RetryMax - i
if remain <= 0 {
break
}
// We're going to retry, consume any response to reuse the connection.
if doErr == nil {
c.drainBody(resp.Body)
}
wait := c.Backoff(c.RetryWaitMin, c.RetryWaitMax, i, resp)
if logger != nil {
desc := fmt.Sprintf("%s %s", req.Method, req.URL)
if resp != nil {
desc = fmt.Sprintf("%s (status: %d)", desc, resp.StatusCode)
}
switch v := logger.(type) {
case LeveledLogger:
v.Debug("retrying request", "request", desc, "timeout", wait, "remaining", remain)
case Logger:
v.Printf("[DEBUG] %s: retrying in %s (%d left)", desc, wait, remain)
}
}
timer := time.NewTimer(wait)
select {
case <-req.Context().Done():
timer.Stop()
c.HTTPClient.CloseIdleConnections()
return nil, req.Context().Err()
case <-timer.C:
}
// Make shallow copy of http Request so that we can modify its body
// without racing against the closeBody call in persistConn.writeLoop.
httpreq := *req.Request
req.Request = &httpreq
}
// this is the closest we have to success criteria
if doErr == nil && respErr == nil && checkErr == nil && !shouldRetry {
return resp, nil
}
defer c.HTTPClient.CloseIdleConnections()
var err error
if checkErr != nil {
err = checkErr
} else if respErr != nil {
err = respErr
} else {
err = doErr
}
if c.ErrorHandler != nil {
return c.ErrorHandler(resp, err, attempt)
}
// By default, we close the response body and return an error without
// returning the response
if resp != nil {
c.drainBody(resp.Body)
}
// this means CheckRetry thought the request was a failure, but didn't
// communicate why
if err == nil {
return nil, fmt.Errorf("%s %s giving up after %d attempt(s)",
req.Method, req.URL, attempt)
}
return nil, fmt.Errorf("%s %s giving up after %d attempt(s): %w",
req.Method, req.URL, attempt, err)
}
// Try to read the response body so we can reuse this connection.
func (c *Client) drainBody(body io.ReadCloser) {
defer body.Close()
_, err := io.Copy(ioutil.Discard, io.LimitReader(body, respReadLimit))
if err != nil {
if c.logger() != nil {
switch v := c.logger().(type) {
case LeveledLogger:
v.Error("error reading response body", "error", err)
case Logger:
v.Printf("[ERR] error reading response body: %v", err)
}
}
}
}
// Get is a shortcut for doing a GET request without making a new client.
func Get(url string) (*http.Response, error) {
return defaultClient.Get(url)
}
// Get is a convenience helper for doing simple GET requests.
func (c *Client) Get(url string) (*http.Response, error) {
req, err := NewRequest("GET", url, nil)
if err != nil {
return nil, err
}
return c.Do(req)
}
// Head is a shortcut for doing a HEAD request without making a new client.
func Head(url string) (*http.Response, error) {
return defaultClient.Head(url)
}
// Head is a convenience method for doing simple HEAD requests.
func (c *Client) Head(url string) (*http.Response, error) {
req, err := NewRequest("HEAD", url, nil)
if err != nil {
return nil, err
}
return c.Do(req)
}
// Post is a shortcut for doing a POST request without making a new client.
func Post(url, bodyType string, body interface{}) (*http.Response, error) {
return defaultClient.Post(url, bodyType, body)
}
// Post is a convenience method for doing simple POST requests.
func (c *Client) Post(url, bodyType string, body interface{}) (*http.Response, error) {
req, err := NewRequest("POST", url, body)
if err != nil {
return nil, err
}
req.Header.Set("Content-Type", bodyType)
return c.Do(req)
}
// PostForm is a shortcut to perform a POST with form data without creating
// a new client.
func PostForm(url string, data url.Values) (*http.Response, error) {
return defaultClient.PostForm(url, data)
}
// PostForm is a convenience method for doing simple POST operations using
// pre-filled url.Values form data.
func (c *Client) PostForm(url string, data url.Values) (*http.Response, error) {
return c.Post(url, "application/x-www-form-urlencoded", strings.NewReader(data.Encode()))
}
// StandardClient returns a stdlib *http.Client with a custom Transport, which
// shims in a *retryablehttp.Client for added retries.
func (c *Client) StandardClient() *http.Client {
return &http.Client{
Transport: &RoundTripper{Client: c},
}
}

View File

@ -0,0 +1,52 @@
package retryablehttp
import (
"errors"
"net/http"
"net/url"
"sync"
)
// RoundTripper implements the http.RoundTripper interface, using a retrying
// HTTP client to execute requests.
//
// It is important to note that retryablehttp doesn't always act exactly as a
// RoundTripper should. This is highly dependent on the retryable client's
// configuration.
type RoundTripper struct {
// The client to use during requests. If nil, the default retryablehttp
// client and settings will be used.
Client *Client
// once ensures that the logic to initialize the default client runs at
// most once, in a single thread.
once sync.Once
}
// init initializes the underlying retryable client.
func (rt *RoundTripper) init() {
if rt.Client == nil {
rt.Client = NewClient()
}
}
// RoundTrip satisfies the http.RoundTripper interface.
func (rt *RoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
rt.once.Do(rt.init)
// Convert the request to be retryable.
retryableReq, err := FromRequest(req)
if err != nil {
return nil, err
}
// Execute the request.
resp, err := rt.Client.Do(retryableReq)
// If we got an error returned by standard library's `Do` method, unwrap it
// otherwise we will wind up erroneously re-nesting the error.
if _, ok := err.(*url.Error); ok {
return resp, errors.Unwrap(err)
}
return resp, err
}

View File

@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright {yyyy} {name of copyright owner}
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.

363
vendor/github.com/hashicorp/go-cleanhttp/LICENSE generated vendored Normal file
View File

@ -0,0 +1,363 @@
Mozilla Public License, version 2.0
1. Definitions
1.1. "Contributor"
means each individual or legal entity that creates, contributes to the
creation of, or owns Covered Software.
1.2. "Contributor Version"
means the combination of the Contributions of others (if any) used by a
Contributor and that particular Contributor's Contribution.
1.3. "Contribution"
means Covered Software of a particular Contributor.
1.4. "Covered Software"
means Source Code Form to which the initial Contributor has attached the
notice in Exhibit A, the Executable Form of such Source Code Form, and
Modifications of such Source Code Form, in each case including portions
thereof.
1.5. "Incompatible With Secondary Licenses"
means
a. that the initial Contributor has attached the notice described in
Exhibit B to the Covered Software; or
b. that the Covered Software was made available under the terms of
version 1.1 or earlier of the License, but not also under the terms of
a Secondary License.
1.6. "Executable Form"
means any form of the work other than Source Code Form.
1.7. "Larger Work"
means a work that combines Covered Software with other material, in a
separate file or files, that is not Covered Software.
1.8. "License"
means this document.
1.9. "Licensable"
means having the right to grant, to the maximum extent possible, whether
at the time of the initial grant or subsequently, any and all of the
rights conveyed by this License.
1.10. "Modifications"
means any of the following:
a. any file in Source Code Form that results from an addition to,
deletion from, or modification of the contents of Covered Software; or
b. any new file in Source Code Form that contains any Covered Software.
1.11. "Patent Claims" of a Contributor
means any patent claim(s), including without limitation, method,
process, and apparatus claims, in any patent Licensable by such
Contributor that would be infringed, but for the grant of the License,
by the making, using, selling, offering for sale, having made, import,
or transfer of either its Contributions or its Contributor Version.
1.12. "Secondary License"
means either the GNU General Public License, Version 2.0, the GNU Lesser
General Public License, Version 2.1, the GNU Affero General Public
License, Version 3.0, or any later versions of those licenses.
1.13. "Source Code Form"
means the form of the work preferred for making modifications.
1.14. "You" (or "Your")
means an individual or a legal entity exercising rights under this
License. For legal entities, "You" includes any entity that controls, is
controlled by, or is under common control with You. For purposes of this
definition, "control" means (a) the power, direct or indirect, to cause
the direction or management of such entity, whether by contract or
otherwise, or (b) ownership of more than fifty percent (50%) of the
outstanding shares or beneficial ownership of such entity.
2. License Grants and Conditions
2.1. Grants
Each Contributor hereby grants You a world-wide, royalty-free,
non-exclusive license:
a. under intellectual property rights (other than patent or trademark)
Licensable by such Contributor to use, reproduce, make available,
modify, display, perform, distribute, and otherwise exploit its
Contributions, either on an unmodified basis, with Modifications, or
as part of a Larger Work; and
b. under Patent Claims of such Contributor to make, use, sell, offer for
sale, have made, import, and otherwise transfer either its
Contributions or its Contributor Version.
2.2. Effective Date
The licenses granted in Section 2.1 with respect to any Contribution
become effective for each Contribution on the date the Contributor first
distributes such Contribution.
2.3. Limitations on Grant Scope
The licenses granted in this Section 2 are the only rights granted under
this License. No additional rights or licenses will be implied from the
distribution or licensing of Covered Software under this License.
Notwithstanding Section 2.1(b) above, no patent license is granted by a
Contributor:
a. for any code that a Contributor has removed from Covered Software; or
b. for infringements caused by: (i) Your and any other third party's
modifications of Covered Software, or (ii) the combination of its
Contributions with other software (except as part of its Contributor
Version); or
c. under Patent Claims infringed by Covered Software in the absence of
its Contributions.
This License does not grant any rights in the trademarks, service marks,
or logos of any Contributor (except as may be necessary to comply with
the notice requirements in Section 3.4).
2.4. Subsequent Licenses
No Contributor makes additional grants as a result of Your choice to
distribute the Covered Software under a subsequent version of this
License (see Section 10.2) or under the terms of a Secondary License (if
permitted under the terms of Section 3.3).
2.5. Representation
Each Contributor represents that the Contributor believes its
Contributions are its original creation(s) or it has sufficient rights to
grant the rights to its Contributions conveyed by this License.
2.6. Fair Use
This License is not intended to limit any rights You have under
applicable copyright doctrines of fair use, fair dealing, or other
equivalents.
2.7. Conditions
Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in
Section 2.1.
3. Responsibilities
3.1. Distribution of Source Form
All distribution of Covered Software in Source Code Form, including any
Modifications that You create or to which You contribute, must be under
the terms of this License. You must inform recipients that the Source
Code Form of the Covered Software is governed by the terms of this
License, and how they can obtain a copy of this License. You may not
attempt to alter or restrict the recipients' rights in the Source Code
Form.
3.2. Distribution of Executable Form
If You distribute Covered Software in Executable Form then:
a. such Covered Software must also be made available in Source Code Form,
as described in Section 3.1, and You must inform recipients of the
Executable Form how they can obtain a copy of such Source Code Form by
reasonable means in a timely manner, at a charge no more than the cost
of distribution to the recipient; and
b. You may distribute such Executable Form under the terms of this
License, or sublicense it under different terms, provided that the
license for the Executable Form does not attempt to limit or alter the
recipients' rights in the Source Code Form under this License.
3.3. Distribution of a Larger Work
You may create and distribute a Larger Work under terms of Your choice,
provided that You also comply with the requirements of this License for
the Covered Software. If the Larger Work is a combination of Covered
Software with a work governed by one or more Secondary Licenses, and the
Covered Software is not Incompatible With Secondary Licenses, this
License permits You to additionally distribute such Covered Software
under the terms of such Secondary License(s), so that the recipient of
the Larger Work may, at their option, further distribute the Covered
Software under the terms of either this License or such Secondary
License(s).
3.4. Notices
You may not remove or alter the substance of any license notices
(including copyright notices, patent notices, disclaimers of warranty, or
limitations of liability) contained within the Source Code Form of the
Covered Software, except that You may alter any license notices to the
extent required to remedy known factual inaccuracies.
3.5. Application of Additional Terms
You may choose to offer, and to charge a fee for, warranty, support,
indemnity or liability obligations to one or more recipients of Covered
Software. However, You may do so only on Your own behalf, and not on
behalf of any Contributor. You must make it absolutely clear that any
such warranty, support, indemnity, or liability obligation is offered by
You alone, and You hereby agree to indemnify every Contributor for any
liability incurred by such Contributor as a result of warranty, support,
indemnity or liability terms You offer. You may include additional
disclaimers of warranty and limitations of liability specific to any
jurisdiction.
4. Inability to Comply Due to Statute or Regulation
If it is impossible for You to comply with any of the terms of this License
with respect to some or all of the Covered Software due to statute,
judicial order, or regulation then You must: (a) comply with the terms of
this License to the maximum extent possible; and (b) describe the
limitations and the code they affect. Such description must be placed in a
text file included with all distributions of the Covered Software under
this License. Except to the extent prohibited by statute or regulation,
such description must be sufficiently detailed for a recipient of ordinary
skill to be able to understand it.
5. Termination
5.1. The rights granted under this License will terminate automatically if You
fail to comply with any of its terms. However, if You become compliant,
then the rights granted under this License from a particular Contributor
are reinstated (a) provisionally, unless and until such Contributor
explicitly and finally terminates Your grants, and (b) on an ongoing
basis, if such Contributor fails to notify You of the non-compliance by
some reasonable means prior to 60 days after You have come back into
compliance. Moreover, Your grants from a particular Contributor are
reinstated on an ongoing basis if such Contributor notifies You of the
non-compliance by some reasonable means, this is the first time You have
received notice of non-compliance with this License from such
Contributor, and You become compliant prior to 30 days after Your receipt
of the notice.
5.2. If You initiate litigation against any entity by asserting a patent
infringement claim (excluding declaratory judgment actions,
counter-claims, and cross-claims) alleging that a Contributor Version
directly or indirectly infringes any patent, then the rights granted to
You by any and all Contributors for the Covered Software under Section
2.1 of this License shall terminate.
5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user
license agreements (excluding distributors and resellers) which have been
validly granted by You or Your distributors under this License prior to
termination shall survive termination.
6. Disclaimer of Warranty
Covered Software is provided under this License on an "as is" basis,
without warranty of any kind, either expressed, implied, or statutory,
including, without limitation, warranties that the Covered Software is free
of defects, merchantable, fit for a particular purpose or non-infringing.
The entire risk as to the quality and performance of the Covered Software
is with You. Should any Covered Software prove defective in any respect,
You (not any Contributor) assume the cost of any necessary servicing,
repair, or correction. This disclaimer of warranty constitutes an essential
part of this License. No use of any Covered Software is authorized under
this License except under this disclaimer.
7. Limitation of Liability
Under no circumstances and under no legal theory, whether tort (including
negligence), contract, or otherwise, shall any Contributor, or anyone who
distributes Covered Software as permitted above, be liable to You for any
direct, indirect, special, incidental, or consequential damages of any
character including, without limitation, damages for lost profits, loss of
goodwill, work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses, even if such party shall have been
informed of the possibility of such damages. This limitation of liability
shall not apply to liability for death or personal injury resulting from
such party's negligence to the extent applicable law prohibits such
limitation. Some jurisdictions do not allow the exclusion or limitation of
incidental or consequential damages, so this exclusion and limitation may
not apply to You.
8. Litigation
Any litigation relating to this License may be brought only in the courts
of a jurisdiction where the defendant maintains its principal place of
business and such litigation shall be governed by laws of that
jurisdiction, without reference to its conflict-of-law provisions. Nothing
in this Section shall prevent a party's ability to bring cross-claims or
counter-claims.
9. Miscellaneous
This License represents the complete agreement concerning the subject
matter hereof. If any provision of this License is held to be
unenforceable, such provision shall be reformed only to the extent
necessary to make it enforceable. Any law or regulation which provides that
the language of a contract shall be construed against the drafter shall not
be used to construe this License against a Contributor.
10. Versions of the License
10.1. New Versions
Mozilla Foundation is the license steward. Except as provided in Section
10.3, no one other than the license steward has the right to modify or
publish new versions of this License. Each version will be given a
distinguishing version number.
10.2. Effect of New Versions
You may distribute the Covered Software under the terms of the version
of the License under which You originally received the Covered Software,
or under the terms of any subsequent version published by the license
steward.
10.3. Modified Versions
If you create software not governed by this License, and you want to
create a new license for such software, you may create and use a
modified version of this License if you rename the license and remove
any references to the name of the license steward (except to note that
such modified license differs from this License).
10.4. Distributing Source Code Form that is Incompatible With Secondary
Licenses If You choose to distribute Source Code Form that is
Incompatible With Secondary Licenses under the terms of this version of
the License, the notice described in Exhibit B of this License must be
attached.
Exhibit A - Source Code Form License Notice
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
If it is not possible or desirable to put the notice in a particular file,
then You may include the notice in a location (such as a LICENSE file in a
relevant directory) where a recipient would be likely to look for such a
notice.
You may add additional accurate notices of copyright ownership.
Exhibit B - "Incompatible With Secondary Licenses" Notice
This Source Code Form is "Incompatible
With Secondary Licenses", as defined by
the Mozilla Public License, v. 2.0.

30
vendor/github.com/hashicorp/go-cleanhttp/README.md generated vendored Normal file
View File

@ -0,0 +1,30 @@
# cleanhttp
Functions for accessing "clean" Go http.Client values
-------------
The Go standard library contains a default `http.Client` called
`http.DefaultClient`. It is a common idiom in Go code to start with
`http.DefaultClient` and tweak it as necessary, and in fact, this is
encouraged; from the `http` package documentation:
> The Client's Transport typically has internal state (cached TCP connections),
so Clients should be reused instead of created as needed. Clients are safe for
concurrent use by multiple goroutines.
Unfortunately, this is a shared value, and it is not uncommon for libraries to
assume that they are free to modify it at will. With enough dependencies, it
can be very easy to encounter strange problems and race conditions due to
manipulation of this shared value across libraries and goroutines (clients are
safe for concurrent use, but writing values to the client struct itself is not
protected).
Making things worse is the fact that a bare `http.Client` will use a default
`http.Transport` called `http.DefaultTransport`, which is another global value
that behaves the same way. So it is not simply enough to replace
`http.DefaultClient` with `&http.Client{}`.
This repository provides some simple functions to get a "clean" `http.Client`
-- one that uses the same default values as the Go standard library, but
returns a client that does not share any state with other clients.

58
vendor/github.com/hashicorp/go-cleanhttp/cleanhttp.go generated vendored Normal file
View File

@ -0,0 +1,58 @@
package cleanhttp
import (
"net"
"net/http"
"runtime"
"time"
)
// DefaultTransport returns a new http.Transport with similar default values to
// http.DefaultTransport, but with idle connections and keepalives disabled.
func DefaultTransport() *http.Transport {
transport := DefaultPooledTransport()
transport.DisableKeepAlives = true
transport.MaxIdleConnsPerHost = -1
return transport
}
// DefaultPooledTransport returns a new http.Transport with similar default
// values to http.DefaultTransport. Do not use this for transient transports as
// it can leak file descriptors over time. Only use this for transports that
// will be re-used for the same host(s).
func DefaultPooledTransport() *http.Transport {
transport := &http.Transport{
Proxy: http.ProxyFromEnvironment,
DialContext: (&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
DualStack: true,
}).DialContext,
MaxIdleConns: 100,
IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
ForceAttemptHTTP2: true,
MaxIdleConnsPerHost: runtime.GOMAXPROCS(0) + 1,
}
return transport
}
// DefaultClient returns a new http.Client with similar default values to
// http.Client, but with a non-shared Transport, idle connections disabled, and
// keepalives disabled.
func DefaultClient() *http.Client {
return &http.Client{
Transport: DefaultTransport(),
}
}
// DefaultPooledClient returns a new http.Client with similar default values to
// http.Client, but with a shared Transport. Do not use this function for
// transient clients as it can leak file descriptors over time. Only use this
// for clients that will be re-used for the same host(s).
func DefaultPooledClient() *http.Client {
return &http.Client{
Transport: DefaultPooledTransport(),
}
}

20
vendor/github.com/hashicorp/go-cleanhttp/doc.go generated vendored Normal file
View File

@ -0,0 +1,20 @@
// Package cleanhttp offers convenience utilities for acquiring "clean"
// http.Transport and http.Client structs.
//
// Values set on http.DefaultClient and http.DefaultTransport affect all
// callers. This can have detrimental effects, esepcially in TLS contexts,
// where client or root certificates set to talk to multiple endpoints can end
// up displacing each other, leading to hard-to-debug issues. This package
// provides non-shared http.Client and http.Transport structs to ensure that
// the configuration will not be overwritten by other parts of the application
// or dependencies.
//
// The DefaultClient and DefaultTransport functions disable idle connections
// and keepalives. Without ensuring that idle connections are closed before
// garbage collection, short-term clients/transports can leak file descriptors,
// eventually leading to "too many open files" errors. If you will be
// connecting to the same hosts repeatedly from the same client, you can use
// DefaultPooledClient to receive a client that has connection pooling
// semantics similar to http.DefaultClient.
//
package cleanhttp

48
vendor/github.com/hashicorp/go-cleanhttp/handlers.go generated vendored Normal file
View File

@ -0,0 +1,48 @@
package cleanhttp
import (
"net/http"
"strings"
"unicode"
)
// HandlerInput provides input options to cleanhttp's handlers
type HandlerInput struct {
ErrStatus int
}
// PrintablePathCheckHandler is a middleware that ensures the request path
// contains only printable runes.
func PrintablePathCheckHandler(next http.Handler, input *HandlerInput) http.Handler {
// Nil-check on input to make it optional
if input == nil {
input = &HandlerInput{
ErrStatus: http.StatusBadRequest,
}
}
// Default to http.StatusBadRequest on error
if input.ErrStatus == 0 {
input.ErrStatus = http.StatusBadRequest
}
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r != nil {
// Check URL path for non-printable characters
idx := strings.IndexFunc(r.URL.Path, func(c rune) bool {
return !unicode.IsPrint(c)
})
if idx != -1 {
w.WriteHeader(input.ErrStatus)
return
}
if next != nil {
next.ServeHTTP(w, r)
}
}
return
})
}

View File

@ -0,0 +1,4 @@
.idea/
*.iml
*.test
.vscode/

363
vendor/github.com/hashicorp/go-retryablehttp/LICENSE generated vendored Normal file
View File

@ -0,0 +1,363 @@
Mozilla Public License, version 2.0
1. Definitions
1.1. "Contributor"
means each individual or legal entity that creates, contributes to the
creation of, or owns Covered Software.
1.2. "Contributor Version"
means the combination of the Contributions of others (if any) used by a
Contributor and that particular Contributor's Contribution.
1.3. "Contribution"
means Covered Software of a particular Contributor.
1.4. "Covered Software"
means Source Code Form to which the initial Contributor has attached the
notice in Exhibit A, the Executable Form of such Source Code Form, and
Modifications of such Source Code Form, in each case including portions
thereof.
1.5. "Incompatible With Secondary Licenses"
means
a. that the initial Contributor has attached the notice described in
Exhibit B to the Covered Software; or
b. that the Covered Software was made available under the terms of
version 1.1 or earlier of the License, but not also under the terms of
a Secondary License.
1.6. "Executable Form"
means any form of the work other than Source Code Form.
1.7. "Larger Work"
means a work that combines Covered Software with other material, in a
separate file or files, that is not Covered Software.
1.8. "License"
means this document.
1.9. "Licensable"
means having the right to grant, to the maximum extent possible, whether
at the time of the initial grant or subsequently, any and all of the
rights conveyed by this License.
1.10. "Modifications"
means any of the following:
a. any file in Source Code Form that results from an addition to,
deletion from, or modification of the contents of Covered Software; or
b. any new file in Source Code Form that contains any Covered Software.
1.11. "Patent Claims" of a Contributor
means any patent claim(s), including without limitation, method,
process, and apparatus claims, in any patent Licensable by such
Contributor that would be infringed, but for the grant of the License,
by the making, using, selling, offering for sale, having made, import,
or transfer of either its Contributions or its Contributor Version.
1.12. "Secondary License"
means either the GNU General Public License, Version 2.0, the GNU Lesser
General Public License, Version 2.1, the GNU Affero General Public
License, Version 3.0, or any later versions of those licenses.
1.13. "Source Code Form"
means the form of the work preferred for making modifications.
1.14. "You" (or "Your")
means an individual or a legal entity exercising rights under this
License. For legal entities, "You" includes any entity that controls, is
controlled by, or is under common control with You. For purposes of this
definition, "control" means (a) the power, direct or indirect, to cause
the direction or management of such entity, whether by contract or
otherwise, or (b) ownership of more than fifty percent (50%) of the
outstanding shares or beneficial ownership of such entity.
2. License Grants and Conditions
2.1. Grants
Each Contributor hereby grants You a world-wide, royalty-free,
non-exclusive license:
a. under intellectual property rights (other than patent or trademark)
Licensable by such Contributor to use, reproduce, make available,
modify, display, perform, distribute, and otherwise exploit its
Contributions, either on an unmodified basis, with Modifications, or
as part of a Larger Work; and
b. under Patent Claims of such Contributor to make, use, sell, offer for
sale, have made, import, and otherwise transfer either its
Contributions or its Contributor Version.
2.2. Effective Date
The licenses granted in Section 2.1 with respect to any Contribution
become effective for each Contribution on the date the Contributor first
distributes such Contribution.
2.3. Limitations on Grant Scope
The licenses granted in this Section 2 are the only rights granted under
this License. No additional rights or licenses will be implied from the
distribution or licensing of Covered Software under this License.
Notwithstanding Section 2.1(b) above, no patent license is granted by a
Contributor:
a. for any code that a Contributor has removed from Covered Software; or
b. for infringements caused by: (i) Your and any other third party's
modifications of Covered Software, or (ii) the combination of its
Contributions with other software (except as part of its Contributor
Version); or
c. under Patent Claims infringed by Covered Software in the absence of
its Contributions.
This License does not grant any rights in the trademarks, service marks,
or logos of any Contributor (except as may be necessary to comply with
the notice requirements in Section 3.4).
2.4. Subsequent Licenses
No Contributor makes additional grants as a result of Your choice to
distribute the Covered Software under a subsequent version of this
License (see Section 10.2) or under the terms of a Secondary License (if
permitted under the terms of Section 3.3).
2.5. Representation
Each Contributor represents that the Contributor believes its
Contributions are its original creation(s) or it has sufficient rights to
grant the rights to its Contributions conveyed by this License.
2.6. Fair Use
This License is not intended to limit any rights You have under
applicable copyright doctrines of fair use, fair dealing, or other
equivalents.
2.7. Conditions
Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in
Section 2.1.
3. Responsibilities
3.1. Distribution of Source Form
All distribution of Covered Software in Source Code Form, including any
Modifications that You create or to which You contribute, must be under
the terms of this License. You must inform recipients that the Source
Code Form of the Covered Software is governed by the terms of this
License, and how they can obtain a copy of this License. You may not
attempt to alter or restrict the recipients' rights in the Source Code
Form.
3.2. Distribution of Executable Form
If You distribute Covered Software in Executable Form then:
a. such Covered Software must also be made available in Source Code Form,
as described in Section 3.1, and You must inform recipients of the
Executable Form how they can obtain a copy of such Source Code Form by
reasonable means in a timely manner, at a charge no more than the cost
of distribution to the recipient; and
b. You may distribute such Executable Form under the terms of this
License, or sublicense it under different terms, provided that the
license for the Executable Form does not attempt to limit or alter the
recipients' rights in the Source Code Form under this License.
3.3. Distribution of a Larger Work
You may create and distribute a Larger Work under terms of Your choice,
provided that You also comply with the requirements of this License for
the Covered Software. If the Larger Work is a combination of Covered
Software with a work governed by one or more Secondary Licenses, and the
Covered Software is not Incompatible With Secondary Licenses, this
License permits You to additionally distribute such Covered Software
under the terms of such Secondary License(s), so that the recipient of
the Larger Work may, at their option, further distribute the Covered
Software under the terms of either this License or such Secondary
License(s).
3.4. Notices
You may not remove or alter the substance of any license notices
(including copyright notices, patent notices, disclaimers of warranty, or
limitations of liability) contained within the Source Code Form of the
Covered Software, except that You may alter any license notices to the
extent required to remedy known factual inaccuracies.
3.5. Application of Additional Terms
You may choose to offer, and to charge a fee for, warranty, support,
indemnity or liability obligations to one or more recipients of Covered
Software. However, You may do so only on Your own behalf, and not on
behalf of any Contributor. You must make it absolutely clear that any
such warranty, support, indemnity, or liability obligation is offered by
You alone, and You hereby agree to indemnify every Contributor for any
liability incurred by such Contributor as a result of warranty, support,
indemnity or liability terms You offer. You may include additional
disclaimers of warranty and limitations of liability specific to any
jurisdiction.
4. Inability to Comply Due to Statute or Regulation
If it is impossible for You to comply with any of the terms of this License
with respect to some or all of the Covered Software due to statute,
judicial order, or regulation then You must: (a) comply with the terms of
this License to the maximum extent possible; and (b) describe the
limitations and the code they affect. Such description must be placed in a
text file included with all distributions of the Covered Software under
this License. Except to the extent prohibited by statute or regulation,
such description must be sufficiently detailed for a recipient of ordinary
skill to be able to understand it.
5. Termination
5.1. The rights granted under this License will terminate automatically if You
fail to comply with any of its terms. However, if You become compliant,
then the rights granted under this License from a particular Contributor
are reinstated (a) provisionally, unless and until such Contributor
explicitly and finally terminates Your grants, and (b) on an ongoing
basis, if such Contributor fails to notify You of the non-compliance by
some reasonable means prior to 60 days after You have come back into
compliance. Moreover, Your grants from a particular Contributor are
reinstated on an ongoing basis if such Contributor notifies You of the
non-compliance by some reasonable means, this is the first time You have
received notice of non-compliance with this License from such
Contributor, and You become compliant prior to 30 days after Your receipt
of the notice.
5.2. If You initiate litigation against any entity by asserting a patent
infringement claim (excluding declaratory judgment actions,
counter-claims, and cross-claims) alleging that a Contributor Version
directly or indirectly infringes any patent, then the rights granted to
You by any and all Contributors for the Covered Software under Section
2.1 of this License shall terminate.
5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user
license agreements (excluding distributors and resellers) which have been
validly granted by You or Your distributors under this License prior to
termination shall survive termination.
6. Disclaimer of Warranty
Covered Software is provided under this License on an "as is" basis,
without warranty of any kind, either expressed, implied, or statutory,
including, without limitation, warranties that the Covered Software is free
of defects, merchantable, fit for a particular purpose or non-infringing.
The entire risk as to the quality and performance of the Covered Software
is with You. Should any Covered Software prove defective in any respect,
You (not any Contributor) assume the cost of any necessary servicing,
repair, or correction. This disclaimer of warranty constitutes an essential
part of this License. No use of any Covered Software is authorized under
this License except under this disclaimer.
7. Limitation of Liability
Under no circumstances and under no legal theory, whether tort (including
negligence), contract, or otherwise, shall any Contributor, or anyone who
distributes Covered Software as permitted above, be liable to You for any
direct, indirect, special, incidental, or consequential damages of any
character including, without limitation, damages for lost profits, loss of
goodwill, work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses, even if such party shall have been
informed of the possibility of such damages. This limitation of liability
shall not apply to liability for death or personal injury resulting from
such party's negligence to the extent applicable law prohibits such
limitation. Some jurisdictions do not allow the exclusion or limitation of
incidental or consequential damages, so this exclusion and limitation may
not apply to You.
8. Litigation
Any litigation relating to this License may be brought only in the courts
of a jurisdiction where the defendant maintains its principal place of
business and such litigation shall be governed by laws of that
jurisdiction, without reference to its conflict-of-law provisions. Nothing
in this Section shall prevent a party's ability to bring cross-claims or
counter-claims.
9. Miscellaneous
This License represents the complete agreement concerning the subject
matter hereof. If any provision of this License is held to be
unenforceable, such provision shall be reformed only to the extent
necessary to make it enforceable. Any law or regulation which provides that
the language of a contract shall be construed against the drafter shall not
be used to construe this License against a Contributor.
10. Versions of the License
10.1. New Versions
Mozilla Foundation is the license steward. Except as provided in Section
10.3, no one other than the license steward has the right to modify or
publish new versions of this License. Each version will be given a
distinguishing version number.
10.2. Effect of New Versions
You may distribute the Covered Software under the terms of the version
of the License under which You originally received the Covered Software,
or under the terms of any subsequent version published by the license
steward.
10.3. Modified Versions
If you create software not governed by this License, and you want to
create a new license for such software, you may create and use a
modified version of this License if you rename the license and remove
any references to the name of the license steward (except to note that
such modified license differs from this License).
10.4. Distributing Source Code Form that is Incompatible With Secondary
Licenses If You choose to distribute Source Code Form that is
Incompatible With Secondary Licenses under the terms of this version of
the License, the notice described in Exhibit B of this License must be
attached.
Exhibit A - Source Code Form License Notice
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
If it is not possible or desirable to put the notice in a particular file,
then You may include the notice in a location (such as a LICENSE file in a
relevant directory) where a recipient would be likely to look for such a
notice.
You may add additional accurate notices of copyright ownership.
Exhibit B - "Incompatible With Secondary Licenses" Notice
This Source Code Form is "Incompatible
With Secondary Licenses", as defined by
the Mozilla Public License, v. 2.0.

11
vendor/github.com/hashicorp/go-retryablehttp/Makefile generated vendored Normal file
View File

@ -0,0 +1,11 @@
default: test
test:
go vet ./...
go test -race ./...
updatedeps:
go get -f -t -u ./...
go get -f -u ./...
.PHONY: default test updatedeps

62
vendor/github.com/hashicorp/go-retryablehttp/README.md generated vendored Normal file
View File

@ -0,0 +1,62 @@
go-retryablehttp
================
[![Build Status](http://img.shields.io/travis/hashicorp/go-retryablehttp.svg?style=flat-square)][travis]
[![Go Documentation](http://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)][godocs]
[travis]: http://travis-ci.org/hashicorp/go-retryablehttp
[godocs]: http://godoc.org/github.com/hashicorp/go-retryablehttp
The `retryablehttp` package provides a familiar HTTP client interface with
automatic retries and exponential backoff. It is a thin wrapper over the
standard `net/http` client library and exposes nearly the same public API. This
makes `retryablehttp` very easy to drop into existing programs.
`retryablehttp` performs automatic retries under certain conditions. Mainly, if
an error is returned by the client (connection errors, etc.), or if a 500-range
response code is received (except 501), then a retry is invoked after a wait
period. Otherwise, the response is returned and left to the caller to
interpret.
The main difference from `net/http` is that requests which take a request body
(POST/PUT et. al) can have the body provided in a number of ways (some more or
less efficient) that allow "rewinding" the request body if the initial request
fails so that the full request can be attempted again. See the
[godoc](http://godoc.org/github.com/hashicorp/go-retryablehttp) for more
details.
Version 0.6.0 and before are compatible with Go prior to 1.12. From 0.6.1 onward, Go 1.12+ is required.
From 0.6.7 onward, Go 1.13+ is required.
Example Use
===========
Using this library should look almost identical to what you would do with
`net/http`. The most simple example of a GET request is shown below:
```go
resp, err := retryablehttp.Get("/foo")
if err != nil {
panic(err)
}
```
The returned response object is an `*http.Response`, the same thing you would
usually get from `net/http`. Had the request failed one or more times, the above
call would block and retry with exponential backoff.
## Getting a stdlib `*http.Client` with retries
It's possible to convert a `*retryablehttp.Client` directly to a `*http.Client`.
This makes use of retryablehttp broadly applicable with minimal effort. Simply
configure a `*retryablehttp.Client` as you wish, and then call `StandardClient()`:
```go
retryClient := retryablehttp.NewClient()
retryClient.RetryMax = 10
standardClient := retryClient.StandardClient() // *http.Client
```
For more usage and examples see the
[godoc](http://godoc.org/github.com/hashicorp/go-retryablehttp).

822
vendor/github.com/hashicorp/go-retryablehttp/client.go generated vendored Normal file
View File

@ -0,0 +1,822 @@
// Package retryablehttp provides a familiar HTTP client interface with
// automatic retries and exponential backoff. It is a thin wrapper over the
// standard net/http client library and exposes nearly the same public API.
// This makes retryablehttp very easy to drop into existing programs.
//
// retryablehttp performs automatic retries under certain conditions. Mainly, if
// an error is returned by the client (connection errors etc), or if a 500-range
// response is received, then a retry is invoked. Otherwise, the response is
// returned and left to the caller to interpret.
//
// Requests which take a request body should provide a non-nil function
// parameter. The best choice is to provide either a function satisfying
// ReaderFunc which provides multiple io.Readers in an efficient manner, a
// *bytes.Buffer (the underlying raw byte slice will be used) or a raw byte
// slice. As it is a reference type, and we will wrap it as needed by readers,
// we can efficiently re-use the request body without needing to copy it. If an
// io.Reader (such as a *bytes.Reader) is provided, the full body will be read
// prior to the first request, and will be efficiently re-used for any retries.
// ReadSeeker can be used, but some users have observed occasional data races
// between the net/http library and the Seek functionality of some
// implementations of ReadSeeker, so should be avoided if possible.
package retryablehttp
import (
"bytes"
"context"
"crypto/x509"
"fmt"
"io"
"io/ioutil"
"log"
"math"
"math/rand"
"net/http"
"net/url"
"os"
"regexp"
"strconv"
"strings"
"sync"
"time"
cleanhttp "github.com/hashicorp/go-cleanhttp"
)
var (
// Default retry configuration
defaultRetryWaitMin = 1 * time.Second
defaultRetryWaitMax = 30 * time.Second
defaultRetryMax = 4
// defaultLogger is the logger provided with defaultClient
defaultLogger = log.New(os.Stderr, "", log.LstdFlags)
// defaultClient is used for performing requests without explicitly making
// a new client. It is purposely private to avoid modifications.
defaultClient = NewClient()
// We need to consume response bodies to maintain http connections, but
// limit the size we consume to respReadLimit.
respReadLimit = int64(4096)
// A regular expression to match the error returned by net/http when the
// configured number of redirects is exhausted. This error isn't typed
// specifically so we resort to matching on the error string.
redirectsErrorRe = regexp.MustCompile(`stopped after \d+ redirects\z`)
// A regular expression to match the error returned by net/http when the
// scheme specified in the URL is invalid. This error isn't typed
// specifically so we resort to matching on the error string.
schemeErrorRe = regexp.MustCompile(`unsupported protocol scheme`)
// A regular expression to match the error returned by net/http when the
// TLS certificate is not trusted. This error isn't typed
// specifically so we resort to matching on the error string.
notTrustedErrorRe = regexp.MustCompile(`certificate is not trusted`)
)
// ReaderFunc is the type of function that can be given natively to NewRequest
type ReaderFunc func() (io.Reader, error)
// ResponseHandlerFunc is a type of function that takes in a Response, and does something with it.
// The ResponseHandlerFunc is called when the HTTP client successfully receives a response and the
// CheckRetry function indicates that a retry of the base request is not necessary.
// If an error is returned from this function, the CheckRetry policy will be used to determine
// whether to retry the whole request (including this handler).
//
// Make sure to check status codes! Even if the request was completed it may have a non-2xx status code.
//
// The response body is not automatically closed. It must be closed either by the ResponseHandlerFunc or
// by the caller out-of-band. Failure to do so will result in a memory leak.
type ResponseHandlerFunc func(*http.Response) error
// LenReader is an interface implemented by many in-memory io.Reader's. Used
// for automatically sending the right Content-Length header when possible.
type LenReader interface {
Len() int
}
// Request wraps the metadata needed to create HTTP requests.
type Request struct {
// body is a seekable reader over the request body payload. This is
// used to rewind the request data in between retries.
body ReaderFunc
responseHandler ResponseHandlerFunc
// Embed an HTTP request directly. This makes a *Request act exactly
// like an *http.Request so that all meta methods are supported.
*http.Request
}
// WithContext returns wrapped Request with a shallow copy of underlying *http.Request
// with its context changed to ctx. The provided ctx must be non-nil.
func (r *Request) WithContext(ctx context.Context) *Request {
return &Request{
body: r.body,
responseHandler: r.responseHandler,
Request: r.Request.WithContext(ctx),
}
}
// SetResponseHandler allows setting the response handler.
func (r *Request) SetResponseHandler(fn ResponseHandlerFunc) {
r.responseHandler = fn
}
// BodyBytes allows accessing the request body. It is an analogue to
// http.Request's Body variable, but it returns a copy of the underlying data
// rather than consuming it.
//
// This function is not thread-safe; do not call it at the same time as another
// call, or at the same time this request is being used with Client.Do.
func (r *Request) BodyBytes() ([]byte, error) {
if r.body == nil {
return nil, nil
}
body, err := r.body()
if err != nil {
return nil, err
}
buf := new(bytes.Buffer)
_, err = buf.ReadFrom(body)
if err != nil {
return nil, err
}
return buf.Bytes(), nil
}
// SetBody allows setting the request body.
//
// It is useful if a new body needs to be set without constructing a new Request.
func (r *Request) SetBody(rawBody interface{}) error {
bodyReader, contentLength, err := getBodyReaderAndContentLength(rawBody)
if err != nil {
return err
}
r.body = bodyReader
r.ContentLength = contentLength
return nil
}
// WriteTo allows copying the request body into a writer.
//
// It writes data to w until there's no more data to write or
// when an error occurs. The return int64 value is the number of bytes
// written. Any error encountered during the write is also returned.
// The signature matches io.WriterTo interface.
func (r *Request) WriteTo(w io.Writer) (int64, error) {
body, err := r.body()
if err != nil {
return 0, err
}
if c, ok := body.(io.Closer); ok {
defer c.Close()
}
return io.Copy(w, body)
}
func getBodyReaderAndContentLength(rawBody interface{}) (ReaderFunc, int64, error) {
var bodyReader ReaderFunc
var contentLength int64
switch body := rawBody.(type) {
// If they gave us a function already, great! Use it.
case ReaderFunc:
bodyReader = body
tmp, err := body()
if err != nil {
return nil, 0, err
}
if lr, ok := tmp.(LenReader); ok {
contentLength = int64(lr.Len())
}
if c, ok := tmp.(io.Closer); ok {
c.Close()
}
case func() (io.Reader, error):
bodyReader = body
tmp, err := body()
if err != nil {
return nil, 0, err
}
if lr, ok := tmp.(LenReader); ok {
contentLength = int64(lr.Len())
}
if c, ok := tmp.(io.Closer); ok {
c.Close()
}
// If a regular byte slice, we can read it over and over via new
// readers
case []byte:
buf := body
bodyReader = func() (io.Reader, error) {
return bytes.NewReader(buf), nil
}
contentLength = int64(len(buf))
// If a bytes.Buffer we can read the underlying byte slice over and
// over
case *bytes.Buffer:
buf := body
bodyReader = func() (io.Reader, error) {
return bytes.NewReader(buf.Bytes()), nil
}
contentLength = int64(buf.Len())
// We prioritize *bytes.Reader here because we don't really want to
// deal with it seeking so want it to match here instead of the
// io.ReadSeeker case.
case *bytes.Reader:
buf, err := ioutil.ReadAll(body)
if err != nil {
return nil, 0, err
}
bodyReader = func() (io.Reader, error) {
return bytes.NewReader(buf), nil
}
contentLength = int64(len(buf))
// Compat case
case io.ReadSeeker:
raw := body
bodyReader = func() (io.Reader, error) {
_, err := raw.Seek(0, 0)
return ioutil.NopCloser(raw), err
}
if lr, ok := raw.(LenReader); ok {
contentLength = int64(lr.Len())
}
// Read all in so we can reset
case io.Reader:
buf, err := ioutil.ReadAll(body)
if err != nil {
return nil, 0, err
}
bodyReader = func() (io.Reader, error) {
return bytes.NewReader(buf), nil
}
contentLength = int64(len(buf))
// No body provided, nothing to do
case nil:
// Unrecognized type
default:
return nil, 0, fmt.Errorf("cannot handle type %T", rawBody)
}
return bodyReader, contentLength, nil
}
// FromRequest wraps an http.Request in a retryablehttp.Request
func FromRequest(r *http.Request) (*Request, error) {
bodyReader, _, err := getBodyReaderAndContentLength(r.Body)
if err != nil {
return nil, err
}
// Could assert contentLength == r.ContentLength
return &Request{body: bodyReader, Request: r}, nil
}
// NewRequest creates a new wrapped request.
func NewRequest(method, url string, rawBody interface{}) (*Request, error) {
return NewRequestWithContext(context.Background(), method, url, rawBody)
}
// NewRequestWithContext creates a new wrapped request with the provided context.
//
// The context controls the entire lifetime of a request and its response:
// obtaining a connection, sending the request, and reading the response headers and body.
func NewRequestWithContext(ctx context.Context, method, url string, rawBody interface{}) (*Request, error) {
bodyReader, contentLength, err := getBodyReaderAndContentLength(rawBody)
if err != nil {
return nil, err
}
httpReq, err := http.NewRequestWithContext(ctx, method, url, nil)
if err != nil {
return nil, err
}
httpReq.ContentLength = contentLength
return &Request{body: bodyReader, Request: httpReq}, nil
}
// Logger interface allows to use other loggers than
// standard log.Logger.
type Logger interface {
Printf(string, ...interface{})
}
// LeveledLogger is an interface that can be implemented by any logger or a
// logger wrapper to provide leveled logging. The methods accept a message
// string and a variadic number of key-value pairs. For log.Printf style
// formatting where message string contains a format specifier, use Logger
// interface.
type LeveledLogger interface {
Error(msg string, keysAndValues ...interface{})
Info(msg string, keysAndValues ...interface{})
Debug(msg string, keysAndValues ...interface{})
Warn(msg string, keysAndValues ...interface{})
}
// hookLogger adapts an LeveledLogger to Logger for use by the existing hook functions
// without changing the API.
type hookLogger struct {
LeveledLogger
}
func (h hookLogger) Printf(s string, args ...interface{}) {
h.Info(fmt.Sprintf(s, args...))
}
// RequestLogHook allows a function to run before each retry. The HTTP
// request which will be made, and the retry number (0 for the initial
// request) are available to users. The internal logger is exposed to
// consumers.
type RequestLogHook func(Logger, *http.Request, int)
// ResponseLogHook is like RequestLogHook, but allows running a function
// on each HTTP response. This function will be invoked at the end of
// every HTTP request executed, regardless of whether a subsequent retry
// needs to be performed or not. If the response body is read or closed
// from this method, this will affect the response returned from Do().
type ResponseLogHook func(Logger, *http.Response)
// CheckRetry specifies a policy for handling retries. It is called
// following each request with the response and error values returned by
// the http.Client. If CheckRetry returns false, the Client stops retrying
// and returns the response to the caller. If CheckRetry returns an error,
// that error value is returned in lieu of the error from the request. The
// Client will close any response body when retrying, but if the retry is
// aborted it is up to the CheckRetry callback to properly close any
// response body before returning.
type CheckRetry func(ctx context.Context, resp *http.Response, err error) (bool, error)
// Backoff specifies a policy for how long to wait between retries.
// It is called after a failing request to determine the amount of time
// that should pass before trying again.
type Backoff func(min, max time.Duration, attemptNum int, resp *http.Response) time.Duration
// ErrorHandler is called if retries are expired, containing the last status
// from the http library. If not specified, default behavior for the library is
// to close the body and return an error indicating how many tries were
// attempted. If overriding this, be sure to close the body if needed.
type ErrorHandler func(resp *http.Response, err error, numTries int) (*http.Response, error)
// Client is used to make HTTP requests. It adds additional functionality
// like automatic retries to tolerate minor outages.
type Client struct {
HTTPClient *http.Client // Internal HTTP client.
Logger interface{} // Customer logger instance. Can be either Logger or LeveledLogger
RetryWaitMin time.Duration // Minimum time to wait
RetryWaitMax time.Duration // Maximum time to wait
RetryMax int // Maximum number of retries
// RequestLogHook allows a user-supplied function to be called
// before each retry.
RequestLogHook RequestLogHook
// ResponseLogHook allows a user-supplied function to be called
// with the response from each HTTP request executed.
ResponseLogHook ResponseLogHook
// CheckRetry specifies the policy for handling retries, and is called
// after each request. The default policy is DefaultRetryPolicy.
CheckRetry CheckRetry
// Backoff specifies the policy for how long to wait between retries
Backoff Backoff
// ErrorHandler specifies the custom error handler to use, if any
ErrorHandler ErrorHandler
loggerInit sync.Once
clientInit sync.Once
}
// NewClient creates a new Client with default settings.
func NewClient() *Client {
return &Client{
HTTPClient: cleanhttp.DefaultPooledClient(),
Logger: defaultLogger,
RetryWaitMin: defaultRetryWaitMin,
RetryWaitMax: defaultRetryWaitMax,
RetryMax: defaultRetryMax,
CheckRetry: DefaultRetryPolicy,
Backoff: DefaultBackoff,
}
}
func (c *Client) logger() interface{} {
c.loggerInit.Do(func() {
if c.Logger == nil {
return
}
switch c.Logger.(type) {
case Logger, LeveledLogger:
// ok
default:
// This should happen in dev when they are setting Logger and work on code, not in prod.
panic(fmt.Sprintf("invalid logger type passed, must be Logger or LeveledLogger, was %T", c.Logger))
}
})
return c.Logger
}
// DefaultRetryPolicy provides a default callback for Client.CheckRetry, which
// will retry on connection errors and server errors.
func DefaultRetryPolicy(ctx context.Context, resp *http.Response, err error) (bool, error) {
// do not retry on context.Canceled or context.DeadlineExceeded
if ctx.Err() != nil {
return false, ctx.Err()
}
// don't propagate other errors
shouldRetry, _ := baseRetryPolicy(resp, err)
return shouldRetry, nil
}
// ErrorPropagatedRetryPolicy is the same as DefaultRetryPolicy, except it
// propagates errors back instead of returning nil. This allows you to inspect
// why it decided to retry or not.
func ErrorPropagatedRetryPolicy(ctx context.Context, resp *http.Response, err error) (bool, error) {
// do not retry on context.Canceled or context.DeadlineExceeded
if ctx.Err() != nil {
return false, ctx.Err()
}
return baseRetryPolicy(resp, err)
}
func baseRetryPolicy(resp *http.Response, err error) (bool, error) {
if err != nil {
if v, ok := err.(*url.Error); ok {
// Don't retry if the error was due to too many redirects.
if redirectsErrorRe.MatchString(v.Error()) {
return false, v
}
// Don't retry if the error was due to an invalid protocol scheme.
if schemeErrorRe.MatchString(v.Error()) {
return false, v
}
// Don't retry if the error was due to TLS cert verification failure.
if notTrustedErrorRe.MatchString(v.Error()) {
return false, v
}
if _, ok := v.Err.(x509.UnknownAuthorityError); ok {
return false, v
}
}
// The error is likely recoverable so retry.
return true, nil
}
// 429 Too Many Requests is recoverable. Sometimes the server puts
// a Retry-After response header to indicate when the server is
// available to start processing request from client.
if resp.StatusCode == http.StatusTooManyRequests {
return true, nil
}
// Check the response code. We retry on 500-range responses to allow
// the server time to recover, as 500's are typically not permanent
// errors and may relate to outages on the server side. This will catch
// invalid response codes as well, like 0 and 999.
if resp.StatusCode == 0 || (resp.StatusCode >= 500 && resp.StatusCode != http.StatusNotImplemented) {
return true, fmt.Errorf("unexpected HTTP status %s", resp.Status)
}
return false, nil
}
// DefaultBackoff provides a default callback for Client.Backoff which
// will perform exponential backoff based on the attempt number and limited
// by the provided minimum and maximum durations.
//
// It also tries to parse Retry-After response header when a http.StatusTooManyRequests
// (HTTP Code 429) is found in the resp parameter. Hence it will return the number of
// 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 || 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)
}
}
}
}
mult := math.Pow(2, float64(attemptNum)) * float64(min)
sleep := time.Duration(mult)
if float64(sleep) != mult || sleep > max {
sleep = max
}
return sleep
}
// LinearJitterBackoff provides a callback for Client.Backoff which will
// perform linear backoff based on the attempt number and with jitter to
// prevent a thundering herd.
//
// min and max here are *not* absolute values. The number to be multiplied by
// the attempt number will be chosen at random from between them, thus they are
// bounding the jitter.
//
// For instance:
// * To get strictly linear backoff of one second increasing each retry, set
// both to one second (1s, 2s, 3s, 4s, ...)
// * To get a small amount of jitter centered around one second increasing each
// retry, set to around one second, such as a min of 800ms and max of 1200ms
// (892ms, 2102ms, 2945ms, 4312ms, ...)
// * To get extreme jitter, set to a very wide spread, such as a min of 100ms
// and a max of 20s (15382ms, 292ms, 51321ms, 35234ms, ...)
func LinearJitterBackoff(min, max time.Duration, attemptNum int, resp *http.Response) time.Duration {
// attemptNum always starts at zero but we want to start at 1 for multiplication
attemptNum++
if max <= min {
// Unclear what to do here, or they are the same, so return min *
// attemptNum
return min * time.Duration(attemptNum)
}
// Seed rand; doing this every time is fine
rand := rand.New(rand.NewSource(int64(time.Now().Nanosecond())))
// Pick a random number that lies somewhere between the min and max and
// multiply by the attemptNum. attemptNum starts at zero so we always
// increment here. We first get a random percentage, then apply that to the
// difference between min and max, and add to min.
jitter := rand.Float64() * float64(max-min)
jitterMin := int64(jitter) + int64(min)
return time.Duration(jitterMin * int64(attemptNum))
}
// PassthroughErrorHandler is an ErrorHandler that directly passes through the
// values from the net/http library for the final request. The body is not
// closed.
func PassthroughErrorHandler(resp *http.Response, err error, _ int) (*http.Response, error) {
return resp, err
}
// Do wraps calling an HTTP method with retries.
func (c *Client) Do(req *Request) (*http.Response, error) {
c.clientInit.Do(func() {
if c.HTTPClient == nil {
c.HTTPClient = cleanhttp.DefaultPooledClient()
}
})
logger := c.logger()
if logger != nil {
switch v := logger.(type) {
case LeveledLogger:
v.Debug("performing request", "method", req.Method, "url", req.URL)
case Logger:
v.Printf("[DEBUG] %s %s", req.Method, req.URL)
}
}
var resp *http.Response
var attempt int
var shouldRetry bool
var doErr, respErr, checkErr error
for i := 0; ; i++ {
doErr, respErr = nil, nil
attempt++
// Always rewind the request body when non-nil.
if req.body != nil {
body, err := req.body()
if err != nil {
c.HTTPClient.CloseIdleConnections()
return resp, err
}
if c, ok := body.(io.ReadCloser); ok {
req.Body = c
} else {
req.Body = ioutil.NopCloser(body)
}
}
if c.RequestLogHook != nil {
switch v := logger.(type) {
case LeveledLogger:
c.RequestLogHook(hookLogger{v}, req.Request, i)
case Logger:
c.RequestLogHook(v, req.Request, i)
default:
c.RequestLogHook(nil, req.Request, i)
}
}
// Attempt the request
resp, doErr = c.HTTPClient.Do(req.Request)
// Check if we should continue with retries.
shouldRetry, checkErr = c.CheckRetry(req.Context(), resp, doErr)
if !shouldRetry && doErr == nil && req.responseHandler != nil {
respErr = req.responseHandler(resp)
shouldRetry, checkErr = c.CheckRetry(req.Context(), resp, respErr)
}
err := doErr
if respErr != nil {
err = respErr
}
if err != nil {
switch v := logger.(type) {
case LeveledLogger:
v.Error("request failed", "error", err, "method", req.Method, "url", req.URL)
case Logger:
v.Printf("[ERR] %s %s request failed: %v", req.Method, req.URL, err)
}
} else {
// Call this here to maintain the behavior of logging all requests,
// even if CheckRetry signals to stop.
if c.ResponseLogHook != nil {
// Call the response logger function if provided.
switch v := logger.(type) {
case LeveledLogger:
c.ResponseLogHook(hookLogger{v}, resp)
case Logger:
c.ResponseLogHook(v, resp)
default:
c.ResponseLogHook(nil, resp)
}
}
}
if !shouldRetry {
break
}
// We do this before drainBody because there's no need for the I/O if
// we're breaking out
remain := c.RetryMax - i
if remain <= 0 {
break
}
// We're going to retry, consume any response to reuse the connection.
if doErr == nil {
c.drainBody(resp.Body)
}
wait := c.Backoff(c.RetryWaitMin, c.RetryWaitMax, i, resp)
if logger != nil {
desc := fmt.Sprintf("%s %s", req.Method, req.URL)
if resp != nil {
desc = fmt.Sprintf("%s (status: %d)", desc, resp.StatusCode)
}
switch v := logger.(type) {
case LeveledLogger:
v.Debug("retrying request", "request", desc, "timeout", wait, "remaining", remain)
case Logger:
v.Printf("[DEBUG] %s: retrying in %s (%d left)", desc, wait, remain)
}
}
timer := time.NewTimer(wait)
select {
case <-req.Context().Done():
timer.Stop()
c.HTTPClient.CloseIdleConnections()
return nil, req.Context().Err()
case <-timer.C:
}
// Make shallow copy of http Request so that we can modify its body
// without racing against the closeBody call in persistConn.writeLoop.
httpreq := *req.Request
req.Request = &httpreq
}
// this is the closest we have to success criteria
if doErr == nil && respErr == nil && checkErr == nil && !shouldRetry {
return resp, nil
}
defer c.HTTPClient.CloseIdleConnections()
var err error
if checkErr != nil {
err = checkErr
} else if respErr != nil {
err = respErr
} else {
err = doErr
}
if c.ErrorHandler != nil {
return c.ErrorHandler(resp, err, attempt)
}
// By default, we close the response body and return an error without
// returning the response
if resp != nil {
c.drainBody(resp.Body)
}
// this means CheckRetry thought the request was a failure, but didn't
// communicate why
if err == nil {
return nil, fmt.Errorf("%s %s giving up after %d attempt(s)",
req.Method, req.URL, attempt)
}
return nil, fmt.Errorf("%s %s giving up after %d attempt(s): %w",
req.Method, req.URL, attempt, err)
}
// Try to read the response body so we can reuse this connection.
func (c *Client) drainBody(body io.ReadCloser) {
defer body.Close()
_, err := io.Copy(ioutil.Discard, io.LimitReader(body, respReadLimit))
if err != nil {
if c.logger() != nil {
switch v := c.logger().(type) {
case LeveledLogger:
v.Error("error reading response body", "error", err)
case Logger:
v.Printf("[ERR] error reading response body: %v", err)
}
}
}
}
// Get is a shortcut for doing a GET request without making a new client.
func Get(url string) (*http.Response, error) {
return defaultClient.Get(url)
}
// Get is a convenience helper for doing simple GET requests.
func (c *Client) Get(url string) (*http.Response, error) {
req, err := NewRequest("GET", url, nil)
if err != nil {
return nil, err
}
return c.Do(req)
}
// Head is a shortcut for doing a HEAD request without making a new client.
func Head(url string) (*http.Response, error) {
return defaultClient.Head(url)
}
// Head is a convenience method for doing simple HEAD requests.
func (c *Client) Head(url string) (*http.Response, error) {
req, err := NewRequest("HEAD", url, nil)
if err != nil {
return nil, err
}
return c.Do(req)
}
// Post is a shortcut for doing a POST request without making a new client.
func Post(url, bodyType string, body interface{}) (*http.Response, error) {
return defaultClient.Post(url, bodyType, body)
}
// Post is a convenience method for doing simple POST requests.
func (c *Client) Post(url, bodyType string, body interface{}) (*http.Response, error) {
req, err := NewRequest("POST", url, body)
if err != nil {
return nil, err
}
req.Header.Set("Content-Type", bodyType)
return c.Do(req)
}
// PostForm is a shortcut to perform a POST with form data without creating
// a new client.
func PostForm(url string, data url.Values) (*http.Response, error) {
return defaultClient.PostForm(url, data)
}
// PostForm is a convenience method for doing simple POST operations using
// pre-filled url.Values form data.
func (c *Client) PostForm(url string, data url.Values) (*http.Response, error) {
return c.Post(url, "application/x-www-form-urlencoded", strings.NewReader(data.Encode()))
}
// StandardClient returns a stdlib *http.Client with a custom Transport, which
// shims in a *retryablehttp.Client for added retries.
func (c *Client) StandardClient() *http.Client {
return &http.Client{
Transport: &RoundTripper{Client: c},
}
}

View File

@ -0,0 +1,52 @@
package retryablehttp
import (
"errors"
"net/http"
"net/url"
"sync"
)
// RoundTripper implements the http.RoundTripper interface, using a retrying
// HTTP client to execute requests.
//
// It is important to note that retryablehttp doesn't always act exactly as a
// RoundTripper should. This is highly dependent on the retryable client's
// configuration.
type RoundTripper struct {
// The client to use during requests. If nil, the default retryablehttp
// client and settings will be used.
Client *Client
// once ensures that the logic to initialize the default client runs at
// most once, in a single thread.
once sync.Once
}
// init initializes the underlying retryable client.
func (rt *RoundTripper) init() {
if rt.Client == nil {
rt.Client = NewClient()
}
}
// RoundTrip satisfies the http.RoundTripper interface.
func (rt *RoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
rt.once.Do(rt.init)
// Convert the request to be retryable.
retryableReq, err := FromRequest(req)
if err != nil {
return nil, err
}
// Execute the request.
resp, err := rt.Client.Do(retryableReq)
// If we got an error returned by standard library's `Do` method, unwrap it
// otherwise we will wind up erroneously re-nesting the error.
if _, ok := err.(*url.Error); ok {
return resp, errors.Unwrap(err)
}
return resp, err
}

33
vendor/github.com/xanzy/go-gitlab/.gitignore generated vendored Normal file
View File

@ -0,0 +1,33 @@
# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
*.a
*.so
# Folders
_obj
_test
# Architecture specific extensions/prefixes
*.[568vq]
[568vq].out
*.cgo1.go
*.cgo2.c
_cgo_defun.c
_cgo_gotypes.go
_cgo_export.*
_testmain.go
*.exe
*.test
*.prof
# IDE specific files and folders
.idea
*.iml
*.swp
*.swo
# vendor
vendor

59
vendor/github.com/xanzy/go-gitlab/.golangci.yml generated vendored Normal file
View File

@ -0,0 +1,59 @@
# This file contains all available configuration options
# with their default values.
# Options for analysis running
run:
concurrency: 4
timeout: 10m
issues-exit-code: 1
# Include test files or not, default is true
tests: true
# Output configuration options
output:
format: line-number
# All available settings of specific linters
linters-settings:
misspell:
locale: US
ignore-words:
- noteable
unused:
# Treat code as a program (not a library) and report unused exported identifiers
check-exported: false
linters:
enable:
- asciicheck
- deadcode
- dogsled
- errorlint
- exportloopref
- goconst
- golint
- gosimple
- govet
- ineffassign
- megacheck
- misspell
- nakedret
- nolintlint
- staticcheck
- structcheck
- typecheck
- unconvert
- unused
- varcheck
- whitespace
disable:
- errcheck
disable-all: false
fast: false
issues:
# Maximum issues count per one linter (set to 0 to disable)
max-issues-per-linter: 0
# Maximum count of issues with the same text (set to 0 to disable)
max-same-issues: 0

201
vendor/github.com/xanzy/go-gitlab/LICENSE generated vendored Normal file
View File

@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright {yyyy} {name of copyright owner}
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.

202
vendor/github.com/xanzy/go-gitlab/README.md generated vendored Normal file
View File

@ -0,0 +1,202 @@
# go-gitlab
A GitLab API client enabling Go programs to interact with GitLab in a simple and uniform way
[![Build Status](https://github.com/xanzy/go-gitlab/workflows/Lint%20and%20Test/badge.svg)](https://github.com/xanzy/go-gitlab/actions?workflow=Lint%20and%20Test)
[![Sourcegraph](https://sourcegraph.com/github.com/xanzy/go-gitlab/-/badge.svg)](https://sourcegraph.com/github.com/xanzy/go-gitlab?badge)
[![GoDoc](https://godoc.org/github.com/xanzy/go-gitlab?status.svg)](https://godoc.org/github.com/xanzy/go-gitlab)
[![Go Report Card](https://goreportcard.com/badge/github.com/xanzy/go-gitlab)](https://goreportcard.com/report/github.com/xanzy/go-gitlab)
## NOTE
Release v0.6.0 (released on 25-08-2017) no longer supports the older V3 GitLab API. If
you need V3 support, please use the `f-api-v3` branch. This release contains some backwards
incompatible changes that were needed to fully support the V4 GitLab API.
## Coverage
This API client package covers most of the existing GitLab API calls and is updated regularly
to add new and/or missing endpoints. Currently, the following services are supported:
- [x] Applications
- [x] Award Emojis
- [x] Branches
- [x] Broadcast Messages
- [x] Commits
- [x] Container Registry
- [x] Custom Attributes
- [x] Deploy Keys
- [x] Deployments
- [x] Discussions (threaded comments)
- [x] Environments
- [x] Epic Issues
- [x] Epics
- [x] Error Tracking
- [x] Events
- [x] Feature Flags
- [x] Geo Nodes
- [x] Generic Packages
- [x] GitLab CI Config Templates
- [x] Gitignores Templates
- [x] Group Access Requests
- [x] Group Issue Boards
- [x] Group Members
- [x] Group Milestones
- [x] Group Wikis
- [x] Group-Level Variables
- [x] Groups
- [x] Instance Clusters
- [x] Invites
- [x] Issue Boards
- [x] Issues
- [x] Jobs
- [x] Keys
- [x] Labels
- [x] License
- [x] Markdown
- [x] Merge Request Approvals
- [x] Merge Requests
- [x] Namespaces
- [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
- [x] Project Import/export
- [x] Project Members
- [x] Project Milestones
- [x] Project Snippets
- [x] Project Vulnerabilities
- [x] Project-Level Variables
- [x] Projects (including setting Webhooks)
- [x] Protected Branches
- [x] Protected Environments
- [x] Protected Tags
- [x] Repositories
- [x] Repository Files
- [x] Repository Submodules
- [x] Runners
- [x] Search
- [x] Services
- [x] Settings
- [x] Sidekiq Metrics
- [x] System Hooks
- [x] Tags
- [x] Todos
- [x] Topics
- [x] Users
- [x] Validate CI Configuration
- [x] Version
- [x] Wikis
## Usage
```go
import "github.com/xanzy/go-gitlab"
```
Construct a new GitLab client, then use the various services on the client to
access different parts of the GitLab API. For example, to list all
users:
```go
git, err := gitlab.NewClient("yourtokengoeshere")
if err != nil {
log.Fatalf("Failed to create client: %v", err)
}
users, _, err := git.Users.ListUsers(&gitlab.ListUsersOptions{})
```
There are a few `With...` option functions that can be used to customize
the API client. For example, to set a custom base URL:
```go
git, err := gitlab.NewClient("yourtokengoeshere", gitlab.WithBaseURL("https://git.mydomain.com/api/v4"))
if err != nil {
log.Fatalf("Failed to create client: %v", err)
}
users, _, err := git.Users.ListUsers(&gitlab.ListUsersOptions{})
```
Some API methods have optional parameters that can be passed. For example,
to list all projects for user "svanharmelen":
```go
git := gitlab.NewClient("yourtokengoeshere")
opt := &gitlab.ListProjectsOptions{Search: gitlab.String("svanharmelen")}
projects, _, err := git.Projects.ListProjects(opt)
```
### Examples
The [examples](https://github.com/xanzy/go-gitlab/tree/master/examples) directory
contains a couple for clear examples, of which one is partially listed here as well:
```go
package main
import (
"log"
"github.com/xanzy/go-gitlab"
)
func main() {
git, err := gitlab.NewClient("yourtokengoeshere")
if err != nil {
log.Fatalf("Failed to create client: %v", err)
}
// Create new project
p := &gitlab.CreateProjectOptions{
Name: gitlab.String("My Project"),
Description: gitlab.String("Just a test project to play with"),
MergeRequestsEnabled: gitlab.Bool(true),
SnippetsEnabled: gitlab.Bool(true),
Visibility: gitlab.Visibility(gitlab.PublicVisibility),
}
project, _, err := git.Projects.CreateProject(p)
if err != nil {
log.Fatal(err)
}
// Add a new snippet
s := &gitlab.CreateProjectSnippetOptions{
Title: gitlab.String("Dummy Snippet"),
FileName: gitlab.String("snippet.go"),
Content: gitlab.String("package main...."),
Visibility: gitlab.Visibility(gitlab.PublicVisibility),
}
_, _, err = git.ProjectSnippets.CreateSnippet(project.ID, s)
if err != nil {
log.Fatal(err)
}
}
```
For complete usage of go-gitlab, see the full [package docs](https://godoc.org/github.com/xanzy/go-gitlab).
## ToDo
- The biggest thing this package still needs is tests :disappointed:
## Issues
- If you have an issue: report it on the [issue tracker](https://github.com/xanzy/go-gitlab/issues)
## Author
Sander van Harmelen (<sander@vanharmelen.nl>)
## License
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>

253
vendor/github.com/xanzy/go-gitlab/access_requests.go generated vendored Normal file
View File

@ -0,0 +1,253 @@
//
// 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"
"time"
)
// AccessRequest represents a access request for a group or project.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/access_requests.html
type AccessRequest struct {
ID int `json:"id"`
Username string `json:"username"`
Name string `json:"name"`
State string `json:"state"`
CreatedAt *time.Time `json:"created_at"`
RequestedAt *time.Time `json:"requested_at"`
AccessLevel AccessLevelValue `json:"access_level"`
}
// AccessRequestsService handles communication with the project/group
// access requests related methods of the GitLab API.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/access_requests.html
type AccessRequestsService struct {
client *Client
}
// ListAccessRequestsOptions represents the available
// ListProjectAccessRequests() or ListGroupAccessRequests() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/access_requests.html#list-access-requests-for-a-group-or-project
type ListAccessRequestsOptions ListOptions
// ListProjectAccessRequests gets a list of access requests
// viewable by the authenticated user.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/access_requests.html#list-access-requests-for-a-group-or-project
func (s *AccessRequestsService) ListProjectAccessRequests(pid interface{}, opt *ListAccessRequestsOptions, options ...RequestOptionFunc) ([]*AccessRequest, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/access_requests", PathEscape(project))
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
var ars []*AccessRequest
resp, err := s.client.Do(req, &ars)
if err != nil {
return nil, resp, err
}
return ars, resp, err
}
// ListGroupAccessRequests gets a list of access requests
// viewable by the authenticated user.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/access_requests.html#list-access-requests-for-a-group-or-project
func (s *AccessRequestsService) ListGroupAccessRequests(gid interface{}, opt *ListAccessRequestsOptions, options ...RequestOptionFunc) ([]*AccessRequest, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/access_requests", PathEscape(group))
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
var ars []*AccessRequest
resp, err := s.client.Do(req, &ars)
if err != nil {
return nil, resp, err
}
return ars, resp, err
}
// RequestProjectAccess requests access for the authenticated user
// to a group or project.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/access_requests.html#request-access-to-a-group-or-project
func (s *AccessRequestsService) RequestProjectAccess(pid interface{}, options ...RequestOptionFunc) (*AccessRequest, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/access_requests", PathEscape(project))
req, err := s.client.NewRequest(http.MethodPost, u, nil, options)
if err != nil {
return nil, nil, err
}
ar := new(AccessRequest)
resp, err := s.client.Do(req, ar)
if err != nil {
return nil, resp, err
}
return ar, resp, err
}
// RequestGroupAccess requests access for the authenticated user
// to a group or project.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/access_requests.html#request-access-to-a-group-or-project
func (s *AccessRequestsService) RequestGroupAccess(gid interface{}, options ...RequestOptionFunc) (*AccessRequest, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/access_requests", PathEscape(group))
req, err := s.client.NewRequest(http.MethodPost, u, nil, options)
if err != nil {
return nil, nil, err
}
ar := new(AccessRequest)
resp, err := s.client.Do(req, ar)
if err != nil {
return nil, resp, err
}
return ar, resp, err
}
// ApproveAccessRequestOptions represents the available
// ApproveProjectAccessRequest() and ApproveGroupAccessRequest() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/access_requests.html#approve-an-access-request
type ApproveAccessRequestOptions struct {
AccessLevel *AccessLevelValue `url:"access_level,omitempty" json:"access_level,omitempty"`
}
// ApproveProjectAccessRequest approves an access request for the given user.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/access_requests.html#approve-an-access-request
func (s *AccessRequestsService) ApproveProjectAccessRequest(pid interface{}, user int, opt *ApproveAccessRequestOptions, options ...RequestOptionFunc) (*AccessRequest, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/access_requests/%d/approve", PathEscape(project), user)
req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
if err != nil {
return nil, nil, err
}
ar := new(AccessRequest)
resp, err := s.client.Do(req, ar)
if err != nil {
return nil, resp, err
}
return ar, resp, err
}
// ApproveGroupAccessRequest approves an access request for the given user.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/access_requests.html#approve-an-access-request
func (s *AccessRequestsService) ApproveGroupAccessRequest(gid interface{}, user int, opt *ApproveAccessRequestOptions, options ...RequestOptionFunc) (*AccessRequest, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/access_requests/%d/approve", PathEscape(group), user)
req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
if err != nil {
return nil, nil, err
}
ar := new(AccessRequest)
resp, err := s.client.Do(req, ar)
if err != nil {
return nil, resp, err
}
return ar, resp, err
}
// DenyProjectAccessRequest denies an access request for the given user.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/access_requests.html#deny-an-access-request
func (s *AccessRequestsService) DenyProjectAccessRequest(pid interface{}, user int, options ...RequestOptionFunc) (*Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("projects/%s/access_requests/%d", PathEscape(project), user)
req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}
// DenyGroupAccessRequest denies an access request for the given user.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/access_requests.html#deny-an-access-request
func (s *AccessRequestsService) DenyGroupAccessRequest(gid interface{}, user int, options ...RequestOptionFunc) (*Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("groups/%s/access_requests/%d", PathEscape(group), user)
req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}

106
vendor/github.com/xanzy/go-gitlab/applications.go generated vendored Normal file
View File

@ -0,0 +1,106 @@
//
// 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"
)
// ApplicationsService handles communication with administrables applications
// of the Gitlab API.
//
// Gitlab API docs : https://docs.gitlab.com/ee/api/applications.html
type ApplicationsService struct {
client *Client
}
// Application represents a GitLab application
type Application struct {
ID int `json:"id"`
ApplicationID string `json:"application_id"`
ApplicationName string `json:"application_name"`
Secret string `json:"secret"`
CallbackURL string `json:"callback_url"`
Confidential bool `json:"confidential"`
}
// CreateApplicationOptions represents the available CreateApplication() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/applications.html#create-an-application
type CreateApplicationOptions struct {
Name *string `url:"name,omitempty" json:"name,omitempty"`
RedirectURI *string `url:"redirect_uri,omitempty" json:"redirect_uri,omitempty"`
Scopes *string `url:"scopes,omitempty" json:"scopes,omitempty"`
Confidential *bool `url:"confidential,omitempty" json:"confidential,omitempty"`
}
// CreateApplication creates a new application owned by the authenticated user.
//
// Gitlab API docs : https://docs.gitlab.com/ee/api/applications.html#create-an-application
func (s *ApplicationsService) CreateApplication(opt *CreateApplicationOptions, options ...RequestOptionFunc) (*Application, *Response, error) {
req, err := s.client.NewRequest(http.MethodPost, "applications", opt, options)
if err != nil {
return nil, nil, err
}
a := new(Application)
resp, err := s.client.Do(req, a)
if err != nil {
return nil, resp, err
}
return a, resp, err
}
// ListApplicationsOptions represents the available
// ListApplications() options.
type ListApplicationsOptions ListOptions
// ListApplications get a list of administrables applications by the authenticated user
//
// Gitlab API docs : https://docs.gitlab.com/ee/api/applications.html#list-all-applications
func (s *ApplicationsService) ListApplications(opt *ListApplicationsOptions, options ...RequestOptionFunc) ([]*Application, *Response, error) {
req, err := s.client.NewRequest(http.MethodGet, "applications", opt, options)
if err != nil {
return nil, nil, err
}
var as []*Application
resp, err := s.client.Do(req, &as)
if err != nil {
return nil, resp, err
}
return as, resp, err
}
// DeleteApplication removes a specific application.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/applications.html#delete-an-application
func (s *ApplicationsService) DeleteApplication(application int, options ...RequestOptionFunc) (*Response, error) {
u := fmt.Sprintf("applications/%d", application)
req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}

199
vendor/github.com/xanzy/go-gitlab/audit_events.go generated vendored Normal file
View File

@ -0,0 +1,199 @@
package gitlab
import (
"fmt"
"net/http"
"time"
)
// AuditEvent represents an audit event for a group, a project or the instance.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/audit_events.html
type AuditEvent struct {
ID int `json:"id"`
AuthorID int `json:"author_id"`
EntityID int `json:"entity_id"`
EntityType string `json:"entity_type"`
Details AuditEventDetails `json:"details"`
CreatedAt *time.Time `json:"created_at"`
}
// AuditEventDetails represents the details portion of an audit event for
// a group, a project or the instance. The exact fields that are returned
// for an audit event depend on the action being recorded.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/audit_events.html
type AuditEventDetails struct {
With string `json:"with"`
Add string `json:"add"`
As string `json:"as"`
Change string `json:"change"`
From string `json:"from"`
To string `json:"to"`
Remove string `json:"remove"`
CustomMessage string `json:"custom_message"`
AuthorName string `json:"author_name"`
TargetID interface{} `json:"target_id"`
TargetType string `json:"target_type"`
TargetDetails string `json:"target_details"`
IPAddress string `json:"ip_address"`
EntityPath string `json:"entity_path"`
FailedLogin string `json:"failed_login"`
}
// AuditEventsService handles communication with the project/group/instance
// audit event related methods of the GitLab API.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/audit_events.html
type AuditEventsService struct {
client *Client
}
// ListAuditEventsOptions represents the available ListProjectAuditEvents(),
// ListGroupAuditEvents() or ListInstanceAuditEvents() options.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/audit_events.html
type ListAuditEventsOptions struct {
ListOptions
CreatedAfter *time.Time `url:"created_after,omitempty" json:"created_after,omitempty"`
CreatedBefore *time.Time `url:"created_before,omitempty" json:"created_before,omitempty"`
}
// ListInstanceAuditEvents gets a list of audit events for instance.
// Authentication as Administrator is required.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/audit_events.html#retrieve-all-instance-audit-events
func (s *AuditEventsService) ListInstanceAuditEvents(opt *ListAuditEventsOptions, options ...RequestOptionFunc) ([]*AuditEvent, *Response, error) {
req, err := s.client.NewRequest(http.MethodGet, "audit_events", opt, options)
if err != nil {
return nil, nil, err
}
var aes []*AuditEvent
resp, err := s.client.Do(req, &aes)
if err != nil {
return nil, resp, err
}
return aes, resp, err
}
// GetInstanceAuditEvent gets a specific instance audit event.
// Authentication as Administrator is required.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/audit_events.html#retrieve-single-instance-audit-event
func (s *AuditEventsService) GetInstanceAuditEvent(event int, options ...RequestOptionFunc) (*AuditEvent, *Response, error) {
u := fmt.Sprintf("audit_events/%d", event)
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}
ae := new(AuditEvent)
resp, err := s.client.Do(req, ae)
if err != nil {
return nil, resp, err
}
return ae, resp, err
}
// ListGroupAuditEvents gets a list of audit events for the specified group
// viewable by the authenticated user.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/audit_events.html#retrieve-all-group-audit-events
func (s *AuditEventsService) ListGroupAuditEvents(gid interface{}, opt *ListAuditEventsOptions, options ...RequestOptionFunc) ([]*AuditEvent, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/audit_events", PathEscape(group))
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
var aes []*AuditEvent
resp, err := s.client.Do(req, &aes)
if err != nil {
return nil, resp, err
}
return aes, resp, err
}
// GetGroupAuditEvent gets a specific group audit event.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/audit_events.html#retrieve-a-specific-group-audit-event
func (s *AuditEventsService) GetGroupAuditEvent(gid interface{}, event int, options ...RequestOptionFunc) (*AuditEvent, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/audit_events/%d", PathEscape(group), event)
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}
ae := new(AuditEvent)
resp, err := s.client.Do(req, ae)
if err != nil {
return nil, resp, err
}
return ae, resp, err
}
// ListProjectAuditEvents gets a list of audit events for the specified project
// viewable by the authenticated user.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/audit_events.html#retrieve-all-project-audit-events
func (s *AuditEventsService) ListProjectAuditEvents(pid interface{}, opt *ListAuditEventsOptions, options ...RequestOptionFunc) ([]*AuditEvent, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/audit_events", PathEscape(project))
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
var aes []*AuditEvent
resp, err := s.client.Do(req, &aes)
if err != nil {
return nil, resp, err
}
return aes, resp, err
}
// GetProjectAuditEvent gets a specific project audit event.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/audit_events.html#retrieve-a-specific-project-audit-event
func (s *AuditEventsService) GetProjectAuditEvent(pid interface{}, event int, options ...RequestOptionFunc) (*AuditEvent, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/audit_events/%d", PathEscape(project), event)
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}
ae := new(AuditEvent)
resp, err := s.client.Do(req, ae)
if err != nil {
return nil, resp, err
}
return ae, resp, err
}

64
vendor/github.com/xanzy/go-gitlab/avatar.go generated vendored Normal file
View File

@ -0,0 +1,64 @@
//
// Copyright 2021, Pavel Kostohrys
//
// 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"
)
// AvatarRequestsService handles communication with the avatar related methods
// of the GitLab API.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/avatar.html
type AvatarRequestsService struct {
client *Client
}
// Avatar represents a GitLab avatar.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/avatar.html
type Avatar struct {
AvatarURL string `json:"avatar_url"`
}
// GetAvatarOptions represents the available GetAvatar() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/avatar.html#get-a-single-avatar-url
type GetAvatarOptions struct {
Email *string `url:"email,omitempty" json:"email,omitempty"`
Size *int `url:"size,omitempty" json:"size,omitempty"`
}
// GetAvatar gets the avatar URL for a user with the given email address.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/avatar.html#get-a-single-avatar-url
func (s *AvatarRequestsService) GetAvatar(opt *GetAvatarOptions, options ...RequestOptionFunc) (*Avatar, *Response, error) {
req, err := s.client.NewRequest(http.MethodGet, "avatar", opt, options)
if err != nil {
return nil, nil, err
}
avatar := new(Avatar)
response, err := s.client.Do(req, avatar)
if err != nil {
return nil, response, err
}
return avatar, response, nil
}

468
vendor/github.com/xanzy/go-gitlab/award_emojis.go generated vendored Normal file
View File

@ -0,0 +1,468 @@
//
// Copyright 2021, Arkbriar
//
// 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"
"time"
)
// AwardEmojiService handles communication with the emoji awards related methods
// of the GitLab API.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/award_emoji.html
type AwardEmojiService struct {
client *Client
}
// AwardEmoji represents a GitLab Award Emoji.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/award_emoji.html
type AwardEmoji struct {
ID int `json:"id"`
Name string `json:"name"`
User struct {
Name string `json:"name"`
Username string `json:"username"`
ID int `json:"id"`
State string `json:"state"`
AvatarURL string `json:"avatar_url"`
WebURL string `json:"web_url"`
} `json:"user"`
CreatedAt *time.Time `json:"created_at"`
UpdatedAt *time.Time `json:"updated_at"`
AwardableID int `json:"awardable_id"`
AwardableType string `json:"awardable_type"`
}
const (
awardMergeRequest = "merge_requests"
awardIssue = "issues"
awardSnippets = "snippets"
)
// ListAwardEmojiOptions represents the available options for listing emoji
// for each resources
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/award_emoji.html
type ListAwardEmojiOptions ListOptions
// ListMergeRequestAwardEmoji gets a list of all award emoji on the merge request.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/award_emoji.html#list-an-awardables-award-emojis
func (s *AwardEmojiService) ListMergeRequestAwardEmoji(pid interface{}, mergeRequestIID int, opt *ListAwardEmojiOptions, options ...RequestOptionFunc) ([]*AwardEmoji, *Response, error) {
return s.listAwardEmoji(pid, awardMergeRequest, mergeRequestIID, opt, options...)
}
// ListIssueAwardEmoji gets a list of all award emoji on the issue.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/award_emoji.html#list-an-awardables-award-emojis
func (s *AwardEmojiService) ListIssueAwardEmoji(pid interface{}, issueIID int, opt *ListAwardEmojiOptions, options ...RequestOptionFunc) ([]*AwardEmoji, *Response, error) {
return s.listAwardEmoji(pid, awardIssue, issueIID, opt, options...)
}
// ListSnippetAwardEmoji gets a list of all award emoji on the snippet.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/award_emoji.html#list-an-awardables-award-emojis
func (s *AwardEmojiService) ListSnippetAwardEmoji(pid interface{}, snippetID int, opt *ListAwardEmojiOptions, options ...RequestOptionFunc) ([]*AwardEmoji, *Response, error) {
return s.listAwardEmoji(pid, awardSnippets, snippetID, opt, options...)
}
func (s *AwardEmojiService) listAwardEmoji(pid interface{}, resource string, resourceID int, opt *ListAwardEmojiOptions, options ...RequestOptionFunc) ([]*AwardEmoji, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/%s/%d/award_emoji",
PathEscape(project),
resource,
resourceID,
)
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
var as []*AwardEmoji
resp, err := s.client.Do(req, &as)
if err != nil {
return nil, resp, err
}
return as, resp, err
}
// GetMergeRequestAwardEmoji get an award emoji from merge request.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/award_emoji.html#get-single-award-emoji
func (s *AwardEmojiService) GetMergeRequestAwardEmoji(pid interface{}, mergeRequestIID, awardID int, options ...RequestOptionFunc) (*AwardEmoji, *Response, error) {
return s.getAwardEmoji(pid, awardMergeRequest, mergeRequestIID, awardID, options...)
}
// GetIssueAwardEmoji get an award emoji from issue.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/award_emoji.html#get-single-award-emoji
func (s *AwardEmojiService) GetIssueAwardEmoji(pid interface{}, issueIID, awardID int, options ...RequestOptionFunc) (*AwardEmoji, *Response, error) {
return s.getAwardEmoji(pid, awardIssue, issueIID, awardID, options...)
}
// GetSnippetAwardEmoji get an award emoji from snippet.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/award_emoji.html#get-single-award-emoji
func (s *AwardEmojiService) GetSnippetAwardEmoji(pid interface{}, snippetID, awardID int, options ...RequestOptionFunc) (*AwardEmoji, *Response, error) {
return s.getAwardEmoji(pid, awardSnippets, snippetID, awardID, options...)
}
func (s *AwardEmojiService) getAwardEmoji(pid interface{}, resource string, resourceID, awardID int, options ...RequestOptionFunc) (*AwardEmoji, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/%s/%d/award_emoji/%d",
PathEscape(project),
resource,
resourceID,
awardID,
)
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}
a := new(AwardEmoji)
resp, err := s.client.Do(req, &a)
if err != nil {
return nil, resp, err
}
return a, resp, err
}
// CreateAwardEmojiOptions represents the available options for awarding emoji
// for a resource
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/award_emoji.html#award-a-new-emoji
type CreateAwardEmojiOptions struct {
Name string `json:"name"`
}
// CreateMergeRequestAwardEmoji get an award emoji from merge request.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/award_emoji.html#award-a-new-emoji
func (s *AwardEmojiService) CreateMergeRequestAwardEmoji(pid interface{}, mergeRequestIID int, opt *CreateAwardEmojiOptions, options ...RequestOptionFunc) (*AwardEmoji, *Response, error) {
return s.createAwardEmoji(pid, awardMergeRequest, mergeRequestIID, opt, options...)
}
// CreateIssueAwardEmoji get an award emoji from issue.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/award_emoji.html#award-a-new-emoji
func (s *AwardEmojiService) CreateIssueAwardEmoji(pid interface{}, issueIID int, opt *CreateAwardEmojiOptions, options ...RequestOptionFunc) (*AwardEmoji, *Response, error) {
return s.createAwardEmoji(pid, awardIssue, issueIID, opt, options...)
}
// CreateSnippetAwardEmoji get an award emoji from snippet.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/award_emoji.html#award-a-new-emoji
func (s *AwardEmojiService) CreateSnippetAwardEmoji(pid interface{}, snippetID int, opt *CreateAwardEmojiOptions, options ...RequestOptionFunc) (*AwardEmoji, *Response, error) {
return s.createAwardEmoji(pid, awardSnippets, snippetID, opt, options...)
}
func (s *AwardEmojiService) createAwardEmoji(pid interface{}, resource string, resourceID int, opt *CreateAwardEmojiOptions, options ...RequestOptionFunc) (*AwardEmoji, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/%s/%d/award_emoji",
PathEscape(project),
resource,
resourceID,
)
req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
if err != nil {
return nil, nil, err
}
a := new(AwardEmoji)
resp, err := s.client.Do(req, &a)
if err != nil {
return nil, resp, err
}
return a, resp, err
}
// DeleteIssueAwardEmoji delete award emoji on an issue.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/award_emoji.html#delete-an-award-emoji
func (s *AwardEmojiService) DeleteIssueAwardEmoji(pid interface{}, issueIID, awardID int, options ...RequestOptionFunc) (*Response, error) {
return s.deleteAwardEmoji(pid, awardIssue, issueIID, awardID, options...)
}
// DeleteMergeRequestAwardEmoji delete award emoji on a merge request.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/award_emoji.html#delete-an-award-emoji
func (s *AwardEmojiService) DeleteMergeRequestAwardEmoji(pid interface{}, mergeRequestIID, awardID int, options ...RequestOptionFunc) (*Response, error) {
return s.deleteAwardEmoji(pid, awardMergeRequest, mergeRequestIID, awardID, options...)
}
// DeleteSnippetAwardEmoji delete award emoji on a snippet.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/award_emoji.html#delete-an-award-emoji
func (s *AwardEmojiService) DeleteSnippetAwardEmoji(pid interface{}, snippetID, awardID int, options ...RequestOptionFunc) (*Response, error) {
return s.deleteAwardEmoji(pid, awardSnippets, snippetID, awardID, options...)
}
// DeleteAwardEmoji Delete an award emoji on the specified resource.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/award_emoji.html#delete-an-award-emoji
func (s *AwardEmojiService) deleteAwardEmoji(pid interface{}, resource string, resourceID, awardID int, options ...RequestOptionFunc) (*Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("projects/%s/%s/%d/award_emoji/%d", PathEscape(project), resource,
resourceID, awardID)
req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}
// ListIssuesAwardEmojiOnNote gets a list of all award emoji on a note from the
// issue.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/award_emoji.html#list-a-comments-award-emojis
func (s *AwardEmojiService) ListIssuesAwardEmojiOnNote(pid interface{}, issueID, noteID int, opt *ListAwardEmojiOptions, options ...RequestOptionFunc) ([]*AwardEmoji, *Response, error) {
return s.listAwardEmojiOnNote(pid, awardIssue, issueID, noteID, opt, options...)
}
// ListMergeRequestAwardEmojiOnNote gets a list of all award emoji on a note
// from the merge request.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/award_emoji.html#list-a-comments-award-emojis
func (s *AwardEmojiService) ListMergeRequestAwardEmojiOnNote(pid interface{}, mergeRequestIID, noteID int, opt *ListAwardEmojiOptions, options ...RequestOptionFunc) ([]*AwardEmoji, *Response, error) {
return s.listAwardEmojiOnNote(pid, awardMergeRequest, mergeRequestIID, noteID, opt, options...)
}
// ListSnippetAwardEmojiOnNote gets a list of all award emoji on a note from the
// snippet.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/award_emoji.html#list-a-comments-award-emojis
func (s *AwardEmojiService) ListSnippetAwardEmojiOnNote(pid interface{}, snippetIID, noteID int, opt *ListAwardEmojiOptions, options ...RequestOptionFunc) ([]*AwardEmoji, *Response, error) {
return s.listAwardEmojiOnNote(pid, awardSnippets, snippetIID, noteID, opt, options...)
}
func (s *AwardEmojiService) listAwardEmojiOnNote(pid interface{}, resources string, ressourceID, noteID int, opt *ListAwardEmojiOptions, options ...RequestOptionFunc) ([]*AwardEmoji, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/%s/%d/notes/%d/award_emoji", PathEscape(project), resources,
ressourceID, noteID)
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
var as []*AwardEmoji
resp, err := s.client.Do(req, &as)
if err != nil {
return nil, resp, err
}
return as, resp, err
}
// GetIssuesAwardEmojiOnNote gets an award emoji on a note from an issue.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/award_emoji.html#get-an-award-emoji-for-a-comment
func (s *AwardEmojiService) GetIssuesAwardEmojiOnNote(pid interface{}, issueID, noteID, awardID int, options ...RequestOptionFunc) (*AwardEmoji, *Response, error) {
return s.getSingleNoteAwardEmoji(pid, awardIssue, issueID, noteID, awardID, options...)
}
// GetMergeRequestAwardEmojiOnNote gets an award emoji on a note from a
// merge request.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/award_emoji.html#get-an-award-emoji-for-a-comment
func (s *AwardEmojiService) GetMergeRequestAwardEmojiOnNote(pid interface{}, mergeRequestIID, noteID, awardID int, options ...RequestOptionFunc) (*AwardEmoji, *Response, error) {
return s.getSingleNoteAwardEmoji(pid, awardMergeRequest, mergeRequestIID, noteID, awardID,
options...)
}
// GetSnippetAwardEmojiOnNote gets an award emoji on a note from a snippet.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/award_emoji.html#get-an-award-emoji-for-a-comment
func (s *AwardEmojiService) GetSnippetAwardEmojiOnNote(pid interface{}, snippetIID, noteID, awardID int, options ...RequestOptionFunc) (*AwardEmoji, *Response, error) {
return s.getSingleNoteAwardEmoji(pid, awardSnippets, snippetIID, noteID, awardID, options...)
}
func (s *AwardEmojiService) getSingleNoteAwardEmoji(pid interface{}, ressource string, resourceID, noteID, awardID int, options ...RequestOptionFunc) (*AwardEmoji, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/%s/%d/notes/%d/award_emoji/%d",
PathEscape(project),
ressource,
resourceID,
noteID,
awardID,
)
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}
a := new(AwardEmoji)
resp, err := s.client.Do(req, &a)
if err != nil {
return nil, resp, err
}
return a, resp, err
}
// CreateIssuesAwardEmojiOnNote gets an award emoji on a note from an issue.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/award_emoji.html#award-a-new-emoji-on-a-comment
func (s *AwardEmojiService) CreateIssuesAwardEmojiOnNote(pid interface{}, issueID, noteID int, opt *CreateAwardEmojiOptions, options ...RequestOptionFunc) (*AwardEmoji, *Response, error) {
return s.createAwardEmojiOnNote(pid, awardIssue, issueID, noteID, opt, options...)
}
// CreateMergeRequestAwardEmojiOnNote gets an award emoji on a note from a
// merge request.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/award_emoji.html#award-a-new-emoji-on-a-comment
func (s *AwardEmojiService) CreateMergeRequestAwardEmojiOnNote(pid interface{}, mergeRequestIID, noteID int, opt *CreateAwardEmojiOptions, options ...RequestOptionFunc) (*AwardEmoji, *Response, error) {
return s.createAwardEmojiOnNote(pid, awardMergeRequest, mergeRequestIID, noteID, opt, options...)
}
// CreateSnippetAwardEmojiOnNote gets an award emoji on a note from a snippet.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/award_emoji.html#award-a-new-emoji-on-a-comment
func (s *AwardEmojiService) CreateSnippetAwardEmojiOnNote(pid interface{}, snippetIID, noteID int, opt *CreateAwardEmojiOptions, options ...RequestOptionFunc) (*AwardEmoji, *Response, error) {
return s.createAwardEmojiOnNote(pid, awardSnippets, snippetIID, noteID, opt, options...)
}
// CreateAwardEmojiOnNote award emoji on a note.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/award_emoji.html#award-a-new-emoji-on-a-comment
func (s *AwardEmojiService) createAwardEmojiOnNote(pid interface{}, resource string, resourceID, noteID int, opt *CreateAwardEmojiOptions, options ...RequestOptionFunc) (*AwardEmoji, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/%s/%d/notes/%d/award_emoji",
PathEscape(project),
resource,
resourceID,
noteID,
)
req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
if err != nil {
return nil, nil, err
}
a := new(AwardEmoji)
resp, err := s.client.Do(req, &a)
if err != nil {
return nil, resp, err
}
return a, resp, err
}
// DeleteIssuesAwardEmojiOnNote deletes an award emoji on a note from an issue.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/award_emoji.html#delete-an-award-emoji-from-a-comment
func (s *AwardEmojiService) DeleteIssuesAwardEmojiOnNote(pid interface{}, issueID, noteID, awardID int, options ...RequestOptionFunc) (*Response, error) {
return s.deleteAwardEmojiOnNote(pid, awardIssue, issueID, noteID, awardID, options...)
}
// DeleteMergeRequestAwardEmojiOnNote deletes an award emoji on a note from a
// merge request.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/award_emoji.html#delete-an-award-emoji-from-a-comment
func (s *AwardEmojiService) DeleteMergeRequestAwardEmojiOnNote(pid interface{}, mergeRequestIID, noteID, awardID int, options ...RequestOptionFunc) (*Response, error) {
return s.deleteAwardEmojiOnNote(pid, awardMergeRequest, mergeRequestIID, noteID, awardID,
options...)
}
// DeleteSnippetAwardEmojiOnNote deletes an award emoji on a note from a snippet.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/award_emoji.html#delete-an-award-emoji-from-a-comment
func (s *AwardEmojiService) DeleteSnippetAwardEmojiOnNote(pid interface{}, snippetIID, noteID, awardID int, options ...RequestOptionFunc) (*Response, error) {
return s.deleteAwardEmojiOnNote(pid, awardSnippets, snippetIID, noteID, awardID, options...)
}
func (s *AwardEmojiService) deleteAwardEmojiOnNote(pid interface{}, resource string, resourceID, noteID, awardID int, options ...RequestOptionFunc) (*Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("projects/%s/%s/%d/notes/%d/award_emoji/%d",
PathEscape(project),
resource,
resourceID,
noteID,
awardID,
)
req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}

367
vendor/github.com/xanzy/go-gitlab/boards.go generated vendored Normal file
View File

@ -0,0 +1,367 @@
//
// 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"
)
// IssueBoardsService handles communication with the issue board related
// methods of the GitLab API.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/boards.html
type IssueBoardsService struct {
client *Client
}
// IssueBoard represents a GitLab issue board.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/boards.html
type IssueBoard struct {
ID int `json:"id"`
Name string `json:"name"`
Project *Project `json:"project"`
Milestone *Milestone `json:"milestone"`
Assignee *struct {
ID int `json:"id"`
Username string `json:"username"`
Name string `json:"name"`
State string `json:"state"`
AvatarURL string `json:"avatar_url"`
WebURL string `json:"web_url"`
} `json:"assignee"`
Lists []*BoardList `json:"lists"`
Weight int `json:"weight"`
Labels []*LabelDetails `json:"labels"`
}
func (b IssueBoard) String() string {
return Stringify(b)
}
// BoardList represents a GitLab board list.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/boards.html
type BoardList struct {
ID int `json:"id"`
Assignee *struct {
ID int `json:"id"`
Name string `json:"name"`
Username string `json:"username"`
} `json:"assignee"`
Iteration *ProjectIteration `json:"iteration"`
Label *Label `json:"label"`
MaxIssueCount int `json:"max_issue_count"`
MaxIssueWeight int `json:"max_issue_weight"`
Milestone *Milestone `json:"milestone"`
Position int `json:"position"`
}
func (b BoardList) String() string {
return Stringify(b)
}
// CreateIssueBoardOptions represents the available CreateIssueBoard() options.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/boards.html#create-an-issue-board
type CreateIssueBoardOptions struct {
Name *string `url:"name,omitempty" json:"name,omitempty"`
}
// CreateIssueBoard creates a new issue board.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/boards.html#create-an-issue-board
func (s *IssueBoardsService) CreateIssueBoard(pid interface{}, opt *CreateIssueBoardOptions, options ...RequestOptionFunc) (*IssueBoard, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/boards", PathEscape(project))
req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
if err != nil {
return nil, nil, err
}
board := new(IssueBoard)
resp, err := s.client.Do(req, board)
if err != nil {
return nil, resp, err
}
return board, resp, err
}
// UpdateIssueBoardOptions represents the available UpdateIssueBoard() options.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/boards.html#update-an-issue-board
type UpdateIssueBoardOptions struct {
Name *string `url:"name,omitempty" json:"name,omitempty"`
AssigneeID *int `url:"assignee_id,omitempty" json:"assignee_id,omitempty"`
MilestoneID *int `url:"milestone_id,omitempty" json:"milestone_id,omitempty"`
Labels *Labels `url:"labels,omitempty" json:"labels,omitempty"`
Weight *int `url:"weight,omitempty" json:"weight,omitempty"`
}
// UpdateIssueBoard update an issue board.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/boards.html#update-an-issue-board
func (s *IssueBoardsService) UpdateIssueBoard(pid interface{}, board int, opt *UpdateIssueBoardOptions, options ...RequestOptionFunc) (*IssueBoard, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/boards/%d", PathEscape(project), board)
req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
if err != nil {
return nil, nil, err
}
is := new(IssueBoard)
resp, err := s.client.Do(req, is)
if err != nil {
return nil, resp, err
}
return is, resp, err
}
// DeleteIssueBoard deletes an issue board.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/boards.html#delete-an-issue-board
func (s *IssueBoardsService) DeleteIssueBoard(pid interface{}, board int, options ...RequestOptionFunc) (*Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("projects/%s/boards/%d", PathEscape(project), board)
req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}
// ListIssueBoardsOptions represents the available ListIssueBoards() options.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/boards.html#list-project-issue-boards
type ListIssueBoardsOptions ListOptions
// ListIssueBoards gets a list of all issue boards in a project.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/boards.html#list-project-issue-boards
func (s *IssueBoardsService) ListIssueBoards(pid interface{}, opt *ListIssueBoardsOptions, options ...RequestOptionFunc) ([]*IssueBoard, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/boards", PathEscape(project))
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
var is []*IssueBoard
resp, err := s.client.Do(req, &is)
if err != nil {
return nil, resp, err
}
return is, resp, err
}
// GetIssueBoard gets a single issue board of a project.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/boards.html#show-a-single-issue-board
func (s *IssueBoardsService) GetIssueBoard(pid interface{}, board int, options ...RequestOptionFunc) (*IssueBoard, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/boards/%d", PathEscape(project), board)
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}
ib := new(IssueBoard)
resp, err := s.client.Do(req, ib)
if err != nil {
return nil, resp, err
}
return ib, resp, err
}
// GetIssueBoardListsOptions represents the available GetIssueBoardLists() options.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/boards.html#list-board-lists-in-a-project-issue-board
type GetIssueBoardListsOptions ListOptions
// GetIssueBoardLists gets a list of the issue board's lists. Does not include
// backlog and closed lists.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/boards.html#list-board-lists-in-a-project-issue-board
func (s *IssueBoardsService) GetIssueBoardLists(pid interface{}, board int, opt *GetIssueBoardListsOptions, options ...RequestOptionFunc) ([]*BoardList, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/boards/%d/lists", PathEscape(project), board)
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
var bl []*BoardList
resp, err := s.client.Do(req, &bl)
if err != nil {
return nil, resp, err
}
return bl, resp, err
}
// GetIssueBoardList gets a single issue board list.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/boards.html#show-a-single-board-list
func (s *IssueBoardsService) GetIssueBoardList(pid interface{}, board, list int, options ...RequestOptionFunc) (*BoardList, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/boards/%d/lists/%d",
PathEscape(project),
board,
list,
)
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}
bl := new(BoardList)
resp, err := s.client.Do(req, bl)
if err != nil {
return nil, resp, err
}
return bl, resp, err
}
// CreateIssueBoardListOptions represents the available CreateIssueBoardList()
// options.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/boards.html#create-a-board-list
type CreateIssueBoardListOptions struct {
LabelID *int `url:"label_id,omitempty" json:"label_id,omitempty"`
AssigneeID *int `url:"assignee_id,omitempty" json:"assignee_id,omitempty"`
MilestoneID *int `url:"milestone_id,omitempty" json:"milestone_id,omitempty"`
IterationID *int `url:"iteration_id,omitempty" json:"iteration_id,omitempty"`
}
// CreateIssueBoardList creates a new issue board list.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/boards.html#create-a-board-list
func (s *IssueBoardsService) CreateIssueBoardList(pid interface{}, board int, opt *CreateIssueBoardListOptions, options ...RequestOptionFunc) (*BoardList, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/boards/%d/lists", PathEscape(project), board)
req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
if err != nil {
return nil, nil, err
}
bl := new(BoardList)
resp, err := s.client.Do(req, bl)
if err != nil {
return nil, resp, err
}
return bl, resp, err
}
// UpdateIssueBoardListOptions represents the available UpdateIssueBoardList()
// options.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/boards.html#reorder-a-list-in-a-board
type UpdateIssueBoardListOptions struct {
Position *int `url:"position" json:"position"`
}
// UpdateIssueBoardList updates the position of an existing issue board list.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/boards.html#reorder-a-list-in-a-board
func (s *IssueBoardsService) UpdateIssueBoardList(pid interface{}, board, list int, opt *UpdateIssueBoardListOptions, options ...RequestOptionFunc) (*BoardList, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/boards/%d/lists/%d",
PathEscape(project),
board,
list,
)
req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
if err != nil {
return nil, nil, err
}
bl := new(BoardList)
resp, err := s.client.Do(req, bl)
if err != nil {
return nil, resp, err
}
return bl, resp, err
}
// DeleteIssueBoardList soft deletes an issue board list. Only for admins and
// project owners.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/boards.html#delete-a-board-list-from-a-board
func (s *IssueBoardsService) DeleteIssueBoardList(pid interface{}, board, list int, options ...RequestOptionFunc) (*Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("projects/%s/boards/%d/lists/%d",
PathEscape(project),
board,
list,
)
req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}

251
vendor/github.com/xanzy/go-gitlab/branches.go generated vendored Normal file
View File

@ -0,0 +1,251 @@
//
// 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"
"net/url"
)
// BranchesService handles communication with the branch related methods
// of the GitLab API.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/branches.html
type BranchesService struct {
client *Client
}
// Branch represents a GitLab branch.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/branches.html
type Branch struct {
Commit *Commit `json:"commit"`
Name string `json:"name"`
Protected bool `json:"protected"`
Merged bool `json:"merged"`
Default bool `json:"default"`
CanPush bool `json:"can_push"`
DevelopersCanPush bool `json:"developers_can_push"`
DevelopersCanMerge bool `json:"developers_can_merge"`
WebURL string `json:"web_url"`
}
func (b Branch) String() string {
return Stringify(b)
}
// ListBranchesOptions represents the available ListBranches() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/branches.html#list-repository-branches
type ListBranchesOptions struct {
ListOptions
Search *string `url:"search,omitempty" json:"search,omitempty"`
}
// ListBranches gets a list of repository branches from a project, sorted by
// name alphabetically.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/branches.html#list-repository-branches
func (s *BranchesService) ListBranches(pid interface{}, opts *ListBranchesOptions, options ...RequestOptionFunc) ([]*Branch, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/repository/branches", PathEscape(project))
req, err := s.client.NewRequest(http.MethodGet, u, opts, options)
if err != nil {
return nil, nil, err
}
var b []*Branch
resp, err := s.client.Do(req, &b)
if err != nil {
return nil, resp, err
}
return b, resp, err
}
// GetBranch gets a single project repository branch.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/branches.html#get-single-repository-branch
func (s *BranchesService) GetBranch(pid interface{}, branch string, options ...RequestOptionFunc) (*Branch, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/repository/branches/%s", PathEscape(project), url.PathEscape(branch))
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}
b := new(Branch)
resp, err := s.client.Do(req, b)
if err != nil {
return nil, resp, err
}
return b, resp, err
}
// ProtectBranchOptions represents the available ProtectBranch() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/branches.html#protect-repository-branch
type ProtectBranchOptions struct {
DevelopersCanPush *bool `url:"developers_can_push,omitempty" json:"developers_can_push,omitempty"`
DevelopersCanMerge *bool `url:"developers_can_merge,omitempty" json:"developers_can_merge,omitempty"`
}
// ProtectBranch protects a single project repository branch. This is an
// 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) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/repository/branches/%s/protect", PathEscape(project), url.PathEscape(branch))
req, err := s.client.NewRequest(http.MethodPut, u, opts, options)
if err != nil {
return nil, nil, err
}
b := new(Branch)
resp, err := s.client.Do(req, b)
if err != nil {
return nil, resp, err
}
return b, resp, err
}
// UnprotectBranch unprotects a single project repository branch. This is an
// 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) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/repository/branches/%s/unprotect", PathEscape(project), url.PathEscape(branch))
req, err := s.client.NewRequest(http.MethodPut, u, nil, options)
if err != nil {
return nil, nil, err
}
b := new(Branch)
resp, err := s.client.Do(req, b)
if err != nil {
return nil, resp, err
}
return b, resp, err
}
// CreateBranchOptions represents the available CreateBranch() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/branches.html#create-repository-branch
type CreateBranchOptions struct {
Branch *string `url:"branch,omitempty" json:"branch,omitempty"`
Ref *string `url:"ref,omitempty" json:"ref,omitempty"`
}
// CreateBranch creates branch from commit SHA or existing branch.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/branches.html#create-repository-branch
func (s *BranchesService) CreateBranch(pid interface{}, opt *CreateBranchOptions, options ...RequestOptionFunc) (*Branch, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/repository/branches", PathEscape(project))
req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
if err != nil {
return nil, nil, err
}
b := new(Branch)
resp, err := s.client.Do(req, b)
if err != nil {
return nil, resp, err
}
return b, resp, err
}
// DeleteBranch deletes an existing branch.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/branches.html#delete-repository-branch
func (s *BranchesService) DeleteBranch(pid interface{}, branch string, options ...RequestOptionFunc) (*Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("projects/%s/repository/branches/%s", PathEscape(project), url.PathEscape(branch))
req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}
// DeleteMergedBranches deletes all branches that are merged into the project's default branch.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/branches.html#delete-merged-branches
func (s *BranchesService) DeleteMergedBranches(pid interface{}, options ...RequestOptionFunc) (*Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("projects/%s/repository/merged_branches", PathEscape(project))
req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}

191
vendor/github.com/xanzy/go-gitlab/broadcast_messages.go generated vendored Normal file
View File

@ -0,0 +1,191 @@
//
// 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"
"time"
)
// BroadcastMessagesService handles communication with the broadcast
// messages methods of the GitLab API.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/broadcast_messages.html
type BroadcastMessagesService struct {
client *Client
}
// BroadcastMessage represents a GitLab issue board.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/broadcast_messages.html#get-all-broadcast-messages
type BroadcastMessage struct {
Message string `json:"message"`
StartsAt *time.Time `json:"starts_at"`
EndsAt *time.Time `json:"ends_at"`
Font string `json:"font"`
ID int `json:"id"`
Active bool `json:"active"`
TargetAccessLevels []AccessLevelValue `json:"target_access_levels"`
TargetPath string `json:"target_path"`
BroadcastType string `json:"broadcast_type"`
Dismissable bool `json:"dismissable"`
// Deprecated: This parameter was removed in GitLab 15.6.
Color string `json:"color"`
}
// ListBroadcastMessagesOptions represents the available ListBroadcastMessages()
// options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/broadcast_messages.html#get-all-broadcast-messages
type ListBroadcastMessagesOptions ListOptions
// ListBroadcastMessages gets a list of all broadcasted messages.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/broadcast_messages.html#get-all-broadcast-messages
func (s *BroadcastMessagesService) ListBroadcastMessages(opt *ListBroadcastMessagesOptions, options ...RequestOptionFunc) ([]*BroadcastMessage, *Response, error) {
req, err := s.client.NewRequest(http.MethodGet, "broadcast_messages", opt, options)
if err != nil {
return nil, nil, err
}
var bs []*BroadcastMessage
resp, err := s.client.Do(req, &bs)
if err != nil {
return nil, resp, err
}
return bs, resp, err
}
// GetBroadcastMessage gets a single broadcast message.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/broadcast_messages.html#get-a-specific-broadcast-message
func (s *BroadcastMessagesService) GetBroadcastMessage(broadcast int, options ...RequestOptionFunc) (*BroadcastMessage, *Response, error) {
u := fmt.Sprintf("broadcast_messages/%d", broadcast)
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}
b := new(BroadcastMessage)
resp, err := s.client.Do(req, &b)
if err != nil {
return nil, resp, err
}
return b, resp, err
}
// CreateBroadcastMessageOptions represents the available CreateBroadcastMessage()
// options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/broadcast_messages.html#create-a-broadcast-message
type CreateBroadcastMessageOptions struct {
Message *string `url:"message" json:"message"`
StartsAt *time.Time `url:"starts_at,omitempty" json:"starts_at,omitempty"`
EndsAt *time.Time `url:"ends_at,omitempty" json:"ends_at,omitempty"`
Font *string `url:"font,omitempty" json:"font,omitempty"`
TargetAccessLevels []AccessLevelValue `url:"target_access_levels,omitempty" json:"target_access_levels,omitempty"`
TargetPath *string `url:"target_path,omitempty" json:"target_path,omitempty"`
BroadcastType *string `url:"broadcast_type,omitempty" json:"broadcast_type,omitempty"`
Dismissable *bool `url:"dismissable,omitempty" json:"dismissable,omitempty"`
// Deprecated: This parameter was removed in GitLab 15.6.
Color *string `url:"color,omitempty" json:"color,omitempty"`
}
// CreateBroadcastMessage creates a message to broadcast.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/broadcast_messages.html#create-a-broadcast-message
func (s *BroadcastMessagesService) CreateBroadcastMessage(opt *CreateBroadcastMessageOptions, options ...RequestOptionFunc) (*BroadcastMessage, *Response, error) {
req, err := s.client.NewRequest(http.MethodPost, "broadcast_messages", opt, options)
if err != nil {
return nil, nil, err
}
b := new(BroadcastMessage)
resp, err := s.client.Do(req, &b)
if err != nil {
return nil, resp, err
}
return b, resp, err
}
// UpdateBroadcastMessageOptions represents the available CreateBroadcastMessage()
// options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/broadcast_messages.html#update-a-broadcast-message
type UpdateBroadcastMessageOptions struct {
Message *string `url:"message,omitempty" json:"message,omitempty"`
StartsAt *time.Time `url:"starts_at,omitempty" json:"starts_at,omitempty"`
EndsAt *time.Time `url:"ends_at,omitempty" json:"ends_at,omitempty"`
Font *string `url:"font,omitempty" json:"font,omitempty"`
TargetAccessLevels []AccessLevelValue `url:"target_access_levels,omitempty" json:"target_access_levels,omitempty"`
TargetPath *string `url:"target_path,omitempty" json:"target_path,omitempty"`
BroadcastType *string `url:"broadcast_type,omitempty" json:"broadcast_type,omitempty"`
Dismissable *bool `url:"dismissable,omitempty" json:"dismissable,omitempty"`
// Deprecated: This parameter was removed in GitLab 15.6.
Color *string `url:"color,omitempty" json:"color,omitempty"`
}
// UpdateBroadcastMessage update a broadcasted message.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/broadcast_messages.html#update-a-broadcast-message
func (s *BroadcastMessagesService) UpdateBroadcastMessage(broadcast int, opt *UpdateBroadcastMessageOptions, options ...RequestOptionFunc) (*BroadcastMessage, *Response, error) {
u := fmt.Sprintf("broadcast_messages/%d", broadcast)
req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
if err != nil {
return nil, nil, err
}
b := new(BroadcastMessage)
resp, err := s.client.Do(req, &b)
if err != nil {
return nil, resp, err
}
return b, resp, err
}
// DeleteBroadcastMessage deletes a broadcasted message.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/broadcast_messages.html#delete-a-broadcast-message
func (s *BroadcastMessagesService) DeleteBroadcastMessage(broadcast int, options ...RequestOptionFunc) (*Response, error) {
u := fmt.Sprintf("broadcast_messages/%d", broadcast)
req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}

95
vendor/github.com/xanzy/go-gitlab/ci_yml_templates.go generated vendored Normal file
View File

@ -0,0 +1,95 @@
//
// 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"
)
// CIYMLTemplatesService handles communication with the gitlab
// CI YML templates related methods of the GitLab API.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/templates/gitlab_ci_ymls.html
type CIYMLTemplatesService struct {
client *Client
}
// CIYMLTemplate represents a GitLab CI YML template.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/templates/gitlab_ci_ymls.html
type CIYMLTemplate struct {
Name string `json:"name"`
Content string `json:"content"`
}
// CIYMLTemplateListItem represents a GitLab CI YML template from the list.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/templates/gitlab_ci_ymls.html
type CIYMLTemplateListItem struct {
Key string `json:"key"`
Name string `json:"name"`
}
// ListCIYMLTemplatesOptions represents the available ListAllTemplates() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/templates/gitlab_ci_ymls.html#list-gitlab-ci-yaml-templates
type ListCIYMLTemplatesOptions ListOptions
// ListAllTemplates get all GitLab CI YML templates.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/templates/gitlab_ci_ymls.html#list-gitlab-ci-yaml-templates
func (s *CIYMLTemplatesService) ListAllTemplates(opt *ListCIYMLTemplatesOptions, options ...RequestOptionFunc) ([]*CIYMLTemplateListItem, *Response, error) {
req, err := s.client.NewRequest(http.MethodGet, "templates/gitlab_ci_ymls", opt, options)
if err != nil {
return nil, nil, err
}
var cts []*CIYMLTemplateListItem
resp, err := s.client.Do(req, &cts)
if err != nil {
return nil, resp, err
}
return cts, resp, err
}
// GetTemplate get a single GitLab CI YML template.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/templates/gitlab_ci_ymls.html#single-gitlab-ci-yaml-template
func (s *CIYMLTemplatesService) GetTemplate(key string, options ...RequestOptionFunc) (*CIYMLTemplate, *Response, error) {
u := fmt.Sprintf("templates/gitlab_ci_ymls/%s", PathEscape(key))
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}
ct := new(CIYMLTemplate)
resp, err := s.client.Do(req, ct)
if err != nil {
return nil, resp, err
}
return ct, resp, err
}

142
vendor/github.com/xanzy/go-gitlab/client_options.go generated vendored Normal file
View File

@ -0,0 +1,142 @@
//
// 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 (
"net/http"
"time"
retryablehttp "github.com/hashicorp/go-retryablehttp"
)
// ClientOptionFunc can be used to customize a new GitLab API client.
type ClientOptionFunc func(*Client) error
// WithBaseURL sets the base URL for API requests to a custom endpoint.
func WithBaseURL(urlStr string) ClientOptionFunc {
return func(c *Client) error {
return c.setBaseURL(urlStr)
}
}
// WithCustomBackoff can be used to configure a custom backoff policy.
func WithCustomBackoff(backoff retryablehttp.Backoff) ClientOptionFunc {
return func(c *Client) error {
c.client.Backoff = backoff
return nil
}
}
// WithCustomLeveledLogger can be used to configure a custom retryablehttp
// leveled logger.
func WithCustomLeveledLogger(leveledLogger retryablehttp.LeveledLogger) ClientOptionFunc {
return func(c *Client) error {
c.client.Logger = leveledLogger
return nil
}
}
// WithCustomLimiter injects a custom rate limiter to the client.
func WithCustomLimiter(limiter RateLimiter) ClientOptionFunc {
return func(c *Client) error {
c.configureLimiterOnce.Do(func() {})
c.limiter = limiter
return nil
}
}
// WithCustomLogger can be used to configure a custom retryablehttp logger.
func WithCustomLogger(logger retryablehttp.Logger) ClientOptionFunc {
return func(c *Client) error {
c.client.Logger = logger
return nil
}
}
// WithCustomRetry can be used to configure a custom retry policy.
func WithCustomRetry(checkRetry retryablehttp.CheckRetry) ClientOptionFunc {
return func(c *Client) error {
c.client.CheckRetry = checkRetry
return nil
}
}
// WithCustomRetryMax can be used to configure a custom maximum number of retries.
func WithCustomRetryMax(retryMax int) ClientOptionFunc {
return func(c *Client) error {
c.client.RetryMax = retryMax
return nil
}
}
// WithCustomRetryWaitMinMax can be used to configure a custom minimum and
// maximum time to wait between retries.
func WithCustomRetryWaitMinMax(waitMin, waitMax time.Duration) ClientOptionFunc {
return func(c *Client) error {
c.client.RetryWaitMin = waitMin
c.client.RetryWaitMax = waitMax
return nil
}
}
// WithErrorHandler can be used to configure a custom error handler.
func WithErrorHandler(handler retryablehttp.ErrorHandler) ClientOptionFunc {
return func(c *Client) error {
c.client.ErrorHandler = handler
return nil
}
}
// WithHTTPClient can be used to configure a custom HTTP client.
func WithHTTPClient(httpClient *http.Client) ClientOptionFunc {
return func(c *Client) error {
c.client.HTTPClient = httpClient
return nil
}
}
// WithRequestLogHook can be used to configure a custom request log hook.
func WithRequestLogHook(hook retryablehttp.RequestLogHook) ClientOptionFunc {
return func(c *Client) error {
c.client.RequestLogHook = hook
return nil
}
}
// WithResponseLogHook can be used to configure a custom response log hook.
func WithResponseLogHook(hook retryablehttp.ResponseLogHook) ClientOptionFunc {
return func(c *Client) error {
c.client.ResponseLogHook = hook
return nil
}
}
// WithoutRetries disables the default retry logic.
func WithoutRetries() ClientOptionFunc {
return func(c *Client) error {
c.disableRetries = true
return nil
}
}
// WithRequestOptions can be used to configure default request options applied to every request.
func WithRequestOptions(options ...RequestOptionFunc) ClientOptionFunc {
return func(c *Client) error {
c.defaultRequestOptions = append(c.defaultRequestOptions, options...)
return nil
}
}

294
vendor/github.com/xanzy/go-gitlab/cluster_agents.go generated vendored Normal file
View File

@ -0,0 +1,294 @@
//
// Copyright 2022, Timo Furrer <tuxtimo@gmail.com>
//
// 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"
"time"
)
// ClusterAgentsService handles communication with the cluster agents related
// methods of the GitLab API.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/cluster_agents.html
type ClusterAgentsService struct {
client *Client
}
// Agent represents a GitLab agent for Kubernetes.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/cluster_agents.html
type Agent struct {
ID int `json:"id"`
Name string `json:"name"`
CreatedAt *time.Time `json:"created_at"`
CreatedByUserID int `json:"created_by_user_id"`
ConfigProject ConfigProject `json:"config_project"`
}
type ConfigProject struct {
ID int `json:"id"`
Description string `json:"description"`
Name string `json:"name"`
NameWithNamespace string `json:"name_with_namespace"`
Path string `json:"path"`
PathWithNamespace string `json:"path_with_namespace"`
CreatedAt *time.Time `json:"created_at"`
}
func (a Agent) String() string {
return Stringify(a)
}
// AgentToken represents a GitLab agent token.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/cluster_agents.html#list-tokens-for-an-agent
type AgentToken struct {
ID int `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
AgentID int `json:"agent_id"`
Status string `json:"status"`
CreatedAt *time.Time `json:"created_at"`
CreatedByUserID int `json:"created_by_user_id"`
LastUsedAt *time.Time `json:"last_used_at"`
Token string `json:"token"`
}
func (a AgentToken) String() string {
return Stringify(a)
}
// ListAgentsOptions represents the available ListAgents() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/cluster_agents.html#list-the-agents-for-a-project
type ListAgentsOptions ListOptions
// ListAgents returns a list of agents registered for the project.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/cluster_agents.html#list-the-agents-for-a-project
func (s *ClusterAgentsService) ListAgents(pid interface{}, opt *ListAgentsOptions, options ...RequestOptionFunc) ([]*Agent, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
uri := fmt.Sprintf("projects/%s/cluster_agents", PathEscape(project))
req, err := s.client.NewRequest(http.MethodGet, uri, opt, options)
if err != nil {
return nil, nil, err
}
var as []*Agent
resp, err := s.client.Do(req, &as)
if err != nil {
return nil, resp, err
}
return as, resp, err
}
// GetAgent gets a single agent details.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/cluster_agents.html#get-details-about-an-agent
func (s *ClusterAgentsService) GetAgent(pid interface{}, id int, options ...RequestOptionFunc) (*Agent, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
uri := fmt.Sprintf("projects/%s/cluster_agents/%d", PathEscape(project), id)
req, err := s.client.NewRequest(http.MethodGet, uri, nil, options)
if err != nil {
return nil, nil, err
}
a := new(Agent)
resp, err := s.client.Do(req, a)
if err != nil {
return nil, resp, err
}
return a, resp, err
}
// RegisterAgentOptions represents the available RegisterAgent()
// options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/cluster_agents.html#register-an-agent-with-a-project
type RegisterAgentOptions struct {
Name *string `url:"name,omitempty" json:"name,omitempty"`
}
// RegisterAgent registers an agent to the project.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/cluster_agents.html#register-an-agent-with-a-project
func (s *ClusterAgentsService) RegisterAgent(pid interface{}, opt *RegisterAgentOptions, options ...RequestOptionFunc) (*Agent, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
uri := fmt.Sprintf("projects/%s/cluster_agents", PathEscape(project))
req, err := s.client.NewRequest(http.MethodPost, uri, opt, options)
if err != nil {
return nil, nil, err
}
a := new(Agent)
resp, err := s.client.Do(req, a)
if err != nil {
return nil, resp, err
}
return a, resp, err
}
// DeleteAgent deletes an existing agent registration.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/cluster_agents.html#delete-a-registered-agent
func (s *ClusterAgentsService) DeleteAgent(pid interface{}, id int, options ...RequestOptionFunc) (*Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, err
}
uri := fmt.Sprintf("projects/%s/cluster_agents/%d", PathEscape(project), id)
req, err := s.client.NewRequest(http.MethodDelete, uri, nil, options)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}
// ListAgentTokensOptions represents the available ListAgentTokens() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/cluster_agents.html#list-tokens-for-an-agent
type ListAgentTokensOptions ListOptions
// ListAgentTokens returns a list of tokens for an agent.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/cluster_agents.html#list-tokens-for-an-agent
func (s *ClusterAgentsService) ListAgentTokens(pid interface{}, aid int, opt *ListAgentTokensOptions, options ...RequestOptionFunc) ([]*AgentToken, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
uri := fmt.Sprintf("projects/%s/cluster_agents/%d/tokens", PathEscape(project), aid)
req, err := s.client.NewRequest(http.MethodGet, uri, opt, options)
if err != nil {
return nil, nil, err
}
var ats []*AgentToken
resp, err := s.client.Do(req, &ats)
if err != nil {
return nil, resp, err
}
return ats, resp, err
}
// GetAgentToken gets a single agent token.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/cluster_agents.html#get-a-single-agent-token
func (s *ClusterAgentsService) GetAgentToken(pid interface{}, aid int, id int, options ...RequestOptionFunc) (*AgentToken, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
uri := fmt.Sprintf("projects/%s/cluster_agents/%d/tokens/%d", PathEscape(project), aid, id)
req, err := s.client.NewRequest(http.MethodGet, uri, nil, options)
if err != nil {
return nil, nil, err
}
at := new(AgentToken)
resp, err := s.client.Do(req, at)
if err != nil {
return nil, resp, err
}
return at, resp, err
}
// CreateAgentTokenOptions represents the available CreateAgentToken() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/cluster_agents.html#create-an-agent-token
type CreateAgentTokenOptions struct {
Name *string `url:"name,omitempty" json:"name,omitempty"`
Description *string `url:"description,omitempty" json:"description,omitempty"`
}
// CreateAgentToken creates a new token for an agent.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/cluster_agents.html#create-an-agent-token
func (s *ClusterAgentsService) CreateAgentToken(pid interface{}, aid int, opt *CreateAgentTokenOptions, options ...RequestOptionFunc) (*AgentToken, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
uri := fmt.Sprintf("projects/%s/cluster_agents/%d/tokens", PathEscape(project), aid)
req, err := s.client.NewRequest(http.MethodPost, uri, opt, options)
if err != nil {
return nil, nil, err
}
at := new(AgentToken)
resp, err := s.client.Do(req, at)
if err != nil {
return nil, resp, err
}
return at, resp, err
}
// RevokeAgentToken revokes an agent token.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/cluster_agents.html#revoke-an-agent-token
func (s *ClusterAgentsService) RevokeAgentToken(pid interface{}, aid int, id int, options ...RequestOptionFunc) (*Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, err
}
uri := fmt.Sprintf("projects/%s/cluster_agents/%d/tokens/%d", PathEscape(project), aid, id)
req, err := s.client.NewRequest(http.MethodDelete, uri, nil, options)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}

596
vendor/github.com/xanzy/go-gitlab/commits.go generated vendored Normal file
View File

@ -0,0 +1,596 @@
//
// 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"
"net/url"
"time"
)
// CommitsService handles communication with the commit related methods
// of the GitLab API.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/commits.html
type CommitsService struct {
client *Client
}
// Commit represents a GitLab commit.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/commits.html
type Commit struct {
ID string `json:"id"`
ShortID string `json:"short_id"`
Title string `json:"title"`
AuthorName string `json:"author_name"`
AuthorEmail string `json:"author_email"`
AuthoredDate *time.Time `json:"authored_date"`
CommitterName string `json:"committer_name"`
CommitterEmail string `json:"committer_email"`
CommittedDate *time.Time `json:"committed_date"`
CreatedAt *time.Time `json:"created_at"`
Message string `json:"message"`
ParentIDs []string `json:"parent_ids"`
Stats *CommitStats `json:"stats"`
Status *BuildStateValue `json:"status"`
LastPipeline *PipelineInfo `json:"last_pipeline"`
ProjectID int `json:"project_id"`
Trailers map[string]string `json:"trailers"`
WebURL string `json:"web_url"`
}
// CommitStats represents the number of added and deleted files in a commit.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/commits.html
type CommitStats struct {
Additions int `json:"additions"`
Deletions int `json:"deletions"`
Total int `json:"total"`
}
func (c Commit) String() string {
return Stringify(c)
}
// ListCommitsOptions represents the available ListCommits() options.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/commits.html#list-repository-commits
type ListCommitsOptions struct {
ListOptions
RefName *string `url:"ref_name,omitempty" json:"ref_name,omitempty"`
Since *time.Time `url:"since,omitempty" json:"since,omitempty"`
Until *time.Time `url:"until,omitempty" json:"until,omitempty"`
Path *string `url:"path,omitempty" json:"path,omitempty"`
All *bool `url:"all,omitempty" json:"all,omitempty"`
WithStats *bool `url:"with_stats,omitempty" json:"with_stats,omitempty"`
FirstParent *bool `url:"first_parent,omitempty" json:"first_parent,omitempty"`
Trailers *bool `url:"trailers,omitempty" json:"trailers,omitempty"`
}
// ListCommits gets a list of repository commits in a project.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/commits.html#list-repository-commits
func (s *CommitsService) ListCommits(pid interface{}, opt *ListCommitsOptions, options ...RequestOptionFunc) ([]*Commit, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/repository/commits", PathEscape(project))
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
var c []*Commit
resp, err := s.client.Do(req, &c)
if err != nil {
return nil, resp, err
}
return c, resp, err
}
// CommitRef represents the reference of branches/tags in a commit.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/commits.html#get-references-a-commit-is-pushed-to
type CommitRef struct {
Type string `json:"type"`
Name string `json:"name"`
}
// GetCommitRefsOptions represents the available GetCommitRefs() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/commits.html#get-references-a-commit-is-pushed-to
type GetCommitRefsOptions struct {
ListOptions
Type *string `url:"type,omitempty" json:"type,omitempty"`
}
// GetCommitRefs gets all references (from branches or tags) a commit is pushed to
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/commits.html#get-references-a-commit-is-pushed-to
func (s *CommitsService) GetCommitRefs(pid interface{}, sha string, opt *GetCommitRefsOptions, options ...RequestOptionFunc) ([]*CommitRef, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/repository/commits/%s/refs", PathEscape(project), url.PathEscape(sha))
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
var cs []*CommitRef
resp, err := s.client.Do(req, &cs)
if err != nil {
return nil, resp, err
}
return cs, resp, err
}
// GetCommit gets a specific commit identified by the commit hash or name of a
// branch or tag.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/commits.html#get-a-single-commit
func (s *CommitsService) GetCommit(pid interface{}, sha string, options ...RequestOptionFunc) (*Commit, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
if sha == "" {
return nil, nil, fmt.Errorf("SHA must be a non-empty string")
}
u := fmt.Sprintf("projects/%s/repository/commits/%s", PathEscape(project), url.PathEscape(sha))
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}
c := new(Commit)
resp, err := s.client.Do(req, c)
if err != nil {
return nil, resp, err
}
return c, resp, err
}
// CreateCommitOptions represents the available options for a new commit.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/commits.html#create-a-commit-with-multiple-files-and-actions
type CreateCommitOptions struct {
Branch *string `url:"branch,omitempty" json:"branch,omitempty"`
CommitMessage *string `url:"commit_message,omitempty" json:"commit_message,omitempty"`
StartBranch *string `url:"start_branch,omitempty" json:"start_branch,omitempty"`
StartSHA *string `url:"start_sha,omitempty" json:"start_sha,omitempty"`
StartProject *string `url:"start_project,omitempty" json:"start_project,omitempty"`
Actions []*CommitActionOptions `url:"actions" json:"actions"`
AuthorEmail *string `url:"author_email,omitempty" json:"author_email,omitempty"`
AuthorName *string `url:"author_name,omitempty" json:"author_name,omitempty"`
Stats *bool `url:"stats,omitempty" json:"stats,omitempty"`
Force *bool `url:"force,omitempty" json:"force,omitempty"`
}
// CommitActionOptions represents the available options for a new single
// file action.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/commits.html#create-a-commit-with-multiple-files-and-actions
type CommitActionOptions struct {
Action *FileActionValue `url:"action,omitempty" json:"action,omitempty"`
FilePath *string `url:"file_path,omitempty" json:"file_path,omitempty"`
PreviousPath *string `url:"previous_path,omitempty" json:"previous_path,omitempty"`
Content *string `url:"content,omitempty" json:"content,omitempty"`
Encoding *string `url:"encoding,omitempty" json:"encoding,omitempty"`
LastCommitID *string `url:"last_commit_id,omitempty" json:"last_commit_id,omitempty"`
ExecuteFilemode *bool `url:"execute_filemode,omitempty" json:"execute_filemode,omitempty"`
}
// CreateCommit creates a commit with multiple files and actions.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/commits.html#create-a-commit-with-multiple-files-and-actions
func (s *CommitsService) CreateCommit(pid interface{}, opt *CreateCommitOptions, options ...RequestOptionFunc) (*Commit, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/repository/commits", PathEscape(project))
req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
if err != nil {
return nil, nil, err
}
c := new(Commit)
resp, err := s.client.Do(req, &c)
if err != nil {
return nil, resp, err
}
return c, resp, err
}
// Diff represents a GitLab diff.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/commits.html
type Diff struct {
Diff string `json:"diff"`
NewPath string `json:"new_path"`
OldPath string `json:"old_path"`
AMode string `json:"a_mode"`
BMode string `json:"b_mode"`
NewFile bool `json:"new_file"`
RenamedFile bool `json:"renamed_file"`
DeletedFile bool `json:"deleted_file"`
}
func (d Diff) String() string {
return Stringify(d)
}
// GetCommitDiffOptions represents the available GetCommitDiff() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/commits.html#get-the-diff-of-a-commit
type GetCommitDiffOptions ListOptions
// GetCommitDiff gets the diff of a commit in a project..
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/commits.html#get-the-diff-of-a-commit
func (s *CommitsService) GetCommitDiff(pid interface{}, sha string, opt *GetCommitDiffOptions, options ...RequestOptionFunc) ([]*Diff, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/repository/commits/%s/diff", PathEscape(project), url.PathEscape(sha))
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
var d []*Diff
resp, err := s.client.Do(req, &d)
if err != nil {
return nil, resp, err
}
return d, resp, err
}
// CommitComment represents a GitLab commit comment.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/commits.html
type CommitComment struct {
Note string `json:"note"`
Path string `json:"path"`
Line int `json:"line"`
LineType string `json:"line_type"`
Author Author `json:"author"`
}
// Author represents a GitLab commit author
type Author struct {
ID int `json:"id"`
Username string `json:"username"`
Email string `json:"email"`
Name string `json:"name"`
State string `json:"state"`
Blocked bool `json:"blocked"`
CreatedAt *time.Time `json:"created_at"`
}
func (c CommitComment) String() string {
return Stringify(c)
}
// GetCommitCommentsOptions represents the available GetCommitComments() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/commits.html#get-the-comments-of-a-commit
type GetCommitCommentsOptions ListOptions
// GetCommitComments gets the comments of a commit in a project.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/commits.html#get-the-comments-of-a-commit
func (s *CommitsService) GetCommitComments(pid interface{}, sha string, opt *GetCommitCommentsOptions, options ...RequestOptionFunc) ([]*CommitComment, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/repository/commits/%s/comments", PathEscape(project), url.PathEscape(sha))
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
var c []*CommitComment
resp, err := s.client.Do(req, &c)
if err != nil {
return nil, resp, err
}
return c, resp, err
}
// PostCommitCommentOptions represents the available PostCommitComment()
// options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/commits.html#post-comment-to-commit
type PostCommitCommentOptions struct {
Note *string `url:"note,omitempty" json:"note,omitempty"`
Path *string `url:"path" json:"path"`
Line *int `url:"line" json:"line"`
LineType *string `url:"line_type" json:"line_type"`
}
// PostCommitComment adds a comment to a commit. Optionally you can post
// comments on a specific line of a commit. Therefor both path, line_new and
// line_old are required.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/commits.html#post-comment-to-commit
func (s *CommitsService) PostCommitComment(pid interface{}, sha string, opt *PostCommitCommentOptions, options ...RequestOptionFunc) (*CommitComment, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/repository/commits/%s/comments", PathEscape(project), url.PathEscape(sha))
req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
if err != nil {
return nil, nil, err
}
c := new(CommitComment)
resp, err := s.client.Do(req, c)
if err != nil {
return nil, resp, err
}
return c, resp, err
}
// GetCommitStatusesOptions represents the available GetCommitStatuses() options.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/commits.html#list-the-statuses-of-a-commit
type GetCommitStatusesOptions struct {
ListOptions
Ref *string `url:"ref,omitempty" json:"ref,omitempty"`
Stage *string `url:"stage,omitempty" json:"stage,omitempty"`
Name *string `url:"name,omitempty" json:"name,omitempty"`
All *bool `url:"all,omitempty" json:"all,omitempty"`
}
// CommitStatus represents a GitLab commit status.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/commits.html#commit-status
type CommitStatus struct {
ID int `json:"id"`
SHA string `json:"sha"`
Ref string `json:"ref"`
Status string `json:"status"`
CreatedAt *time.Time `json:"created_at"`
StartedAt *time.Time `json:"started_at"`
FinishedAt *time.Time `json:"finished_at"`
Name string `json:"name"`
AllowFailure bool `json:"allow_failure"`
Coverage float64 `json:"coverage"`
Author Author `json:"author"`
Description string `json:"description"`
TargetURL string `json:"target_url"`
}
// GetCommitStatuses gets the statuses of a commit in a project.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/commits.html#list-the-statuses-of-a-commit
func (s *CommitsService) GetCommitStatuses(pid interface{}, sha string, opt *GetCommitStatusesOptions, options ...RequestOptionFunc) ([]*CommitStatus, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/repository/commits/%s/statuses", PathEscape(project), url.PathEscape(sha))
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
var cs []*CommitStatus
resp, err := s.client.Do(req, &cs)
if err != nil {
return nil, resp, err
}
return cs, resp, err
}
// SetCommitStatusOptions represents the available SetCommitStatus() options.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/commits.html#set-the-pipeline-status-of-a-commit
type SetCommitStatusOptions struct {
State BuildStateValue `url:"state" json:"state"`
Ref *string `url:"ref,omitempty" json:"ref,omitempty"`
Name *string `url:"name,omitempty" json:"name,omitempty"`
Context *string `url:"context,omitempty" json:"context,omitempty"`
TargetURL *string `url:"target_url,omitempty" json:"target_url,omitempty"`
Description *string `url:"description,omitempty" json:"description,omitempty"`
Coverage *float64 `url:"coverage,omitempty" json:"coverage,omitempty"`
PipelineID *int `url:"pipeline_id,omitempty" json:"pipeline_id,omitempty"`
}
// SetCommitStatus sets the status of a commit in a project.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/commits.html#set-the-pipeline-status-of-a-commit
func (s *CommitsService) SetCommitStatus(pid interface{}, sha string, opt *SetCommitStatusOptions, options ...RequestOptionFunc) (*CommitStatus, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/statuses/%s", PathEscape(project), url.PathEscape(sha))
req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
if err != nil {
return nil, nil, err
}
cs := new(CommitStatus)
resp, err := s.client.Do(req, &cs)
if err != nil {
return nil, resp, err
}
return cs, resp, err
}
// ListMergeRequestsByCommit gets merge request associated with a commit.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/commits.html#list-merge-requests-associated-with-a-commit
func (s *CommitsService) ListMergeRequestsByCommit(pid interface{}, sha string, options ...RequestOptionFunc) ([]*MergeRequest, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/repository/commits/%s/merge_requests", PathEscape(project), url.PathEscape(sha))
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}
var mrs []*MergeRequest
resp, err := s.client.Do(req, &mrs)
if err != nil {
return nil, resp, err
}
return mrs, resp, err
}
// CherryPickCommitOptions represents the available CherryPickCommit() options.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/commits.html#cherry-pick-a-commit
type CherryPickCommitOptions struct {
Branch *string `url:"branch,omitempty" json:"branch,omitempty"`
DryRun *bool `url:"dry_run,omitempty" json:"dry_run,omitempty"`
Message *string `url:"message,omitempty" json:"message,omitempty"`
}
// CherryPickCommit cherry picks a commit to a given branch.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/commits.html#cherry-pick-a-commit
func (s *CommitsService) CherryPickCommit(pid interface{}, sha string, opt *CherryPickCommitOptions, options ...RequestOptionFunc) (*Commit, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/repository/commits/%s/cherry_pick", PathEscape(project), url.PathEscape(sha))
req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
if err != nil {
return nil, nil, err
}
c := new(Commit)
resp, err := s.client.Do(req, &c)
if err != nil {
return nil, resp, err
}
return c, resp, err
}
// RevertCommitOptions represents the available RevertCommit() options.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/commits.html#revert-a-commit
type RevertCommitOptions struct {
Branch *string `url:"branch,omitempty" json:"branch,omitempty"`
}
// RevertCommit reverts a commit in a given branch.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/commits.html#revert-a-commit
func (s *CommitsService) RevertCommit(pid interface{}, sha string, opt *RevertCommitOptions, options ...RequestOptionFunc) (*Commit, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/repository/commits/%s/revert", PathEscape(project), url.PathEscape(sha))
req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
if err != nil {
return nil, nil, err
}
c := new(Commit)
resp, err := s.client.Do(req, &c)
if err != nil {
return nil, resp, err
}
return c, resp, err
}
// GPGSignature represents a Gitlab commit's GPG Signature.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/commits.html#get-gpg-signature-of-a-commit
type GPGSignature struct {
KeyID int `json:"gpg_key_id"`
KeyPrimaryKeyID string `json:"gpg_key_primary_keyid"`
KeyUserName string `json:"gpg_key_user_name"`
KeyUserEmail string `json:"gpg_key_user_email"`
VerificationStatus string `json:"verification_status"`
KeySubkeyID int `json:"gpg_key_subkey_id"`
}
// GetGPGSiganature gets a GPG signature of a commit.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/commits.html#get-gpg-signature-of-a-commit
func (s *CommitsService) GetGPGSiganature(pid interface{}, sha string, options ...RequestOptionFunc) (*GPGSignature, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/repository/commits/%s/signature", PathEscape(project), url.PathEscape(sha))
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}
sig := new(GPGSignature)
resp, err := s.client.Do(req, &sig)
if err != nil {
return nil, resp, err
}
return sig, resp, err
}

310
vendor/github.com/xanzy/go-gitlab/container_registry.go generated vendored Normal file
View File

@ -0,0 +1,310 @@
//
// 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"
"time"
)
// ContainerRegistryService handles communication with the container registry
// related methods of the GitLab API.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/container_registry.html
type ContainerRegistryService struct {
client *Client
}
// RegistryRepository represents a GitLab content registry repository.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/container_registry.html
type RegistryRepository struct {
ID int `json:"id"`
Name string `json:"name"`
Path string `json:"path"`
ProjectID int `json:"project_id"`
Location string `json:"location"`
CreatedAt *time.Time `json:"created_at"`
CleanupPolicyStartedAt *time.Time `json:"cleanup_policy_started_at"`
TagsCount int `json:"tags_count"`
Tags []*RegistryRepositoryTag `json:"tags"`
}
func (s RegistryRepository) String() string {
return Stringify(s)
}
// RegistryRepositoryTag represents a GitLab registry image tag.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/container_registry.html
type RegistryRepositoryTag struct {
Name string `json:"name"`
Path string `json:"path"`
Location string `json:"location"`
Revision string `json:"revision"`
ShortRevision string `json:"short_revision"`
Digest string `json:"digest"`
CreatedAt *time.Time `json:"created_at"`
TotalSize int `json:"total_size"`
}
func (s RegistryRepositoryTag) String() string {
return Stringify(s)
}
// ListRegistryRepositoriesOptions represents the available
// ListRegistryRepositories() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/container_registry.html#list-registry-repositories
type ListRegistryRepositoriesOptions struct {
ListOptions
// Deprecated: These options are deprecated for ListGroupRegistryRepositories calls. (Removed in GitLab 15.0)
Tags *bool `url:"tags,omitempty" json:"tags,omitempty"`
TagsCount *bool `url:"tags_count,omitempty" json:"tags_count,omitempty"`
}
// ListProjectRegistryRepositories gets a list of registry repositories in a project.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/container_registry.html#within-a-project
func (s *ContainerRegistryService) ListProjectRegistryRepositories(pid interface{}, opt *ListRegistryRepositoriesOptions, options ...RequestOptionFunc) ([]*RegistryRepository, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/registry/repositories", PathEscape(project))
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
var repos []*RegistryRepository
resp, err := s.client.Do(req, &repos)
if err != nil {
return nil, resp, err
}
return repos, resp, err
}
// ListGroupRegistryRepositories gets a list of registry repositories in a group.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/container_registry.html#within-a-group
func (s *ContainerRegistryService) ListGroupRegistryRepositories(gid interface{}, opt *ListRegistryRepositoriesOptions, options ...RequestOptionFunc) ([]*RegistryRepository, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/registry/repositories", PathEscape(group))
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
var repos []*RegistryRepository
resp, err := s.client.Do(req, &repos)
if err != nil {
return nil, resp, err
}
return repos, resp, err
}
// GetSingleRegistryRepositoryOptions represents the available
// GetSingleRegistryRepository() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/container_registry.html#get-details-of-a-single-repository
type GetSingleRegistryRepositoryOptions struct {
Tags *bool `url:"tags,omitempty" json:"tags,omitempty"`
TagsCount *bool `url:"tags_count,omitempty" json:"tags_count,omitempty"`
}
// GetSingleRegistryRepository gets the details of single registry repository.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/container_registry.html#get-details-of-a-single-repository
func (s *ContainerRegistryService) GetSingleRegistryRepository(pid interface{}, opt *GetSingleRegistryRepositoryOptions, options ...RequestOptionFunc) (*RegistryRepository, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("registry/repositories/%s", PathEscape(project))
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
repo := new(RegistryRepository)
resp, err := s.client.Do(req, repo)
if err != nil {
return nil, resp, err
}
return repo, resp, err
}
// DeleteRegistryRepository deletes a repository in a registry.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/container_registry.html#delete-registry-repository
func (s *ContainerRegistryService) DeleteRegistryRepository(pid interface{}, repository int, options ...RequestOptionFunc) (*Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("projects/%s/registry/repositories/%d", PathEscape(project), repository)
req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}
// ListRegistryRepositoryTagsOptions represents the available
// ListRegistryRepositoryTags() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/container_registry.html#list-registry-repository-tags
type ListRegistryRepositoryTagsOptions ListOptions
// ListRegistryRepositoryTags gets a list of tags for given registry repository.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/container_registry.html#list-registry-repository-tags
func (s *ContainerRegistryService) ListRegistryRepositoryTags(pid interface{}, repository int, opt *ListRegistryRepositoryTagsOptions, options ...RequestOptionFunc) ([]*RegistryRepositoryTag, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/registry/repositories/%d/tags",
PathEscape(project),
repository,
)
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
var tags []*RegistryRepositoryTag
resp, err := s.client.Do(req, &tags)
if err != nil {
return nil, resp, err
}
return tags, resp, err
}
// GetRegistryRepositoryTagDetail get details of a registry repository tag
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/container_registry.html#get-details-of-a-registry-repository-tag
func (s *ContainerRegistryService) GetRegistryRepositoryTagDetail(pid interface{}, repository int, tagName string, options ...RequestOptionFunc) (*RegistryRepositoryTag, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/registry/repositories/%d/tags/%s",
PathEscape(project),
repository,
tagName,
)
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}
tag := new(RegistryRepositoryTag)
resp, err := s.client.Do(req, &tag)
if err != nil {
return nil, resp, err
}
return tag, resp, err
}
// DeleteRegistryRepositoryTag deletes a registry repository tag.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/container_registry.html#delete-a-registry-repository-tag
func (s *ContainerRegistryService) DeleteRegistryRepositoryTag(pid interface{}, repository int, tagName string, options ...RequestOptionFunc) (*Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("projects/%s/registry/repositories/%d/tags/%s",
PathEscape(project),
repository,
tagName,
)
req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}
// DeleteRegistryRepositoryTagsOptions represents the available
// DeleteRegistryRepositoryTags() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/container_registry.html#delete-registry-repository-tags-in-bulk
type DeleteRegistryRepositoryTagsOptions struct {
NameRegexpDelete *string `url:"name_regex_delete,omitempty" json:"name_regex_delete,omitempty"`
NameRegexpKeep *string `url:"name_regex_keep,omitempty" json:"name_regex_keep,omitempty"`
KeepN *int `url:"keep_n,omitempty" json:"keep_n,omitempty"`
OlderThan *string `url:"older_than,omitempty" json:"older_than,omitempty"`
// Deprecated: NameRegexp is deprecated in favor of NameRegexpDelete.
NameRegexp *string `url:"name_regex,omitempty" json:"name_regex,omitempty"`
}
// DeleteRegistryRepositoryTags deletes repository tags in bulk based on
// given criteria.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/container_registry.html#delete-registry-repository-tags-in-bulk
func (s *ContainerRegistryService) DeleteRegistryRepositoryTags(pid interface{}, repository int, opt *DeleteRegistryRepositoryTagsOptions, options ...RequestOptionFunc) (*Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("projects/%s/registry/repositories/%d/tags",
PathEscape(project),
repository,
)
req, err := s.client.NewRequest(http.MethodDelete, u, opt, options)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}

188
vendor/github.com/xanzy/go-gitlab/custom_attributes.go generated vendored Normal file
View File

@ -0,0 +1,188 @@
//
// 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"
)
// CustomAttributesService handles communication with the group, project and
// user custom attributes related methods of the GitLab API.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/custom_attributes.html
type CustomAttributesService struct {
client *Client
}
// CustomAttribute struct is used to unmarshal response to api calls.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/custom_attributes.html
type CustomAttribute struct {
Key string `json:"key"`
Value string `json:"value"`
}
// ListCustomUserAttributes lists the custom attributes of the specified user.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/custom_attributes.html#list-custom-attributes
func (s *CustomAttributesService) ListCustomUserAttributes(user int, options ...RequestOptionFunc) ([]*CustomAttribute, *Response, error) {
return s.listCustomAttributes("users", user, options...)
}
// ListCustomGroupAttributes lists the custom attributes of the specified group.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/custom_attributes.html#list-custom-attributes
func (s *CustomAttributesService) ListCustomGroupAttributes(group int, options ...RequestOptionFunc) ([]*CustomAttribute, *Response, error) {
return s.listCustomAttributes("groups", group, options...)
}
// ListCustomProjectAttributes lists the custom attributes of the specified project.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/custom_attributes.html#list-custom-attributes
func (s *CustomAttributesService) ListCustomProjectAttributes(project int, options ...RequestOptionFunc) ([]*CustomAttribute, *Response, error) {
return s.listCustomAttributes("projects", project, options...)
}
func (s *CustomAttributesService) listCustomAttributes(resource string, id int, options ...RequestOptionFunc) ([]*CustomAttribute, *Response, error) {
u := fmt.Sprintf("%s/%d/custom_attributes", resource, id)
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}
var cas []*CustomAttribute
resp, err := s.client.Do(req, &cas)
if err != nil {
return nil, resp, err
}
return cas, resp, err
}
// GetCustomUserAttribute returns the user attribute with a speciifc key.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/custom_attributes.html#single-custom-attribute
func (s *CustomAttributesService) GetCustomUserAttribute(user int, key string, options ...RequestOptionFunc) (*CustomAttribute, *Response, error) {
return s.getCustomAttribute("users", user, key, options...)
}
// GetCustomGroupAttribute returns the group attribute with a speciifc key.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/custom_attributes.html#single-custom-attribute
func (s *CustomAttributesService) GetCustomGroupAttribute(group int, key string, options ...RequestOptionFunc) (*CustomAttribute, *Response, error) {
return s.getCustomAttribute("groups", group, key, options...)
}
// GetCustomProjectAttribute returns the project attribute with a speciifc key.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/custom_attributes.html#single-custom-attribute
func (s *CustomAttributesService) GetCustomProjectAttribute(project int, key string, options ...RequestOptionFunc) (*CustomAttribute, *Response, error) {
return s.getCustomAttribute("projects", project, key, options...)
}
func (s *CustomAttributesService) getCustomAttribute(resource string, id int, key string, options ...RequestOptionFunc) (*CustomAttribute, *Response, error) {
u := fmt.Sprintf("%s/%d/custom_attributes/%s", resource, id, key)
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}
var ca *CustomAttribute
resp, err := s.client.Do(req, &ca)
if err != nil {
return nil, resp, err
}
return ca, resp, err
}
// SetCustomUserAttribute sets the custom attributes of the specified user.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/custom_attributes.html#set-custom-attribute
func (s *CustomAttributesService) SetCustomUserAttribute(user int, c CustomAttribute, options ...RequestOptionFunc) (*CustomAttribute, *Response, error) {
return s.setCustomAttribute("users", user, c, options...)
}
// SetCustomGroupAttribute sets the custom attributes of the specified group.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/custom_attributes.html#set-custom-attribute
func (s *CustomAttributesService) SetCustomGroupAttribute(group int, c CustomAttribute, options ...RequestOptionFunc) (*CustomAttribute, *Response, error) {
return s.setCustomAttribute("groups", group, c, options...)
}
// SetCustomProjectAttribute sets the custom attributes of the specified project.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/custom_attributes.html#set-custom-attribute
func (s *CustomAttributesService) SetCustomProjectAttribute(project int, c CustomAttribute, options ...RequestOptionFunc) (*CustomAttribute, *Response, error) {
return s.setCustomAttribute("projects", project, c, options...)
}
func (s *CustomAttributesService) setCustomAttribute(resource string, id int, c CustomAttribute, options ...RequestOptionFunc) (*CustomAttribute, *Response, error) {
u := fmt.Sprintf("%s/%d/custom_attributes/%s", resource, id, c.Key)
req, err := s.client.NewRequest(http.MethodPut, u, c, options)
if err != nil {
return nil, nil, err
}
ca := new(CustomAttribute)
resp, err := s.client.Do(req, ca)
if err != nil {
return nil, resp, err
}
return ca, resp, err
}
// DeleteCustomUserAttribute removes the custom attribute of the specified user.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/custom_attributes.html#delete-custom-attribute
func (s *CustomAttributesService) DeleteCustomUserAttribute(user int, key string, options ...RequestOptionFunc) (*Response, error) {
return s.deleteCustomAttribute("users", user, key, options...)
}
// DeleteCustomGroupAttribute removes the custom attribute of the specified group.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/custom_attributes.html#delete-custom-attribute
func (s *CustomAttributesService) DeleteCustomGroupAttribute(group int, key string, options ...RequestOptionFunc) (*Response, error) {
return s.deleteCustomAttribute("groups", group, key, options...)
}
// DeleteCustomProjectAttribute removes the custom attribute of the specified project.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/custom_attributes.html#delete-custom-attribute
func (s *CustomAttributesService) DeleteCustomProjectAttribute(project int, key string, options ...RequestOptionFunc) (*Response, error) {
return s.deleteCustomAttribute("projects", project, key, options...)
}
func (s *CustomAttributesService) deleteCustomAttribute(resource string, id int, key string, options ...RequestOptionFunc) (*Response, error) {
u := fmt.Sprintf("%s/%d/custom_attributes/%s", resource, id, key)
req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}

275
vendor/github.com/xanzy/go-gitlab/deploy_keys.go generated vendored Normal file
View File

@ -0,0 +1,275 @@
//
// 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"
"time"
)
// DeployKeysService handles communication with the keys related methods
// of the GitLab API.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/deploy_keys.html
type DeployKeysService struct {
client *Client
}
// InstanceDeployKey represents a GitLab deploy key with the associated
// projects it has write access to.
type InstanceDeployKey struct {
ID int `json:"id"`
Title string `json:"title"`
CreatedAt *time.Time `json:"created_at"`
Key string `json:"key"`
Fingerprint string `json:"fingerprint"`
ProjectsWithWriteAccess []*DeployKeyProject `json:"projects_with_write_access"`
}
func (k InstanceDeployKey) String() string {
return Stringify(k)
}
// DeployKeyProject refers to a project an InstanceDeployKey has write access to.
type DeployKeyProject struct {
ID int `json:"id"`
Description string `json:"description"`
Name string `json:"name"`
NameWithNamespace string `json:"name_with_namespace"`
Path string `json:"path"`
PathWithNamespace string `json:"path_with_namespace"`
CreatedAt *time.Time `json:"created_at"`
}
func (k DeployKeyProject) String() string {
return Stringify(k)
}
// ProjectDeployKey represents a GitLab project deploy key.
type ProjectDeployKey struct {
ID int `json:"id"`
Title string `json:"title"`
Key string `json:"key"`
CreatedAt *time.Time `json:"created_at"`
CanPush bool `json:"can_push"`
}
func (k ProjectDeployKey) String() string {
return Stringify(k)
}
// ListProjectDeployKeysOptions represents the available ListAllDeployKeys()
// options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/deploy_keys.html#list-all-deploy-keys
type ListInstanceDeployKeysOptions struct {
ListOptions
Public *bool `url:"public,omitempty" json:"public,omitempty"`
}
// ListAllDeployKeys gets a list of all deploy keys
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/deploy_keys.html#list-all-deploy-keys
func (s *DeployKeysService) ListAllDeployKeys(opt *ListInstanceDeployKeysOptions, options ...RequestOptionFunc) ([]*InstanceDeployKey, *Response, error) {
req, err := s.client.NewRequest(http.MethodGet, "deploy_keys", opt, options)
if err != nil {
return nil, nil, err
}
var ks []*InstanceDeployKey
resp, err := s.client.Do(req, &ks)
if err != nil {
return nil, resp, err
}
return ks, resp, err
}
// ListProjectDeployKeysOptions represents the available ListProjectDeployKeys()
// options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/deploy_keys.html#list-deploy-keys-for-project
type ListProjectDeployKeysOptions ListOptions
// ListProjectDeployKeys gets a list of a project's deploy keys
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/deploy_keys.html#list-deploy-keys-for-project
func (s *DeployKeysService) ListProjectDeployKeys(pid interface{}, opt *ListProjectDeployKeysOptions, options ...RequestOptionFunc) ([]*ProjectDeployKey, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/deploy_keys", PathEscape(project))
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
var ks []*ProjectDeployKey
resp, err := s.client.Do(req, &ks)
if err != nil {
return nil, resp, err
}
return ks, resp, err
}
// GetDeployKey gets a single deploy key.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/deploy_keys.html#get-a-single-deploy-key
func (s *DeployKeysService) GetDeployKey(pid interface{}, deployKey int, options ...RequestOptionFunc) (*ProjectDeployKey, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/deploy_keys/%d", PathEscape(project), deployKey)
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}
k := new(ProjectDeployKey)
resp, err := s.client.Do(req, k)
if err != nil {
return nil, resp, err
}
return k, resp, err
}
// AddDeployKeyOptions represents the available ADDDeployKey() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/deploy_keys.html#add-deploy-key
type AddDeployKeyOptions struct {
Title *string `url:"title,omitempty" json:"title,omitempty"`
Key *string `url:"key,omitempty" json:"key,omitempty"`
CanPush *bool `url:"can_push,omitempty" json:"can_push,omitempty"`
}
// AddDeployKey creates a new deploy key for a project. If deploy key already
// exists in another project - it will be joined to project but only if
// original one was is accessible by same user.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/deploy_keys.html#add-deploy-key
func (s *DeployKeysService) AddDeployKey(pid interface{}, opt *AddDeployKeyOptions, options ...RequestOptionFunc) (*ProjectDeployKey, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/deploy_keys", PathEscape(project))
req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
if err != nil {
return nil, nil, err
}
k := new(ProjectDeployKey)
resp, err := s.client.Do(req, k)
if err != nil {
return nil, resp, err
}
return k, resp, err
}
// DeleteDeployKey deletes a deploy key from a project.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/deploy_keys.html#delete-deploy-key
func (s *DeployKeysService) DeleteDeployKey(pid interface{}, deployKey int, options ...RequestOptionFunc) (*Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("projects/%s/deploy_keys/%d", PathEscape(project), deployKey)
req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}
// EnableDeployKey enables a deploy key.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/deploy_keys.html#enable-a-deploy-key
func (s *DeployKeysService) EnableDeployKey(pid interface{}, deployKey int, options ...RequestOptionFunc) (*ProjectDeployKey, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/deploy_keys/%d/enable", PathEscape(project), deployKey)
req, err := s.client.NewRequest(http.MethodPost, u, nil, options)
if err != nil {
return nil, nil, err
}
k := new(ProjectDeployKey)
resp, err := s.client.Do(req, k)
if err != nil {
return nil, resp, err
}
return k, resp, err
}
// UpdateDeployKeyOptions represents the available UpdateDeployKey() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/deploy_keys.html#update-deploy-key
type UpdateDeployKeyOptions struct {
Title *string `url:"title,omitempty" json:"title,omitempty"`
CanPush *bool `url:"can_push,omitempty" json:"can_push,omitempty"`
}
// UpdateDeployKey updates a deploy key for a project.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/deploy_keys.html#update-deploy-key
func (s *DeployKeysService) UpdateDeployKey(pid interface{}, deployKey int, opt *UpdateDeployKeyOptions, options ...RequestOptionFunc) (*ProjectDeployKey, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/deploy_keys/%d", PathEscape(project), deployKey)
req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
if err != nil {
return nil, nil, err
}
k := new(ProjectDeployKey)
resp, err := s.client.Do(req, k)
if err != nil {
return nil, resp, err
}
return k, resp, err
}

290
vendor/github.com/xanzy/go-gitlab/deploy_tokens.go generated vendored Normal file
View File

@ -0,0 +1,290 @@
//
// 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"
"time"
)
// DeployTokensService handles communication with the deploy tokens related methods
// of the GitLab API.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/deploy_tokens.html
type DeployTokensService struct {
client *Client
}
// DeployToken represents a GitLab deploy token.
type DeployToken struct {
ID int `json:"id"`
Name string `json:"name"`
Username string `json:"username"`
ExpiresAt *time.Time `json:"expires_at"`
Revoked bool `json:"revoked"`
Expired bool `json:"expired"`
Token string `json:"token,omitempty"`
Scopes []string `json:"scopes"`
}
func (k DeployToken) String() string {
return Stringify(k)
}
// ListAllDeployTokens gets a list of all deploy tokens.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/deploy_tokens.html#list-all-deploy-tokens
func (s *DeployTokensService) ListAllDeployTokens(options ...RequestOptionFunc) ([]*DeployToken, *Response, error) {
req, err := s.client.NewRequest(http.MethodGet, "deploy_tokens", nil, options)
if err != nil {
return nil, nil, err
}
var ts []*DeployToken
resp, err := s.client.Do(req, &ts)
if err != nil {
return nil, resp, err
}
return ts, resp, err
}
// ListProjectDeployTokensOptions represents the available ListProjectDeployTokens()
// options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/deploy_tokens.html#list-project-deploy-tokens
type ListProjectDeployTokensOptions ListOptions
// ListProjectDeployTokens gets a list of a project's deploy tokens.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/deploy_tokens.html#list-project-deploy-tokens
func (s *DeployTokensService) ListProjectDeployTokens(pid interface{}, opt *ListProjectDeployTokensOptions, options ...RequestOptionFunc) ([]*DeployToken, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/deploy_tokens", PathEscape(project))
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
var ts []*DeployToken
resp, err := s.client.Do(req, &ts)
if err != nil {
return nil, resp, err
}
return ts, resp, err
}
// GetProjectDeployToken gets a single deploy token.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/deploy_tokens.html#get-a-project-deploy-token
func (s *DeployTokensService) GetProjectDeployToken(pid interface{}, deployToken int, options ...RequestOptionFunc) (*DeployToken, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/deploy_tokens/%d", PathEscape(project), deployToken)
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}
t := new(DeployToken)
resp, err := s.client.Do(req, t)
if err != nil {
return nil, resp, err
}
return t, resp, err
}
// CreateProjectDeployTokenOptions represents the available CreateProjectDeployToken() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/deploy_tokens.html#create-a-project-deploy-token
type CreateProjectDeployTokenOptions struct {
Name *string `url:"name,omitempty" json:"name,omitempty"`
ExpiresAt *time.Time `url:"expires_at,omitempty" json:"expires_at,omitempty"`
Username *string `url:"username,omitempty" json:"username,omitempty"`
Scopes *[]string `url:"scopes,omitempty" json:"scopes,omitempty"`
}
// CreateProjectDeployToken creates a new deploy token for a project.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/deploy_tokens.html#create-a-project-deploy-token
func (s *DeployTokensService) CreateProjectDeployToken(pid interface{}, opt *CreateProjectDeployTokenOptions, options ...RequestOptionFunc) (*DeployToken, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/deploy_tokens", PathEscape(project))
req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
if err != nil {
return nil, nil, err
}
t := new(DeployToken)
resp, err := s.client.Do(req, t)
if err != nil {
return nil, resp, err
}
return t, resp, err
}
// DeleteProjectDeployToken removes a deploy token from the project.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/deploy_tokens.html#delete-a-project-deploy-token
func (s *DeployTokensService) DeleteProjectDeployToken(pid interface{}, deployToken int, options ...RequestOptionFunc) (*Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("projects/%s/deploy_tokens/%d", PathEscape(project), deployToken)
req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}
// ListGroupDeployTokensOptions represents the available ListGroupDeployTokens()
// options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/deploy_tokens.html#list-group-deploy-tokens
type ListGroupDeployTokensOptions ListOptions
// ListGroupDeployTokens gets a list of a groups deploy tokens.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/deploy_tokens.html#list-group-deploy-tokens
func (s *DeployTokensService) ListGroupDeployTokens(gid interface{}, opt *ListGroupDeployTokensOptions, options ...RequestOptionFunc) ([]*DeployToken, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/deploy_tokens", PathEscape(group))
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
var ts []*DeployToken
resp, err := s.client.Do(req, &ts)
if err != nil {
return nil, resp, err
}
return ts, resp, err
}
// GetGroupDeployToken gets a single deploy token.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/deploy_tokens.html#get-a-group-deploy-token
func (s *DeployTokensService) GetGroupDeployToken(gid interface{}, deployToken int, options ...RequestOptionFunc) (*DeployToken, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/deploy_tokens/%d", PathEscape(group), deployToken)
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}
t := new(DeployToken)
resp, err := s.client.Do(req, t)
if err != nil {
return nil, resp, err
}
return t, resp, err
}
// CreateGroupDeployTokenOptions represents the available CreateGroupDeployToken() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/deploy_tokens.html#create-a-group-deploy-token
type CreateGroupDeployTokenOptions struct {
Name *string `url:"name,omitempty" json:"name,omitempty"`
ExpiresAt *time.Time `url:"expires_at,omitempty" json:"expires_at,omitempty"`
Username *string `url:"username,omitempty" json:"username,omitempty"`
Scopes *[]string `url:"scopes,omitempty" json:"scopes,omitempty"`
}
// CreateGroupDeployToken creates a new deploy token for a group.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/deploy_tokens.html#create-a-group-deploy-token
func (s *DeployTokensService) CreateGroupDeployToken(gid interface{}, opt *CreateGroupDeployTokenOptions, options ...RequestOptionFunc) (*DeployToken, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/deploy_tokens", PathEscape(group))
req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
if err != nil {
return nil, nil, err
}
t := new(DeployToken)
resp, err := s.client.Do(req, t)
if err != nil {
return nil, resp, err
}
return t, resp, err
}
// DeleteGroupDeployToken removes a deploy token from the group.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/deploy_tokens.html#delete-a-group-deploy-token
func (s *DeployTokensService) DeleteGroupDeployToken(gid interface{}, deployToken int, options ...RequestOptionFunc) (*Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("groups/%s/deploy_tokens/%d", PathEscape(group), deployToken)
req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}

203
vendor/github.com/xanzy/go-gitlab/deployments.go generated vendored Normal file
View File

@ -0,0 +1,203 @@
//
// 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"
"time"
)
// DeploymentsService handles communication with the deployment related methods
// of the GitLab API.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/deployments.html
type DeploymentsService struct {
client *Client
}
// Deployment represents the Gitlab deployment
type Deployment struct {
ID int `json:"id"`
IID int `json:"iid"`
Ref string `json:"ref"`
SHA string `json:"sha"`
Status string `json:"status"`
CreatedAt *time.Time `json:"created_at"`
UpdatedAt *time.Time `json:"updated_at"`
User *ProjectUser `json:"user"`
Environment *Environment `json:"environment"`
Deployable struct {
ID int `json:"id"`
Status string `json:"status"`
Stage string `json:"stage"`
Name string `json:"name"`
Ref string `json:"ref"`
Tag bool `json:"tag"`
Coverage float64 `json:"coverage"`
CreatedAt *time.Time `json:"created_at"`
StartedAt *time.Time `json:"started_at"`
FinishedAt *time.Time `json:"finished_at"`
Duration float64 `json:"duration"`
User *User `json:"user"`
Commit *Commit `json:"commit"`
Pipeline struct {
ID int `json:"id"`
SHA string `json:"sha"`
Ref string `json:"ref"`
Status string `json:"status"`
CreatedAt *time.Time `json:"created_at"`
UpdatedAt *time.Time `json:"updated_at"`
} `json:"pipeline"`
Runner *Runner `json:"runner"`
} `json:"deployable"`
}
// ListProjectDeploymentsOptions represents the available ListProjectDeployments() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/deployments.html#list-project-deployments
type ListProjectDeploymentsOptions struct {
ListOptions
OrderBy *string `url:"order_by,omitempty" json:"order_by,omitempty"`
Sort *string `url:"sort,omitempty" json:"sort,omitempty"`
Environment *string `url:"environment,omitempty" json:"environment,omitempty"`
Status *string `url:"status,omitempty" json:"status,omitempty"`
// Only for Gitlab versions less than 14
UpdatedAfter *time.Time `url:"updated_after,omitempty" json:"updated_after,omitempty"`
UpdatedBefore *time.Time `url:"updated_before,omitempty" json:"updated_before,omitempty"`
// Only for Gitlab 14 or higher
FinishedAfter *time.Time `url:"finished_after,omitempty" json:"finished_after,omitempty"`
FinishedBefore *time.Time `url:"finished_before,omitempty" json:"finished_before,omitempty"`
}
// ListProjectDeployments gets a list of deployments in a project.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/deployments.html#list-project-deployments
func (s *DeploymentsService) ListProjectDeployments(pid interface{}, opts *ListProjectDeploymentsOptions, options ...RequestOptionFunc) ([]*Deployment, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/deployments", PathEscape(project))
req, err := s.client.NewRequest(http.MethodGet, u, opts, options)
if err != nil {
return nil, nil, err
}
var ds []*Deployment
resp, err := s.client.Do(req, &ds)
if err != nil {
return nil, resp, err
}
return ds, resp, err
}
// GetProjectDeployment get a deployment for a project.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/deployments.html#get-a-specific-deployment
func (s *DeploymentsService) GetProjectDeployment(pid interface{}, deployment int, options ...RequestOptionFunc) (*Deployment, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/deployments/%d", PathEscape(project), deployment)
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}
d := new(Deployment)
resp, err := s.client.Do(req, d)
if err != nil {
return nil, resp, err
}
return d, resp, err
}
// CreateProjectDeploymentOptions represents the available
// CreateProjectDeployment() options.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/deployments.html#create-a-deployment
type CreateProjectDeploymentOptions struct {
Environment *string `url:"environment,omitempty" json:"environment,omitempty"`
Ref *string `url:"ref,omitempty" json:"ref,omitempty"`
SHA *string `url:"sha,omitempty" json:"sha,omitempty"`
Tag *bool `url:"tag,omitempty" json:"tag,omitempty"`
Status *DeploymentStatusValue `url:"status,omitempty" json:"status,omitempty"`
}
// CreateProjectDeployment creates a project deployment.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/deployments.html#create-a-deployment
func (s *DeploymentsService) CreateProjectDeployment(pid interface{}, opt *CreateProjectDeploymentOptions, options ...RequestOptionFunc) (*Deployment, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/deployments", PathEscape(project))
req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
if err != nil {
return nil, nil, err
}
d := new(Deployment)
resp, err := s.client.Do(req, &d)
if err != nil {
return nil, resp, err
}
return d, resp, err
}
// UpdateProjectDeploymentOptions represents the available
// UpdateProjectDeployment() options.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/deployments.html#update-a-deployment
type UpdateProjectDeploymentOptions struct {
Status *DeploymentStatusValue `url:"status,omitempty" json:"status,omitempty"`
}
// UpdateProjectDeployment updates a project deployment.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/deployments.html#update-a-deployment
func (s *DeploymentsService) UpdateProjectDeployment(pid interface{}, deployment int, opt *UpdateProjectDeploymentOptions, options ...RequestOptionFunc) (*Deployment, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/deployments/%d", PathEscape(project), deployment)
req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
if err != nil {
return nil, nil, err
}
d := new(Deployment)
resp, err := s.client.Do(req, &d)
if err != nil {
return nil, resp, err
}
return d, resp, err
}

View File

@ -0,0 +1,53 @@
// 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
//
// 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"
)
// DeploymentMergeRequestsService handles communication with the deployment's
// merge requests related methods of the GitLab API.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/deployments.html#list-of-merge-requests-associated-with-a-deployment
type DeploymentMergeRequestsService struct {
client *Client
}
// ListDeploymentMergeRequests get the merge requests associated with deployment.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/deployments.html#list-of-merge-requests-associated-with-a-deployment
func (s *DeploymentMergeRequestsService) ListDeploymentMergeRequests(pid interface{}, deployment int, opts *ListMergeRequestsOptions, options ...RequestOptionFunc) ([]*MergeRequest, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/deployments/%d/merge_requests", PathEscape(project), deployment)
req, err := s.client.NewRequest(http.MethodGet, u, opts, options)
if err != nil {
return nil, nil, err
}
var mrs []*MergeRequest
resp, err := s.client.Do(req, &mrs)
if err != nil {
return nil, resp, err
}
return mrs, resp, err
}

1114
vendor/github.com/xanzy/go-gitlab/discussions.go generated vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,93 @@
//
// Copyright 2022, FantasyTeddy
//
// 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"
"net/url"
)
// DockerfileTemplatesService handles communication with the Dockerfile
// templates related methods of the GitLab API.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/templates/dockerfiles.html
type DockerfileTemplatesService struct {
client *Client
}
// DockerfileTemplate represents a GitLab Dockerfile template.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/templates/dockerfiles.html
type DockerfileTemplate struct {
Name string `json:"name"`
Content string `json:"content"`
}
// DockerfileTemplateListItem represents a GitLab Dockerfile template from the list.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/templates/dockerfiles.html
type DockerfileTemplateListItem struct {
Key string `json:"key"`
Name string `json:"name"`
}
// ListDockerfileTemplatesOptions represents the available ListAllTemplates() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/templates/dockerfiles.html#list-dockerfile-templates
type ListDockerfileTemplatesOptions ListOptions
// ListTemplates get a list of available Dockerfile templates.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/templates/dockerfiles.html#list-dockerfile-templates
func (s *DockerfileTemplatesService) ListTemplates(opt *ListDockerfileTemplatesOptions, options ...RequestOptionFunc) ([]*DockerfileTemplateListItem, *Response, error) {
req, err := s.client.NewRequest(http.MethodGet, "templates/dockerfiles", opt, options)
if err != nil {
return nil, nil, err
}
var gs []*DockerfileTemplateListItem
resp, err := s.client.Do(req, &gs)
if err != nil {
return nil, resp, err
}
return gs, resp, err
}
// GetTemplate get a single Dockerfile template.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/templates/dockerfiles.html#single-dockerfile-template
func (s *DockerfileTemplatesService) GetTemplate(key string, options ...RequestOptionFunc) (*DockerfileTemplate, *Response, error) {
u := fmt.Sprintf("templates/dockerfiles/%s", url.PathEscape(key))
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}
g := new(DockerfileTemplate)
resp, err := s.client.Do(req, g)
if err != nil {
return nil, resp, err
}
return g, resp, err
}

224
vendor/github.com/xanzy/go-gitlab/environments.go generated vendored Normal file
View File

@ -0,0 +1,224 @@
//
// 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"
"time"
)
// EnvironmentsService handles communication with the environment related methods
// of the GitLab API.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/environments.html
type EnvironmentsService struct {
client *Client
}
// Environment represents a GitLab environment.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/environments.html
type Environment struct {
ID int `json:"id"`
Name string `json:"name"`
Slug string `json:"slug"`
State string `json:"state"`
Tier string `json:"tier"`
ExternalURL string `json:"external_url"`
Project *Project `json:"project"`
CreatedAt *time.Time `json:"created_at"`
UpdatedAt *time.Time `json:"updated_at"`
LastDeployment *Deployment `json:"last_deployment"`
}
func (env Environment) String() string {
return Stringify(env)
}
// ListEnvironmentsOptions represents the available ListEnvironments() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/environments.html#list-environments
type ListEnvironmentsOptions struct {
ListOptions
Name *string `url:"name,omitempty" json:"name,omitempty"`
Search *string `url:"search,omitempty" json:"search,omitempty"`
States *string `url:"states,omitempty" json:"states,omitempty"`
}
// ListEnvironments gets a list of environments from a project, sorted by name
// alphabetically.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/environments.html#list-environments
func (s *EnvironmentsService) ListEnvironments(pid interface{}, opts *ListEnvironmentsOptions, options ...RequestOptionFunc) ([]*Environment, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/environments", PathEscape(project))
req, err := s.client.NewRequest(http.MethodGet, u, opts, options)
if err != nil {
return nil, nil, err
}
var envs []*Environment
resp, err := s.client.Do(req, &envs)
if err != nil {
return nil, resp, err
}
return envs, resp, err
}
// GetEnvironment gets a specific environment from a project.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/environments.html#get-a-specific-environment
func (s *EnvironmentsService) GetEnvironment(pid interface{}, environment int, options ...RequestOptionFunc) (*Environment, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/environments/%d", PathEscape(project), environment)
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}
env := new(Environment)
resp, err := s.client.Do(req, env)
if err != nil {
return nil, resp, err
}
return env, resp, err
}
// CreateEnvironmentOptions represents the available CreateEnvironment() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/environments.html#create-a-new-environment
type CreateEnvironmentOptions struct {
Name *string `url:"name,omitempty" json:"name,omitempty"`
ExternalURL *string `url:"external_url,omitempty" json:"external_url,omitempty"`
Tier *string `url:"tier,omitempty" json:"tier,omitempty"`
}
// CreateEnvironment adds an environment to a project. This is an idempotent
// method and can be called multiple times with the same parameters. Createing
// an environment that is already a environment does not affect the
// existing environmentship.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/environments.html#create-a-new-environment
func (s *EnvironmentsService) CreateEnvironment(pid interface{}, opt *CreateEnvironmentOptions, options ...RequestOptionFunc) (*Environment, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/environments", PathEscape(project))
req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
if err != nil {
return nil, nil, err
}
env := new(Environment)
resp, err := s.client.Do(req, env)
if err != nil {
return nil, resp, err
}
return env, resp, err
}
// EditEnvironmentOptions represents the available EditEnvironment() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/environments.html#update-an-existing-environment
type EditEnvironmentOptions struct {
Name *string `url:"name,omitempty" json:"name,omitempty"`
ExternalURL *string `url:"external_url,omitempty" json:"external_url,omitempty"`
Tier *string `url:"tier,omitempty" json:"tier,omitempty"`
}
// EditEnvironment updates a project team environment to a specified access level..
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/environments.html#update-an-existing-environment
func (s *EnvironmentsService) EditEnvironment(pid interface{}, environment int, opt *EditEnvironmentOptions, options ...RequestOptionFunc) (*Environment, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/environments/%d", PathEscape(project), environment)
req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
if err != nil {
return nil, nil, err
}
env := new(Environment)
resp, err := s.client.Do(req, env)
if err != nil {
return nil, resp, err
}
return env, resp, err
}
// DeleteEnvironment removes an environment from a project team.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/environments.html#delete-an-environment
func (s *EnvironmentsService) DeleteEnvironment(pid interface{}, environment int, options ...RequestOptionFunc) (*Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("projects/%s/environments/%d", PathEscape(project), environment)
req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}
// StopEnvironment stop an environment from a project team.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/environments.html#stop-an-environment
func (s *EnvironmentsService) StopEnvironment(pid interface{}, environmentID int, options ...RequestOptionFunc) (*Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("projects/%s/environments/%d/stop", PathEscape(project), environmentID)
req, err := s.client.NewRequest(http.MethodPost, u, nil, options)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}

152
vendor/github.com/xanzy/go-gitlab/epic_issues.go generated vendored Normal file
View File

@ -0,0 +1,152 @@
//
// 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"
)
// EpicIssuesService handles communication with the epic issue related methods
// of the GitLab API.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/epic_issues.html
type EpicIssuesService struct {
client *Client
}
// EpicIssueAssignment contains both the epic and issue objects returned from
// Gitlab with the assignment ID.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/epic_issues.html
type EpicIssueAssignment struct {
ID int `json:"id"`
Epic *Epic `json:"epic"`
Issue *Issue `json:"issue"`
}
// ListEpicIssues get a list of epic issues.
//
// Gitlab API docs:
// https://docs.gitlab.com/ee/api/epic_issues.html#list-issues-for-an-epic
func (s *EpicIssuesService) ListEpicIssues(gid interface{}, epic int, opt *ListOptions, options ...RequestOptionFunc) ([]*Issue, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/epics/%d/issues", PathEscape(group), epic)
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
var is []*Issue
resp, err := s.client.Do(req, &is)
if err != nil {
return nil, resp, err
}
return is, resp, err
}
// AssignEpicIssue assigns an existing issue to an epic.
//
// Gitlab API Docs:
// https://docs.gitlab.com/ee/api/epic_issues.html#assign-an-issue-to-the-epic
func (s *EpicIssuesService) AssignEpicIssue(gid interface{}, epic, issue int, options ...RequestOptionFunc) (*EpicIssueAssignment, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/epics/%d/issues/%d", PathEscape(group), epic, issue)
req, err := s.client.NewRequest(http.MethodPost, u, nil, options)
if err != nil {
return nil, nil, err
}
a := new(EpicIssueAssignment)
resp, err := s.client.Do(req, a)
if err != nil {
return nil, resp, err
}
return a, resp, err
}
// RemoveEpicIssue removes an issue from an epic.
//
// Gitlab API Docs:
// https://docs.gitlab.com/ee/api/epic_issues.html#remove-an-issue-from-the-epic
func (s *EpicIssuesService) RemoveEpicIssue(gid interface{}, epic, epicIssue int, options ...RequestOptionFunc) (*EpicIssueAssignment, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/epics/%d/issues/%d", PathEscape(group), epic, epicIssue)
req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
if err != nil {
return nil, nil, err
}
a := new(EpicIssueAssignment)
resp, err := s.client.Do(req, a)
if err != nil {
return nil, resp, err
}
return a, resp, err
}
// UpdateEpicIsssueAssignmentOptions describes the UpdateEpicIssueAssignment()
// options.
//
// Gitlab API Docs:
// https://docs.gitlab.com/ee/api/epic_issues.html#update-epic---issue-association
type UpdateEpicIsssueAssignmentOptions struct {
*ListOptions
MoveBeforeID *int `url:"move_before_id,omitempty" json:"move_before_id,omitempty"`
MoveAfterID *int `url:"move_after_id,omitempty" json:"move_after_id,omitempty"`
}
// UpdateEpicIssueAssignment moves an issue before or after another issue in an
// epic issue list.
//
// Gitlab API Docs:
// https://docs.gitlab.com/ee/api/epic_issues.html#update-epic---issue-association
func (s *EpicIssuesService) UpdateEpicIssueAssignment(gid interface{}, epic, epicIssue int, opt *UpdateEpicIsssueAssignmentOptions, options ...RequestOptionFunc) ([]*Issue, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/epics/%d/issues/%d", PathEscape(group), epic, epicIssue)
req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
if err != nil {
return nil, nil, err
}
var is []*Issue
resp, err := s.client.Do(req, &is)
if err != nil {
return nil, resp, err
}
return is, resp, err
}

266
vendor/github.com/xanzy/go-gitlab/epics.go generated vendored Normal file
View File

@ -0,0 +1,266 @@
//
// 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"
"time"
)
// EpicsService handles communication with the epic related methods
// of the GitLab API.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/epics.html
type EpicsService struct {
client *Client
}
// EpicAuthor represents a author of the epic.
type EpicAuthor struct {
ID int `json:"id"`
State string `json:"state"`
WebURL string `json:"web_url"`
Name string `json:"name"`
AvatarURL string `json:"avatar_url"`
Username string `json:"username"`
}
// Epic represents a GitLab epic.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/epics.html
type Epic struct {
ID int `json:"id"`
IID int `json:"iid"`
GroupID int `json:"group_id"`
ParentID int `json:"parent_id"`
Title string `json:"title"`
Description string `json:"description"`
State string `json:"state"`
Confidential bool `json:"confidential"`
WebURL string `json:"web_url"`
Author *EpicAuthor `json:"author"`
StartDate *ISOTime `json:"start_date"`
StartDateIsFixed bool `json:"start_date_is_fixed"`
StartDateFixed *ISOTime `json:"start_date_fixed"`
StartDateFromMilestones *ISOTime `json:"start_date_from_milestones"`
DueDate *ISOTime `json:"due_date"`
DueDateIsFixed bool `json:"due_date_is_fixed"`
DueDateFixed *ISOTime `json:"due_date_fixed"`
DueDateFromMilestones *ISOTime `json:"due_date_from_milestones"`
CreatedAt *time.Time `json:"created_at"`
UpdatedAt *time.Time `json:"updated_at"`
ClosedAt *time.Time `json:"closed_at"`
Labels []string `json:"labels"`
Upvotes int `json:"upvotes"`
Downvotes int `json:"downvotes"`
UserNotesCount int `json:"user_notes_count"`
URL string `json:"url"`
}
func (e Epic) String() string {
return Stringify(e)
}
// ListGroupEpicsOptions represents the available ListGroupEpics() options.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/epics.html#list-epics-for-a-group
type ListGroupEpicsOptions struct {
ListOptions
AuthorID *int `url:"author_id,omitempty" json:"author_id,omitempty"`
Labels *Labels `url:"labels,comma,omitempty" json:"labels,omitempty"`
WithLabelDetails *bool `url:"with_labels_details,omitempty" json:"with_labels_details,omitempty"`
OrderBy *string `url:"order_by,omitempty" json:"order_by,omitempty"`
Sort *string `url:"sort,omitempty" json:"sort,omitempty"`
Search *string `url:"search,omitempty" json:"search,omitempty"`
State *string `url:"state,omitempty" json:"state,omitempty"`
CreatedAfter *time.Time `url:"created_after,omitempty" json:"created_after,omitempty"`
CreatedBefore *time.Time `url:"created_before,omitempty" json:"created_before,omitempty"`
UpdatedAfter *time.Time `url:"updated_after,omitempty" json:"updated_after,omitempty"`
UpdatedBefore *time.Time `url:"updated_before,omitempty" json:"updated_before,omitempty"`
IncludeAncestorGroups *bool `url:"include_ancestor_groups,omitempty" json:"include_ancestor_groups,omitempty"`
IncludeDescendantGroups *bool `url:"include_descendant_groups,omitempty" json:"include_descendant_groups,omitempty"`
MyReactionEmoji *string `url:"my_reaction_emoji,omitempty" json:"my_reaction_emoji,omitempty"`
}
// ListGroupEpics gets a list of group epics. This function accepts pagination
// parameters page and per_page to return the list of group epics.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/epics.html#list-epics-for-a-group
func (s *EpicsService) ListGroupEpics(gid interface{}, opt *ListGroupEpicsOptions, options ...RequestOptionFunc) ([]*Epic, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/epics", PathEscape(group))
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
var es []*Epic
resp, err := s.client.Do(req, &es)
if err != nil {
return nil, resp, err
}
return es, resp, err
}
// GetEpic gets a single group epic.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/epics.html#single-epic
func (s *EpicsService) GetEpic(gid interface{}, epic int, options ...RequestOptionFunc) (*Epic, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/epics/%d", PathEscape(group), epic)
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}
e := new(Epic)
resp, err := s.client.Do(req, e)
if err != nil {
return nil, resp, err
}
return e, resp, err
}
// GetEpicLinks gets all child epics of an epic.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/epic_links.html
func (s *EpicsService) GetEpicLinks(gid interface{}, epic int, options ...RequestOptionFunc) ([]*Epic, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/epics/%d/epics", PathEscape(group), epic)
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}
var e []*Epic
resp, err := s.client.Do(req, &e)
if err != nil {
return nil, resp, err
}
return e, resp, err
}
// CreateEpicOptions represents the available CreateEpic() options.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/epics.html#new-epic
type CreateEpicOptions struct {
Title *string `url:"title,omitempty" json:"title,omitempty"`
Description *string `url:"description,omitempty" json:"description,omitempty"`
Labels *Labels `url:"labels,comma,omitempty" json:"labels,omitempty"`
StartDateIsFixed *bool `url:"start_date_is_fixed,omitempty" json:"start_date_is_fixed,omitempty"`
StartDateFixed *ISOTime `url:"start_date_fixed,omitempty" json:"start_date_fixed,omitempty"`
DueDateIsFixed *bool `url:"due_date_is_fixed,omitempty" json:"due_date_is_fixed,omitempty"`
DueDateFixed *ISOTime `url:"due_date_fixed,omitempty" json:"due_date_fixed,omitempty"`
}
// CreateEpic creates a new group epic.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/epics.html#new-epic
func (s *EpicsService) CreateEpic(gid interface{}, opt *CreateEpicOptions, options ...RequestOptionFunc) (*Epic, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/epics", PathEscape(group))
req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
if err != nil {
return nil, nil, err
}
e := new(Epic)
resp, err := s.client.Do(req, e)
if err != nil {
return nil, resp, err
}
return e, resp, err
}
// UpdateEpicOptions represents the available UpdateEpic() options.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/epics.html#update-epic
type UpdateEpicOptions struct {
Title *string `url:"title,omitempty" json:"title,omitempty"`
Confidential *bool `url:"confidential,omitempty" json:"confidential,omitempty"`
Description *string `url:"description,omitempty" json:"description,omitempty"`
Labels *Labels `url:"labels,comma,omitempty" json:"labels,omitempty"`
StartDateIsFixed *bool `url:"start_date_is_fixed,omitempty" json:"start_date_is_fixed,omitempty"`
StartDateFixed *ISOTime `url:"start_date_fixed,omitempty" json:"start_date_fixed,omitempty"`
DueDateIsFixed *bool `url:"due_date_is_fixed,omitempty" json:"due_date_is_fixed,omitempty"`
DueDateFixed *ISOTime `url:"due_date_fixed,omitempty" json:"due_date_fixed,omitempty"`
StateEvent *string `url:"state_event,omitempty" json:"state_event,omitempty"`
}
// UpdateEpic updates an existing group epic. This function is also used
// to mark an epic as closed.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/epics.html#update-epic
func (s *EpicsService) UpdateEpic(gid interface{}, epic int, opt *UpdateEpicOptions, options ...RequestOptionFunc) (*Epic, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/epics/%d", PathEscape(group), epic)
req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
if err != nil {
return nil, nil, err
}
e := new(Epic)
resp, err := s.client.Do(req, e)
if err != nil {
return nil, resp, err
}
return e, resp, err
}
// DeleteEpic deletes a single group epic.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/epics.html#delete-epic
func (s *EpicsService) DeleteEpic(gid interface{}, epic int, options ...RequestOptionFunc) (*Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("groups/%s/epics/%d", PathEscape(group), epic)
req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}

196
vendor/github.com/xanzy/go-gitlab/error_tracking.go generated vendored Normal file
View File

@ -0,0 +1,196 @@
//
// Copyright 2022, Ryan Glab <ryan.j.glab@gmail.com>
//
// 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"
)
// ErrorTrackingService handles communication with the error tracking
// methods of the GitLab API.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/error_tracking.html
type ErrorTrackingService struct {
client *Client
}
// ErrorTrackingClientKey represents an error tracking client key.
//
// GitLab docs:
// https://docs.gitlab.com/ee/api/error_tracking.html#error-tracking-client-keys
type ErrorTrackingClientKey struct {
ID int `json:"id"`
Active bool `json:"active"`
PublicKey string `json:"public_key"`
SentryDsn string `json:"sentry_dsn"`
}
func (p ErrorTrackingClientKey) String() string {
return Stringify(p)
}
// ErrorTrackingSettings represents error tracking settings for a GitLab project.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/error_tracking.html#error-tracking-project-settings
type ErrorTrackingSettings struct {
Active bool `json:"active"`
ProjectName string `json:"project_name"`
SentryExternalURL string `json:"sentry_external_url"`
APIURL string `json:"api_url"`
Integrated bool `json:"integrated"`
}
func (p ErrorTrackingSettings) String() string {
return Stringify(p)
}
// GetErrorTrackingSettings gets error tracking settings.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/error_tracking.html#get-error-tracking-settings
func (s *ErrorTrackingService) GetErrorTrackingSettings(pid interface{}, options ...RequestOptionFunc) (*ErrorTrackingSettings, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/error_tracking/settings", PathEscape(project))
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}
ets := new(ErrorTrackingSettings)
resp, err := s.client.Do(req, ets)
if err != nil {
return nil, resp, err
}
return ets, resp, err
}
// EnableDisableErrorTrackingOptions represents the available
// EnableDisableErrorTracking() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/error_tracking.html#enable-or-disable-the-error-tracking-project-settings
type EnableDisableErrorTrackingOptions struct {
Active *bool `url:"active,omitempty" json:"active,omitempty"`
Integrated *bool `url:"integrated,omitempty" json:"integrated,omitempty"`
}
// EnableDisableErrorTracking allows you to enable or disable the error tracking
// settings for a project.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/error_tracking.html#enable-or-disable-the-error-tracking-project-settings
func (s *ErrorTrackingService) EnableDisableErrorTracking(pid interface{}, opt *EnableDisableErrorTrackingOptions, options ...RequestOptionFunc) (*ErrorTrackingSettings, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/error_tracking/settings", PathEscape(project))
req, err := s.client.NewRequest(http.MethodPatch, u, opt, options)
if err != nil {
return nil, nil, err
}
ets := new(ErrorTrackingSettings)
resp, err := s.client.Do(req, &ets)
if err != nil {
return nil, resp, err
}
return ets, resp, err
}
// ListClientKeysOptions represents the available ListClientKeys() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/error_tracking.html#list-project-client-keys
type ListClientKeysOptions ListOptions
// ListClientKeys lists error tracking project client keys.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/error_tracking.html#list-project-client-keys
func (s *ErrorTrackingService) ListClientKeys(pid interface{}, opt *ListClientKeysOptions, options ...RequestOptionFunc) ([]*ErrorTrackingClientKey, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/error_tracking/client_keys", PathEscape(project))
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
var cks []*ErrorTrackingClientKey
resp, err := s.client.Do(req, &cks)
if err != nil {
return nil, resp, err
}
return cks, resp, err
}
// CreateClientKey creates a new client key for a project.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/error_tracking.html#create-a-client-key
func (s *ErrorTrackingService) CreateClientKey(pid interface{}, options ...RequestOptionFunc) (*ErrorTrackingClientKey, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/error_tracking/client_keys", PathEscape(project))
req, err := s.client.NewRequest(http.MethodPost, u, nil, options)
if err != nil {
return nil, nil, err
}
ck := new(ErrorTrackingClientKey)
resp, err := s.client.Do(req, ck)
if err != nil {
return nil, resp, err
}
return ck, resp, err
}
// DeleteClientKey removes a client key from the project.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/error_tracking.html#delete-a-client-key
func (s *ErrorTrackingService) DeleteClientKey(pid interface{}, keyID int, options ...RequestOptionFunc) (*Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("projects/%s/error_tracking/client_keys/%d", PathEscape(project), keyID)
req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}

286
vendor/github.com/xanzy/go-gitlab/event_parsing.go generated vendored Normal file
View File

@ -0,0 +1,286 @@
//
// 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 (
"encoding/json"
"fmt"
"net/http"
)
// EventType represents a Gitlab event type.
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"
EventTypeFeatureFlag EventType = "Feature Flag Hook"
EventTypeIssue EventType = "Issue Hook"
EventTypeJob EventType = "Job Hook"
EventTypeMember EventType = "Member Hook"
EventTypeMergeRequest EventType = "Merge Request Hook"
EventTypeNote EventType = "Note Hook"
EventTypePipeline EventType = "Pipeline Hook"
EventTypePush EventType = "Push Hook"
EventTypeRelease EventType = "Release Hook"
EventTypeServiceHook EventType = "Service Hook"
EventTypeSubGroup EventType = "Subgroup 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"
noteableTypeIssue = "Issue"
noteableTypeMergeRequest = "MergeRequest"
noteableTypeSnippet = "Snippet"
)
type noteEvent struct {
ObjectKind string `json:"object_kind"`
ObjectAttributes struct {
NoteableType string `json:"noteable_type"`
} `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.
func HookEventType(r *http.Request) EventType {
return EventType(r.Header.Get(eventTypeHeader))
}
// ParseHook tries to parse both web- and system hooks.
//
// Example usage:
//
// func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// payload, err := ioutil.ReadAll(r.Body)
// if err != nil { ... }
// event, err := gitlab.ParseHook(gitlab.HookEventType(r), payload)
// if err != nil { ... }
// switch event := event.(type) {
// case *gitlab.PushEvent:
// processPushEvent(event)
// case *gitlab.MergeEvent:
// processMergeEvent(event)
// ...
// }
// }
func ParseHook(eventType EventType, payload []byte) (event interface{}, err error) {
switch eventType {
case EventTypeSystemHook:
return ParseSystemhook(payload)
default:
return ParseWebhook(eventType, payload)
}
}
// ParseSystemhook parses the event payload. For recognized event types, a
// value of the corresponding struct type will be returned. An error will be
// returned for unrecognized event types.
//
// Example usage:
//
// func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// payload, err := ioutil.ReadAll(r.Body)
// if err != nil { ... }
// event, err := gitlab.ParseSystemhook(payload)
// if err != nil { ... }
// switch event := event.(type) {
// case *gitlab.PushSystemEvent:
// processPushSystemEvent(event)
// case *gitlab.MergeSystemEvent:
// processMergeSystemEvent(event)
// ...
// }
// }
func ParseSystemhook(payload []byte) (event interface{}, err error) {
e := &systemHookEvent{}
err = json.Unmarshal(payload, e)
if err != nil {
return nil, err
}
switch e.EventName {
case eventObjectKindPush:
event = &PushSystemEvent{}
case eventObjectKindTagPush:
event = &TagPushSystemEvent{}
case "repository_update":
event = &RepositoryUpdateSystemEvent{}
case
"project_create",
"project_update",
"project_destroy",
"project_transfer",
"project_rename":
event = &ProjectSystemEvent{}
case
"group_create",
"group_destroy",
"group_rename":
event = &GroupSystemEvent{}
case "key_create", "key_destroy":
event = &KeySystemEvent{}
case
"user_create",
"user_destroy",
"user_rename",
"user_failed_login":
event = &UserSystemEvent{}
case
"user_add_to_group",
"user_remove_from_group",
"user_update_for_group":
event = &UserGroupSystemEvent{}
case
"user_add_to_team",
"user_remove_from_team",
"user_update_for_team":
event = &UserTeamSystemEvent{}
default:
switch e.ObjectKind {
case string(MergeRequestEventTargetType):
event = &MergeEvent{}
default:
return nil, fmt.Errorf("unexpected system hook type %s", e.EventName)
}
}
if err := json.Unmarshal(payload, event); err != nil {
return nil, err
}
return event, nil
}
// WebhookEventType returns the event type for the given request.
func WebhookEventType(r *http.Request) EventType {
return EventType(r.Header.Get(eventTypeHeader))
}
// ParseWebhook parses the event payload. For recognized event types, a
// value of the corresponding struct type will be returned. An error will
// be returned for unrecognized event types.
//
// Example usage:
//
// func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// payload, err := ioutil.ReadAll(r.Body)
// if err != nil { ... }
// event, err := gitlab.ParseWebhook(gitlab.HookEventType(r), payload)
// if err != nil { ... }
// switch event := event.(type) {
// case *gitlab.PushEvent:
// processPushEvent(event)
// case *gitlab.MergeEvent:
// processMergeEvent(event)
// ...
// }
// }
func ParseWebhook(eventType EventType, payload []byte) (event interface{}, err error) {
switch eventType {
case EventTypeBuild:
event = &BuildEvent{}
case EventTypeDeployment:
event = &DeploymentEvent{}
case EventTypeFeatureFlag:
event = &FeatureFlagEvent{}
case EventTypeIssue, EventConfidentialIssue:
event = &IssueEvent{}
case EventTypeJob:
event = &JobEvent{}
case EventTypeMember:
event = &MemberEvent{}
case EventTypeMergeRequest:
event = &MergeEvent{}
case EventTypeNote, EventConfidentialNote:
note := &noteEvent{}
err := json.Unmarshal(payload, note)
if err != nil {
return nil, err
}
if note.ObjectKind != string(NoteEventTargetType) {
return nil, fmt.Errorf("unexpected object kind %s", note.ObjectKind)
}
switch note.ObjectAttributes.NoteableType {
case noteableTypeCommit:
event = &CommitCommentEvent{}
case noteableTypeMergeRequest:
event = &MergeCommentEvent{}
case noteableTypeIssue:
event = &IssueCommentEvent{}
case noteableTypeSnippet:
event = &SnippetCommentEvent{}
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 EventTypeSubGroup:
event = &SubGroupEvent{}
case EventTypeTagPush:
event = &TagEvent{}
case EventTypeWikiPage:
event = &WikiPageEvent{}
default:
return nil, fmt.Errorf("unexpected event type: %s", eventType)
}
if err := json.Unmarshal(payload, event); err != nil {
return nil, err
}
return event, nil
}

View File

@ -0,0 +1,249 @@
//
// 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 "time"
// systemHookEvent is used to pre-process events to determine the
// system hook event type.
type systemHookEvent struct {
BaseSystemEvent
ObjectKind string `json:"object_kind"`
}
// BaseSystemEvent contains system hook's common properties.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/administration/system_hooks.html
type BaseSystemEvent struct {
EventName string `json:"event_name"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
}
// ProjectSystemEvent represents a project system event.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/administration/system_hooks.html
type ProjectSystemEvent struct {
BaseSystemEvent
Name string `json:"name"`
Path string `json:"path"`
PathWithNamespace string `json:"path_with_namespace"`
ProjectID int `json:"project_id"`
OwnerName string `json:"owner_name"`
OwnerEmail string `json:"owner_email"`
ProjectVisibility string `json:"project_visibility"`
OldPathWithNamespace string `json:"old_path_with_namespace,omitempty"`
}
// GroupSystemEvent represents a group system event.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/administration/system_hooks.html
type GroupSystemEvent struct {
BaseSystemEvent
Name string `json:"name"`
Path string `json:"path"`
PathWithNamespace string `json:"full_path"`
GroupID int `json:"group_id"`
OwnerName string `json:"owner_name"`
OwnerEmail string `json:"owner_email"`
ProjectVisibility string `json:"project_visibility"`
OldPath string `json:"old_path,omitempty"`
OldPathWithNamespace string `json:"old_full_path,omitempty"`
}
// KeySystemEvent represents a key system event.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/administration/system_hooks.html
type KeySystemEvent struct {
BaseSystemEvent
ID int `json:"id"`
Username string `json:"username"`
Key string `json:"key"`
}
// UserSystemEvent represents a user system event.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/administration/system_hooks.html
type UserSystemEvent struct {
BaseSystemEvent
ID int `json:"user_id"`
Name string `json:"name"`
Username string `json:"username"`
OldUsername string `json:"old_username,omitempty"`
Email string `json:"email"`
State string `json:"state,omitempty"`
}
// UserGroupSystemEvent represents a user group system event.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/administration/system_hooks.html
type UserGroupSystemEvent struct {
BaseSystemEvent
ID int `json:"user_id"`
Name string `json:"user_name"`
Username string `json:"user_username"`
Email string `json:"user_email"`
GroupID int `json:"group_id"`
GroupName string `json:"group_name"`
GroupPath string `json:"group_path"`
GroupAccess string `json:"group_access"`
}
// UserTeamSystemEvent represents a user team system event.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/administration/system_hooks.html
type UserTeamSystemEvent struct {
BaseSystemEvent
ID int `json:"user_id"`
Name string `json:"user_name"`
Username string `json:"user_username"`
Email string `json:"user_email"`
ProjectID int `json:"project_id"`
ProjectName string `json:"project_name"`
ProjectPath string `json:"project_path"`
ProjectPathWithNamespace string `json:"project_path_with_namespace"`
ProjectVisibility string `json:"project_visibility"`
AccessLevel string `json:"access_level"`
}
// PushSystemEvent represents a push system event.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/administration/system_hooks.html#push-events
type PushSystemEvent struct {
BaseSystemEvent
Before string `json:"before"`
After string `json:"after"`
Ref string `json:"ref"`
CheckoutSHA string `json:"checkout_sha"`
UserID int `json:"user_id"`
UserName string `json:"user_name"`
UserUsername string `json:"user_username"`
UserEmail string `json:"user_email"`
UserAvatar string `json:"user_avatar"`
ProjectID int `json:"project_id"`
Project struct {
Name string `json:"name"`
Description string `json:"description"`
WebURL string `json:"web_url"`
AvatarURL string `json:"avatar_url"`
GitHTTPURL string `json:"git_http_url"`
GitSSHURL string `json:"git_ssh_url"`
Namespace string `json:"namespace"`
VisibilityLevel int `json:"visibility_level"`
PathWithNamespace string `json:"path_with_namespace"`
DefaultBranch string `json:"default_branch"`
Homepage string `json:"homepage"`
URL string `json:"url"`
} `json:"project"`
Commits []struct {
ID string `json:"id"`
Message string `json:"message"`
Timestamp time.Time `json:"timestamp"`
URL string `json:"url"`
Author struct {
Name string `json:"name"`
Email string `json:"email"`
} `json:"author"`
} `json:"commits"`
TotalCommitsCount int `json:"total_commits_count"`
}
// TagPushSystemEvent represents a tag push system event.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/administration/system_hooks.html#tag-events
type TagPushSystemEvent struct {
BaseSystemEvent
Before string `json:"before"`
After string `json:"after"`
Ref string `json:"ref"`
CheckoutSHA string `json:"checkout_sha"`
UserID int `json:"user_id"`
UserName string `json:"user_name"`
UserUsername string `json:"user_username"`
UserEmail string `json:"user_email"`
UserAvatar string `json:"user_avatar"`
ProjectID int `json:"project_id"`
Project struct {
Name string `json:"name"`
Description string `json:"description"`
WebURL string `json:"web_url"`
AvatarURL string `json:"avatar_url"`
GitHTTPURL string `json:"git_http_url"`
GitSSHURL string `json:"git_ssh_url"`
Namespace string `json:"namespace"`
VisibilityLevel int `json:"visibility_level"`
PathWithNamespace string `json:"path_with_namespace"`
DefaultBranch string `json:"default_branch"`
Homepage string `json:"homepage"`
URL string `json:"url"`
} `json:"project"`
Commits []struct {
ID string `json:"id"`
Message string `json:"message"`
Timestamp time.Time `json:"timestamp"`
URL string `json:"url"`
Author struct {
Name string `json:"name"`
Email string `json:"email"`
} `json:"author"`
} `json:"commits"`
TotalCommitsCount int `json:"total_commits_count"`
}
// RepositoryUpdateSystemEvent represents a repository updated system event.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/administration/system_hooks.html#repository-update-events
type RepositoryUpdateSystemEvent struct {
BaseSystemEvent
UserID int `json:"user_id"`
UserName string `json:"user_name"`
UserEmail string `json:"user_email"`
UserAvatar string `json:"user_avatar"`
ProjectID int `json:"project_id"`
Project struct {
ID int `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
WebURL string `json:"web_url"`
AvatarURL string `json:"avatar_url"`
GitHTTPURL string `json:"git_http_url"`
GitSSHURL string `json:"git_ssh_url"`
Namespace string `json:"namespace"`
VisibilityLevel int `json:"visibility_level"`
PathWithNamespace string `json:"path_with_namespace"`
DefaultBranch string `json:"default_branch"`
CiConfigPath string `json:"ci_config_path"`
Homepage string `json:"homepage"`
URL string `json:"url"`
} `json:"project"`
Changes []struct {
Before string `json:"before"`
After string `json:"after"`
Ref string `json:"ref"`
} `json:"changes"`
Refs []string `json:"refs"`
}

1173
vendor/github.com/xanzy/go-gitlab/event_webhook_types.go generated vendored Normal file

File diff suppressed because it is too large Load Diff

224
vendor/github.com/xanzy/go-gitlab/events.go generated vendored Normal file
View File

@ -0,0 +1,224 @@
//
// 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"
"time"
)
// EventsService handles communication with the event related methods of
// the GitLab API.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/events.html
type EventsService struct {
client *Client
}
// ContributionEvent represents a user's contribution
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/events.html#get-user-contribution-events
type ContributionEvent struct {
ID int `json:"id"`
Title string `json:"title"`
ProjectID int `json:"project_id"`
ActionName string `json:"action_name"`
TargetID int `json:"target_id"`
TargetIID int `json:"target_iid"`
TargetType string `json:"target_type"`
AuthorID int `json:"author_id"`
TargetTitle string `json:"target_title"`
CreatedAt *time.Time `json:"created_at"`
PushData struct {
CommitCount int `json:"commit_count"`
Action string `json:"action"`
RefType string `json:"ref_type"`
CommitFrom string `json:"commit_from"`
CommitTo string `json:"commit_to"`
Ref string `json:"ref"`
CommitTitle string `json:"commit_title"`
} `json:"push_data"`
Note *Note `json:"note"`
Author struct {
Name string `json:"name"`
Username string `json:"username"`
ID int `json:"id"`
State string `json:"state"`
AvatarURL string `json:"avatar_url"`
WebURL string `json:"web_url"`
} `json:"author"`
AuthorUsername string `json:"author_username"`
}
// ListContributionEventsOptions represents the options for GetUserContributionEvents
//
// GitLap API docs:
// https://docs.gitlab.com/ee/api/events.html#get-user-contribution-events
type ListContributionEventsOptions struct {
ListOptions
Action *EventTypeValue `url:"action,omitempty" json:"action,omitempty"`
TargetType *EventTargetTypeValue `url:"target_type,omitempty" json:"target_type,omitempty"`
Before *ISOTime `url:"before,omitempty" json:"before,omitempty"`
After *ISOTime `url:"after,omitempty" json:"after,omitempty"`
Sort *string `url:"sort,omitempty" json:"sort,omitempty"`
}
// ListUserContributionEvents retrieves user contribution events
// for the specified user, sorted from newest to oldest.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/events.html#get-user-contribution-events
func (s *UsersService) ListUserContributionEvents(uid interface{}, opt *ListContributionEventsOptions, options ...RequestOptionFunc) ([]*ContributionEvent, *Response, error) {
user, err := parseID(uid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("users/%s/events", user)
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
var cs []*ContributionEvent
resp, err := s.client.Do(req, &cs)
if err != nil {
return nil, resp, err
}
return cs, resp, err
}
// ListCurrentUserContributionEvents gets a list currently authenticated user's events
//
// GitLab API docs: https://docs.gitlab.com/ee/api/events.html#list-currently-authenticated-users-events
func (s *EventsService) ListCurrentUserContributionEvents(opt *ListContributionEventsOptions, options ...RequestOptionFunc) ([]*ContributionEvent, *Response, error) {
req, err := s.client.NewRequest(http.MethodGet, "events", opt, options)
if err != nil {
return nil, nil, err
}
var cs []*ContributionEvent
resp, err := s.client.Do(req, &cs)
if err != nil {
return nil, resp, err
}
return cs, resp, err
}
// ProjectEvent represents a GitLab project event.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/events.html#list-a-projects-visible-events
type ProjectEvent struct {
ID int `json:"id"`
Title string `json:"title"`
ProjectID int `json:"project_id"`
ActionName string `json:"action_name"`
TargetID int `json:"target_id"`
TargetIID int `json:"target_iid"`
TargetType string `json:"target_type"`
AuthorID int `json:"author_id"`
TargetTitle string `json:"target_title"`
CreatedAt string `json:"created_at"`
Author struct {
Name string `json:"name"`
Username string `json:"username"`
ID int `json:"id"`
State string `json:"state"`
AvatarURL string `json:"avatar_url"`
WebURL string `json:"web_url"`
} `json:"author"`
AuthorUsername string `json:"author_username"`
Data struct {
Before string `json:"before"`
After string `json:"after"`
Ref string `json:"ref"`
UserID int `json:"user_id"`
UserName string `json:"user_name"`
Repository *Repository `json:"repository"`
Commits []*Commit `json:"commits"`
TotalCommitsCount int `json:"total_commits_count"`
} `json:"data"`
Note struct {
ID int `json:"id"`
Body string `json:"body"`
Attachment string `json:"attachment"`
Author struct {
ID int `json:"id"`
Username string `json:"username"`
Email string `json:"email"`
Name string `json:"name"`
State string `json:"state"`
AvatarURL string `json:"avatar_url"`
WebURL string `json:"web_url"`
} `json:"author"`
CreatedAt *time.Time `json:"created_at"`
System bool `json:"system"`
NoteableID int `json:"noteable_id"`
NoteableType string `json:"noteable_type"`
NoteableIID int `json:"noteable_iid"`
} `json:"note"`
PushData struct {
CommitCount int `json:"commit_count"`
Action string `json:"action"`
RefType string `json:"ref_type"`
CommitFrom string `json:"commit_from"`
CommitTo string `json:"commit_to"`
Ref string `json:"ref"`
CommitTitle string `json:"commit_title"`
} `json:"push_data"`
}
func (s ProjectEvent) String() string {
return Stringify(s)
}
// ListProjectVisibleEventsOptions represents the available
// ListProjectVisibleEvents() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/events.html#list-a-projects-visible-events
type ListProjectVisibleEventsOptions ListOptions
// ListProjectVisibleEvents gets the events for the specified project.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/events.html#list-a-projects-visible-events
func (s *EventsService) ListProjectVisibleEvents(pid interface{}, opt *ListProjectVisibleEventsOptions, options ...RequestOptionFunc) ([]*ProjectEvent, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/events", PathEscape(project))
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
var p []*ProjectEvent
resp, err := s.client.Do(req, &p)
if err != nil {
return nil, resp, err
}
return p, resp, err
}

View File

@ -0,0 +1,199 @@
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
}
// SetExternalStatusCheckStatusOptions represents the available
// SetExternalStatusCheckStatus() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/status_checks.html#set-status-of-an-external-status-check
type SetExternalStatusCheckStatusOptions struct {
SHA *string `url:"sha,omitempty" json:"sha,omitempty"`
ExternalStatusCheckID *int `url:"external_status_check_id,omitempty" json:"external_status_check_id,omitempty"`
Status *string `url:"status,omitempty" json:"status,omitempty"`
}
// SetExternalStatusCheckStatus sets the status of an external status check.
//
// Gitlab API docs:
// https://docs.gitlab.com/ee/api/status_checks.html#set-status-of-an-external-status-check
func (s *ExternalStatusChecksService) SetExternalStatusCheckStatus(pid interface{}, mergeRequest int, opt *SetExternalStatusCheckStatusOptions, options ...RequestOptionFunc) (*Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("projects/%s/merge_requests/%d/status_check_responses", PathEscape(project), mergeRequest)
req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}
// 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
}
// CreateExternalStatusCheckOptions represents the available
// CreateExternalStatusCheck() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/status_checks.html#create-external-status-check
type CreateExternalStatusCheckOptions struct {
Name *string `url:"name,omitempty" json:"name,omitempty"`
ExternalURL *string `url:"external_url,omitempty" json:"external_url,omitempty"`
ProtectedBranchIDs *[]int `url:"protected_branch_ids,omitempty" json:"protected_branch_ids,omitempty"`
}
// CreateExternalStatusCheck creates an external status check.
//
// Gitlab API docs:
// https://docs.gitlab.com/ee/api/status_checks.html#create-external-status-check
func (s *ExternalStatusChecksService) CreateExternalStatusCheck(pid interface{}, opt *CreateExternalStatusCheckOptions, options ...RequestOptionFunc) (*Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("projects/%s/external_status_checks", PathEscape(project))
req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}
// DeleteExternalStatusCheck deletes an external status check.
//
// Gitlab API docs:
// https://docs.gitlab.com/ee/api/status_checks.html#delete-external-status-check
func (s *ExternalStatusChecksService) DeleteExternalStatusCheck(pid interface{}, check int, options ...RequestOptionFunc) (*Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("projects/%s/external_status_checks/%d", PathEscape(project), check)
req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}
// UpdateExternalStatusCheckOptions represents the available
// UpdateExternalStatusCheck() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/status_checks.html#update-external-status-check
type UpdateExternalStatusCheckOptions struct {
Name *string `url:"name,omitempty" json:"name,omitempty"`
ExternalURL *string `url:"external_url,omitempty" json:"external_url,omitempty"`
ProtectedBranchIDs *[]int `url:"protected_branch_ids,omitempty" json:"protected_branch_ids,omitempty"`
}
// UpdateExternalStatusCheck updates an external status check.
//
// Gitlab API docs:
// https://docs.gitlab.com/ee/api/status_checks.html#update-external-status-check
func (s *ExternalStatusChecksService) UpdateExternalStatusCheck(pid interface{}, check int, opt *UpdateExternalStatusCheckOptions, options ...RequestOptionFunc) (*Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("projects/%s/external_status_checks/%d", PathEscape(project), check)
req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}

96
vendor/github.com/xanzy/go-gitlab/feature_flags.go generated vendored Normal file
View File

@ -0,0 +1,96 @@
//
// 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"
"net/url"
)
// FeaturesService handles the communication with the application FeaturesService
// related methods of the GitLab API.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/features.html
type FeaturesService struct {
client *Client
}
// Feature represents a GitLab feature flag.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/features.html
type Feature struct {
Name string `json:"name"`
State string `json:"state"`
Gates []Gate
}
// Gate represents a gate of a GitLab feature flag.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/features.html
type Gate struct {
Key string `json:"key"`
Value interface{} `json:"value"`
}
func (f Feature) String() string {
return Stringify(f)
}
// ListFeatures gets a list of feature flags
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/features.html#list-all-features
func (s *FeaturesService) ListFeatures(options ...RequestOptionFunc) ([]*Feature, *Response, error) {
req, err := s.client.NewRequest(http.MethodGet, "features", nil, options)
if err != nil {
return nil, nil, err
}
var f []*Feature
resp, err := s.client.Do(req, &f)
if err != nil {
return nil, resp, err
}
return f, resp, err
}
// SetFeatureFlag sets or creates a feature flag gate
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/features.html#set-or-create-a-feature
func (s *FeaturesService) SetFeatureFlag(name string, value interface{}, options ...RequestOptionFunc) (*Feature, *Response, error) {
u := fmt.Sprintf("features/%s", url.PathEscape(name))
opt := struct {
Value interface{} `url:"value" json:"value"`
}{
value,
}
req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
if err != nil {
return nil, nil, err
}
f := &Feature{}
resp, err := s.client.Do(req, f)
if err != nil {
return nil, resp, err
}
return f, resp, err
}

194
vendor/github.com/xanzy/go-gitlab/freeze_periods.go generated vendored Normal file
View File

@ -0,0 +1,194 @@
//
// Copyright 2021 Paul Cioanca
//
// 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"
"time"
)
// FreezePeriodsService handles the communication with the freeze periods
// related methods of the GitLab API.
//
// https://docs.gitlab.com/ee/api/freeze_periods.html
type FreezePeriodsService struct {
client *Client
}
// FreezePeriod represents a freeze period object.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/freeze_periods.html#list-freeze-periods
type FreezePeriod struct {
ID int `json:"id"`
FreezeStart string `json:"freeze_start"`
FreezeEnd string `json:"freeze_end"`
CronTimezone string `json:"cron_timezone"`
CreatedAt *time.Time `json:"created_at"`
UpdatedAt *time.Time `json:"updated_at"`
}
// ListFreezePeriodsOptions represents the available ListFreezePeriodsOptions()
// options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/freeze_periods.html#list-freeze-periods
type ListFreezePeriodsOptions ListOptions
// ListFreezePeriods gets a list of project project freeze periods.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/freeze_periods.html#list-freeze-periods
func (s *FreezePeriodsService) ListFreezePeriods(pid interface{}, opt *ListFreezePeriodsOptions, options ...RequestOptionFunc) ([]*FreezePeriod, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/freeze_periods", PathEscape(project))
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
var fp []*FreezePeriod
resp, err := s.client.Do(req, &fp)
if err != nil {
return nil, resp, err
}
return fp, resp, err
}
// GetFreezePeriod gets a specific freeze period for a project.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/freeze_periods.html#get-a-freeze-period-by-a-freeze_period_id
func (s *FreezePeriodsService) GetFreezePeriod(pid interface{}, freezePeriod int, options ...RequestOptionFunc) (*FreezePeriod, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/freeze_periods/%d", PathEscape(project), freezePeriod)
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}
fp := new(FreezePeriod)
resp, err := s.client.Do(req, fp)
if err != nil {
return nil, resp, err
}
return fp, resp, err
}
// CreateFreezePeriodOptions represents the available CreateFreezePeriodOptions()
// options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/freeze_periods.html#create-a-freeze-period
type CreateFreezePeriodOptions struct {
FreezeStart *string `url:"freeze_start,omitempty" json:"freeze_start,omitempty"`
FreezeEnd *string `url:"freeze_end,omitempty" json:"freeze_end,omitempty"`
CronTimezone *string `url:"cron_timezone,omitempty" json:"cron_timezone,omitempty"`
}
// CreateFreezePeriodOptions adds a freeze period to a specified project.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/freeze_periods.html#create-a-freeze-period
func (s *FreezePeriodsService) CreateFreezePeriodOptions(pid interface{}, opt *CreateFreezePeriodOptions, options ...RequestOptionFunc) (*FreezePeriod, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/freeze_periods", PathEscape(project))
req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
if err != nil {
return nil, nil, err
}
fp := new(FreezePeriod)
resp, err := s.client.Do(req, fp)
if err != nil {
return nil, resp, err
}
return fp, resp, err
}
// UpdateFreezePeriodOptions represents the available UpdateFreezePeriodOptions()
// options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/freeze_periods.html#update-a-freeze-period
type UpdateFreezePeriodOptions struct {
FreezeStart *string `url:"freeze_start,omitempty" json:"freeze_start,omitempty"`
FreezeEnd *string `url:"freeze_end,omitempty" json:"freeze_end,omitempty"`
CronTimezone *string `url:"cron_timezone,omitempty" json:"cron_timezone,omitempty"`
}
// UpdateFreezePeriodOptions edits a freeze period for a specified project.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/freeze_periods.html#update-a-freeze-period
func (s *FreezePeriodsService) UpdateFreezePeriodOptions(pid interface{}, freezePeriod int, opt *UpdateFreezePeriodOptions, options ...RequestOptionFunc) (*FreezePeriod, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/freeze_periods/%d", PathEscape(project), freezePeriod)
req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
if err != nil {
return nil, nil, err
}
fp := new(FreezePeriod)
resp, err := s.client.Do(req, fp)
if err != nil {
return nil, resp, err
}
return fp, resp, err
}
// DeleteFreezePeriod removes a freeze period from a project. This is an
// idempotent method and can be called multiple times. Either the hook is
// available or not.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/freeze_periods.html#delete-a-freeze-period
func (s *FreezePeriodsService) DeleteFreezePeriod(pid interface{}, freezePeriod int, options ...RequestOptionFunc) (*Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("projects/%s/freeze_periods/%d", PathEscape(project), freezePeriod)
req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}

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

@ -0,0 +1,93 @@
//
// 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"
"net/url"
)
// GitIgnoreTemplatesService handles communication with the gitignore
// templates related methods of the GitLab API.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/templates/gitignores.html
type GitIgnoreTemplatesService struct {
client *Client
}
// GitIgnoreTemplate represents a GitLab gitignore template.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/templates/gitignores.html
type GitIgnoreTemplate struct {
Name string `json:"name"`
Content string `json:"content"`
}
// GitIgnoreTemplateListItem represents a GitLab gitignore template from the list.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/templates/gitignores.html
type GitIgnoreTemplateListItem struct {
Key string `json:"key"`
Name string `json:"name"`
}
// ListTemplatesOptions represents the available ListAllTemplates() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/templates/gitignores.html#get-all-gitignore-templates
type ListTemplatesOptions ListOptions
// ListTemplates get a list of available git ignore templates
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/templates/gitignores.html#get-all-gitignore-templates
func (s *GitIgnoreTemplatesService) ListTemplates(opt *ListTemplatesOptions, options ...RequestOptionFunc) ([]*GitIgnoreTemplateListItem, *Response, error) {
req, err := s.client.NewRequest(http.MethodGet, "templates/gitignores", opt, options)
if err != nil {
return nil, nil, err
}
var gs []*GitIgnoreTemplateListItem
resp, err := s.client.Do(req, &gs)
if err != nil {
return nil, resp, err
}
return gs, resp, err
}
// GetTemplate get a git ignore template
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/templates/gitignores.html#get-a-single-gitignore-template
func (s *GitIgnoreTemplatesService) GetTemplate(key string, options ...RequestOptionFunc) (*GitIgnoreTemplate, *Response, error) {
u := fmt.Sprintf("templates/gitignores/%s", url.PathEscape(key))
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}
g := new(GitIgnoreTemplate)
resp, err := s.client.Do(req, g)
if err != nil {
return nil, resp, err
}
return g, resp, err
}

952
vendor/github.com/xanzy/go-gitlab/gitlab.go generated vendored Normal file
View File

@ -0,0 +1,952 @@
//
// 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 implements a GitLab API client.
package gitlab
import (
"bytes"
"context"
"encoding/json"
"fmt"
"io"
"math/rand"
"mime/multipart"
"net/http"
"net/url"
"sort"
"strconv"
"strings"
"sync"
"time"
"github.com/google/go-querystring/query"
"github.com/hashicorp/go-cleanhttp"
retryablehttp "github.com/hashicorp/go-retryablehttp"
"golang.org/x/oauth2"
"golang.org/x/time/rate"
)
const (
defaultBaseURL = "https://gitlab.com/"
apiVersionPath = "api/v4/"
userAgent = "go-gitlab"
headerRateLimit = "RateLimit-Limit"
headerRateReset = "RateLimit-Reset"
)
// AuthType represents an authentication type within GitLab.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/
type AuthType int
// List of available authentication types.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/
const (
BasicAuth AuthType = iota
JobToken
OAuthToken
PrivateToken
)
// A Client manages communication with the GitLab API.
type Client struct {
// HTTP client used to communicate with the API.
client *retryablehttp.Client
// Base URL for API requests. Defaults to the public GitLab API, but can be
// set to a domain endpoint to use with a self hosted GitLab server. baseURL
// should always be specified with a trailing slash.
baseURL *url.URL
// disableRetries is used to disable the default retry logic.
disableRetries bool
// configureLimiterOnce is used to make sure the limiter is configured exactly
// once and block all other calls until the initial (one) call is done.
configureLimiterOnce sync.Once
// Limiter is used to limit API calls and prevent 429 responses.
limiter RateLimiter
// Token type used to make authenticated API calls.
authType AuthType
// Username and password used for basic authentication.
username, password string
// Token used to make authenticated API calls.
token string
// Protects the token field from concurrent read/write accesses.
tokenLock sync.RWMutex
// Default request options applied to every request.
defaultRequestOptions []RequestOptionFunc
// User agent used when communicating with the GitLab API.
UserAgent string
// Services used for talking to different parts of the GitLab API.
AccessRequests *AccessRequestsService
Applications *ApplicationsService
AuditEvents *AuditEventsService
Avatar *AvatarRequestsService
AwardEmoji *AwardEmojiService
Boards *IssueBoardsService
Branches *BranchesService
BroadcastMessage *BroadcastMessagesService
CIYMLTemplate *CIYMLTemplatesService
ClusterAgents *ClusterAgentsService
Commits *CommitsService
ContainerRegistry *ContainerRegistryService
CustomAttribute *CustomAttributesService
DeployKeys *DeployKeysService
DeployTokens *DeployTokensService
DeploymentMergeRequests *DeploymentMergeRequestsService
Deployments *DeploymentsService
Discussions *DiscussionsService
DockerfileTemplate *DockerfileTemplatesService
Environments *EnvironmentsService
EpicIssues *EpicIssuesService
Epics *EpicsService
ErrorTracking *ErrorTrackingService
Events *EventsService
ExternalStatusChecks *ExternalStatusChecksService
Features *FeaturesService
FreezePeriods *FreezePeriodsService
GenericPackages *GenericPackagesService
GeoNodes *GeoNodesService
GitIgnoreTemplates *GitIgnoreTemplatesService
GroupAccessTokens *GroupAccessTokensService
GroupBadges *GroupBadgesService
GroupCluster *GroupClustersService
GroupImportExport *GroupImportExportService
GroupIssueBoards *GroupIssueBoardsService
GroupIterations *GroupIterationsService
GroupLabels *GroupLabelsService
GroupMembers *GroupMembersService
GroupMilestones *GroupMilestonesService
GroupVariables *GroupVariablesService
GroupWikis *GroupWikisService
Groups *GroupsService
InstanceCluster *InstanceClustersService
InstanceVariables *InstanceVariablesService
Invites *InvitesService
IssueLinks *IssueLinksService
Issues *IssuesService
IssuesStatistics *IssuesStatisticsService
Jobs *JobsService
Keys *KeysService
Labels *LabelsService
License *LicenseService
LicenseTemplates *LicenseTemplatesService
ManagedLicenses *ManagedLicensesService
Markdown *MarkdownService
MergeRequestApprovals *MergeRequestApprovalsService
MergeRequests *MergeRequestsService
Metadata *MetadataService
Milestones *MilestonesService
Namespaces *NamespacesService
Notes *NotesService
NotificationSettings *NotificationSettingsService
Packages *PackagesService
Pages *PagesService
PagesDomains *PagesDomainsService
PersonalAccessTokens *PersonalAccessTokensService
PipelineSchedules *PipelineSchedulesService
PipelineTriggers *PipelineTriggersService
Pipelines *PipelinesService
PlanLimits *PlanLimitsService
ProjectAccessTokens *ProjectAccessTokensService
ProjectBadges *ProjectBadgesService
ProjectCluster *ProjectClustersService
ProjectFeatureFlags *ProjectFeatureFlagService
ProjectImportExport *ProjectImportExportService
ProjectIterations *ProjectIterationsService
ProjectMembers *ProjectMembersService
ProjectMirrors *ProjectMirrorService
ProjectSnippets *ProjectSnippetsService
ProjectTemplates *ProjectTemplatesService
ProjectVariables *ProjectVariablesService
ProjectVulnerabilities *ProjectVulnerabilitiesService
Projects *ProjectsService
ProtectedBranches *ProtectedBranchesService
ProtectedEnvironments *ProtectedEnvironmentsService
ProtectedTags *ProtectedTagsService
ReleaseLinks *ReleaseLinksService
Releases *ReleasesService
Repositories *RepositoriesService
RepositoryFiles *RepositoryFilesService
RepositorySubmodules *RepositorySubmodulesService
ResourceLabelEvents *ResourceLabelEventsService
ResourceMilestoneEvents *ResourceMilestoneEventsService
ResourceStateEvents *ResourceStateEventsService
ResourceWeightEvents *ResourceWeightEventsService
Runners *RunnersService
Search *SearchService
Services *ServicesService
Settings *SettingsService
Sidekiq *SidekiqService
Snippets *SnippetsService
SystemHooks *SystemHooksService
Tags *TagsService
Todos *TodosService
Topics *TopicsService
Users *UsersService
Validate *ValidateService
Version *VersionService
Wikis *WikisService
}
// ListOptions specifies the optional parameters to various List methods that
// support pagination.
type ListOptions struct {
// For paginated result sets, page of results to retrieve.
Page int `url:"page,omitempty" json:"page,omitempty"`
// For paginated result sets, the number of results to include per page.
PerPage int `url:"per_page,omitempty" json:"per_page,omitempty"`
}
// RateLimiter describes the interface that all (custom) rate limiters must implement.
type RateLimiter interface {
Wait(context.Context) error
}
// NewClient returns a new GitLab API client. To use API methods which require
// authentication, provide a valid private or personal token.
func NewClient(token string, options ...ClientOptionFunc) (*Client, error) {
client, err := newClient(options...)
if err != nil {
return nil, err
}
client.authType = PrivateToken
client.token = token
return client, nil
}
// NewBasicAuthClient returns a new GitLab API client. To use API methods which
// require authentication, provide a valid username and password.
func NewBasicAuthClient(username, password string, options ...ClientOptionFunc) (*Client, error) {
client, err := newClient(options...)
if err != nil {
return nil, err
}
client.authType = BasicAuth
client.username = username
client.password = password
return client, nil
}
// NewJobClient returns a new GitLab API client. To use API methods which require
// authentication, provide a valid job token.
func NewJobClient(token string, options ...ClientOptionFunc) (*Client, error) {
client, err := newClient(options...)
if err != nil {
return nil, err
}
client.authType = JobToken
client.token = token
return client, nil
}
// NewOAuthClient returns a new GitLab API client. To use API methods which
// require authentication, provide a valid oauth token.
func NewOAuthClient(token string, options ...ClientOptionFunc) (*Client, error) {
client, err := newClient(options...)
if err != nil {
return nil, err
}
client.authType = OAuthToken
client.token = token
return client, nil
}
func newClient(options ...ClientOptionFunc) (*Client, error) {
c := &Client{UserAgent: userAgent}
// Configure the HTTP client.
c.client = &retryablehttp.Client{
Backoff: c.retryHTTPBackoff,
CheckRetry: c.retryHTTPCheck,
ErrorHandler: retryablehttp.PassthroughErrorHandler,
HTTPClient: cleanhttp.DefaultPooledClient(),
RetryWaitMin: 100 * time.Millisecond,
RetryWaitMax: 400 * time.Millisecond,
RetryMax: 5,
}
// Set the default base URL.
c.setBaseURL(defaultBaseURL)
// Apply any given client options.
for _, fn := range options {
if fn == nil {
continue
}
if err := fn(c); err != nil {
return nil, err
}
}
// If no custom limiter was set using a client option, configure
// the default rate limiter with values that implicitly disable
// rate limiting until an initial HTTP call is done and we can
// use the headers to try and properly configure the limiter.
if c.limiter == nil {
c.limiter = rate.NewLimiter(rate.Inf, 0)
}
// Create the internal timeStats service.
timeStats := &timeStatsService{client: c}
// Create all the public services.
c.AccessRequests = &AccessRequestsService{client: c}
c.Applications = &ApplicationsService{client: c}
c.AuditEvents = &AuditEventsService{client: c}
c.Avatar = &AvatarRequestsService{client: c}
c.AwardEmoji = &AwardEmojiService{client: c}
c.Boards = &IssueBoardsService{client: c}
c.Branches = &BranchesService{client: c}
c.BroadcastMessage = &BroadcastMessagesService{client: c}
c.CIYMLTemplate = &CIYMLTemplatesService{client: c}
c.ClusterAgents = &ClusterAgentsService{client: c}
c.Commits = &CommitsService{client: c}
c.ContainerRegistry = &ContainerRegistryService{client: c}
c.CustomAttribute = &CustomAttributesService{client: c}
c.DeployKeys = &DeployKeysService{client: c}
c.DeployTokens = &DeployTokensService{client: c}
c.DeploymentMergeRequests = &DeploymentMergeRequestsService{client: c}
c.Deployments = &DeploymentsService{client: c}
c.Discussions = &DiscussionsService{client: c}
c.DockerfileTemplate = &DockerfileTemplatesService{client: c}
c.Environments = &EnvironmentsService{client: c}
c.EpicIssues = &EpicIssuesService{client: c}
c.Epics = &EpicsService{client: c}
c.ErrorTracking = &ErrorTrackingService{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.GroupAccessTokens = &GroupAccessTokensService{client: c}
c.GroupBadges = &GroupBadgesService{client: c}
c.GroupCluster = &GroupClustersService{client: c}
c.GroupImportExport = &GroupImportExportService{client: c}
c.GroupIssueBoards = &GroupIssueBoardsService{client: c}
c.GroupIterations = &GroupIterationsService{client: c}
c.GroupLabels = &GroupLabelsService{client: c}
c.GroupMembers = &GroupMembersService{client: c}
c.GroupMilestones = &GroupMilestonesService{client: c}
c.GroupVariables = &GroupVariablesService{client: c}
c.GroupWikis = &GroupWikisService{client: c}
c.Groups = &GroupsService{client: c}
c.InstanceCluster = &InstanceClustersService{client: c}
c.InstanceVariables = &InstanceVariablesService{client: c}
c.Invites = &InvitesService{client: c}
c.IssueLinks = &IssueLinksService{client: c}
c.Issues = &IssuesService{client: c, timeStats: timeStats}
c.IssuesStatistics = &IssuesStatisticsService{client: c}
c.Jobs = &JobsService{client: c}
c.Keys = &KeysService{client: c}
c.Labels = &LabelsService{client: c}
c.License = &LicenseService{client: c}
c.LicenseTemplates = &LicenseTemplatesService{client: c}
c.ManagedLicenses = &ManagedLicensesService{client: c}
c.Markdown = &MarkdownService{client: c}
c.MergeRequestApprovals = &MergeRequestApprovalsService{client: c}
c.MergeRequests = &MergeRequestsService{client: c, timeStats: timeStats}
c.Metadata = &MetadataService{client: c}
c.Milestones = &MilestonesService{client: c}
c.Namespaces = &NamespacesService{client: c}
c.Notes = &NotesService{client: c}
c.NotificationSettings = &NotificationSettingsService{client: c}
c.Packages = &PackagesService{client: c}
c.Pages = &PagesService{client: c}
c.PagesDomains = &PagesDomainsService{client: c}
c.PersonalAccessTokens = &PersonalAccessTokensService{client: c}
c.PipelineSchedules = &PipelineSchedulesService{client: c}
c.PipelineTriggers = &PipelineTriggersService{client: c}
c.Pipelines = &PipelinesService{client: c}
c.PlanLimits = &PlanLimitsService{client: c}
c.ProjectAccessTokens = &ProjectAccessTokensService{client: c}
c.ProjectBadges = &ProjectBadgesService{client: c}
c.ProjectCluster = &ProjectClustersService{client: c}
c.ProjectFeatureFlags = &ProjectFeatureFlagService{client: c}
c.ProjectImportExport = &ProjectImportExportService{client: c}
c.ProjectIterations = &ProjectIterationsService{client: c}
c.ProjectMembers = &ProjectMembersService{client: c}
c.ProjectMirrors = &ProjectMirrorService{client: c}
c.ProjectSnippets = &ProjectSnippetsService{client: c}
c.ProjectTemplates = &ProjectTemplatesService{client: c}
c.ProjectVariables = &ProjectVariablesService{client: c}
c.ProjectVulnerabilities = &ProjectVulnerabilitiesService{client: c}
c.Projects = &ProjectsService{client: c}
c.ProtectedBranches = &ProtectedBranchesService{client: c}
c.ProtectedEnvironments = &ProtectedEnvironmentsService{client: c}
c.ProtectedTags = &ProtectedTagsService{client: c}
c.ReleaseLinks = &ReleaseLinksService{client: c}
c.Releases = &ReleasesService{client: c}
c.Repositories = &RepositoriesService{client: c}
c.RepositoryFiles = &RepositoryFilesService{client: c}
c.RepositorySubmodules = &RepositorySubmodulesService{client: c}
c.ResourceLabelEvents = &ResourceLabelEventsService{client: c}
c.ResourceMilestoneEvents = &ResourceMilestoneEventsService{client: c}
c.ResourceStateEvents = &ResourceStateEventsService{client: c}
c.ResourceWeightEvents = &ResourceWeightEventsService{client: c}
c.Runners = &RunnersService{client: c}
c.Search = &SearchService{client: c}
c.Services = &ServicesService{client: c}
c.Settings = &SettingsService{client: c}
c.Sidekiq = &SidekiqService{client: c}
c.Snippets = &SnippetsService{client: c}
c.SystemHooks = &SystemHooksService{client: c}
c.Tags = &TagsService{client: c}
c.Todos = &TodosService{client: c}
c.Topics = &TopicsService{client: c}
c.Users = &UsersService{client: c}
c.Validate = &ValidateService{client: c}
c.Version = &VersionService{client: c}
c.Wikis = &WikisService{client: c}
return c, nil
}
// retryHTTPCheck provides a callback for Client.CheckRetry which
// will retry both rate limit (429) and server (>= 500) errors.
func (c *Client) retryHTTPCheck(ctx context.Context, resp *http.Response, err error) (bool, error) {
if ctx.Err() != nil {
return false, ctx.Err()
}
if err != nil {
return false, err
}
if !c.disableRetries && (resp.StatusCode == 429 || resp.StatusCode >= 500) {
return true, nil
}
return false, nil
}
// retryHTTPBackoff provides a generic callback for Client.Backoff which
// will pass through all calls based on the status code of the response.
func (c *Client) retryHTTPBackoff(min, max time.Duration, attemptNum int, resp *http.Response) time.Duration {
// Use the rate limit backoff function when we are rate limited.
if resp != nil && resp.StatusCode == 429 {
return rateLimitBackoff(min, max, attemptNum, resp)
}
// Set custom duration's when we experience a service interruption.
min = 700 * time.Millisecond
max = 900 * time.Millisecond
return retryablehttp.LinearJitterBackoff(min, max, attemptNum, resp)
}
// rateLimitBackoff provides a callback for Client.Backoff which will use the
// RateLimit-Reset header to determine the time to wait. We add some jitter
// to prevent a thundering herd.
//
// min and max are mainly used for bounding the jitter that will be added to
// the reset time retrieved from the headers. But if the final wait time is
// less then min, min will be used instead.
func rateLimitBackoff(min, max time.Duration, attemptNum int, resp *http.Response) time.Duration {
// rnd is used to generate pseudo-random numbers.
rnd := rand.New(rand.NewSource(time.Now().UnixNano()))
// First create some jitter bounded by the min and max durations.
jitter := time.Duration(rnd.Float64() * float64(max-min))
if resp != nil {
if v := resp.Header.Get(headerRateReset); v != "" {
if reset, _ := strconv.ParseInt(v, 10, 64); reset > 0 {
// Only update min if the given time to wait is longer.
if wait := time.Until(time.Unix(reset, 0)); wait > min {
min = wait
}
}
}
}
return min + jitter
}
// configureLimiter configures the rate limiter.
func (c *Client) configureLimiter(ctx context.Context, headers http.Header) {
if v := headers.Get(headerRateLimit); v != "" {
if rateLimit, _ := strconv.ParseFloat(v, 64); rateLimit > 0 {
// The rate limit is based on requests per minute, so for our limiter to
// work correctly we divide the limit by 60 to get the limit per second.
rateLimit /= 60
// Configure the limit and burst using a split of 2/3 for the limit and
// 1/3 for the burst. This enables clients to burst 1/3 of the allowed
// calls before the limiter kicks in. The remaining calls will then be
// spread out evenly using intervals of time.Second / limit which should
// prevent hitting the rate limit.
limit := rate.Limit(rateLimit * 0.66)
burst := int(rateLimit * 0.33)
// Create a new limiter using the calculated values.
c.limiter = rate.NewLimiter(limit, burst)
// Call the limiter once as we have already made a request
// to get the headers and the limiter is not aware of this.
c.limiter.Wait(ctx)
}
}
}
// BaseURL return a copy of the baseURL.
func (c *Client) BaseURL() *url.URL {
u := *c.baseURL
return &u
}
// setBaseURL sets the base URL for API requests to a custom endpoint.
func (c *Client) setBaseURL(urlStr string) error {
// Make sure the given URL end with a slash
if !strings.HasSuffix(urlStr, "/") {
urlStr += "/"
}
baseURL, err := url.Parse(urlStr)
if err != nil {
return err
}
if !strings.HasSuffix(baseURL.Path, apiVersionPath) {
baseURL.Path += apiVersionPath
}
// Update the base URL of the client.
c.baseURL = baseURL
return nil
}
// NewRequest creates a new API request. The method expects a relative URL
// path that will be resolved relative to the base URL of the Client.
// Relative URL paths should always be specified without a preceding slash.
// If specified, the value pointed to by body is JSON encoded and included
// as the request body.
func (c *Client) NewRequest(method, path string, opt interface{}, options []RequestOptionFunc) (*retryablehttp.Request, error) {
u := *c.baseURL
unescaped, err := url.PathUnescape(path)
if err != nil {
return nil, err
}
// Set the encoded path data
u.RawPath = c.baseURL.Path + path
u.Path = c.baseURL.Path + unescaped
// Create a request specific headers map.
reqHeaders := make(http.Header)
reqHeaders.Set("Accept", "application/json")
if c.UserAgent != "" {
reqHeaders.Set("User-Agent", c.UserAgent)
}
var body interface{}
switch {
case method == http.MethodPatch || method == http.MethodPost || method == http.MethodPut:
reqHeaders.Set("Content-Type", "application/json")
if opt != nil {
body, err = json.Marshal(opt)
if err != nil {
return nil, err
}
}
case opt != nil:
q, err := query.Values(opt)
if err != nil {
return nil, err
}
u.RawQuery = q.Encode()
}
req, err := retryablehttp.NewRequest(method, u.String(), body)
if err != nil {
return nil, err
}
for _, fn := range append(c.defaultRequestOptions, options...) {
if fn == nil {
continue
}
if err := fn(req); err != nil {
return nil, err
}
}
// Set the request specific headers.
for k, v := range reqHeaders {
req.Header[k] = v
}
return req, nil
}
// UploadRequest creates an API request for uploading a file. The method
// expects a relative URL path that will be resolved relative to the base
// URL of the Client. Relative URL paths should always be specified without
// a preceding slash. If specified, the value pointed to by body is JSON
// encoded and included as the request body.
func (c *Client) UploadRequest(method, path string, content io.Reader, filename string, uploadType UploadType, opt interface{}, options []RequestOptionFunc) (*retryablehttp.Request, error) {
u := *c.baseURL
unescaped, err := url.PathUnescape(path)
if err != nil {
return nil, err
}
// Set the encoded path data
u.RawPath = c.baseURL.Path + path
u.Path = c.baseURL.Path + unescaped
// Create a request specific headers map.
reqHeaders := make(http.Header)
reqHeaders.Set("Accept", "application/json")
if c.UserAgent != "" {
reqHeaders.Set("User-Agent", c.UserAgent)
}
b := new(bytes.Buffer)
w := multipart.NewWriter(b)
fw, err := w.CreateFormFile(string(uploadType), filename)
if err != nil {
return nil, err
}
if _, err := io.Copy(fw, content); err != nil {
return nil, err
}
if opt != nil {
fields, err := query.Values(opt)
if err != nil {
return nil, err
}
for name := range fields {
if err = w.WriteField(name, fmt.Sprintf("%v", fields.Get(name))); err != nil {
return nil, err
}
}
}
if err = w.Close(); err != nil {
return nil, err
}
reqHeaders.Set("Content-Type", w.FormDataContentType())
req, err := retryablehttp.NewRequest(method, u.String(), b)
if err != nil {
return nil, err
}
for _, fn := range append(c.defaultRequestOptions, options...) {
if fn == nil {
continue
}
if err := fn(req); err != nil {
return nil, err
}
}
// Set the request specific headers.
for k, v := range reqHeaders {
req.Header[k] = v
}
return req, nil
}
// Response is a GitLab API response. This wraps the standard http.Response
// returned from GitLab and provides convenient access to things like
// pagination links.
type Response struct {
*http.Response
// These fields provide the page values for paginating through a set of
// results. Any or all of these may be set to the zero value for
// responses that are not part of a paginated set, or for which there
// are no additional pages.
TotalItems int
TotalPages int
ItemsPerPage int
CurrentPage int
NextPage int
PreviousPage int
}
// newResponse creates a new Response for the provided http.Response.
func newResponse(r *http.Response) *Response {
response := &Response{Response: r}
response.populatePageValues()
return response
}
const (
xTotal = "X-Total"
xTotalPages = "X-Total-Pages"
xPerPage = "X-Per-Page"
xPage = "X-Page"
xNextPage = "X-Next-Page"
xPrevPage = "X-Prev-Page"
)
// populatePageValues parses the HTTP Link response headers and populates the
// various pagination link values in the Response.
func (r *Response) populatePageValues() {
if totalItems := r.Header.Get(xTotal); totalItems != "" {
r.TotalItems, _ = strconv.Atoi(totalItems)
}
if totalPages := r.Header.Get(xTotalPages); totalPages != "" {
r.TotalPages, _ = strconv.Atoi(totalPages)
}
if itemsPerPage := r.Header.Get(xPerPage); itemsPerPage != "" {
r.ItemsPerPage, _ = strconv.Atoi(itemsPerPage)
}
if currentPage := r.Header.Get(xPage); currentPage != "" {
r.CurrentPage, _ = strconv.Atoi(currentPage)
}
if nextPage := r.Header.Get(xNextPage); nextPage != "" {
r.NextPage, _ = strconv.Atoi(nextPage)
}
if previousPage := r.Header.Get(xPrevPage); previousPage != "" {
r.PreviousPage, _ = strconv.Atoi(previousPage)
}
}
// Do sends an API request and returns the API response. The API response is
// JSON decoded and stored in the value pointed to by v, or returned as an
// error if an API error has occurred. If v implements the io.Writer
// interface, the raw response body will be written to v, without attempting to
// first decode it.
func (c *Client) Do(req *retryablehttp.Request, v interface{}) (*Response, error) {
// Wait will block until the limiter can obtain a new token.
err := c.limiter.Wait(req.Context())
if err != nil {
return nil, err
}
// Set the correct authentication header. If using basic auth, then check
// if we already have a token and if not first authenticate and get one.
var basicAuthToken string
switch c.authType {
case BasicAuth:
c.tokenLock.RLock()
basicAuthToken = c.token
c.tokenLock.RUnlock()
if basicAuthToken == "" {
// If we don't have a token yet, we first need to request one.
basicAuthToken, err = c.requestOAuthToken(req.Context(), basicAuthToken)
if err != nil {
return nil, err
}
}
req.Header.Set("Authorization", "Bearer "+basicAuthToken)
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)
if err != nil {
return nil, err
}
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 {
return nil, err
}
return c.Do(req, v)
}
defer resp.Body.Close()
// If not yet configured, try to configure the rate limiter
// using the response headers we just received. Fail silently
// so the limiter will remain disabled in case of an error.
c.configureLimiterOnce.Do(func() { c.configureLimiter(req.Context(), resp.Header) })
response := newResponse(resp)
err = CheckResponse(resp)
if err != nil {
// Even though there was an error, we still return the response
// in case the caller wants to inspect it further.
return response, err
}
if v != nil {
if w, ok := v.(io.Writer); ok {
_, err = io.Copy(w, resp.Body)
} else {
err = json.NewDecoder(resp.Body).Decode(v)
}
}
return response, err
}
func (c *Client) requestOAuthToken(ctx context.Context, token string) (string, error) {
c.tokenLock.Lock()
defer c.tokenLock.Unlock()
// Return early if the token was updated while waiting for the lock.
if c.token != token {
return c.token, nil
}
config := &oauth2.Config{
Endpoint: oauth2.Endpoint{
AuthURL: strings.TrimSuffix(c.baseURL.String(), apiVersionPath) + "oauth/authorize",
TokenURL: strings.TrimSuffix(c.baseURL.String(), apiVersionPath) + "oauth/token",
},
}
ctx = context.WithValue(ctx, oauth2.HTTPClient, c.client.HTTPClient)
t, err := config.PasswordCredentialsToken(ctx, c.username, c.password)
if err != nil {
return "", err
}
c.token = t.AccessToken
return c.token, nil
}
// Helper function to accept and format both the project ID or name as project
// identifier for all API calls.
func parseID(id interface{}) (string, error) {
switch v := id.(type) {
case int:
return strconv.Itoa(v), nil
case string:
return v, nil
default:
return "", fmt.Errorf("invalid ID type %#v, the ID must be an int or a string", id)
}
}
// Helper function to escape a project identifier.
func PathEscape(s string) string {
return strings.ReplaceAll(url.PathEscape(s), ".", "%2E")
}
// An ErrorResponse reports one or more errors caused by an API request.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/index.html#data-validation-and-error-reporting
type ErrorResponse struct {
Body []byte
Response *http.Response
Message string
}
func (e *ErrorResponse) Error() string {
path, _ := url.QueryUnescape(e.Response.Request.URL.Path)
u := fmt.Sprintf("%s://%s%s", e.Response.Request.URL.Scheme, e.Response.Request.URL.Host, path)
return fmt.Sprintf("%s %s: %d %s", e.Response.Request.Method, u, e.Response.StatusCode, e.Message)
}
// CheckResponse checks the API response for errors, and returns them if present.
func CheckResponse(r *http.Response) error {
switch r.StatusCode {
case 200, 201, 202, 204, 304:
return nil
}
errorResponse := &ErrorResponse{Response: r}
data, err := io.ReadAll(r.Body)
if err == nil && data != nil {
errorResponse.Body = data
var raw interface{}
if err := json.Unmarshal(data, &raw); err != nil {
errorResponse.Message = fmt.Sprintf("failed to parse unknown error format: %s", data)
} else {
errorResponse.Message = parseError(raw)
}
}
return errorResponse
}
// Format:
//
// {
// "message": {
// "<property-name>": [
// "<error-message>",
// "<error-message>",
// ...
// ],
// "<embed-entity>": {
// "<property-name>": [
// "<error-message>",
// "<error-message>",
// ...
// ],
// }
// },
// "error": "<error-message>"
// }
func parseError(raw interface{}) string {
switch raw := raw.(type) {
case string:
return raw
case []interface{}:
var errs []string
for _, v := range raw {
errs = append(errs, parseError(v))
}
return fmt.Sprintf("[%s]", strings.Join(errs, ", "))
case map[string]interface{}:
var errs []string
for k, v := range raw {
errs = append(errs, fmt.Sprintf("{%s: %s}", k, parseError(v)))
}
sort.Strings(errs)
return strings.Join(errs, ", ")
default:
return fmt.Sprintf("failed to parse unexpected error type: %T", raw)
}
}

View File

@ -0,0 +1,165 @@
//
// Copyright 2022, Masahiro Yoshida
//
// 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"
"time"
)
// GroupAccessTokensService handles communication with the
// groups access tokens related methods of the GitLab API.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/group_access_tokens.html
type GroupAccessTokensService struct {
client *Client
}
// GroupAccessToken represents a GitLab group access token.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/group_access_tokens.html
type GroupAccessToken struct {
ID int `json:"id"`
UserID int `json:"user_id"`
Name string `json:"name"`
Scopes []string `json:"scopes"`
CreatedAt *time.Time `json:"created_at"`
ExpiresAt *ISOTime `json:"expires_at"`
LastUsedAt *time.Time `json:"last_used_at"`
Active bool `json:"active"`
Revoked bool `json:"revoked"`
Token string `json:"token"`
AccessLevel AccessLevelValue `json:"access_level"`
}
func (v GroupAccessToken) String() string {
return Stringify(v)
}
// ListGroupAccessTokensOptions represents the available options for
// listing variables in a group.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_access_tokens.html#list-group-access-tokens
type ListGroupAccessTokensOptions ListOptions
// ListGroupAccessTokens gets a list of all group access tokens in a group.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_access_tokens.html#list-group-access-tokens
func (s *GroupAccessTokensService) ListGroupAccessTokens(gid interface{}, opt *ListGroupAccessTokensOptions, options ...RequestOptionFunc) ([]*GroupAccessToken, *Response, error) {
groups, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/access_tokens", PathEscape(groups))
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
var gats []*GroupAccessToken
resp, err := s.client.Do(req, &gats)
if err != nil {
return nil, resp, err
}
return gats, resp, err
}
// GetGroupAccessToken gets a single group access tokens in a group.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_access_tokens.html#get-a-group-access-token
func (s *GroupAccessTokensService) GetGroupAccessToken(gid interface{}, id int, options ...RequestOptionFunc) (*GroupAccessToken, *Response, error) {
groups, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/access_tokens/%d", PathEscape(groups), id)
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}
gat := new(GroupAccessToken)
resp, err := s.client.Do(req, &gat)
if err != nil {
return nil, resp, err
}
return gat, resp, err
}
// CreateGroupAccessTokenOptions represents the available CreateVariable()
// options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_access_tokens.html#create-a-group-access-token
type CreateGroupAccessTokenOptions struct {
Name *string `url:"name,omitempty" json:"name,omitempty"`
Scopes *[]string `url:"scopes,omitempty" json:"scopes,omitempty"`
AccessLevel *AccessLevelValue `url:"access_level,omitempty" json:"access_level,omitempty"`
ExpiresAt *ISOTime `url:"expires_at,omitempty" json:"expires_at,omitempty"`
}
// CreateGroupAccessToken creates a new group access token.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_access_tokens.html#create-a-group-access-token
func (s *GroupAccessTokensService) CreateGroupAccessToken(gid interface{}, opt *CreateGroupAccessTokenOptions, options ...RequestOptionFunc) (*GroupAccessToken, *Response, error) {
groups, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/access_tokens", PathEscape(groups))
req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
if err != nil {
return nil, nil, err
}
pat := new(GroupAccessToken)
resp, err := s.client.Do(req, pat)
if err != nil {
return nil, resp, err
}
return pat, resp, err
}
// RevokeGroupAccessToken revokes a group access token.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_access_tokens.html#revoke-a-group-access-token
func (s *GroupAccessTokensService) RevokeGroupAccessToken(gid interface{}, id int, options ...RequestOptionFunc) (*Response, error) {
groups, err := parseID(gid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("groups/%s/access_tokens/%d", PathEscape(groups), id)
req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}

230
vendor/github.com/xanzy/go-gitlab/group_badges.go generated vendored Normal file
View File

@ -0,0 +1,230 @@
//
// 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"
)
// GroupBadgesService handles communication with the group badges
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_badges.html
type GroupBadgesService struct {
client *Client
}
// BadgeKind represents a GitLab Badge Kind
type BadgeKind string
// all possible values Badge Kind
const (
ProjectBadgeKind BadgeKind = "project"
GroupBadgeKind BadgeKind = "group"
)
// GroupBadge represents a group badge.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_badges.html
type GroupBadge struct {
ID int `json:"id"`
LinkURL string `json:"link_url"`
ImageURL string `json:"image_url"`
RenderedLinkURL string `json:"rendered_link_url"`
RenderedImageURL string `json:"rendered_image_url"`
Kind BadgeKind `json:"kind"`
}
// ListGroupBadgesOptions represents the available ListGroupBadges() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_badges.html#list-all-badges-of-a-group
type ListGroupBadgesOptions ListOptions
// ListGroupBadges gets a list of a group badges.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_badges.html#list-all-badges-of-a-group
func (s *GroupBadgesService) ListGroupBadges(gid interface{}, opt *ListGroupBadgesOptions, options ...RequestOptionFunc) ([]*GroupBadge, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/badges", PathEscape(group))
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
var gb []*GroupBadge
resp, err := s.client.Do(req, &gb)
if err != nil {
return nil, resp, err
}
return gb, resp, err
}
// GetGroupBadge gets a group badge.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_badges.html#get-a-badge-of-a-group
func (s *GroupBadgesService) GetGroupBadge(gid interface{}, badge int, options ...RequestOptionFunc) (*GroupBadge, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/badges/%d", PathEscape(group), badge)
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}
gb := new(GroupBadge)
resp, err := s.client.Do(req, gb)
if err != nil {
return nil, resp, err
}
return gb, resp, err
}
// AddGroupBadgeOptions represents the available AddGroupBadge() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_badges.html#add-a-badge-to-a-group
type AddGroupBadgeOptions struct {
LinkURL *string `url:"link_url,omitempty" json:"link_url,omitempty"`
ImageURL *string `url:"image_url,omitempty" json:"image_url,omitempty"`
}
// AddGroupBadge adds a badge to a group.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_badges.html#add-a-badge-to-a-group
func (s *GroupBadgesService) AddGroupBadge(gid interface{}, opt *AddGroupBadgeOptions, options ...RequestOptionFunc) (*GroupBadge, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/badges", PathEscape(group))
req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
if err != nil {
return nil, nil, err
}
gb := new(GroupBadge)
resp, err := s.client.Do(req, gb)
if err != nil {
return nil, resp, err
}
return gb, resp, err
}
// EditGroupBadgeOptions represents the available EditGroupBadge() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_badges.html#edit-a-badge-of-a-group
type EditGroupBadgeOptions struct {
LinkURL *string `url:"link_url,omitempty" json:"link_url,omitempty"`
ImageURL *string `url:"image_url,omitempty" json:"image_url,omitempty"`
}
// EditGroupBadge updates a badge of a group.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_badges.html#edit-a-badge-of-a-group
func (s *GroupBadgesService) EditGroupBadge(gid interface{}, badge int, opt *EditGroupBadgeOptions, options ...RequestOptionFunc) (*GroupBadge, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/badges/%d", PathEscape(group), badge)
req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
if err != nil {
return nil, nil, err
}
gb := new(GroupBadge)
resp, err := s.client.Do(req, gb)
if err != nil {
return nil, resp, err
}
return gb, resp, err
}
// DeleteGroupBadge removes a badge from a group.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_badges.html#remove-a-badge-from-a-group
func (s *GroupBadgesService) DeleteGroupBadge(gid interface{}, badge int, options ...RequestOptionFunc) (*Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("groups/%s/badges/%d", PathEscape(group), badge)
req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}
// GroupBadgePreviewOptions represents the available PreviewGroupBadge() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_badges.html#preview-a-badge-from-a-group
type GroupBadgePreviewOptions struct {
LinkURL *string `url:"link_url,omitempty" json:"link_url,omitempty"`
ImageURL *string `url:"image_url,omitempty" json:"image_url,omitempty"`
}
// PreviewGroupBadge returns how the link_url and image_url final URLs would be after
// resolving the placeholder interpolation.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_badges.html#preview-a-badge-from-a-group
func (s *GroupBadgesService) PreviewGroupBadge(gid interface{}, opt *GroupBadgePreviewOptions, options ...RequestOptionFunc) (*GroupBadge, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/badges/render", PathEscape(group))
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
gb := new(GroupBadge)
resp, err := s.client.Do(req, &gb)
if err != nil {
return nil, resp, err
}
return gb, resp, err
}

352
vendor/github.com/xanzy/go-gitlab/group_boards.go generated vendored Normal file
View File

@ -0,0 +1,352 @@
//
// Copyright 2021, Patrick Webster
//
// 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"
)
// GroupIssueBoardsService handles communication with the group issue board
// related methods of the GitLab API.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_boards.html
type GroupIssueBoardsService struct {
client *Client
}
// GroupIssueBoard represents a GitLab group issue board.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_boards.html
type GroupIssueBoard struct {
ID int `json:"id"`
Name string `json:"name"`
Group *Group `json:"group"`
Milestone *Milestone `json:"milestone"`
Lists []*BoardList `json:"lists"`
}
func (b GroupIssueBoard) String() string {
return Stringify(b)
}
// ListGroupIssueBoardsOptions represents the available
// ListGroupIssueBoards() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_boards.html#list-all-group-issue-boards-in-a-group
type ListGroupIssueBoardsOptions ListOptions
// ListGroupIssueBoards gets a list of all issue boards in a group.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_boards.html#list-all-group-issue-boards-in-a-group
func (s *GroupIssueBoardsService) ListGroupIssueBoards(gid interface{}, opt *ListGroupIssueBoardsOptions, options ...RequestOptionFunc) ([]*GroupIssueBoard, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/boards", PathEscape(group))
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
var gs []*GroupIssueBoard
resp, err := s.client.Do(req, &gs)
if err != nil {
return nil, resp, err
}
return gs, resp, err
}
// CreateGroupIssueBoardOptions represents the available
// CreateGroupIssueBoard() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_boards.html#create-a-group-issue-board
type CreateGroupIssueBoardOptions struct {
Name *string `url:"name" json:"name"`
}
// CreateGroupIssueBoard creates a new issue board.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_boards.html#create-a-group-issue-board
func (s *GroupIssueBoardsService) CreateGroupIssueBoard(gid interface{}, opt *CreateGroupIssueBoardOptions, options ...RequestOptionFunc) (*GroupIssueBoard, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/boards", PathEscape(group))
req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
if err != nil {
return nil, nil, err
}
gib := new(GroupIssueBoard)
resp, err := s.client.Do(req, gib)
if err != nil {
return nil, resp, err
}
return gib, resp, err
}
// GetGroupIssueBoard gets a single issue board of a group.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_boards.html#single-group-issue-board
func (s *GroupIssueBoardsService) GetGroupIssueBoard(gid interface{}, board int, options ...RequestOptionFunc) (*GroupIssueBoard, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/boards/%d", PathEscape(group), board)
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}
gib := new(GroupIssueBoard)
resp, err := s.client.Do(req, gib)
if err != nil {
return nil, resp, err
}
return gib, resp, err
}
// UpdateGroupIssueBoardOptions represents a group issue board.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_boards.html#update-a-group-issue-board
type UpdateGroupIssueBoardOptions struct {
Name *string `url:"name,omitempty" json:"name,omitempty"`
AssigneeID *int `url:"assignee_id,omitempty" json:"assignee_id,omitempty"`
MilestoneID *int `url:"milestone_id,omitempty" json:"milestone_id,omitempty"`
Labels *Labels `url:"labels,omitempty" json:"labels,omitempty"`
Weight *int `url:"weight,omitempty" json:"weight,omitempty"`
}
// UpdateIssueBoard updates a single issue board of a group.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_boards.html#update-a-group-issue-board
func (s *GroupIssueBoardsService) UpdateIssueBoard(gid interface{}, board int, opt *UpdateGroupIssueBoardOptions, options ...RequestOptionFunc) (*GroupIssueBoard, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/boards/%d", PathEscape(group), board)
req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
if err != nil {
return nil, nil, err
}
gib := new(GroupIssueBoard)
resp, err := s.client.Do(req, gib)
if err != nil {
return nil, resp, err
}
return gib, resp, err
}
// DeleteIssueBoard delete a single issue board of a group.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_boards.html#delete-a-group-issue-board
func (s *GroupIssueBoardsService) DeleteIssueBoard(gid interface{}, board int, options ...RequestOptionFunc) (*Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("groups/%s/boards/%d", PathEscape(group), board)
req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}
// ListGroupIssueBoardListsOptions represents the available
// ListGroupIssueBoardLists() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_boards.html#list-group-issue-board-lists
type ListGroupIssueBoardListsOptions ListOptions
// ListGroupIssueBoardLists gets a list of the issue board's lists. Does not include
// backlog and closed lists.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/group_boards.html#list-group-issue-board-lists
func (s *GroupIssueBoardsService) ListGroupIssueBoardLists(gid interface{}, board int, opt *ListGroupIssueBoardListsOptions, options ...RequestOptionFunc) ([]*BoardList, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/boards/%d/lists", PathEscape(group), board)
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
var gbl []*BoardList
resp, err := s.client.Do(req, &gbl)
if err != nil {
return nil, resp, err
}
return gbl, resp, err
}
// GetGroupIssueBoardList gets a single issue board list.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_boards.html#single-group-issue-board-list
func (s *GroupIssueBoardsService) GetGroupIssueBoardList(gid interface{}, board, list int, options ...RequestOptionFunc) (*BoardList, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/boards/%d/lists/%d",
PathEscape(group),
board,
list,
)
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}
gbl := new(BoardList)
resp, err := s.client.Do(req, gbl)
if err != nil {
return nil, resp, err
}
return gbl, resp, err
}
// CreateGroupIssueBoardListOptions represents the available
// CreateGroupIssueBoardList() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_boards.html#new-group-issue-board-list
type CreateGroupIssueBoardListOptions struct {
LabelID *int `url:"label_id" json:"label_id"`
}
// CreateGroupIssueBoardList creates a new issue board list.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_boards.html#new-group-issue-board-list
func (s *GroupIssueBoardsService) CreateGroupIssueBoardList(gid interface{}, board int, opt *CreateGroupIssueBoardListOptions, options ...RequestOptionFunc) (*BoardList, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/boards/%d/lists", PathEscape(group), board)
req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
if err != nil {
return nil, nil, err
}
gbl := new(BoardList)
resp, err := s.client.Do(req, gbl)
if err != nil {
return nil, resp, err
}
return gbl, resp, err
}
// UpdateGroupIssueBoardListOptions represents the available
// UpdateGroupIssueBoardList() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_boards.html#edit-group-issue-board-list
type UpdateGroupIssueBoardListOptions struct {
Position *int `url:"position" json:"position"`
}
// UpdateIssueBoardList updates the position of an existing
// group issue board list.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_boards.html#edit-group-issue-board-list
func (s *GroupIssueBoardsService) UpdateIssueBoardList(gid interface{}, board, list int, opt *UpdateGroupIssueBoardListOptions, options ...RequestOptionFunc) ([]*BoardList, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/boards/%d/lists/%d",
PathEscape(group),
board,
list,
)
req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
if err != nil {
return nil, nil, err
}
var gbl []*BoardList
resp, err := s.client.Do(req, &gbl)
if err != nil {
return nil, resp, err
}
return gbl, resp, err
}
// DeleteGroupIssueBoardList soft deletes a group issue board list.
// Only for admins and group owners.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_boards.html#delete-a-group-issue-board-list
func (s *GroupIssueBoardsService) DeleteGroupIssueBoardList(gid interface{}, board, list int, options ...RequestOptionFunc) (*Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("groups/%s/boards/%d/lists/%d",
PathEscape(group),
board,
list,
)
req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}

217
vendor/github.com/xanzy/go-gitlab/group_clusters.go generated vendored Normal file
View File

@ -0,0 +1,217 @@
//
// Copyright 2021, Paul Shoemaker
//
// 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"
"time"
)
// GroupClustersService handles communication with the
// group clusters related methods of the GitLab API.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_clusters.html
type GroupClustersService struct {
client *Client
}
// GroupCluster represents a GitLab Group Cluster.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/group_clusters.html
type GroupCluster struct {
ID int `json:"id"`
Name string `json:"name"`
Domain string `json:"domain"`
CreatedAt *time.Time `json:"created_at"`
Managed bool `json:"managed"`
Enabled bool `json:"enabled"`
ProviderType string `json:"provider_type"`
PlatformType string `json:"platform_type"`
EnvironmentScope string `json:"environment_scope"`
ClusterType string `json:"cluster_type"`
User *User `json:"user"`
PlatformKubernetes *PlatformKubernetes `json:"platform_kubernetes"`
ManagementProject *ManagementProject `json:"management_project"`
Group *Group `json:"group"`
}
func (v GroupCluster) String() string {
return Stringify(v)
}
// ListClusters gets a list of all clusters in a group.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_clusters.html#list-group-clusters
func (s *GroupClustersService) ListClusters(pid interface{}, options ...RequestOptionFunc) ([]*GroupCluster, *Response, error) {
group, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/clusters", PathEscape(group))
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}
var pcs []*GroupCluster
resp, err := s.client.Do(req, &pcs)
if err != nil {
return nil, resp, err
}
return pcs, resp, err
}
// GetCluster gets a cluster.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_clusters.html#get-a-single-group-cluster
func (s *GroupClustersService) GetCluster(pid interface{}, cluster int, options ...RequestOptionFunc) (*GroupCluster, *Response, error) {
group, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/clusters/%d", PathEscape(group), cluster)
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}
gc := new(GroupCluster)
resp, err := s.client.Do(req, &gc)
if err != nil {
return nil, resp, err
}
return gc, resp, err
}
// AddGroupClusterOptions represents the available AddCluster() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_clusters.html#add-existing-cluster-to-group
type AddGroupClusterOptions struct {
Name *string `url:"name,omitempty" json:"name,omitempty"`
Domain *string `url:"domain,omitempty" json:"domain,omitempty"`
ManagementProjectID *string `url:"management_project_id,omitempty" json:"management_project_id,omitempty"`
Enabled *bool `url:"enabled,omitempty" json:"enabled,omitempty"`
Managed *bool `url:"managed,omitempty" json:"managed,omitempty"`
EnvironmentScope *string `url:"environment_scope,omitempty" json:"environment_scope,omitempty"`
PlatformKubernetes *AddGroupPlatformKubernetesOptions `url:"platform_kubernetes_attributes,omitempty" json:"platform_kubernetes_attributes,omitempty"`
}
// AddGroupPlatformKubernetesOptions represents the available PlatformKubernetes options for adding.
type AddGroupPlatformKubernetesOptions struct {
APIURL *string `url:"api_url,omitempty" json:"api_url,omitempty"`
Token *string `url:"token,omitempty" json:"token,omitempty"`
CaCert *string `url:"ca_cert,omitempty" json:"ca_cert,omitempty"`
Namespace *string `url:"namespace,omitempty" json:"namespace,omitempty"`
AuthorizationType *string `url:"authorization_type,omitempty" json:"authorization_type,omitempty"`
}
// AddCluster adds an existing cluster to the group.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_clusters.html#add-existing-cluster-to-group
func (s *GroupClustersService) AddCluster(pid interface{}, opt *AddGroupClusterOptions, options ...RequestOptionFunc) (*GroupCluster, *Response, error) {
group, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/clusters/user", PathEscape(group))
req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
if err != nil {
return nil, nil, err
}
gc := new(GroupCluster)
resp, err := s.client.Do(req, gc)
if err != nil {
return nil, resp, err
}
return gc, resp, err
}
// EditGroupClusterOptions represents the available EditCluster() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_clusters.html#edit-group-cluster
type EditGroupClusterOptions struct {
Name *string `url:"name,omitempty" json:"name,omitempty"`
Domain *string `url:"domain,omitempty" json:"domain,omitempty"`
EnvironmentScope *string `url:"environment_scope,omitempty" json:"environment_scope,omitempty"`
PlatformKubernetes *EditGroupPlatformKubernetesOptions `url:"platform_kubernetes_attributes,omitempty" json:"platform_kubernetes_attributes,omitempty"`
ManagementProjectID *string `url:"management_project_id,omitempty" json:"management_project_id,omitempty"`
}
// EditGroupPlatformKubernetesOptions represents the available PlatformKubernetes options for editing.
type EditGroupPlatformKubernetesOptions struct {
APIURL *string `url:"api_url,omitempty" json:"api_url,omitempty"`
Token *string `url:"token,omitempty" json:"token,omitempty"`
CaCert *string `url:"ca_cert,omitempty" json:"ca_cert,omitempty"`
}
// EditCluster updates an existing group cluster.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_clusters.html#edit-group-cluster
func (s *GroupClustersService) EditCluster(pid interface{}, cluster int, opt *EditGroupClusterOptions, options ...RequestOptionFunc) (*GroupCluster, *Response, error) {
group, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/clusters/%d", PathEscape(group), cluster)
req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
if err != nil {
return nil, nil, err
}
gc := new(GroupCluster)
resp, err := s.client.Do(req, gc)
if err != nil {
return nil, resp, err
}
return gc, resp, err
}
// DeleteCluster deletes an existing group cluster.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_clusters.html#delete-group-cluster
func (s *GroupClustersService) DeleteCluster(pid interface{}, cluster int, options ...RequestOptionFunc) (*Response, error) {
group, err := parseID(pid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("groups/%s/clusters/%d", PathEscape(group), cluster)
req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}

218
vendor/github.com/xanzy/go-gitlab/group_hooks.go generated vendored Normal file
View File

@ -0,0 +1,218 @@
//
// Copyright 2021, Eric Stevens
//
// 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"
"time"
)
// GroupHook represents a GitLab group hook.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/groups.html#list-group-hooks
type GroupHook struct {
ID int `json:"id"`
URL string `json:"url"`
GroupID int `json:"group_id"`
PushEvents bool `json:"push_events"`
PushEventsBranchFilter string `json:"push_events_branch_filter"`
IssuesEvents bool `json:"issues_events"`
ConfidentialIssuesEvents bool `json:"confidential_issues_events"`
ConfidentialNoteEvents bool `json:"confidential_note_events"`
MergeRequestsEvents bool `json:"merge_requests_events"`
TagPushEvents bool `json:"tag_push_events"`
NoteEvents bool `json:"note_events"`
JobEvents bool `json:"job_events"`
PipelineEvents bool `json:"pipeline_events"`
WikiPageEvents bool `json:"wiki_page_events"`
DeploymentEvents bool `json:"deployment_events"`
ReleasesEvents bool `json:"releases_events"`
SubGroupEvents bool `json:"subgroup_events"`
EnableSSLVerification bool `json:"enable_ssl_verification"`
AlertStatus string `json:"alert_status"`
CreatedAt *time.Time `json:"created_at"`
}
// ListGroupHooksOptions represents the available ListGroupHooks() options.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/groups.html#list-group-hooks
type ListGroupHooksOptions ListOptions
// ListGroupHooks gets a list of group hooks.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/groups.html#list-group-hooks
func (s *GroupsService) ListGroupHooks(gid interface{}, opt *ListGroupHooksOptions, options ...RequestOptionFunc) ([]*GroupHook, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/hooks", PathEscape(group))
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
var gh []*GroupHook
resp, err := s.client.Do(req, &gh)
if err != nil {
return nil, resp, err
}
return gh, resp, err
}
// GetGroupHook gets a specific hook for a group.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/groups.html#get-group-hook
func (s *GroupsService) GetGroupHook(pid interface{}, hook int, options ...RequestOptionFunc) (*GroupHook, *Response, error) {
group, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/hooks/%d", PathEscape(group), hook)
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}
gh := new(GroupHook)
resp, err := s.client.Do(req, gh)
if err != nil {
return nil, resp, err
}
return gh, resp, err
}
// AddGroupHookOptions represents the available AddGroupHook() options.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/groups.html#add-group-hook
type AddGroupHookOptions struct {
URL *string `url:"url,omitempty" json:"url,omitempty"`
PushEvents *bool `url:"push_events,omitempty" json:"push_events,omitempty"`
PushEventsBranchFilter *string `url:"push_events_branch_filter,omitempty" json:"push_events_branch_filter,omitempty"`
IssuesEvents *bool `url:"issues_events,omitempty" json:"issues_events,omitempty"`
ConfidentialIssuesEvents *bool `url:"confidential_issues_events,omitempty" json:"confidential_issues_events,omitempty"`
ConfidentialNoteEvents *bool `url:"confidential_note_events,omitempty" json:"confidential_note_events,omitempty"`
MergeRequestsEvents *bool `url:"merge_requests_events,omitempty" json:"merge_requests_events,omitempty"`
TagPushEvents *bool `url:"tag_push_events,omitempty" json:"tag_push_events,omitempty"`
NoteEvents *bool `url:"note_events,omitempty" json:"note_events,omitempty"`
JobEvents *bool `url:"job_events,omitempty" json:"job_events,omitempty"`
PipelineEvents *bool `url:"pipeline_events,omitempty" json:"pipeline_events,omitempty"`
WikiPageEvents *bool `url:"wiki_page_events,omitempty" json:"wiki_page_events,omitempty"`
DeploymentEvents *bool `url:"deployment_events,omitempty" json:"deployment_events,omitempty"`
ReleasesEvents *bool `url:"releases_events,omitempty" json:"releases_events,omitempty"`
SubGroupEvents *bool `url:"subgroup_events,omitempty" json:"subgroup_events,omitempty"`
EnableSSLVerification *bool `url:"enable_ssl_verification,omitempty" json:"enable_ssl_verification,omitempty"`
Token *string `url:"token,omitempty" json:"token,omitempty"`
}
// AddGroupHook create a new group scoped webhook.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/groups.html#add-group-hook
func (s *GroupsService) AddGroupHook(gid interface{}, opt *AddGroupHookOptions, options ...RequestOptionFunc) (*GroupHook, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/hooks", PathEscape(group))
req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
if err != nil {
return nil, nil, err
}
gh := new(GroupHook)
resp, err := s.client.Do(req, gh)
if err != nil {
return nil, resp, err
}
return gh, resp, err
}
// EditGroupHookOptions represents the available EditGroupHook() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/groups.html#edit-group-hook
type EditGroupHookOptions struct {
URL *string `url:"url,omitempty" json:"url,omitempty"`
PushEvents *bool `url:"push_events,omitempty" json:"push_events,omitempty"`
PushEventsBranchFilter *string `url:"push_events_branch_filter,omitempty" json:"push_events_branch_filter,omitempty"`
IssuesEvents *bool `url:"issues_events,omitempty" json:"issues_events,omitempty"`
ConfidentialIssuesEvents *bool `url:"confidential_issues_events,omitempty" json:"confidential_issues_events,omitempty"`
ConfidentialNoteEvents *bool `url:"confidential_note_events,omitempty" json:"confidential_note_events,omitempty"`
MergeRequestsEvents *bool `url:"merge_requests_events,omitempty" json:"merge_requests_events,omitempty"`
TagPushEvents *bool `url:"tag_push_events,omitempty" json:"tag_push_events,omitempty"`
NoteEvents *bool `url:"note_events,omitempty" json:"note_events,omitempty"`
JobEvents *bool `url:"job_events,omitempty" json:"job_events,omitempty"`
PipelineEvents *bool `url:"pipeline_events,omitempty" json:"pipeline_events,omitempty"`
WikiPageEvents *bool `url:"wiki_page_events,omitempty" json:"wiki_page_events,omitempty"`
DeploymentEvents *bool `url:"deployment_events,omitempty" json:"deployment_events,omitempty"`
ReleasesEvents *bool `url:"releases_events,omitempty" json:"releases_events,omitempty"`
SubGroupEvents *bool `url:"subgroup_events,omitempty" json:"subgroup_events,omitempty"`
EnableSSLVerification *bool `url:"enable_ssl_verification,omitempty" json:"enable_ssl_verification,omitempty"`
Token *string `url:"token,omitempty" json:"token,omitempty"`
}
// EditGroupHook edits a hook for a specified group.
//
// Gitlab API docs:
// https://docs.gitlab.com/ee/api/groups.html#edit-group-hook
func (s *GroupsService) EditGroupHook(pid interface{}, hook int, opt *EditGroupHookOptions, options ...RequestOptionFunc) (*GroupHook, *Response, error) {
group, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/hooks/%d", PathEscape(group), hook)
req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
if err != nil {
return nil, nil, err
}
gh := new(GroupHook)
resp, err := s.client.Do(req, gh)
if err != nil {
return nil, resp, err
}
return gh, resp, err
}
// DeleteGroupHook removes a hook from a group. This is an idempotent
// method and can be called multiple times.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/groups.html#delete-group-hook
func (s *GroupsService) DeleteGroupHook(pid interface{}, hook int, options ...RequestOptionFunc) (*Response, error) {
group, err := parseID(pid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("groups/%s/hooks/%d", PathEscape(group), hook)
req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}

View File

@ -0,0 +1,180 @@
//
// 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 (
"bytes"
"fmt"
"io"
"mime/multipart"
"net/http"
"os"
"path/filepath"
"strconv"
)
// GroupImportExportService handles communication with the group import export
// related methods of the GitLab API.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/group_import_export.html
type GroupImportExportService struct {
client *Client
}
// ScheduleExport starts a new group export.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_import_export.html#schedule-new-export
func (s *GroupImportExportService) ScheduleExport(gid interface{}, options ...RequestOptionFunc) (*Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("groups/%s/export", PathEscape(group))
req, err := s.client.NewRequest(http.MethodPost, u, nil, options)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}
// ExportDownload downloads the finished export.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_import_export.html#export-download
func (s *GroupImportExportService) ExportDownload(gid interface{}, options ...RequestOptionFunc) (*bytes.Reader, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/export/download", PathEscape(group))
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}
exportDownload := new(bytes.Buffer)
resp, err := s.client.Do(req, exportDownload)
if err != nil {
return nil, resp, err
}
return bytes.NewReader(exportDownload.Bytes()), resp, err
}
// GroupImportFileOptions represents the available ImportFile() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_import_export.html#import-a-file
type GroupImportFileOptions struct {
Name *string `url:"name,omitempty" json:"name,omitempty"`
Path *string `url:"path,omitempty" json:"path,omitempty"`
File *string `url:"file,omitempty" json:"file,omitempty"`
ParentID *int `url:"parent_id,omitempty" json:"parent_id,omitempty"`
}
// ImportFile imports a file.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_import_export.html#import-a-file
func (s *GroupImportExportService) ImportFile(opt *GroupImportFileOptions, options ...RequestOptionFunc) (*Response, error) {
// First check if we got all required options.
if opt.Name == nil || *opt.Name == "" {
return nil, fmt.Errorf("Missing required option: Name")
}
if opt.Path == nil || *opt.Path == "" {
return nil, fmt.Errorf("Missing required option: Path")
}
if opt.File == nil || *opt.File == "" {
return nil, fmt.Errorf("Missing required option: File")
}
f, err := os.Open(*opt.File)
if err != nil {
return nil, err
}
defer f.Close()
b := &bytes.Buffer{}
w := multipart.NewWriter(b)
_, filename := filepath.Split(*opt.File)
fw, err := w.CreateFormFile("file", filename)
if err != nil {
return nil, err
}
_, err = io.Copy(fw, f)
if err != nil {
return nil, err
}
// Populate the additional fields.
fw, err = w.CreateFormField("name")
if err != nil {
return nil, err
}
_, err = fw.Write([]byte(*opt.Name))
if err != nil {
return nil, err
}
fw, err = w.CreateFormField("path")
if err != nil {
return nil, err
}
_, err = fw.Write([]byte(*opt.Path))
if err != nil {
return nil, err
}
if opt.ParentID != nil {
fw, err = w.CreateFormField("parent_id")
if err != nil {
return nil, err
}
_, err = fw.Write([]byte(strconv.Itoa(*opt.ParentID)))
if err != nil {
return nil, err
}
}
if err = w.Close(); err != nil {
return nil, err
}
req, err := s.client.NewRequest(http.MethodPost, "groups/import", nil, options)
if err != nil {
return nil, err
}
// Set the buffer as the request body.
if err = req.SetBody(b); err != nil {
return nil, err
}
// Overwrite the default content type.
req.Header.Set("Content-Type", w.FormDataContentType())
return s.client.Do(req, nil)
}

90
vendor/github.com/xanzy/go-gitlab/group_iterations.go generated vendored Normal file
View File

@ -0,0 +1,90 @@
//
// Copyright 2022, Daniel Steinke
//
// 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"
"time"
)
// IterationsAPI handles communication with the iterations related methods
// of the GitLab API
//
// GitLab API docs: https://docs.gitlab.com/ee/api/group_iterations.html
type GroupIterationsService struct {
client *Client
}
// GroupInteration represents a GitLab iteration.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/group_iterations.html
type GroupIteration struct {
ID int `json:"id"`
IID int `json:"iid"`
Sequence int `json:"sequence"`
GroupID int `json:"group_id"`
Title string `json:"title"`
Description string `json:"description"`
State int `json:"state"`
CreatedAt *time.Time `json:"created_at"`
UpdatedAt *time.Time `json:"updated_at"`
DueDate *ISOTime `json:"due_date"`
StartDate *ISOTime `json:"start_date"`
WebURL string `json:"web_url"`
}
func (i GroupIteration) String() string {
return Stringify(i)
}
// ListGroupIterationsOptions contains the available ListGroupIterations()
// options
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_iterations.html#list-group-iterations
type ListGroupIterationsOptions struct {
ListOptions
State *string `url:"state,omitempty" json:"state,omitempty"`
Search *string `url:"search,omitempty" json:"search,omitempty"`
IncludeAncestors *bool `url:"include_ancestors,omitempty" json:"include_ancestors,omitempty"`
}
// ListGroupIterations returns a list of group iterations.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_iterations.html#list-group-iterations
func (s *GroupIterationsService) ListGroupIterations(gid interface{}, opt *ListGroupIterationsOptions, options ...RequestOptionFunc) ([]*GroupIteration, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/iterations", PathEscape(group))
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
var gis []*GroupIteration
resp, err := s.client.Do(req, &gis)
if err != nil {
return nil, nil, err
}
return gis, resp, err
}

249
vendor/github.com/xanzy/go-gitlab/group_labels.go generated vendored Normal file
View File

@ -0,0 +1,249 @@
//
// 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"
)
// GroupLabelsService handles communication with the label related methods of the
// GitLab API.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/group_labels.html
type GroupLabelsService struct {
client *Client
}
// GroupLabel represents a GitLab group label.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/group_labels.html
type GroupLabel Label
func (l GroupLabel) String() string {
return Stringify(l)
}
// ListGroupLabelsOptions represents the available ListGroupLabels() options.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/group_labels.html#list-group-labels
type ListGroupLabelsOptions struct {
ListOptions
WithCounts *bool `url:"with_counts,omitempty" json:"with_counts,omitempty"`
IncludeAncestorGroups *bool `url:"include_ancestor_groups,omitempty" json:"include_ancestor_groups,omitempty"`
IncludeDescendantGrouops *bool `url:"include_descendant_groups,omitempty" json:"include_descendant_groups,omitempty"`
OnlyGroupLabels *bool `url:"only_group_labels,omitempty" json:"only_group_labels,omitempty"`
Search *string `url:"search,omitempty" json:"search,omitempty"`
}
// ListGroupLabels gets all labels for given group.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_labels.html#list-group-labels
func (s *GroupLabelsService) ListGroupLabels(gid interface{}, opt *ListGroupLabelsOptions, options ...RequestOptionFunc) ([]*GroupLabel, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/labels", PathEscape(group))
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
var l []*GroupLabel
resp, err := s.client.Do(req, &l)
if err != nil {
return nil, resp, err
}
return l, resp, err
}
// GetGroupLabel get a single label for a given group.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_labels.html#get-a-single-group-label
func (s *GroupLabelsService) GetGroupLabel(gid interface{}, labelID interface{}, options ...RequestOptionFunc) (*GroupLabel, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
label, err := parseID(labelID)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/labels/%s", PathEscape(group), PathEscape(label))
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}
var l *GroupLabel
resp, err := s.client.Do(req, &l)
if err != nil {
return nil, resp, err
}
return l, resp, err
}
// CreateGroupLabelOptions represents the available CreateGroupLabel() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_labels.html#create-a-new-group-label
type CreateGroupLabelOptions CreateLabelOptions
// CreateGroupLabel creates a new label for given group with given name and
// color.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_labels.html#create-a-new-group-label
func (s *GroupLabelsService) CreateGroupLabel(gid interface{}, opt *CreateGroupLabelOptions, options ...RequestOptionFunc) (*GroupLabel, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/labels", PathEscape(group))
req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
if err != nil {
return nil, nil, err
}
l := new(GroupLabel)
resp, err := s.client.Do(req, l)
if err != nil {
return nil, resp, err
}
return l, resp, err
}
// DeleteGroupLabelOptions represents the available DeleteGroupLabel() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_labels.html#delete-a-group-label
type DeleteGroupLabelOptions DeleteLabelOptions
// DeleteGroupLabel deletes a group label given by its name.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/group_labels.html#delete-a-group-label
func (s *GroupLabelsService) DeleteGroupLabel(gid interface{}, opt *DeleteGroupLabelOptions, options ...RequestOptionFunc) (*Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("groups/%s/labels", PathEscape(group))
req, err := s.client.NewRequest(http.MethodDelete, u, opt, options)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}
// UpdateGroupLabelOptions represents the available UpdateGroupLabel() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_labels.html#update-a-group-label
type UpdateGroupLabelOptions UpdateLabelOptions
// UpdateGroupLabel updates an existing label with new name or now color. At least
// one parameter is required, to update the label.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_labels.html#update-a-group-label
func (s *GroupLabelsService) UpdateGroupLabel(gid interface{}, opt *UpdateGroupLabelOptions, options ...RequestOptionFunc) (*GroupLabel, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/labels", PathEscape(group))
req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
if err != nil {
return nil, nil, err
}
l := new(GroupLabel)
resp, err := s.client.Do(req, l)
if err != nil {
return nil, resp, err
}
return l, resp, err
}
// SubscribeToGroupLabel subscribes the authenticated user to a label to receive
// notifications. If the user is already subscribed to the label, the status
// code 304 is returned.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_labels.html#subscribe-to-a-group-label
func (s *GroupLabelsService) SubscribeToGroupLabel(gid interface{}, labelID interface{}, options ...RequestOptionFunc) (*GroupLabel, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
label, err := parseID(labelID)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/labels/%s/subscribe", PathEscape(group), PathEscape(label))
req, err := s.client.NewRequest(http.MethodPost, u, nil, options)
if err != nil {
return nil, nil, err
}
l := new(GroupLabel)
resp, err := s.client.Do(req, l)
if err != nil {
return nil, resp, err
}
return l, resp, err
}
// UnsubscribeFromGroupLabel unsubscribes the authenticated user from a label to not
// receive notifications from it. If the user is not subscribed to the label, the
// status code 304 is returned.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_labels.html#unsubscribe-from-a-group-label
func (s *GroupLabelsService) UnsubscribeFromGroupLabel(gid interface{}, labelID interface{}, options ...RequestOptionFunc) (*Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, err
}
label, err := parseID(labelID)
if err != nil {
return nil, err
}
u := fmt.Sprintf("groups/%s/labels/%s/unsubscribe", PathEscape(group), PathEscape(label))
req, err := s.client.NewRequest(http.MethodPost, u, nil, options)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}

362
vendor/github.com/xanzy/go-gitlab/group_members.go generated vendored Normal file
View File

@ -0,0 +1,362 @@
//
// 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"
"time"
)
// GroupMembersService handles communication with the group members
// related methods of the GitLab API.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/members.html
type GroupMembersService struct {
client *Client
}
// GroupMemberSAMLIdentity represents the SAML Identity link for the group member.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/members.html#list-all-members-of-a-group-or-project
// Gitlab MR for API change: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/20357
// Gitlab MR for API Doc change: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/25652
type GroupMemberSAMLIdentity struct {
ExternUID string `json:"extern_uid"`
Provider string `json:"provider"`
SAMLProviderID int `json:"saml_provider_id"`
}
// GroupMember represents a GitLab group member.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/members.html
type GroupMember struct {
ID int `json:"id"`
Username string `json:"username"`
Name string `json:"name"`
State string `json:"state"`
AvatarURL string `json:"avatar_url"`
WebURL string `json:"web_url"`
CreatedAt *time.Time `json:"created_at"`
ExpiresAt *ISOTime `json:"expires_at"`
AccessLevel AccessLevelValue `json:"access_level"`
Email string `json:"email,omitempty"`
GroupSAMLIdentity *GroupMemberSAMLIdentity `json:"group_saml_identity"`
}
// ListGroupMembersOptions represents the available ListGroupMembers() and
// ListAllGroupMembers() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/members.html#list-all-members-of-a-group-or-project
type ListGroupMembersOptions struct {
ListOptions
Query *string `url:"query,omitempty" json:"query,omitempty"`
UserIDs *[]int `url:"user_ids[],omitempty" json:"user_ids,omitempty"`
}
// ListGroupMembers get a list of group members viewable by the authenticated
// user. Inherited members through ancestor groups are not included.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/members.html#list-all-members-of-a-group-or-project
func (s *GroupsService) ListGroupMembers(gid interface{}, opt *ListGroupMembersOptions, options ...RequestOptionFunc) ([]*GroupMember, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/members", PathEscape(group))
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
var gm []*GroupMember
resp, err := s.client.Do(req, &gm)
if err != nil {
return nil, resp, err
}
return gm, resp, err
}
// ListAllGroupMembers get a list of group members viewable by the authenticated
// user. Returns a list including inherited members through ancestor groups.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/members.html#list-all-members-of-a-group-or-project-including-inherited-and-invited-members
func (s *GroupsService) ListAllGroupMembers(gid interface{}, opt *ListGroupMembersOptions, options ...RequestOptionFunc) ([]*GroupMember, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/members/all", PathEscape(group))
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
var gm []*GroupMember
resp, err := s.client.Do(req, &gm)
if err != nil {
return nil, resp, err
}
return gm, resp, err
}
// AddGroupMemberOptions represents the available AddGroupMember() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/members.html#add-a-member-to-a-group-or-project
type AddGroupMemberOptions struct {
UserID *int `url:"user_id,omitempty" json:"user_id,omitempty"`
AccessLevel *AccessLevelValue `url:"access_level,omitempty" json:"access_level,omitempty"`
ExpiresAt *string `url:"expires_at,omitempty" json:"expires_at"`
}
// GetGroupMember gets a member of a group.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/members.html#get-a-member-of-a-group-or-project
func (s *GroupMembersService) GetGroupMember(gid interface{}, user int, options ...RequestOptionFunc) (*GroupMember, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/members/%d", PathEscape(group), user)
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}
gm := new(GroupMember)
resp, err := s.client.Do(req, gm)
if err != nil {
return nil, resp, err
}
return gm, resp, err
}
// BillableGroupMember represents a GitLab billable group member.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/members.html#list-all-billable-members-of-a-group
type BillableGroupMember struct {
ID int `json:"id"`
Username string `json:"username"`
Name string `json:"name"`
State string `json:"state"`
AvatarURL string `json:"avatar_url"`
WebURL string `json:"web_url"`
Email string `json:"email"`
LastActivityOn *ISOTime `json:"last_activity_on"`
MembershipType string `json:"membership_type"`
Removable bool `json:"removable"`
CreatedAt *time.Time `json:"created_at"`
IsLastOwner bool `json:"is_last_owner"`
LastLoginAt *time.Time `json:"last_login_at"`
}
// ListBillableGroupMembersOptions represents the available ListBillableGroupMembers() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/members.html#list-all-billable-members-of-a-group
type ListBillableGroupMembersOptions struct {
ListOptions
Search *string `url:"search,omitempty" json:"search,omitempty"`
Sort *string `url:"sort,omitempty" json:"sort,omitempty"`
}
// ListBillableGroupMembers Gets a list of group members that count as billable.
// The list includes members in the subgroup or subproject.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/members.html#list-all-billable-members-of-a-group
func (s *GroupsService) ListBillableGroupMembers(gid interface{}, opt *ListBillableGroupMembersOptions, options ...RequestOptionFunc) ([]*BillableGroupMember, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/billable_members", PathEscape(group))
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
var bgm []*BillableGroupMember
resp, err := s.client.Do(req, &bgm)
if err != nil {
return nil, resp, err
}
return bgm, resp, err
}
// RemoveBillableGroupMember removes a given group members that count as billable.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/members.html#remove-a-billable-member-from-a-group
func (s *GroupsService) RemoveBillableGroupMember(gid interface{}, user int, options ...RequestOptionFunc) (*Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("groups/%s/billable_members/%d", PathEscape(group), user)
req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}
// AddGroupMember adds a user to the list of group members.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/members.html#add-a-member-to-a-group-or-project
func (s *GroupMembersService) AddGroupMember(gid interface{}, opt *AddGroupMemberOptions, options ...RequestOptionFunc) (*GroupMember, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/members", PathEscape(group))
req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
if err != nil {
return nil, nil, err
}
gm := new(GroupMember)
resp, err := s.client.Do(req, gm)
if err != nil {
return nil, resp, err
}
return gm, resp, err
}
// ShareWithGroup shares a group with the group.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/groups.html#share-groups-with-groups
func (s *GroupMembersService) ShareWithGroup(gid interface{}, opt *ShareWithGroupOptions, options ...RequestOptionFunc) (*Group, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/share", PathEscape(group))
req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
if err != nil {
return nil, nil, err
}
g := new(Group)
resp, err := s.client.Do(req, g)
if err != nil {
return nil, resp, err
}
return g, resp, err
}
// DeleteShareWithGroup allows to unshare a group from a group.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/groups.html#delete-link-sharing-group-with-another-group
func (s *GroupMembersService) DeleteShareWithGroup(gid interface{}, groupID int, options ...RequestOptionFunc) (*Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("groups/%s/share/%d", PathEscape(group), groupID)
req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}
// EditGroupMemberOptions represents the available EditGroupMember()
// options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/members.html#edit-a-member-of-a-group-or-project
type EditGroupMemberOptions struct {
AccessLevel *AccessLevelValue `url:"access_level,omitempty" json:"access_level,omitempty"`
ExpiresAt *string `url:"expires_at,omitempty" json:"expires_at,omitempty"`
}
// EditGroupMember updates a member of a group.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/members.html#edit-a-member-of-a-group-or-project
func (s *GroupMembersService) EditGroupMember(gid interface{}, user int, opt *EditGroupMemberOptions, options ...RequestOptionFunc) (*GroupMember, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/members/%d", PathEscape(group), user)
req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
if err != nil {
return nil, nil, err
}
gm := new(GroupMember)
resp, err := s.client.Do(req, gm)
if err != nil {
return nil, resp, err
}
return gm, resp, err
}
// RemoveGroupMemberOptions represents the available options to remove a group member.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/members.html#remove-a-member-from-a-group-or-project
type RemoveGroupMemberOptions struct {
SkipSubresources *bool `url:"skip_subresources,omitempty" json:"skip_subresources,omitempty"`
UnassignIssuables *bool `url:"unassign_issuables,omitempty" json:"unassign_issuables,omitempty"`
}
// RemoveGroupMember removes user from user team.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/members.html#remove-a-member-from-a-group-or-project
func (s *GroupMembersService) RemoveGroupMember(gid interface{}, user int, opt *RemoveGroupMemberOptions, options ...RequestOptionFunc) (*Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("groups/%s/members/%d", PathEscape(group), user)
req, err := s.client.NewRequest(http.MethodDelete, u, opt, options)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}

296
vendor/github.com/xanzy/go-gitlab/group_milestones.go generated vendored Normal file
View File

@ -0,0 +1,296 @@
//
// 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"
"time"
)
// GroupMilestonesService handles communication with the milestone related
// methods of the GitLab API.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/group_milestones.html
type GroupMilestonesService struct {
client *Client
}
// GroupMilestone represents a GitLab milestone.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/group_milestones.html
type GroupMilestone struct {
ID int `json:"id"`
IID int `json:"iid"`
GroupID int `json:"group_id"`
Title string `json:"title"`
Description string `json:"description"`
StartDate *ISOTime `json:"start_date"`
DueDate *ISOTime `json:"due_date"`
State string `json:"state"`
UpdatedAt *time.Time `json:"updated_at"`
CreatedAt *time.Time `json:"created_at"`
Expired *bool `json:"expired"`
}
func (m GroupMilestone) String() string {
return Stringify(m)
}
// ListGroupMilestonesOptions represents the available
// ListGroupMilestones() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_milestones.html#list-group-milestones
type ListGroupMilestonesOptions struct {
ListOptions
IIDs *[]int `url:"iids[],omitempty" json:"iids,omitempty"`
State *string `url:"state,omitempty" json:"state,omitempty"`
Title *string `url:"title,omitempty" json:"title,omitempty"`
Search *string `url:"search,omitempty" json:"search,omitempty"`
IncludeParentMilestones *bool `url:"include_parent_milestones,omitempty" json:"include_parent_milestones,omitempty"`
}
// ListGroupMilestones returns a list of group milestones.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_milestones.html#list-group-milestones
func (s *GroupMilestonesService) ListGroupMilestones(gid interface{}, opt *ListGroupMilestonesOptions, options ...RequestOptionFunc) ([]*GroupMilestone, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/milestones", PathEscape(group))
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
var m []*GroupMilestone
resp, err := s.client.Do(req, &m)
if err != nil {
return nil, resp, err
}
return m, resp, err
}
// GetGroupMilestone gets a single group milestone.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_milestones.html#get-single-milestone
func (s *GroupMilestonesService) GetGroupMilestone(gid interface{}, milestone int, options ...RequestOptionFunc) (*GroupMilestone, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/milestones/%d", PathEscape(group), milestone)
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}
m := new(GroupMilestone)
resp, err := s.client.Do(req, m)
if err != nil {
return nil, resp, err
}
return m, resp, err
}
// CreateGroupMilestoneOptions represents the available CreateGroupMilestone() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_milestones.html#create-new-milestone
type CreateGroupMilestoneOptions struct {
Title *string `url:"title,omitempty" json:"title,omitempty"`
Description *string `url:"description,omitempty" json:"description,omitempty"`
StartDate *ISOTime `url:"start_date,omitempty" json:"start_date,omitempty"`
DueDate *ISOTime `url:"due_date,omitempty" json:"due_date,omitempty"`
}
// CreateGroupMilestone creates a new group milestone.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_milestones.html#create-new-milestone
func (s *GroupMilestonesService) CreateGroupMilestone(gid interface{}, opt *CreateGroupMilestoneOptions, options ...RequestOptionFunc) (*GroupMilestone, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/milestones", PathEscape(group))
req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
if err != nil {
return nil, nil, err
}
m := new(GroupMilestone)
resp, err := s.client.Do(req, m)
if err != nil {
return nil, resp, err
}
return m, resp, err
}
// UpdateGroupMilestoneOptions represents the available UpdateGroupMilestone() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_milestones.html#edit-milestone
type UpdateGroupMilestoneOptions struct {
Title *string `url:"title,omitempty" json:"title,omitempty"`
Description *string `url:"description,omitempty" json:"description,omitempty"`
StartDate *ISOTime `url:"start_date,omitempty" json:"start_date,omitempty"`
DueDate *ISOTime `url:"due_date,omitempty" json:"due_date,omitempty"`
StateEvent *string `url:"state_event,omitempty" json:"state_event,omitempty"`
}
// UpdateGroupMilestone updates an existing group milestone.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_milestones.html#edit-milestone
func (s *GroupMilestonesService) UpdateGroupMilestone(gid interface{}, milestone int, opt *UpdateGroupMilestoneOptions, options ...RequestOptionFunc) (*GroupMilestone, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/milestones/%d", PathEscape(group), milestone)
req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
if err != nil {
return nil, nil, err
}
m := new(GroupMilestone)
resp, err := s.client.Do(req, m)
if err != nil {
return nil, resp, err
}
return m, resp, err
}
// GetGroupMilestoneIssuesOptions represents the available GetGroupMilestoneIssues() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_milestones.html#get-all-issues-assigned-to-a-single-milestone
type GetGroupMilestoneIssuesOptions ListOptions
// GetGroupMilestoneIssues gets all issues assigned to a single group milestone.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_milestones.html#get-all-issues-assigned-to-a-single-milestone
func (s *GroupMilestonesService) GetGroupMilestoneIssues(gid interface{}, milestone int, opt *GetGroupMilestoneIssuesOptions, options ...RequestOptionFunc) ([]*Issue, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/milestones/%d/issues", PathEscape(group), milestone)
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
var i []*Issue
resp, err := s.client.Do(req, &i)
if err != nil {
return nil, resp, err
}
return i, resp, err
}
// GetGroupMilestoneMergeRequestsOptions represents the available
// GetGroupMilestoneMergeRequests() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_milestones.html#get-all-merge-requests-assigned-to-a-single-milestone
type GetGroupMilestoneMergeRequestsOptions ListOptions
// GetGroupMilestoneMergeRequests gets all merge requests assigned to a
// single group milestone.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_milestones.html#get-all-merge-requests-assigned-to-a-single-milestone
func (s *GroupMilestonesService) GetGroupMilestoneMergeRequests(gid interface{}, milestone int, opt *GetGroupMilestoneMergeRequestsOptions, options ...RequestOptionFunc) ([]*MergeRequest, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/milestones/%d/merge_requests", PathEscape(group), milestone)
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
var mr []*MergeRequest
resp, err := s.client.Do(req, &mr)
if err != nil {
return nil, resp, err
}
return mr, resp, err
}
// BurndownChartEvent reprensents a burnout chart event
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_milestones.html#get-all-burndown-chart-events-for-a-single-milestone
type BurndownChartEvent struct {
CreatedAt *time.Time `json:"created_at"`
Weight *int `json:"weight"`
Action *string `json:"action"`
}
// GetGroupMilestoneBurndownChartEventsOptions represents the available
// GetGroupMilestoneBurndownChartEventsOptions() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_milestones.html#get-all-burndown-chart-events-for-a-single-milestone
type GetGroupMilestoneBurndownChartEventsOptions ListOptions
// GetGroupMilestoneBurndownChartEvents gets all merge requests assigned to a
// single group milestone.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_milestones.html#get-all-burndown-chart-events-for-a-single-milestone
func (s *GroupMilestonesService) GetGroupMilestoneBurndownChartEvents(gid interface{}, milestone int, opt *GetGroupMilestoneBurndownChartEventsOptions, options ...RequestOptionFunc) ([]*BurndownChartEvent, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/milestones/%d/burndown_events", PathEscape(group), milestone)
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
var be []*BurndownChartEvent
resp, err := s.client.Do(req, &be)
if err != nil {
return nil, resp, err
}
return be, resp, err
}

206
vendor/github.com/xanzy/go-gitlab/group_variables.go generated vendored Normal file
View File

@ -0,0 +1,206 @@
//
// Copyright 2021, Patrick Webster
//
// 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"
"net/url"
)
// GroupVariablesService handles communication with the
// group variables related methods of the GitLab API.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_level_variables.html
type GroupVariablesService struct {
client *Client
}
// GroupVariable represents a GitLab group Variable.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_level_variables.html
type GroupVariable struct {
Key string `json:"key"`
Value string `json:"value"`
VariableType VariableTypeValue `json:"variable_type"`
Protected bool `json:"protected"`
Masked bool `json:"masked"`
Raw bool `json:"raw"`
EnvironmentScope string `json:"environment_scope"`
}
func (v GroupVariable) String() string {
return Stringify(v)
}
// ListGroupVariablesOptions represents the available options for listing variables
// for a group.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_level_variables.html#list-group-variables
type ListGroupVariablesOptions ListOptions
// ListVariables gets a list of all variables for a group.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_level_variables.html#list-group-variables
func (s *GroupVariablesService) ListVariables(gid interface{}, opt *ListGroupVariablesOptions, options ...RequestOptionFunc) ([]*GroupVariable, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/variables", PathEscape(group))
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
var vs []*GroupVariable
resp, err := s.client.Do(req, &vs)
if err != nil {
return nil, resp, err
}
return vs, resp, err
}
// GetVariable gets a variable.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_level_variables.html#show-variable-details
func (s *GroupVariablesService) GetVariable(gid interface{}, key string, options ...RequestOptionFunc) (*GroupVariable, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/variables/%s", PathEscape(group), url.PathEscape(key))
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}
v := new(GroupVariable)
resp, err := s.client.Do(req, v)
if err != nil {
return nil, resp, err
}
return v, resp, err
}
// CreateGroupVariableOptions represents the available CreateVariable()
// options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_level_variables.html#create-variable
type CreateGroupVariableOptions struct {
Key *string `url:"key,omitempty" json:"key,omitempty"`
Value *string `url:"value,omitempty" json:"value,omitempty"`
VariableType *VariableTypeValue `url:"variable_type,omitempty" json:"variable_type,omitempty"`
Protected *bool `url:"protected,omitempty" json:"protected,omitempty"`
Masked *bool `url:"masked,omitempty" json:"masked,omitempty"`
Raw *bool `url:"raw,omitempty" json:"raw,omitempty"`
EnvironmentScope *string `url:"environment_scope,omitempty" json:"environment_scope,omitempty"`
}
// CreateVariable creates a new group variable.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_level_variables.html#create-variable
func (s *GroupVariablesService) CreateVariable(gid interface{}, opt *CreateGroupVariableOptions, options ...RequestOptionFunc) (*GroupVariable, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/variables", PathEscape(group))
req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
if err != nil {
return nil, nil, err
}
v := new(GroupVariable)
resp, err := s.client.Do(req, v)
if err != nil {
return nil, resp, err
}
return v, resp, err
}
// UpdateGroupVariableOptions represents the available UpdateVariable()
// options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_level_variables.html#update-variable
type UpdateGroupVariableOptions struct {
Value *string `url:"value,omitempty" json:"value,omitempty"`
VariableType *VariableTypeValue `url:"variable_type,omitempty" json:"variable_type,omitempty"`
Protected *bool `url:"protected,omitempty" json:"protected,omitempty"`
Masked *bool `url:"masked,omitempty" json:"masked,omitempty"`
Raw *bool `url:"raw,omitempty" json:"raw,omitempty"`
EnvironmentScope *string `url:"environment_scope,omitempty" json:"environment_scope,omitempty"`
}
// UpdateVariable updates the position of an existing
// group issue board list.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_level_variables.html#update-variable
func (s *GroupVariablesService) UpdateVariable(gid interface{}, key string, opt *UpdateGroupVariableOptions, options ...RequestOptionFunc) (*GroupVariable, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/variables/%s", PathEscape(group), url.PathEscape(key))
req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
if err != nil {
return nil, nil, err
}
v := new(GroupVariable)
resp, err := s.client.Do(req, v)
if err != nil {
return nil, resp, err
}
return v, resp, err
}
// RemoveVariable removes a group's variable.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_level_variables.html#remove-variable
func (s *GroupVariablesService) RemoveVariable(gid interface{}, key string, options ...RequestOptionFunc) (*Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("groups/%s/variables/%s", PathEscape(group), url.PathEscape(key))
req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}

204
vendor/github.com/xanzy/go-gitlab/group_wikis.go generated vendored Normal file
View File

@ -0,0 +1,204 @@
//
// Copyright 2021, Markus Lackner
//
// 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"
"net/url"
)
// GroupWikisService handles communication with the group wikis related methods of
// the Gitlab API.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/group_wikis.html
type GroupWikisService struct {
client *Client
}
// GroupWiki represents a GitLab groups wiki.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/group_wikis.html
type GroupWiki struct {
Content string `json:"content"`
Encoding string `json:"encoding"`
Format WikiFormatValue `json:"format"`
Slug string `json:"slug"`
Title string `json:"title"`
}
func (w GroupWiki) String() string {
return Stringify(w)
}
// ListGroupWikisOptions represents the available ListGroupWikis options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_wikis.html#list-wiki-pages
type ListGroupWikisOptions struct {
WithContent *bool `url:"with_content,omitempty" json:"with_content,omitempty"`
}
// ListGroupWikis lists all pages of the wiki of the given group id.
// When with_content is set, it also returns the content of the pages.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_wikis.html#list-wiki-pages
func (s *GroupWikisService) ListGroupWikis(gid interface{}, opt *ListGroupWikisOptions, options ...RequestOptionFunc) ([]*GroupWiki, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/wikis", PathEscape(group))
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
var gws []*GroupWiki
resp, err := s.client.Do(req, &gws)
if err != nil {
return nil, resp, err
}
return gws, resp, err
}
// GetGroupWikiPageOptions represents options to GetGroupWikiPage
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_wikis.html#get-a-wiki-page
type GetGroupWikiPageOptions struct {
RenderHTML *bool `url:"render_html,omitempty" json:"render_html,omitempty"`
Version *string `url:"version,omitempty" json:"version,omitempty"`
}
// GetGroupWikiPage gets a wiki page for a given group.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_wikis.html#get-a-wiki-page
func (s *GroupWikisService) GetGroupWikiPage(gid interface{}, slug string, opt *GetGroupWikiPageOptions, options ...RequestOptionFunc) (*GroupWiki, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/wikis/%s", PathEscape(group), url.PathEscape(slug))
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
gw := new(GroupWiki)
resp, err := s.client.Do(req, gw)
if err != nil {
return nil, resp, err
}
return gw, resp, err
}
// CreateGroupWikiPageOptions represents options to CreateGroupWikiPage.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_wikis.html#create-a-new-wiki-page
type CreateGroupWikiPageOptions struct {
Content *string `url:"content,omitempty" json:"content,omitempty"`
Title *string `url:"title,omitempty" json:"title,omitempty"`
Format *WikiFormatValue `url:"format,omitempty" json:"format,omitempty"`
}
// CreateGroupWikiPage creates a new wiki page for the given group with
// the given title, slug, and content.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_wikis.html#create-a-new-wiki-page
func (s *GroupWikisService) CreateGroupWikiPage(gid interface{}, opt *CreateGroupWikiPageOptions, options ...RequestOptionFunc) (*GroupWiki, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/wikis", PathEscape(group))
req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
if err != nil {
return nil, nil, err
}
w := new(GroupWiki)
resp, err := s.client.Do(req, w)
if err != nil {
return nil, resp, err
}
return w, resp, err
}
// EditGroupWikiPageOptions represents options to EditGroupWikiPage.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_wikis.html#edit-an-existing-wiki-page
type EditGroupWikiPageOptions struct {
Content *string `url:"content,omitempty" json:"content,omitempty"`
Title *string `url:"title,omitempty" json:"title,omitempty"`
Format *WikiFormatValue `url:"format,omitempty" json:"format,omitempty"`
}
// EditGroupWikiPage Updates an existing wiki page. At least one parameter is
// required to update the wiki page.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_wikis.html#edit-an-existing-wiki-page
func (s *GroupWikisService) EditGroupWikiPage(gid interface{}, slug string, opt *EditGroupWikiPageOptions, options ...RequestOptionFunc) (*GroupWiki, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/wikis/%s", PathEscape(group), url.PathEscape(slug))
req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
if err != nil {
return nil, nil, err
}
w := new(GroupWiki)
resp, err := s.client.Do(req, w)
if err != nil {
return nil, resp, err
}
return w, resp, err
}
// DeleteGroupWikiPage deletes a wiki page with a given slug.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_wikis.html#delete-a-wiki-page
func (s *GroupWikisService) DeleteGroupWikiPage(gid interface{}, slug string, options ...RequestOptionFunc) (*Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("groups/%s/wikis/%s", PathEscape(group), url.PathEscape(slug))
req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}

1113
vendor/github.com/xanzy/go-gitlab/groups.go generated vendored Normal file

File diff suppressed because it is too large Load Diff

153
vendor/github.com/xanzy/go-gitlab/instance_clusters.go generated vendored Normal file
View File

@ -0,0 +1,153 @@
//
// Copyright 2021, Serena Fang
//
// 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"
"time"
)
// InstanceClustersService handles communication with the
// instance clusters related methods of the GitLab API.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/instance_clusters.html
type InstanceClustersService struct {
client *Client
}
// InstanceCluster represents a GitLab Instance Cluster.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/instance_clusters.html
type InstanceCluster struct {
ID int `json:"id"`
Name string `json:"name"`
Domain string `json:"domain"`
Managed bool `json:"managed"`
CreatedAt *time.Time `json:"created_at"`
ProviderType string `json:"provider_type"`
PlatformType string `json:"platform_type"`
EnvironmentScope string `json:"environment_scope"`
ClusterType string `json:"cluster_type"`
User *User `json:"user"`
PlatformKubernetes *PlatformKubernetes `json:"platform_kubernetes"`
ManagementProject *ManagementProject `json:"management_project"`
}
func (v InstanceCluster) String() string {
return Stringify(v)
}
// ListClusters gets a list of all instance clusters.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/instance_clusters.html#list-instance-clusters
func (s *InstanceClustersService) ListClusters(options ...RequestOptionFunc) ([]*InstanceCluster, *Response, error) {
u := "admin/clusters"
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}
var ics []*InstanceCluster
resp, err := s.client.Do(req, &ics)
if err != nil {
return nil, resp, err
}
return ics, resp, err
}
// GetCluster gets an instance cluster.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/instance_clusters.html#get-a-single-instance-cluster
func (s *InstanceClustersService) GetCluster(cluster int, options ...RequestOptionFunc) (*InstanceCluster, *Response, error) {
u := fmt.Sprintf("admin/clusters/%d", cluster)
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}
ic := new(InstanceCluster)
resp, err := s.client.Do(req, &ic)
if err != nil {
return nil, resp, err
}
return ic, resp, err
}
// AddCluster adds an existing cluster to the instance.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/instance_clusters.html#add-existing-instance-cluster
func (s *InstanceClustersService) AddCluster(opt *AddClusterOptions, options ...RequestOptionFunc) (*InstanceCluster, *Response, error) {
u := "admin/clusters/add"
req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
if err != nil {
return nil, nil, err
}
ic := new(InstanceCluster)
resp, err := s.client.Do(req, ic)
if err != nil {
return nil, resp, err
}
return ic, resp, err
}
// EditCluster updates an existing instance cluster.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/instance_clusters.html#edit-instance-cluster
func (s *InstanceClustersService) EditCluster(cluster int, opt *EditClusterOptions, options ...RequestOptionFunc) (*InstanceCluster, *Response, error) {
u := fmt.Sprintf("admin/clusters/%d", cluster)
req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
if err != nil {
return nil, nil, err
}
ic := new(InstanceCluster)
resp, err := s.client.Do(req, ic)
if err != nil {
return nil, resp, err
}
return ic, resp, err
}
// DeleteCluster deletes an existing instance cluster.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/instance_clusters.html#delete-instance-cluster
func (s *InstanceClustersService) DeleteCluster(cluster int, options ...RequestOptionFunc) (*Response, error) {
u := fmt.Sprintf("admin/clusters/%d", cluster)
req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}

183
vendor/github.com/xanzy/go-gitlab/instance_variables.go generated vendored Normal file
View File

@ -0,0 +1,183 @@
//
// Copyright 2021, Patrick Webster
//
// 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"
"net/url"
)
// InstanceVariablesService handles communication with the
// instance level CI variables related methods of the GitLab API.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/instance_level_ci_variables.html
type InstanceVariablesService struct {
client *Client
}
// InstanceVariable represents a GitLab instance level CI Variable.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/instance_level_ci_variables.html
type InstanceVariable struct {
Key string `json:"key"`
Value string `json:"value"`
VariableType VariableTypeValue `json:"variable_type"`
Protected bool `json:"protected"`
Masked bool `json:"masked"`
Raw bool `json:"raw"`
}
func (v InstanceVariable) String() string {
return Stringify(v)
}
// ListInstanceVariablesOptions represents the available options for listing variables
// for an instance.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/instance_level_ci_variables.html#list-all-instance-variables
type ListInstanceVariablesOptions ListOptions
// ListVariables gets a list of all variables for an instance.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/instance_level_ci_variables.html#list-all-instance-variables
func (s *InstanceVariablesService) ListVariables(opt *ListInstanceVariablesOptions, options ...RequestOptionFunc) ([]*InstanceVariable, *Response, error) {
u := "admin/ci/variables"
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
var vs []*InstanceVariable
resp, err := s.client.Do(req, &vs)
if err != nil {
return nil, resp, err
}
return vs, resp, err
}
// GetVariable gets a variable.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/instance_level_ci_variables.html#show-instance-variable-details
func (s *InstanceVariablesService) GetVariable(key string, options ...RequestOptionFunc) (*InstanceVariable, *Response, error) {
u := fmt.Sprintf("admin/ci/variables/%s", url.PathEscape(key))
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}
v := new(InstanceVariable)
resp, err := s.client.Do(req, v)
if err != nil {
return nil, resp, err
}
return v, resp, err
}
// CreateInstanceVariableOptions represents the available CreateVariable()
// options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/instance_level_ci_variables.html#create-instance-variable
type CreateInstanceVariableOptions struct {
Key *string `url:"key,omitempty" json:"key,omitempty"`
Value *string `url:"value,omitempty" json:"value,omitempty"`
VariableType *VariableTypeValue `url:"variable_type,omitempty" json:"variable_type,omitempty"`
Protected *bool `url:"protected,omitempty" json:"protected,omitempty"`
Masked *bool `url:"masked,omitempty" json:"masked,omitempty"`
Raw *bool `url:"raw,omitempty" json:"raw,omitempty"`
}
// CreateVariable creates a new instance level CI variable.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/instance_level_ci_variables.html#create-instance-variable
func (s *InstanceVariablesService) CreateVariable(opt *CreateInstanceVariableOptions, options ...RequestOptionFunc) (*InstanceVariable, *Response, error) {
u := "admin/ci/variables"
req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
if err != nil {
return nil, nil, err
}
v := new(InstanceVariable)
resp, err := s.client.Do(req, v)
if err != nil {
return nil, resp, err
}
return v, resp, err
}
// UpdateInstanceVariableOptions represents the available UpdateVariable()
// options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/instance_level_ci_variables.html#update-instance-variable
type UpdateInstanceVariableOptions struct {
Value *string `url:"value,omitempty" json:"value,omitempty"`
VariableType *VariableTypeValue `url:"variable_type,omitempty" json:"variable_type,omitempty"`
Protected *bool `url:"protected,omitempty" json:"protected,omitempty"`
Masked *bool `url:"masked,omitempty" json:"masked,omitempty"`
Raw *bool `url:"raw,omitempty" json:"raw,omitempty"`
}
// UpdateVariable updates the position of an existing
// instance level CI variable.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/instance_level_ci_variables.html#update-instance-variable
func (s *InstanceVariablesService) UpdateVariable(key string, opt *UpdateInstanceVariableOptions, options ...RequestOptionFunc) (*InstanceVariable, *Response, error) {
u := fmt.Sprintf("admin/ci/variables/%s", url.PathEscape(key))
req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
if err != nil {
return nil, nil, err
}
v := new(InstanceVariable)
resp, err := s.client.Do(req, v)
if err != nil {
return nil, resp, err
}
return v, resp, err
}
// RemoveVariable removes an instance level CI variable.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/instance_level_ci_variables.html#remove-instance-variable
func (s *InstanceVariablesService) RemoveVariable(key string, options ...RequestOptionFunc) (*Response, error) {
u := fmt.Sprintf("admin/ci/variables/%s", url.PathEscape(key))
req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}

176
vendor/github.com/xanzy/go-gitlab/invites.go generated vendored Normal file
View File

@ -0,0 +1,176 @@
//
// 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"
"time"
)
// InvitesService handles communication with the invitation related
// methods of the GitLab API.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/invitations.html
type InvitesService struct {
client *Client
}
// PendingInvite represents a pending invite.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/invitations.html
type PendingInvite struct {
ID int `json:"id"`
InviteEmail string `json:"invite_email"`
CreatedAt *time.Time `json:"created_at"`
AccessLevel AccessLevelValue `json:"access_level"`
ExpiresAt *time.Time `json:"expires_at"`
UserName string `json:"user_name"`
CreatedByName string `json:"created_by_name"`
}
// ListPendingInvitationsOptions represents the available
// ListPendingInvitations() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/invitations.html#list-all-invitations-pending-for-a-group-or-project
type ListPendingInvitationsOptions struct {
ListOptions
Query *string `url:"query,omitempty" json:"query,omitempty"`
}
// ListPendingGroupInvitations gets a list of invited group members.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/invitations.html#list-all-invitations-pending-for-a-group-or-project
func (s *InvitesService) ListPendingGroupInvitations(gid interface{}, opt *ListPendingInvitationsOptions, options ...RequestOptionFunc) ([]*PendingInvite, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/invitations", PathEscape(group))
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
var pis []*PendingInvite
resp, err := s.client.Do(req, &pis)
if err != nil {
return nil, resp, err
}
return pis, resp, err
}
// ListPendingProjectInvitations gets a list of invited project members.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/invitations.html#list-all-invitations-pending-for-a-group-or-project
func (s *InvitesService) ListPendingProjectInvitations(pid interface{}, opt *ListPendingInvitationsOptions, options ...RequestOptionFunc) ([]*PendingInvite, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/invitations", PathEscape(project))
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
var pis []*PendingInvite
resp, err := s.client.Do(req, &pis)
if err != nil {
return nil, resp, err
}
return pis, resp, err
}
// InvitesOptions represents the available GroupInvites() and ProjectInvites()
// options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/invitations.html#add-a-member-to-a-group-or-project
type InvitesOptions struct {
ID interface{} `url:"id,omitempty" json:"id,omitempty"`
Email *string `url:"email,omitempty" json:"email,omitempty"`
UserID interface{} `url:"user_id,omitempty" json:"user_id,omitempty"`
AccessLevel *AccessLevelValue `url:"access_level,omitempty" json:"access_level,omitempty"`
ExpiresAt *ISOTime `url:"expires_at,omitempty" json:"expires_at,omitempty"`
}
// InvitesResult represents an invitations result.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/invitations.html#add-a-member-to-a-group-or-project
type InvitesResult struct {
Status string `json:"status"`
Message map[string]string `json:"message,omitempty"`
}
// GroupInvites invites new users by email to join a group.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/invitations.html#add-a-member-to-a-group-or-project
func (s *InvitesService) GroupInvites(gid interface{}, opt *InvitesOptions, options ...RequestOptionFunc) (*InvitesResult, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/invitations", PathEscape(group))
req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
if err != nil {
return nil, nil, err
}
ir := new(InvitesResult)
resp, err := s.client.Do(req, ir)
if err != nil {
return nil, resp, err
}
return ir, resp, err
}
// ProjectInvites invites new users by email to join a project.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/invitations.html#add-a-member-to-a-group-or-project
func (s *InvitesService) ProjectInvites(pid interface{}, opt *InvitesOptions, options ...RequestOptionFunc) (*InvitesResult, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/invitations", PathEscape(project))
req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
if err != nil {
return nil, nil, err
}
ir := new(InvitesResult)
resp, err := s.client.Do(req, ir)
if err != nil {
return nil, resp, err
}
return ir, resp, err
}

186
vendor/github.com/xanzy/go-gitlab/issue_links.go generated vendored Normal file
View File

@ -0,0 +1,186 @@
//
// Copyright 2021, Arkbriar
//
// 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"
"time"
)
// IssueLinksService handles communication with the issue relations related methods
// of the GitLab API.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/issue_links.html
type IssueLinksService struct {
client *Client
}
// IssueLink represents a two-way relation between two issues.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/issue_links.html
type IssueLink struct {
SourceIssue *Issue `json:"source_issue"`
TargetIssue *Issue `json:"target_issue"`
LinkType string `json:"link_type"`
}
// IssueRelation gets a relation between two issues.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/issue_links.html#list-issue-relations
type IssueRelation struct {
ID int `json:"id"`
IID int `json:"iid"`
State string `json:"state"`
Description string `json:"description"`
Confidential bool `json:"confidential"`
Author *IssueAuthor `json:"author"`
Milestone *Milestone `json:"milestone"`
ProjectID int `json:"project_id"`
Assignees []*IssueAssignee `json:"assignees"`
Assignee *IssueAssignee `json:"assignee"`
UpdatedAt *time.Time `json:"updated_at"`
Title string `json:"title"`
CreatedAt *time.Time `json:"created_at"`
Labels Labels `json:"labels"`
DueDate *ISOTime `json:"due_date"`
WebURL string `json:"web_url"`
References *IssueReferences `json:"references"`
Weight int `json:"weight"`
UserNotesCount int `json:"user_notes_count"`
IssueLinkID int `json:"issue_link_id"`
LinkType string `json:"link_type"`
LinkCreatedAt *time.Time `json:"link_created_at"`
LinkUpdatedAt *time.Time `json:"link_updated_at"`
}
// ListIssueRelations gets a list of related issues of a given issue,
// sorted by the relationship creation datetime (ascending).
//
// Issues will be filtered according to the user authorizations.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/issue_links.html#list-issue-relations
func (s *IssueLinksService) ListIssueRelations(pid interface{}, issue int, options ...RequestOptionFunc) ([]*IssueRelation, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/issues/%d/links", PathEscape(project), issue)
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}
var is []*IssueRelation
resp, err := s.client.Do(req, &is)
if err != nil {
return nil, resp, err
}
return is, resp, err
}
// GetIssueLink gets a specific issue link.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/issue_links.html#get-an-issue-link
func (s *IssueLinksService) GetIssueLink(pid interface{}, issue, issueLink int, options ...RequestOptionFunc) (*IssueLink, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/issues/%d/links/%d", PathEscape(project), issue, issueLink)
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}
il := new(IssueLink)
resp, err := s.client.Do(req, il)
if err != nil {
return nil, resp, err
}
return il, resp, err
}
// CreateIssueLinkOptions represents the available CreateIssueLink() options.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/issue_links.html#create-an-issue-link
type CreateIssueLinkOptions struct {
TargetProjectID *string `json:"target_project_id"`
TargetIssueIID *string `json:"target_issue_iid"`
LinkType *string `json:"link_type"`
}
// CreateIssueLink creates a two-way relation between two issues.
// User must be allowed to update both issues in order to succeed.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/issue_links.html#create-an-issue-link
func (s *IssueLinksService) CreateIssueLink(pid interface{}, issue int, opt *CreateIssueLinkOptions, options ...RequestOptionFunc) (*IssueLink, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/issues/%d/links", PathEscape(project), issue)
req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
if err != nil {
return nil, nil, err
}
i := new(IssueLink)
resp, err := s.client.Do(req, &i)
if err != nil {
return nil, resp, err
}
return i, resp, err
}
// DeleteIssueLink deletes an issue link, thus removes the two-way relationship.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/issue_links.html#delete-an-issue-link
func (s *IssueLinksService) DeleteIssueLink(pid interface{}, issue, issueLink int, options ...RequestOptionFunc) (*IssueLink, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/issues/%d/links/%d",
PathEscape(project),
issue,
issueLink)
req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
if err != nil {
return nil, nil, err
}
il := new(IssueLink)
resp, err := s.client.Do(req, &il)
if err != nil {
return nil, resp, err
}
return il, resp, err
}

786
vendor/github.com/xanzy/go-gitlab/issues.go generated vendored Normal file
View File

@ -0,0 +1,786 @@
//
// 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 (
"bytes"
"encoding/json"
"fmt"
"net/http"
"net/url"
"reflect"
"strings"
"time"
)
// IssuesService handles communication with the issue related methods
// of the GitLab API.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/issues.html
type IssuesService struct {
client *Client
timeStats *timeStatsService
}
// IssueAuthor represents a author of the issue.
type IssueAuthor struct {
ID int `json:"id"`
State string `json:"state"`
WebURL string `json:"web_url"`
Name string `json:"name"`
AvatarURL string `json:"avatar_url"`
Username string `json:"username"`
}
// IssueAssignee represents a assignee of the issue.
type IssueAssignee struct {
ID int `json:"id"`
State string `json:"state"`
WebURL string `json:"web_url"`
Name string `json:"name"`
AvatarURL string `json:"avatar_url"`
Username string `json:"username"`
}
// IssueReferences represents references of the issue.
type IssueReferences struct {
Short string `json:"short"`
Relative string `json:"relative"`
Full string `json:"full"`
}
// IssueCloser represents a closer of the issue.
type IssueCloser struct {
ID int `json:"id"`
State string `json:"state"`
WebURL string `json:"web_url"`
Name string `json:"name"`
AvatarURL string `json:"avatar_url"`
Username string `json:"username"`
}
// IssueLinks represents links of the issue.
type IssueLinks struct {
Self string `json:"self"`
Notes string `json:"notes"`
AwardEmoji string `json:"award_emoji"`
Project string `json:"project"`
}
// Issue represents a GitLab issue.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/issues.html
type Issue struct {
ID int `json:"id"`
IID int `json:"iid"`
ExternalID string `json:"external_id"`
State string `json:"state"`
Description string `json:"description"`
HealthStatus string `json:"health_status"`
Author *IssueAuthor `json:"author"`
Milestone *Milestone `json:"milestone"`
ProjectID int `json:"project_id"`
Assignees []*IssueAssignee `json:"assignees"`
Assignee *IssueAssignee `json:"assignee"`
UpdatedAt *time.Time `json:"updated_at"`
ClosedAt *time.Time `json:"closed_at"`
ClosedBy *IssueCloser `json:"closed_by"`
Title string `json:"title"`
CreatedAt *time.Time `json:"created_at"`
MovedToID int `json:"moved_to_id"`
Labels Labels `json:"labels"`
LabelDetails []*LabelDetails `json:"label_details"`
Upvotes int `json:"upvotes"`
Downvotes int `json:"downvotes"`
DueDate *ISOTime `json:"due_date"`
WebURL string `json:"web_url"`
References *IssueReferences `json:"references"`
TimeStats *TimeStats `json:"time_stats"`
Confidential bool `json:"confidential"`
Weight int `json:"weight"`
DiscussionLocked bool `json:"discussion_locked"`
IssueType *string `json:"issue_type,omitempty"`
Subscribed bool `json:"subscribed"`
UserNotesCount int `json:"user_notes_count"`
Links *IssueLinks `json:"_links"`
IssueLinkID int `json:"issue_link_id"`
MergeRequestCount int `json:"merge_requests_count"`
EpicIssueID int `json:"epic_issue_id"`
Epic *Epic `json:"epic"`
Iteration *GroupIteration `json:"iteration"`
TaskCompletionStatus *TasksCompletionStatus `json:"task_completion_status"`
}
func (i Issue) String() string {
return Stringify(i)
}
// UnmarshalJSON implements the json.Unmarshaler interface.
func (i *Issue) UnmarshalJSON(data []byte) error {
type alias Issue
raw := make(map[string]interface{})
err := json.Unmarshal(data, &raw)
if err != nil {
return err
}
if reflect.TypeOf(raw["id"]).Kind() == reflect.String {
raw["external_id"] = raw["id"]
delete(raw, "id")
}
labelDetails, ok := raw["labels"].([]interface{})
if ok && len(labelDetails) > 0 {
// We only want to change anything if we got label details.
if _, ok := labelDetails[0].(map[string]interface{}); ok {
labels := make([]interface{}, len(labelDetails))
for i, details := range labelDetails {
labels[i] = details.(map[string]interface{})["name"]
}
// Set the correct values
raw["labels"] = labels
raw["label_details"] = labelDetails
}
}
data, err = json.Marshal(raw)
if err != nil {
return err
}
return json.Unmarshal(data, (*alias)(i))
}
// Labels is a custom type with specific marshaling characteristics.
type Labels []string
// MarshalJSON implements the json.Marshaler interface.
func (l *Labels) MarshalJSON() ([]byte, error) {
if *l == nil {
return []byte(`null`), nil
}
return json.Marshal(strings.Join(*l, ","))
}
// UnmarshalJSON implements the json.Unmarshaler interface.
func (l *Labels) UnmarshalJSON(data []byte) error {
type alias Labels
if !bytes.HasPrefix(data, []byte("[")) {
data = []byte(fmt.Sprintf("[%s]", string(data)))
}
return json.Unmarshal(data, (*alias)(l))
}
// EncodeValues implements the query.EncodeValues interface
func (l *Labels) EncodeValues(key string, v *url.Values) error {
v.Set(key, strings.Join(*l, ","))
return nil
}
// LabelDetails represents detailed label information.
type LabelDetails struct {
ID int `json:"id"`
Name string `json:"name"`
Color string `json:"color"`
Description string `json:"description"`
DescriptionHTML string `json:"description_html"`
TextColor string `json:"text_color"`
}
// ListIssuesOptions represents the available ListIssues() options.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/issues.html#list-issues
type ListIssuesOptions struct {
ListOptions
State *string `url:"state,omitempty" json:"state,omitempty"`
Labels *Labels `url:"labels,comma,omitempty" json:"labels,omitempty"`
NotLabels *Labels `url:"not[labels],comma,omitempty" json:"not[labels],omitempty"`
WithLabelDetails *bool `url:"with_labels_details,omitempty" json:"with_labels_details,omitempty"`
Milestone *string `url:"milestone,omitempty" json:"milestone,omitempty"`
NotMilestone *string `url:"not[milestone],omitempty" json:"not[milestone],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"`
NotAuthorUsername *string `url:"not[author_username],omitempty" json:"not[author_username],omitempty"`
NotAuthorID *[]int `url:"not[author_id],omitempty" json:"not[author_id],omitempty"`
AssigneeID *AssigneeIDValue `url:"assignee_id,omitempty" json:"assignee_id,omitempty"`
NotAssigneeID *[]int `url:"not[assignee_id],omitempty" json:"not[assignee_id],omitempty"`
AssigneeUsername *string `url:"assignee_username,omitempty" json:"assignee_username,omitempty"`
NotAssigneeUsername *string `url:"not[assignee_username],omitempty" json:"not[assignee_username],omitempty"`
MyReactionEmoji *string `url:"my_reaction_emoji,omitempty" json:"my_reaction_emoji,omitempty"`
NotMyReactionEmoji *[]string `url:"not[my_reaction_emoji],omitempty" json:"not[my_reaction_emoji],omitempty"`
IIDs *[]int `url:"iids[],omitempty" json:"iids,omitempty"`
In *string `url:"in,omitempty" json:"in,omitempty"`
NotIn *string `url:"not[in],omitempty" json:"not[in],omitempty"`
OrderBy *string `url:"order_by,omitempty" json:"order_by,omitempty"`
Sort *string `url:"sort,omitempty" json:"sort,omitempty"`
Search *string `url:"search,omitempty" json:"search,omitempty"`
NotSearch *string `url:"not[search],omitempty" json:"not[search],omitempty"`
CreatedAfter *time.Time `url:"created_after,omitempty" json:"created_after,omitempty"`
CreatedBefore *time.Time `url:"created_before,omitempty" json:"created_before,omitempty"`
DueDate *string `url:"due_date,omitempty" json:"due_date,omitempty"`
UpdatedAfter *time.Time `url:"updated_after,omitempty" json:"updated_after,omitempty"`
UpdatedBefore *time.Time `url:"updated_before,omitempty" json:"updated_before,omitempty"`
Confidential *bool `url:"confidential,omitempty" json:"confidential,omitempty"`
IssueType *string `url:"issue_type,omitempty" json:"issue_type,omitempty"`
IterationID *int `url:"iteration_id,omitempty" json:"iteration_id,omitempty"`
}
// ListIssues gets all issues created by authenticated user. This function
// takes pagination parameters page and per_page to restrict the list of issues.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/issues.html#list-issues
func (s *IssuesService) ListIssues(opt *ListIssuesOptions, options ...RequestOptionFunc) ([]*Issue, *Response, error) {
req, err := s.client.NewRequest(http.MethodGet, "issues", opt, options)
if err != nil {
return nil, nil, err
}
var i []*Issue
resp, err := s.client.Do(req, &i)
if err != nil {
return nil, resp, err
}
return i, resp, err
}
// ListGroupIssuesOptions represents the available ListGroupIssues() options.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/issues.html#list-group-issues
type ListGroupIssuesOptions struct {
ListOptions
State *string `url:"state,omitempty" json:"state,omitempty"`
Labels *Labels `url:"labels,comma,omitempty" json:"labels,omitempty"`
NotLabels *Labels `url:"not[labels],comma,omitempty" json:"not[labels],omitempty"`
WithLabelDetails *bool `url:"with_labels_details,omitempty" json:"with_labels_details,omitempty"`
IIDs *[]int `url:"iids[],omitempty" json:"iids,omitempty"`
Milestone *string `url:"milestone,omitempty" json:"milestone,omitempty"`
NotMilestone *string `url:"not[milestone],omitempty" json:"not[milestone],omitempty"`
Scope *string `url:"scope,omitempty" json:"scope,omitempty"`
AuthorID *int `url:"author_id,omitempty" json:"author_id,omitempty"`
NotAuthorID *[]int `url:"not[author_id],omitempty" json:"not[author_id],omitempty"`
AuthorUsername *string `url:"author_username,omitempty" json:"author_username,omitempty"`
NotAuthorUsername *string `url:"not[author_username],omitempty" json:"not[author_username],omitempty"`
AssigneeID *AssigneeIDValue `url:"assignee_id,omitempty" json:"assignee_id,omitempty"`
NotAssigneeID *[]int `url:"not[assignee_id],omitempty" json:"not[assignee_id],omitempty"`
AssigneeUsername *string `url:"assignee_username,omitempty" json:"assignee_username,omitempty"`
NotAssigneeUsername *string `url:"not[assignee_username],omitempty" json:"not[assignee_username],omitempty"`
MyReactionEmoji *string `url:"my_reaction_emoji,omitempty" json:"my_reaction_emoji,omitempty"`
NotMyReactionEmoji *[]string `url:"not[my_reaction_emoji],omitempty" json:"not[my_reaction_emoji],omitempty"`
OrderBy *string `url:"order_by,omitempty" json:"order_by,omitempty"`
Sort *string `url:"sort,omitempty" json:"sort,omitempty"`
Search *string `url:"search,omitempty" json:"search,omitempty"`
NotSearch *string `url:"not[search],omitempty" json:"not[search],omitempty"`
In *string `url:"in,omitempty" json:"in,omitempty"`
NotIn *string `url:"not[in],omitempty" json:"not[in],omitempty"`
CreatedAfter *time.Time `url:"created_after,omitempty" json:"created_after,omitempty"`
CreatedBefore *time.Time `url:"created_before,omitempty" json:"created_before,omitempty"`
DueDate *string `url:"due_date,omitempty" json:"due_date,omitempty"`
UpdatedAfter *time.Time `url:"updated_after,omitempty" json:"updated_after,omitempty"`
UpdatedBefore *time.Time `url:"updated_before,omitempty" json:"updated_before,omitempty"`
IssueType *string `url:"issue_type,omitempty" json:"issue_type,omitempty"`
IterationID *int `url:"iteration_id,omitempty" json:"iteration_id,omitempty"`
}
// ListGroupIssues gets a list of group issues. This function accepts
// pagination parameters page and per_page to return the list of group issues.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/issues.html#list-group-issues
func (s *IssuesService) ListGroupIssues(pid interface{}, opt *ListGroupIssuesOptions, options ...RequestOptionFunc) ([]*Issue, *Response, error) {
group, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/issues", PathEscape(group))
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
var i []*Issue
resp, err := s.client.Do(req, &i)
if err != nil {
return nil, resp, err
}
return i, resp, err
}
// ListProjectIssuesOptions represents the available ListProjectIssues() options.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/issues.html#list-project-issues
type ListProjectIssuesOptions struct {
ListOptions
IIDs *[]int `url:"iids[],omitempty" json:"iids,omitempty"`
State *string `url:"state,omitempty" json:"state,omitempty"`
Labels *Labels `url:"labels,comma,omitempty" json:"labels,omitempty"`
NotLabels *Labels `url:"not[labels],comma,omitempty" json:"not[labels],omitempty"`
WithLabelDetails *bool `url:"with_labels_details,omitempty" json:"with_labels_details,omitempty"`
Milestone *string `url:"milestone,omitempty" json:"milestone,omitempty"`
NotMilestone *string `url:"not[milestone],omitempty" json:"not[milestone],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"`
NotAuthorUsername *string `url:"not[author_username],omitempty" json:"not[author_username],omitempty"`
NotAuthorID *[]int `url:"not[author_id],omitempty" json:"not[author_id],omitempty"`
AssigneeID *AssigneeIDValue `url:"assignee_id,omitempty" json:"assignee_id,omitempty"`
NotAssigneeID *[]int `url:"not[assignee_id],omitempty" json:"not[assignee_id],omitempty"`
AssigneeUsername *string `url:"assignee_username,omitempty" json:"assignee_username,omitempty"`
NotAssigneeUsername *string `url:"not[assignee_username],omitempty" json:"not[assignee_username],omitempty"`
MyReactionEmoji *string `url:"my_reaction_emoji,omitempty" json:"my_reaction_emoji,omitempty"`
NotMyReactionEmoji *[]string `url:"not[my_reaction_emoji],omitempty" json:"not[my_reaction_emoji],omitempty"`
OrderBy *string `url:"order_by,omitempty" json:"order_by,omitempty"`
Sort *string `url:"sort,omitempty" json:"sort,omitempty"`
Search *string `url:"search,omitempty" json:"search,omitempty"`
In *string `url:"in,omitempty" json:"in,omitempty"`
NotIn *string `url:"not[in],omitempty" json:"not[in],omitempty"`
CreatedAfter *time.Time `url:"created_after,omitempty" json:"created_after,omitempty"`
CreatedBefore *time.Time `url:"created_before,omitempty" json:"created_before,omitempty"`
DueDate *string `url:"due_date,omitempty" json:"due_date,omitempty"`
UpdatedAfter *time.Time `url:"updated_after,omitempty" json:"updated_after,omitempty"`
UpdatedBefore *time.Time `url:"updated_before,omitempty" json:"updated_before,omitempty"`
Confidential *bool `url:"confidential,omitempty" json:"confidential,omitempty"`
IssueType *string `url:"issue_type,omitempty" json:"issue_type,omitempty"`
IterationID *int `url:"iteration_id,omitempty" json:"iteration_id,omitempty"`
}
// ListProjectIssues gets a list of project issues. This function accepts
// pagination parameters page and per_page to return the list of project issues.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/issues.html#list-project-issues
func (s *IssuesService) ListProjectIssues(pid interface{}, opt *ListProjectIssuesOptions, options ...RequestOptionFunc) ([]*Issue, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/issues", PathEscape(project))
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
var i []*Issue
resp, err := s.client.Do(req, &i)
if err != nil {
return nil, resp, err
}
return i, resp, err
}
// GetIssueByID gets a single issue.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/issues.html#single-issue
func (s *IssuesService) GetIssueByID(issue int, options ...RequestOptionFunc) (*Issue, *Response, error) {
u := fmt.Sprintf("issues/%d", issue)
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}
i := new(Issue)
resp, err := s.client.Do(req, i)
if err != nil {
return nil, resp, err
}
return i, resp, err
}
// GetIssue gets a single project issue.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/issues.html#single-project-issue
func (s *IssuesService) GetIssue(pid interface{}, issue int, options ...RequestOptionFunc) (*Issue, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/issues/%d", PathEscape(project), issue)
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}
i := new(Issue)
resp, err := s.client.Do(req, i)
if err != nil {
return nil, resp, err
}
return i, resp, err
}
// CreateIssueOptions represents the available CreateIssue() options.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/issues.html#new-issue
type CreateIssueOptions struct {
IID *int `url:"iid,omitempty" json:"iid,omitempty"`
Title *string `url:"title,omitempty" json:"title,omitempty"`
Description *string `url:"description,omitempty" json:"description,omitempty"`
Confidential *bool `url:"confidential,omitempty" json:"confidential,omitempty"`
AssigneeIDs *[]int `url:"assignee_ids,omitempty" json:"assignee_ids,omitempty"`
MilestoneID *int `url:"milestone_id,omitempty" json:"milestone_id,omitempty"`
Labels *Labels `url:"labels,comma,omitempty" json:"labels,omitempty"`
CreatedAt *time.Time `url:"created_at,omitempty" json:"created_at,omitempty"`
DueDate *ISOTime `url:"due_date,omitempty" json:"due_date,omitempty"`
MergeRequestToResolveDiscussionsOf *int `url:"merge_request_to_resolve_discussions_of,omitempty" json:"merge_request_to_resolve_discussions_of,omitempty"`
DiscussionToResolve *string `url:"discussion_to_resolve,omitempty" json:"discussion_to_resolve,omitempty"`
Weight *int `url:"weight,omitempty" json:"weight,omitempty"`
IssueType *string `url:"issue_type,omitempty" json:"issue_type,omitempty"`
}
// CreateIssue creates a new project issue.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/issues.html#new-issue
func (s *IssuesService) CreateIssue(pid interface{}, opt *CreateIssueOptions, options ...RequestOptionFunc) (*Issue, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/issues", PathEscape(project))
req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
if err != nil {
return nil, nil, err
}
i := new(Issue)
resp, err := s.client.Do(req, i)
if err != nil {
return nil, resp, err
}
return i, resp, err
}
// UpdateIssueOptions represents the available UpdateIssue() options.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/issues.html#edit-issue
type UpdateIssueOptions struct {
Title *string `url:"title,omitempty" json:"title,omitempty"`
Description *string `url:"description,omitempty" json:"description,omitempty"`
Confidential *bool `url:"confidential,omitempty" json:"confidential,omitempty"`
AssigneeIDs *[]int `url:"assignee_ids,omitempty" json:"assignee_ids,omitempty"`
MilestoneID *int `url:"milestone_id,omitempty" json:"milestone_id,omitempty"`
Labels *Labels `url:"labels,comma,omitempty" json:"labels,omitempty"`
AddLabels *Labels `url:"add_labels,comma,omitempty" json:"add_labels,omitempty"`
RemoveLabels *Labels `url:"remove_labels,comma,omitempty" json:"remove_labels,omitempty"`
StateEvent *string `url:"state_event,omitempty" json:"state_event,omitempty"`
UpdatedAt *time.Time `url:"updated_at,omitempty" json:"updated_at,omitempty"`
DueDate *ISOTime `url:"due_date,omitempty" json:"due_date,omitempty"`
Weight *int `url:"weight,omitempty" json:"weight,omitempty"`
DiscussionLocked *bool `url:"discussion_locked,omitempty" json:"discussion_locked,omitempty"`
IssueType *string `url:"issue_type,omitempty" json:"issue_type,omitempty"`
}
// UpdateIssue updates an existing project issue. This function is also used
// to mark an issue as closed.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/issues.html#edit-issues
func (s *IssuesService) UpdateIssue(pid interface{}, issue int, opt *UpdateIssueOptions, options ...RequestOptionFunc) (*Issue, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/issues/%d", PathEscape(project), issue)
req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
if err != nil {
return nil, nil, err
}
i := new(Issue)
resp, err := s.client.Do(req, i)
if err != nil {
return nil, resp, err
}
return i, resp, err
}
// DeleteIssue deletes a single project issue.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/issues.html#delete-an-issue
func (s *IssuesService) DeleteIssue(pid interface{}, issue int, options ...RequestOptionFunc) (*Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("projects/%s/issues/%d", PathEscape(project), issue)
req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}
// MoveIssueOptions represents the available MoveIssue() options.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/issues.html#move-an-issue
type MoveIssueOptions struct {
ToProjectID *int `url:"to_project_id,omitempty" json:"to_project_id,omitempty"`
}
// MoveIssue updates an existing project issue. This function is also used
// to mark an issue as closed.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/issues.html#move-an-issue
func (s *IssuesService) MoveIssue(pid interface{}, issue int, opt *MoveIssueOptions, options ...RequestOptionFunc) (*Issue, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/issues/%d/move", PathEscape(project), issue)
req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
if err != nil {
return nil, nil, err
}
i := new(Issue)
resp, err := s.client.Do(req, i)
if err != nil {
return nil, resp, err
}
return i, resp, err
}
// SubscribeToIssue subscribes the authenticated user to the given issue to
// receive notifications. If the user is already subscribed to the issue, the
// status code 304 is returned.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/issues.html#subscribe-to-an-issue
func (s *IssuesService) SubscribeToIssue(pid interface{}, issue int, options ...RequestOptionFunc) (*Issue, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/issues/%d/subscribe", PathEscape(project), issue)
req, err := s.client.NewRequest(http.MethodPost, u, nil, options)
if err != nil {
return nil, nil, err
}
i := new(Issue)
resp, err := s.client.Do(req, i)
if err != nil {
return nil, resp, err
}
return i, resp, err
}
// UnsubscribeFromIssue unsubscribes the authenticated user from the given
// issue to not receive notifications from that merge request. If the user
// is not subscribed to the issue, status code 304 is returned.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/issues.html#unsubscribe-from-an-issue
func (s *IssuesService) UnsubscribeFromIssue(pid interface{}, issue int, options ...RequestOptionFunc) (*Issue, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/issues/%d/unsubscribe", PathEscape(project), issue)
req, err := s.client.NewRequest(http.MethodPost, u, nil, options)
if err != nil {
return nil, nil, err
}
i := new(Issue)
resp, err := s.client.Do(req, i)
if err != nil {
return nil, resp, err
}
return i, resp, err
}
// CreateTodo creates a todo for the current user for an issue.
// If there already exists a todo for the user on that issue, status code
// 304 is returned.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/issues.html#create-a-to-do-item
func (s *IssuesService) CreateTodo(pid interface{}, issue int, options ...RequestOptionFunc) (*Todo, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/issues/%d/todo", PathEscape(project), issue)
req, err := s.client.NewRequest(http.MethodPost, u, nil, options)
if err != nil {
return nil, nil, err
}
t := new(Todo)
resp, err := s.client.Do(req, t)
if err != nil {
return nil, resp, err
}
return t, resp, err
}
// ListMergeRequestsClosingIssueOptions represents the available
// ListMergeRequestsClosingIssue() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/issues.html#list-merge-requests-that-close-a-particular-issue-on-merge
type ListMergeRequestsClosingIssueOptions ListOptions
// ListMergeRequestsClosingIssue gets all the merge requests that will close
// issue when merged.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/issues.html#list-merge-requests-that-close-a-particular-issue-on-merge
func (s *IssuesService) ListMergeRequestsClosingIssue(pid interface{}, issue int, opt *ListMergeRequestsClosingIssueOptions, options ...RequestOptionFunc) ([]*MergeRequest, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/issues/%d/closed_by", PathEscape(project), issue)
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
var m []*MergeRequest
resp, err := s.client.Do(req, &m)
if err != nil {
return nil, resp, err
}
return m, resp, err
}
// ListMergeRequestsRelatedToIssueOptions represents the available
// ListMergeRequestsRelatedToIssue() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/issues.html#list-merge-requests-related-to-issue
type ListMergeRequestsRelatedToIssueOptions ListOptions
// ListMergeRequestsRelatedToIssue gets all the merge requests that are
// related to the issue
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/issues.html#list-merge-requests-related-to-issue
func (s *IssuesService) ListMergeRequestsRelatedToIssue(pid interface{}, issue int, opt *ListMergeRequestsRelatedToIssueOptions, options ...RequestOptionFunc) ([]*MergeRequest, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/issues/%d/related_merge_requests",
PathEscape(project),
issue,
)
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
var m []*MergeRequest
resp, err := s.client.Do(req, &m)
if err != nil {
return nil, resp, err
}
return m, resp, err
}
// SetTimeEstimate sets the time estimate for a single project issue.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/issues.html#set-a-time-estimate-for-an-issue
func (s *IssuesService) SetTimeEstimate(pid interface{}, issue int, opt *SetTimeEstimateOptions, options ...RequestOptionFunc) (*TimeStats, *Response, error) {
return s.timeStats.setTimeEstimate(pid, "issues", issue, opt, options...)
}
// ResetTimeEstimate resets the time estimate for a single project issue.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/issues.html#reset-the-time-estimate-for-an-issue
func (s *IssuesService) ResetTimeEstimate(pid interface{}, issue int, options ...RequestOptionFunc) (*TimeStats, *Response, error) {
return s.timeStats.resetTimeEstimate(pid, "issues", issue, options...)
}
// AddSpentTime adds spent time for a single project issue.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/issues.html#add-spent-time-for-an-issue
func (s *IssuesService) AddSpentTime(pid interface{}, issue int, opt *AddSpentTimeOptions, options ...RequestOptionFunc) (*TimeStats, *Response, error) {
return s.timeStats.addSpentTime(pid, "issues", issue, opt, options...)
}
// ResetSpentTime resets the spent time for a single project issue.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/issues.html#reset-spent-time-for-an-issue
func (s *IssuesService) ResetSpentTime(pid interface{}, issue int, options ...RequestOptionFunc) (*TimeStats, *Response, error) {
return s.timeStats.resetSpentTime(pid, "issues", issue, options...)
}
// GetTimeSpent gets the spent time for a single project issue.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/issues.html#get-time-tracking-stats
func (s *IssuesService) GetTimeSpent(pid interface{}, issue int, options ...RequestOptionFunc) (*TimeStats, *Response, error) {
return s.timeStats.getTimeSpent(pid, "issues", issue, options...)
}
// GetParticipants gets a list of issue participants.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/issues.html#participants-on-issues
func (s *IssuesService) GetParticipants(pid interface{}, issue int, options ...RequestOptionFunc) ([]*BasicUser, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/issues/%d/participants", PathEscape(project), issue)
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}
var bu []*BasicUser
resp, err := s.client.Do(req, &bu)
if err != nil {
return nil, resp, err
}
return bu, resp, err
}

187
vendor/github.com/xanzy/go-gitlab/issues_statistics.go generated vendored Normal file
View File

@ -0,0 +1,187 @@
//
// 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"
"time"
)
// IssuesStatisticsService handles communication with the issues statistics
// related methods of the GitLab API.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/issues_statistics.html
type IssuesStatisticsService struct {
client *Client
}
// IssuesStatistics represents a GitLab issues statistic.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/issues_statistics.html
type IssuesStatistics struct {
Statistics struct {
Counts struct {
All int `json:"all"`
Closed int `json:"closed"`
Opened int `json:"opened"`
} `json:"counts"`
} `json:"statistics"`
}
func (n IssuesStatistics) String() string {
return Stringify(n)
}
// GetIssuesStatisticsOptions represents the available GetIssuesStatistics() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/issues_statistics.html#get-issues-statistics
type GetIssuesStatisticsOptions struct {
Labels *Labels `url:"labels,omitempty" json:"labels,omitempty"`
Milestone *string `url:"milestone,omitempty" json:"milestone,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"`
AssigneeUsername *[]string `url:"assignee_username,omitempty" json:"assignee_username,omitempty"`
MyReactionEmoji *string `url:"my_reaction_emoji,omitempty" json:"my_reaction_emoji,omitempty"`
IIDs *[]int `url:"iids[],omitempty" json:"iids,omitempty"`
Search *string `url:"search,omitempty" json:"search,omitempty"`
In *string `url:"in,omitempty" json:"in,omitempty"`
CreatedAfter *time.Time `url:"created_after,omitempty" json:"created_after,omitempty"`
CreatedBefore *time.Time `url:"created_before,omitempty" json:"created_before,omitempty"`
UpdatedAfter *time.Time `url:"updated_after,omitempty" json:"updated_after,omitempty"`
UpdatedBefore *time.Time `url:"updated_before,omitempty" json:"updated_before,omitempty"`
Confidential *bool `url:"confidential,omitempty" json:"confidential,omitempty"`
}
// GetIssuesStatistics gets issues statistics on all issues the authenticated
// user has access to.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/issues_statistics.html#get-issues-statistics
func (s *IssuesStatisticsService) GetIssuesStatistics(opt *GetIssuesStatisticsOptions, options ...RequestOptionFunc) (*IssuesStatistics, *Response, error) {
req, err := s.client.NewRequest(http.MethodGet, "issues_statistics", opt, options)
if err != nil {
return nil, nil, err
}
is := new(IssuesStatistics)
resp, err := s.client.Do(req, is)
if err != nil {
return nil, resp, err
}
return is, resp, err
}
// GetGroupIssuesStatisticsOptions represents the available GetGroupIssuesStatistics()
// options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/issues_statistics.html#get-group-issues-statistics
type GetGroupIssuesStatisticsOptions struct {
Labels *Labels `url:"labels,omitempty" json:"labels,omitempty"`
IIDs *[]int `url:"iids[],omitempty" json:"iids,omitempty"`
Milestone *string `url:"milestone,omitempty" json:"milestone,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"`
AssigneeUsername *[]string `url:"assignee_username,omitempty" json:"assignee_username,omitempty"`
MyReactionEmoji *string `url:"my_reaction_emoji,omitempty" json:"my_reaction_emoji,omitempty"`
Search *string `url:"search,omitempty" json:"search,omitempty"`
CreatedAfter *time.Time `url:"created_after,omitempty" json:"created_after,omitempty"`
CreatedBefore *time.Time `url:"created_before,omitempty" json:"created_before,omitempty"`
UpdatedAfter *time.Time `url:"updated_after,omitempty" json:"updated_after,omitempty"`
UpdatedBefore *time.Time `url:"updated_before,omitempty" json:"updated_before,omitempty"`
Confidential *bool `url:"confidential,omitempty" json:"confidential,omitempty"`
}
// GetGroupIssuesStatistics gets issues count statistics for given group.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/issues_statistics.html#get-group-issues-statistics
func (s *IssuesStatisticsService) GetGroupIssuesStatistics(gid interface{}, opt *GetGroupIssuesStatisticsOptions, options ...RequestOptionFunc) (*IssuesStatistics, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/issues_statistics", PathEscape(group))
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
is := new(IssuesStatistics)
resp, err := s.client.Do(req, is)
if err != nil {
return nil, resp, err
}
return is, resp, err
}
// GetProjectIssuesStatisticsOptions represents the available
// GetProjectIssuesStatistics() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/issues_statistics.html#get-project-issues-statistics
type GetProjectIssuesStatisticsOptions struct {
IIDs *[]int `url:"iids[],omitempty" json:"iids,omitempty"`
Labels *Labels `url:"labels,omitempty" json:"labels,omitempty"`
Milestone *string `url:"milestone,omitempty" json:"milestone,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"`
AssigneeUsername *[]string `url:"assignee_username,omitempty" json:"assignee_username,omitempty"`
MyReactionEmoji *string `url:"my_reaction_emoji,omitempty" json:"my_reaction_emoji,omitempty"`
Search *string `url:"search,omitempty" json:"search,omitempty"`
CreatedAfter *time.Time `url:"created_after,omitempty" json:"created_after,omitempty"`
CreatedBefore *time.Time `url:"created_before,omitempty" json:"created_before,omitempty"`
UpdatedAfter *time.Time `url:"updated_after,omitempty" json:"updated_after,omitempty"`
UpdatedBefore *time.Time `url:"updated_before,omitempty" json:"updated_before,omitempty"`
Confidential *bool `url:"confidential,omitempty" json:"confidential,omitempty"`
}
// GetProjectIssuesStatistics gets issues count statistics for given project.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/issues_statistics.html#get-project-issues-statistics
func (s *IssuesStatisticsService) GetProjectIssuesStatistics(pid interface{}, opt *GetProjectIssuesStatisticsOptions, options ...RequestOptionFunc) (*IssuesStatistics, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/issues_statistics", PathEscape(project))
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
is := new(IssuesStatistics)
resp, err := s.client.Do(req, is)
if err != nil {
return nil, resp, err
}
return is, resp, err
}

562
vendor/github.com/xanzy/go-gitlab/jobs.go generated vendored Normal file
View File

@ -0,0 +1,562 @@
//
// Copyright 2021, Arkbriar
//
// 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"
"net/http"
"time"
)
// JobsService handles communication with the ci builds related methods
// of the GitLab API.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/jobs.html
type JobsService struct {
client *Client
}
// Job represents a ci build.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/jobs.html
type Job struct {
Commit *Commit `json:"commit"`
Coverage float64 `json:"coverage"`
AllowFailure bool `json:"allow_failure"`
CreatedAt *time.Time `json:"created_at"`
StartedAt *time.Time `json:"started_at"`
FinishedAt *time.Time `json:"finished_at"`
Duration float64 `json:"duration"`
QueuedDuration float64 `json:"queued_duration"`
ArtifactsExpireAt *time.Time `json:"artifacts_expire_at"`
TagList []string `json:"tag_list"`
ID int `json:"id"`
Name string `json:"name"`
Pipeline struct {
ID int `json:"id"`
ProjectID int `json:"project_id"`
Ref string `json:"ref"`
Sha string `json:"sha"`
Status string `json:"status"`
} `json:"pipeline"`
Ref string `json:"ref"`
Artifacts []struct {
FileType string `json:"file_type"`
Filename string `json:"filename"`
Size int `json:"size"`
FileFormat string `json:"file_format"`
} `json:"artifacts"`
ArtifactsFile struct {
Filename string `json:"filename"`
Size int `json:"size"`
} `json:"artifacts_file"`
Runner struct {
ID int `json:"id"`
Description string `json:"description"`
Active bool `json:"active"`
IsShared bool `json:"is_shared"`
Name string `json:"name"`
} `json:"runner"`
Stage string `json:"stage"`
Status string `json:"status"`
FailureReason string `json:"failure_reason"`
Tag bool `json:"tag"`
WebURL string `json:"web_url"`
Project *Project `json:"project"`
User *User `json:"user"`
}
// Bridge represents a pipeline bridge.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/jobs.html#list-pipeline-bridges
type Bridge struct {
Commit *Commit `json:"commit"`
Coverage float64 `json:"coverage"`
AllowFailure bool `json:"allow_failure"`
CreatedAt *time.Time `json:"created_at"`
StartedAt *time.Time `json:"started_at"`
FinishedAt *time.Time `json:"finished_at"`
Duration float64 `json:"duration"`
ID int `json:"id"`
Name string `json:"name"`
Pipeline PipelineInfo `json:"pipeline"`
Ref string `json:"ref"`
Stage string `json:"stage"`
Status string `json:"status"`
Tag bool `json:"tag"`
WebURL string `json:"web_url"`
User *User `json:"user"`
DownstreamPipeline *PipelineInfo `json:"downstream_pipeline"`
}
// ListJobsOptions represents the available ListProjectJobs() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/jobs.html#list-project-jobs
type ListJobsOptions struct {
ListOptions
Scope *[]BuildStateValue `url:"scope[],omitempty" json:"scope,omitempty"`
IncludeRetried *bool `url:"include_retried,omitempty" json:"include_retried,omitempty"`
}
// ListProjectJobs gets a list of jobs in a project.
//
// The scope of jobs to show, one or array of: created, pending, running,
// failed, success, canceled, skipped; showing all jobs if none provided
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/jobs.html#list-project-jobs
func (s *JobsService) ListProjectJobs(pid interface{}, opts *ListJobsOptions, options ...RequestOptionFunc) ([]*Job, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/jobs", PathEscape(project))
req, err := s.client.NewRequest(http.MethodGet, u, opts, options)
if err != nil {
return nil, nil, err
}
var jobs []*Job
resp, err := s.client.Do(req, &jobs)
if err != nil {
return nil, resp, err
}
return jobs, resp, err
}
// ListPipelineJobs gets a list of jobs for specific pipeline in a
// project. If the pipeline ID is not found, it will respond with 404.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/jobs.html#list-pipeline-jobs
func (s *JobsService) ListPipelineJobs(pid interface{}, pipelineID int, opts *ListJobsOptions, options ...RequestOptionFunc) ([]*Job, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/pipelines/%d/jobs", PathEscape(project), pipelineID)
req, err := s.client.NewRequest(http.MethodGet, u, opts, options)
if err != nil {
return nil, nil, err
}
var jobs []*Job
resp, err := s.client.Do(req, &jobs)
if err != nil {
return nil, resp, err
}
return jobs, resp, err
}
// ListPipelineBridges gets a list of bridges for specific pipeline in a
// project.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/jobs.html#list-pipeline-jobs
func (s *JobsService) ListPipelineBridges(pid interface{}, pipelineID int, opts *ListJobsOptions, options ...RequestOptionFunc) ([]*Bridge, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/pipelines/%d/bridges", PathEscape(project), pipelineID)
req, err := s.client.NewRequest(http.MethodGet, u, opts, options)
if err != nil {
return nil, nil, err
}
var bridges []*Bridge
resp, err := s.client.Do(req, &bridges)
if err != nil {
return nil, resp, err
}
return bridges, resp, err
}
// GetJobTokensJobOptions represents the available GetJobTokensJob() options.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/jobs.html#get-job-tokens-job
type GetJobTokensJobOptions struct {
JobToken *string `url:"job_token,omitempty" json:"job_token,omitempty"`
}
// GetJobTokensJob retrieves the job that generated a job token.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/jobs.html#get-job-tokens-job
func (s *JobsService) GetJobTokensJob(opts *GetJobTokensJobOptions, options ...RequestOptionFunc) (*Job, *Response, error) {
req, err := s.client.NewRequest(http.MethodGet, "job", opts, options)
if err != nil {
return nil, nil, err
}
job := new(Job)
resp, err := s.client.Do(req, job)
if err != nil {
return nil, resp, err
}
return job, resp, err
}
// GetJob gets a single job of a project.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/jobs.html#get-a-single-job
func (s *JobsService) GetJob(pid interface{}, jobID int, options ...RequestOptionFunc) (*Job, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/jobs/%d", PathEscape(project), jobID)
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}
job := new(Job)
resp, err := s.client.Do(req, job)
if err != nil {
return nil, resp, err
}
return job, resp, err
}
// GetJobArtifacts get jobs artifacts of a project
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/job_artifacts.html#get-job-artifacts
func (s *JobsService) GetJobArtifacts(pid interface{}, jobID int, options ...RequestOptionFunc) (*bytes.Reader, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/jobs/%d/artifacts", PathEscape(project), jobID)
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}
artifactsBuf := new(bytes.Buffer)
resp, err := s.client.Do(req, artifactsBuf)
if err != nil {
return nil, resp, err
}
return bytes.NewReader(artifactsBuf.Bytes()), resp, err
}
// DownloadArtifactsFileOptions represents the available DownloadArtifactsFile()
// options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/job_artifacts.html#download-the-artifacts-archive
type DownloadArtifactsFileOptions struct {
Job *string `url:"job" json:"job"`
}
// DownloadArtifactsFile download the artifacts file from the given
// reference name and job provided the job finished successfully.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/job_artifacts.html#download-the-artifacts-archive
func (s *JobsService) DownloadArtifactsFile(pid interface{}, refName string, opt *DownloadArtifactsFileOptions, options ...RequestOptionFunc) (*bytes.Reader, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/jobs/artifacts/%s/download", PathEscape(project), refName)
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
artifactsBuf := new(bytes.Buffer)
resp, err := s.client.Do(req, artifactsBuf)
if err != nil {
return nil, resp, err
}
return bytes.NewReader(artifactsBuf.Bytes()), resp, err
}
// DownloadSingleArtifactsFile download a file from the artifacts from the
// given reference name and job provided the job finished successfully.
// Only a single file is going to be extracted from the archive and streamed
// to a client.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/job_artifacts.html#download-a-single-artifact-file-by-job-id
func (s *JobsService) DownloadSingleArtifactsFile(pid interface{}, jobID int, artifactPath string, options ...RequestOptionFunc) (*bytes.Reader, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf(
"projects/%s/jobs/%d/artifacts/%s",
PathEscape(project),
jobID,
artifactPath,
)
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}
artifactBuf := new(bytes.Buffer)
resp, err := s.client.Do(req, artifactBuf)
if err != nil {
return nil, resp, err
}
return bytes.NewReader(artifactBuf.Bytes()), resp, err
}
// DownloadSingleArtifactsFile download a single artifact file for a specific
// job of the latest successful pipeline for the given reference name from
// inside the jobs artifacts archive. The file is extracted from the archive
// and streamed to the client.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/job_artifacts.html#download-a-single-artifact-file-from-specific-tag-or-branch
func (s *JobsService) DownloadSingleArtifactsFileByTagOrBranch(pid interface{}, refName string, artifactPath string, opt *DownloadArtifactsFileOptions, options ...RequestOptionFunc) (*bytes.Reader, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf(
"projects/%s/jobs/artifacts/%s/raw/%s",
PathEscape(project),
PathEscape(refName),
artifactPath,
)
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
artifactBuf := new(bytes.Buffer)
resp, err := s.client.Do(req, artifactBuf)
if err != nil {
return nil, resp, err
}
return bytes.NewReader(artifactBuf.Bytes()), resp, err
}
// GetTraceFile gets a trace of a specific job of a project
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/jobs.html#get-a-log-file
func (s *JobsService) GetTraceFile(pid interface{}, jobID int, options ...RequestOptionFunc) (*bytes.Reader, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/jobs/%d/trace", PathEscape(project), jobID)
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}
traceBuf := new(bytes.Buffer)
resp, err := s.client.Do(req, traceBuf)
if err != nil {
return nil, resp, err
}
return bytes.NewReader(traceBuf.Bytes()), resp, err
}
// CancelJob cancels a single job of a project.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/jobs.html#cancel-a-job
func (s *JobsService) CancelJob(pid interface{}, jobID int, options ...RequestOptionFunc) (*Job, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/jobs/%d/cancel", PathEscape(project), jobID)
req, err := s.client.NewRequest(http.MethodPost, u, nil, options)
if err != nil {
return nil, nil, err
}
job := new(Job)
resp, err := s.client.Do(req, job)
if err != nil {
return nil, resp, err
}
return job, resp, err
}
// RetryJob retries a single job of a project
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/jobs.html#retry-a-job
func (s *JobsService) RetryJob(pid interface{}, jobID int, options ...RequestOptionFunc) (*Job, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/jobs/%d/retry", PathEscape(project), jobID)
req, err := s.client.NewRequest(http.MethodPost, u, nil, options)
if err != nil {
return nil, nil, err
}
job := new(Job)
resp, err := s.client.Do(req, job)
if err != nil {
return nil, resp, err
}
return job, resp, err
}
// EraseJob erases a single job of a project, removes a job
// artifacts and a job trace.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/jobs.html#erase-a-job
func (s *JobsService) EraseJob(pid interface{}, jobID int, options ...RequestOptionFunc) (*Job, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/jobs/%d/erase", PathEscape(project), jobID)
req, err := s.client.NewRequest(http.MethodPost, u, nil, options)
if err != nil {
return nil, nil, err
}
job := new(Job)
resp, err := s.client.Do(req, job)
if err != nil {
return nil, resp, err
}
return job, resp, err
}
// KeepArtifacts prevents artifacts from being deleted when
// expiration is set.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/job_artifacts.html#keep-artifacts
func (s *JobsService) KeepArtifacts(pid interface{}, jobID int, options ...RequestOptionFunc) (*Job, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/jobs/%d/artifacts/keep", PathEscape(project), jobID)
req, err := s.client.NewRequest(http.MethodPost, u, nil, options)
if err != nil {
return nil, nil, err
}
job := new(Job)
resp, err := s.client.Do(req, job)
if err != nil {
return nil, resp, err
}
return job, resp, err
}
// PlayJobOptions represents the available PlayJob() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/jobs.html#run-a-job
type PlayJobOptions struct {
JobVariablesAttributes *[]*JobVariableOptions `url:"job_variables_attributes,omitempty" json:"job_variables_attributes,omitempty"`
}
// JobVariableOptions represents a single job variable.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/jobs.html#run-a-job
type JobVariableOptions struct {
Key *string `url:"key,omitempty" json:"key,omitempty"`
Value *string `url:"value,omitempty" json:"value,omitempty"`
VariableType *string `url:"variable_type,omitempty" json:"variable_type,omitempty"`
}
// PlayJob triggers a manual action to start a job.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/jobs.html#run-a-job
func (s *JobsService) PlayJob(pid interface{}, jobID int, opt *PlayJobOptions, options ...RequestOptionFunc) (*Job, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/jobs/%d/play", PathEscape(project), jobID)
req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
if err != nil {
return nil, nil, err
}
job := new(Job)
resp, err := s.client.Do(req, job)
if err != nil {
return nil, resp, err
}
return job, resp, err
}
// DeleteArtifacts delete artifacts of a job
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/job_artifacts.html#delete-job-artifacts
func (s *JobsService) DeleteArtifacts(pid interface{}, jobID int, options ...RequestOptionFunc) (*Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("projects/%s/jobs/%d/artifacts", PathEscape(project), jobID)
req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}

66
vendor/github.com/xanzy/go-gitlab/keys.go generated vendored Normal file
View File

@ -0,0 +1,66 @@
//
// Copyright 2021, Patrick Webster
//
// 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"
"time"
)
// KeysService handles communication with the
// keys related methods of the GitLab API.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/keys.html
type KeysService struct {
client *Client
}
// Key represents a GitLab user's SSH key.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/keys.html
type Key struct {
ID int `json:"id"`
Title string `json:"title"`
Key string `json:"key"`
CreatedAt *time.Time `json:"created_at"`
User User `json:"user"`
}
// GetKeyWithUser gets a single key by id along with the associated
// user information.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/keys.html#get-ssh-key-with-user-by-id-of-an-ssh-key
func (s *KeysService) GetKeyWithUser(key int, options ...RequestOptionFunc) (*Key, *Response, error) {
u := fmt.Sprintf("keys/%d", key)
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}
k := new(Key)
resp, err := s.client.Do(req, k)
if err != nil {
return nil, resp, err
}
return k, resp, err
}

309
vendor/github.com/xanzy/go-gitlab/labels.go generated vendored Normal file
View File

@ -0,0 +1,309 @@
//
// 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 (
"encoding/json"
"fmt"
"net/http"
)
// LabelsService handles communication with the label related methods of the
// GitLab API.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/labels.html
type LabelsService struct {
client *Client
}
// Label represents a GitLab label.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/labels.html
type Label struct {
ID int `json:"id"`
Name string `json:"name"`
Color string `json:"color"`
TextColor string `json:"text_color"`
Description string `json:"description"`
OpenIssuesCount int `json:"open_issues_count"`
ClosedIssuesCount int `json:"closed_issues_count"`
OpenMergeRequestsCount int `json:"open_merge_requests_count"`
Subscribed bool `json:"subscribed"`
Priority int `json:"priority"`
IsProjectLabel bool `json:"is_project_label"`
}
// UnmarshalJSON implements the json.Unmarshaler interface.
func (l *Label) UnmarshalJSON(data []byte) error {
type alias Label
if err := json.Unmarshal(data, (*alias)(l)); err != nil {
return err
}
if l.Name == "" {
var raw map[string]interface{}
if err := json.Unmarshal(data, &raw); err != nil {
return err
}
if title, ok := raw["title"].(string); ok {
l.Name = title
}
}
return nil
}
func (l Label) String() string {
return Stringify(l)
}
// ListLabelsOptions represents the available ListLabels() options.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/labels.html#list-labels
type ListLabelsOptions struct {
ListOptions
WithCounts *bool `url:"with_counts,omitempty" json:"with_counts,omitempty"`
IncludeAncestorGroups *bool `url:"include_ancestor_groups,omitempty" json:"include_ancestor_groups,omitempty"`
Search *string `url:"search,omitempty" json:"search,omitempty"`
}
// ListLabels gets all labels for given project.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/labels.html#list-labels
func (s *LabelsService) ListLabels(pid interface{}, opt *ListLabelsOptions, options ...RequestOptionFunc) ([]*Label, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/labels", PathEscape(project))
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
var l []*Label
resp, err := s.client.Do(req, &l)
if err != nil {
return nil, resp, err
}
return l, resp, err
}
// GetLabel get a single label for a given project.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/labels.html#get-a-single-project-label
func (s *LabelsService) GetLabel(pid interface{}, labelID interface{}, options ...RequestOptionFunc) (*Label, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
label, err := parseID(labelID)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/labels/%s", PathEscape(project), PathEscape(label))
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}
var l *Label
resp, err := s.client.Do(req, &l)
if err != nil {
return nil, resp, err
}
return l, resp, err
}
// CreateLabelOptions represents the available CreateLabel() options.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/labels.html#create-a-new-label
type CreateLabelOptions struct {
Name *string `url:"name,omitempty" json:"name,omitempty"`
Color *string `url:"color,omitempty" json:"color,omitempty"`
Description *string `url:"description,omitempty" json:"description,omitempty"`
Priority *int `url:"priority,omitempty" json:"priority,omitempty"`
}
// CreateLabel creates a new label for given repository with given name and
// color.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/labels.html#create-a-new-label
func (s *LabelsService) CreateLabel(pid interface{}, opt *CreateLabelOptions, options ...RequestOptionFunc) (*Label, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/labels", PathEscape(project))
req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
if err != nil {
return nil, nil, err
}
l := new(Label)
resp, err := s.client.Do(req, l)
if err != nil {
return nil, resp, err
}
return l, resp, err
}
// DeleteLabelOptions represents the available DeleteLabel() options.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/labels.html#delete-a-label
type DeleteLabelOptions struct {
Name *string `url:"name,omitempty" json:"name,omitempty"`
}
// DeleteLabel deletes a label given by its name.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/labels.html#delete-a-label
func (s *LabelsService) DeleteLabel(pid interface{}, opt *DeleteLabelOptions, options ...RequestOptionFunc) (*Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("projects/%s/labels", PathEscape(project))
req, err := s.client.NewRequest(http.MethodDelete, u, opt, options)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}
// UpdateLabelOptions represents the available UpdateLabel() options.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/labels.html#edit-an-existing-label
type UpdateLabelOptions struct {
Name *string `url:"name,omitempty" json:"name,omitempty"`
NewName *string `url:"new_name,omitempty" json:"new_name,omitempty"`
Color *string `url:"color,omitempty" json:"color,omitempty"`
Description *string `url:"description,omitempty" json:"description,omitempty"`
Priority *int `url:"priority,omitempty" json:"priority,omitempty"`
}
// UpdateLabel updates an existing label with new name or now color. At least
// one parameter is required, to update the label.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/labels.html#edit-an-existing-label
func (s *LabelsService) UpdateLabel(pid interface{}, opt *UpdateLabelOptions, options ...RequestOptionFunc) (*Label, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/labels", PathEscape(project))
req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
if err != nil {
return nil, nil, err
}
l := new(Label)
resp, err := s.client.Do(req, l)
if err != nil {
return nil, resp, err
}
return l, resp, err
}
// SubscribeToLabel subscribes the authenticated user to a label to receive
// notifications. If the user is already subscribed to the label, the status
// code 304 is returned.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/labels.html#subscribe-to-a-label
func (s *LabelsService) SubscribeToLabel(pid interface{}, labelID interface{}, options ...RequestOptionFunc) (*Label, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
label, err := parseID(labelID)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/labels/%s/subscribe", PathEscape(project), PathEscape(label))
req, err := s.client.NewRequest(http.MethodPost, u, nil, options)
if err != nil {
return nil, nil, err
}
l := new(Label)
resp, err := s.client.Do(req, l)
if err != nil {
return nil, resp, err
}
return l, resp, err
}
// UnsubscribeFromLabel unsubscribes the authenticated user from a label to not
// receive notifications from it. If the user is not subscribed to the label, the
// status code 304 is returned.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/labels.html#unsubscribe-from-a-label
func (s *LabelsService) UnsubscribeFromLabel(pid interface{}, labelID interface{}, options ...RequestOptionFunc) (*Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, err
}
label, err := parseID(labelID)
if err != nil {
return nil, err
}
u := fmt.Sprintf("projects/%s/labels/%s/unsubscribe", PathEscape(project), PathEscape(label))
req, err := s.client.NewRequest(http.MethodPost, u, nil, options)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}
// PromoteLabel Promotes a project label to a group label.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/labels.html#promote-a-project-label-to-a-group-label
func (s *LabelsService) PromoteLabel(pid interface{}, labelID interface{}, options ...RequestOptionFunc) (*Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, err
}
label, err := parseID(labelID)
if err != nil {
return nil, err
}
u := fmt.Sprintf("projects/%s/labels/%s/promote", PathEscape(project), PathEscape(label))
req, err := s.client.NewRequest(http.MethodPut, u, nil, options)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}

128
vendor/github.com/xanzy/go-gitlab/license.go generated vendored Normal file
View File

@ -0,0 +1,128 @@
//
// Copyright 2021, Patrick Webster
//
// 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"
"time"
)
// LicenseService handles communication with the license
// related methods of the GitLab API.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/license.html
type LicenseService struct {
client *Client
}
// License represents a GitLab license.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/license.html
type License struct {
ID int `json:"id"`
Plan string `json:"plan"`
CreatedAt *time.Time `json:"created_at"`
StartsAt *ISOTime `json:"starts_at"`
ExpiresAt *ISOTime `json:"expires_at"`
HistoricalMax int `json:"historical_max"`
MaximumUserCount int `json:"maximum_user_count"`
Expired bool `json:"expired"`
Overage int `json:"overage"`
UserLimit int `json:"user_limit"`
ActiveUsers int `json:"active_users"`
Licensee struct {
Name string `json:"Name"`
Company string `json:"Company"`
Email string `json:"Email"`
} `json:"licensee"`
// Add on codes that may occur in legacy licenses that don't have a plan yet.
// https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/app/models/license.rb
AddOns struct {
GitLabAuditorUser int `json:"GitLab_Auditor_User"`
GitLabDeployBoard int `json:"GitLab_DeployBoard"`
GitLabFileLocks int `json:"GitLab_FileLocks"`
GitLabGeo int `json:"GitLab_Geo"`
GitLabServiceDesk int `json:"GitLab_ServiceDesk"`
} `json:"add_ons"`
}
func (l License) String() string {
return Stringify(l)
}
// GetLicense retrieves information about the current license.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/license.html#retrieve-information-about-the-current-license
func (s *LicenseService) GetLicense(options ...RequestOptionFunc) (*License, *Response, error) {
req, err := s.client.NewRequest(http.MethodGet, "license", nil, options)
if err != nil {
return nil, nil, err
}
l := new(License)
resp, err := s.client.Do(req, l)
if err != nil {
return nil, resp, err
}
return l, resp, err
}
// AddLicenseOptions represents the available AddLicense() options.
//
// https://docs.gitlab.com/ee/api/license.html#add-a-new-license
type AddLicenseOptions struct {
License *string `url:"license" json:"license"`
}
// AddLicense adds a new license.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/license.html#add-a-new-license
func (s *LicenseService) AddLicense(opt *AddLicenseOptions, options ...RequestOptionFunc) (*License, *Response, error) {
req, err := s.client.NewRequest(http.MethodPost, "license", opt, options)
if err != nil {
return nil, nil, err
}
l := new(License)
resp, err := s.client.Do(req, l)
if err != nil {
return nil, resp, err
}
return l, resp, err
}
// DeleteLicense deletes an existing license.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/license.html#delete-a-license
func (s *LicenseService) DeleteLicense(licenseID int, options ...RequestOptionFunc) (*Response, error) {
u := fmt.Sprintf("license/%d", licenseID)
req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}

109
vendor/github.com/xanzy/go-gitlab/license_templates.go generated vendored Normal file
View File

@ -0,0 +1,109 @@
//
// 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"
)
// LicenseTemplate represents a license template.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/templates/licenses.html
type LicenseTemplate struct {
Key string `json:"key"`
Name string `json:"name"`
Nickname string `json:"nickname"`
Featured bool `json:"featured"`
HTMLURL string `json:"html_url"`
SourceURL string `json:"source_url"`
Description string `json:"description"`
Conditions []string `json:"conditions"`
Permissions []string `json:"permissions"`
Limitations []string `json:"limitations"`
Content string `json:"content"`
}
// LicenseTemplatesService handles communication with the license templates
// related methods of the GitLab API.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/templates/licenses.html
type LicenseTemplatesService struct {
client *Client
}
// ListLicenseTemplatesOptions represents the available
// ListLicenseTemplates() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/templates/licenses.html#list-license-templates
type ListLicenseTemplatesOptions struct {
ListOptions
Popular *bool `url:"popular,omitempty" json:"popular,omitempty"`
}
// ListLicenseTemplates get all license templates.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/templates/licenses.html#list-license-templates
func (s *LicenseTemplatesService) ListLicenseTemplates(opt *ListLicenseTemplatesOptions, options ...RequestOptionFunc) ([]*LicenseTemplate, *Response, error) {
req, err := s.client.NewRequest(http.MethodGet, "templates/licenses", opt, options)
if err != nil {
return nil, nil, err
}
var lts []*LicenseTemplate
resp, err := s.client.Do(req, &lts)
if err != nil {
return nil, resp, err
}
return lts, resp, err
}
// GetLicenseTemplateOptions represents the available
// GetLicenseTemplate() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/templates/licenses.html#single-license-template
type GetLicenseTemplateOptions struct {
Project *string `url:"project,omitempty" json:"project,omitempty"`
Fullname *string `url:"fullname,omitempty" json:"fullname,omitempty"`
}
// GetLicenseTemplate get a single license template. You can pass parameters
// to replace the license placeholder.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/templates/licenses.html#single-license-template
func (s *LicenseTemplatesService) GetLicenseTemplate(template string, opt *GetLicenseTemplateOptions, options ...RequestOptionFunc) (*LicenseTemplate, *Response, error) {
u := fmt.Sprintf("templates/licenses/%s", template)
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
lt := new(LicenseTemplate)
resp, err := s.client.Do(req, lt)
if err != nil {
return nil, resp, err
}
return lt, resp, err
}

Some files were not shown because too many files have changed in this diff Show More