* 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 }) {
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;
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: {
.onboarding-choices {
display: flex;
justify-content: space-around;
- padding: 44px 100px;
+ padding: 44px 170px;
background-color: var(--barBackgroundColor);
margin-top: var(--pagePadding);
}
.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);
}
}
/**
- * 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)
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);
+ });
+}