]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-13001 Add new API helper functions
authorWouter Admiraal <wouter.admiraal@sonarsource.com>
Thu, 30 Jan 2020 13:21:59 +0000 (14:21 +0100)
committerSonarTech <sonartech@sonarsource.com>
Thu, 20 Feb 2020 19:46:15 +0000 (20:46 +0100)
server/sonar-web/src/main/js/api/alm-integrations.ts [new file with mode: 0644]
server/sonar-web/src/main/js/helpers/mocks/alm-integrations.ts [new file with mode: 0644]
server/sonar-web/src/main/js/types/alm-integration.ts [new file with mode: 0644]

diff --git a/server/sonar-web/src/main/js/api/alm-integrations.ts b/server/sonar-web/src/main/js/api/alm-integrations.ts
new file mode 100644 (file)
index 0000000..9e8430a
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+import { get, getJSON, post, postJSON } from 'sonar-ui-common/helpers/request';
+import throwGlobalError from '../app/utils/throwGlobalError';
+import { BitbucketProject, BitbucketRepository } from '../types/alm-integration';
+import { ProjectBase } from './components';
+
+export function setAlmPersonalAccessToken(almSetting: string, pat: string): Promise<void> {
+  return post('/api/alm_integrations/set_pat', { almSetting, pat }).catch(throwGlobalError);
+}
+
+export function checkPersonalAccessTokenIsValid(almSetting: string): Promise<boolean> {
+  return get('/api/alm_integrations/check_pat', { almSetting })
+    .then(() => true)
+    .catch(response => {
+      if (response.status === 400) {
+        return false;
+      } else {
+        return throwGlobalError(response);
+      }
+    });
+}
+
+export function getBitbucketServerProjects(
+  almSetting: string
+): Promise<{ projects: BitbucketProject[] }> {
+  return getJSON('/api/alm_integrations/list_bitbucketserver_projects', { almSetting });
+}
+
+export function getBitbucketServerRepositories(
+  almSetting: string,
+  projectName: string
+): Promise<{
+  isLastPage: boolean;
+  repositories: BitbucketRepository[];
+}> {
+  return getJSON('/api/alm_integrations/search_bitbucketserver_repos', {
+    almSetting,
+    projectName
+  });
+}
+
+export function importBitbucketServerProject(
+  almSetting: string,
+  projectKey: string,
+  repositorySlug: string
+): Promise<{ project: ProjectBase }> {
+  return postJSON('/api/alm_integrations/import_bitbucketserver_project', {
+    almSetting,
+    projectKey,
+    repositorySlug
+  }).catch(throwGlobalError);
+}
diff --git a/server/sonar-web/src/main/js/helpers/mocks/alm-integrations.ts b/server/sonar-web/src/main/js/helpers/mocks/alm-integrations.ts
new file mode 100644 (file)
index 0000000..6e04e48
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+import { BitbucketProject, BitbucketRepository } from '../../types/alm-integration';
+
+export function mockBitbucketProject(overrides: Partial<BitbucketProject> = {}): BitbucketProject {
+  return {
+    id: 1,
+    key: 'project',
+    name: 'Project',
+    ...overrides
+  };
+}
+
+export function mockBitbucketRepository(
+  overrides: Partial<BitbucketRepository> = {}
+): BitbucketRepository {
+  return {
+    id: 1,
+    slug: 'project__repo',
+    name: 'Repo',
+    projectKey: 'project',
+    ...overrides
+  };
+}
diff --git a/server/sonar-web/src/main/js/types/alm-integration.ts b/server/sonar-web/src/main/js/types/alm-integration.ts
new file mode 100644 (file)
index 0000000..e746ef1
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+export interface BitbucketProject {
+  id: number;
+  key: string;
+  name: string;
+}
+
+export interface BitbucketRepository {
+  id: number;
+  name: string;
+  projectKey: string;
+  sqProjectKey?: string;
+  slug: string;
+}
+
+export type BitbucketProjectRepositories = T.Dict<{
+  allShown: boolean;
+  repositories: BitbucketRepository[];
+}>;