codemodctl 0.1.3 → 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.
Files changed (2) hide show
  1. package/dist/cli.js +31 -18
  2. package/package.json +2 -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
- if (exec("git diff --quiet || git diff --cached --quiet").stderr?.read().toString().trim()) {
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
- const remoteBaseBranchExec = exec("git remote show origin | sed -n '/HEAD branch/s/.*: //p'");
81
- if (remoteBaseBranchExec.stderr?.read().toString().trim()) {
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(remoteBaseBranchExec.stderr?.read().toString().trim());
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
- const gitCheckoutBranchExec = exec(`git checkout -b ${codemodBranchName}`);
90
- if (gitCheckoutBranchExec.stderr?.read().toString().trim()) {
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(gitCheckoutBranchExec.stderr?.read().toString().trim());
99
+ console.error(error);
93
100
  process.exit(1);
94
101
  }
95
- const addChanges = exec("git add .");
96
- if (addChanges.stderr?.read().toString().trim()) {
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(addChanges.stderr?.read().toString().trim());
107
+ console.error(error);
99
108
  process.exit(1);
100
109
  }
101
- const commitChanges = exec(`git commit -m "${commitMessage}"`);
102
- if (commitChanges.stderr?.read().toString().trim()) {
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(commitChanges.stderr?.read().toString().trim());
115
+ console.error(error);
105
116
  process.exit(1);
106
117
  }
107
- const pushChanges = exec(`git push origin ${codemodBranchName} --force`);
108
- if (pushChanges.stderr?.read().toString().trim()) {
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(pushChanges.stderr?.read().toString().trim());
123
+ console.error(error);
111
124
  process.exit(1);
112
125
  }
113
126
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codemodctl",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "CLI tool and utilities for workflow engine operations, file sharding, and codeowner analysis",
5
5
  "type": "module",
6
6
  "exports": {
@@ -38,6 +38,7 @@
38
38
  "@ast-grep/napi": "^0.39.4",
39
39
  "citty": "^0.1.6",
40
40
  "codeowners": "^5.1.1",
41
+ "execa": "^9.6.0",
41
42
  "glob": "^11.0.0",
42
43
  "node-fetch": "^3.3.2",
43
44
  "yaml": "^2.7.1"