clairo 1.0.2 → 1.0.3
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 +49 -5
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -125,6 +125,33 @@ function getCurrentBranch() {
|
|
|
125
125
|
return { success: false, error: "Failed to get current branch" };
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
|
+
function findRemoteWithBranch(branch) {
|
|
129
|
+
try {
|
|
130
|
+
const remoteBranches = execSync("git branch -r", {
|
|
131
|
+
encoding: "utf-8",
|
|
132
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
133
|
+
});
|
|
134
|
+
const remotes = listRemotes();
|
|
135
|
+
if (!remotes.success) {
|
|
136
|
+
return { success: false, error: "Failed to list remotes" };
|
|
137
|
+
}
|
|
138
|
+
for (const remote of remotes.data) {
|
|
139
|
+
if (remoteBranches.includes(`${remote.name}/${branch}`)) {
|
|
140
|
+
const sshMatch = remote.url.match(/git@github\.com:(.+?)\/(.+?)(?:\.git)?$/);
|
|
141
|
+
if (sshMatch) {
|
|
142
|
+
return { success: true, data: { remote: remote.name, owner: sshMatch[1] } };
|
|
143
|
+
}
|
|
144
|
+
const httpsMatch = remote.url.match(/https:\/\/github\.com\/(.+?)\/(.+?)(?:\.git)?$/);
|
|
145
|
+
if (httpsMatch) {
|
|
146
|
+
return { success: true, data: { remote: remote.name, owner: httpsMatch[1] } };
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return { success: false, error: "Branch not found on any remote" };
|
|
151
|
+
} catch {
|
|
152
|
+
return { success: false, error: "Failed to find remote with branch" };
|
|
153
|
+
}
|
|
154
|
+
}
|
|
128
155
|
|
|
129
156
|
// src/lib/github/index.ts
|
|
130
157
|
import { exec } from "child_process";
|
|
@@ -896,7 +923,7 @@ function PullRequestsBox({
|
|
|
896
923
|
if (key.downArrow || input === "j") {
|
|
897
924
|
setHighlightedIndex((prev) => Math.min(totalItems - 1, prev + 1));
|
|
898
925
|
}
|
|
899
|
-
if (
|
|
926
|
+
if (input === " ") {
|
|
900
927
|
if (highlightedIndex === prs.length) {
|
|
901
928
|
onCreatePR();
|
|
902
929
|
} else if (prs[highlightedIndex]) {
|
|
@@ -967,7 +994,7 @@ function RemotesBox({ remotes, selectedRemote, onSelect, loading, error, isFocus
|
|
|
967
994
|
if (key.downArrow || input === "j") {
|
|
968
995
|
setHighlightedIndex((prev) => Math.min(remotes.length - 1, prev + 1));
|
|
969
996
|
}
|
|
970
|
-
if (
|
|
997
|
+
if (input === " ") {
|
|
971
998
|
onSelect(remotes[highlightedIndex].name);
|
|
972
999
|
}
|
|
973
1000
|
},
|
|
@@ -1027,8 +1054,9 @@ function GitHubView({ isFocused, onKeybindingsChange, onLogUpdated }) {
|
|
|
1027
1054
|
}
|
|
1028
1055
|
const bindings = [];
|
|
1029
1056
|
if (focusedBox === "remotes") {
|
|
1030
|
-
bindings.push({ key: "
|
|
1057
|
+
bindings.push({ key: "Space", label: "Select Remote" });
|
|
1031
1058
|
} else if (focusedBox === "prs") {
|
|
1059
|
+
bindings.push({ key: "Space", label: "Select" });
|
|
1032
1060
|
bindings.push({ key: "n", label: "New PR", color: "green" });
|
|
1033
1061
|
bindings.push({ key: "r", label: "Refresh" });
|
|
1034
1062
|
bindings.push({ key: "o", label: "Open", color: "green" });
|
|
@@ -1140,11 +1168,24 @@ function GitHubView({ isFocused, onKeybindingsChange, onLogUpdated }) {
|
|
|
1140
1168
|
const prNumbersBeforeCreate = useRef2(/* @__PURE__ */ new Set());
|
|
1141
1169
|
const pollingIntervalRef = useRef2(null);
|
|
1142
1170
|
const handleCreatePR = useCallback(() => {
|
|
1171
|
+
if (!currentBranch) {
|
|
1172
|
+
setErrors((prev) => ({ ...prev, prs: "No branch detected" }));
|
|
1173
|
+
return;
|
|
1174
|
+
}
|
|
1175
|
+
const remoteResult = findRemoteWithBranch(currentBranch);
|
|
1176
|
+
if (!remoteResult.success) {
|
|
1177
|
+
setErrors((prev) => ({ ...prev, prs: "Push your branch to a remote first" }));
|
|
1178
|
+
return;
|
|
1179
|
+
}
|
|
1143
1180
|
prNumbersBeforeCreate.current = new Set(prs.map((pr) => pr.number));
|
|
1144
|
-
|
|
1181
|
+
const headFlag = `${remoteResult.data.owner}:${currentBranch}`;
|
|
1182
|
+
exec3(`gh pr create --web --head "${headFlag}"`, (error) => {
|
|
1145
1183
|
process.stdout.emit("resize");
|
|
1184
|
+
if (error) {
|
|
1185
|
+
setErrors((prev) => ({ ...prev, prs: `Failed to create PR: ${error.message}` }));
|
|
1186
|
+
}
|
|
1146
1187
|
});
|
|
1147
|
-
if (!
|
|
1188
|
+
if (!currentRepoSlug) return;
|
|
1148
1189
|
let attempts = 0;
|
|
1149
1190
|
const maxAttempts = 24;
|
|
1150
1191
|
const pollInterval = 5e3;
|
|
@@ -1193,6 +1234,9 @@ function GitHubView({ isFocused, onKeybindingsChange, onLogUpdated }) {
|
|
|
1193
1234
|
if (focusedBox === "prs") refreshPRs();
|
|
1194
1235
|
if (focusedBox === "details") refreshDetails();
|
|
1195
1236
|
}
|
|
1237
|
+
if (input === "n" && focusedBox === "prs") {
|
|
1238
|
+
handleCreatePR();
|
|
1239
|
+
}
|
|
1196
1240
|
},
|
|
1197
1241
|
{ isActive: isFocused }
|
|
1198
1242
|
);
|