forked from rcarmstrong/go-bamboo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clone.go
38 lines (31 loc) · 1.08 KB
/
clone.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
package bamboo
import (
"fmt"
"net/http"
)
// CloneService handles the cloning of one Bamboo resource to another.
type CloneService service
// ClonePlan clones a plan from one project to another given the full project-plan key for
// the source plan and the destination plan. The destination project does not need to be in
// the same project as the source plan. Returns a Plan struct of the resulting plan.
func (c *CloneService) ClonePlan(srcKey, dstKey string) (*Plan, *http.Response, error) {
var u string
if !emptyStrings(srcKey, dstKey) {
u = fmt.Sprintf("clone/%s:%s.json", srcKey, dstKey)
} else {
return nil, nil, &simpleError{"Source key and/or destination key cannot be empty strings"}
}
request, err := c.client.NewRequest(http.MethodPut, u, nil)
if err != nil {
return nil, nil, err
}
clonedPlan := Plan{}
response, err := c.client.Do(request, &clonedPlan)
if err != nil {
return nil, response, err
}
if !(response.StatusCode == 200) {
return nil, response, &simpleError{fmt.Sprintf("Clone returned %d", response.StatusCode)}
}
return &clonedPlan, response, nil
}