Skip to content

Commit 4337e05

Browse files
authored
ci: conventional commits aws#5484
- Rename "topic" to "type". - Add "deps" type. - Require a scope for "feat" and "fix".
1 parent 0486797 commit 4337e05

File tree

2 files changed

+37
-33
lines changed

2 files changed

+37
-33
lines changed

.github/workflows/lintcommit.js

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,20 @@ const fs = require('fs')
2020
// const core = require('@actions/core')
2121
// const github = require('@actions/github')
2222

23-
const topics = new Set([
23+
const types = new Set([
2424
'build',
2525
// Don't allow "chore" because it's over-used.
26-
// Instead, add a new topic if absolutely needed (if the existing ones can't possibly apply).
26+
// Instead, add a new type if absolutely needed (if the existing ones can't possibly apply).
2727
// 'chore',
2828
'ci',
2929
'config',
30+
'deps',
3031
'docs',
3132
'feat',
3233
'fix',
3334
'perf',
3435
'refactor',
36+
'revert',
3537
'style',
3638
'telemetry',
3739
'test',
@@ -42,23 +44,26 @@ const topics = new Set([
4244
const scopes = new Set([
4345
'amazonq',
4446
'core',
47+
'explorer',
4548
'lambda',
4649
'logs',
4750
'redshift',
4851
'q-chat',
4952
'q-featuredev',
5053
'q-inlinechat',
5154
'q-transform',
55+
'sam',
5256
's3',
5357
'telemetry',
58+
'toolkit',
5459
'ui',
5560
])
5661
void scopes
5762

5863
/**
5964
* Checks that a pull request title, or commit message subject, follows the expected format:
6065
*
61-
* topic(scope): message
66+
* type(scope): message
6267
*
6368
* Returns undefined if `title` is valid, else an error message.
6469
*/
@@ -70,22 +75,20 @@ function validateTitle(title) {
7075
return 'missing colon (:) char'
7176
}
7277

73-
const topicScope = parts[0]
78+
const typeScope = parts[0]
7479

75-
if (topicScope.startsWith('revert')) {
76-
return validateTitle(subject)
77-
}
78-
79-
const [topic, scope] = topicScope.split(/\(([^)]+)\)$/)
80+
const [type, scope] = typeScope.split(/\(([^)]+)\)$/)
8081

81-
if (/\s+/.test(topic)) {
82-
return `topic contains whitespace: "${topic}"`
83-
} else if (topic === 'chore') {
84-
return 'do not use "chore" as a topic. If the existing valid topics are insufficent, add a new topic to the `lintcommit.js` script.'
85-
} else if (!topics.has(topic)) {
86-
return `invalid topic "${topic}"`
87-
} else if (!scope && topicScope.includes('(')) {
88-
return `must be formatted like topic(scope):`
82+
if (/\s+/.test(type)) {
83+
return `type contains whitespace: "${type}"`
84+
} else if (type === 'chore') {
85+
return 'Do not use "chore" as a type. If the existing valid types are insufficent, add a new type to the `lintcommit.js` script.'
86+
} else if (!types.has(type)) {
87+
return `invalid type "${type}"`
88+
} else if (!scope && typeScope.includes('(')) {
89+
return `must be formatted like type(scope):`
90+
} else if (!scope && ['feat', 'fix'].includes(type)) {
91+
return `"${type}" type must include a scope (example: "${type}(amazonq)")`
8992
} else if (scope && scope.length > 30) {
9093
return 'invalid scope (must be <=30 chars)'
9194
} else if (scope && /[^- a-z0-9]+/.test(scope)) {
@@ -115,14 +118,14 @@ function run() {
115118
const failReason = validateTitle(title)
116119
const msg = failReason
117120
? `
118-
Pull request title does not match the [expected format](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#pull-request-title):
121+
Invalid pull request title: \`${title}\`
119122
120-
* Title: \`${title}\`
121-
* Reason: ${failReason}
122-
* Expected format: \`topic(scope): subject...\`
123-
* topic: one of (${Array.from(topics).join(', ')})
123+
* Problem: ${failReason}
124+
* Expected format: \`type(scope): subject...\`
125+
* type: one of (${Array.from(types).join(', ')})
124126
* scope: lowercase, <30 chars
125127
* subject: must be <100 chars
128+
* documentation: https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#pull-request-title
126129
`
127130
: `Pull request title matches the [expected format](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#pull-request-title).`
128131

@@ -140,27 +143,28 @@ Pull request title does not match the [expected format](https://github.com/aws/a
140143

141144
function _test() {
142145
const tests = {
143-
' foo(scope): bar': 'topic contains whitespace: " foo"',
146+
' foo(scope): bar': 'type contains whitespace: " foo"',
144147
'build: update build process': undefined,
145148
'chore: update dependencies':
146-
'do not use "chore" as a topic. If the existing valid topics are insufficent, add a new topic to the `lintcommit.js` script.',
149+
'Do not use "chore" as a type. If the existing valid types are insufficent, add a new type to the `lintcommit.js` script.',
147150
'ci: configure CI/CD': undefined,
148151
'config: update configuration files': undefined,
152+
'deps: bump the aws-sdk group across 1 directory with 5 updates': undefined,
149153
'docs: update documentation': undefined,
150154
'feat(foo): add new feature': undefined,
151155
'feat(foo):': 'empty subject',
152-
'feat foo):': 'topic contains whitespace: "feat foo)"',
153-
'feat(foo)): sujet': 'invalid topic "feat(foo))"',
154-
'feat(foo: sujet': 'invalid topic "feat(foo"',
155-
'feat(q foo bar): bar':
156-
'do not use "chore" as a topic. If the existing valid topics are insufficent, add a new topic to the `lintcommit.js` script.',
156+
'feat foo):': 'type contains whitespace: "feat foo)"',
157+
'feat(foo)): sujet': 'invalid type "feat(foo))"',
158+
'feat(foo: sujet': 'invalid type "feat(foo"',
157159
'feat(Q Foo Bar): bar': 'invalid scope (must be lowercase, ascii only): "Q Foo Bar"',
158160
'feat(scope):': 'empty subject',
159161
'feat(q foo bar): bar': undefined,
160162
'feat(foo): x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x ':
161163
'invalid subject (must be <=100 chars)',
164+
'feat: foo': '"feat" type must include a scope (example: "feat(amazonq)")',
165+
'fix: foo': '"fix" type must include a scope (example: "fix(amazonq)")',
162166
'fix(a-b-c): resolve issue': undefined,
163-
'foo (scope): bar': 'topic contains whitespace: "foo "',
167+
'foo (scope): bar': 'type contains whitespace: "foo "',
164168
'invalid title': 'missing colon (:) char',
165169
'perf: optimize performance': undefined,
166170
'refactor: improve code structure': undefined,

CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,8 @@ user's point of view.
283283
284284
The title of your pull request must follow this format (checked by [lintcommit.js](.github/workflows/lintcommit.js)):
285285
286-
- format: `topic(scope): subject...`
287-
- topic: must be a valid topic (`build`, `ci`, `config`, `docs`, `feat`, `fix`, `perf`, `refactor`, `style`, `telemetry`, `test`, `types`)
286+
- format: `type(scope): subject...`
287+
- type: must be a valid type (`build`, `ci`, `config`, `deps`, `docs`, `feat`, `fix`, `perf`, `refactor`, `style`, `telemetry`, `test`, `types`)
288288
- see [lintcommit.js](.github/workflows/lintcommit.js))
289289
- "chore" is intentionally rejected because it tends to be over-used.
290290
- user-facing changes should always choose "feat" or "fix", and include a [changelog](#changelog) item.
@@ -320,7 +320,7 @@ guidelines](https://cbea.ms/git-commit/):
320320
321321
- Subject: single line up to 50-72 characters
322322
- Imperative voice ("Fix bug", not "Fixed"/"Fixes"/"Fixing").
323-
- [Formatted as `topic(scope): subject...`](#pull-request-title).
323+
- [Formatted as `type(scope): subject...`](#pull-request-title).
324324
- Helps humans _and_ scripts scan and omit ranges of the history at a glance.
325325
- Body: describe the change as a [Problem/Solution pair](#pull-request-description).
326326

0 commit comments

Comments
 (0)