vtasks-automate-cli 0.1.0 → 0.2.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/content/index.js +94 -0
- package/init.js +25 -5
- package/package.json +2 -1
package/content/index.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
const { exec } = require('child_process');
|
|
2
|
+
const config = require('./config');
|
|
3
|
+
|
|
4
|
+
const LOG_COLORS = {
|
|
5
|
+
RED: '\x1b[31m',
|
|
6
|
+
GREEN: '\x1b[32m',
|
|
7
|
+
YELLOW: '\x1b[33m',
|
|
8
|
+
BLUE: '\x1b[34m',
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
class GitService {
|
|
12
|
+
static async getCurrentBranch() {
|
|
13
|
+
return new Promise((resolve, reject) => {
|
|
14
|
+
exec('git branch --show-current', (error, stdout, stderr) => {
|
|
15
|
+
if (error) {
|
|
16
|
+
console.log('Error: ', error);
|
|
17
|
+
reject('Error gettig current branch: Error executing git cmd');
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const branch = stdout.trim();
|
|
21
|
+
resolve(branch);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
static async getCurrentUser() {
|
|
27
|
+
return new Promise((resolve, reject) => {
|
|
28
|
+
exec('git config --list', (error, stdout, stderr) => {
|
|
29
|
+
if (error) {
|
|
30
|
+
console.log('Error: ', error);
|
|
31
|
+
reject('Error getting user email: Error executing git cmd');
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const list = stdout.split('\n');
|
|
35
|
+
const item = list.find(t => t.startsWith('user.email'));
|
|
36
|
+
if (!item) {
|
|
37
|
+
reject('Error getting user email: user.email not found');
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const split = item.split('=');
|
|
41
|
+
|
|
42
|
+
const email = split[1].trim();
|
|
43
|
+
resolve(email);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async function main() {
|
|
50
|
+
console.log(LOG_COLORS.BLUE, 'Checking vTasks config:');
|
|
51
|
+
if (!config) {
|
|
52
|
+
console.log(LOG_COLORS.RED, 'Git user email not found');
|
|
53
|
+
throw new Error('Missing config.js file');
|
|
54
|
+
}
|
|
55
|
+
const userEmail = await GitService.getCurrentUser();
|
|
56
|
+
if (!userEmail) {
|
|
57
|
+
console.log(LOG_COLORS.RED, 'Git user email not found');
|
|
58
|
+
throw new Error('Git user email not found');
|
|
59
|
+
}
|
|
60
|
+
console.log(LOG_COLORS.GREEN, `User email: ${userEmail}`);
|
|
61
|
+
const projectName = config.projectName;
|
|
62
|
+
if (!projectName) {
|
|
63
|
+
console.log(LOG_COLORS.RED, 'Missing project name configuration');
|
|
64
|
+
throw new Error('Missing Project name');
|
|
65
|
+
}
|
|
66
|
+
console.log(LOG_COLORS.GREEN, `Project: ${projectName}`);
|
|
67
|
+
let issueNumber;
|
|
68
|
+
const branch = await GitService.getCurrentBranch();
|
|
69
|
+
if (branch != 'qa' && !branch != 'dev') {
|
|
70
|
+
issueNumber = Number(branch.split('_')[0]);
|
|
71
|
+
console.log(LOG_COLORS.GREEN, `Currently working on issue: ${issueNumber}`);
|
|
72
|
+
const response = await fetch(`${config.vTasksUrl}`, {
|
|
73
|
+
method: 'POST',
|
|
74
|
+
body: JSON.stringify({
|
|
75
|
+
projectName,
|
|
76
|
+
branch,
|
|
77
|
+
userEmail,
|
|
78
|
+
issueNumber,
|
|
79
|
+
}),
|
|
80
|
+
headers: {
|
|
81
|
+
'Content-Type': 'application/json',
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
const parsed = await response.json();
|
|
85
|
+
console.log(LOG_COLORS.GREEN, 'vTasks status changed successfully!');
|
|
86
|
+
} else {
|
|
87
|
+
console.log(
|
|
88
|
+
LOG_COLORS.YELLOW,
|
|
89
|
+
'Warning: you are working in a not issue branch',
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
main();
|
package/init.js
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import readline from "readline";
|
|
3
|
+
import axios from "axios";
|
|
4
|
+
import { exec } from "child_process";
|
|
5
|
+
|
|
6
|
+
import fs from "fs";
|
|
7
|
+
import path from "path";
|
|
8
|
+
import { fileURLToPath } from "url";
|
|
9
|
+
import { dirname } from "path";
|
|
5
10
|
|
|
6
11
|
const VTASKS_URL = "http://localhost:3040";
|
|
7
12
|
|
|
@@ -85,7 +90,7 @@ const main = async () => {
|
|
|
85
90
|
LOG_COLORS.RED,
|
|
86
91
|
`Error: User email not found (${userEmail}) - Try again`
|
|
87
92
|
);
|
|
88
|
-
return 1;
|
|
93
|
+
return process.exit(1);
|
|
89
94
|
}
|
|
90
95
|
console.log(LOG_COLORS.GREEN, `User email checked: ${userEmail} ✓`);
|
|
91
96
|
|
|
@@ -99,8 +104,23 @@ const main = async () => {
|
|
|
99
104
|
LOG_COLORS.RED,
|
|
100
105
|
`Error: Project not found (${projectName}) - Try again`
|
|
101
106
|
);
|
|
102
|
-
return 1;
|
|
107
|
+
return process.exit(1);
|
|
108
|
+
}
|
|
109
|
+
console.log(LOG_COLORS.BLUE, "Generating scripts");
|
|
110
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
111
|
+
const __dirname = dirname(__filename);
|
|
112
|
+
|
|
113
|
+
const carpetaDestino = path.join(process.cwd(), "vTasks");
|
|
114
|
+
const archivoOrigen = path.join(__dirname, "content", "index.js");
|
|
115
|
+
const archivoDestino = path.join(carpetaDestino, "index.js");
|
|
116
|
+
if (fs.existsSync(carpetaDestino)) {
|
|
117
|
+
console.error(LOG_COLORS.RED, "Error: vTasks directory already exist");
|
|
118
|
+
process.exit(1);
|
|
103
119
|
}
|
|
120
|
+
fs.mkdirSync(carpetaDestino, { recursive: true });
|
|
121
|
+
fs.copyFileSync(archivoOrigen, archivoDestino);
|
|
122
|
+
|
|
123
|
+
console.log(LOG_COLORS.GREEN, "Set Up completed ✓");
|
|
104
124
|
};
|
|
105
125
|
|
|
106
126
|
main();
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vtasks-automate-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Automate your vTasks workflow with ease — move tasks between states without opening the app",
|
|
5
5
|
"bin": {
|
|
6
6
|
"vtasks-automate": "init.js"
|
|
7
7
|
},
|
|
8
|
+
"type": "module",
|
|
8
9
|
"author": "nahuel-venturing",
|
|
9
10
|
"license": "ISC",
|
|
10
11
|
"dependencies": {
|