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

All contributors bug #1070

Merged
merged 4 commits into from
Mar 19, 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
11 changes: 11 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,17 @@
"code",
"doc"
]
},
{
"login": "hborawski",
"name": "Harris Borawski",
"avatar_url": "https://avatars1.githubusercontent.com/u/1325154?v=4",
"profile": "https://github.com/hborawski",
"contributions": [
"doc",
"test",
"code"
]
}
],
"commitConvention": "none"
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds
<td align="center"><a href="http://www.jeremiahzucker.com"><img src="https://avatars1.githubusercontent.com/u/9255651?v=4" width="100px;" alt=""/><br /><sub><b>Jeremiah Zucker</b></sub></a><br /><a href="https://github.com/intuit/auto/commits?author=sugarmanz" title="Documentation">📖</a></td>
<td align="center"><a href="https://www.unconfinedsoftware.com/"><img src="https://avatars2.githubusercontent.com/u/13172697?v=4" width="100px;" alt=""/><br /><sub><b>Brandon Miller</b></sub></a><br /><a href="https://github.com/intuit/auto/commits?author=unknownerror404" title="Code">💻</a> <a href="https://github.com/intuit/auto/commits?author=unknownerror404" title="Documentation">📖</a></td>
</tr>
<tr>
<td align="center"><a href="https://github.com/hborawski"><img src="https://avatars1.githubusercontent.com/u/1325154?v=4" width="100px;" alt=""/><br /><sub><b>Harris Borawski</b></sub></a><br /><a href="https://github.com/intuit/auto/commits?author=hborawski" title="Documentation">📖</a> <a href="https://github.com/intuit/auto/commits?author=hborawski" title="Tests">⚠️</a> <a href="https://github.com/intuit/auto/commits?author=hborawski" title="Code">💻</a></td>
</tr>
</table>

<!-- markdownlint-enable -->
Expand Down
40 changes: 38 additions & 2 deletions plugins/all-contributors/__tests__/all-contributors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const gitShow = jest.fn();
const getLernaPackages = jest.fn();

getLernaPackages.mockReturnValue(Promise.resolve([]));
gitShow.mockReturnValue('');
gitShow.mockReturnValue(Promise.resolve(''));
exec.mockReturnValue('');

jest.mock('child_process');
Expand Down Expand Up @@ -133,7 +133,7 @@ describe('All Contributors Plugin', () => {
subject: 'Do the thing',
hash: '123',
labels: [],
files: [],
files: ['src/index.ts'],
authors: [{ username: 'Jeff', hash: '123' }]
}
]
Expand Down Expand Up @@ -266,6 +266,42 @@ describe('All Contributors Plugin', () => {
);
});

test('should include sub-commit contributors', async () => {
const releasedLabel = new AllContributors();
const autoHooks = makeHooks();
mockRead(
'{ "contributors": [ { "login": "Jeff", "contributions": ["infra"] } ] }'
);

releasedLabel.apply({ hooks: autoHooks, logger: dummyLog() } as Auto.Auto);

await autoHooks.afterAddToChangelog.promise({
bump: Auto.SEMVER.patch,
currentVersion: '0.0.0',
lastRelease: '0.0.0',
releaseNotes: '',
commits: [
{
subject: 'Do the thing',
hash: '123',
labels: [],
files: ['src/index.ts'],
authors: [
{ username: 'Jeff', hash: '123' },
{ username: 'Adam', hash: '456' }
]
}
]
});

expect(exec.mock.calls[0][0]).toBe(
'npx all-contributors-cli add Jeff infra,code'
);
expect(exec.mock.calls[1][0]).toBe(
'npx all-contributors-cli add Adam code'
);
});

test('should not update if no new contribution types', async () => {
const releasedLabel = new AllContributors();
const autoHooks = makeHooks();
Expand Down
23 changes: 6 additions & 17 deletions plugins/all-contributors/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,21 +124,14 @@ export default class AllContributorsPlugin implements IPlugin {
auto.hooks.afterAddToChangelog.tapPromise(
this.name,
async ({ commits }) => {
await this.updateContributors(auto, commits);
const rootDir = process.cwd();

let packages: {
/** name of the package to manage contributors in */
name: string;
/** path to the package */
path: string;
}[];
// Always do the root package
let packages = [{ path: rootDir, name: 'root-package' }];

try {
packages = await getLernaPackages();
} catch (error) {
packages = [{ path: rootDir, name: 'single-package' }];
}
// Try to get sub-packages
packages = [...packages, ...(await getLernaPackages())];
} catch (error) {}

// Cannot run git operations in parallel
await packages.reduce(async (last, { name, path }) => {
Expand Down Expand Up @@ -229,15 +222,11 @@ export default class AllContributorsPlugin implements IPlugin {
return isMatch;
})
.forEach(contribution => {
authors.forEach(({ username, hash }) => {
authors.forEach(({ username }) => {
if (!username) {
return;
}

if (commit.hash !== hash) {
return;
}

if (!authorContributions[username]) {
authorContributions[username] = new Set();
}
Expand Down