nitor 1.0.0 → 1.1.0
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/CHANGELOG.md +8 -0
- package/README.md +16 -10
- package/package.json +1 -1
- package/services/cleanup.js +63 -0
- package/services/enums/actions.enum.js +7 -6
- package/services/process-commands.js +26 -1
package/CHANGELOG.md
CHANGED
|
@@ -16,3 +16,11 @@ We are pleased to announce the first official release of **Nitor**.
|
|
|
16
16
|
- Scriptable and extensible for automation and integration into larger workflows.
|
|
17
17
|
|
|
18
18
|
For a complete list of changes and discussion, see [Issue #1](https://github.com/codebynithin/nitor/issues/1).
|
|
19
|
+
|
|
20
|
+
## [1.1.0] - 2025-11-14
|
|
21
|
+
|
|
22
|
+
### New Features
|
|
23
|
+
|
|
24
|
+
- Added cleanup command to delete all local branches except master/main.
|
|
25
|
+
|
|
26
|
+
- [Issue #6](https://github.com/codebynithin/nitor/issues/6)
|
package/README.md
CHANGED
|
@@ -23,22 +23,23 @@ A CLI utility toolkit for automating and managing build, deploy, and status oper
|
|
|
23
23
|
- AI text refactoring
|
|
24
24
|
- Backup and restore MongoDB
|
|
25
25
|
- Merge git branches
|
|
26
|
+
- Cleanup local git branches
|
|
26
27
|
|
|
27
28
|
## Requirements
|
|
28
29
|
|
|
29
30
|
- Node.js >= 14.x
|
|
30
31
|
- npm >= 6.x
|
|
31
32
|
- A properly configured `.env.nu` file in your `~/Desktop` directory with required tokens and URLs:
|
|
32
|
-
- `CSRF_TOKEN`
|
|
33
|
-
- `COOKIE`
|
|
34
|
-
- `ORIGIN`
|
|
35
|
-
- `GITLAB_TOKEN`
|
|
36
|
-
- `MR_PROMPT`
|
|
37
|
-
- `MR_LANG`
|
|
38
|
-
- `AI_API_KEY`
|
|
39
|
-
- `AI_MODEL`
|
|
40
|
-
- `BACKUP_CONFIG`
|
|
41
|
-
- `RESTORE_CONFIG`
|
|
33
|
+
- `CSRF_TOKEN` - CSRF token for Gitlab (Copy from browser)
|
|
34
|
+
- `COOKIE` - Cookie for Gitlab (Copy from browser)
|
|
35
|
+
- `ORIGIN` - Origin for Gitlab website url, eg: `https://gitlab.com/`
|
|
36
|
+
- `GITLAB_TOKEN` - Gitlab token
|
|
37
|
+
- `MR_PROMPT` - Merge request prompt
|
|
38
|
+
- `MR_LANG` - Merge request language
|
|
39
|
+
- `AI_API_KEY` - AI API key
|
|
40
|
+
- `AI_MODEL` - AI model
|
|
41
|
+
- `BACKUP_CONFIG` - Backup configuration
|
|
42
|
+
- `RESTORE_CONFIG` - Restore configuration
|
|
42
43
|
|
|
43
44
|
## Usage
|
|
44
45
|
|
|
@@ -86,6 +87,10 @@ nitor <command> [options]
|
|
|
86
87
|
```bash
|
|
87
88
|
nitor merge -source <source branch> -target <target branch>
|
|
88
89
|
```
|
|
90
|
+
- **Cleanup:**
|
|
91
|
+
```bash
|
|
92
|
+
nitor cleanup
|
|
93
|
+
```
|
|
89
94
|
|
|
90
95
|
### Command Reference
|
|
91
96
|
|
|
@@ -101,6 +106,7 @@ nitor <command> [options]
|
|
|
101
106
|
- `backup` : Backup specified projects
|
|
102
107
|
- `restore` : Restore specified projects
|
|
103
108
|
- `merge` : Merge source branch into target branch
|
|
109
|
+
- `cleanup` : Cleanup local git branches (checkout to master and delete all other branches)
|
|
104
110
|
|
|
105
111
|
### Options
|
|
106
112
|
|
package/package.json
CHANGED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
const { execSync } = require('child_process');
|
|
2
|
+
|
|
3
|
+
const cleanup = async () => {
|
|
4
|
+
try {
|
|
5
|
+
console.log('Starting cleanup process...\n');
|
|
6
|
+
|
|
7
|
+
// Get current branch
|
|
8
|
+
const currentBranch = execSync('git branch --show-current', { encoding: 'utf-8' }).trim();
|
|
9
|
+
console.log(`Current branch: ${currentBranch}`);
|
|
10
|
+
|
|
11
|
+
// Checkout to master
|
|
12
|
+
console.log('\nChecking out to master branch...');
|
|
13
|
+
try {
|
|
14
|
+
execSync('git checkout master', { encoding: 'utf-8', stdio: 'inherit' });
|
|
15
|
+
} catch (error) {
|
|
16
|
+
// Try main if master doesn't exist
|
|
17
|
+
console.log('Master branch not found, trying main...');
|
|
18
|
+
execSync('git checkout main', { encoding: 'utf-8', stdio: 'inherit' });
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Get all local branches except master/main
|
|
22
|
+
console.log('\nFetching list of local branches...');
|
|
23
|
+
const branches = execSync('git branch', { encoding: 'utf-8' })
|
|
24
|
+
.split('\n')
|
|
25
|
+
.map((branch) => branch.trim().replace('* ', ''))
|
|
26
|
+
.filter((branch) => branch && branch !== 'master' && branch !== 'main');
|
|
27
|
+
|
|
28
|
+
if (!branches.length) {
|
|
29
|
+
console.log('\nNo branches to delete. Cleanup complete!');
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
console.log(`\nFound ${branches.length} branch(es) to delete:`);
|
|
34
|
+
|
|
35
|
+
// Delete each branch
|
|
36
|
+
console.log('\nDeleting branches...');
|
|
37
|
+
let deletedCount = 0;
|
|
38
|
+
let failedCount = 0;
|
|
39
|
+
|
|
40
|
+
for (const branch of branches) {
|
|
41
|
+
try {
|
|
42
|
+
execSync(`git branch -D ${branch}`, { encoding: 'utf-8' });
|
|
43
|
+
console.log(` ✓ Deleted: ${branch}`);
|
|
44
|
+
deletedCount++;
|
|
45
|
+
} catch (error) {
|
|
46
|
+
console.log(` ✗ Failed to delete: ${branch}`);
|
|
47
|
+
failedCount++;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
console.log(`\nCleanup complete!`);
|
|
52
|
+
console.log(` Deleted: ${deletedCount} branch(es)`);
|
|
53
|
+
|
|
54
|
+
if (failedCount > 0) {
|
|
55
|
+
console.log(` Failed: ${failedCount} branch(es)`);
|
|
56
|
+
}
|
|
57
|
+
} catch (error) {
|
|
58
|
+
console.error('Error during cleanup:', error.message);
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
module.exports = { cleanup };
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
module.exports = {
|
|
2
2
|
ACTIONS: {
|
|
3
|
+
BACKUP: 'backup',
|
|
4
|
+
BUILD_DEPLOY: 'build-deploy',
|
|
3
5
|
BUILD: 'build',
|
|
6
|
+
CLEANUP: 'cleanup',
|
|
7
|
+
CREATE_BRANCH: 'create-branch',
|
|
4
8
|
DEPLOY: 'deploy',
|
|
5
|
-
BUILD_DEPLOY: 'build-deploy',
|
|
6
|
-
VERSION: 'version',
|
|
7
9
|
HELP: 'help',
|
|
8
|
-
CREATE_BRANCH: 'create-branch',
|
|
9
|
-
REVIEW: 'review',
|
|
10
|
-
REFACTOR: 'refactor',
|
|
11
|
-
BACKUP: 'backup',
|
|
12
10
|
MERGE: 'merge',
|
|
11
|
+
REFACTOR: 'refactor',
|
|
12
|
+
REVIEW: 'review',
|
|
13
|
+
VERSION: 'version',
|
|
13
14
|
},
|
|
14
15
|
};
|
|
@@ -8,6 +8,7 @@ const { mrAIReview } = require('./review');
|
|
|
8
8
|
const { refactor } = require('./refactor');
|
|
9
9
|
const { backup } = require('./mongodb-backup');
|
|
10
10
|
const { merge } = require('./merge');
|
|
11
|
+
const { cleanup } = require('./cleanup');
|
|
11
12
|
|
|
12
13
|
const processArgs = async (type, value) => {
|
|
13
14
|
try {
|
|
@@ -16,6 +17,7 @@ const processArgs = async (type, value) => {
|
|
|
16
17
|
if (
|
|
17
18
|
type !== ACTIONS.HELP &&
|
|
18
19
|
type !== ACTIONS.VERSION &&
|
|
20
|
+
type !== ACTIONS.CLEANUP &&
|
|
19
21
|
!value.includes('--h') &&
|
|
20
22
|
!value.includes('-help')
|
|
21
23
|
) {
|
|
@@ -224,6 +226,26 @@ This command will:
|
|
|
224
226
|
break;
|
|
225
227
|
}
|
|
226
228
|
|
|
229
|
+
case ACTIONS.CLEANUP: {
|
|
230
|
+
if (value === '-help' || value === '--h') {
|
|
231
|
+
console.log(`usage: \tnu cleanup
|
|
232
|
+
|
|
233
|
+
Cleanup local git branches
|
|
234
|
+
|
|
235
|
+
This command will:
|
|
236
|
+
1. Checkout to master (or main) branch
|
|
237
|
+
2. Delete all other local branches
|
|
238
|
+
|
|
239
|
+
Note: This operation cannot be undone. Make sure you have pushed any important changes.`);
|
|
240
|
+
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
await cleanup();
|
|
245
|
+
|
|
246
|
+
break;
|
|
247
|
+
}
|
|
248
|
+
|
|
227
249
|
case ACTIONS.VERSION: {
|
|
228
250
|
const path = require('path');
|
|
229
251
|
const packageJson = require(path.resolve(__dirname, '../package.json'));
|
|
@@ -237,7 +259,8 @@ This command will:
|
|
|
237
259
|
case ACTIONS.HELP: {
|
|
238
260
|
console.log(`usage: nitor \t[${ACTIONS.VERSION}] [${ACTIONS.HELP}]
|
|
239
261
|
\t[${ACTIONS.BUILD}] [${ACTIONS.DEPLOY}] [${ACTIONS.BUILD_DEPLOY}]
|
|
240
|
-
\t[${ACTIONS.CREATE_BRANCH}] [${ACTIONS.REVIEW}] [${ACTIONS.MERGE}]
|
|
262
|
+
\t[${ACTIONS.CREATE_BRANCH}] [${ACTIONS.REVIEW}] [${ACTIONS.MERGE}]
|
|
263
|
+
\t[${ACTIONS.CLEANUP}]\n
|
|
241
264
|
Available commands:\n
|
|
242
265
|
build : Build specified components
|
|
243
266
|
deploy : Deploy specified components
|
|
@@ -246,6 +269,7 @@ Available commands:\n
|
|
|
246
269
|
review : AI Review specified merge request
|
|
247
270
|
refactor : REFACTOR the provided text for improved clarity, conciseness, and professional quality.
|
|
248
271
|
merge : Merge source branch into target branch
|
|
272
|
+
cleanup : Cleanup local git branches (checkout to master and delete all other branches)
|
|
249
273
|
version : Show version info
|
|
250
274
|
help : Show help
|
|
251
275
|
|
|
@@ -259,6 +283,7 @@ Example usage:\n
|
|
|
259
283
|
nitor review -project <project short name> -mergeId <merge id> -repository <repository name>
|
|
260
284
|
nitor refactor <text>
|
|
261
285
|
nitor merge -source <source branch> -target <target branch>
|
|
286
|
+
nitor cleanup
|
|
262
287
|
|
|
263
288
|
Running 'nitor help' will list available subcommands and provide some conceptual guides.`);
|
|
264
289
|
break;
|