Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: integrate new development flow thjs-123 #128

Merged
merged 2 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: add new development flow thjs-123
  • Loading branch information
v0ldemar01 committed Jun 11, 2024
commit 696b7122bef3aa82f0b2666dfa92c6a38542ac34
50 changes: 11 additions & 39 deletions commitlint.config.ts
Original file line number Diff line number Diff line change
@@ -1,50 +1,22 @@
import { type SyncRule, type UserConfig } from '@commitlint/types';
import { RuleConfigSeverity, type UserConfig } from '@commitlint/types';

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

const COMMIT_MODIFIERS = ['+', '*', '-'];
const COMMIT_MESSAGE_REGEXP = new RegExp(
`^(((${ProjectPrefix.APP})-[0-9]{1,6})|(${ProjectPrefix.ENVIRONMENTS.join(
'|'
)})): ([${COMMIT_MODIFIERS.join(',')}]) (.*\\S)$`
);
const COMMIT_MESSAGE_MATCH_RULE_MESSAGE = `commit message doesn't match format requirements
Commit message must have one of the following formats:
- <project-prefix>-<issue-number>: <modifier> <description>
- <environment>: <modifier> <description>
Where:
- <project-prefix>: ${ProjectPrefix.APP}
- <modifier>: ${COMMIT_MODIFIERS.join(', ')}
- <environment>: ${ProjectPrefix.ENVIRONMENTS.join(', ')}
Examples:
- ${ProjectPrefix.APP}-5: + ui/ux lecture
- ${ProjectPrefix.APP}-12: * docker homework
- production: - comments in ui/ux homework`;

const configuration: UserConfig = {
defaultIgnores: true,
const config: UserConfig = {
extends: ['@commitlint/config-conventional'],
parserPreset: {
parserOpts: {
headerCorrespondence: ['prefix', 'modifier', 'description'],
headerPattern: COMMIT_MESSAGE_REGEXP
issuePrefixes: ProjectPrefix.ISSUE_PREFIXES.map(prefix => `${prefix}-`)
}
},
plugins: [
{
rules: {
'commit-message-match': (({ header }) => {
if (!COMMIT_MESSAGE_REGEXP.test(header as string)) {
return [false, COMMIT_MESSAGE_MATCH_RULE_MESSAGE];
}

return [true];
}) as SyncRule
}
}
],
rules: {
'commit-message-match': [2, 'always']
'references-empty': [RuleConfigSeverity.Error, 'never'],
'scope-enum': [
RuleConfigSeverity.Error,
'always',
[...ProjectPrefix.SCOPES.APPS, ...ProjectPrefix.SCOPES.PACKAGES]
]
}
};

export default configuration;
export default config;
84 changes: 41 additions & 43 deletions dangerfile.ts
Original file line number Diff line number Diff line change
@@ -1,58 +1,56 @@
import {
danger,
fail,
type GitHubPRDSL as LibraryGitHubDSL,
GitHubMergeRef,
GitHubRepo,
GitHubDSL
} from 'danger';
import { type GitHubPRDSL as LibraryGitHubDSL, danger, fail } from 'danger';

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

const LABELS_EMPTY_LENGTH = 0;

type GitHubPRDSL = LibraryGitHubDSL & {
head: GitHubMergeRef & {
repo: GitHubRepo & {
has_projects: boolean;
};
};
milestone: Record<string, unknown> | null;
labels: unknown[];
project_id: string | null;
milestone: Record<string, unknown> | null;
project_id: null | string;
};

const BranchPrefix = {
TASK: 'task',
FIX: 'fix'
} as const;

const DangerConfig = {
type DangerConfig = {
ASSIGNEES: {
IS_REQUIRED: boolean;
};
BRANCH: {
PATTERN: RegExp | null;
};
LABELS: {
IS_REQUIRED: boolean;
};
MILESTONE: {
IS_REQUIRED: boolean;
};
TITLE: {
IS_REQUIRED: true,
PATTERN: RegExp | null;
};
};

const config: DangerConfig = {
ASSIGNEES: {
IS_REQUIRED: true
},
BRANCH: {
PATTERN: new RegExp(
`^((${
ProjectPrefix.APP
})-[0-9]{1,6}): (.*\\S)$|(${ProjectPrefix.ENVIRONMENTS.join(
'|'
)}) to (${ProjectPrefix.ENVIRONMENTS.join('|')})$`
`^[0-9]{1,6}-${ProjectPrefix.CHANGE_TYPES.join('|')}-[a-zA-Z0-9-]+$|(${ProjectPrefix.ENVIRONMENTS.join('|')})$`
)
},
ASSIGNEES: {
LABELS: {
IS_REQUIRED: true
},
LABELS: {
MILESTONE: {
IS_REQUIRED: true
},
BRANCH: {
IS_REQUIRED: true,
TITLE: {
PATTERN: new RegExp(
`^((${Object.values(BranchPrefix).join('|')})/(${
ProjectPrefix.APP
})-[0-9]{1,6})-[a-zA-Z0-9-]+$|(${ProjectPrefix.ENVIRONMENTS.join('|')})$`
`^(${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})?$`
)
}
};

const { pr } = danger.github as GitHubDSL & Record<'pr', GitHubPRDSL>;
const pr = danger.github.pr as GitHubPRDSL;

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

const checkLabels = (): void => {
const hasLabels = pr.labels.length > 0;
const hasLabels = pr.labels.length > LABELS_EMPTY_LENGTH;

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

const applyDanger = (): void => {
if (DangerConfig.TITLE.IS_REQUIRED) {
checkTitle(DangerConfig.TITLE.PATTERN);
if (config.TITLE.PATTERN) {
checkTitle(config.TITLE.PATTERN);
}

if (DangerConfig.ASSIGNEES.IS_REQUIRED) {
if (config.ASSIGNEES.IS_REQUIRED) {
checkAssignees();
}

if (DangerConfig.LABELS.IS_REQUIRED) {
if (config.LABELS.IS_REQUIRED) {
checkLabels();
}

if (DangerConfig.BRANCH.IS_REQUIRED) {
checkBranch(DangerConfig.BRANCH.PATTERN);
if (config.BRANCH.PATTERN) {
checkBranch(config.BRANCH.PATTERN);
}
};

Expand Down
26 changes: 26 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
},
"devDependencies": {
"@commitlint/cli": "19.3.0",
"@commitlint/config-conventional": "19.2.2",
"@commitlint/types": "19.0.3",
"@eslint/js": "9.4.0",
"@ls-lint/ls-lint": "2.2.3",
Expand Down
21 changes: 19 additions & 2 deletions project.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
const ProjectPrefix = {
APP: 'thjs',
ENVIRONMENTS: ['development', 'production']
CHANGE_TYPES: [
'build',
'chore',
'ci',
'docs',
'feat',
'fix',
'perf',
'refactor',
'revert',
'style',
'test'
],
ENVIRONMENTS: ['production', 'development'],
ISSUE_PREFIXES: ['thjs'],
SCOPES: {
APPS: ['frontend', 'backend'],
PACKAGES: ['shared']
}
} as const;

export { ProjectPrefix };
Loading