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-integration.ts 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2018 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 { getJSON, postJSON, post, requestTryAndRepeat } from '../helpers/request';
  21. import throwGlobalError from '../app/utils/throwGlobalError';
  22. export function bindAlmOrganization(data: { installationId: string; organization: string }) {
  23. return post('/api/alm_integration/bind_organization', data).catch(throwGlobalError);
  24. }
  25. export function getAlmAppInfo(): Promise<{ application: T.AlmApplication }> {
  26. return getJSON('/api/alm_integration/show_app_info').catch(throwGlobalError);
  27. }
  28. export interface GetAlmOrganizationResponse {
  29. almOrganization: T.AlmOrganization;
  30. boundOrganization?: T.OrganizationBase;
  31. }
  32. export function getAlmOrganization(data: {
  33. installationId: string;
  34. }): Promise<GetAlmOrganizationResponse> {
  35. return requestTryAndRepeat(() => getJSON('/api/alm_integration/show_organization', data), 25, 20)
  36. .catch(throwGlobalError)
  37. .then(({ almOrganization, boundOrganization }) => ({
  38. almOrganization: {
  39. ...almOrganization,
  40. name: almOrganization.name || almOrganization.key
  41. },
  42. boundOrganization
  43. }));
  44. }
  45. export function getRepositories(data: {
  46. organization: string;
  47. }): Promise<{ repositories: T.AlmRepository[] }> {
  48. return getJSON('/api/alm_integration/list_repositories', data).catch(throwGlobalError);
  49. }
  50. export function listUnboundApplications(): Promise<T.AlmUnboundApplication[]> {
  51. return getJSON('/api/alm_integration/list_unbound_applications').then(
  52. ({ applications }) =>
  53. applications.map((app: T.AlmUnboundApplication) => ({ ...app, name: app.name || app.key })),
  54. throwGlobalError
  55. );
  56. }
  57. export function provisionProject(data: {
  58. installationKeys: string[];
  59. organization: string;
  60. }): Promise<{ projects: Array<{ projectKey: string }> }> {
  61. return postJSON('/api/alm_integration/provision_projects', {
  62. ...data,
  63. installationKeys: data.installationKeys.join(',')
  64. }).catch(throwGlobalError);
  65. }