mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-30 14:09:42 -05:00
9a5e628a7e
* Add Attachment API * repos/:owner/:repo/releases (add attachments) * repos/:owner/:repo/releases/:id (add attachments) * repos/:owner/:repo/releases/:id/attachments * repos/:owner/:repo/releases/:id/attachments/:attachment_id Signed-off-by: Jonas Franz <info@jonasfranz.de> * Add unit tests for new attachment functions Fix comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * fix lint * Update vendor.json Signed-off-by: Jonas Franz <info@jonasfranz.software> * remove version of sdk Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix unit tests Add missing license header Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add CreateReleaseAttachment Add EditReleaseAttachment Add DeleteReleaseAttachment Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add filename query parameter for choosing another name for an attachment Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix order of imports Signed-off-by: Jonas Franz <info@jonasfranz.software> * Restricting updatable attachment columns Signed-off-by: Jonas Franz <info@jonasfranz.software> * gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update go-sdk Replace Attachments with Assets Signed-off-by: Jonas Franz <info@jonasfranz.de> * Update go-sdk Signed-off-by: Jonas Franz <info@jonasfranz.de> * Updating go-sdk and regenerating swagger Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add missing file of go-sdk Signed-off-by: Jonas Franz <info@jonasfranz.software> * Change origin of code.gitea.io/sdk to code.gitea.io/sdk Update code.gitea.io/sdk Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update swagger Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update updateAttachment
80 lines
2.5 KiB
Go
80 lines
2.5 KiB
Go
// Copyright 2017 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"
|
|
"time"
|
|
)
|
|
|
|
// GPGKey a user GPG key to sign commit and tag in repository
|
|
type GPGKey struct {
|
|
ID int64 `json:"id"`
|
|
PrimaryKeyID string `json:"primary_key_id"`
|
|
KeyID string `json:"key_id"`
|
|
PublicKey string `json:"public_key"`
|
|
Emails []*GPGKeyEmail `json:"emails"`
|
|
SubsKey []*GPGKey `json:"subkeys"`
|
|
CanSign bool `json:"can_sign"`
|
|
CanEncryptComms bool `json:"can_encrypt_comms"`
|
|
CanEncryptStorage bool `json:"can_encrypt_storage"`
|
|
CanCertify bool `json:"can_certify"`
|
|
// swagger:strfmt date-time
|
|
Created time.Time `json:"created_at,omitempty"`
|
|
// swagger:strfmt date-time
|
|
Expires time.Time `json:"expires_at,omitempty"`
|
|
}
|
|
|
|
// GPGKeyEmail an email attached to a GPGKey
|
|
// swagger:model GPGKeyEmail
|
|
type GPGKeyEmail struct {
|
|
Email string `json:"email"`
|
|
Verified bool `json:"verified"`
|
|
}
|
|
|
|
// CreateGPGKeyOption options create user GPG key
|
|
type CreateGPGKeyOption struct {
|
|
// An armored GPG key to add
|
|
//
|
|
// required: true
|
|
// unique: true
|
|
ArmoredKey string `json:"armored_public_key" binding:"Required"`
|
|
}
|
|
|
|
// ListGPGKeys list all the GPG keys of the user
|
|
func (c *Client) ListGPGKeys(user string) ([]*GPGKey, error) {
|
|
keys := make([]*GPGKey, 0, 10)
|
|
return keys, c.getParsedResponse("GET", fmt.Sprintf("/users/%s/gpg_keys", user), nil, nil, &keys)
|
|
}
|
|
|
|
// ListMyGPGKeys list all the GPG keys of current user
|
|
func (c *Client) ListMyGPGKeys() ([]*GPGKey, error) {
|
|
keys := make([]*GPGKey, 0, 10)
|
|
return keys, c.getParsedResponse("GET", "/user/gpg_keys", nil, nil, &keys)
|
|
}
|
|
|
|
// GetGPGKey get current user's GPG key by key id
|
|
func (c *Client) GetGPGKey(keyID int64) (*GPGKey, error) {
|
|
key := new(GPGKey)
|
|
return key, c.getParsedResponse("GET", fmt.Sprintf("/user/gpg_keys/%d", keyID), nil, nil, &key)
|
|
}
|
|
|
|
// CreateGPGKey create GPG key with options
|
|
func (c *Client) CreateGPGKey(opt CreateGPGKeyOption) (*GPGKey, error) {
|
|
body, err := json.Marshal(&opt)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
key := new(GPGKey)
|
|
return key, c.getParsedResponse("POST", "/user/gpg_keys", jsonHeader, bytes.NewReader(body), key)
|
|
}
|
|
|
|
// DeleteGPGKey delete GPG key with key id
|
|
func (c *Client) DeleteGPGKey(keyID int64) error {
|
|
_, err := c.getResponse("DELETE", fmt.Sprintf("/user/gpg_keys/%d", keyID), nil, nil)
|
|
return err
|
|
}
|