From: Grégoire Aubert Date: Wed, 12 Dec 2018 08:57:39 +0000 (+0100) Subject: SONARCLOUD-217 Try to fetch the installed alm organization on a longer period of... X-Git-Tag: 7.5~15 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=3a08c1730f3fe248414add8fa57a61c5670e04c9;p=sonarqube.git SONARCLOUD-217 Try to fetch the installed alm organization on a longer period of time --- diff --git a/server/sonar-web/src/main/js/api/alm-integration.ts b/server/sonar-web/src/main/js/api/alm-integration.ts index dd5660065ae..c5d570c4576 100644 --- a/server/sonar-web/src/main/js/api/alm-integration.ts +++ b/server/sonar-web/src/main/js/api/alm-integration.ts @@ -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 { - 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: { diff --git a/server/sonar-web/src/main/js/apps/organizations/components/OrganizationJustCreated.css b/server/sonar-web/src/main/js/apps/organizations/components/OrganizationJustCreated.css index 17bec1f2bca..2779ccbce5c 100644 --- a/server/sonar-web/src/main/js/apps/organizations/components/OrganizationJustCreated.css +++ b/server/sonar-web/src/main/js/apps/organizations/components/OrganizationJustCreated.css @@ -19,5 +19,5 @@ */ .organization-just-created { margin: 120px auto 0; - width: 700px; + width: 800px; } diff --git a/server/sonar-web/src/main/js/apps/tutorials/styles.css b/server/sonar-web/src/main/js/apps/tutorials/styles.css index ae75cc4bca2..90eaeaeaf03 100644 --- a/server/sonar-web/src/main/js/apps/tutorials/styles.css +++ b/server/sonar-web/src/main/js/apps/tutorials/styles.css @@ -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); } diff --git a/server/sonar-web/src/main/js/helpers/request.ts b/server/sonar-web/src/main/js/helpers/request.ts index 1ae4d87dc5a..438275cdc2a 100644 --- a/server/sonar-web/src/main/js/helpers/request.ts +++ b/server/sonar-web/src/main/js/helpers/request.ts @@ -257,7 +257,7 @@ export function post(url: string, data?: RequestData): Promise { } /** - * 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 { return request(url) @@ -273,3 +273,27 @@ export function requestDelete(url: string, data?: RequestData): Promise { export function delay(response: any): Promise { return new Promise(resolve => setTimeout(() => resolve(response), 1200)); } + +export function requestTryAndRepeat( + repeatAPICall: () => Promise, + 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); + }); +}