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

feat: extend helpUrl from shareable config #2846

Merged
merged 6 commits into from
Nov 1, 2021
Merged
Show file tree
Hide file tree
Changes from 5 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
21 changes: 21 additions & 0 deletions @commitlint/format/src/format.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,24 @@ test('format result omits help for empty problems', () => {
expect.arrayContaining([expect.stringContaining('Get help:')])
);
});

test('format result should not contain `Get help` prefix if helpUrl is not provided', () => {
const actual = formatResult(
{
warnings: [
{
level: 2,
name: 'warning-name',
message: 'There was a warning',
},
],
},
{
helpUrl: '',
}
);

expect(actual).not.toEqual(
expect.arrayContaining([expect.stringContaining('Get help:')])
);
});
7 changes: 5 additions & 2 deletions @commitlint/format/src/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,17 @@ export function formatResult(
const fmtSummary =
enabled && typeof summary === 'string' ? chalk.bold(summary) : summary;

const help = hasProblems ? `ⓘ Get help: ${options.helpUrl}` : undefined;
const help =
hasProblems && options.helpUrl
? `ⓘ Get help: ${options.helpUrl}`
: undefined;

return [
...problems,
hasProblems ? '' : undefined,
fmtSummary,
help,
help ? '' : undefined,
hasProblems ? '' : undefined,
].filter((line): line is string => typeof line === 'string');
}

Expand Down
3 changes: 3 additions & 0 deletions @commitlint/load/fixtures/help-url/commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
helpUrl: 'https://github.com/conventional-changelog/commitlint'
};
18 changes: 18 additions & 0 deletions @commitlint/load/src/load.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,3 +453,21 @@ test('resolves parser preset from conventional commits without factory support',
/^(\w*)(?:\((.*)\))?!?: (.*)$/
);
});

test('helpUrl should be loaded from the shareable config', async () => {
const cwd = await gitBootstrap('fixtures/help-url');
const actual = await load({}, {cwd});

expect(actual.helpUrl).toStrictEqual(
'https://github.com/conventional-changelog/commitlint'
);
});

test('default helpUrl should be loaded if not provided in shareable configs', async () => {
const cwd = await gitBootstrap('fixtures/basic');
const actual = await load({}, {cwd});

expect(actual.helpUrl).toStrictEqual(
'https://github.com/conventional-changelog/commitlint/#what-is-commitlint'
);
});
4 changes: 3 additions & 1 deletion @commitlint/load/src/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ export default async function load(
}, {});

const helpUrl =
typeof config.helpUrl === 'string'
typeof extended.helpUrl === 'string'
? extended.helpUrl
: typeof config.helpUrl === 'string'
? config.helpUrl
: 'https://github.com/conventional-changelog/commitlint/#what-is-commitlint';

Expand Down
1 change: 1 addition & 0 deletions @commitlint/resolve-extends/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface ResolvedConfig {
export interface ResolveExtendsConfig {
parserPreset?: unknown;
extends?: string | string[];
helpUrl?: string;
[key: string]: unknown;
}

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ npx husky install
yarn husky install

# Add hook
npx husky add .husky/commit-msg 'npx --no-install commitlint --edit "$1"'
npx husky add .husky/commit-msg 'npx --no -- commitlint --edit "$1"'
```

Check the [husky documentation](https://typicode.github.io/husky/#/?id=manual) on how you can automatically have Git hooks enabled after install for different `yarn` versions.
Expand Down Expand Up @@ -193,7 +193,7 @@ is room and need for improvement. The items on the roadmap should enhance `commi

### Releases

Security patches will be applied to versions which are not yet EOL.
escapedcat marked this conversation as resolved.
Show resolved Hide resolved
Security patches will be applied to versions which are not yet EOL.\
Features will only be applied to the current main version.

| Release | Inital release | End-of-life |
Expand All @@ -204,7 +204,7 @@ Features will only be applied to the current main version.

_Dates are subject to change._

We're not a sponsored OSS project. Therefor we can't promise that we will release patch versions for older releases in a timley manner.
We're not a sponsored OSS project. Therefor we can't promise that we will release patch versions for older releases in a timley manner.\
If you are stuck on an older version and need a security patch we're happy if you can provide a PR.

## Related projects
Expand Down Expand Up @@ -242,7 +242,7 @@ For more information on how to contribute please take a look at our [contributio
### Publishing a release

Before publishing a release do a `yarn run publish --dry-run` to get the upcoming version and update the version
in the [`should print help` test](https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/cli/src/cli.test.ts#L431).
in the [`should print help` test](https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/cli/src/cli.test.ts#L431).\
Commit that change before creating the new version without `--dry-run`.

```sh
Expand Down
6 changes: 3 additions & 3 deletions docs/guides-local-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ npx husky install
yarn husky install

# Add hook
npx husky add .husky/commit-msg 'npx --no-install commitlint --edit $1'
npx husky add .husky/commit-msg 'npx --no -- commitlint --edit $1'
escapedcat marked this conversation as resolved.
Show resolved Hide resolved
# or
yarn husky add .husky/commit-msg 'yarn commitlint --edit $1'
```

**Please note that currently @commitlint/cli doesn't support yarn v2 Plug'n'Play (using yarn v2 with `nodeLinker: node-modules` in your .yarnrc.yml file may work sometimes)**
**Please note that currently @commitlint/cli doesn't support yarn v2 Plug'n'Play (using yarn v2 with `nodeLinker: node-modules` in your .yarnrc.yml file may work sometimes)**\
Check the [husky documentation](https://typicode.github.io/husky/#/?id=manual) on how you can automatically have Git hooks enabled after install for different `yarn` versions.

## Test
Expand Down Expand Up @@ -70,7 +70,7 @@ No staged files match any of provided globs.
husky > commit-msg hook failed (add --no-verify to bypass)
```

Since [v8.0.0](https://github.com/conventional-changelog/commitlint/releases/tag/v8.0.0) `commitlint` won't output anything if there is not problem with your commit.
Since [v8.0.0](https://github.com/conventional-changelog/commitlint/releases/tag/v8.0.0) `commitlint` won't output anything if there is not problem with your commit.\
(You can use the `--verbose` flag to get positive output)

```bash
Expand Down