Skip to content

Commit

Permalink
Merge pull request #16 from Polymer/fix-excludes
Browse files Browse the repository at this point in the history
fix excludes filtering, add tests
  • Loading branch information
FredKSchott committed Jan 4, 2018
2 parents 52bac64 + 73f06be commit 2269db2
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Changelog

## Unreleased
- Made `Workspace.determineGitHubRepos()` method public.
- Fixed `excludes` pattern filtering bug.
<!-- Add new, unreleased items here. -->

## v2.0.0 [12-18-2017]
Expand Down
46 changes: 43 additions & 3 deletions src/test/workspace_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,60 @@
import {assert} from 'chai';
import path = require('path');
import {Workspace} from '../workspace';
import * as mockApi from './_util/mock-api';
import {testApiToken} from './_util/mock-api';

const testGitHubToken = 'TEST_GITHUB_TOKEN';
const testWorkspaceDir = path.join(__dirname, 'TEST_WORKSPACE_DIR');

suite('src/workspace', function() {
suite('Workspace', () => {
suiteSetup(() => {
mockApi.setup();
});

suiteTeardown(() => {
mockApi.teardown();
});

suite('workspace.init()', () => {
test('can be initialized with an empty set of patterns', async () => {
const workspace =
new Workspace({token: testGitHubToken, dir: testWorkspaceDir, match: []});
const workspace = new Workspace(
{token: testApiToken, dir: testWorkspaceDir, match: []});
const {workspaceRepos, failures} = await workspace.init();
assert.deepEqual(workspaceRepos, []);
assert.deepEqual([...failures], []);
});
});

suite('workspace._determineGitHubRepos()', () => {
test(
'succesfully determines repos for a set of patterns to match',
async () => {
const workspace = new Workspace({
token: testApiToken,
dir: testWorkspaceDir,
match: ['PolymerElements/paper-*']
});
const repos = await workspace._determineGitHubRepos();
assert.deepEqual(repos.map((r) => r.fullName), [
'PolymerElements/paper-appbar',
'PolymerElements/paper-button'
]);
});

test(
'succesfully determines repos for sets of patterns to match and exclude',
async () => {
const workspace = new Workspace({
token: testApiToken,
dir: testWorkspaceDir,
match: ['PolymerElements/paper-*'],
exclude: ['PolymerElements/paper-button']
});
const repos = await workspace._determineGitHubRepos();
assert.deepEqual(
repos.map((r) => r.fullName), ['PolymerElements/paper-appbar']);
});
});
});
});
13 changes: 7 additions & 6 deletions src/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,20 +165,21 @@ export class Workspace {
* wildcard-containing patterns as needed) to return full GitHub repo
* information for all matched repos.
*/
private async _determineGitHubRepos(): Promise<GitHubRepo[]> {
async _determineGitHubRepos(): Promise<GitHubRepo[]> {
const matchPatterns = this.options.match;
const excludePatterns =
(this.options.exclude || []).map(String.prototype.toLowerCase);
(this.options.exclude ||
[]).map(((excludePattern) => excludePattern.toLowerCase()));
const allMatchedReferences =
await this._github.expandRepoPatterns(matchPatterns);
const matchedReferences = allMatchedReferences.filter((ref) => {
return !excludePatterns.includes(ref.fullName.toLowerCase());
});
// Fetch the full repo information for each matched reference
const matchedRepos =
await batchProcess(matchedReferences, async (ref) => {
return this._github.getRepoInfo(ref);
}, {concurrency: githubConcurrencyPreset});
const matchedRepos = await batchProcess(
matchedReferences,
async (ref) => this._github.getRepoInfo(ref),
{concurrency: githubConcurrencyPreset});
matchedRepos.failures.forEach((err, ref) => {
console.log(`Repo not found: ${ref.fullName} (${err.message})`);
});
Expand Down

0 comments on commit 2269db2

Please sign in to comment.