Skip to content
This repository has been archived by the owner on May 7, 2021. It is now read-only.

Commit

Permalink
fix(launcher): retry /git/user api call on fail (#3520)
Browse files Browse the repository at this point in the history
* fix(launcher): retry /git/user api call on fail

* fix(launcher): remove extra api call for git orgs
  • Loading branch information
vikram-raj authored and christianvogt committed Feb 25, 2019
1 parent 1203f35 commit fd48778
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 30 deletions.
Expand Up @@ -66,10 +66,6 @@ describe('Service: AppLauncherGitproviderService', () => {
expect(req1.request.method).toBe('GET');
expect(req1.request.headers.get('Authorization')).toEqual('Bearer mock-token');
req1.flush(user);
const req2: TestRequest = controller.expectOne('http://example.com/services/git/organizations');
expect(req2.request.method).toBe('GET');
expect(req2.request.headers.get('Authorization')).toEqual('Bearer mock-token');
req2.flush(orgs);
}));

it('should get user orgs', (done: DoneFn) => {
Expand Down
Expand Up @@ -3,7 +3,7 @@ import { Injectable, Inject } from '@angular/core';
import { GitHubDetails, GitProviderService, HelperService, BuildTool } from 'ngx-launcher';
import { AuthenticationService } from 'ngx-login-client';
import { EMPTY, Observable, of, throwError } from 'rxjs';
import { catchError, map, mergeMap, tap } from 'rxjs/operators';
import { catchError, map, mergeMap, tap, retry } from 'rxjs/operators';

import { cloneDeep } from 'lodash';
import { ProviderService } from '../../../shared/account/provider.service';
Expand Down Expand Up @@ -58,9 +58,10 @@ export class AppLauncherGitproviderService implements GitProviderService {
*/
private getGitHubUserData(): Observable<any> {
const url = `${this.END_POINT + this.API_BASE}user`;
return this.http
.get(url, { headers: this.headers })
.pipe(catchError((error: HttpErrorResponse) => throwError(error)));
return this.http.get(url, { headers: this.headers }).pipe(
retry(3),
catchError((error: HttpErrorResponse) => throwError(error)),
);
}

/**
Expand All @@ -87,28 +88,23 @@ export class AppLauncherGitproviderService implements GitProviderService {
if (user && user.login) {
this.gitHubUserLogin = user.login;
const orgs: { [name: string]: string } = {};
return this.getUserOrgs(user.login).pipe(
mergeMap((orgsArr) => {
if (orgsArr && orgsArr.length >= 0) {
this.repositories[''] = AppLauncherGitproviderService.removeOrganizationPrefix(
user.repositories,
);
for (let i = 0; i < orgsArr.length; i++) {
orgs[orgsArr[i]] = orgsArr[i];
}
orgs[user.login] = undefined;
const gitHubDetails = {
authenticated: true,
avatar: user.avatarUrl,
login: user.login,
organizations: orgs,
repositoryList: this.repositories[''],
} as GitHubDetails;
return of(gitHubDetails);
}
return EMPTY;
}),
);
if (user.organizations && user.organizations.length >= 0) {
this.repositories[''] = AppLauncherGitproviderService.removeOrganizationPrefix(
user.repositories,
);
for (let i = 0; i < user.organizations.length; i++) {
orgs[user.organizations[i]] = user.organizations[i];
}
orgs[user.login] = undefined;
const gitHubDetails = {
authenticated: true,
avatar: user.avatarUrl,
login: user.login,
organizations: orgs,
repositoryList: this.repositories[''],
} as GitHubDetails;
return of(gitHubDetails);
}
}
return EMPTY;
}),
Expand Down

0 comments on commit fd48778

Please sign in to comment.