Skip to content

Commit

Permalink
Merge pull request #9 from lightness/feature/allow-multiple-repo-search
Browse files Browse the repository at this point in the history
Allow search in multiple repos
  • Loading branch information
lightness authored Aug 22, 2019
2 parents 812cecd + 1e0652d commit c086b2f
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "github-repo-tools",
"version": "2.4.0",
"version": "2.4.1",
"description": "Useful tool to get versions (node or npm package) from repo(s) of Github user/org",
"main": "build/index.js",
"bin": {
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export interface IFilterOptions {
export interface IOwnerOptions {
org?: string;
user?: string;
repo?: string;
repos?: string[];
}

export interface IPackageOptions {
Expand Down
16 changes: 4 additions & 12 deletions src/modules/base/base.report.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,17 @@ export abstract class BaseReportService<T extends IReportItem> {
protected abstract handleRepo(repo: string, options: IProgramOptions): Promise<T>;

public async getReport(options: IProgramOptions): Promise<T[]> {
const { org, user, token, repo } = options;

if (repo) {
this.presenterService.showProcessingSpinner(options);
const repoReport = await this.getRepoReport(repo, options);
this.presenterService.hideSpinner({ success: true });

return [repoReport];
}
const { org, user, token, repos } = options;

const repos = await this.octokitService.getRepos({ org, user, token });
const reposToSearch = repos || await this.octokitService.getRepos({ org, user, token });

if (!repos) {
if (!reposToSearch) {
return null;
}

this.presenterService.showProcessingSpinner(options);
const result = await Promise.all(
repos.map(async repo => await this.getRepoReport(repo, options))
reposToSearch.map(async repo => await this.getRepoReport(repo, options))
);
this.presenterService.hideSpinner({ success: true });

Expand Down
4 changes: 2 additions & 2 deletions src/modules/cli/commander.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ export class CommanderService {
describe: 'github user where search applied',
type: 'string',
})
.option('repo', {
.option('repos', {
alias: 'r',
describe: 'github user where search applied',
type: 'string',
type: 'array',
})
.option('package', {
alias: 'p',
Expand Down
4 changes: 2 additions & 2 deletions src/modules/presenter/default.presenter.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ export class DefaultPresenterService implements IPresenterService {
}

protected getRepoToSearch(options: IProgramOptions): string {
const { repo } = options;
const { repos } = options;

return repo ? `${chalk.green(repo)}` : 'all repos';
return repos ? `${chalk.green(repos.join(', '))}` : 'all repos';
}

}

0 comments on commit c086b2f

Please sign in to comment.