f0b06dea Andy McCall 1 month ago
1
// Activation: sign in, find the Oxygen extension's API, register the
2
// remote provider, wire the views, the review controller and the commands.
3
4
import * as vscode from "vscode";
5
import { HubAuth } from "./auth";
6
import { ChecksBar } from "./checks";
bf73998c Andy McCall 1 month ago ↶
7
import { ProposalContentProvider, SCHEME, openAllChanges, openFileDiff, refOf } from "./diff";
f0b06dea Andy McCall 1 month ago
8
import { hubUrl } from "./hub";
b2dd082c Andy McCall 1 month ago ↶
9
import { InboxBar } from "./inbox";
1cc0ff44 Andy McCall 1 month ago ↶
10
import { draftRelease, ReleasesProvider } from "./releases";
f902d5b8 Andy McCall 1 month ago ↶
11
import { ReferenceCompletions, ReferenceHovers, ReferenceIndex, SELECTOR } from "./references";
95f69b4a Andy McCall 1 month ago ↶
12
import { annotateTodo, issueBody, todoTitle } from "./refs";
f0b06dea Andy McCall 1 month ago
13
import { IssueNode, IssuesProvider, showIssue } from "./issues";
14
import type { OxygenAPI } from "./oxygenapi";
bf73998c Andy McCall 1 month ago ↶
15
import { HubRepo, ProposalFileNode, ProposalNode, ProposalsProvider, showDetail } from "./proposals";
f0b06dea Andy McCall 1 month ago
16
import { makeProvider } from "./provider";
17
import { ReviewController } from "./review";
18
19
let auth: HubAuth;
20
let oxygen: OxygenAPI | undefined;
21
let proposals: ProposalsProvider;
22
let issues: IssuesProvider;
23
let review: ReviewController;
24
let bar: ChecksBar;
bf73998c Andy McCall 1 month ago ↶
25
let content: ProposalContentProvider;
b2dd082c Andy McCall 1 month ago ↶
26
let inbox: InboxBar;
f902d5b8 Andy McCall 1 month ago ↶
27
let references: ReferenceIndex;
1cc0ff44 Andy McCall 1 month ago ↶
28
let releases: ReleasesProvider;
f0b06dea Andy McCall 1 month ago
29
30
export async function activate(context: vscode.ExtensionContext): Promise<void> {
31
auth = new HubAuth(context.secrets);
32
await auth.load();
33
context.subscriptions.push(auth);
34
52cef001 Andy McCall 1 month ago ↶
35
const ext = vscode.extensions.getExtension<OxygenAPI>("oxygen.oxygen-vscode");
f0b06dea Andy McCall 1 month ago
36
oxygen = ext ? ((await ext.activate()) as OxygenAPI | undefined) : undefined;
37
if (!oxygen) {
092b8bf9 Andy McCall 1 month ago ↶
38
void vscode.window.showWarningMessage("OxygenHub: the Oxygen extension is not available; install oxygen.oxygen-vscode 0.7.0 or later.");
f0b06dea Andy McCall 1 month ago
39
} else {
40
context.subscriptions.push(oxygen.registerRemoteProvider(makeProvider({ bases: () => auth.bases() })));
41
context.subscriptions.push(oxygen.onDidChangeRepositories(() => refreshAll()));
42
}
43
44
proposals = new ProposalsProvider(() => oxygen, auth);
45
issues = new IssuesProvider(() => proposals.repos(), auth);
46
review = new ReviewController(auth);
47
bar = new ChecksBar(auth, () => proposals.repos());
b2dd082c Andy McCall 1 month ago ↶
48
inbox = new InboxBar(auth, async (t) => {
49
const repo = (await proposals.repos()).find((r) => r.base === t.base && r.owner === t.owner && r.name === t.name);
50
if (!repo) {
51
return false;
52
}
53
const client = auth.clientFor(repo.base);
54
if (t.kind === "proposal") {
55
const [p, checks] = await Promise.all([client.proposal(repo.owner, repo.name, t.number), client.proposalChecks(repo.owner, repo.name, t.number).catch(() => [])]);
56
showDetail(repo, p, checks);
57
} else {
58
await showIssue(auth, repo, await client.issue(repo.owner, repo.name, t.number));
59
}
60
return true;
61
});
62
context.subscriptions.push(inbox);
1cc0ff44 Andy McCall 1 month ago ↶
63
releases = new ReleasesProvider(() => proposals.repos(), auth);
64
context.subscriptions.push(vscode.window.registerTreeDataProvider("oxygenhub.releases", releases));
f902d5b8 Andy McCall 1 month ago ↶
65
references = new ReferenceIndex(auth, () => proposals.repos());
66
context.subscriptions.push(
67
vscode.languages.registerCompletionItemProvider(SELECTOR, new ReferenceCompletions(references), "#", "@"),
68
vscode.languages.registerHoverProvider(SELECTOR, new ReferenceHovers(references)),
69
);
bf73998c Andy McCall 1 month ago ↶
70
content = new ProposalContentProvider(auth);
71
context.subscriptions.push(content, vscode.workspace.registerTextDocumentContentProvider(SCHEME, content));
f0b06dea Andy McCall 1 month ago
72
context.subscriptions.push(vscode.window.registerTreeDataProvider("oxygenhub.proposals", proposals), vscode.window.registerTreeDataProvider("oxygenhub.issues", issues), review, bar);
73
context.subscriptions.push(auth.onDidChange(() => refreshAll()));
74
75
context.subscriptions.push(
76
vscode.commands.registerCommand("oxygenhub.signIn", async () => {
77
const repos = oxygen ? await guessHubs() : [];
78
await auth.signIn(repos[0]);
79
refreshAll();
80
}),
81
vscode.commands.registerCommand("oxygenhub.signOut", async () => {
82
const pick = await vscode.window.showQuickPick(auth.all().map((s) => s.base), { placeHolder: "Sign out of" });
83
if (pick) {
84
await auth.removeSession(pick);
85
refreshAll();
86
}
87
}),
88
vscode.commands.registerCommand("oxygenhub.refresh", () => refreshAll()),
b2dd082c Andy McCall 1 month ago ↶
89
vscode.commands.registerCommand("oxygenhub.inbox", () => inbox.show()),
1cc0ff44 Andy McCall 1 month ago ↶
90
vscode.commands.registerCommand("oxygenhub.draftRelease", async (node?: { repo?: HubRepo }) => {
91
const repos = await proposals.repos();
92
const repo = node?.repo ?? (repos.length === 1 ? repos[0] : (await vscode.window.showQuickPick(repos.map((r) => ({ label: `${r.owner}/${r.name}`, r })), { placeHolder: "Repository" }))?.r);
93
if (!repo) {
94
return;
95
}
96
try {
97
const r = await draftRelease(auth, repo);
98
if (r) {
99
releases.refresh();
092b8bf9 Andy McCall 1 month ago ↶
100
const open = await vscode.window.showInformationMessage(`OxygenHub: released ${r.tag}.`, "Open on Hub");
1cc0ff44 Andy McCall 1 month ago ↶
101
if (open) {
102
void vscode.env.openExternal(vscode.Uri.parse(r.url));
103
}
104
}
105
} catch (e) {
092b8bf9 Andy McCall 1 month ago ↶
106
void vscode.window.showErrorMessage(`OxygenHub: ${(e as Error).message}`);
1cc0ff44 Andy McCall 1 month ago ↶
107
}
108
}),
f0b06dea Andy McCall 1 month ago
109
vscode.commands.registerCommand("oxygenhub.openProposal", async (node?: ProposalNode) => {
110
const n = node ?? (await pickProposal());
111
if (!n) {
112
return;
113
}
114
const checks = await auth.clientFor(n.repo.base).proposalChecks(n.repo.owner, n.repo.name, n.p.number).catch(() => []);
115
showDetail(n.repo, n.p, checks);
116
}),
117
vscode.commands.registerCommand("oxygenhub.openOnHub", (node?: ProposalNode | IssueNode) => {
118
if (!node) {
119
return;
120
}
121
const target = node.kind === "proposal" ? { kind: "proposal", number: node.p.number } : { kind: "issue", number: node.i.number };
122
void vscode.env.openExternal(vscode.Uri.parse(hubUrl(node.repo.base, node.repo.owner, node.repo.name, target)));
123
}),
bf73998c Andy McCall 1 month ago ↶
124
vscode.commands.registerCommand("oxygenhub.openProposalFile", async (node: ProposalFileNode) => {
125
await openFileDiff(node.repo, node.p.number, node.f);
126
await review.loadDiff(node.repo, node.p.number).catch(() => undefined);
127
}),
128
vscode.commands.registerCommand("oxygenhub.openProposalChanges", (...args: unknown[]) =>
129
withProposal(args, async (repo, number) => {
130
try {
131
const client = auth.clientFor(repo.base);
132
const [p, files] = await Promise.all([client.proposal(repo.owner, repo.name, number), client.proposalFiles(repo.owner, repo.name, number)]);
133
await openAllChanges(repo, p, files);
134
await review.loadDiff(repo, number);
135
} catch (e) {
092b8bf9 Andy McCall 1 month ago ↶
136
void vscode.window.showErrorMessage(`OxygenHub: ${(e as Error).message}`);
bf73998c Andy McCall 1 month ago ↶
137
}
138
}),
139
),
f0b06dea Andy McCall 1 month ago
140
vscode.commands.registerCommand("oxygenhub.checkoutProposal", (...args: unknown[]) => withProposal(args, checkout)),
141
vscode.commands.registerCommand("oxygenhub.review", (...args: unknown[]) => withProposal(args, reviewProposal)),
142
vscode.commands.registerCommand("oxygenhub.sealApproval", (...args: unknown[]) => withProposal(args, (repo, number) => runInTerminal(repo, `oxy seal --proposal ${hubUrl(repo.base, repo.owner, repo.name, { kind: "proposal", number })}`))),
143
vscode.commands.registerCommand("oxygenhub.land", (...args: unknown[]) => withProposal(args, (repo, number) => runInTerminal(repo, `oxy proposal land ${hubUrl(repo.base, repo.owner, repo.name, { kind: "proposal", number })}`))),
144
vscode.commands.registerCommand("oxygenhub.closeProposal", (...args: unknown[]) =>
145
withProposal(args, async (repo, number) => {
146
void vscode.env.openExternal(vscode.Uri.parse(hubUrl(repo.base, repo.owner, repo.name, { kind: "proposal", number })));
147
}),
148
),
149
vscode.commands.registerCommand("oxygenhub.createProposal", () => createProposal()),
150
vscode.commands.registerCommand("oxygenhub.newIssue", () => newIssue()),
95f69b4a Andy McCall 1 month ago ↶
151
vscode.commands.registerCommand("oxygenhub.issueFromSelection", () => issueFromSelection()),
f0b06dea Andy McCall 1 month ago
152
vscode.commands.registerCommand("oxygenhub.openIssue", async (node?: IssueNode) => node && showIssue(auth, node.repo, node.i)),
153
vscode.commands.registerCommand("oxygenhub.commentIssue", (...args: unknown[]) =>
154
withIssue(args, async (repo, number) => {
155
const body = await vscode.window.showInputBox({ prompt: `Comment on #${number}` });
156
if (body) {
157
await auth.clientFor(repo.base).commentIssue(repo.owner, repo.name, number, body);
158
issues.refresh();
159
}
160
}),
161
),
162
vscode.commands.registerCommand("oxygenhub.closeIssue", (...args: unknown[]) => withIssue(args, async (repo, number) => (await auth.clientFor(repo.base).setIssueState(repo.owner, repo.name, number, "closed"), issues.refresh()))),
163
vscode.commands.registerCommand("oxygenhub.reopenIssue", (...args: unknown[]) => withIssue(args, async (repo, number) => (await auth.clientFor(repo.base).setIssueState(repo.owner, repo.name, number, "open"), issues.refresh()))),
164
vscode.commands.registerCommand("oxygenhub.assignMe", (...args: unknown[]) =>
165
withIssue(args, async (repo, number) => {
092b8bf9 Andy McCall 1 month ago ↶
166
void vscode.window.showInformationMessage(`OxygenHub: assigning is on the hub for now: ${hubUrl(repo.base, repo.owner, repo.name, { kind: "issue", number })}`);
f0b06dea Andy McCall 1 month ago
167
}),
168
),
169
vscode.commands.registerCommand("oxygenhub.reply", (reply: vscode.CommentReply) => review.reply(reply)),
170
vscode.commands.registerCommand("oxygenhub.newThread", (reply: vscode.CommentReply) => review.reply(reply)),
171
vscode.commands.registerCommand("oxygenhub.resolveThread", (thread: vscode.CommentThread) => {
172
thread.state = thread.state === vscode.CommentThreadState.Resolved ? vscode.CommentThreadState.Unresolved : vscode.CommentThreadState.Resolved;
173
}),
174
);
175
bar.start();
b2dd082c Andy McCall 1 month ago ↶
176
inbox.start();
f0b06dea Andy McCall 1 month ago
177
}
178
179
function refreshAll(): void {
180
proposals.refresh();
f902d5b8 Andy McCall 1 month ago ↶
181
references.clear();
bf73998c Andy McCall 1 month ago ↶
182
refreshOpenDiffs();
f0b06dea Andy McCall 1 month ago
183
issues.refresh();
1cc0ff44 Andy McCall 1 month ago ↶
184
releases.refresh();
f0b06dea Andy McCall 1 month ago
185
void bar.refresh();
b2dd082c Andy McCall 1 month ago ↶
186
void inbox.refresh();
f0b06dea Andy McCall 1 month ago
187
}
188
bf73998c Andy McCall 1 month ago ↶
189
/** Reload the sides of open proposal diffs, which may have gained changes. */
190
function refreshOpenDiffs(): void {
191
const seen = new Set<string>();
192
for (const doc of vscode.workspace.textDocuments) {
193
const r = refOf(doc.uri);
194
const key = r && `${r.base}/${r.owner}/${r.name}#${r.number}`;
195
if (r && key && !seen.has(key)) {
196
seen.add(key);
197
content.refresh(r.base, r.owner, r.name, r.number);
198
}
199
}
200
}
201
f0b06dea Andy McCall 1 month ago
202
async function guessHubs(): Promise<string[]> {
203
const out: string[] = [];
204
for (const r of oxygen?.repositories ?? []) {
205
for (const remote of await r.remotes().catch(() => [])) {
206
const m = /^(https?:\/\/[^/]+)\/[^/]+\/[^/]+\/?$/.exec(remote.url);
58889495 Andy McCall 1 month ago ↶
207
if (m && remote.ca) {
208
auth.setCa(m[1], remote.ca);
209
}
f0b06dea Andy McCall 1 month ago
210
if (m && !out.includes(m[1])) {
211
out.push(m[1]);
212
}
213
}
214
}
215
return out;
216
}
217
218
async function pickProposal(): Promise<ProposalNode | undefined> {
219
const items: { label: string; description: string; node: ProposalNode }[] = [];
220
for (const repo of await proposals.repos()) {
221
for (const p of await proposals.proposalsOf(repo).catch(() => [])) {
222
items.push({ label: `#${p.number} ${p.title}`, description: `${repo.owner}/${repo.name} · ${p.author} → ${p.target}`, node: { kind: "proposal", repo, p } });
223
}
224
}
225
return (await vscode.window.showQuickPick(items, { placeHolder: "Proposal" }))?.node;
226
}
227
228
/** Commands take a tree node, or the webview's `[base, owner, name, number]`. */
229
async function withProposal(args: unknown[], f: (repo: HubRepo, number: number) => Promise<void>): Promise<void> {
230
const a = args[0];
231
if (a && typeof a === "object" && (a as ProposalNode).kind === "proposal") {
232
const n = a as ProposalNode;
233
return f(n.repo, n.p.number);
234
}
235
if (Array.isArray(a) && a.length === 4) {
236
const [base, owner, name, number] = a as [string, string, string, number];
237
const repo = (await proposals.repos()).find((r) => r.base === base && r.owner === owner && r.name === name);
238
if (repo) {
239
return f(repo, number);
240
}
241
}
242
const n = await pickProposal();
243
if (n) {
244
return f(n.repo, n.p.number);
245
}
246
}
247
248
async function withIssue(args: unknown[], f: (repo: HubRepo, number: number) => Promise<void>): Promise<void> {
249
const a = args[0];
250
if (a && typeof a === "object" && (a as IssueNode).kind === "issue") {
251
const n = a as IssueNode;
252
return f(n.repo, n.i.number);
253
}
254
if (Array.isArray(a) && a.length === 4) {
255
const [base, owner, name, number] = a as [string, string, string, number];
256
const repo = (await proposals.repos()).find((r) => r.base === base && r.owner === owner && r.name === name);
257
if (repo) {
258
return f(repo, number);
259
}
260
}
261
}
262
263
function runInTerminal(repo: HubRepo, command: string): Promise<void> {
092b8bf9 Andy McCall 1 month ago ↶
264
const t = vscode.window.createTerminal({ name: "OxygenHub", cwd: repo.handle.root });
f0b06dea Andy McCall 1 month ago
265
t.show();
266
t.sendText(command);
267
return Promise.resolve();
268
}
269
270
/** Fetch the proposal's changes and switch to a local bookmark at its projected heads (spec §5). */
271
async function checkout(repo: HubRepo, number: number): Promise<void> {
272
const p = await auth.clientFor(repo.base).proposal(repo.owner, repo.name, number);
273
const prefix = vscode.workspace.getConfiguration("oxygenhub").get<string>("proposalBookmarkPrefix") ?? "proposal/";
274
const bookmark = `${prefix}${number}`;
275
try {
276
await repo.handle.json(["fetch", repo.remote, "--json"]);
277
const existing = repo.handle.bookmarks.some((b) => b.name === bookmark);
278
if (!existing) {
279
await repo.handle.json(["bookmark", "create", bookmark, ...p.projected_heads, "--json"]).catch(() => repo.handle.json(["bookmark", "create", bookmark, "--json"]));
280
}
281
await repo.handle.json(["bookmark", "set", bookmark, ...p.projected_heads, "--json"]).catch(() => undefined);
282
await repo.handle.json(["bookmark", "switch", bookmark, "--json"]);
283
await repo.handle.refresh();
284
await review.load(repo, number);
092b8bf9 Andy McCall 1 month ago ↶
285
void vscode.window.showInformationMessage(`OxygenHub: checked out #${number} as ${bookmark}; review threads are in place.`);
f0b06dea Andy McCall 1 month ago
286
} catch (e) {
092b8bf9 Andy McCall 1 month ago ↶
287
void vscode.window.showErrorMessage(`OxygenHub: could not check out #${number}: ${(e as Error).message}`);
f0b06dea Andy McCall 1 month ago
288
}
289
}
290
291
async function reviewProposal(repo: HubRepo, number: number): Promise<void> {
292
const verdict = await vscode.window.showQuickPick(
293
[
294
{ label: "Comment", value: "comment" as const },
295
{ label: "Approve", value: "approve" as const, description: "then seal it with oxy so it counts" },
296
{ label: "Request changes", value: "changes" as const },
297
],
298
{ placeHolder: `Review #${number}` },
299
);
300
if (!verdict) {
301
return;
302
}
303
const body = (await vscode.window.showInputBox({ prompt: "Summary (optional)" })) ?? "";
304
try {
305
await auth.clientFor(repo.base).review(repo.owner, repo.name, number, verdict.value, body);
306
} catch (e) {
092b8bf9 Andy McCall 1 month ago ↶
307
void vscode.window.showErrorMessage(`OxygenHub: ${(e as Error).message}`);
f0b06dea Andy McCall 1 month ago
308
return;
309
}
310
proposals.refresh();
311
if (verdict.value === "approve") {
312
const pick = await vscode.window.showInformationMessage("Approval recorded. Seal it with your key so it counts?", "Seal now");
313
if (pick === "Seal now") {
314
await runInTerminal(repo, `oxy seal --proposal ${hubUrl(repo.base, repo.owner, repo.name, { kind: "proposal", number })}`);
315
}
316
}
317
}
318
319
async function createProposal(): Promise<void> {
320
const repos = await proposals.repos();
321
const repo = repos.length === 1 ? repos[0] : (await vscode.window.showQuickPick(repos.map((r) => ({ label: `${r.owner}/${r.name}`, r })), { placeHolder: "Repository" }))?.r;
322
if (!repo) {
323
return;
324
}
325
const source = repo.handle.currentBookmark;
326
if (!source) {
092b8bf9 Andy McCall 1 month ago ↶
327
void vscode.window.showWarningMessage("OxygenHub: no current bookmark.");
f0b06dea Andy McCall 1 month ago
328
return;
329
}
330
const remoteBookmarks = await auth.clientFor(repo.base).bookmarks(repo.owner, repo.name).catch(() => []);
331
const target = await vscode.window.showQuickPick(remoteBookmarks.filter((b) => b.name !== source).map((b) => b.name), { placeHolder: `Propose ${source} into…` });
332
if (!target) {
333
return;
334
}
335
const title = await vscode.window.showInputBox({ prompt: "Title", value: source });
336
if (!title) {
337
return;
338
}
339
try {
340
await repo.handle.json(["push", repo.remote, "--bookmark", source, "--json"]).catch(() => undefined);
341
const p = await auth.clientFor(repo.base).createProposal(repo.owner, repo.name, { title, body: "", target, source, draft: false });
342
proposals.refresh();
343
void vscode.env.openExternal(vscode.Uri.parse(p.url));
344
} catch (e) {
092b8bf9 Andy McCall 1 month ago ↶
345
void vscode.window.showErrorMessage(`OxygenHub: ${(e as Error).message}`);
f0b06dea Andy McCall 1 month ago
346
}
347
}
348
349
async function newIssue(): Promise<void> {
350
const repos = await proposals.repos();
351
const repo = repos.length === 1 ? repos[0] : (await vscode.window.showQuickPick(repos.map((r) => ({ label: `${r.owner}/${r.name}`, r })), { placeHolder: "Repository" }))?.r;
352
if (!repo) {
353
return;
354
}
355
const title = await vscode.window.showInputBox({ prompt: "Issue title" });
356
if (!title) {
357
return;
358
}
359
const body = (await vscode.window.showInputBox({ prompt: "Description (optional)" })) ?? "";
360
try {
361
const i = await auth.clientFor(repo.base).createIssue(repo.owner, repo.name, title, body);
362
issues.refresh();
092b8bf9 Andy McCall 1 month ago ↶
363
void vscode.window.showInformationMessage(`OxygenHub: opened #${i.number}.`);
f0b06dea Andy McCall 1 month ago
364
} catch (e) {
092b8bf9 Andy McCall 1 month ago ↶
365
void vscode.window.showErrorMessage(`OxygenHub: ${(e as Error).message}`);
f0b06dea Andy McCall 1 month ago
366
}
367
}
368
95f69b4a Andy McCall 1 month ago ↶
369
/**
370
* An issue from the editor (spec §8.1): the selection, or the current line,
371
* quoted under a permalink to it on the hub. A TODO line suggests the title
372
* and afterwards records the issue's number.
373
*/
374
async function issueFromSelection(): Promise<void> {
375
const editor = vscode.window.activeTextEditor;
376
if (!editor || editor.document.uri.scheme !== "file") {
092b8bf9 Andy McCall 1 month ago ↶
377
void vscode.window.showWarningMessage("OxygenHub: open a file of the repository first.");
95f69b4a Andy McCall 1 month ago ↶
378
return;
379
}
380
const doc = editor.document;
381
const file = doc.uri.fsPath;
382
const repo = (await proposals.repos()).filter((r) => file.startsWith(r.handle.root + "/") || file.startsWith(r.handle.root + "\\")).sort((a, b) => b.handle.root.length - a.handle.root.length)[0];
383
if (!repo) {
092b8bf9 Andy McCall 1 month ago ↶
384
void vscode.window.showWarningMessage("OxygenHub: this file is not in a repository with a hub remote.");
95f69b4a Andy McCall 1 month ago ↶
385
return;
386
}
387
const sel = editor.selection;
388
const startLine = sel.start.line;
389
const endLine = sel.isEmpty ? sel.start.line : sel.end.character === 0 && sel.end.line > sel.start.line ? sel.end.line - 1 : sel.end.line;
390
const code = doc.getText(new vscode.Range(startLine, 0, endLine, doc.lineAt(endLine).text.length));
391
const todoLine = [...Array(endLine - startLine + 1).keys()].map((i) => startLine + i).find((l) => todoTitle(doc.lineAt(l).text) !== undefined);
392
const title = await vscode.window.showInputBox({ prompt: "Issue title", value: todoLine !== undefined ? todoTitle(doc.lineAt(todoLine).text) : "" });
393
if (!title) {
394
return;
395
}
396
// Pin the link to the head when the bookmark has one; otherwise follow the bookmark.
397
const bookmark = repo.handle.bookmarks.find((b) => b.name === repo.handle.currentBookmark);
398
const pinned = bookmark?.heads.length === 1 && !doc.isDirty;
399
const reference = pinned ? bookmark!.heads[0] : (repo.handle.currentBookmark ?? "main");
400
const path = file.slice(repo.handle.root.length + 1).split("\\").join("/");
401
const permalink = hubUrl(repo.base, repo.owner, repo.name, { kind: "file", reference, path, line: startLine + 1, endLine: endLine + 1 });
402
const body = issueBody({ permalink, path, startLine: startLine + 1, endLine: endLine + 1, language: doc.languageId === "plaintext" ? "" : doc.languageId, code, pinned });
403
try {
404
const client = auth.clientFor(repo.base);
405
const issue = await client.createIssue(repo.owner, repo.name, title, body);
406
issues.refresh();
407
references.clear();
408
if (todoLine !== undefined) {
409
const line = doc.lineAt(todoLine);
410
const annotated = annotateTodo(line.text, issue.number);
411
if (annotated !== line.text) {
092b8bf9 Andy McCall 1 month ago ↶
412
const pick = await vscode.window.showInformationMessage(`OxygenHub: opened #${issue.number}. Record it in the TODO?`, "Add (#" + issue.number + ")");
95f69b4a Andy McCall 1 month ago ↶
413
if (pick) {
414
await editor.edit((e) => e.replace(line.range, annotated));
415
}
416
}
417
}
418
await showIssue(auth, repo, issue);
419
} catch (e) {
092b8bf9 Andy McCall 1 month ago ↶
420
void vscode.window.showErrorMessage(`OxygenHub: ${(e as Error).message}`);
95f69b4a Andy McCall 1 month ago ↶
421
}
422
}
423
f0b06dea Andy McCall 1 month ago
424
export function deactivate(): void {}