Skip to content
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package-lock.json
**/node_modules
dist
tsconfig*.json
56 changes: 56 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"prettier",
"plugin:import/recommended",
"plugin:prettier/recommended",
"plugin:storybook/recommended",
"plugin:import/typescript"
],
"plugins": [
"@typescript-eslint",
"prettier",
"sort-destructure-keys",
"simple-import-sort",
"json-format",
"unused-imports",
"import"
],
"env": {
"browser": true,
"node": true,
"jest": true
},
"rules": {
"prettier/prettier": "error",
"simple-import-sort/imports": "error",
"simple-import-sort/exports": "error",
"sort-destructure-keys/sort-destructure-keys": "error",
"unused-imports/no-unused-imports": "error",
"@typescript-eslint/consistent-type-imports": "error"
},
"settings": {
"import/parsers": {
"@typescript-eslint/parser": [".ts", ".tsx"]
},
"react": {
"version": "detect"
},
"import/resolver": {
"typescript": {} // this loads <rootdir>/tsconfig.json to eslint
}
},
"overrides": [
{
"files": ["*.js"],
"rules": {
"@typescript-eslint/no-var-requires": "off",
"unicorn/prefer-module": "off",
"unicorn/prevent-abbreviations": "off"
}
}
]
}
11 changes: 0 additions & 11 deletions .eslintrc.js

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/lint-pr-title.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12
node-version: 16
- uses: ./
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
config: some config
commitlintConfigFile: commitlint.config.js
File renamed without changes.
15 changes: 0 additions & 15 deletions .releaserc.json

This file was deleted.

5 changes: 0 additions & 5 deletions CHANGELOG.md

This file was deleted.

62 changes: 27 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,48 +1,40 @@
# action-semantic-pull-request
# PR Title Linter (GitHub Action)

