projects.go 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174
  1. //
  2. // Copyright 2017, Sander van Harmelen
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //
  16. package gitlab
  17. import (
  18. "bytes"
  19. "fmt"
  20. "io"
  21. "io/ioutil"
  22. "mime/multipart"
  23. "net/url"
  24. "os"
  25. "time"
  26. )
  27. // ProjectsService handles communication with the repositories related methods
  28. // of the GitLab API.
  29. //
  30. // GitLab API docs: https://docs.gitlab.com/ce/api/projects.html
  31. type ProjectsService struct {
  32. client *Client
  33. }
  34. // Project represents a GitLab project.
  35. //
  36. // GitLab API docs: https://docs.gitlab.com/ce/api/projects.html
  37. type Project struct {
  38. ID int `json:"id"`
  39. Description string `json:"description"`
  40. DefaultBranch string `json:"default_branch"`
  41. Public bool `json:"public"`
  42. Visibility VisibilityValue `json:"visibility"`
  43. SSHURLToRepo string `json:"ssh_url_to_repo"`
  44. HTTPURLToRepo string `json:"http_url_to_repo"`
  45. WebURL string `json:"web_url"`
  46. TagList []string `json:"tag_list"`
  47. Owner *User `json:"owner"`
  48. Name string `json:"name"`
  49. NameWithNamespace string `json:"name_with_namespace"`
  50. Path string `json:"path"`
  51. PathWithNamespace string `json:"path_with_namespace"`
  52. IssuesEnabled bool `json:"issues_enabled"`
  53. OpenIssuesCount int `json:"open_issues_count"`
  54. MergeRequestsEnabled bool `json:"merge_requests_enabled"`
  55. ApprovalsBeforeMerge int `json:"approvals_before_merge"`
  56. JobsEnabled bool `json:"jobs_enabled"`
  57. WikiEnabled bool `json:"wiki_enabled"`
  58. SnippetsEnabled bool `json:"snippets_enabled"`
  59. ContainerRegistryEnabled bool `json:"container_registry_enabled"`
  60. CreatedAt *time.Time `json:"created_at,omitempty"`
  61. LastActivityAt *time.Time `json:"last_activity_at,omitempty"`
  62. CreatorID int `json:"creator_id"`
  63. Namespace *ProjectNamespace `json:"namespace"`
  64. ImportStatus string `json:"import_status"`
  65. ImportError string `json:"import_error"`
  66. Permissions *Permissions `json:"permissions"`
  67. Archived bool `json:"archived"`
  68. AvatarURL string `json:"avatar_url"`
  69. SharedRunnersEnabled bool `json:"shared_runners_enabled"`
  70. ForksCount int `json:"forks_count"`
  71. StarCount int `json:"star_count"`
  72. RunnersToken string `json:"runners_token"`
  73. PublicBuilds bool `json:"public_builds"`
  74. OnlyAllowMergeIfPipelineSucceeds bool `json:"only_allow_merge_if_pipeline_succeeds"`
  75. OnlyAllowMergeIfAllDiscussionsAreResolved bool `json:"only_allow_merge_if_all_discussions_are_resolved"`
  76. LFSEnabled bool `json:"lfs_enabled"`
  77. RequestAccessEnabled bool `json:"request_access_enabled"`
  78. MergeMethod MergeMethodValue `json:"merge_method"`
  79. ForkedFromProject *ForkParent `json:"forked_from_project"`
  80. SharedWithGroups []struct {
  81. GroupID int `json:"group_id"`
  82. GroupName string `json:"group_name"`
  83. GroupAccessLevel int `json:"group_access_level"`
  84. } `json:"shared_with_groups"`
  85. Statistics *ProjectStatistics `json:"statistics"`
  86. Links *Links `json:"_links,omitempty"`
  87. CIConfigPath *string `json:"ci_config_path"`
  88. }
  89. // Repository represents a repository.
  90. type Repository struct {
  91. Name string `json:"name"`
  92. Description string `json:"description"`
  93. WebURL string `json:"web_url"`
  94. AvatarURL string `json:"avatar_url"`
  95. GitSSHURL string `json:"git_ssh_url"`
  96. GitHTTPURL string `json:"git_http_url"`
  97. Namespace string `json:"namespace"`
  98. Visibility VisibilityValue `json:"visibility"`
  99. PathWithNamespace string `json:"path_with_namespace"`
  100. DefaultBranch string `json:"default_branch"`
  101. Homepage string `json:"homepage"`
  102. URL string `json:"url"`
  103. SSHURL string `json:"ssh_url"`
  104. HTTPURL string `json:"http_url"`
  105. }
  106. // ProjectNamespace represents a project namespace.
  107. type ProjectNamespace struct {
  108. ID int `json:"id"`
  109. Name string `json:"name"`
  110. Path string `json:"path"`
  111. Kind string `json:"kind"`
  112. FullPath string `json:"full_path"`
  113. }
  114. // StorageStatistics represents a statistics record for a group or project.
  115. type StorageStatistics struct {
  116. StorageSize int64 `json:"storage_size"`
  117. RepositorySize int64 `json:"repository_size"`
  118. LfsObjectsSize int64 `json:"lfs_objects_size"`
  119. JobArtifactsSize int64 `json:"job_artifacts_size"`
  120. }
  121. // ProjectStatistics represents a statistics record for a project.
  122. type ProjectStatistics struct {
  123. StorageStatistics
  124. CommitCount int `json:"commit_count"`
  125. }
  126. // Permissions represents permissions.
  127. type Permissions struct {
  128. ProjectAccess *ProjectAccess `json:"project_access"`
  129. GroupAccess *GroupAccess `json:"group_access"`
  130. }
  131. // ProjectAccess represents project access.
  132. type ProjectAccess struct {
  133. AccessLevel AccessLevelValue `json:"access_level"`
  134. NotificationLevel NotificationLevelValue `json:"notification_level"`
  135. }
  136. // GroupAccess represents group access.
  137. type GroupAccess struct {
  138. AccessLevel AccessLevelValue `json:"access_level"`
  139. NotificationLevel NotificationLevelValue `json:"notification_level"`
  140. }
  141. // ForkParent represents the parent project when this is a fork.
  142. type ForkParent struct {
  143. HTTPURLToRepo string `json:"http_url_to_repo"`
  144. ID int `json:"id"`
  145. Name string `json:"name"`
  146. NameWithNamespace string `json:"name_with_namespace"`
  147. Path string `json:"path"`
  148. PathWithNamespace string `json:"path_with_namespace"`
  149. WebURL string `json:"web_url"`
  150. }
  151. // Links represents a project web links for self, issues, merge_requests,
  152. // repo_branches, labels, events, members.
  153. type Links struct {
  154. Self string `json:"self"`
  155. Issues string `json:"issues"`
  156. MergeRequests string `json:"merge_requests"`
  157. RepoBranches string `json:"repo_branches"`
  158. Labels string `json:"labels"`
  159. Events string `json:"events"`
  160. Members string `json:"members"`
  161. }
  162. func (s Project) String() string {
  163. return Stringify(s)
  164. }
  165. // ListProjectsOptions represents the available ListProjects() options.
  166. //
  167. // GitLab API docs: https://docs.gitlab.com/ce/api/projects.html#list-projects
  168. type ListProjectsOptions struct {
  169. ListOptions
  170. Archived *bool `url:"archived,omitempty" json:"archived,omitempty"`
  171. OrderBy *string `url:"order_by,omitempty" json:"order_by,omitempty"`
  172. Sort *string `url:"sort,omitempty" json:"sort,omitempty"`
  173. Search *string `url:"search,omitempty" json:"search,omitempty"`
  174. Simple *bool `url:"simple,omitempty" json:"simple,omitempty"`
  175. Owned *bool `url:"owned,omitempty" json:"owned,omitempty"`
  176. Membership *bool `url:"membership,omitempty" json:"membership,omitempty"`
  177. Starred *bool `url:"starred,omitempty" json:"starred,omitempty"`
  178. Statistics *bool `url:"statistics,omitempty" json:"statistics,omitempty"`
  179. Visibility *VisibilityValue `url:"visibility,omitempty" json:"visibility,omitempty"`
  180. WithIssuesEnabled *bool `url:"with_issues_enabled,omitempty" json:"with_issues_enabled,omitempty"`
  181. WithMergeRequestsEnabled *bool `url:"with_merge_requests_enabled,omitempty" json:"with_merge_requests_enabled,omitempty"`
  182. MinAccessLevel *AccessLevelValue `url:"min_access_level,omitempty" json:"min_access_level,omitempty"`
  183. }
  184. // ListProjects gets a list of projects accessible by the authenticated user.
  185. //
  186. // GitLab API docs: https://docs.gitlab.com/ce/api/projects.html#list-projects
  187. func (s *ProjectsService) ListProjects(opt *ListProjectsOptions, options ...OptionFunc) ([]*Project, *Response, error) {
  188. req, err := s.client.NewRequest("GET", "projects", opt, options)
  189. if err != nil {
  190. return nil, nil, err
  191. }
  192. var p []*Project
  193. resp, err := s.client.Do(req, &p)
  194. if err != nil {
  195. return nil, resp, err
  196. }
  197. return p, resp, err
  198. }
  199. // ListUserProjects gets a list of projects for the given user.
  200. //
  201. // GitLab API docs:
  202. // https://docs.gitlab.com/ce/api/projects.html#list-user-projects
  203. func (s *ProjectsService) ListUserProjects(uid interface{}, opt *ListProjectsOptions, options ...OptionFunc) ([]*Project, *Response, error) {
  204. user, err := parseID(uid)
  205. if err != nil {
  206. return nil, nil, err
  207. }
  208. u := fmt.Sprintf("users/%s/projects", user)
  209. req, err := s.client.NewRequest("GET", u, opt, options)
  210. if err != nil {
  211. return nil, nil, err
  212. }
  213. var p []*Project
  214. resp, err := s.client.Do(req, &p)
  215. if err != nil {
  216. return nil, resp, err
  217. }
  218. return p, resp, err
  219. }
  220. // ProjectUser represents a GitLab project user.
  221. type ProjectUser struct {
  222. ID int `json:"id"`
  223. Name string `json:"name"`
  224. Username string `json:"username"`
  225. State string `json:"state"`
  226. AvatarURL string `json:"avatar_url"`
  227. WebURL string `json:"web_url"`
  228. }
  229. // ListProjectUserOptions represents the available ListProjectsUsers() options.
  230. //
  231. // GitLab API docs: https://docs.gitlab.com/ce/api/projects.html#get-project-users
  232. type ListProjectUserOptions struct {
  233. ListOptions
  234. Search *string `url:"search,omitempty" json:"search,omitempty"`
  235. }
  236. // ListProjectsUsers gets a list of users for the given project.
  237. //
  238. // GitLab API docs:
  239. // https://docs.gitlab.com/ce/api/projects.html#get-project-users
  240. func (s *ProjectsService) ListProjectsUsers(pid interface{}, opt *ListProjectUserOptions, options ...OptionFunc) ([]*ProjectUser, *Response, error) {
  241. project, err := parseID(pid)
  242. if err != nil {
  243. return nil, nil, err
  244. }
  245. u := fmt.Sprintf("projects/%s/users", url.QueryEscape(project))
  246. req, err := s.client.NewRequest("GET", u, opt, options)
  247. if err != nil {
  248. return nil, nil, err
  249. }
  250. var p []*ProjectUser
  251. resp, err := s.client.Do(req, &p)
  252. if err != nil {
  253. return nil, resp, err
  254. }
  255. return p, resp, err
  256. }
  257. // ProjectLanguages is a map of strings because the response is arbitrary
  258. //
  259. // Gitlab API docs: https://docs.gitlab.com/ce/api/projects.html#languages
  260. type ProjectLanguages map[string]float32
  261. // GetProjectLanguages gets a list of languages used by the project
  262. //
  263. // GitLab API docs: https://docs.gitlab.com/ce/api/projects.html#languages
  264. func (s *ProjectsService) GetProjectLanguages(pid interface{}, options ...OptionFunc) (*ProjectLanguages, *Response, error) {
  265. project, err := parseID(pid)
  266. if err != nil {
  267. return nil, nil, err
  268. }
  269. u := fmt.Sprintf("projects/%s/languages", url.QueryEscape(project))
  270. req, err := s.client.NewRequest("GET", u, nil, options)
  271. if err != nil {
  272. return nil, nil, err
  273. }
  274. p := new(ProjectLanguages)
  275. resp, err := s.client.Do(req, p)
  276. if err != nil {
  277. return nil, resp, err
  278. }
  279. return p, resp, err
  280. }
  281. // GetProject gets a specific project, identified by project ID or
  282. // NAMESPACE/PROJECT_NAME, which is owned by the authenticated user.
  283. //
  284. // GitLab API docs:
  285. // https://docs.gitlab.com/ce/api/projects.html#get-single-project
  286. func (s *ProjectsService) GetProject(pid interface{}, options ...OptionFunc) (*Project, *Response, error) {
  287. project, err := parseID(pid)
  288. if err != nil {
  289. return nil, nil, err
  290. }
  291. u := fmt.Sprintf("projects/%s", url.QueryEscape(project))
  292. req, err := s.client.NewRequest("GET", u, nil, options)
  293. if err != nil {
  294. return nil, nil, err
  295. }
  296. p := new(Project)
  297. resp, err := s.client.Do(req, p)
  298. if err != nil {
  299. return nil, resp, err
  300. }
  301. return p, resp, err
  302. }
  303. // ProjectEvent represents a GitLab project event.
  304. //
  305. // GitLab API docs:
  306. // https://docs.gitlab.com/ce/api/projects.html#get-project-events
  307. type ProjectEvent struct {
  308. Title interface{} `json:"title"`
  309. ProjectID int `json:"project_id"`
  310. ActionName string `json:"action_name"`
  311. TargetID interface{} `json:"target_id"`
  312. TargetType interface{} `json:"target_type"`
  313. AuthorID int `json:"author_id"`
  314. AuthorUsername string `json:"author_username"`
  315. Data struct {
  316. Before string `json:"before"`
  317. After string `json:"after"`
  318. Ref string `json:"ref"`
  319. UserID int `json:"user_id"`
  320. UserName string `json:"user_name"`
  321. Repository *Repository `json:"repository"`
  322. Commits []*Commit `json:"commits"`
  323. TotalCommitsCount int `json:"total_commits_count"`
  324. } `json:"data"`
  325. TargetTitle interface{} `json:"target_title"`
  326. }
  327. func (s ProjectEvent) String() string {
  328. return Stringify(s)
  329. }
  330. // GetProjectEventsOptions represents the available GetProjectEvents() options.
  331. //
  332. // GitLab API docs:
  333. // https://docs.gitlab.com/ce/api/projects.html#get-project-events
  334. type GetProjectEventsOptions ListOptions
  335. // GetProjectEvents gets the events for the specified project. Sorted from
  336. // newest to latest.
  337. //
  338. // GitLab API docs:
  339. // https://docs.gitlab.com/ce/api/projects.html#get-project-events
  340. func (s *ProjectsService) GetProjectEvents(pid interface{}, opt *GetProjectEventsOptions, options ...OptionFunc) ([]*ProjectEvent, *Response, error) {
  341. project, err := parseID(pid)
  342. if err != nil {
  343. return nil, nil, err
  344. }
  345. u := fmt.Sprintf("projects/%s/events", url.QueryEscape(project))
  346. req, err := s.client.NewRequest("GET", u, opt, options)
  347. if err != nil {
  348. return nil, nil, err
  349. }
  350. var p []*ProjectEvent
  351. resp, err := s.client.Do(req, &p)
  352. if err != nil {
  353. return nil, resp, err
  354. }
  355. return p, resp, err
  356. }
  357. // CreateProjectOptions represents the available CreateProjects() options.
  358. //
  359. // GitLab API docs: https://docs.gitlab.com/ee/api/projects.html#create-project
  360. type CreateProjectOptions struct {
  361. Name *string `url:"name,omitempty" json:"name,omitempty"`
  362. Path *string `url:"path,omitempty" json:"path,omitempty"`
  363. DefaultBranch *string `url:"default_branch,omitempty" json:"default_branch,omitempty"`
  364. NamespaceID *int `url:"namespace_id,omitempty" json:"namespace_id,omitempty"`
  365. Description *string `url:"description,omitempty" json:"description,omitempty"`
  366. IssuesEnabled *bool `url:"issues_enabled,omitempty" json:"issues_enabled,omitempty"`
  367. MergeRequestsEnabled *bool `url:"merge_requests_enabled,omitempty" json:"merge_requests_enabled,omitempty"`
  368. JobsEnabled *bool `url:"jobs_enabled,omitempty" json:"jobs_enabled,omitempty"`
  369. WikiEnabled *bool `url:"wiki_enabled,omitempty" json:"wiki_enabled,omitempty"`
  370. SnippetsEnabled *bool `url:"snippets_enabled,omitempty" json:"snippets_enabled,omitempty"`
  371. ResolveOutdatedDiffDiscussions *bool `url:"resolve_outdated_diff_discussions,omitempty" json:"resolve_outdated_diff_discussions,omitempty"`
  372. ContainerRegistryEnabled *bool `url:"container_registry_enabled,omitempty" json:"container_registry_enabled,omitempty"`
  373. SharedRunnersEnabled *bool `url:"shared_runners_enabled,omitempty" json:"shared_runners_enabled,omitempty"`
  374. Visibility *VisibilityValue `url:"visibility,omitempty" json:"visibility,omitempty"`
  375. ImportURL *string `url:"import_url,omitempty" json:"import_url,omitempty"`
  376. PublicBuilds *bool `url:"public_builds,omitempty" json:"public_builds,omitempty"`
  377. OnlyAllowMergeIfPipelineSucceeds *bool `url:"only_allow_merge_if_pipeline_succeeds,omitempty" json:"only_allow_merge_if_pipeline_succeeds,omitempty"`
  378. OnlyAllowMergeIfAllDiscussionsAreResolved *bool `url:"only_allow_merge_if_all_discussions_are_resolved,omitempty" json:"only_allow_merge_if_all_discussions_are_resolved,omitempty"`
  379. MergeMethod *MergeMethodValue `url:"merge_method,omitempty" json:"merge_method,omitempty"`
  380. LFSEnabled *bool `url:"lfs_enabled,omitempty" json:"lfs_enabled,omitempty"`
  381. RequestAccessEnabled *bool `url:"request_access_enabled,omitempty" json:"request_access_enabled,omitempty"`
  382. TagList *[]string `url:"tag_list,omitempty" json:"tag_list,omitempty"`
  383. PrintingMergeRequestLinkEnabled *bool `url:"printing_merge_request_link_enabled,omitempty" json:"printing_merge_request_link_enabled,omitempty"`
  384. CIConfigPath *string `url:"ci_config_path,omitempty" json:"ci_config_path,omitempty"`
  385. ApprovalsBeforeMerge *int `url:"approvals_before_merge" json:"approvals_before_merge"`
  386. }
  387. // CreateProject creates a new project owned by the authenticated user.
  388. //
  389. // GitLab API docs: https://docs.gitlab.com/ce/api/projects.html#create-project
  390. func (s *ProjectsService) CreateProject(opt *CreateProjectOptions, options ...OptionFunc) (*Project, *Response, error) {
  391. req, err := s.client.NewRequest("POST", "projects", opt, options)
  392. if err != nil {
  393. return nil, nil, err
  394. }
  395. p := new(Project)
  396. resp, err := s.client.Do(req, p)
  397. if err != nil {
  398. return nil, resp, err
  399. }
  400. return p, resp, err
  401. }
  402. // CreateProjectForUserOptions represents the available CreateProjectForUser()
  403. // options.
  404. //
  405. // GitLab API docs:
  406. // https://docs.gitlab.com/ce/api/projects.html#create-project-for-user
  407. type CreateProjectForUserOptions CreateProjectOptions
  408. // CreateProjectForUser creates a new project owned by the specified user.
  409. // Available only for admins.
  410. //
  411. // GitLab API docs:
  412. // https://docs.gitlab.com/ce/api/projects.html#create-project-for-user
  413. func (s *ProjectsService) CreateProjectForUser(user int, opt *CreateProjectForUserOptions, options ...OptionFunc) (*Project, *Response, error) {
  414. u := fmt.Sprintf("projects/user/%d", user)
  415. req, err := s.client.NewRequest("POST", u, opt, options)
  416. if err != nil {
  417. return nil, nil, err
  418. }
  419. p := new(Project)
  420. resp, err := s.client.Do(req, p)
  421. if err != nil {
  422. return nil, resp, err
  423. }
  424. return p, resp, err
  425. }
  426. // EditProjectOptions represents the available EditProject() options.
  427. //
  428. // GitLab API docs: https://docs.gitlab.com/ce/api/projects.html#edit-project
  429. type EditProjectOptions CreateProjectOptions
  430. // EditProject updates an existing project.
  431. //
  432. // GitLab API docs: https://docs.gitlab.com/ce/api/projects.html#edit-project
  433. func (s *ProjectsService) EditProject(pid interface{}, opt *EditProjectOptions, options ...OptionFunc) (*Project, *Response, error) {
  434. project, err := parseID(pid)
  435. if err != nil {
  436. return nil, nil, err
  437. }
  438. u := fmt.Sprintf("projects/%s", url.QueryEscape(project))
  439. req, err := s.client.NewRequest("PUT", u, opt, options)
  440. if err != nil {
  441. return nil, nil, err
  442. }
  443. p := new(Project)
  444. resp, err := s.client.Do(req, p)
  445. if err != nil {
  446. return nil, resp, err
  447. }
  448. return p, resp, err
  449. }
  450. // ForkProject forks a project into the user namespace of the authenticated
  451. // user.
  452. //
  453. // GitLab API docs: https://docs.gitlab.com/ce/api/projects.html#fork-project
  454. func (s *ProjectsService) ForkProject(pid interface{}, options ...OptionFunc) (*Project, *Response, error) {
  455. project, err := parseID(pid)
  456. if err != nil {
  457. return nil, nil, err
  458. }
  459. u := fmt.Sprintf("projects/%s/fork", url.QueryEscape(project))
  460. req, err := s.client.NewRequest("POST", u, nil, options)
  461. if err != nil {
  462. return nil, nil, err
  463. }
  464. p := new(Project)
  465. resp, err := s.client.Do(req, p)
  466. if err != nil {
  467. return nil, resp, err
  468. }
  469. return p, resp, err
  470. }
  471. // StarProject stars a given the project.
  472. //
  473. // GitLab API docs:
  474. // https://docs.gitlab.com/ce/api/projects.html#star-a-project
  475. func (s *ProjectsService) StarProject(pid interface{}, options ...OptionFunc) (*Project, *Response, error) {
  476. project, err := parseID(pid)
  477. if err != nil {
  478. return nil, nil, err
  479. }
  480. u := fmt.Sprintf("projects/%s/star", url.QueryEscape(project))
  481. req, err := s.client.NewRequest("POST", u, nil, options)
  482. if err != nil {
  483. return nil, nil, err
  484. }
  485. p := new(Project)
  486. resp, err := s.client.Do(req, p)
  487. if err != nil {
  488. return nil, resp, err
  489. }
  490. return p, resp, err
  491. }
  492. // UnstarProject unstars a given project.
  493. //
  494. // GitLab API docs:
  495. // https://docs.gitlab.com/ce/api/projects.html#unstar-a-project
  496. func (s *ProjectsService) UnstarProject(pid interface{}, options ...OptionFunc) (*Project, *Response, error) {
  497. project, err := parseID(pid)
  498. if err != nil {
  499. return nil, nil, err
  500. }
  501. u := fmt.Sprintf("projects/%s/unstar", url.QueryEscape(project))
  502. req, err := s.client.NewRequest("POST", u, nil, options)
  503. if err != nil {
  504. return nil, nil, err
  505. }
  506. p := new(Project)
  507. resp, err := s.client.Do(req, p)
  508. if err != nil {
  509. return nil, resp, err
  510. }
  511. return p, resp, err
  512. }
  513. // ArchiveProject archives the project if the user is either admin or the
  514. // project owner of this project.
  515. //
  516. // GitLab API docs:
  517. // https://docs.gitlab.com/ce/api/projects.html#archive-a-project
  518. func (s *ProjectsService) ArchiveProject(pid interface{}, options ...OptionFunc) (*Project, *Response, error) {
  519. project, err := parseID(pid)
  520. if err != nil {
  521. return nil, nil, err
  522. }
  523. u := fmt.Sprintf("projects/%s/archive", url.QueryEscape(project))
  524. req, err := s.client.NewRequest("POST", u, nil, options)
  525. if err != nil {
  526. return nil, nil, err
  527. }
  528. p := new(Project)
  529. resp, err := s.client.Do(req, p)
  530. if err != nil {
  531. return nil, resp, err
  532. }
  533. return p, resp, err
  534. }
  535. // UnarchiveProject unarchives the project if the user is either admin or
  536. // the project owner of this project.
  537. //
  538. // GitLab API docs:
  539. // https://docs.gitlab.com/ce/api/projects.html#unarchive-a-project
  540. func (s *ProjectsService) UnarchiveProject(pid interface{}, options ...OptionFunc) (*Project, *Response, error) {
  541. project, err := parseID(pid)
  542. if err != nil {
  543. return nil, nil, err
  544. }
  545. u := fmt.Sprintf("projects/%s/unarchive", url.QueryEscape(project))
  546. req, err := s.client.NewRequest("POST", u, nil, options)
  547. if err != nil {
  548. return nil, nil, err
  549. }
  550. p := new(Project)
  551. resp, err := s.client.Do(req, p)
  552. if err != nil {
  553. return nil, resp, err
  554. }
  555. return p, resp, err
  556. }
  557. // DeleteProject removes a project including all associated resources
  558. // (issues, merge requests etc.)
  559. //
  560. // GitLab API docs: https://docs.gitlab.com/ce/api/projects.html#remove-project
  561. func (s *ProjectsService) DeleteProject(pid interface{}, options ...OptionFunc) (*Response, error) {
  562. project, err := parseID(pid)
  563. if err != nil {
  564. return nil, err
  565. }
  566. u := fmt.Sprintf("projects/%s", url.QueryEscape(project))
  567. req, err := s.client.NewRequest("DELETE", u, nil, options)
  568. if err != nil {
  569. return nil, err
  570. }
  571. return s.client.Do(req, nil)
  572. }
  573. // ShareWithGroupOptions represents options to share project with groups
  574. //
  575. // GitLab API docs: https://docs.gitlab.com/ce/api/projects.html#share-project-with-group
  576. type ShareWithGroupOptions struct {
  577. GroupID *int `url:"group_id" json:"group_id"`
  578. GroupAccess *AccessLevelValue `url:"group_access" json:"group_access"`
  579. ExpiresAt *string `url:"expires_at" json:"expires_at"`
  580. }
  581. // ShareProjectWithGroup allows to share a project with a group.
  582. //
  583. // GitLab API docs: https://docs.gitlab.com/ce/api/projects.html#share-project-with-group
  584. func (s *ProjectsService) ShareProjectWithGroup(pid interface{}, opt *ShareWithGroupOptions, options ...OptionFunc) (*Response, error) {
  585. project, err := parseID(pid)
  586. if err != nil {
  587. return nil, err
  588. }
  589. u := fmt.Sprintf("projects/%s/share", url.QueryEscape(project))
  590. req, err := s.client.NewRequest("POST", u, opt, options)
  591. if err != nil {
  592. return nil, err
  593. }
  594. return s.client.Do(req, nil)
  595. }
  596. // DeleteSharedProjectFromGroup allows to unshare a project from a group.
  597. //
  598. // GitLab API docs: https://docs.gitlab.com/ce/api/projects.html#delete-a-shared-project-link-within-a-group
  599. func (s *ProjectsService) DeleteSharedProjectFromGroup(pid interface{}, groupID int, options ...OptionFunc) (*Response, error) {
  600. project, err := parseID(pid)
  601. if err != nil {
  602. return nil, err
  603. }
  604. u := fmt.Sprintf("projects/%s/share/%d", url.QueryEscape(project), groupID)
  605. req, err := s.client.NewRequest("DELETE", u, nil, options)
  606. if err != nil {
  607. return nil, err
  608. }
  609. return s.client.Do(req, nil)
  610. }
  611. // ProjectMember represents a project member.
  612. //
  613. // GitLab API docs:
  614. // https://docs.gitlab.com/ce/api/projects.html#list-project-team-members
  615. type ProjectMember struct {
  616. ID int `json:"id"`
  617. Username string `json:"username"`
  618. Email string `json:"email"`
  619. Name string `json:"name"`
  620. State string `json:"state"`
  621. CreatedAt *time.Time `json:"created_at"`
  622. AccessLevel AccessLevelValue `json:"access_level"`
  623. }
  624. // ProjectHook represents a project hook.
  625. //
  626. // GitLab API docs:
  627. // https://docs.gitlab.com/ce/api/projects.html#list-project-hooks
  628. type ProjectHook struct {
  629. ID int `json:"id"`
  630. URL string `json:"url"`
  631. ProjectID int `json:"project_id"`
  632. PushEvents bool `json:"push_events"`
  633. IssuesEvents bool `json:"issues_events"`
  634. ConfidentialIssuesEvents bool `json:"confidential_issues_events"`
  635. MergeRequestsEvents bool `json:"merge_requests_events"`
  636. TagPushEvents bool `json:"tag_push_events"`
  637. NoteEvents bool `json:"note_events"`
  638. JobEvents bool `json:"job_events"`
  639. PipelineEvents bool `json:"pipeline_events"`
  640. WikiPageEvents bool `json:"wiki_page_events"`
  641. EnableSSLVerification bool `json:"enable_ssl_verification"`
  642. CreatedAt *time.Time `json:"created_at"`
  643. }
  644. // ListProjectHooksOptions represents the available ListProjectHooks() options.
  645. //
  646. // GitLab API docs: https://docs.gitlab.com/ce/api/projects.html#list-project-hooks
  647. type ListProjectHooksOptions ListOptions
  648. // ListProjectHooks gets a list of project hooks.
  649. //
  650. // GitLab API docs:
  651. // https://docs.gitlab.com/ce/api/projects.html#list-project-hooks
  652. func (s *ProjectsService) ListProjectHooks(pid interface{}, opt *ListProjectHooksOptions, options ...OptionFunc) ([]*ProjectHook, *Response, error) {
  653. project, err := parseID(pid)
  654. if err != nil {
  655. return nil, nil, err
  656. }
  657. u := fmt.Sprintf("projects/%s/hooks", url.QueryEscape(project))
  658. req, err := s.client.NewRequest("GET", u, opt, options)
  659. if err != nil {
  660. return nil, nil, err
  661. }
  662. var ph []*ProjectHook
  663. resp, err := s.client.Do(req, &ph)
  664. if err != nil {
  665. return nil, resp, err
  666. }
  667. return ph, resp, err
  668. }
  669. // GetProjectHook gets a specific hook for a project.
  670. //
  671. // GitLab API docs:
  672. // https://docs.gitlab.com/ce/api/projects.html#get-project-hook
  673. func (s *ProjectsService) GetProjectHook(pid interface{}, hook int, options ...OptionFunc) (*ProjectHook, *Response, error) {
  674. project, err := parseID(pid)
  675. if err != nil {
  676. return nil, nil, err
  677. }
  678. u := fmt.Sprintf("projects/%s/hooks/%d", url.QueryEscape(project), hook)
  679. req, err := s.client.NewRequest("GET", u, nil, options)
  680. if err != nil {
  681. return nil, nil, err
  682. }
  683. ph := new(ProjectHook)
  684. resp, err := s.client.Do(req, ph)
  685. if err != nil {
  686. return nil, resp, err
  687. }
  688. return ph, resp, err
  689. }
  690. // AddProjectHookOptions represents the available AddProjectHook() options.
  691. //
  692. // GitLab API docs:
  693. // https://docs.gitlab.com/ce/api/projects.html#add-project-hook
  694. type AddProjectHookOptions struct {
  695. URL *string `url:"url,omitempty" json:"url,omitempty"`
  696. PushEvents *bool `url:"push_events,omitempty" json:"push_events,omitempty"`
  697. IssuesEvents *bool `url:"issues_events,omitempty" json:"issues_events,omitempty"`
  698. ConfidentialIssuesEvents *bool `url:"confidential_issues_events,omitempty" json:"confidential_issues_events,omitempty"`
  699. MergeRequestsEvents *bool `url:"merge_requests_events,omitempty" json:"merge_requests_events,omitempty"`
  700. TagPushEvents *bool `url:"tag_push_events,omitempty" json:"tag_push_events,omitempty"`
  701. NoteEvents *bool `url:"note_events,omitempty" json:"note_events,omitempty"`
  702. JobEvents *bool `url:"job_events,omitempty" json:"job_events,omitempty"`
  703. PipelineEvents *bool `url:"pipeline_events,omitempty" json:"pipeline_events,omitempty"`
  704. WikiPageEvents *bool `url:"wiki_page_events,omitempty" json:"wiki_page_events,omitempty"`
  705. EnableSSLVerification *bool `url:"enable_ssl_verification,omitempty" json:"enable_ssl_verification,omitempty"`
  706. Token *string `url:"token,omitempty" json:"token,omitempty"`
  707. }
  708. // AddProjectHook adds a hook to a specified project.
  709. //
  710. // GitLab API docs:
  711. // https://docs.gitlab.com/ce/api/projects.html#add-project-hook
  712. func (s *ProjectsService) AddProjectHook(pid interface{}, opt *AddProjectHookOptions, options ...OptionFunc) (*ProjectHook, *Response, error) {
  713. project, err := parseID(pid)
  714. if err != nil {
  715. return nil, nil, err
  716. }
  717. u := fmt.Sprintf("projects/%s/hooks", url.QueryEscape(project))
  718. req, err := s.client.NewRequest("POST", u, opt, options)
  719. if err != nil {
  720. return nil, nil, err
  721. }
  722. ph := new(ProjectHook)
  723. resp, err := s.client.Do(req, ph)
  724. if err != nil {
  725. return nil, resp, err
  726. }
  727. return ph, resp, err
  728. }
  729. // EditProjectHookOptions represents the available EditProjectHook() options.
  730. //
  731. // GitLab API docs:
  732. // https://docs.gitlab.com/ce/api/projects.html#edit-project-hook
  733. type EditProjectHookOptions struct {
  734. URL *string `url:"url,omitempty" json:"url,omitempty"`
  735. PushEvents *bool `url:"push_events,omitempty" json:"push_events,omitempty"`
  736. IssuesEvents *bool `url:"issues_events,omitempty" json:"issues_events,omitempty"`
  737. ConfidentialIssuesEvents *bool `url:"confidential_issues_events,omitempty" json:"confidential_issues_events,omitempty"`
  738. MergeRequestsEvents *bool `url:"merge_requests_events,omitempty" json:"merge_requests_events,omitempty"`
  739. TagPushEvents *bool `url:"tag_push_events,omitempty" json:"tag_push_events,omitempty"`
  740. NoteEvents *bool `url:"note_events,omitempty" json:"note_events,omitempty"`
  741. JobEvents *bool `url:"job_events,omitempty" json:"job_events,omitempty"`
  742. PipelineEvents *bool `url:"pipeline_events,omitempty" json:"pipeline_events,omitempty"`
  743. WikiPageEvents *bool `url:"wiki_page_events,omitempty" json:"wiki_page_events,omitempty"`
  744. EnableSSLVerification *bool `url:"enable_ssl_verification,omitempty" json:"enable_ssl_verification,omitempty"`
  745. Token *string `url:"token,omitempty" json:"token,omitempty"`
  746. }
  747. // EditProjectHook edits a hook for a specified project.
  748. //
  749. // GitLab API docs:
  750. // https://docs.gitlab.com/ce/api/projects.html#edit-project-hook
  751. func (s *ProjectsService) EditProjectHook(pid interface{}, hook int, opt *EditProjectHookOptions, options ...OptionFunc) (*ProjectHook, *Response, error) {
  752. project, err := parseID(pid)
  753. if err != nil {
  754. return nil, nil, err
  755. }
  756. u := fmt.Sprintf("projects/%s/hooks/%d", url.QueryEscape(project), hook)
  757. req, err := s.client.NewRequest("PUT", u, opt, options)
  758. if err != nil {
  759. return nil, nil, err
  760. }
  761. ph := new(ProjectHook)
  762. resp, err := s.client.Do(req, ph)
  763. if err != nil {
  764. return nil, resp, err
  765. }
  766. return ph, resp, err
  767. }
  768. // DeleteProjectHook removes a hook from a project. This is an idempotent
  769. // method and can be called multiple times. Either the hook is available or not.
  770. //
  771. // GitLab API docs:
  772. // https://docs.gitlab.com/ce/api/projects.html#delete-project-hook
  773. func (s *ProjectsService) DeleteProjectHook(pid interface{}, hook int, options ...OptionFunc) (*Response, error) {
  774. project, err := parseID(pid)
  775. if err != nil {
  776. return nil, err
  777. }
  778. u := fmt.Sprintf("projects/%s/hooks/%d", url.QueryEscape(project), hook)
  779. req, err := s.client.NewRequest("DELETE", u, nil, options)
  780. if err != nil {
  781. return nil, err
  782. }
  783. return s.client.Do(req, nil)
  784. }
  785. // ProjectForkRelation represents a project fork relationship.
  786. //
  787. // GitLab API docs:
  788. // https://docs.gitlab.com/ce/api/projects.html#admin-fork-relation
  789. type ProjectForkRelation struct {
  790. ID int `json:"id"`
  791. ForkedToProjectID int `json:"forked_to_project_id"`
  792. ForkedFromProjectID int `json:"forked_from_project_id"`
  793. CreatedAt *time.Time `json:"created_at"`
  794. UpdatedAt *time.Time `json:"updated_at"`
  795. }
  796. // CreateProjectForkRelation creates a forked from/to relation between
  797. // existing projects.
  798. //
  799. // GitLab API docs:
  800. // https://docs.gitlab.com/ce/api/projects.html#create-a-forked-fromto-relation-between-existing-projects.
  801. func (s *ProjectsService) CreateProjectForkRelation(pid int, fork int, options ...OptionFunc) (*ProjectForkRelation, *Response, error) {
  802. u := fmt.Sprintf("projects/%d/fork/%d", pid, fork)
  803. req, err := s.client.NewRequest("POST", u, nil, options)
  804. if err != nil {
  805. return nil, nil, err
  806. }
  807. pfr := new(ProjectForkRelation)
  808. resp, err := s.client.Do(req, pfr)
  809. if err != nil {
  810. return nil, resp, err
  811. }
  812. return pfr, resp, err
  813. }
  814. // DeleteProjectForkRelation deletes an existing forked from relationship.
  815. //
  816. // GitLab API docs:
  817. // https://docs.gitlab.com/ce/api/projects.html#delete-an-existing-forked-from-relationship
  818. func (s *ProjectsService) DeleteProjectForkRelation(pid int, options ...OptionFunc) (*Response, error) {
  819. u := fmt.Sprintf("projects/%d/fork", pid)
  820. req, err := s.client.NewRequest("DELETE", u, nil, options)
  821. if err != nil {
  822. return nil, err
  823. }
  824. return s.client.Do(req, nil)
  825. }
  826. // ProjectFile represents an uploaded project file
  827. //
  828. // GitLab API docs: https://docs.gitlab.com/ce/api/projects.html#upload-a-file
  829. type ProjectFile struct {
  830. Alt string `json:"alt"`
  831. URL string `json:"url"`
  832. Markdown string `json:"markdown"`
  833. }
  834. // UploadFile upload a file from disk
  835. //
  836. // GitLab API docs: https://docs.gitlab.com/ce/api/projects.html#upload-a-file
  837. func (s *ProjectsService) UploadFile(pid interface{}, file string, options ...OptionFunc) (*ProjectFile, *Response, error) {
  838. project, err := parseID(pid)
  839. if err != nil {
  840. return nil, nil, err
  841. }
  842. u := fmt.Sprintf("projects/%s/uploads", url.QueryEscape(project))
  843. f, err := os.Open(file)
  844. if err != nil {
  845. return nil, nil, err
  846. }
  847. defer f.Close()
  848. b := &bytes.Buffer{}
  849. w := multipart.NewWriter(b)
  850. fw, err := w.CreateFormFile("file", file)
  851. if err != nil {
  852. return nil, nil, err
  853. }
  854. _, err = io.Copy(fw, f)
  855. if err != nil {
  856. return nil, nil, err
  857. }
  858. w.Close()
  859. req, err := s.client.NewRequest("", u, nil, options)
  860. if err != nil {
  861. return nil, nil, err
  862. }
  863. req.Body = ioutil.NopCloser(b)
  864. req.ContentLength = int64(b.Len())
  865. req.Header.Set("Content-Type", w.FormDataContentType())
  866. req.Method = "POST"
  867. uf := &ProjectFile{}
  868. resp, err := s.client.Do(req, uf)
  869. if err != nil {
  870. return nil, resp, err
  871. }
  872. return uf, resp, nil
  873. }
  874. // ListProjectForks gets a list of project forks.
  875. //
  876. // GitLab API docs:
  877. // https://docs.gitlab.com/ce/api/projects.html#list-forks-of-a-project
  878. func (s *ProjectsService) ListProjectForks(pid interface{}, opt *ListProjectsOptions, options ...OptionFunc) ([]*Project, *Response, error) {
  879. project, err := parseID(pid)
  880. if err != nil {
  881. return nil, nil, err
  882. }
  883. u := fmt.Sprintf("projects/%s/forks", url.QueryEscape(project))
  884. req, err := s.client.NewRequest("GET", u, opt, options)
  885. if err != nil {
  886. return nil, nil, err
  887. }
  888. var forks []*Project
  889. resp, err := s.client.Do(req, &forks)
  890. if err != nil {
  891. return nil, resp, err
  892. }
  893. return forks, resp, err
  894. }
  895. // ProjectPushRules represents a project push rule.
  896. //
  897. // GitLab API docs:
  898. // https://docs.gitlab.com/ee/api/projects.html#push-rules
  899. type ProjectPushRules struct {
  900. ID int `json:"id"`
  901. ProjectID int `json:"project_id"`
  902. CommitMessageRegex string `json:"commit_message_regex"`
  903. BranchNameRegex string `json:"branch_name_regex"`
  904. DenyDeleteTag bool `json:"deny_delete_tag"`
  905. CreatedAt *time.Time `json:"created_at"`
  906. MemberCheck bool `json:"member_check"`
  907. PreventSecrets bool `json:"prevent_secrets"`
  908. AuthorEmailRegex string `json:"author_email_regex"`
  909. FileNameRegex string `json:"file_name_regex"`
  910. MaxFileSize int `json:"max_file_size"`
  911. }
  912. // GetProjectPushRules gets the push rules of a project.
  913. //
  914. // GitLab API docs:
  915. // https://docs.gitlab.com/ee/api/projects.html#get-project-push-rules
  916. func (s *ProjectsService) GetProjectPushRules(pid interface{}, options ...OptionFunc) (*ProjectPushRules, *Response, error) {
  917. project, err := parseID(pid)
  918. if err != nil {
  919. return nil, nil, err
  920. }
  921. u := fmt.Sprintf("projects/%s/push_rule", url.QueryEscape(project))
  922. req, err := s.client.NewRequest("GET", u, nil, options)
  923. if err != nil {
  924. return nil, nil, err
  925. }
  926. ppr := new(ProjectPushRules)
  927. resp, err := s.client.Do(req, ppr)
  928. if err != nil {
  929. return nil, resp, err
  930. }
  931. return ppr, resp, err
  932. }
  933. // AddProjectPushRuleOptions represents the available AddProjectPushRule()
  934. // options.
  935. //
  936. // GitLab API docs:
  937. // https://docs.gitlab.com/ee/api/projects.html#add-project-push-rule
  938. type AddProjectPushRuleOptions struct {
  939. DenyDeleteTag *bool `url:"deny_delete_tag,omitempty" json:"deny_delete_tag,omitempty"`
  940. MemberCheck *bool `url:"member_check,omitempty" json:"member_check,omitempty"`
  941. PreventSecrets *bool `url:"prevent_secrets,omitempty" json:"prevent_secrets,omitempty"`
  942. CommitMessageRegex *string `url:"commit_message_regex,omitempty" json:"commit_message_regex,omitempty"`
  943. BranchNameRegex *string `url:"branch_name_regex,omitempty" json:"branch_name_regex,omitempty"`
  944. AuthorEmailRegex *string `url:"author_email_regex,omitempty" json:"author_email_regex,omitempty"`
  945. FileNameRegex *string `url:"file_name_regex,omitempty" json:"file_name_regex,omitempty"`
  946. MaxFileSize *int `url:"max_file_size,omitempty" json:"max_file_size,omitempty"`
  947. }
  948. // AddProjectPushRule adds a push rule to a specified project.
  949. //
  950. // GitLab API docs:
  951. // https://docs.gitlab.com/ee/api/projects.html#add-project-push-rule
  952. func (s *ProjectsService) AddProjectPushRule(pid interface{}, opt *AddProjectPushRuleOptions, options ...OptionFunc) (*ProjectPushRules, *Response, error) {
  953. project, err := parseID(pid)
  954. if err != nil {
  955. return nil, nil, err
  956. }
  957. u := fmt.Sprintf("projects/%s/push_rule", url.QueryEscape(project))
  958. req, err := s.client.NewRequest("POST", u, opt, options)
  959. if err != nil {
  960. return nil, nil, err
  961. }
  962. ppr := new(ProjectPushRules)
  963. resp, err := s.client.Do(req, ppr)
  964. if err != nil {
  965. return nil, resp, err
  966. }
  967. return ppr, resp, err
  968. }
  969. // EditProjectPushRuleOptions represents the available EditProjectPushRule()
  970. // options.
  971. //
  972. // GitLab API docs:
  973. // https://docs.gitlab.com/ee/api/projects.html#edit-project-push-rule
  974. type EditProjectPushRuleOptions struct {
  975. AuthorEmailRegex *string `url:"author_email_regex,omitempty" json:"author_email_regex,omitempty"`
  976. BranchNameRegex *string `url:"branch_name_regex,omitempty" json:"branch_name_regex,omitempty"`
  977. CommitMessageRegex *string `url:"commit_message_regex,omitempty" json:"commit_message_regex,omitempty"`
  978. FileNameRegex *string `url:"file_name_regex,omitempty" json:"file_name_regex,omitempty"`
  979. DenyDeleteTag *bool `url:"deny_delete_tag,omitempty" json:"deny_delete_tag,omitempty"`
  980. MemberCheck *bool `url:"member_check,omitempty" json:"member_check,omitempty"`
  981. PreventSecrets *bool `url:"prevent_secrets,omitempty" json:"prevent_secrets,omitempty"`
  982. MaxFileSize *int `url:"max_file_size,omitempty" json:"max_file_size,omitempty"`
  983. }
  984. // EditProjectPushRule edits a push rule for a specified project.
  985. //
  986. // GitLab API docs:
  987. // https://docs.gitlab.com/ee/api/projects.html#edit-project-push-rule
  988. func (s *ProjectsService) EditProjectPushRule(pid interface{}, opt *EditProjectPushRuleOptions, options ...OptionFunc) (*ProjectPushRules, *Response, error) {
  989. project, err := parseID(pid)
  990. if err != nil {
  991. return nil, nil, err
  992. }
  993. u := fmt.Sprintf("projects/%s/push_rule", url.QueryEscape(project))
  994. req, err := s.client.NewRequest("PUT", u, opt, options)
  995. if err != nil {
  996. return nil, nil, err
  997. }
  998. ppr := new(ProjectPushRules)
  999. resp, err := s.client.Do(req, ppr)
  1000. if err != nil {
  1001. return nil, resp, err
  1002. }
  1003. return ppr, resp, err
  1004. }
  1005. // DeleteProjectPushRule removes a push rule from a project. This is an
  1006. // idempotent method and can be called multiple times. Either the push rule is
  1007. // available or not.
  1008. //
  1009. // GitLab API docs:
  1010. // https://docs.gitlab.com/ee/api/projects.html#delete-project-push-rule
  1011. func (s *ProjectsService) DeleteProjectPushRule(pid interface{}, options ...OptionFunc) (*Response, error) {
  1012. project, err := parseID(pid)
  1013. if err != nil {
  1014. return nil, err
  1015. }
  1016. u := fmt.Sprintf("projects/%s/push_rule", url.QueryEscape(project))
  1017. req, err := s.client.NewRequest("DELETE", u, nil, options)
  1018. if err != nil {
  1019. return nil, err
  1020. }
  1021. return s.client.Do(req, nil)
  1022. }