codemodctl 0.1.2 → 0.1.4

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 +20 -3
  2. package/package.json +2 -1
package/dist/cli.js CHANGED
@@ -31,19 +31,20 @@ const createCommand = defineCommand({
31
31
  base: {
32
32
  type: "string",
33
33
  description: "Base branch to merge into",
34
- required: false,
35
- default: "main"
34
+ required: false
36
35
  },
37
36
  push: {
38
37
  type: "boolean",
39
38
  required: false
40
39
  },
41
40
  commitMessage: {
41
+ alias: "m",
42
42
  type: "string",
43
43
  description: "Message to commit",
44
44
  required: false
45
45
  },
46
46
  branchName: {
47
+ alias: "b",
47
48
  type: "string",
48
49
  description: "Branch to create the pull request from",
49
50
  required: false
@@ -76,7 +77,21 @@ const createCommand = defineCommand({
76
77
  }
77
78
  const taskIdSignature = crypto.createHash("sha256").update(taskId).digest("hex").slice(0, 8);
78
79
  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()) {
82
+ console.error("Error: Failed to get remote base branch");
83
+ console.error(remoteBaseBranchExec.stderr?.read().toString().trim());
84
+ process.exit(1);
85
+ }
86
+ const remoteBaseBranch = remoteBaseBranchExec.stdout?.read().toString().trim();
87
+ console.debug(`Remote base branch: ${remoteBaseBranch}`);
79
88
  if (push) {
89
+ const gitCheckoutBranchExec = exec(`git checkout -b ${codemodBranchName}`);
90
+ if (gitCheckoutBranchExec.stderr?.read().toString().trim()) {
91
+ console.error("Error: Failed to checkout branch");
92
+ console.error(gitCheckoutBranchExec.stderr?.read().toString().trim());
93
+ process.exit(1);
94
+ }
80
95
  const addChanges = exec("git add .");
81
96
  if (addChanges.stderr?.read().toString().trim()) {
82
97
  console.error("Error: Failed to add changes");
@@ -98,8 +113,10 @@ const createCommand = defineCommand({
98
113
  }
99
114
  const prData = { title };
100
115
  if (body) prData.body = body;
101
- if (head) prData.head = head;
116
+ if (codemodBranchName && push) prData.head = codemodBranchName;
117
+ else if (head) prData.head = head;
102
118
  if (base) prData.base = base;
119
+ else if (remoteBaseBranch) prData.base = remoteBaseBranch;
103
120
  try {
104
121
  console.debug("Creating pull request...");
105
122
  console.debug(`Title: ${title}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codemodctl",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
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"