vtasks-automate-cli 0.3.0 → 0.4.1
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 +29 -29
- package/init.js +21 -0
- package/package.json +1 -1
package/content/index.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
const { exec } = require(
|
|
2
|
-
const config = require(
|
|
1
|
+
const { exec } = require("child_process");
|
|
2
|
+
const config = require("./config");
|
|
3
3
|
|
|
4
4
|
const LOG_COLORS = {
|
|
5
|
-
RED:
|
|
6
|
-
GREEN:
|
|
7
|
-
YELLOW:
|
|
8
|
-
BLUE:
|
|
5
|
+
RED: "\x1b[31m",
|
|
6
|
+
GREEN: "\x1b[32m",
|
|
7
|
+
YELLOW: "\x1b[33m",
|
|
8
|
+
BLUE: "\x1b[34m",
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
class GitService {
|
|
12
12
|
static async getCurrentBranch() {
|
|
13
13
|
return new Promise((resolve, reject) => {
|
|
14
|
-
exec(
|
|
14
|
+
exec("git branch --show-current", (error, stdout, stderr) => {
|
|
15
15
|
if (error) {
|
|
16
|
-
console.log(
|
|
17
|
-
reject(
|
|
16
|
+
console.log("Error: ", error);
|
|
17
|
+
reject("Error gettig current branch: Error executing git cmd");
|
|
18
18
|
return;
|
|
19
19
|
}
|
|
20
20
|
const branch = stdout.trim();
|
|
@@ -25,19 +25,19 @@ class GitService {
|
|
|
25
25
|
|
|
26
26
|
static async getCurrentUser() {
|
|
27
27
|
return new Promise((resolve, reject) => {
|
|
28
|
-
exec(
|
|
28
|
+
exec("git config --list", (error, stdout, stderr) => {
|
|
29
29
|
if (error) {
|
|
30
|
-
console.log(
|
|
31
|
-
reject(
|
|
30
|
+
console.log("Error: ", error);
|
|
31
|
+
reject("Error getting user email: Error executing git cmd");
|
|
32
32
|
return;
|
|
33
33
|
}
|
|
34
|
-
const list = stdout.split(
|
|
35
|
-
const item = list.find(t => t.startsWith(
|
|
34
|
+
const list = stdout.split("\n");
|
|
35
|
+
const item = list.find((t) => t.startsWith("user.email"));
|
|
36
36
|
if (!item) {
|
|
37
|
-
reject(
|
|
37
|
+
reject("Error getting user email: user.email not found");
|
|
38
38
|
return;
|
|
39
39
|
}
|
|
40
|
-
const split = item.split(
|
|
40
|
+
const split = item.split("=");
|
|
41
41
|
|
|
42
42
|
const email = split[1].trim();
|
|
43
43
|
resolve(email);
|
|
@@ -47,30 +47,30 @@ class GitService {
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
async function main() {
|
|
50
|
-
console.log(LOG_COLORS.BLUE,
|
|
50
|
+
console.log(LOG_COLORS.BLUE, "Checking vTasks config:");
|
|
51
51
|
if (!config) {
|
|
52
|
-
console.log(LOG_COLORS.RED,
|
|
53
|
-
throw new Error(
|
|
52
|
+
console.log(LOG_COLORS.RED, "Git user email not found");
|
|
53
|
+
throw new Error("Missing config.js file");
|
|
54
54
|
}
|
|
55
55
|
const userEmail = await GitService.getCurrentUser();
|
|
56
56
|
if (!userEmail) {
|
|
57
|
-
console.log(LOG_COLORS.RED,
|
|
58
|
-
throw new Error(
|
|
57
|
+
console.log(LOG_COLORS.RED, "Git user email not found");
|
|
58
|
+
throw new Error("Git user email not found");
|
|
59
59
|
}
|
|
60
60
|
console.log(LOG_COLORS.GREEN, `User email: ${userEmail}`);
|
|
61
61
|
const projectName = config.projectName;
|
|
62
62
|
if (!projectName) {
|
|
63
|
-
console.log(LOG_COLORS.RED,
|
|
64
|
-
throw new Error(
|
|
63
|
+
console.log(LOG_COLORS.RED, "Missing project name configuration");
|
|
64
|
+
throw new Error("Missing Project name");
|
|
65
65
|
}
|
|
66
66
|
console.log(LOG_COLORS.GREEN, `Project: ${projectName}`);
|
|
67
67
|
let issueNumber;
|
|
68
68
|
const branch = await GitService.getCurrentBranch();
|
|
69
|
-
if (branch !=
|
|
70
|
-
issueNumber = Number(branch.split(
|
|
69
|
+
if (branch != "qa" && branch != "dev") {
|
|
70
|
+
issueNumber = Number(branch.split("_")[0]);
|
|
71
71
|
console.log(LOG_COLORS.GREEN, `Currently working on issue: ${issueNumber}`);
|
|
72
72
|
const response = await fetch(`${config.vTasksUrl}`, {
|
|
73
|
-
method:
|
|
73
|
+
method: "POST",
|
|
74
74
|
body: JSON.stringify({
|
|
75
75
|
projectName,
|
|
76
76
|
branch,
|
|
@@ -78,15 +78,15 @@ async function main() {
|
|
|
78
78
|
issueNumber,
|
|
79
79
|
}),
|
|
80
80
|
headers: {
|
|
81
|
-
|
|
81
|
+
"Content-Type": "application/json",
|
|
82
82
|
},
|
|
83
83
|
});
|
|
84
84
|
const parsed = await response.json();
|
|
85
|
-
console.log(LOG_COLORS.GREEN,
|
|
85
|
+
console.log(LOG_COLORS.GREEN, "vTasks status changed successfully!");
|
|
86
86
|
} else {
|
|
87
87
|
console.log(
|
|
88
88
|
LOG_COLORS.YELLOW,
|
|
89
|
-
|
|
89
|
+
"Warning: you are working in a not issue branch"
|
|
90
90
|
);
|
|
91
91
|
}
|
|
92
92
|
}
|
package/init.js
CHANGED
|
@@ -113,9 +113,15 @@ const main = async () => {
|
|
|
113
113
|
const __dirname = dirname(__filename);
|
|
114
114
|
|
|
115
115
|
const carpetaDestino = path.join(process.cwd(), "vTasks");
|
|
116
|
+
const githooksFolder = path.join(process.cwd(), ".githooks");
|
|
117
|
+
|
|
116
118
|
const archivoOrigen = path.join(__dirname, "content", "index.js");
|
|
117
119
|
const archivoDestino = path.join(carpetaDestino, "index.js");
|
|
118
120
|
const archivoConfig = path.join(carpetaDestino, "config.js");
|
|
121
|
+
const postCommitFile = path.join(githooksFolder, "post-checkout");
|
|
122
|
+
|
|
123
|
+
const gitIgnoreFile = path.join(process.cwd(), ".gitignore");
|
|
124
|
+
|
|
119
125
|
if (fs.existsSync(carpetaDestino)) {
|
|
120
126
|
console.error(LOG_COLORS.RED, "Error: vTasks directory already exist");
|
|
121
127
|
process.exit(1);
|
|
@@ -128,7 +134,22 @@ const main = async () => {
|
|
|
128
134
|
vTasksUrl: '${VTASKS_CONFIG_URL}'
|
|
129
135
|
};
|
|
130
136
|
`;
|
|
137
|
+
const postCommitContent = `#!/bin/bash
|
|
138
|
+
|
|
139
|
+
echo -e "\e[34mSwitching current branch\e[0m"
|
|
140
|
+
node ./vTasks/index.js`;
|
|
131
141
|
fs.writeFileSync(archivoConfig, configContent);
|
|
142
|
+
fs.writeFileSync(postCommitFile, postCommitContent);
|
|
143
|
+
|
|
144
|
+
if (fs.existsSync(archivoGitignore)) {
|
|
145
|
+
let gitIgnoreContent = fs.readFileSync(gitIgnoreFile, "utf-8");
|
|
146
|
+
|
|
147
|
+
gitIgnoreContent += "\n\n";
|
|
148
|
+
gitIgnoreContent += "#vTasks config\n";
|
|
149
|
+
gitIgnoreContent += "vTasks/config.js\n";
|
|
150
|
+
} else {
|
|
151
|
+
console.log(LOG_COLORS.YELLOW, ".gitignore file not found");
|
|
152
|
+
}
|
|
132
153
|
|
|
133
154
|
console.log(LOG_COLORS.GREEN, "Set Up completed ✓");
|
|
134
155
|
};
|