Skip to content
This repository has been archived by the owner on Jan 24, 2023. It is now read-only.

Fix deploy from gitlab using a group's repo #4479

Merged
merged 1 commit into from
Aug 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
import { Observable, of as observableOf } from 'rxjs';
import { map } from 'rxjs/operators';
import { combineLatest, Observable, of as observableOf, of } from 'rxjs';
import { catchError, map } from 'rxjs/operators';
import { Md5 } from 'ts-md5/dist/md5';

import { GitBranch, GitCommit, GitRepo } from '../../../store/types/git.types';
Expand Down Expand Up @@ -29,19 +29,18 @@ export class GitLabSCM implements GitSCM {
getRepository(httpClient: HttpClient, projectName: string): Observable<GitRepo> {
const parts = projectName.split('/');

let obs$ = httpClient.get(`${gitLabAPIUrl}/users/${parts[0]}/projects?search=${parts[1]}`);
if (parts.length !== 2) {
obs$ = observableOf(null);
}
const obs$ = parts.length !== 2 ?
observableOf(null) :
httpClient.get(`${gitLabAPIUrl}/projects/${parts.join('%2F')}`);

return obs$.pipe(
map((data: any) => {
if (data.length !== 1) {
if (!data) {
throw new HttpErrorResponse({
status: 404
});
}
return this.convertProject(data[0]);
return this.convertProject(data);
})
);
}
Expand Down Expand Up @@ -110,17 +109,25 @@ export class GitLabSCM implements GitSCM {

getMatchingRepositories(httpClient: HttpClient, projectName: string): Observable<string[]> {
const prjParts = projectName.split('/');
let url = `${gitLabAPIUrl}/projects?search=${projectName}`;
if (prjParts.length > 1) {
url = `${gitLabAPIUrl}/users/${prjParts[0]}/projects?search=${prjParts[1]}`;
}
return httpClient.get(url).pipe(
map((repos: any) => {
return repos.map(item => item.path_with_namespace);
})

const obs$ = prjParts.length > 1 ?
this.getMatchingUserGroupRepositories(httpClient, prjParts) :
httpClient.get(`${gitLabAPIUrl}/projects?search=${projectName}`);

return obs$.pipe(
map((repos: any[]) => repos.map(item => item.path_with_namespace)),
);
}

private getMatchingUserGroupRepositories(httpClient: HttpClient, prjParts: string[]): Observable<any[]> {
return combineLatest([
httpClient.get<[]>(`${gitLabAPIUrl}/users/${prjParts[0]}/projects/?search=${prjParts[1]}`).pipe(catchError(() => of([]))),
httpClient.get<[]>(`${gitLabAPIUrl}/groups/${prjParts[0]}/projects?search=${prjParts[1]}`).pipe(catchError(() => of([]))),
]).pipe(
map(([a, b]: [any[], any[]]) => a.concat(b)),
)
}

private convertProject(prj: any): GitRepo {
return {
...prj,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ export function createFailedGithubRequestMessage(error: any, logger: LoggerServi
const response = parseHttpPipeError(error, logger);
const message = response.message || '';
return error.status === 403 && message.startsWith('API rate limit exceeded for') ?
'Github ' + message.substring(0, message.indexOf('(')) :
'Github request failed';
'Git ' + message.substring(0, message.indexOf('(')) :
'Git request failed';
}

@Injectable()
Expand Down