mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-18 11:27:59 +01:00
49b1948cb1
* first draft
* update gitea sdk to 9e280adb4da
* adapt feat of updated sdk
* releases now works
* break the Reactions loop
* use convertGiteaLabel
* fix endless loop because paggination is not supported there !!!
* rename gitea local uploader files
* pagination can bite you in the ass
* Version Checks
* lint
* docs
* rename gitea sdk import to miss future conficts
* go-swagger: dont scan the sdk structs
* make sure gitea can shutdown gracefully
* make GetPullRequests and GetIssues similar
* rm useles
* Add Test: started ...
* ... add tests ...
* Add tests and Fixing things
* Workaround missing SHA
* Adapt: Ensure that all migration requests are cancellable
(714ab71ddc
)
* LINT: fix misspells in test set
* adapt ListMergeRequestAwardEmoji
* update sdk
* Return error when creating giteadownloader failed
* update sdk
* adapt new sdk
* adopt new features
* check version before err
* adapt: 'migrate service type switch page'
* optimize
* Fix DefaultBranch
* impruve
* handle subPath
* fix test
* Fix ReviewCommentPosition
* test GetReviews
* add DefaultBranch int test set
* rm unused
* Update SDK to v0.13.0
* addopt sdk changes
* found better link
* format template
* Update Docs
* Update Gitea SDK (v0.13.1)
69 lines
1.9 KiB
Go
Vendored
69 lines
1.9 KiB
Go
Vendored
// Copyright 2018 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 (
|
|
"encoding/json"
|
|
"errors"
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
// Reference represents a Git reference.
|
|
type Reference struct {
|
|
Ref string `json:"ref"`
|
|
URL string `json:"url"`
|
|
Object *GitObject `json:"object"`
|
|
}
|
|
|
|
// GitObject represents a Git object.
|
|
type GitObject struct {
|
|
Type string `json:"type"`
|
|
SHA string `json:"sha"`
|
|
URL string `json:"url"`
|
|
}
|
|
|
|
// GetRepoRef get one ref's information of one repository
|
|
func (c *Client) GetRepoRef(user, repo, ref string) (*Reference, *Response, error) {
|
|
ref = strings.TrimPrefix(ref, "refs/")
|
|
r := new(Reference)
|
|
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/git/refs/%s", user, repo, ref), nil, nil, &r)
|
|
if _, ok := err.(*json.UnmarshalTypeError); ok {
|
|
// Multiple refs
|
|
return nil, resp, errors.New("no exact match found for this ref")
|
|
} else if err != nil {
|
|
return nil, resp, err
|
|
}
|
|
|
|
return r, resp, nil
|
|
}
|
|
|
|
// GetRepoRefs get list of ref's information of one repository
|
|
func (c *Client) GetRepoRefs(user, repo, ref string) ([]*Reference, *Response, error) {
|
|
ref = strings.TrimPrefix(ref, "refs/")
|
|
data, resp, err := c.getResponse("GET", fmt.Sprintf("/repos/%s/%s/git/refs/%s", user, repo, ref), nil, nil)
|
|
if err != nil {
|
|
return nil, resp, err
|
|
}
|
|
|
|
// Attempt to unmarshal single returned ref.
|
|
r := new(Reference)
|
|
refErr := json.Unmarshal(data, r)
|
|
if refErr == nil {
|
|
return []*Reference{r}, resp, nil
|
|
}
|
|
|
|
// Attempt to unmarshal multiple refs.
|
|
var rs []*Reference
|
|
refsErr := json.Unmarshal(data, &rs)
|
|
if refsErr == nil {
|
|
if len(rs) == 0 {
|
|
return nil, resp, errors.New("unexpected response: an array of refs with length 0")
|
|
}
|
|
return rs, resp, nil
|
|
}
|
|
|
|
return nil, resp, fmt.Errorf("unmarshalling failed for both single and multiple refs: %s and %s", refErr, refsErr)
|
|
}
|