Skip to content

Commit

Permalink
refactor(cli)!: rename remote to linkUrl
Browse files Browse the repository at this point in the history
* cli, more accurate naming, remote to link url
* cmds, update remote to link url
* files, update dep injection
* parse, update dep injection
  • Loading branch information
cdcabrera committed Jan 29, 2024
1 parent 756d47b commit 56d4949
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 59 deletions.
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,20 @@ or Yarn
--changelog Changelog output filename and relative path
[string] [default: "./CHANGELOG.md"]
--commit-path [CHANGELOG.md] path used for commits. This will be
"joined" with "remote-url". Defaults to the commits
path for GitHub. [string] [default: "commit/"]
"joined" with "link-url". Defaults to the commits path
for GitHub. [string] [default: "commit/"]
--compare-path [CHANGELOG.md] path used for version comparison. This
will be "joined" with "remote-url". Defaults to the
will be "joined" with "link-url". Defaults to the
comparison path for GitHub.
[string] [default: "compare/"]
--link-url Url override for updating all [CHANGELOG.md] base urls.
This should start with "http". Attempts to use "$ git
remote get-url origin", if it starts with "http"
[string]
--package package.json read, output and relative path
[string] [default: "./package.json"]
--pr-path [CHANGELOG.md] path used for PRs/MRs. This will be
"joined" with "remote-url". Defaults to the PR path for
"joined" with "link-url". Defaults to the PR path for
GitHub. [string] [default: "pull/"]
--release-message A list of prefix release scope commit messages. First
list item is the new commit message prefix, the second
Expand All @@ -73,9 +77,6 @@ or Yarn
[array] [default: "chore(release)"]
--release-desc Add a description under the release version header
copy. Example, "⚠ BREAKING CHANGES" [string]
--remote-url Git remote get-url for updating [CHANGELOG.md] base
urls. This should start with "http". Defaults to "$ git
remote get-url origin" [string]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]
```
Expand Down Expand Up @@ -144,11 +145,11 @@ To get your release commit setup from a "forked" repository...
1. Make sure your working branch is synced and updated with the remote branch you want to merge into
1. Run and confirm the hashes AND LINKS with the remote align in the terminal with...
```
$ changelog --dry-run --remote-url https://github.com/[the remote url].git
$ changelog --dry-run --link-url https://github.com/[the remote url].git
```
1. Run the release script
```
$ changelog --remote-url https://github.com/[the remote url].git
$ changelog --link-url https://github.com/[the remote url].git
```
1. Setup your pull/merge request, there should be a single commit difference... your release commit.
> If there is more than one commit difference then you incorrectly synced your branch. Confer online, or with your team, for the git commands needed.
Expand Down
24 changes: 12 additions & 12 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const {
'pr-path': prPath,
'release-message': releaseTypeScope,
'release-desc': releaseDescription,
'remote-url': remoteUrl
'link-url': linkUrl
} = yargs
.usage('Generate a CHANGELOG.md with conventional commit types.\n\nUsage: changelog [options]')
.help('help')
Expand Down Expand Up @@ -80,13 +80,18 @@ const {
.option('commit-path', {
default: 'commit/',
describe:
'[CHANGELOG.md] path used for commits. This will be "joined" with "remote-url". Defaults to the commits path for GitHub.',
'[CHANGELOG.md] path used for commits. This will be "joined" with "link-url". Defaults to the commits path for GitHub.',
type: 'string'
})
.option('compare-path', {
default: 'compare/',
describe:
'[CHANGELOG.md] path used for version comparison. This will be "joined" with "remote-url". Defaults to the comparison path for GitHub.',
'[CHANGELOG.md] path used for version comparison. This will be "joined" with "link-url". Defaults to the comparison path for GitHub.',
type: 'string'
})
.option('link-url', {
describe:
'Url override for updating all [CHANGELOG.md] base urls. This should start with "http". Attempts to use "$ git remote get-url origin", if it starts with "http"',
type: 'string'
})
.option('package', {
Expand All @@ -97,7 +102,7 @@ const {
.option('pr-path', {
default: 'pull/',
describe:
'[CHANGELOG.md] path used for PRs/MRs. This will be "joined" with "remote-url". Defaults to the PR path for GitHub.',
'[CHANGELOG.md] path used for PRs/MRs. This will be "joined" with "link-url". Defaults to the PR path for GitHub.',
type: 'string'
})
.option('release-message', {
Expand All @@ -109,11 +114,6 @@ const {
.option('release-desc', {
describe: 'Add a description under the release version header copy. Example, "\u26A0 BREAKING CHANGES"',
type: 'string'
})
.option('remote-url', {
describe:
'Git remote get-url for updating [CHANGELOG.md] base urls. This should start with "http". Defaults to "$ git remote get-url origin"',
type: 'string'
}).argv;

/**
Expand All @@ -123,7 +123,7 @@ const {
* packageFile: string, releaseDescription: string, isAllowNonConventionalCommits: boolean,
* releaseBranch: string, prPath: string, isCommit: boolean, overrideVersion: string|*,
* changelogPath: Function, commitPath: string, changelogFile: string,
* releaseTypeScope: string[]|string, isDryRun: boolean, remoteUrl: string,
* releaseTypeScope: string[]|string, isDryRun: boolean, linkUrl: string,
* isBasic: boolean}}
* @private
*/
Expand All @@ -140,6 +140,7 @@ OPTIONS._set = {
isDryRun,
isCommit,
isOverrideVersion: overrideVersion !== undefined,
linkUrl,
overrideVersion,
packageFile,
packagePath: function () {
Expand All @@ -148,8 +149,7 @@ OPTIONS._set = {
prPath,
releaseBranch,
releaseDescription,
releaseTypeScope,
remoteUrl
releaseTypeScope
};

/**
Expand Down
16 changes: 8 additions & 8 deletions src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Functions for `git`, `package.json` version, and more
* [~commitFiles(version, options)](#module_Commands..commitFiles) ⇒ <code>string</code>
* [~getCurrentVersion(options)](#module_Commands..getCurrentVersion) ⇒ <code>\*</code>
* [~getReleaseCommit(options)](#module_Commands..getReleaseCommit) ⇒ <code>string</code>
* [~getRemoteUrls(options)](#module_Commands..getRemoteUrls) ⇒ <code>Object</code>
* [~getLinkUrls(options)](#module_Commands..getLinkUrls) ⇒ <code>Object</code>
* [~getGit(options, settings)](#module_Commands..getGit) ⇒ <code>Array</code>
* [~getGitLog(commitHash, searchFilter)](#module_Commands..getGit..getGitLog) ⇒ <code>string</code>
* [~getOverrideVersion(options)](#module_Commands..getOverrideVersion) ⇒ <code>Object</code>
Expand Down Expand Up @@ -124,10 +124,10 @@ Get last release commit hash
</tr> </tbody>
</table>

<a name="module_Commands..getRemoteUrls"></a>
<a name="module_Commands..getLinkUrls"></a>

### Commands~getRemoteUrls(options) ⇒ <code>Object</code>
Get the repositories remote
### Commands~getLinkUrls(options) ⇒ <code>Object</code>
Get the repository link prefix for markdown links.

**Kind**: inner method of [<code>Commands</code>](#module_Commands)
<table>
Expand All @@ -144,9 +144,9 @@ Get the repositories remote
</tr><tr>
<td>options.comparePath</td><td><code>string</code></td>
</tr><tr>
<td>options.prPath</td><td><code>string</code></td>
<td>options.linkUrl</td><td><code>string</code></td>
</tr><tr>
<td>options.remoteUrl</td><td><code>string</code></td>
<td>options.prPath</td><td><code>string</code></td>
</tr> </tbody>
</table>

Expand Down Expand Up @@ -298,7 +298,7 @@ Update CHANGELOG.md with commit output.
</tr><tr>
<td>settings.getComparisonCommitHashes</td><td><code>function</code></td><td></td>
</tr><tr>
<td>settings.getRemoteUrls</td><td><code>function</code></td><td></td>
<td>settings.getLinkUrls</td><td><code>function</code></td><td></td>
</tr><tr>
<td>settings.headerMd</td><td><code>string</code></td><td></td>
</tr> </tbody>
Expand Down Expand Up @@ -525,7 +525,7 @@ Format commit message for CHANGELOG.md
</tr><tr>
<td>settings</td><td><code>object</code></td>
</tr><tr>
<td>settings.getRemoteUrls</td><td><code>function</code></td>
<td>settings.getLinkUrls</td><td><code>function</code></td>
</tr> </tbody>
</table>

Expand Down
16 changes: 8 additions & 8 deletions src/__tests__/__snapshots__/cmds.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ exports[`Commands should attempt to run commands: commands 1`] = `
},
],
},
{
"getLinkUrls": {
"baseUrl": undefined,
"commitUrl": undefined,
"compareUrl": undefined,
"prUrl": undefined,
},
},
{
"getOverrideVersion": {
"clean": "<semverClean>[null]</semverClean>",
Expand All @@ -22,14 +30,6 @@ exports[`Commands should attempt to run commands: commands 1`] = `
{
"getReleaseCommit": "<execSync>["git log HEAD --grep=\\"chore(release)\\" --pretty=oneline -1"]</execSync>",
},
{
"getRemoteUrls": {
"baseUrl": undefined,
"commitUrl": undefined,
"compareUrl": undefined,
"prUrl": undefined,
},
},
{
"getVersion": {
"clean": "<semverClean>["<semverInc>[\\"0.0.100\\",\\"\\"]</semverInc>"]</semverClean>",
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/files.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('Files', () => {
expect(
updateChangelog({ ...commitObj, packageVersion: '1.0.0' }, undefined, {
getComparisonCommitHashes: () => comparisonObjNoReleaseCommit,
getRemoteUrls: () => urlObj
getLinkUrls: () => urlObj
})
).toMatchSnapshot('urls and paths, no release commit');

Expand All @@ -66,7 +66,7 @@ describe('Files', () => {
expect(
updateChangelog({ ...commitObj, packageVersion: '1.0.0' }, undefined, {
getComparisonCommitHashes: () => comparisonObjReleaseCommit,
getRemoteUrls: () => urlObj
getLinkUrls: () => urlObj
})
).toMatchSnapshot('urls and paths, release commit');

Expand All @@ -80,7 +80,7 @@ describe('Files', () => {
},
{
getComparisonCommitHashes: () => comparisonObjReleaseCommit,
getRemoteUrls: () => urlObj
getLinkUrls: () => urlObj
}
)
).toMatchSnapshot('urls and paths, release commit, no markdown links');
Expand Down
8 changes: 4 additions & 4 deletions src/__tests__/parse.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ describe('Parse', () => {
parseCommitMessage({ message: commitMessageRefactor }),
{},
{
getRemoteUrls: () => ({
getLinkUrls: () => ({
commitUrl: 'https://localhost/lorem/ipsum/commitsmock/',
prUrl: 'https://localhost/lorem/ipsum/prmock/'
})
Expand Down Expand Up @@ -140,7 +140,7 @@ describe('Parse', () => {
const { mockClear: urlPathObjClear } = mockObjectProperty(OPTIONS, {
commitPath: 'sit',
prPath: 'dolor',
remoteUrl: 'https://localhost/lorem/ipsum'
linkUrl: 'https://localhost/lorem/ipsum'
});
const urlPathObj = parseCommits({ getGit: () => commitLog });
urlPathObjClear();
Expand All @@ -150,15 +150,15 @@ describe('Parse', () => {
commitPath: 'sit',
isBasic: true,
prPath: 'dolor',
remoteUrl: 'https://localhost/lorem/ipsum'
linkUrl: 'https://localhost/lorem/ipsum'
});
const basicCommitsNoMarkdownLinksObj = parseCommits({ getGit: () => commitLog });
basicCommitsNoMarkdownLinksObjClear();

// Allow general commit messages
const { mockClear: generalCommitsObjClear } = mockObjectProperty(OPTIONS, {
isAllowNonConventionalCommits: true,
remoteUrl: 'https://localhost/lorem/ipsum'
linkUrl: 'https://localhost/lorem/ipsum'
});
const generalCommitsObj = parseCommits({ getGit: () => commitLog });
generalCommitsObjClear();
Expand Down
14 changes: 7 additions & 7 deletions src/cmds.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,27 +83,27 @@ const getReleaseCommit = ({ releaseTypeScope, releaseBranch } = OPTIONS) => {
};

/**
* Get the repositories remote
* Get the repository link prefix for markdown links.
*
* @param {object} options
* @param {string} options.commitPath
* @param {string} options.comparePath
* @param {string} options.linkUrl
* @param {string} options.prPath
* @param {string} options.remoteUrl
* @returns {{baseUrl: string, prUrl, commitUrl}}
*/
const getRemoteUrls = ({ commitPath, comparePath, prPath, remoteUrl } = OPTIONS) => {
const setUrl = remoteUrl || runCmd('git remote get-url origin', 'Skipping remote path check... {0}');
const getLinkUrls = ({ commitPath, comparePath, linkUrl, prPath } = OPTIONS) => {
const setUrl = linkUrl || runCmd('git remote get-url origin', 'Skipping remote path check... {0}');
let updatedUrl;
let commitUrl;
let compareUrl;
let prUrl;

if (/^http/.test(setUrl)) {
updatedUrl = setUrl.trim().replace(/(\.git)$/, '');
const [protocol, remotePath] = updatedUrl.split('://');
const [protocol, linkPath] = updatedUrl.split('://');
const generateUrl = path => {
let tempUrl = typeof path === 'string' && `${protocol}://${join(remotePath, path)}`;
let tempUrl = typeof path === 'string' && `${protocol}://${join(linkPath, path)}`;
if (tempUrl && !/\/$/.test(tempUrl)) {
tempUrl += '/';
}
Expand Down Expand Up @@ -263,9 +263,9 @@ const getVersion = (versionBump, { getCurrentVersion: getAliasCurrentVersion = g
module.exports = {
commitFiles,
getGit,
getLinkUrls,
getOverrideVersion,
getReleaseCommit,
getRemoteUrls,
getVersion,
runCmd
};
8 changes: 4 additions & 4 deletions src/files.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { dirname } = require('path');
const { existsSync, readFileSync, writeFileSync } = require('fs');
const { OPTIONS } = require('./global');
const { getRemoteUrls, runCmd } = require('./cmds');
const { getLinkUrls, runCmd } = require('./cmds');
const { getComparisonCommitHashes } = require('./parse');

/**
Expand Down Expand Up @@ -31,7 +31,7 @@ const { getComparisonCommitHashes } = require('./parse');
* @param {string} settings.breakingChangeReleaseDesc
* @param {string} settings.fallbackPackageVersion
* @param {Function} settings.getComparisonCommitHashes
* @param {Function} settings.getRemoteUrls
* @param {Function} settings.getLinkUrls
* @param {string} settings.headerMd
* @returns {string}
*/
Expand All @@ -42,14 +42,14 @@ const updateChangelog = (
breakingChangeReleaseDesc = `\u26A0 BREAKING CHANGES`,
fallbackPackageVersion = '¯\\_(ツ)_/¯',
getComparisonCommitHashes: getAliasComparisonCommitHashes = getComparisonCommitHashes,
getRemoteUrls: getAliasRemoteUrls = getRemoteUrls,
getLinkUrls: getAliasLinkUrls = getLinkUrls,
headerMd = `# Changelog\nAll notable changes to this project will be documented in this file.`
} = {}
) => {
const systemTimestamp = ((date && new Date(date)) || new Date()).toLocaleDateString('fr-CA', {
timeZone: 'UTC'
});
const { compareUrl } = getAliasRemoteUrls();
const { compareUrl } = getAliasLinkUrls();
const updatedReleaseDescription = releaseDescription || (isBreakingChanges && breakingChangeReleaseDesc) || '';
let header = headerMd;
let version = fallbackPackageVersion;
Expand Down
8 changes: 4 additions & 4 deletions src/parse.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { generalCommitType, conventionalCommitType, OPTIONS } = require('./global');
const { getGit, getReleaseCommit, getRemoteUrls } = require('./cmds');
const { getGit, getReleaseCommit, getLinkUrls } = require('./cmds');

/**
* Parse and format commit messages
Expand Down Expand Up @@ -106,15 +106,15 @@ const parseCommitMessage = (
* @param {object} options
* @param {boolean} options.isBasic
* @param {object} settings
* @param {Function} settings.getRemoteUrls
* @param {Function} settings.getLinkUrls
* @returns {string}
*/
const formatChangelogMessage = (
{ scope, description, prNumber, hash, isBreaking } = {},
{ isBasic } = OPTIONS,
{ getRemoteUrls: getAliasRemoteUrls = getRemoteUrls } = {}
{ getLinkUrls: getAliasLinkUrls = getLinkUrls } = {}
) => {
const { commitUrl, prUrl } = getAliasRemoteUrls();
const { commitUrl, prUrl } = getAliasLinkUrls();
let output;

const updatedBreaking = (isBreaking && '\u26A0 ') || '';
Expand Down

0 comments on commit 56d4949

Please sign in to comment.