@elsikora/git-branch-lint 1.1.0 → 1.1.1-dev.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +74 -15
- package/bin/application/use-cases/check-working-directory-use-case.d.ts +13 -0
- package/bin/application/use-cases/check-working-directory.use-case.d.ts +13 -0
- package/bin/application/use-cases/create-branch-use-case.d.ts +14 -0
- package/bin/application/use-cases/create-branch.use-case.d.ts +14 -0
- package/bin/application/use-cases/get-branch-config.use-case.d.ts +15 -0
- package/bin/application/use-cases/{get-current-branch-use-case.d.ts → get-current-branch.use-case.d.ts} +1 -1
- package/bin/application/use-cases/{lint-branch-name-use-case.d.ts → lint-branch-name.use-case.d.ts} +4 -4
- package/bin/application/use-cases/push-branch.use-case.d.ts +13 -0
- package/bin/application/use-cases/validate-branch-name-use-case.d.ts +15 -0
- package/bin/application/use-cases/validate-branch-name.use-case.d.ts +15 -0
- package/bin/domain/errors/branch-creation.error.d.ts +24 -0
- package/bin/domain/interface/branch.repository.interface.d.ts +23 -0
- package/bin/domain/{interfaces/repositories/iconfig-repository.d.ts → interface/config.repository.interface.d.ts} +2 -2
- package/bin/domain/interface/repository.interface.d.ts +2 -0
- package/bin/domain/type/branch.type.d.ts +5 -0
- package/bin/domain/type/config.type.d.ts +7 -0
- package/bin/domain/{interfaces → type}/rules.type.d.ts +1 -1
- package/bin/index.d.ts +1 -1
- package/bin/index.js +432 -188
- package/bin/index.js.map +1 -1
- package/bin/infrastructure/config/{cosmiconfig-repository.d.ts → cosmiconfig.repository.d.ts} +4 -4
- package/bin/infrastructure/git/git-branch.repository.d.ts +26 -0
- package/bin/presentation/cli/controllers/create-branch.controller.d.ts +25 -0
- package/bin/presentation/cli/{cli-controller.d.ts → controllers/lint.controller.d.ts} +5 -5
- package/bin/presentation/cli/formatters/branch-choice.formatter.d.ts +27 -0
- package/bin/presentation/cli/formatters/{hint-formatter.d.ts → hint.formatter.d.ts} +2 -2
- package/bin/presentation/cli/prompts/branch-creation.prompt.d.ts +25 -0
- package/package.json +25 -18
- package/bin/application/create-branch-tool/createBranch.d.ts +0 -1
- package/bin/application/create-branch-tool/utils/alignChoices.d.ts +0 -8
- package/bin/application/create-branch-tool/utils/branchNameQuiz.d.ts +0 -2
- package/bin/application/create-branch-tool/utils/runGitCommand.d.ts +0 -1
- package/bin/application/use-cases/get-branch-config-use-case.d.ts +0 -19
- package/bin/domain/interfaces/branch.type.d.ts +0 -5
- package/bin/domain/interfaces/config.type.d.ts +0 -7
- package/bin/domain/interfaces/repositories/ibranch-repository.d.ts +0 -9
- package/bin/domain/interfaces/repository-interfaces.d.ts +0 -2
- package/bin/domain/repositories/branch-repository.d.ts +0 -10
- package/bin/domain/repositories/config-repository.d.ts +0 -12
- package/bin/infrastructure/git/git-branch-repository.d.ts +0 -11
- /package/bin/domain/{entities/branch.d.ts → entity/branch.entity.d.ts} +0 -0
- /package/bin/domain/errors/{lint-errors.d.ts → lint.error.d.ts} +0 -0
- /package/bin/presentation/cli/formatters/{error-formatter.d.ts → error.formatter.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -38,13 +38,13 @@ Git Branch Lint is a powerful tool designed to maintain consistent git branch na
|
|
|
38
38
|
## 🛠 Installation
|
|
39
39
|
```bash
|
|
40
40
|
# Using npm
|
|
41
|
-
npm install --save-dev git-branch-lint
|
|
41
|
+
npm install --save-dev @elsikora/git-branch-lint
|
|
42
42
|
|
|
43
43
|
# Using yarn
|
|
44
|
-
yarn add -D git-branch-lint
|
|
44
|
+
yarn add -D @elsikora/git-branch-lint
|
|
45
45
|
|
|
46
46
|
# Using pnpm
|
|
47
|
-
pnpm add -D git-branch-lint
|
|
47
|
+
pnpm add -D @elsikora/git-branch-lint
|
|
48
48
|
```
|
|
49
49
|
|
|
50
50
|
## 💡 Usage
|
|
@@ -52,7 +52,7 @@ pnpm add -D git-branch-lint
|
|
|
52
52
|
|
|
53
53
|
Run the linter directly:
|
|
54
54
|
```bash
|
|
55
|
-
git-branch-lint
|
|
55
|
+
npx @elsikora/git-branch-lint
|
|
56
56
|
```
|
|
57
57
|
|
|
58
58
|
## Configuration
|
|
@@ -78,7 +78,7 @@ Add to your `package.json`:
|
|
|
78
78
|
{
|
|
79
79
|
"husky": {
|
|
80
80
|
"hooks": {
|
|
81
|
-
"pre-commit": "git-branch-lint"
|
|
81
|
+
"pre-commit": "npx @elsikora/git-branch-lint"
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
}
|
|
@@ -89,18 +89,77 @@ Add to your `package.json`:
|
|
|
89
89
|
Custom configuration in JavaScript (`.elsikora/git-branch-lint.config.js`):
|
|
90
90
|
```javascript
|
|
91
91
|
module.exports = {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
92
|
+
branches: {
|
|
93
|
+
bugfix: { description: "🐞 Fixing issues in existing functionality", title: "Bugfix" },
|
|
94
|
+
feature: { description: "🆕 Integration of new functionality", title: "Feature" },
|
|
95
|
+
hotfix: { description: "🚑 Critical fixes for urgent issues", title: "Hotfix" },
|
|
96
|
+
release: { description: "📦 Preparing a new release version", title: "Release" },
|
|
97
|
+
support: { description: "🛠️ Support and maintenance tasks", title: "Support" },
|
|
98
|
+
},
|
|
99
|
+
ignore: ["dev"],
|
|
100
|
+
rules: {
|
|
101
|
+
"branch-max-length": 50,
|
|
102
|
+
"branch-min-length": 5,
|
|
103
|
+
"branch-pattern": ":type/:name",
|
|
104
|
+
"branch-prohibited": ["main", "master", "release"],
|
|
105
|
+
"branch-subject-pattern": "[a-z0-9-]+",
|
|
106
|
+
},
|
|
101
107
|
}
|
|
102
108
|
```
|
|
103
109
|
|
|
110
|
+
Typescript support (`.elsikora/git-branch-lint.config.ts`):
|
|
111
|
+
```typescript
|
|
112
|
+
import type { BranchLintConfig } from "@elsikora/git-branch-lint";
|
|
113
|
+
|
|
114
|
+
const config: BranchLintConfig = {
|
|
115
|
+
branches: {
|
|
116
|
+
bugfix: { description: "🆕 Integration of new functionality", title: "Feature" },
|
|
117
|
+
feature: { description: "🐞 Fixing issues in existing functionality", title: "Bugfix" },
|
|
118
|
+
hotfix: { description: "🚑 Critical fixes for urgent issues", title: "Hotfix" },
|
|
119
|
+
release: { description: "📦 Preparing a new release version", title: "Release" },
|
|
120
|
+
support: { description: "🛠️ Support and maintenance tasks", title: "Support" },
|
|
121
|
+
},
|
|
122
|
+
ignore: [dev],
|
|
123
|
+
rules: {
|
|
124
|
+
"branch-max-length": 50,
|
|
125
|
+
"branch-min-length": 5,
|
|
126
|
+
"branch-pattern": ":type/:name",
|
|
127
|
+
"branch-prohibited": ["main", "master", "release"],
|
|
128
|
+
"branch-subject-pattern": "[a-z0-9-]+",
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
export default config;
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Create branch tool
|
|
136
|
+
|
|
137
|
+
Create branch tool is a command-line utility included in the @elsikora/branch-lint package. It facilitates the creation of Git branches by guiding users through an interactive prompt to select a branch type and name, ensuring compliance with the project's branch naming conventions as defined in the configuration.
|
|
138
|
+
|
|
139
|
+
Example:
|
|
140
|
+
```bash
|
|
141
|
+
npx @elsikora/branch-lint -b
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Prompts:
|
|
145
|
+
```bash
|
|
146
|
+
🌿 Creating a new branch...
|
|
147
|
+
|
|
148
|
+
❔ Select the type of branch you're creating:
|
|
149
|
+
Feature: 🆕 Integration of new functionality
|
|
150
|
+
Bugfix: 🐞 Fixing issues in existing functionality
|
|
151
|
+
❯ Hotfix: 🚑 Critical fixes for urgent issues
|
|
152
|
+
Release: 📦 Preparing a new release version
|
|
153
|
+
Support: 🛠️ Support and maintenance tasks
|
|
154
|
+
|
|
155
|
+
Enter the branch name (e.g., authorization): new-ui
|
|
156
|
+
|
|
157
|
+
⌛️ Creating branch: feature/new-ui
|
|
158
|
+
Do you want to push the branch to the remote repository? (y/N) y
|
|
159
|
+
|
|
160
|
+
✅ Branch feature/new-ui pushed to remote repository!
|
|
161
|
+
```
|
|
162
|
+
|
|
104
163
|
## CI/CD Integration
|
|
105
164
|
|
|
106
165
|
GitHub Actions example:
|
|
@@ -115,7 +174,7 @@ jobs:
|
|
|
115
174
|
- uses: actions/checkout@v2
|
|
116
175
|
- uses: actions/setup-node@v2
|
|
117
176
|
- run: npm install
|
|
118
|
-
- run: npx git-branch-lint
|
|
177
|
+
- run: npx @elsikora/git-branch-lint
|
|
119
178
|
```
|
|
120
179
|
|
|
121
180
|
## 🛣 Roadmap
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { IBranchRepository } from "../../domain/interface/branch.repository.interface";
|
|
2
|
+
/**
|
|
3
|
+
* Use case for checking working directory status
|
|
4
|
+
*/
|
|
5
|
+
export declare class CheckWorkingDirectoryUseCase {
|
|
6
|
+
private readonly branchRepository;
|
|
7
|
+
constructor(branchRepository: IBranchRepository);
|
|
8
|
+
/**
|
|
9
|
+
* Execute the use case
|
|
10
|
+
* @throws {UncommittedChangesError} When there are uncommitted changes
|
|
11
|
+
*/
|
|
12
|
+
execute(): Promise<void>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { IBranchRepository } from "../../domain/interface/branch.repository.interface";
|
|
2
|
+
/**
|
|
3
|
+
* Use case for checking working directory status
|
|
4
|
+
*/
|
|
5
|
+
export declare class CheckWorkingDirectoryUseCase {
|
|
6
|
+
private readonly branchRepository;
|
|
7
|
+
constructor(branchRepository: IBranchRepository);
|
|
8
|
+
/**
|
|
9
|
+
* Execute the use case
|
|
10
|
+
* @throws {UncommittedChangesError} When there are uncommitted changes
|
|
11
|
+
*/
|
|
12
|
+
execute(): Promise<void>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { IBranchRepository } from "../../domain/interface/branch.repository.interface";
|
|
2
|
+
/**
|
|
3
|
+
* Use case for creating a new branch
|
|
4
|
+
*/
|
|
5
|
+
export declare class CreateBranchUseCase {
|
|
6
|
+
private readonly branchRepository;
|
|
7
|
+
constructor(branchRepository: IBranchRepository);
|
|
8
|
+
/**
|
|
9
|
+
* Execute the use case
|
|
10
|
+
* @param branchName The name of the branch to create
|
|
11
|
+
* @throws {BranchAlreadyExistsError} When trying to create current branch
|
|
12
|
+
*/
|
|
13
|
+
execute(branchName: string): Promise<void>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { IBranchRepository } from "../../domain/interface/branch.repository.interface";
|
|
2
|
+
/**
|
|
3
|
+
* Use case for creating a new branch
|
|
4
|
+
*/
|
|
5
|
+
export declare class CreateBranchUseCase {
|
|
6
|
+
private readonly branchRepository;
|
|
7
|
+
constructor(branchRepository: IBranchRepository);
|
|
8
|
+
/**
|
|
9
|
+
* Execute the use case
|
|
10
|
+
* @param branchName The name of the branch to create
|
|
11
|
+
* @throws {BranchAlreadyExistsError} When trying to create current branch
|
|
12
|
+
*/
|
|
13
|
+
execute(branchName: string): Promise<void>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { IConfigRepository } from "../../domain/interface/config.repository.interface";
|
|
2
|
+
import type { IBranchLintConfig } from "../../domain/type/config.type";
|
|
3
|
+
/**
|
|
4
|
+
* Use case for retrieving branch configuration
|
|
5
|
+
*/
|
|
6
|
+
export declare class GetBranchConfigUseCase {
|
|
7
|
+
private readonly configRepository;
|
|
8
|
+
constructor(configRepository: IConfigRepository);
|
|
9
|
+
/**
|
|
10
|
+
* Execute the use case
|
|
11
|
+
* @param appName - The application name
|
|
12
|
+
* @returns The branch configuration
|
|
13
|
+
*/
|
|
14
|
+
execute(appName: string): Promise<IBranchLintConfig>;
|
|
15
|
+
}
|
package/bin/application/use-cases/{lint-branch-name-use-case.d.ts → lint-branch-name.use-case.d.ts}
RENAMED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { IBranchLintConfig } from "../../domain/type/config.type";
|
|
2
2
|
/**
|
|
3
|
-
* Use case for linting
|
|
3
|
+
* Use case for linting branch names
|
|
4
4
|
*/
|
|
5
5
|
export declare class LintBranchNameUseCase {
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* Execute the use case
|
|
8
8
|
* @param branchName The branch name to lint
|
|
9
9
|
* @param config The branch configuration
|
|
10
10
|
* @throws {ProhibitedBranchError} When branch name is prohibited
|
|
@@ -12,7 +12,7 @@ export declare class LintBranchNameUseCase {
|
|
|
12
12
|
* @throws {BranchTooShortError} When branch name is shorter than the minimum length
|
|
13
13
|
* @throws {BranchTooLongError} When branch name is longer than the maximum length
|
|
14
14
|
*/
|
|
15
|
-
execute(branchName: string, config:
|
|
15
|
+
execute(branchName: string, config: IBranchLintConfig): void;
|
|
16
16
|
/**
|
|
17
17
|
* Validate the branch name against the pattern
|
|
18
18
|
* @param branchName The branch name to validate
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { IBranchRepository } from "../../domain/interface/branch.repository.interface";
|
|
2
|
+
/**
|
|
3
|
+
* Use case for pushing a branch to remote repository
|
|
4
|
+
*/
|
|
5
|
+
export declare class PushBranchUseCase {
|
|
6
|
+
private readonly branchRepository;
|
|
7
|
+
constructor(branchRepository: IBranchRepository);
|
|
8
|
+
/**
|
|
9
|
+
* Execute the use case
|
|
10
|
+
* @param branchName The name of the branch to push
|
|
11
|
+
*/
|
|
12
|
+
execute(branchName: string): Promise<void>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Use case for validating branch name format
|
|
3
|
+
*/
|
|
4
|
+
export declare class ValidateBranchNameUseCase {
|
|
5
|
+
private readonly BRANCH_NAME_PATTERN;
|
|
6
|
+
/**
|
|
7
|
+
* Execute the use case
|
|
8
|
+
* @param branchName The branch name to validate
|
|
9
|
+
* @returns Validation result with error message if invalid
|
|
10
|
+
*/
|
|
11
|
+
execute(branchName: string): {
|
|
12
|
+
errorMessage?: string;
|
|
13
|
+
isValid: boolean;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Use case for validating branch name format
|
|
3
|
+
*/
|
|
4
|
+
export declare class ValidateBranchNameUseCase {
|
|
5
|
+
private readonly BRANCH_NAME_PATTERN;
|
|
6
|
+
/**
|
|
7
|
+
* Execute the use case
|
|
8
|
+
* @param branchName The branch name to validate
|
|
9
|
+
* @returns Validation result with error message if invalid
|
|
10
|
+
*/
|
|
11
|
+
execute(branchName: string): {
|
|
12
|
+
errorMessage?: string;
|
|
13
|
+
isValid: boolean;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base error class for branch creation errors
|
|
3
|
+
*/
|
|
4
|
+
export declare class BranchCreationError extends Error {
|
|
5
|
+
constructor(message: string);
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Error thrown when trying to create a branch that already exists
|
|
9
|
+
*/
|
|
10
|
+
export declare class BranchAlreadyExistsError extends BranchCreationError {
|
|
11
|
+
constructor(branchName: string);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Error thrown when git operation fails
|
|
15
|
+
*/
|
|
16
|
+
export declare class GitOperationError extends BranchCreationError {
|
|
17
|
+
constructor(operation: string, details?: string);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Error thrown when working directory has uncommitted changes
|
|
21
|
+
*/
|
|
22
|
+
export declare class UncommittedChangesError extends BranchCreationError {
|
|
23
|
+
constructor();
|
|
24
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Repository interface for branch operations
|
|
3
|
+
*/
|
|
4
|
+
export interface IBranchRepository {
|
|
5
|
+
/**
|
|
6
|
+
* Create a new branch
|
|
7
|
+
* @param branchName The name of the branch to create
|
|
8
|
+
*/
|
|
9
|
+
createBranch(branchName: string): Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* Get the current branch name
|
|
12
|
+
*/
|
|
13
|
+
getCurrentBranchName(): Promise<string>;
|
|
14
|
+
/**
|
|
15
|
+
* Check if working directory has uncommitted changes
|
|
16
|
+
*/
|
|
17
|
+
hasUncommittedChanges(): Promise<boolean>;
|
|
18
|
+
/**
|
|
19
|
+
* Push branch to remote repository
|
|
20
|
+
* @param branchName The name of the branch to push
|
|
21
|
+
*/
|
|
22
|
+
pushBranch(branchName: string): Promise<void>;
|
|
23
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { BranchLintConfig } from "../config.type";
|
|
2
1
|
/**
|
|
3
2
|
* Repository interface for configuration operations
|
|
4
3
|
*/
|
|
4
|
+
import type { IBranchLintConfig } from "../type/config.type";
|
|
5
5
|
export interface IConfigRepository {
|
|
6
6
|
/**
|
|
7
7
|
* Get the branch configuration
|
|
8
8
|
* @param appName The name of the application
|
|
9
9
|
*/
|
|
10
|
-
getConfig(appName: string): Promise<
|
|
10
|
+
getConfig(appName: string): Promise<IBranchLintConfig>;
|
|
11
11
|
}
|
package/bin/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export type {
|
|
1
|
+
export type { IBranchLintConfig } from "./domain/type/config.type";
|