Compare commits

...

3 Commits
v0.13 ... v0.15

Author SHA1 Message Date
Webber
44bde7feb9 Base number of commits off of the branch on origin 2020-05-02 16:37:24 +02:00
Webber
5328bda08e Base number of commits off of the branch 2020-05-02 16:37:24 +02:00
Webber
34e4b86924 Fix case where no tags does not trigger false 2020-05-01 20:32:41 +02:00
4 changed files with 43 additions and 13 deletions

File diff suppressed because one or more lines are too long

View File

@@ -26,4 +26,24 @@ expect.extend({
pass, pass,
}; };
}, },
toBeParsableToANumber(received) {
let pass = false;
let errorMessage = '';
try {
Number.parseInt(received, 10);
pass = true;
} catch (error) {
errorMessage = error;
}
const message = () => `Expected ${this.utils.printExpected(received)} to be parsable as a number
, but received error: ${this.utils.printReceived(errorMessage)}.`;
return {
message,
pass,
};
},
}); });

View File

@@ -44,5 +44,13 @@ describe('System', () => {
expect(info).toHaveBeenCalledTimes(2); expect(info).toHaveBeenCalledTimes(2);
expect(info).toHaveBeenLastCalledWith('3\n'); expect(info).toHaveBeenLastCalledWith('3\n');
}); });
it('allows pipes using buffer', async () => {
await expect(
System.run('sh', undefined, {
input: Buffer.from('git tag --list --merged HEAD | grep v[0-9]* | wc -l'),
}),
).resolves.toBeParsableToANumber();
});
}); });
}); });

View File

@@ -183,25 +183,27 @@ export default class Versioning {
* Whether or not the repository has any version tags yet. * Whether or not the repository has any version tags yet.
*/ */
static async hasAnyVersionTags() { static async hasAnyVersionTags() {
const numberOfVersionCommits = await System.run('git', [ const numberOfCommitsAsString = await System.run('sh', undefined, {
'tag', input: Buffer.from('git tag --list --merged HEAD | grep v[0-9]* | wc -l'),
'--list', silent: false,
'--merged', });
'HEAD',
'|',
'grep v[0-9]*',
'|',
'wc -l',
]);
return numberOfVersionCommits !== '0'; const numberOfCommits = Number.parseInt(numberOfCommitsAsString, 10);
return numberOfCommits !== 0;
} }
/** /**
* Get the total number of commits on head. * Get the total number of commits on head.
*
* Note: HEAD should not be used, as it may be detached, resulting in an additional count.
*/ */
static async getTotalNumberOfCommits() { static async getTotalNumberOfCommits() {
const numberOfCommitsAsString = await System.run('git', ['rev-list', '--count', 'HEAD']); const numberOfCommitsAsString = await System.run('git', [
'rev-list',
'--count',
`origin/${this.branch}`,
]);
return Number.parseInt(numberOfCommitsAsString, 10); return Number.parseInt(numberOfCommitsAsString, 10);
} }