-
Notifications
You must be signed in to change notification settings - Fork 0
/
branch.go
65 lines (60 loc) · 2.07 KB
/
branch.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package wharfapi
import (
"fmt"
"github.com/iver-wharf/wharf-api-client-go/v2/pkg/model/request"
"github.com/iver-wharf/wharf-api-client-go/v2/pkg/model/response"
)
// CreateProjectBranch adds a branch to the project with the matching
// project ID by invoking the HTTP request:
// POST /api/project/{projectId}/branch
//
// Added in wharf-api v5.0.0.
func (c *Client) CreateProjectBranch(projectID uint, branch request.Branch) (response.Branch, error) {
if err := c.validateEndpointVersion(5, 0, 0); err != nil {
return response.Branch{}, err
}
var newBranch response.Branch
path := fmt.Sprintf("/api/project/%d/branch", projectID)
err := c.postJSONUnmarshal(path, nil, branch, &newBranch)
return newBranch, err
}
// UpdateProjectBranchList resets the default branch and list of branches for a project
// using the project ID from the first branch in the provided list by invoking
// the HTTP request:
// PUT /api/project/{projectId}/branch
//
// Added in wharf-api v5.0.0.
func (c *Client) UpdateProjectBranchList(projectID uint, branches []request.Branch) ([]response.Branch, error) {
if err := c.validateEndpointVersion(5, 0, 0); err != nil {
return nil, err
}
body := request.BranchListUpdate{
Branches: make([]request.BranchUpdate, 0, len(branches)),
}
for _, b := range branches {
body.Branches = append(body.Branches, request.BranchUpdate{
Name: b.Name,
})
if b.Default {
body.DefaultBranch = b.Name
}
}
var response response.BranchList
path := fmt.Sprintf("/api/project/%d/branch", projectID)
err := c.putJSONUnmarshal(path, nil, body, &response)
return response.Branches, err
}
// GetProjectBranchList gets the branches for a project by invoking the HTTP
// request:
// GET /api/project/{projectId}/branch
//
// Added in wharf-api v5.0.0.
func (c *Client) GetProjectBranchList(projectID uint) ([]response.Branch, error) {
if err := c.validateEndpointVersion(5, 0, 0); err != nil {
return nil, err
}
path := fmt.Sprintf("/api/project/%d/branch", projectID)
var branches []response.Branch
err := c.getUnmarshal(path, nil, &branches)
return branches, err
}