2016-02-02 21:54:14 +00:00
|
|
|
// Copyright 2016 The Gogs Authors. All rights reserved.
|
2020-04-24 16:39:40 +01:00
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
2016-02-02 21:54:14 +00:00
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2016-11-07 01:57:49 +00:00
|
|
|
package gitea
|
2016-01-14 15:21:47 +00:00
|
|
|
|
2016-01-15 13:35:31 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
2019-10-13 02:34:01 +01:00
|
|
|
"time"
|
2016-01-15 13:35:31 +00:00
|
|
|
)
|
|
|
|
|
2019-10-13 02:34:01 +01:00
|
|
|
// PayloadUser represents the author or committer of a commit
|
|
|
|
type PayloadUser struct {
|
|
|
|
// Full name of the commit author
|
|
|
|
Name string `json:"name"`
|
|
|
|
Email string `json:"email"`
|
|
|
|
UserName string `json:"username"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: consider using same format as API when commits API are added.
|
|
|
|
// applies to PayloadCommit and PayloadCommitVerification
|
|
|
|
|
|
|
|
// PayloadCommit represents a commit
|
|
|
|
type PayloadCommit struct {
|
|
|
|
// sha1 hash of the commit
|
|
|
|
ID string `json:"id"`
|
|
|
|
Message string `json:"message"`
|
|
|
|
URL string `json:"url"`
|
|
|
|
Author *PayloadUser `json:"author"`
|
|
|
|
Committer *PayloadUser `json:"committer"`
|
|
|
|
Verification *PayloadCommitVerification `json:"verification"`
|
|
|
|
Timestamp time.Time `json:"timestamp"`
|
|
|
|
Added []string `json:"added"`
|
|
|
|
Removed []string `json:"removed"`
|
|
|
|
Modified []string `json:"modified"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// PayloadCommitVerification represents the GPG verification of a commit
|
|
|
|
type PayloadCommitVerification struct {
|
|
|
|
Verified bool `json:"verified"`
|
|
|
|
Reason string `json:"reason"`
|
|
|
|
Signature string `json:"signature"`
|
|
|
|
Payload string `json:"payload"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// Branch represents a repository branch
|
|
|
|
type Branch struct {
|
|
|
|
Name string `json:"name"`
|
|
|
|
Commit *PayloadCommit `json:"commit"`
|
|
|
|
}
|
2016-01-14 15:21:47 +00:00
|
|
|
|
2020-02-05 07:59:55 +00:00
|
|
|
// ListRepoBranchesOptions options for listing a repository's branches
|
|
|
|
type ListRepoBranchesOptions struct {
|
|
|
|
ListOptions
|
|
|
|
}
|
|
|
|
|
2016-11-10 09:44:00 +00:00
|
|
|
// ListRepoBranches list all the branches of one repository
|
2020-02-05 07:59:55 +00:00
|
|
|
func (c *Client) ListRepoBranches(user, repo string, opt ListRepoBranchesOptions) ([]*Branch, error) {
|
|
|
|
opt.setDefaults()
|
|
|
|
branches := make([]*Branch, 0, opt.PageSize)
|
|
|
|
return branches, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/branches?%s", user, repo, opt.getURLQuery().Encode()), nil, nil, &branches)
|
2016-01-14 15:21:47 +00:00
|
|
|
}
|
|
|
|
|
2016-11-10 09:44:00 +00:00
|
|
|
// GetRepoBranch get one branch's information of one repository
|
2016-01-14 15:21:47 +00:00
|
|
|
func (c *Client) GetRepoBranch(user, repo, branch string) (*Branch, error) {
|
|
|
|
b := new(Branch)
|
2020-04-24 16:39:40 +01:00
|
|
|
if err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/branches/%s", user, repo, branch), nil, nil, &b); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return b, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteRepoBranch delete a branch in a repository
|
|
|
|
func (c *Client) DeleteRepoBranch(user, repo, branch string) (bool, error) {
|
|
|
|
if err := c.CheckServerVersionConstraint(">=1.12.0"); err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
status, err := c.getStatusCode("DELETE", fmt.Sprintf("/repos/%s/%s/branches/%s", user, repo, branch), nil, nil)
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
return status == 204, nil
|
2016-01-14 15:21:47 +00:00
|
|
|
}
|