services.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  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. "fmt"
  19. "net/url"
  20. "time"
  21. )
  22. // ServicesService handles communication with the services related methods of
  23. // the GitLab API.
  24. //
  25. // GitLab API docs: https://docs.gitlab.com/ce/api/services.html
  26. type ServicesService struct {
  27. client *Client
  28. }
  29. // Service represents a GitLab service.
  30. //
  31. // GitLab API docs: https://docs.gitlab.com/ce/api/services.html
  32. type Service struct {
  33. ID int `json:"id"`
  34. Title string `json:"title"`
  35. CreatedAt *time.Time `json:"created_at"`
  36. UpdatedAt *time.Time `json:"updated_at"`
  37. Active bool `json:"active"`
  38. PushEvents bool `json:"push_events"`
  39. IssuesEvents bool `json:"issues_events"`
  40. ConfidentialIssuesEvents bool `json:"confidential_issues_events"`
  41. MergeRequestsEvents bool `json:"merge_requests_events"`
  42. TagPushEvents bool `json:"tag_push_events"`
  43. NoteEvents bool `json:"note_events"`
  44. ConfidentialNoteEvents bool `json:"confidential_note_events"`
  45. PipelineEvents bool `json:"pipeline_events"`
  46. JobEvents bool `json:"job_events"`
  47. WikiPageEvents bool `json:"wiki_page_events"`
  48. }
  49. // SetGitLabCIServiceOptions represents the available SetGitLabCIService()
  50. // options.
  51. //
  52. // GitLab API docs:
  53. // https://docs.gitlab.com/ce/api/services.html#edit-gitlab-ci-service
  54. type SetGitLabCIServiceOptions struct {
  55. Token *string `url:"token,omitempty" json:"token,omitempty"`
  56. ProjectURL *string `url:"project_url,omitempty" json:"project_url,omitempty"`
  57. }
  58. // SetGitLabCIService sets GitLab CI service for a project.
  59. //
  60. // GitLab API docs:
  61. // https://docs.gitlab.com/ce/api/services.html#edit-gitlab-ci-service
  62. func (s *ServicesService) SetGitLabCIService(pid interface{}, opt *SetGitLabCIServiceOptions, options ...OptionFunc) (*Response, error) {
  63. project, err := parseID(pid)
  64. if err != nil {
  65. return nil, err
  66. }
  67. u := fmt.Sprintf("projects/%s/services/gitlab-ci", url.QueryEscape(project))
  68. req, err := s.client.NewRequest("PUT", u, opt, options)
  69. if err != nil {
  70. return nil, err
  71. }
  72. return s.client.Do(req, nil)
  73. }
  74. // DeleteGitLabCIService deletes GitLab CI service settings for a project.
  75. //
  76. // GitLab API docs:
  77. // https://docs.gitlab.com/ce/api/services.html#delete-gitlab-ci-service
  78. func (s *ServicesService) DeleteGitLabCIService(pid interface{}, options ...OptionFunc) (*Response, error) {
  79. project, err := parseID(pid)
  80. if err != nil {
  81. return nil, err
  82. }
  83. u := fmt.Sprintf("projects/%s/services/gitlab-ci", url.QueryEscape(project))
  84. req, err := s.client.NewRequest("DELETE", u, nil, options)
  85. if err != nil {
  86. return nil, err
  87. }
  88. return s.client.Do(req, nil)
  89. }
  90. // SetHipChatServiceOptions represents the available SetHipChatService()
  91. // options.
  92. //
  93. // GitLab API docs:
  94. // https://docs.gitlab.com/ce/api/services.html#edit-hipchat-service
  95. type SetHipChatServiceOptions struct {
  96. Token *string `url:"token,omitempty" json:"token,omitempty" `
  97. Room *string `url:"room,omitempty" json:"room,omitempty"`
  98. }
  99. // SetHipChatService sets HipChat service for a project
  100. //
  101. // GitLab API docs:
  102. // https://docs.gitlab.com/ce/api/services.html#edit-hipchat-service
  103. func (s *ServicesService) SetHipChatService(pid interface{}, opt *SetHipChatServiceOptions, options ...OptionFunc) (*Response, error) {
  104. project, err := parseID(pid)
  105. if err != nil {
  106. return nil, err
  107. }
  108. u := fmt.Sprintf("projects/%s/services/hipchat", url.QueryEscape(project))
  109. req, err := s.client.NewRequest("PUT", u, opt, options)
  110. if err != nil {
  111. return nil, err
  112. }
  113. return s.client.Do(req, nil)
  114. }
  115. // DeleteHipChatService deletes HipChat service for project.
  116. //
  117. // GitLab API docs:
  118. // https://docs.gitlab.com/ce/api/services.html#delete-hipchat-service
  119. func (s *ServicesService) DeleteHipChatService(pid interface{}, options ...OptionFunc) (*Response, error) {
  120. project, err := parseID(pid)
  121. if err != nil {
  122. return nil, err
  123. }
  124. u := fmt.Sprintf("projects/%s/services/hipchat", url.QueryEscape(project))
  125. req, err := s.client.NewRequest("DELETE", u, nil, options)
  126. if err != nil {
  127. return nil, err
  128. }
  129. return s.client.Do(req, nil)
  130. }
  131. // DroneCIService represents Drone CI service settings.
  132. //
  133. // GitLab API docs:
  134. // https://docs.gitlab.com/ce/api/services.html#drone-ci
  135. type DroneCIService struct {
  136. Service
  137. Properties *DroneCIServiceProperties `json:"properties"`
  138. }
  139. // DroneCIServiceProperties represents Drone CI specific properties.
  140. //
  141. // GitLab API docs:
  142. // https://docs.gitlab.com/ce/api/services.html#drone-ci
  143. type DroneCIServiceProperties struct {
  144. Token string `json:"token"`
  145. DroneURL string `json:"drone_url"`
  146. EnableSSLVerification bool `json:"enable_ssl_verification"`
  147. }
  148. // GetDroneCIService gets Drone CI service settings for a project.
  149. //
  150. // GitLab API docs:
  151. // https://docs.gitlab.com/ce/api/services.html#get-drone-ci-service-settings
  152. func (s *ServicesService) GetDroneCIService(pid interface{}, options ...OptionFunc) (*DroneCIService, *Response, error) {
  153. project, err := parseID(pid)
  154. if err != nil {
  155. return nil, nil, err
  156. }
  157. u := fmt.Sprintf("projects/%s/services/drone-ci", url.QueryEscape(project))
  158. req, err := s.client.NewRequest("GET", u, nil, options)
  159. if err != nil {
  160. return nil, nil, err
  161. }
  162. svc := new(DroneCIService)
  163. resp, err := s.client.Do(req, svc)
  164. if err != nil {
  165. return nil, resp, err
  166. }
  167. return svc, resp, err
  168. }
  169. // SetDroneCIServiceOptions represents the available SetDroneCIService()
  170. // options.
  171. //
  172. // GitLab API docs:
  173. // https://docs.gitlab.com/ce/api/services.html#createedit-drone-ci-service
  174. type SetDroneCIServiceOptions struct {
  175. Token *string `url:"token" json:"token" `
  176. DroneURL *string `url:"drone_url" json:"drone_url"`
  177. EnableSSLVerification *bool `url:"enable_ssl_verification,omitempty" json:"enable_ssl_verification,omitempty"`
  178. }
  179. // SetDroneCIService sets Drone CI service for a project.
  180. //
  181. // GitLab API docs:
  182. // https://docs.gitlab.com/ce/api/services.html#createedit-drone-ci-service
  183. func (s *ServicesService) SetDroneCIService(pid interface{}, opt *SetDroneCIServiceOptions, options ...OptionFunc) (*Response, error) {
  184. project, err := parseID(pid)
  185. if err != nil {
  186. return nil, err
  187. }
  188. u := fmt.Sprintf("projects/%s/services/drone-ci", url.QueryEscape(project))
  189. req, err := s.client.NewRequest("PUT", u, opt, options)
  190. if err != nil {
  191. return nil, err
  192. }
  193. return s.client.Do(req, nil)
  194. }
  195. // DeleteDroneCIService deletes Drone CI service settings for a project.
  196. //
  197. // GitLab API docs:
  198. // https://docs.gitlab.com/ce/api/services.html#delete-drone-ci-service
  199. func (s *ServicesService) DeleteDroneCIService(pid interface{}, options ...OptionFunc) (*Response, error) {
  200. project, err := parseID(pid)
  201. if err != nil {
  202. return nil, err
  203. }
  204. u := fmt.Sprintf("projects/%s/services/drone-ci", url.QueryEscape(project))
  205. req, err := s.client.NewRequest("DELETE", u, nil, options)
  206. if err != nil {
  207. return nil, err
  208. }
  209. return s.client.Do(req, nil)
  210. }
  211. // SlackService represents Slack service settings.
  212. //
  213. // GitLab API docs:
  214. // https://docs.gitlab.com/ce/api/services.html#slack
  215. type SlackService struct {
  216. Service
  217. Properties *SlackServiceProperties `json:"properties"`
  218. }
  219. // SlackServiceProperties represents Slack specific properties.
  220. //
  221. // GitLab API docs:
  222. // https://docs.gitlab.com/ce/api/services.html#slack
  223. type SlackServiceProperties struct {
  224. // Note: NotifyOnlyBrokenPipelines and NotifyOnlyDefaultBranch are not
  225. // just "bool" because in some cases gitlab returns
  226. // "notify_only_broken_pipelines": true, and in other cases
  227. // "notify_only_broken_pipelines": "1". The same is for
  228. // "notify_only_default_branch" field.
  229. // We need to handle this, until the bug will be fixed.
  230. // Ref: https://gitlab.com/gitlab-org/gitlab-ce/issues/50122
  231. NotifyOnlyBrokenPipelines BoolValue `url:"notify_only_broken_pipelines,omitempty" json:"notify_only_broken_pipelines,omitempty"`
  232. NotifyOnlyDefaultBranch BoolValue `url:"notify_only_default_branch,omitempty" json:"notify_only_default_branch,omitempty"`
  233. WebHook string `url:"webhook,omitempty" json:"webhook,omitempty"`
  234. Username string `url:"username,omitempty" json:"username,omitempty"`
  235. Channel string `url:"channel,omitempty" json:"channel,omitempty"`
  236. PushChannel string `url:"push_channel,omitempty" json:"push_channel,omitempty"`
  237. IssueChannel string `url:"issue_channel,omitempty" json:"issue_channel,omitempty"`
  238. ConfidentialIssueChannel string `url:"confidential_issue_channel,omitempty" json:"confidential_issue_channel,omitempty"`
  239. MergeRequestChannel string `url:"merge_request_channel,omitempty" json:"merge_request_channel,omitempty"`
  240. NoteChannel string `url:"note_channel,omitempty" json:"note_channel,omitempty"`
  241. ConfidentialNoteChannel string `url:"confidential_note_channel,omitempty" json:"confidential_note_channel,omitempty"`
  242. TagPushChannel string `url:"tag_push_channel,omitempty" json:"tag_push_channel,omitempty"`
  243. PipelineChannel string `url:"pipeline_channel,omitempty" json:"pipeline_channel,omitempty"`
  244. WikiPageChannel string `url:"wiki_page_channel,omitempty" json:"wiki_page_channel,omitempty"`
  245. }
  246. // GetSlackService gets Slack service settings for a project.
  247. //
  248. // GitLab API docs:
  249. // https://docs.gitlab.com/ce/api/services.html#get-slack-service-settings
  250. func (s *ServicesService) GetSlackService(pid interface{}, options ...OptionFunc) (*SlackService, *Response, error) {
  251. project, err := parseID(pid)
  252. if err != nil {
  253. return nil, nil, err
  254. }
  255. u := fmt.Sprintf("projects/%s/services/slack", url.QueryEscape(project))
  256. req, err := s.client.NewRequest("GET", u, nil, options)
  257. if err != nil {
  258. return nil, nil, err
  259. }
  260. svc := new(SlackService)
  261. resp, err := s.client.Do(req, svc)
  262. if err != nil {
  263. return nil, resp, err
  264. }
  265. return svc, resp, err
  266. }
  267. // SetSlackServiceOptions represents the available SetSlackService()
  268. // options.
  269. //
  270. // GitLab API docs:
  271. // https://docs.gitlab.com/ce/api/services.html#edit-slack-service
  272. type SetSlackServiceOptions struct {
  273. WebHook *string `url:"webhook,omitempty" json:"webhook,omitempty"`
  274. Username *string `url:"username,omitempty" json:"username,omitempty"`
  275. Channel *string `url:"channel,omitempty" json:"channel,omitempty"`
  276. NotifyOnlyBrokenPipelines *bool `url:"notify_only_broken_pipelines,omitempty" json:"notify_only_broken_pipelines,omitempty"`
  277. NotifyOnlyDefaultBranch *bool `url:"notify_only_default_branch,omitempty" json:"notify_only_default_branch,omitempty"`
  278. PushEvents *bool `url:"push_events,omitempty" json:"push_events,omitempty"`
  279. PushChannel *string `url:"push_channel,omitempty" json:"push_channel,omitempty"`
  280. IssuesEvents *bool `url:"issues_events,omitempty" json:"issues_events,omitempty"`
  281. IssueChannel *string `url:"issue_channel,omitempty" json:"issue_channel,omitempty"`
  282. ConfidentialIssuesEvents *bool `url:"confidential_issues_events,omitempty" json:"confidential_issues_events,omitempty"`
  283. ConfidentialIssueChannel *string `url:"confidential_issue_channel,omitempty" json:"confidential_issue_channel,omitempty"`
  284. MergeRequestsEvents *bool `url:"merge_requests_events,omitempty" json:"merge_requests_events,omitempty"`
  285. MergeRequestChannel *string `url:"merge_request_channel,omitempty" json:"merge_request_channel,omitempty"`
  286. TagPushEvents *bool `url:"tag_push_events,omitempty" json:"tag_push_events,omitempty"`
  287. TagPushChannel *string `url:"tag_push_channel,omitempty" json:"tag_push_channel,omitempty"`
  288. NoteEvents *bool `url:"note_events,omitempty" json:"note_events,omitempty"`
  289. NoteChannel *string `url:"note_channel,omitempty" json:"note_channel,omitempty"`
  290. ConfidentialNoteEvents *bool `url:"confidential_note_events" json:"confidential_note_events"`
  291. // TODO: Currently, GitLab ignores this option (not implemented yet?), so
  292. // there is no way to set it. Uncomment when this is fixed.
  293. // See: https://gitlab.com/gitlab-org/gitlab-ce/issues/49730
  294. //ConfidentialNoteChannel *string `json:"confidential_note_channel,omitempty"`
  295. PipelineEvents *bool `url:"pipeline_events,omitempty" json:"pipeline_events,omitempty"`
  296. PipelineChannel *string `url:"pipeline_channel,omitempty" json:"pipeline_channel,omitempty"`
  297. WikiPageChannel *string `url:"wiki_page_channel,omitempty" json:"wiki_page_channel,omitempty"`
  298. WikiPageEvents *bool `url:"wiki_page_events" json:"wiki_page_events"`
  299. }
  300. // SetSlackService sets Slack service for a project
  301. //
  302. // GitLab API docs:
  303. // https://docs.gitlab.com/ce/api/services.html#edit-slack-service
  304. func (s *ServicesService) SetSlackService(pid interface{}, opt *SetSlackServiceOptions, options ...OptionFunc) (*Response, error) {
  305. project, err := parseID(pid)
  306. if err != nil {
  307. return nil, err
  308. }
  309. u := fmt.Sprintf("projects/%s/services/slack", url.QueryEscape(project))
  310. req, err := s.client.NewRequest("PUT", u, opt, options)
  311. if err != nil {
  312. return nil, err
  313. }
  314. return s.client.Do(req, nil)
  315. }
  316. // DeleteSlackService deletes Slack service for project.
  317. //
  318. // GitLab API docs:
  319. // https://docs.gitlab.com/ce/api/services.html#delete-slack-service
  320. func (s *ServicesService) DeleteSlackService(pid interface{}, options ...OptionFunc) (*Response, error) {
  321. project, err := parseID(pid)
  322. if err != nil {
  323. return nil, err
  324. }
  325. u := fmt.Sprintf("projects/%s/services/slack", url.QueryEscape(project))
  326. req, err := s.client.NewRequest("DELETE", u, nil, options)
  327. if err != nil {
  328. return nil, err
  329. }
  330. return s.client.Do(req, nil)
  331. }
  332. // JiraService represents Jira service settings.
  333. //
  334. // GitLab API docs:
  335. // https://docs.gitlab.com/ce/api/services.html#jira
  336. type JiraService struct {
  337. Service
  338. Properties *JiraServiceProperties `json:"properties"`
  339. }
  340. // JiraServiceProperties represents Jira specific properties.
  341. //
  342. // GitLab API docs:
  343. // https://docs.gitlab.com/ce/api/services.html#jira
  344. type JiraServiceProperties struct {
  345. URL *string `url:"url,omitempty" json:"url,omitempty"`
  346. ProjectKey *string `url:"project_key,omitempty" json:"project_key,omitempty" `
  347. Username *string `url:"username,omitempty" json:"username,omitempty" `
  348. Password *string `url:"password,omitempty" json:"password,omitempty" `
  349. JiraIssueTransitionID *string `url:"jira_issue_transition_id,omitempty" json:"jira_issue_transition_id,omitempty"`
  350. }
  351. // GetJiraService gets Jira service settings for a project.
  352. //
  353. // GitLab API docs:
  354. // https://docs.gitlab.com/ce/api/services.html#get-jira-service-settings
  355. func (s *ServicesService) GetJiraService(pid interface{}, options ...OptionFunc) (*JiraService, *Response, error) {
  356. project, err := parseID(pid)
  357. if err != nil {
  358. return nil, nil, err
  359. }
  360. u := fmt.Sprintf("projects/%s/services/jira", url.QueryEscape(project))
  361. req, err := s.client.NewRequest("GET", u, nil, options)
  362. if err != nil {
  363. return nil, nil, err
  364. }
  365. svc := new(JiraService)
  366. resp, err := s.client.Do(req, svc)
  367. if err != nil {
  368. return nil, resp, err
  369. }
  370. return svc, resp, err
  371. }
  372. // SetJiraServiceOptions represents the available SetJiraService()
  373. // options.
  374. //
  375. // GitLab API docs:
  376. // https://docs.gitlab.com/ce/api/services.html#edit-jira-service
  377. type SetJiraServiceOptions JiraServiceProperties
  378. // SetJiraService sets Jira service for a project
  379. //
  380. // GitLab API docs:
  381. // https://docs.gitlab.com/ce/api/services.html#edit-jira-service
  382. func (s *ServicesService) SetJiraService(pid interface{}, opt *SetJiraServiceOptions, options ...OptionFunc) (*Response, error) {
  383. project, err := parseID(pid)
  384. if err != nil {
  385. return nil, err
  386. }
  387. u := fmt.Sprintf("projects/%s/services/jira", url.QueryEscape(project))
  388. req, err := s.client.NewRequest("PUT", u, opt, options)
  389. if err != nil {
  390. return nil, err
  391. }
  392. return s.client.Do(req, nil)
  393. }
  394. // DeleteJiraService deletes Jira service for project.
  395. //
  396. // GitLab API docs:
  397. // https://docs.gitlab.com/ce/api/services.html#delete-jira-service
  398. func (s *ServicesService) DeleteJiraService(pid interface{}, options ...OptionFunc) (*Response, error) {
  399. project, err := parseID(pid)
  400. if err != nil {
  401. return nil, err
  402. }
  403. u := fmt.Sprintf("projects/%s/services/jira", url.QueryEscape(project))
  404. req, err := s.client.NewRequest("DELETE", u, nil, options)
  405. if err != nil {
  406. return nil, err
  407. }
  408. return s.client.Do(req, nil)
  409. }
  410. // JenkinsCIService represents Jenkins CI service settings.
  411. //
  412. // GitLab API docs:
  413. // https://docs.gitlab.com/ee/api/services.html#jenkins-ci
  414. type JenkinsCIService struct {
  415. Service
  416. Properties *JenkinsCIServiceProperties `json:"properties"`
  417. }
  418. // JenkinsCIServiceProperties represents Jenkins CI specific properties.
  419. //
  420. // GitLab API docs:
  421. // https://docs.gitlab.com/ee/api/services.html#jenkins-ci
  422. type JenkinsCIServiceProperties struct {
  423. URL *string `url:"jenkins_url,omitempty" json:"jenkins_url,omitempty"`
  424. ProjectName *string `url:"project_name,omitempty" json:"project_name,omitempty"`
  425. Username *string `url:"username,omitempty" json:"username,omitempty"`
  426. }
  427. // GetJenkinsCIService gets Jenkins CI service settings for a project.
  428. //
  429. // GitLab API docs:
  430. // https://docs.gitlab.com/ee/api/services.html#get-jenkins-ci-service-settings
  431. func (s *ServicesService) GetJenkinsCIService(pid interface{}, options ...OptionFunc) (*JenkinsCIService, *Response, error) {
  432. project, err := parseID(pid)
  433. if err != nil {
  434. return nil, nil, err
  435. }
  436. u := fmt.Sprintf("projects/%s/services/jenkins", url.QueryEscape(project))
  437. req, err := s.client.NewRequest("GET", u, nil, options)
  438. if err != nil {
  439. return nil, nil, err
  440. }
  441. svc := new(JenkinsCIService)
  442. resp, err := s.client.Do(req, svc)
  443. if err != nil {
  444. return nil, resp, err
  445. }
  446. return svc, resp, err
  447. }
  448. // SetJenkinsCIServiceOptions represents the available SetJenkinsCIService()
  449. // options.
  450. //
  451. // GitLab API docs:
  452. // https://docs.gitlab.com/ee/api/services.html#jenkins-ci
  453. type SetJenkinsCIServiceOptions struct {
  454. URL *string `url:"jenkins_url,omitempty" json:"jenkins_url,omitempty"`
  455. ProjectName *string `url:"project_name,omitempty" json:"project_name,omitempty"`
  456. Username *string `url:"username,omitempty" json:"username,omitempty"`
  457. Password *string `url:"password,omitempty" json:"password,omitempty"`
  458. }
  459. // SetJenkinsCIService sets Jenkins service for a project
  460. //
  461. // GitLab API docs:
  462. // https://docs.gitlab.com/ee/api/services.html#create-edit-jenkins-ci-service
  463. func (s *ServicesService) SetJenkinsCIService(pid interface{}, opt *SetJenkinsCIServiceOptions, options ...OptionFunc) (*Response, error) {
  464. project, err := parseID(pid)
  465. if err != nil {
  466. return nil, err
  467. }
  468. u := fmt.Sprintf("projects/%s/services/jenkins", url.QueryEscape(project))
  469. req, err := s.client.NewRequest("PUT", u, opt, options)
  470. if err != nil {
  471. return nil, err
  472. }
  473. return s.client.Do(req, nil)
  474. }
  475. // DeleteJenkinsCIService deletes Jenkins CI service for project.
  476. //
  477. // GitLab API docs:
  478. // https://docs.gitlab.com/ce/api/services.html#delete-jira-service
  479. func (s *ServicesService) DeleteJenkinsCIService(pid interface{}, options ...OptionFunc) (*Response, error) {
  480. project, err := parseID(pid)
  481. if err != nil {
  482. return nil, err
  483. }
  484. u := fmt.Sprintf("projects/%s/services/jenkins", url.QueryEscape(project))
  485. req, err := s.client.NewRequest("DELETE", u, nil, options)
  486. if err != nil {
  487. return nil, err
  488. }
  489. return s.client.Do(req, nil)
  490. }
  491. // MicrosoftTeamsService represents Microsoft Teams service settings.
  492. //
  493. // GitLab API docs:
  494. // https://docs.gitlab.com/ce/api/services.html#microsoft-teams
  495. type MicrosoftTeamsService struct {
  496. Service
  497. Properties *MicrosoftTeamsServiceProperties `json:"properties"`
  498. }
  499. // MicrosoftTeamsServiceProperties represents Microsoft Teams specific properties.
  500. //
  501. // GitLab API docs:
  502. // https://docs.gitlab.com/ce/api/services.html#microsoft-teams
  503. type MicrosoftTeamsServiceProperties struct {
  504. WebHook string `json:"webhook"`
  505. }
  506. // GetMicrosoftTeamsService gets MicrosoftTeams service settings for a project.
  507. //
  508. // GitLab API docs:
  509. // https://docs.gitlab.com/ce/api/services.html#get-microsoft-teams-service-settings
  510. func (s *ServicesService) GetMicrosoftTeamsService(pid interface{}, options ...OptionFunc) (*MicrosoftTeamsService, *Response, error) {
  511. project, err := parseID(pid)
  512. if err != nil {
  513. return nil, nil, err
  514. }
  515. u := fmt.Sprintf("projects/%s/services/microsoft-teams", url.QueryEscape(project))
  516. req, err := s.client.NewRequest("GET", u, nil, options)
  517. if err != nil {
  518. return nil, nil, err
  519. }
  520. svc := new(MicrosoftTeamsService)
  521. resp, err := s.client.Do(req, svc)
  522. if err != nil {
  523. return nil, resp, err
  524. }
  525. return svc, resp, err
  526. }
  527. // SetMicrosoftTeamsServiceOptions represents the available SetMicrosoftTeamsService()
  528. // options.
  529. //
  530. // GitLab API docs:
  531. // https://docs.gitlab.com/ce/api/services.html#create-edit-microsoft-teams-service
  532. type SetMicrosoftTeamsServiceOptions struct {
  533. WebHook *string `url:"webhook,omitempty" json:"webhook,omitempty"`
  534. }
  535. // SetMicrosoftTeamsService sets Microsoft Teams service for a project
  536. //
  537. // GitLab API docs:
  538. // https://docs.gitlab.com/ce/api/services.html#create-edit-microsoft-teams-service
  539. func (s *ServicesService) SetMicrosoftTeamsService(pid interface{}, opt *SetMicrosoftTeamsServiceOptions, options ...OptionFunc) (*Response, error) {
  540. project, err := parseID(pid)
  541. if err != nil {
  542. return nil, err
  543. }
  544. u := fmt.Sprintf("projects/%s/services/microsoft-teams", url.QueryEscape(project))
  545. req, err := s.client.NewRequest("PUT", u, opt, options)
  546. if err != nil {
  547. return nil, err
  548. }
  549. return s.client.Do(req, nil)
  550. }
  551. // DeleteMicrosoftTeamsService deletes Microsoft Teams service for project.
  552. //
  553. // GitLab API docs:
  554. // https://docs.gitlab.com/ce/api/services.html#delete-microsoft-teams-service
  555. func (s *ServicesService) DeleteMicrosoftTeamsService(pid interface{}, options ...OptionFunc) (*Response, error) {
  556. project, err := parseID(pid)
  557. if err != nil {
  558. return nil, err
  559. }
  560. u := fmt.Sprintf("projects/%s/services/microsoft-teams", url.QueryEscape(project))
  561. req, err := s.client.NewRequest("DELETE", u, nil, options)
  562. if err != nil {
  563. return nil, err
  564. }
  565. return s.client.Do(req, nil)
  566. }