Skip to content

Commit 02c7e6f

Browse files
authored
Merge pull request #128 from BinaryStudioAcademy/123-feat-integrate-new-development-flow
feat: integrate new development flow thjs-123
2 parents 48d91f6 + a5af7f3 commit 02c7e6f

File tree

5 files changed

+97
-83
lines changed

5 files changed

+97
-83
lines changed

commitlint.config.ts

Lines changed: 11 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,22 @@
1-
import { type SyncRule, type UserConfig } from '@commitlint/types';
1+
import { RuleConfigSeverity, type UserConfig } from '@commitlint/types';
22

33
import { ProjectPrefix } from './project.config.js';
44

5-
const COMMIT_MODIFIERS = ['+', '*', '-'];
6-
const COMMIT_MESSAGE_REGEXP = new RegExp(
7-
`^(((${ProjectPrefix.APP})-[0-9]{1,6})|(${ProjectPrefix.ENVIRONMENTS.join(
8-
'|'
9-
)})): ([${COMMIT_MODIFIERS.join(',')}]) (.*\\S)$`
10-
);
11-
const COMMIT_MESSAGE_MATCH_RULE_MESSAGE = `commit message doesn't match format requirements
12-
Commit message must have one of the following formats:
13-
- <project-prefix>-<issue-number>: <modifier> <description>
14-
- <environment>: <modifier> <description>
15-
Where:
16-
- <project-prefix>: ${ProjectPrefix.APP}
17-
- <modifier>: ${COMMIT_MODIFIERS.join(', ')}
18-
- <environment>: ${ProjectPrefix.ENVIRONMENTS.join(', ')}
19-
Examples:
20-
- ${ProjectPrefix.APP}-5: + ui/ux lecture
21-
- ${ProjectPrefix.APP}-12: * docker homework
22-
- production: - comments in ui/ux homework`;
23-
24-
const configuration: UserConfig = {
25-
defaultIgnores: true,
5+
const config: UserConfig = {
6+
extends: ['@commitlint/config-conventional'],
267
parserPreset: {
278
parserOpts: {
28-
headerCorrespondence: ['prefix', 'modifier', 'description'],
29-
headerPattern: COMMIT_MESSAGE_REGEXP
9+
issuePrefixes: ProjectPrefix.ISSUE_PREFIXES.map(prefix => `${prefix}-`)
3010
}
3111
},
32-
plugins: [
33-
{
34-
rules: {
35-
'commit-message-match': (({ header }) => {
36-
if (!COMMIT_MESSAGE_REGEXP.test(header as string)) {
37-
return [false, COMMIT_MESSAGE_MATCH_RULE_MESSAGE];
38-
}
39-
40-
return [true];
41-
}) as SyncRule
42-
}
43-
}
44-
],
4512
rules: {
46-
'commit-message-match': [2, 'always']
13+
'references-empty': [RuleConfigSeverity.Error, 'never'],
14+
'scope-enum': [
15+
RuleConfigSeverity.Error,
16+
'always',
17+
[...ProjectPrefix.SCOPES.APPS, ...ProjectPrefix.SCOPES.PACKAGES]
18+
]
4719
}
4820
};
4921

50-
export default configuration;
22+
export default config;

dangerfile.ts

Lines changed: 40 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,56 @@
1-
import {
2-
danger,
3-
fail,
4-
type GitHubPRDSL as LibraryGitHubDSL,
5-
GitHubMergeRef,
6-
GitHubRepo,
7-
GitHubDSL
8-
} from 'danger';
1+
import { type GitHubPRDSL as LibraryGitHubDSL, danger, fail } from 'danger';
92

103
import { ProjectPrefix } from './project.config';
114

5+
const LABELS_EMPTY_LENGTH = 0;
6+
127
type GitHubPRDSL = LibraryGitHubDSL & {
13-
head: GitHubMergeRef & {
14-
repo: GitHubRepo & {
15-
has_projects: boolean;
16-
};
17-
};
18-
milestone: Record<string, unknown> | null;
198
labels: unknown[];
20-
project_id: string | null;
9+
milestone: Record<string, unknown> | null;
10+
project_id: null | string;
2111
};
2212

23-
const BranchPrefix = {
24-
TASK: 'task',
25-
FIX: 'fix'
26-
} as const;
27-
28-
const DangerConfig = {
13+
type DangerConfig = {
14+
ASSIGNEES: {
15+
IS_REQUIRED: boolean;
16+
};
17+
BRANCH: {
18+
PATTERN: RegExp | null;
19+
};
20+
LABELS: {
21+
IS_REQUIRED: boolean;
22+
};
23+
MILESTONE: {
24+
IS_REQUIRED: boolean;
25+
};
2926
TITLE: {
30-
IS_REQUIRED: true,
27+
PATTERN: RegExp | null;
28+
};
29+
};
30+
31+
const config: DangerConfig = {
32+
ASSIGNEES: {
33+
IS_REQUIRED: true
34+
},
35+
BRANCH: {
3136
PATTERN: new RegExp(
32-
`^((${
33-
ProjectPrefix.APP
34-
})-[0-9]{1,6}): (.*\\S)$|(${ProjectPrefix.ENVIRONMENTS.join(
35-
'|'
36-
)}) to (${ProjectPrefix.ENVIRONMENTS.join('|')})$`
37+
`^[0-9]{1,6}-${ProjectPrefix.CHANGE_TYPES.join('|')}-[a-zA-Z0-9-]+$|(${ProjectPrefix.ENVIRONMENTS.join('|')})$`
3738
)
3839
},
39-
ASSIGNEES: {
40+
LABELS: {
4041
IS_REQUIRED: true
4142
},
42-
LABELS: {
43+
MILESTONE: {
4344
IS_REQUIRED: true
4445
},
45-
BRANCH: {
46-
IS_REQUIRED: true,
46+
TITLE: {
4747
PATTERN: new RegExp(
48-
`^((${Object.values(BranchPrefix).join('|')})/(${
49-
ProjectPrefix.APP
50-
})-[0-9]{1,6})-[a-zA-Z0-9-]+$|(${ProjectPrefix.ENVIRONMENTS.join('|')})$`
48+
`^(${ProjectPrefix.CHANGE_TYPES.join('|')})(\\((${ProjectPrefix.SCOPES.APPS.join('|')}|${ProjectPrefix.SCOPES.PACKAGES.join('|')})(\\/(${ProjectPrefix.SCOPES.APPS.join('|')}|${ProjectPrefix.SCOPES.PACKAGES.join('|')}))*\\))?: (.*\\S )?(${ProjectPrefix.ISSUE_PREFIXES.join('|')})-[0-9]{1,6}((\\.[0-9]+){1,2})?$`
5149
)
5250
}
5351
};
5452

55-
const { pr } = danger.github as GitHubDSL & Record<'pr', GitHubPRDSL>;
53+
const pr = danger.github.pr as GitHubPRDSL;
5654

5755
const checkAssignees = (): void => {
5856
const hasAssignees = Boolean(pr.assignee);
@@ -75,7 +73,7 @@ const checkTitle = (titlePattern: RegExp): void => {
7573
};
7674

7775
const checkLabels = (): void => {
78-
const hasLabels = pr.labels.length > 0;
76+
const hasLabels = pr.labels.length > LABELS_EMPTY_LENGTH;
7977

8078
if (!hasLabels) {
8179
fail('This pull request should have at least one label.');
@@ -95,20 +93,20 @@ const checkBranch = (branchPattern: RegExp): void => {
9593
};
9694

9795
const applyDanger = (): void => {
98-
if (DangerConfig.TITLE.IS_REQUIRED) {
99-
checkTitle(DangerConfig.TITLE.PATTERN);
96+
if (config.TITLE.PATTERN) {
97+
checkTitle(config.TITLE.PATTERN);
10098
}
10199

102-
if (DangerConfig.ASSIGNEES.IS_REQUIRED) {
100+
if (config.ASSIGNEES.IS_REQUIRED) {
103101
checkAssignees();
104102
}
105103

106-
if (DangerConfig.LABELS.IS_REQUIRED) {
104+
if (config.LABELS.IS_REQUIRED) {
107105
checkLabels();
108106
}
109107

110-
if (DangerConfig.BRANCH.IS_REQUIRED) {
111-
checkBranch(DangerConfig.BRANCH.PATTERN);
108+
if (config.BRANCH.PATTERN) {
109+
checkBranch(config.BRANCH.PATTERN);
112110
}
113111
};
114112

package-lock.json

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
},
3030
"devDependencies": {
3131
"@commitlint/cli": "19.3.0",
32+
"@commitlint/config-conventional": "19.2.2",
3233
"@commitlint/types": "19.0.3",
3334
"@eslint/js": "9.4.0",
3435
"@ls-lint/ls-lint": "2.2.3",

project.config.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
11
const ProjectPrefix = {
2-
APP: 'thjs',
3-
ENVIRONMENTS: ['development', 'production']
2+
CHANGE_TYPES: [
3+
'build',
4+
'chore',
5+
'ci',
6+
'docs',
7+
'feat',
8+
'fix',
9+
'perf',
10+
'refactor',
11+
'revert',
12+
'style',
13+
'test'
14+
],
15+
ENVIRONMENTS: ['production', 'development'],
16+
ISSUE_PREFIXES: ['thjs'],
17+
SCOPES: {
18+
APPS: ['frontend', 'backend'],
19+
PACKAGES: ['shared']
20+
}
421
} as const;
522

623
export { ProjectPrefix };

0 commit comments

Comments
 (0)