This is a [Github Action](https://github.com/features/actions) that ensures that your PR title matches the [Conventional Commits spec](https://www.conventionalcommits.org/).
This GitHub action will use your repository-specific commitlint config to lint the Pull Request titles in your repository.
By default it will look for a `commitlint.config.js` in your repository root to use. You can specify a different path using the inputs, see below.

This is helpful when you're using [semantic-release](https://github.com/semantic-release/semantic-release) with the Conventional Commits preset. When using the "Squash and merge" strategy, Github will suggest to use the PR title as the commit message. With this action you can validate that the PR title will lead to a correct commit message.
**⚠ If your config extends existing commitlint presets you need to install them manually!**

## Validation
## How to use in a workflow

Examples for valid PR titles:
- fix: Correct typo.
- feat: Add support for Node 12.
- refactor!: Drop support for Node 6.
```yml
name: PR checks

Note that since PR titles only have a single line, you have to use the `!` syntax for breaking changes.
on:
pull_request:
types: [opened, reopened, edited, synchronize]
branches: [main]

See [Conventional Commits](https://www.conventionalcommits.org/) for more examples.
jobs:
title-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

### Work in progress
- name: manually install any commitlint presets that we extend from
run: npm install --no-save @commitlint/config-conventional

Github has support for [draft pull requests](https://github.blog/2019-02-14-introducing-draft-pull-requests/), which will disable the merge button until the PR is marked as ready for merge.
- uses: dreampulse/action-lint-pull-request-title
```

However, [this feature might be disabled for your repository](https://github.community/t/draft-pull-requests-not-available/1753/7). In this case you can use the special `[WIP] ` prefix to indicate that a pull request is work in progress and isn't ready to be merged. This will avoid the validation of the PR title and the pull request checks remain pending.
## Inputs

## Example config
- `commitlintConfigFile`: Use this to specify the path to your commitlint config (default: `commitlint.config.js`)
- `helpUrl`: Use this to specify a custom url that will guide users to your specific commit rules (default: `https://www.conventionalcommits.org`)

```yml
name: "Lint PR"
on:
pull_request_target:
types:
- opened
- edited
- synchronize

jobs:
main:
runs-on: ubuntu-latest
steps:
- uses: amannn/action-semantic-pull-request@v1.2.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Optionally you can configure which types are allowed.
# Default: https://github.com/commitizen/conventional-commit-types
with:
types: fix, feat
- uses: dreampulse/action-lint-pull-request-title
with:
commitlintConfigFile: commitlint.config.js
helpUrl: "https://example.com/commit-guidelines"
```

Note the usage of [`pull_request_target`](https://github.blog/2020-08-03-github-actions-improvements-for-fork-and-pull-request-workflows/) as the event trigger is necessary for a fork-based workflow so the API token is valid for status reporting.
21 changes: 12 additions & 9 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
name: commitlint-pull-request-title
name: action-lint-pull-request-title
description: This action runs your repositorie's commitlint config against your Pull Request titles
author: Jonathan Häberle <jonathan.haeberle@gmail.com>
description: Ensure your PR has a valid commit lint title.
runs:
using: 'node12'
main: 'index.js'
branding:
icon: 'shield'
color: 'green'
using: node16
main: dist/index.js
inputs:
config:
description: "The commit lint configuration"
commitlintConfigFile:
description: The path to your local commitlint config file
required: false
default: ./commitlint.config.js
helpUrl:
description: Provide a help url for users of this action
required: false
default: https://www.conventionalcommits.org
135 changes: 135 additions & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
module.exports = {
parserPreset: "conventional-changelog-conventionalcommits",
rules: {
"body-leading-blank": [1, "always"],
"body-max-line-length": [2, "always", 100],
"footer-leading-blank": [1, "always"],
"footer-max-line-length": [2, "always", 100],
"header-max-length": [2, "always", 100],
"subject-case": [
2,
"never",
["sentence-case", "start-case", "pascal-case", "upper-case"],
],
"subject-empty": [2, "never"],
"subject-full-stop": [2, "never", "."],
"type-case": [2, "always", "lower-case"],
"type-empty": [2, "never"],
"type-enum": [
2,
"always",
[
"build",
"chore",
"ci",
"docs",
"feat",
"fix",
"perf",
"refactor",
"revert",
"style",
"test",
],
],
},
prompt: {
questions: {
type: {
description: "Select the type of change that you're committing",
enum: {
feat: {
description: "A new feature",
title: "Features",
emoji: "✨",
},
fix: {
description: "A bug fix",
title: "Bug Fixes",
emoji: "🐛",
},
docs: {
description: "Documentation only changes",
title: "Documentation",
emoji: "📚",
},
style: {
description:
"Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)",
title: "Styles",
emoji: "💎",
},
refactor: {
description:
"A code change that neither fixes a bug nor adds a feature",
title: "Code Refactoring",
emoji: "📦",
},
perf: {
description: "A code change that improves performance",
title: "Performance Improvements",
emoji: "🚀",
},
test: {
description: "Adding missing tests or correcting existing tests",
title: "Tests",
emoji: "🚨",
},
build: {
description:
"Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)",
title: "Builds",
emoji: "🛠",
},
ci: {
description:
"Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)",
title: "Continuous Integrations",
emoji: "⚙️",
},
chore: {
description: "Other changes that don't modify src or test files",
title: "Chores",
emoji: "♻️",
},
revert: {
description: "Reverts a previous commit",
title: "Reverts",
emoji: "🗑",
},
},
},
scope: {
description:
"What is the scope of this change (e.g. component or file name)",
},
subject: {
description:
"Write a short, imperative tense description of the change",
},
body: {
description: "Provide a longer description of the change",
},
isBreaking: {
description: "Are there any breaking changes?",
},
breakingBody: {
description:
"A BREAKING CHANGE commit requires a body. Please enter a longer description of the commit itself",
},
breaking: {
description: "Describe the breaking changes",
},
isIssueAffected: {
description: "Does this change affect any open issues?",
},
issuesBody: {
description:
"If issues are closed, the commit requires a body. Please enter a longer description of the commit itself",
},
issues: {
description: 'Add issue references (e.g. "fix #123", "re #123".)',
},
},
},
};
11 changes: 8 additions & 3 deletions ...nal-changelog-writer/templates/commit.hbs → dist/commit.hbs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
* {{header}}
*{{#if scope}} **{{scope}}:**
{{~/if}} {{#if subject}}
{{~subject}}
{{~else}}
{{~header}}
{{~/if}}

{{~!-- commit link --}} {{#if @root.linkReferences~}}
([{{hash}}](
([{{shortHash}}](
{{~#if @root.repository}}
{{~#if @root.host}}
{{~@root.host}}/
Expand All @@ -15,7 +20,7 @@
{{~/if}}/
{{~@root.commit}}/{{hash}}))
{{~else}}
{{~hash}}
{{~shortHash}}
{{~/if}}

{{~!-- commit references --}}
Expand Down
11 changes: 11 additions & 0 deletions dist/footer.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{{#if noteGroups}}
{{#each noteGroups}}

### {{title}}

{{#each notes}}
* {{#if commit.scope}}**{{commit.scope}}:** {{/if}}{{text}}
{{/each}}
{{/each}}

{{/if}}
Loading