PurposeThis extension provided a build task called "Commit Comment Validator" which allows teams to validate that either some or all commits in pull requests conform to a supplied regular expression. How it worksThe task can be added as a step/task in an Azure DevOps pipeline. Once it is added the task will examine commit messages to make sure they pass the provided regular expression. The task will fail if the validation fails. ConfigurationAll Commits Must Match (allCommitsMustMatch)This setting determines the behavior of validation concerning whether the whole set of examined commits must pass validation or any of the commits must pass validation. Default
Enabled Behavior
Disabled Behavior
PR Mode (prMode)This settings effects how the task decides which commit messages will actually be validated by examining the git history of the current repo and branch. Default
Enabled BehaviorWhen using 'PR Mode', the task will examine all of the commits in the PR that triggered the pipeline run. Ideally, this should be used if the pipeline that your build task is in is a pipeline which is triggered by a pull request. Disabled BehaviorWhen not using 'PR Mode', the task requires you to configure a diffBranch configuration. In this case, the task will compare the 'current' branch from the repository it is being run within w/ the configured 'diffBranch' (i.e. origin/main). So if the difference between the current repository and the configured 'diffBranch' is 3 commits, then all of these 3 commits will be examined against the configured regular expression. Diff. Branch (diffBranch)This configuration determines what branch to diff the 'current' branch (from the context of the repository that the running task is being run from) against when determining the commit messages to validate. It is required if prMode is false. Default
Regular Expression (regExPattern)The regular expression pattern (Irregexp flavor) to match commit messages against.\n\nA match means the commit message is valid.\n\nThe default pattern will match comments that are valid based on the Conventional Commits specification Default
Regular Expression Flags (regExFlags)Regular expression flags to use. OptionsSimply type a string of characters (no slashes or anything needed). With the 'u' flag, \p{Extended_Pictographic} will match an emoji character. Default
The default 'um' allows matching unicode and multiline. How to useAfter installing the extension, you can add the task to your pipeline. PR modeValidate all of the commits messages in the PR from a pipeline which is triggered by a PR in Azure Devops against conventional commit standards. Pair this with a GitVersion config that relies on conventional commit standards to determine package SemVer increment for auto-incrementing major/minor/patch versions reliably. Further pair this with Husky/git hooks that trigger git-cz or similar to automate enforcing devs using conventional commit standards for a truly automated package version experience.
Non PR ModeValidate that the commits that result from diffing the current branch against origin/main conventional commit standards.
RestrictionsThis task has only been tested against Azure DevOps pipelines. Also there are known issues with regular expression parsing if the build agent which is executing the task is running an older versions of Node (v6 to be exact although we havent' tested thoroughly on other versions). ContributeAt the moment this code is private but we would consider opening it up to the public. Drop a question in Q & A if you'd like to contribute. We pay attention to it! |