1.0.9 • Published 2 months ago

conventional-commits-lint v1.0.9

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

Conventional Commit Linter

The Conventional Commit Linter is a tool that helps enforce conventional commit message formats in your Git repositories. Conventional Commits are a structured way of writing commit messages, which helps in automatic changelog generation, versioning, and semantic release.

Installation

To install the Conventional Commit Linter, you can use npm:

npm install -g conventional-commit-linter

To run the linter (from a git repo):

conventional-commit-linter

Example output of valid commit format:

Evaluating commit "feat: add search button"
[OK] The last commit message follows the Conventional Commits style.

Example output with incorrect commit format:

Evaluating commit "Added search button"
[FAILED] The last commit message does not follow the Conventional Commits style.
 - Has inforrect type (prefix).
 - The first letter of the commit message should be lowercase.

Use in Azure DevOps YAML pipeline

Example of validing the newest commit message (can be modified to validate all commits).

steps:
  - task: NodeTool@0
    displayName: Setup Node
    inputs:
      versionSpec: '20.x'

  - task: PowerShell@2
    displayName: Lint git commit subject
    inputs:
      targetType: inline
      script: |
        # Fetch the source branch commit(s) using Azure DevOps REST API
        # Create a Personal Access Token (PAT) following this guide (set Build (read), Code (Read)),
        # https://learn.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=azure-devops&tabs=Windows

        $organization = "YourOrganization"
        $project = "YourProject"
        $repositoryId = "YourRepository"
        $pullRequestId = $(System.PullRequest.PullRequestId)
        $pat = "$(PAT_VARIABLE_IN_DEVOPS)"
        $url = "https://dev.azure.com/$organization/_apis/git/repositories/$project/pullRequests/$pullRequestId/commits?api-version=7.1-preview.1"

        $response = Invoke-RestMethod -Uri $url -Headers @{Authorization = "Basic " + [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes(":$pat"))}

        if ($response.value.Count -gt 0) {
          $firstComment = $response.value[0].comment

          # Install conventional-coomits-lint and pass the subject as an argument
          npm install -g conventional-commits-lint
          conventional-commits-lint -s $firstComment
        } else {
            Write-Host "No commits found for pull request $pullRequestId"
        }

Features

  • Enforces conventional commit message formats
  • Supports various configuration options
  • Easily integrable with Git hooks or CI/CD pipelines

Contributing

Contributions are welcome!

References

  • Conventional Commits Lint at npmjs
  • Conventional Commits Lint at GitHub

License

This project is licensed under the MIT License.

1.0.9

2 months ago

1.0.8

2 months ago

1.0.2

2 months ago

1.0.7

2 months ago

1.0.6

2 months ago

1.0.5

2 months ago

1.0.4

2 months ago

1.0.3

2 months ago

1.0.1

2 months ago

1.0.0

2 months ago