mirror of
https://github.com/github/awesome-copilot.git
synced 2026-07-18 11:50:00 +00:00
chore: publish from main
This commit is contained in:
@@ -72,6 +72,15 @@ function normalizeText(value, fallback = "") {
|
||||
return typeof value === "string" ? value.trim() : fallback;
|
||||
}
|
||||
|
||||
function captureCwd(ctx) {
|
||||
const dir = ctx?.session?.workingDirectory;
|
||||
return typeof dir === "string" && dir.trim() ? dir : null;
|
||||
}
|
||||
|
||||
function cwdForContext(ctx) {
|
||||
return captureCwd(ctx) || servers.get(ctx?.instanceId)?.cwd || null;
|
||||
}
|
||||
|
||||
function escapeHtml(value) {
|
||||
return normalizeText(value).replace(/[&<>"']/g, (char) => {
|
||||
if (char === "&") return "&";
|
||||
@@ -385,7 +394,7 @@ async function runGh(args, cwd) {
|
||||
return result.stdout;
|
||||
}
|
||||
|
||||
async function closeGithubIssue(board, item, note) {
|
||||
async function closeGithubIssue(board, item, note, cwd = process.cwd()) {
|
||||
const issueNumber = normalizeText(item?.number);
|
||||
const repo = normalizeText(board?.repo || item?.repo);
|
||||
if (!issueNumber || !repo) {
|
||||
@@ -397,7 +406,7 @@ async function closeGithubIssue(board, item, note) {
|
||||
args.push("--comment", comment);
|
||||
}
|
||||
try {
|
||||
await runGh(args, activeSession?.workspacePath || process.cwd());
|
||||
await runGh(args, cwd);
|
||||
} catch (error) {
|
||||
const stderr = normalizeText(error?.stderr || "");
|
||||
if (stderr.toLowerCase().includes("already closed")) {
|
||||
@@ -407,7 +416,7 @@ async function closeGithubIssue(board, item, note) {
|
||||
}
|
||||
}
|
||||
|
||||
async function commentGithubIssue(board, item, note) {
|
||||
async function commentGithubIssue(board, item, note, cwd = process.cwd()) {
|
||||
const repo = normalizeText(board?.repo || item?.repo);
|
||||
const issueNumber = extractIssueNumber(item);
|
||||
const comment = normalizeText(note);
|
||||
@@ -418,7 +427,7 @@ async function commentGithubIssue(board, item, note) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await runGh(["issue", "comment", issueNumber, "--repo", repo, "--body", comment], activeSession?.workspacePath || process.cwd());
|
||||
await runGh(["issue", "comment", issueNumber, "--repo", repo, "--body", comment], cwd);
|
||||
} catch (error) {
|
||||
const stderr = normalizeText(error?.stderr || "");
|
||||
throw new Error(stderr || `Failed to comment on issue #${issueNumber} in ${repo}.`);
|
||||
@@ -510,11 +519,11 @@ function pruneDecisionsForCurrentItems(board) {
|
||||
}
|
||||
}
|
||||
|
||||
async function syncBoardFromRepo(board, filtersInput) {
|
||||
const workspacePath = activeSession?.workspacePath;
|
||||
async function syncBoardFromRepo(board, filtersInput, cwd = null) {
|
||||
const commandCwd = cwd || process.cwd();
|
||||
let repo = normalizeText(board.repo);
|
||||
if (!repo && workspacePath) {
|
||||
const repoData = await runGhJson(["repo", "view", "--json", "nameWithOwner"], workspacePath);
|
||||
if (!repo && cwd) {
|
||||
const repoData = await runGhJson(["repo", "view", "--json", "nameWithOwner"], cwd);
|
||||
repo = normalizeText(repoData?.nameWithOwner);
|
||||
}
|
||||
if (!repo) {
|
||||
@@ -535,7 +544,7 @@ async function syncBoardFromRepo(board, filtersInput) {
|
||||
"--json",
|
||||
"number,title,url,labels,assignees,createdAt,updatedAt,author,body",
|
||||
],
|
||||
workspacePath || process.cwd(),
|
||||
commandCwd,
|
||||
);
|
||||
|
||||
const filteredIssues = Array.isArray(issues) ? sortIssues(issues.filter((issue) => issueMatchesFilters(issue, filters)), filters.sortBy) : [];
|
||||
@@ -1843,6 +1852,7 @@ async function handleServerRequest(instanceId, req, res) {
|
||||
await ensureStorageLoaded();
|
||||
const board = getOrCreateBoard(entry.boardId);
|
||||
board.title = entry.title;
|
||||
const cwd = entry.cwd || null;
|
||||
|
||||
if (req.method === "GET" && req.url === "/") {
|
||||
res.setHeader("Content-Type", "text/html; charset=utf-8");
|
||||
@@ -1866,7 +1876,7 @@ async function handleServerRequest(instanceId, req, res) {
|
||||
if (payload?.resetDecisions === true) {
|
||||
resetBoardDecisions(board);
|
||||
}
|
||||
await syncBoardFromRepo(board, payload?.filters);
|
||||
await syncBoardFromRepo(board, payload?.filters, cwd);
|
||||
await persistStorage();
|
||||
res.setHeader("Content-Type", "application/json; charset=utf-8");
|
||||
res.end(JSON.stringify(buildBoardState(board)));
|
||||
@@ -1905,10 +1915,10 @@ async function handleServerRequest(instanceId, req, res) {
|
||||
return;
|
||||
}
|
||||
if (decision === "close") {
|
||||
await closeGithubIssue(board, item, payload?.note);
|
||||
await closeGithubIssue(board, item, payload?.note, cwd || process.cwd());
|
||||
}
|
||||
if (payload?.quickResponse === true && decision !== "close" && normalizeText(payload?.note)) {
|
||||
await commentGithubIssue(board, item, payload?.note);
|
||||
await commentGithubIssue(board, item, payload?.note, cwd || process.cwd());
|
||||
}
|
||||
if (decision === "assign_agent") {
|
||||
const sessionStatus = await startImplementationSession(board, item, payload?.agent, payload?.note);
|
||||
@@ -1932,7 +1942,7 @@ async function handleServerRequest(instanceId, req, res) {
|
||||
res.end("Not found");
|
||||
}
|
||||
|
||||
async function startServer(instanceId) {
|
||||
async function startServer(instanceId, cwd) {
|
||||
const server = createServer((req, res) => {
|
||||
handleServerRequest(instanceId, req, res).catch((error) => {
|
||||
if (res.headersSent) {
|
||||
@@ -1946,7 +1956,7 @@ async function startServer(instanceId) {
|
||||
await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
|
||||
const address = server.address();
|
||||
const port = typeof address === "object" && address ? address.port : 0;
|
||||
return { server, url: `http://127.0.0.1:${port}/` };
|
||||
return { server, url: `http://127.0.0.1:${port}/`, cwd };
|
||||
}
|
||||
|
||||
const session = await joinSession({
|
||||
@@ -1998,6 +2008,7 @@ const session = await joinSession({
|
||||
additionalProperties: false,
|
||||
},
|
||||
handler: async (ctx) => {
|
||||
const cwd = cwdForContext(ctx);
|
||||
await ensureStorageLoaded();
|
||||
const board = getOrCreateBoard(normalizeText(ctx.input?.boardId, "default"));
|
||||
const title = normalizeText(ctx.input?.title);
|
||||
@@ -2008,7 +2019,7 @@ const session = await joinSession({
|
||||
if (repo) {
|
||||
board.repo = repo;
|
||||
}
|
||||
await syncBoardFromRepo(board, ctx.input?.filters);
|
||||
await syncBoardFromRepo(board, ctx.input?.filters, cwd);
|
||||
await persistStorage();
|
||||
return buildBoardState(board);
|
||||
},
|
||||
@@ -2072,6 +2083,7 @@ const session = await joinSession({
|
||||
additionalProperties: false,
|
||||
},
|
||||
handler: async (ctx) => {
|
||||
const cwd = cwdForContext(ctx);
|
||||
await ensureStorageLoaded();
|
||||
const board = getOrCreateBoard(normalizeText(ctx.input?.boardId, "default"));
|
||||
const itemId = normalizeText(ctx.input?.itemId);
|
||||
@@ -2081,10 +2093,10 @@ const session = await joinSession({
|
||||
throw new Error(`Item "${itemId}" not found`);
|
||||
}
|
||||
if (decision === "close") {
|
||||
await closeGithubIssue(board, item, ctx.input?.note);
|
||||
await closeGithubIssue(board, item, ctx.input?.note, cwd || process.cwd());
|
||||
}
|
||||
if (ctx.input?.commentOnIssue === true && decision !== "close" && normalizeText(ctx.input?.note)) {
|
||||
await commentGithubIssue(board, item, ctx.input?.note);
|
||||
await commentGithubIssue(board, item, ctx.input?.note, cwd || process.cwd());
|
||||
}
|
||||
if (decision === "assign_agent") {
|
||||
const sessionStatus = await startImplementationSession(board, item, ctx.input?.agent, ctx.input?.note);
|
||||
@@ -2120,6 +2132,8 @@ const session = await joinSession({
|
||||
},
|
||||
],
|
||||
open: async (ctx) => {
|
||||
let entry = servers.get(ctx.instanceId);
|
||||
const cwd = cwdForContext(ctx);
|
||||
await ensureStorageLoaded();
|
||||
const boardId = normalizeText(ctx.input?.boardId, "default");
|
||||
const board = getOrCreateBoard(boardId);
|
||||
@@ -2139,17 +2153,17 @@ const session = await joinSession({
|
||||
setBoardItems(board, ctx.input.items, true);
|
||||
await persistStorage();
|
||||
} else if (syncFromRepo) {
|
||||
await syncBoardFromRepo(board, board.filters);
|
||||
await syncBoardFromRepo(board, board.filters, cwd);
|
||||
await persistStorage();
|
||||
}
|
||||
|
||||
let entry = servers.get(ctx.instanceId);
|
||||
if (!entry) {
|
||||
entry = await startServer(ctx.instanceId);
|
||||
entry = await startServer(ctx.instanceId, cwd);
|
||||
servers.set(ctx.instanceId, entry);
|
||||
}
|
||||
entry.boardId = boardId;
|
||||
entry.title = title;
|
||||
entry.cwd = cwd;
|
||||
return {
|
||||
title,
|
||||
status: "Swipe to triage backlog",
|
||||
|
||||
Reference in New Issue
Block a user