vtasks-automate-cli 0.4.0 → 0.4.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/content/index.js +29 -29
- package/init.js +12 -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
|
@@ -120,6 +120,8 @@ const main = async () => {
|
|
|
120
120
|
const archivoConfig = path.join(carpetaDestino, "config.js");
|
|
121
121
|
const postCommitFile = path.join(githooksFolder, "post-checkout");
|
|
122
122
|
|
|
123
|
+
const gitIgnoreFile = path.join(process.cwd(), ".gitignore");
|
|
124
|
+
|
|
123
125
|
if (fs.existsSync(carpetaDestino)) {
|
|
124
126
|
console.error(LOG_COLORS.RED, "Error: vTasks directory already exist");
|
|
125
127
|
process.exit(1);
|
|
@@ -139,6 +141,16 @@ node ./vTasks/index.js`;
|
|
|
139
141
|
fs.writeFileSync(archivoConfig, configContent);
|
|
140
142
|
fs.writeFileSync(postCommitFile, postCommitContent);
|
|
141
143
|
|
|
144
|
+
if (fs.existsSync(gitIgnoreContent)) {
|
|
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
|
+
}
|
|
153
|
+
|
|
142
154
|
console.log(LOG_COLORS.GREEN, "Set Up completed ✓");
|
|
143
155
|
};
|
|
144
156
|
|