Skip to content

Commit

Permalink
fix(parse): comparison, last release commit (#6)
Browse files Browse the repository at this point in the history
* files, annotation
* parse, release commit instead of range
  • Loading branch information
cdcabrera committed Oct 14, 2022
1 parent d956f5f commit e2739e5
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 17 deletions.
24 changes: 22 additions & 2 deletions src/__tests__/__snapshots__/files.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,9 +1,29 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Files should create, and update CHANGELOG.md version with a comparison urls: urls and paths 1`] = `
exports[`Files should create, and update CHANGELOG.md version with a comparison urls: urls and paths, no release commit 1`] = `
"# Changelog
All notable changes to this project will be documented in this file.
## [1.0.0](https://localhost/lorem/ipsum/comparmock/FIRSTdd312345d421231231312312345dca11235...LASTg45b597123453031234555b6d25574ccacee) (2022-10-01)
## 1.0.0 (2022-10-01)
### Features
* **dolor** issues/20 sit enhancements (#8) (53a1234)
### Code Refactoring
* **file** lorem updates (#8) (LASTg45)
### Chores
* **build** npm packages (#15) (e5c456e)
### Bug Fixes
* **build** eslint, jsdoc updates (#16) (d123453)
"
`;

exports[`Files should create, and update CHANGELOG.md version with a comparison urls: urls and paths, release commit 1`] = `
"# Changelog
All notable changes to this project will be documented in this file.
## [1.0.0](https://localhost/lorem/ipsum/comparmock/REALFIRST2345d421231231312312345dca11235...LASTg45b597123453031234555b6d25574ccacee) (2022-10-01)
### Features
* **dolor** issues/20 sit enhancements (#8) (53a1234)
Expand Down
11 changes: 9 additions & 2 deletions src/__tests__/__snapshots__/parse.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,16 @@ exports[`Parse should format a changelog commit message: formatChangelogMessages
}
`;

exports[`Parse should get the first, last commits: first and last 1`] = `
exports[`Parse should get the first, last commits: first and last, no release commit 1`] = `
{
"first": "FIRST12345dd312345d42123123131231ca11235",
"first": null,
"last": null,
}
`;

