codemodctl 0.1.4 → 0.1.5
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/dist/cli.js +31 -18
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { analyzeCodeowners } from "./codeowner-analysis-CeRIGuLu.js";
|
|
3
3
|
import { defineCommand, runMain } from "citty";
|
|
4
|
-
import { exec } from "node:child_process";
|
|
5
4
|
import crypto from "node:crypto";
|
|
5
|
+
import { $ } from "execa";
|
|
6
6
|
import fetch from "node-fetch";
|
|
7
7
|
import { writeFile } from "node:fs/promises";
|
|
8
8
|
|
|
@@ -71,43 +71,56 @@ const createCommand = defineCommand({
|
|
|
71
71
|
console.error("Error: BUTTERFLOW_API_AUTH_TOKEN environment variable is required");
|
|
72
72
|
process.exit(1);
|
|
73
73
|
}
|
|
74
|
-
|
|
74
|
+
try {
|
|
75
|
+
await $`git diff --quiet`;
|
|
76
|
+
await $`git diff --cached --quiet`;
|
|
75
77
|
console.error("No changes detected, skipping pull request creation.");
|
|
76
78
|
process.exit(0);
|
|
79
|
+
} catch {
|
|
80
|
+
console.log("Changes detected, proceeding with pull request creation...");
|
|
77
81
|
}
|
|
78
82
|
const taskIdSignature = crypto.createHash("sha256").update(taskId).digest("hex").slice(0, 8);
|
|
79
83
|
const codemodBranchName = branchName ? branchName : `codemod-${taskIdSignature}`;
|
|
80
|
-
|
|
81
|
-
|
|
84
|
+
let remoteBaseBranch;
|
|
85
|
+
try {
|
|
86
|
+
remoteBaseBranch = (await $`git remote show origin`).stdout.match(/HEAD branch: (.+)/)?.[1]?.trim() || "main";
|
|
87
|
+
} catch (error) {
|
|
82
88
|
console.error("Error: Failed to get remote base branch");
|
|
83
|
-
console.error(
|
|
89
|
+
console.error(error);
|
|
84
90
|
process.exit(1);
|
|
85
91
|
}
|
|
86
|
-
const remoteBaseBranch = remoteBaseBranchExec.stdout?.read().toString().trim();
|
|
87
92
|
console.debug(`Remote base branch: ${remoteBaseBranch}`);
|
|
88
93
|
if (push) {
|
|
89
|
-
|
|
90
|
-
|
|
94
|
+
try {
|
|
95
|
+
await $`git checkout -b ${codemodBranchName}`;
|
|
96
|
+
console.log(`✅ Created and checked out branch: ${codemodBranchName}`);
|
|
97
|
+
} catch (error) {
|
|
91
98
|
console.error("Error: Failed to checkout branch");
|
|
92
|
-
console.error(
|
|
99
|
+
console.error(error);
|
|
93
100
|
process.exit(1);
|
|
94
101
|
}
|
|
95
|
-
|
|
96
|
-
|
|
102
|
+
try {
|
|
103
|
+
await $`git add .`;
|
|
104
|
+
console.log("✅ Added changes to staging");
|
|
105
|
+
} catch (error) {
|
|
97
106
|
console.error("Error: Failed to add changes");
|
|
98
|
-
console.error(
|
|
107
|
+
console.error(error);
|
|
99
108
|
process.exit(1);
|
|
100
109
|
}
|
|
101
|
-
|
|
102
|
-
|
|
110
|
+
try {
|
|
111
|
+
await $`git commit -m ${commitMessage}`;
|
|
112
|
+
console.log("✅ Committed changes");
|
|
113
|
+
} catch (error) {
|
|
103
114
|
console.error("Error: Failed to commit changes");
|
|
104
|
-
console.error(
|
|
115
|
+
console.error(error);
|
|
105
116
|
process.exit(1);
|
|
106
117
|
}
|
|
107
|
-
|
|
108
|
-
|
|
118
|
+
try {
|
|
119
|
+
await $`git push origin ${codemodBranchName} --force`;
|
|
120
|
+
console.log(`✅ Pushed branch to origin: ${codemodBranchName}`);
|
|
121
|
+
} catch (error) {
|
|
109
122
|
console.error("Error: Failed to push changes");
|
|
110
|
-
console.error(
|
|
123
|
+
console.error(error);
|
|
111
124
|
process.exit(1);
|
|
112
125
|
}
|
|
113
126
|
}
|