mirror of
https://github.com/gabrie30/ghorg.git
synced 2025-08-12 17:27:13 +02:00
Bumps code.gitea.io/sdk/gitea from 0.18.0 to 0.19.0. --- updated-dependencies: - dependency-name: code.gitea.io/sdk/gitea dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
67 lines
1.9 KiB
Go
67 lines
1.9 KiB
Go
// Copyright 2024 The Gitea Authors. All rights reserved.
|
|
// Use of this source code is governed by a MIT-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package gitea
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
"net/url"
|
|
)
|
|
|
|
// ListRepoActionSecretOption list RepoActionSecret options
|
|
type ListRepoActionSecretOption struct {
|
|
ListOptions
|
|
}
|
|
|
|
// ListRepoActionSecret list a repository's secrets
|
|
func (c *Client) ListRepoActionSecret(user, repo string, opt ListRepoActionSecretOption) ([]*Secret, *Response, error) {
|
|
if err := escapeValidatePathSegments(&user, &repo); err != nil {
|
|
return nil, nil, err
|
|
}
|
|
opt.setDefaults()
|
|
secrets := make([]*Secret, 0, opt.PageSize)
|
|
|
|
link, _ := url.Parse(fmt.Sprintf("/repos/%s/%s/actions/secrets", user, repo))
|
|
link.RawQuery = opt.getURLQuery().Encode()
|
|
resp, err := c.getParsedResponse("GET", link.String(), jsonHeader, nil, &secrets)
|
|
return secrets, resp, err
|
|
}
|
|
|
|
// CreateRepoActionSecret creates a secret for the specified repository in the Gitea Actions.
|
|
// It takes the organization name and the secret options as parameters.
|
|
// The function returns the HTTP response and an error, if any.
|
|
func (c *Client) CreateRepoActionSecret(user, repo string, opt CreateSecretOption) (*Response, error) {
|
|
if err := escapeValidatePathSegments(&user, &repo); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := (&opt).Validate(); err != nil {
|
|
return nil, err
|
|
}
|
|
body, err := json.Marshal(&opt)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
status, resp, err := c.getStatusCode("PUT", fmt.Sprintf("/repos/%s/%s/actions/secrets/%s", user, repo, opt.Name), jsonHeader, bytes.NewReader(body))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
switch status {
|
|
case http.StatusCreated:
|
|
return resp, nil
|
|
case http.StatusNoContent:
|
|
return resp, nil
|
|
case http.StatusNotFound:
|
|
return resp, fmt.Errorf("forbidden")
|
|
case http.StatusBadRequest:
|
|
return resp, fmt.Errorf("bad request")
|
|
default:
|
|
return resp, fmt.Errorf("unexpected Status: %d", status)
|
|
}
|
|
}
|