exports[`Parse should get the first, last commits: first and last, release commit 1`] = `
{
"first": "REALFIRST123452345d42123123131231ca11235",
"last": "LAST1f12345b597123453031234555bvvvccacee",
}
`;
Expand Down
24 changes: 20 additions & 4 deletions src/__tests__/files.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,39 @@ describe('Files', () => {
53a12345479ef91123456e921234548ac4123450 feat(dolor): issues/20 sit enhancements (#8)
d1234537b5e94a6512345xeb96503312345x18d2 fix(build): eslint, jsdoc updates (#16)
e5c456ea12345vv4610fa4aff7812345ss31b1e2 chore(build): npm packages (#15)
FIRSTdd312345d421231231312312345dca11235 Initial commit
FIRSTdd312345d421231231312312345dca11235 Initial-like commit
`;

const urlObj = {
compareUrl: 'https://localhost/lorem/ipsum/comparmock/'
};

const commitObj = parseCommits(undefined, { getGit: () => commitLog });
const comparisonObj = getComparisonCommitHashes({ getGit: () => commitLog });
const comparisonObjNoReleaseCommit = getComparisonCommitHashes({
getGit: () => commitLog,
getReleaseCommit: () => ''
});

expect(
updateChangelog(commitObj, '1.0.0', {
date: '2022-10-01',
getComparisonCommitHashes: () => comparisonObj,
getComparisonCommitHashes: () => comparisonObjNoReleaseCommit,
getRemoteUrls: () => urlObj
})
).toMatchSnapshot('urls and paths');
).toMatchSnapshot('urls and paths, no release commit');

const comparisonObjReleaseCommit = getComparisonCommitHashes({
getGit: () => `${commitLog}\nREALFIRST2345d421231231312312345dca11235 chore(release): 0.1.0`,
getReleaseCommit: () => 'REALFIRST2345d421231231312312345dca11235'
});

expect(
updateChangelog(commitObj, '1.0.0', {
date: '2022-10-01',
getComparisonCommitHashes: () => comparisonObjReleaseCommit,
getRemoteUrls: () => urlObj
})
).toMatchSnapshot('urls and paths, release commit');
});

it('should update a package.json', () => {
Expand Down
15 changes: 12 additions & 3 deletions src/__tests__/parse.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,20 @@ describe('Parse', () => {
53a12345479ef91123456e921234548ac4123450 feat(dolor): issues/20 sit enhancements (#8)
d1234537b5e94a6512345xeb96503312345x18d2 fix(build): eslint, jsdoc updates (#16)
e5c456ea12345vv4610fa4aff7812345ss31b1e2 chore(build): npm packages (#15)
FIRST12345dd312345d42123123131231ca11235 Initial commit
FIRST12345dd312345d42123123131231ca11235 Initial-like commit
`;

const comparisonObj = getComparisonCommitHashes({ getGit: () => commitLog });
expect(comparisonObj).toMatchSnapshot('first and last');
const comparisonObjNoReleaseCommit = getComparisonCommitHashes({
getGit: () => commitLog,
getReleaseCommit: () => ''
});
expect(comparisonObjNoReleaseCommit).toMatchSnapshot('first and last, no release commit');

const comparisonObjReleaseCommit = getComparisonCommitHashes({
getGit: () => `${commitLog}\nREALFIRST123452345d42123123131231ca11235 chore(release): 0.1.0`,
getReleaseCommit: () => 'REALFIRST123452345d42123123131231ca11235'
});
expect(comparisonObjReleaseCommit).toMatchSnapshot('first and last, release commit');
});

it('should parse a commit message', () => {
Expand Down
4 changes: 4 additions & 0 deletions src/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ const { getRemoteUrls, runCmd } = require('./cmds');
const { getComparisonCommitHashes } = require('./parse');
const { _COMMIT_CHANGELOG_CONTEXT_PATH: CONTEXT_PATH } = global;

/**
* ToDo: syntax for the comparison can include the use of caret
* Review using caret vs a release commit for determining range
*/
/**
* Update CHANGELOG.md with commit output.
*
Expand Down
15 changes: 10 additions & 5 deletions src/parse.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { generalCommitType, conventionalCommitType } = require('./global');
const { getGit, getRemoteUrls } = require('./cmds');
const { getGit, getReleaseCommit, getRemoteUrls } = require('./cmds');

/**
* Aggregate conventional commit types. Optionally allow non-conventional commit types.
Expand All @@ -21,15 +21,20 @@ const getCommitType = ({ isAllowNonConventionalCommits } = {}) => ({
* @param {Function} options.getGit
* @return {{last: string, first: string}}
*/
const getComparisonCommitHashes = ({ getGit: getAliasGit = getGit } = {}) => {
const [first, ...rest] = getAliasGit()
const getComparisonCommitHashes = ({
getGit: getAliasGit = getGit,
getReleaseCommit: getAliasReleaseCommit = getReleaseCommit
} = {}) => {
const releaseCommitHash = getAliasReleaseCommit().split(/\s/)[0];
const rest = getAliasGit()
.trim()
.split(/\n/g)
.map(value => value.trim().split(/\s/)[0])
.reverse();

return {
first,
last: rest.pop()
first: releaseCommitHash || null,
last: (releaseCommitHash && rest.pop()) || null
};
};

Expand Down
2 changes: 1 addition & 1 deletion tests/__snapshots__/code.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ exports[`General code checks should only have specific console.[warn|log|info|er
"cmds.js:21: console.error(color.RED, errorMessage.replace('{0}', e.message), color.NOCOLOR)",
"cmds.js:138: console.error(color.RED, \`Semver: \${e.message}\`, color.NOCOLOR)",
"cmds.js:168: console.error(color.RED, \`Semver: \${e.message}\`, color.NOCOLOR)",
"files.js:69: console.info(\` \${updatedBody}\`)",
"files.js:73: console.info(\` \${updatedBody}\`)",
"global.js:64: console.error(color.RED, \`Conventional commit types: \${e.message}\`, color.NOCOLOR)",
"index.js:42: console.info( index.js:56: console.info(color.NOCOLOR)",
]
Expand Down

0 comments on commit e2739e5

Please sign in to comment.