feat(tools): branch_protection_get
This commit is contained in:
@@ -123,6 +123,33 @@ func (c *Client) DeleteBranch(ctx context.Context, owner, repo, branch string) e
|
||||
return MapStatus(status, body)
|
||||
}
|
||||
|
||||
type BranchProtection struct {
|
||||
Protected bool `json:"-"`
|
||||
RequiredApprovals int64 `json:"required_approvals"`
|
||||
PushWhitelist []string `json:"push_whitelist_usernames"`
|
||||
MergeWhitelist []string `json:"merge_whitelist_usernames"`
|
||||
}
|
||||
|
||||
func (c *Client) GetBranchProtection(ctx context.Context, owner, repo, branch string) (*BranchProtection, error) {
|
||||
p := fmt.Sprintf("/api/v1/repos/%s/%s/branch_protections/%s", owner, repo, branch)
|
||||
body, status, err := c.GetJSON(ctx, p)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if status == 404 {
|
||||
return &BranchProtection{Protected: false}, nil
|
||||
}
|
||||
if err := MapStatus(status, body); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var bp BranchProtection
|
||||
if err := json.Unmarshal(body, &bp); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
bp.Protected = true
|
||||
return &bp, nil
|
||||
}
|
||||
|
||||
// UpsertFile creates a file when args.Sha is empty (POST) or updates an existing
|
||||
// file when args.Sha is set (PUT). Gitea routes both operations by HTTP method on
|
||||
// the same /contents/{path} URL, and rejects PUT without a sha.
|
||||
|
||||
Reference in New Issue
Block a user