@saeed42/worktree-worker 1.3.5 → 1.4.0
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/main.js +141 -2
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
// src/main.ts
|
|
4
4
|
import { serve } from "@hono/node-server";
|
|
5
|
-
import { Hono as
|
|
5
|
+
import { Hono as Hono5 } from "hono";
|
|
6
6
|
import { cors } from "hono/cors";
|
|
7
7
|
import { logger as honoLogger } from "hono/logger";
|
|
8
8
|
import { secureHeaders } from "hono/secure-headers";
|
|
@@ -1472,8 +1472,146 @@ worktree.post("/worktrees/cleanup", async (c) => {
|
|
|
1472
1472
|
}
|
|
1473
1473
|
});
|
|
1474
1474
|
|
|
1475
|
+
// src/routes/git.routes.ts
|
|
1476
|
+
import { Hono as Hono4 } from "hono";
|
|
1477
|
+
import { z as z3 } from "zod";
|
|
1478
|
+
import * as fs from "fs/promises";
|
|
1479
|
+
var git = new Hono4();
|
|
1480
|
+
var gitConfigSchema = z3.object({
|
|
1481
|
+
user: z3.object({
|
|
1482
|
+
name: z3.string().min(1, "Name is required"),
|
|
1483
|
+
email: z3.string().email("Valid email is required")
|
|
1484
|
+
}).optional(),
|
|
1485
|
+
credentials: z3.object({
|
|
1486
|
+
githubToken: z3.string().min(1, "GitHub token is required")
|
|
1487
|
+
}).optional()
|
|
1488
|
+
});
|
|
1489
|
+
git.post("/config", async (c) => {
|
|
1490
|
+
const log = logger.child({ route: "git/config" });
|
|
1491
|
+
try {
|
|
1492
|
+
const body = await c.req.json().catch(() => ({}));
|
|
1493
|
+
const parsed = gitConfigSchema.safeParse(body);
|
|
1494
|
+
if (!parsed.success) {
|
|
1495
|
+
return c.json(
|
|
1496
|
+
{ success: false, error: { code: "VALIDATION_ERROR", message: parsed.error.message } },
|
|
1497
|
+
400
|
|
1498
|
+
);
|
|
1499
|
+
}
|
|
1500
|
+
const { user, credentials } = parsed.data;
|
|
1501
|
+
const configured = [];
|
|
1502
|
+
if (user) {
|
|
1503
|
+
log.info("Configuring git user identity", { name: user.name, email: user.email });
|
|
1504
|
+
const nameResult = await gitService.exec(["config", "--global", "user.name", user.name]);
|
|
1505
|
+
if (nameResult.code !== 0) {
|
|
1506
|
+
log.error("Failed to set git user.name", { stderr: nameResult.stderr });
|
|
1507
|
+
return c.json(
|
|
1508
|
+
{ success: false, error: { code: "GIT_CONFIG_ERROR", message: "Failed to set user.name" } },
|
|
1509
|
+
500
|
|
1510
|
+
);
|
|
1511
|
+
}
|
|
1512
|
+
const emailResult = await gitService.exec(["config", "--global", "user.email", user.email]);
|
|
1513
|
+
if (emailResult.code !== 0) {
|
|
1514
|
+
log.error("Failed to set git user.email", { stderr: emailResult.stderr });
|
|
1515
|
+
return c.json(
|
|
1516
|
+
{ success: false, error: { code: "GIT_CONFIG_ERROR", message: "Failed to set user.email" } },
|
|
1517
|
+
500
|
|
1518
|
+
);
|
|
1519
|
+
}
|
|
1520
|
+
configured.push("user_configured");
|
|
1521
|
+
log.debug("Git user identity configured successfully");
|
|
1522
|
+
}
|
|
1523
|
+
if (credentials?.githubToken) {
|
|
1524
|
+
log.info("Configuring git credentials");
|
|
1525
|
+
await gitService.exec([
|
|
1526
|
+
"config",
|
|
1527
|
+
"--global",
|
|
1528
|
+
"credential.helper",
|
|
1529
|
+
"store --file=/tmp/.git-credentials"
|
|
1530
|
+
]);
|
|
1531
|
+
await gitService.exec(["config", "--global", "core.askPass", ""]);
|
|
1532
|
+
const credLine = `https://x-access-token:${credentials.githubToken}@github.com
|
|
1533
|
+
`;
|
|
1534
|
+
await fs.writeFile("/tmp/.git-credentials", credLine, { mode: 384 });
|
|
1535
|
+
configured.push("credentials_configured");
|
|
1536
|
+
log.debug("Git credentials configured successfully");
|
|
1537
|
+
}
|
|
1538
|
+
if (configured.length === 0) {
|
|
1539
|
+
return c.json(
|
|
1540
|
+
{ success: false, error: { code: "NO_CONFIG", message: "No configuration provided" } },
|
|
1541
|
+
400
|
|
1542
|
+
);
|
|
1543
|
+
}
|
|
1544
|
+
return c.json({
|
|
1545
|
+
success: true,
|
|
1546
|
+
data: { configured }
|
|
1547
|
+
});
|
|
1548
|
+
} catch (err) {
|
|
1549
|
+
const error = err;
|
|
1550
|
+
log.error("Failed to configure git", { error: error.message });
|
|
1551
|
+
return c.json(
|
|
1552
|
+
{ success: false, error: { code: "INTERNAL_ERROR", message: error.message } },
|
|
1553
|
+
500
|
|
1554
|
+
);
|
|
1555
|
+
}
|
|
1556
|
+
});
|
|
1557
|
+
git.get("/config", async (c) => {
|
|
1558
|
+
const log = logger.child({ route: "git/config" });
|
|
1559
|
+
try {
|
|
1560
|
+
const nameResult = await gitService.exec(["config", "--global", "user.name"]);
|
|
1561
|
+
const name = nameResult.code === 0 ? nameResult.stdout.trim() : null;
|
|
1562
|
+
const emailResult = await gitService.exec(["config", "--global", "user.email"]);
|
|
1563
|
+
const email = emailResult.code === 0 ? emailResult.stdout.trim() : null;
|
|
1564
|
+
let credentialsConfigured = false;
|
|
1565
|
+
try {
|
|
1566
|
+
await fs.access("/tmp/.git-credentials");
|
|
1567
|
+
credentialsConfigured = true;
|
|
1568
|
+
} catch {
|
|
1569
|
+
}
|
|
1570
|
+
return c.json({
|
|
1571
|
+
success: true,
|
|
1572
|
+
data: {
|
|
1573
|
+
user: {
|
|
1574
|
+
name: name || null,
|
|
1575
|
+
email: email || null
|
|
1576
|
+
},
|
|
1577
|
+
credentialsConfigured
|
|
1578
|
+
}
|
|
1579
|
+
});
|
|
1580
|
+
} catch (err) {
|
|
1581
|
+
const error = err;
|
|
1582
|
+
log.error("Failed to get git config", { error: error.message });
|
|
1583
|
+
return c.json(
|
|
1584
|
+
{ success: false, error: { code: "INTERNAL_ERROR", message: error.message } },
|
|
1585
|
+
500
|
|
1586
|
+
);
|
|
1587
|
+
}
|
|
1588
|
+
});
|
|
1589
|
+
git.delete("/config", async (c) => {
|
|
1590
|
+
const log = logger.child({ route: "git/config" });
|
|
1591
|
+
try {
|
|
1592
|
+
await gitService.exec(["config", "--global", "--unset", "user.name"]);
|
|
1593
|
+
await gitService.exec(["config", "--global", "--unset", "user.email"]);
|
|
1594
|
+
try {
|
|
1595
|
+
await fs.unlink("/tmp/.git-credentials");
|
|
1596
|
+
} catch {
|
|
1597
|
+
}
|
|
1598
|
+
log.info("Git config cleared");
|
|
1599
|
+
return c.json({
|
|
1600
|
+
success: true,
|
|
1601
|
+
data: { cleared: true }
|
|
1602
|
+
});
|
|
1603
|
+
} catch (err) {
|
|
1604
|
+
const error = err;
|
|
1605
|
+
log.error("Failed to clear git config", { error: error.message });
|
|
1606
|
+
return c.json(
|
|
1607
|
+
{ success: false, error: { code: "INTERNAL_ERROR", message: error.message } },
|
|
1608
|
+
500
|
|
1609
|
+
);
|
|
1610
|
+
}
|
|
1611
|
+
});
|
|
1612
|
+
|
|
1475
1613
|
// src/main.ts
|
|
1476
|
-
var app = new
|
|
1614
|
+
var app = new Hono5();
|
|
1477
1615
|
app.use("*", secureHeaders());
|
|
1478
1616
|
app.use(
|
|
1479
1617
|
"*",
|
|
@@ -1504,6 +1642,7 @@ app.get("/", (c) => {
|
|
|
1504
1642
|
});
|
|
1505
1643
|
app.use("/v1/*", authMiddleware);
|
|
1506
1644
|
app.route("/v1/repo", repo);
|
|
1645
|
+
app.route("/v1/git", git);
|
|
1507
1646
|
app.route("/v1", worktree);
|
|
1508
1647
|
app.onError((err, c) => {
|
|
1509
1648
|
const requestId = c.req.header("X-Request-ID") || "unknown";
|