Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getGitReposInFolder: fix async folder filtering #311

Merged
merged 1 commit into from
Sep 26, 2018
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
3 changes: 2 additions & 1 deletion src/adapter/repository/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { IFileStatParser, ILogParser } from '../parsers/types';
import { ITEM_ENTRY_SEPARATOR, LOG_ENTRY_SEPARATOR, LOG_FORMAT_ARGS } from './constants';
import { GitOriginType } from './index';
import { IGitArgsService } from './types';
import { asyncFilter } from '../../common/helpers';

@injectable()
export class Git implements IGitService {
Expand Down Expand Up @@ -426,7 +427,7 @@ export class Git implements IGitService {
.map(item => path.join(dir, item));
filteredItems.push(dir);

const folders = await Promise.all<string>(filteredItems.filter(async item => (await fs.stat(item)).isDirectory()));
const folders = await asyncFilter(filteredItems, async item => (await fs.stat(item)).isDirectory());
const gitRootArgs = this.gitArgsService.getGitRootArgs();
const gitRoots = (await Promise.all(folders.map(async item => {
try {
Expand Down
8 changes: 8 additions & 0 deletions src/common/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,11 @@ export function formatDate(date: Date) {
const dateOptions = { weekday: 'short', day: 'numeric', month: 'short', year: 'numeric', hour: 'numeric', minute: 'numeric' };
return date.toLocaleString(lang, dateOptions);
}

export async function asyncFilter<T>(arr: T[], callback): Promise<T[]> {
return (
await Promise.all(arr.map(
async item => (await callback(item)) ? item : undefined)
)
).filter(i => i !== undefined) as T[];
}