]> source.dussan.org Git - sonarqube.git/commitdiff
SONARCLOUD-217 Try to fetch the installed alm organization on a longer period of...
authorGrégoire Aubert <gregoire.aubert@sonarsource.com>
Wed, 12 Dec 2018 08:57:39 +0000 (09:57 +0100)
committerSonarTech <sonartech@sonarsource.com>
Thu, 13 Dec 2018 19:21:04 +0000 (20:21 +0100)
server/sonar-web/src/main/js/api/alm-integration.ts
server/sonar-web/src/main/js/apps/organizations/components/OrganizationJustCreated.css
server/sonar-web/src/main/js/apps/tutorials/styles.css
server/sonar-web/src/main/js/helpers/request.ts

index dd5660065aeb898e0d7bbcfc25b7714325bb0da9..c5d570c45766c6f1667739f1455f7f5f346a5168 100644 (file)
@@ -17,7 +17,7 @@
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
-import { getJSON, postJSON, post } from '../helpers/request';
+import { getJSON, postJSON, post, requestTryAndRepeat } from '../helpers/request';
 import throwGlobalError from '../app/utils/throwGlobalError';
 
 export function bindAlmOrganization(data: { installationId: string; organization: string }) {
@@ -28,23 +28,6 @@ export function getAlmAppInfo(): Promise<{ application: T.AlmApplication }> {
   return getJSON('/api/alm_integration/show_app_info').catch(throwGlobalError);
 }
 
-function fetchAlmOrganization(data: { installationId: string }, remainingTries: number) {
-  return getJSON('/api/alm_integration/show_organization', data).catch(
-    (error: { response: Response }) => {
-      remainingTries--;
-      if (error.response.status === 404) {
-        if (remainingTries > 0) {
-          return new Promise(resolve => {
-            setTimeout(() => resolve(fetchAlmOrganization(data, remainingTries)), 500);
-          });
-        }
-        return Promise.reject();
-      }
-      return throwGlobalError(error);
-    }
-  );
-}
-
 export interface GetAlmOrganizationResponse {
   almOrganization: T.AlmOrganization;
   boundOrganization?: T.OrganizationBase;
@@ -53,13 +36,15 @@ export interface GetAlmOrganizationResponse {
 export function getAlmOrganization(data: {
   installationId: string;
 }): Promise<GetAlmOrganizationResponse> {
-  return fetchAlmOrganization(data, 5).then(({ almOrganization, boundOrganization }) => ({
-    almOrganization: {
-      ...almOrganization,
-      name: almOrganization.name || almOrganization.key
-    },
-    boundOrganization
-  }));
+  return requestTryAndRepeat(() => getJSON('/api/alm_integration/show_organization', data), 25, 20)
+    .catch(throwGlobalError)
+    .then(({ almOrganization, boundOrganization }) => ({
+      almOrganization: {
+        ...almOrganization,
+        name: almOrganization.name || almOrganization.key
+      },
+      boundOrganization
+    }));
 }
 
 export function getRepositories(data: {
index 17bec1f2bcaa4957669901c37c7617fa5334b027..2779ccbce5c581ebb26099af540d28e88a3f3e80 100644 (file)
@@ -19,5 +19,5 @@
  */
 .organization-just-created {
   margin: 120px auto 0;
-  width: 700px;
+  width: 800px;
 }
index ae75cc4bca2d4d75dca892456c75ef011be90c2f..90eaeaeaf037084db7888f5989cba73f04ab6fb2 100644 (file)
@@ -62,7 +62,7 @@
 .onboarding-choices {
   display: flex;
   justify-content: space-around;
-  padding: 44px 100px;
+  padding: 44px 170px;
   background-color: var(--barBackgroundColor);
   margin-top: var(--pagePadding);
 }
@@ -99,6 +99,7 @@
 .onboarding-choice:focus,
 .onboarding-choice:active {
   background-color: #fff;
-  box-shadow: 0 10px 30px 0 rgba(0, 0, 0, 0.35);
   color: var(--darkBlue);
+  box-shadow: var(--defaultShadow);
+  transform: translateY(-2px);
 }
index 1ae4d87dc5aa4d626e93b021d34c52a85e6f71bb..438275cdc2a15fff14eebb1c8b3915c6d64b004f 100644 (file)
@@ -257,7 +257,7 @@ export function post(url: string, data?: RequestData): Promise<void> {
 }
 
 /**
- * Shortcut to do a POST request and return response json
+ * Shortcut to do a DELETE request and return response json
  */
 export function requestDelete(url: string, data?: RequestData): Promise<any> {
   return request(url)
@@ -273,3 +273,27 @@ export function requestDelete(url: string, data?: RequestData): Promise<any> {
 export function delay(response: any): Promise<any> {
   return new Promise(resolve => setTimeout(() => resolve(response), 1200));
 }
+
+export function requestTryAndRepeat<T>(
+  repeatAPICall: () => Promise<T>,
+  tries: number,
+  slowTriesThreshold: number,
+  repeatErrors = [404]
+) {
+  return repeatAPICall().catch((error: { response: Response }) => {
+    if (repeatErrors.includes(error.response.status)) {
+      tries--;
+      if (tries > 0) {
+        return new Promise(resolve => {
+          setTimeout(
+            () =>
+              resolve(requestTryAndRepeat(repeatAPICall, tries, slowTriesThreshold, repeatErrors)),
+            tries > slowTriesThreshold ? 500 : 3000
+          );
+        });
+      }
+      return Promise.reject();
+    }
+    return Promise.reject(error);
+  });
+}