forked from educlos/testrail
-
Notifications
You must be signed in to change notification settings - Fork 0
/
project.go
122 lines (108 loc) · 3.21 KB
/
project.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package resttail
import (
"fmt"
"strconv"
)
type Groups struct {
ID int `json:"id"`
Role string `json:"role"`
RoleID int `json:"role_id"`
}
type Users struct {
GlobalRole *int `json:"global_role"`
GlobalRoleID *int `json:"global_role_id"`
ID int `json:"id"`
ProjectRole *int `json:"project_role"`
ProjectRoleID *int `json:"project_role_id"`
}
// Project represents a Project
type Project struct {
Announcement string `json:"announcement"`
CompletedOn int `json:"completed_on"`
Groups []Groups `json:"groups"`
ID int `json:"id"`
IsCompleted bool `json:"is_completed"`
Name string `json:"name"`
DefaultRoleID int `json:"default_role_id"`
DefaultRole string `json:"default_role"`
ShowAnnouncement bool `json:"show_announcement"`
SuiteMode int `json:"suite_mode"`
URL string `json:"url"`
Users []Users `json:"users"`
}
type Projects struct {
Links Links `json:"_links"`
Limit int `json:"limit"`
Offset int `json:"offset"`
Projects []Project `json:"projects"`
}
// SendableProject represents a Project
// that can be created or updated via the ap
type SendableProject struct {
Name string `json:"name"`
Announcement string `json:"announcement,omitempty"`
ShowAnnouncement bool `json:"show_announcement,omitempty"`
SuiteMode int `json:"suite_mode,omitempty"`
}
// GetProject returns the existing project projectID
func (c *Client) GetProject(projectID int) (Project, error) {
returnProject := Project{}
err := c.sendRequest(
"GET",
"get_project/"+strconv.Itoa(projectID),
nil,
&returnProject,
)
return returnProject, err
}
// GetProjects returns a list available projects
// can be filtered by completed status of the project
func (c *Client) GetProjects(isCompleted ...bool) (Projects, error) {
uri := "get_projects"
if len(isCompleted) > 0 {
uri = uri + "&is_completed=" + btoitos(isCompleted[0])
}
returnProjects := Projects{
Links: Links{},
Limit: 0,
Offset: 0,
Projects: nil,
}
var err error
if c.useBetaApi {
err = c.sendRequestBeta("GET", uri, nil, &returnProjects, "projects")
} else {
err = c.sendRequest("GET", uri, nil, &returnProjects)
}
return returnProjects, err
}
// AddProject creates a new project and return its
func (c *Client) AddProject(newProject SendableProject) (Project, error) {
createdProject := Project{}
err := c.sendRequest("POST", "add_project", newProject, &createdProject)
return createdProject, err
}
// UpdateProject updates the existing project projectID and returns it
func (c *Client) UpdateProject(
projectID int,
updates SendableProject,
isCompleted ...bool,
) (Project, error) {
updatedProject := Project{}
uri := "update_project/" + strconv.Itoa(projectID)
if len(isCompleted) > 0 {
uri = uri + "&is_completed=" + btoitos(isCompleted[0])
}
fmt.Println(uri)
err := c.sendRequest("POST", uri, updates, &updatedProject)
return updatedProject, err
}
// DeleteProject deletes the project projectID
func (c *Client) DeleteProject(projectID int) error {
return c.sendRequest(
"POST",
"delete_project/"+strconv.Itoa(projectID),
nil,
nil,
)
}