You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

alm-settings.ts 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2021 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. import throwGlobalError from '../app/utils/throwGlobalError';
  21. import { get, getJSON, HttpStatus, parseError, parseJSON, post } from '../helpers/request';
  22. import {
  23. AlmSettingsBindingDefinitions,
  24. AlmSettingsInstance,
  25. AzureBindingDefinition,
  26. AzureProjectAlmBindingParams,
  27. BitbucketCloudBindingDefinition,
  28. BitbucketCloudProjectAlmBindingParams,
  29. BitbucketProjectAlmBindingParams,
  30. BitbucketServerBindingDefinition,
  31. GithubBindingDefinition,
  32. GithubProjectAlmBindingParams,
  33. GitlabBindingDefinition,
  34. GitlabProjectAlmBindingParams,
  35. ProjectAlmBindingConfigurationErrors,
  36. ProjectAlmBindingResponse
  37. } from '../types/alm-settings';
  38. export function getAlmDefinitions(): Promise<AlmSettingsBindingDefinitions> {
  39. return getJSON('/api/alm_settings/list_definitions');
  40. }
  41. export function getAlmSettings(project?: string): Promise<AlmSettingsInstance[]> {
  42. return getAlmSettingsNoCatch(project).catch(throwGlobalError);
  43. }
  44. export function getAlmSettingsNoCatch(project?: string): Promise<AlmSettingsInstance[]> {
  45. return getJSON('/api/alm_settings/list', { project }).then(({ almSettings }) => almSettings);
  46. }
  47. export function validateAlmSettings(key: string): Promise<string> {
  48. return get('/api/alm_settings/validate', { key })
  49. .then(() => {
  50. return '';
  51. })
  52. .catch((response: Response) => {
  53. if (response.status === HttpStatus.BadRequest) {
  54. return parseError(response);
  55. } else {
  56. return throwGlobalError(response);
  57. }
  58. });
  59. }
  60. export function createGithubConfiguration(data: GithubBindingDefinition) {
  61. return post('/api/alm_settings/create_github', data).catch(throwGlobalError);
  62. }
  63. export function updateGithubConfiguration(data: GithubBindingDefinition & { newKey: string }) {
  64. return post('/api/alm_settings/update_github', data).catch(throwGlobalError);
  65. }
  66. export function createAzureConfiguration(data: AzureBindingDefinition) {
  67. return post('/api/alm_settings/create_azure', data).catch(throwGlobalError);
  68. }
  69. export function updateAzureConfiguration(data: AzureBindingDefinition & { newKey: string }) {
  70. return post('/api/alm_settings/update_azure', data).catch(throwGlobalError);
  71. }
  72. export function createBitbucketServerConfiguration(data: BitbucketServerBindingDefinition) {
  73. return post('/api/alm_settings/create_bitbucket', data).catch(throwGlobalError);
  74. }
  75. export function updateBitbucketServerConfiguration(
  76. data: BitbucketServerBindingDefinition & { newKey: string }
  77. ) {
  78. return post('/api/alm_settings/update_bitbucket', data).catch(throwGlobalError);
  79. }
  80. export function createBitbucketCloudConfiguration(data: BitbucketCloudBindingDefinition) {
  81. return post('/api/alm_settings/create_bitbucketcloud', data).catch(throwGlobalError);
  82. }
  83. export function updateBitbucketCloudConfiguration(
  84. data: BitbucketCloudBindingDefinition & { newKey: string }
  85. ) {
  86. return post('/api/alm_settings/update_bitbucketcloud', data).catch(throwGlobalError);
  87. }
  88. export function createGitlabConfiguration(data: GitlabBindingDefinition) {
  89. return post('/api/alm_settings/create_gitlab', data).catch(throwGlobalError);
  90. }
  91. export function updateGitlabConfiguration(data: GitlabBindingDefinition & { newKey: string }) {
  92. return post('/api/alm_settings/update_gitlab', data).catch(throwGlobalError);
  93. }
  94. export function deleteConfiguration(key: string) {
  95. return post('/api/alm_settings/delete', { key }).catch(throwGlobalError);
  96. }
  97. export function countBindedProjects(almSetting: string) {
  98. return getJSON('/api/alm_settings/count_binding', { almSetting })
  99. .then(({ projects }) => projects)
  100. .catch(throwGlobalError);
  101. }
  102. export function getProjectAlmBinding(project: string): Promise<ProjectAlmBindingResponse> {
  103. return getJSON('/api/alm_settings/get_binding', { project });
  104. }
  105. export function deleteProjectAlmBinding(project: string): Promise<void> {
  106. return post('/api/alm_settings/delete_binding', { project }).catch(throwGlobalError);
  107. }
  108. export function setProjectAzureBinding(data: AzureProjectAlmBindingParams) {
  109. return post('/api/alm_settings/set_azure_binding', data).catch(throwGlobalError);
  110. }
  111. export function setProjectBitbucketBinding(data: BitbucketProjectAlmBindingParams) {
  112. return post('/api/alm_settings/set_bitbucket_binding', data).catch(throwGlobalError);
  113. }
  114. export function setProjectBitbucketCloudBinding(data: BitbucketCloudProjectAlmBindingParams) {
  115. return post('/api/alm_settings/set_bitbucketcloud_binding', data).catch(throwGlobalError);
  116. }
  117. export function setProjectGithubBinding(data: GithubProjectAlmBindingParams) {
  118. return post('/api/alm_settings/set_github_binding', data).catch(throwGlobalError);
  119. }
  120. export function setProjectGitlabBinding(data: GitlabProjectAlmBindingParams) {
  121. return post('/api/alm_settings/set_gitlab_binding', data).catch(throwGlobalError);
  122. }
  123. export function validateProjectAlmBinding(
  124. projectKey: string
  125. ): Promise<ProjectAlmBindingConfigurationErrors | undefined> {
  126. return get('/api/alm_settings/validate_binding', { project: projectKey })
  127. .then(() => undefined)
  128. .catch((response: Response) => {
  129. if (response.status === HttpStatus.BadRequest) {
  130. return parseJSON(response);
  131. }
  132. return throwGlobalError(response);
  133. });
  134. }