-
Notifications
You must be signed in to change notification settings - Fork 2
/
project.go
131 lines (115 loc) · 5.2 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
123
124
125
126
127
128
129
130
131
package buddy
import (
"net/http"
)
const (
ProjectStatusActive = "ACTIVE"
ProjectStatusClosed = "CLOSED"
ProjectAccessPublic = "PUBLIC"
ProjectAccessPrivate = "PRIVATE"
)
type ProjectService struct {
client *Client
}
type Project struct {
Url string `json:"url"`
HtmlUrl string `json:"html_url"`
Name string `json:"name"`
DisplayName string `json:"display_name"`
Status string `json:"status"`
CreateDate string `json:"create_date"`
CreatedBy *Member `json:"created_by"`
HttpRepository string `json:"http_repository"`
SshRepository string `json:"ssh_repository"`
DefaultBranch string `json:"default_branch"`
UpdateDefaultBranchFromExternal bool `json:"update_default_branch_from_external"`
FetchSubmodules bool `json:"fetch_submodules"`
FetchSubmodulesEnvKey string `json:"fetch_submodules_env_key"`
Access string `json:"access"`
AllowPullRequests bool `json:"allow_pull_requests"`
WithoutRepository bool `json:"without_repository,omitempty"`
}
type Projects struct {
Url string `json:"url"`
HtmlUrl string `json:"html_url"`
Projects []*Project `json:"projects"`
}
type ProjectIntegration struct {
HashId string `json:"hash_id"`
}
type ProjectCreateOps struct {
Name *string `json:"name,omitempty"`
DisplayName *string `json:"display_name,omitempty"`
ExternalProjectId *string `json:"external_project_id,omitempty"`
GitLabProjectId *string `json:"git_lab_project_id,omitempty"`
CustomRepoUrl *string `json:"custom_repo_url,omitempty"`
CustomRepoUser *string `json:"custom_repo_user,omitempty"`
CustomRepoPass *string `json:"custom_repo_pass,omitempty"`
CustomRepoSshKeyId *int `json:"custom_repo_ssh_key_id,omitempty"`
UpdateDefaultBranchFromExternal *bool `json:"update_default_branch_from_external,omitempty"`
Integration *ProjectIntegration `json:"integration,omitempty"`
FetchSubmodules *bool `json:"fetch_submodules,omitempty"`
FetchSubmodulesEnvKey *string `json:"fetch_submodules_env_key,omitempty"`
Access *string `json:"access,omitempty"`
AllowPullRequests *bool `json:"allow_pull_requests,omitempty"`
WithoutRepository *bool `json:"without_repository,omitempty"`
}
type ProjectUpdateOps struct {
DisplayName *string `json:"display_name,omitempty"`
Name *string `json:"name,omitempty"`
UpdateDefaultBranchFromExternal *bool `json:"update_default_branch_from_external,omitempty"`
FetchSubmodules *bool `json:"fetch_submodules,omitempty"`
FetchSubmodulesEnvKey *string `json:"fetch_submodules_env_key,omitempty"`
Access *string `json:"access,omitempty"`
AllowPullRequests *bool `json:"allow_pull_requests,omitempty"`
}
type ProjectListQuery struct {
PageQuery
Membership bool `url:"membership,omitempty"`
Status string `url:"status,omitempty"`
}
func (s *ProjectService) Create(domain string, ops *ProjectCreateOps) (*Project, *http.Response, error) {
var p *Project
resp, err := s.client.Create(s.client.NewUrlPath("/workspaces/%s/projects", domain), &ops, nil, &p)
return p, resp, err
}
func (s *ProjectService) Delete(domain string, projectName string) (*http.Response, error) {
return s.client.Delete(s.client.NewUrlPath("/workspaces/%s/projects/%s", domain, projectName), nil, nil)
}
func (s *ProjectService) Update(domain string, projectName string, ops *ProjectUpdateOps) (*Project, *http.Response, error) {
var p *Project
resp, err := s.client.Patch(s.client.NewUrlPath("/workspaces/%s/projects/%s", domain, projectName), &ops, nil, &p)
return p, resp, err
}
func (s *ProjectService) Get(domain string, projectName string) (*Project, *http.Response, error) {
var p *Project
resp, err := s.client.Get(s.client.NewUrlPath("/workspaces/%s/projects/%s", domain, projectName), &p, nil)
return p, resp, err
}
func (s *ProjectService) GetList(domain string, query *ProjectListQuery) (*Projects, *http.Response, error) {
var l *Projects
resp, err := s.client.Get(s.client.NewUrlPath("/workspaces/%s/projects", domain), &l, query)
return l, resp, err
}
func (s *ProjectService) GetListAll(domain string, query *ProjectListQuery) (*Projects, *http.Response, error) {
if query == nil {
query = &ProjectListQuery{}
}
query.Page = 1
query.PerPage = 30
var all Projects
for {
l, resp, err := s.GetList(domain, query)
if err != nil {
return nil, resp, err
}
if len(l.Projects) == 0 {
break
}
all.Url = l.Url
all.HtmlUrl = l.HtmlUrl
all.Projects = append(all.Projects, l.Projects...)
query.Page += 1
}
return &all, nil, nil
}