-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbranch.go
80 lines (64 loc) · 2.59 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package cloudcms
import (
"fmt"
"net/url"
)
func (session *CloudCmsSession) QueryBranches(repositoryId string, query JsonObject, pagination JsonObject) (*ResultMap, error) {
res, err := session.Post(fmt.Sprintf("/repositories/%s/branches/query", repositoryId), ToParams(pagination), MapToReader(query))
if err != nil {
return nil, err
}
return ToResultMap(res), nil
}
func (session *CloudCmsSession) ReadBranch(repositoryId string, branchId string) (JsonObject, error) {
return session.Get(fmt.Sprintf("/repositories/%s/branches/%s", repositoryId, branchId), nil)
}
func (session *CloudCmsSession) CreateBranch(repositoryId string, parentBranchId string, changesetId string, obj JsonObject) (JsonObject, error) {
params := url.Values{}
if changesetId != "" {
params.Add("changeset", changesetId)
}
if parentBranchId != "" {
params.Add("branch", parentBranchId)
}
return session.Post(fmt.Sprintf("/repositories/%s/branches", repositoryId), params, MapToReader(obj))
}
func (session *CloudCmsSession) ListBranches(repositoryId string, pagination JsonObject) (*ResultMap, error) {
params := ToParams(pagination)
params.Add("full", "true")
res, err := session.Get(fmt.Sprintf("/repositories/%s/branches", repositoryId), params)
if err != nil {
return nil, err
}
return ToResultMap(res), nil
}
func (session *CloudCmsSession) DeleteBranch(repositoryId string, branchId string) error {
_, err := session.Delete(fmt.Sprintf("/repositories/%s/branches/%s", repositoryId, branchId), nil)
return err
}
func (session *CloudCmsSession) UpdateBranch(repositoryId string, branchObj JsonObject) (JsonObject, error) {
doc := branchObj["_doc"]
// Ensure branch id is a string
switch doc.(type) {
case string:
break
default:
return nil, fmt.Errorf("failed to determine branch ID: %v", branchObj)
}
return session.Put(fmt.Sprintf("/repositories/%s/branches/%s", repositoryId, doc.(string)), nil, MapToReader(branchObj))
}
func (session *CloudCmsSession) StartResetBranch(repositoryId string, branchId string, changesetId string) (string, error) {
params := url.Values{"id": []string{changesetId}}
res, err := session.Post(fmt.Sprintf("/repositories/%s/branches/%s/reset/start", repositoryId, branchId), params, nil)
if err != nil {
return "", err
}
return ExtractId(&res), nil
}
func (session *CloudCmsSession) StartChangesetHistory(repositoryId string, branchId string, config JsonObject) (string, error) {
res, err := session.Post(fmt.Sprintf("/repositories/%s/branches/%s/history/start", repositoryId, branchId), ToParams(config), nil)
if err != nil {
return "", err
}
return ExtractId(&res), nil
}