Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion connectors/github/src/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ function media(prefix: Uint8Array, declared: string | null): string {
? mime
: "application/octet-stream";
}
/** Signed storage requests carry no API credentials, even across redirects. */
// Signed storage requests carry no API credentials, even across redirects.
export async function openAsset(
value: string,
signal: AbortSignal,
Expand Down
13 changes: 3 additions & 10 deletions connectors/github/src/definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,8 @@ function appOf(values: {

type Settings = Readonly<Partial<SettingValues<typeof githubSettings>>>;

/** The connector for the settings a run reads, which the kit builds again at
* the start of each run. With none, it is in its widest shape. */
export function connector(settings: Settings = {}) {
// A process that reads no stars holds no star field, so it never writes or
// puts back the marks another process sets on the rows it syncs.
// A process that reads no stars holds no star field, so it never puts back the marks another process sets.
const starFields =
settings.github_stars === false ? [] : ["starred", "starred_at"];
return defineConnector<typeof githubSettings>({
Expand Down Expand Up @@ -159,10 +156,7 @@ export function connector(settings: Settings = {}) {
],
readOnly: [...starFields, "synced"],
derived: [...starFields, "synced"],
// Nothing turns a synced row into a star-only one: a star-only write,
// or one process putting back what it last wrote, leaves `synced`
// alone, and a row another process has marked synced since this one
// agreed on it is not this one's to archive.
// A row another process has marked synced is not this one's to archive.
policy: (item, entry, archiving) =>
item?.properties["synced"] !== true
? {}
Expand Down Expand Up @@ -461,8 +455,7 @@ export function connector(settings: Settings = {}) {
from_type_constraints: [issueType],
to_type_constraints: [issueType],
},
// Retired (see `retired`): cleared on every row written with them, so one synced before
// holds only `about` and `comments-on`.
// Retired: cleared on every row written with them, so one synced before holds only `about` and `comments-on`.
{
id: references,
cardinality: "many-to-many",
Expand Down
23 changes: 2 additions & 21 deletions connectors/github/src/discussion-write.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ const reasons = {
duplicate: "DUPLICATE",
} as const;

/** The reason a row asks to close for: one GitHub offers, or resolved. */
function closing(item: Item): (typeof reasons)[keyof typeof reasons] {
const asked = text(item, "state_reason")?.toLowerCase();
return asked !== undefined && asked in reasons
Expand All @@ -86,9 +85,7 @@ function commentAnswer(context: Context, comment: DiscussionComment): Entry {
);
}

/** Asked of each installation the sync uses, with the token that reads
* Discussions. A node none of them shows is gone; where one refused the
* App Discussions, the node may be there, so the change waits. */
// Where one installation refused the App Discussions, the node may be there, so the change waits.
async function seekIn<T>(
context: Context,
app: App,
Expand Down Expand Up @@ -171,8 +168,6 @@ async function commentAt(
};
}

/** A refusal of a Discussions write, as a refused change rather than a
* failed run. */
async function refused(
error: unknown,
place: Place,
Expand All @@ -188,7 +183,6 @@ async function discussionsMadeSince(
signal: AbortSignal,
attempted: string,
): Promise<{ node_id: string; body: string; discussion: Discussion }[]> {
// GitHub takes no idempotency key: find what the first try made.
const since = new Date(Date.parse(attempted) - margin).toISOString();
const bot = await botOf(app, signal);
const listed = await listDiscussions(
Expand Down Expand Up @@ -222,9 +216,6 @@ async function commentsMadeSince(

type Handled = { entry: Entry | undefined } | undefined;

/** Which kind of thread a comment is in: where the row was placed, or for a
* row with no placement, which kind its node is. An issue comment goes on to
* the issue path unasked. */
async function threadIsDiscussion(
change: Change,
context: Context,
Expand All @@ -242,8 +233,6 @@ async function threadIsDiscussion(
return (await commentAt(context, app, item, node)) !== undefined;
}

/** Whether what a comment comments on belongs to a discussion: a discussion,
* or a comment that GitHub holds in one. An issue's comment does not. */
async function inDiscussion(
thread: Item,
context: Context,
Expand All @@ -256,8 +245,6 @@ async function inDiscussion(
return (await commentAt(context, app, thread, node)) !== undefined;
}

/** Carries a change to a discussion or to a comment on one; nothing for any
* other row, which the issue path carries. */
export async function carryDiscussions(
change: Change,
context: Context,
Expand Down Expand Up @@ -421,8 +408,6 @@ async function createRow(
return place(change, context, where, posted, false);
}

/** Brings a discussion a create made to what the row says: a retry finds one
* made before the row changed, and a row can be made closed. */
async function place(
change: Change,
context: Context,
Expand Down Expand Up @@ -521,8 +506,7 @@ async function createComment(
change.connections?.[commentsOn]?.added[0] ??
change.placement?.[commentsOn]?.[0];
const hostNode = thread === undefined ? undefined : text(thread, "github_id");
// A reply comments on its parent comment, so the discussion is the one
// GitHub holds that comment in.
// A reply comments on its parent comment, so the discussion is the one GitHub holds that comment in.
const discussionNode =
thread?.type === commentType && hostNode !== undefined
? (await commentAt(context, app, thread, hostNode))?.comment.discussion
Expand Down Expand Up @@ -619,9 +603,6 @@ async function createComment(
return commentAnswer(context, comment);
}

/** Posts a comment again that is gone from GitHub, under the App's name only
* where the App wrote it. `undefined` where the row is not a discussion
* comment placed in a discussion. */
export async function remakeDiscussions(
change: Change,
context: Context,
Expand Down
69 changes: 10 additions & 59 deletions connectors/github/src/discussions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ import {
import { batches, query, reads, type Client } from "./github.js";
import { loginOf } from "./graph.js";

/** A comment cursor asked a little early, so a discussion GitHub shows late
* under an earlier time is still read; what comes again is unchanged. */
// Asked a little early, so a discussion GitHub shows late under an earlier time is still read.
const overlap = 5 * 60 * 1000;

const discussionFields = `
Expand All @@ -36,9 +35,7 @@ const commentFields = `

const whereFields = "discussion { id repository { id nameWithOwner } }";

/** The first page of a discussion's comments, and of each comment's replies,
* asked with the discussion itself so a read is one request where they fit.
* Less than GitHub allows keeps the query's cost down; the rest is paged. */
// Asked with the discussion so a read is one request where they fit; fewer than GitHub allows keeps the query's cost down.
const commentsFirst = 20;
const repliesFirst = 10;
const inlineComments = `comments(first: ${String(commentsFirst)}) {
Expand Down Expand Up @@ -151,9 +148,6 @@ function advance(
return cursor;
}

/** Why GitHub will not show the App or token a repository's Discussions: the
* installation does not hold the permission, or its answer names the
* repository as unreadable. Anything else is no refusal and is thrown on. */
export class DiscussionsRefused extends Error {
override name = "DiscussionsRefused";
}
Expand All @@ -176,7 +170,6 @@ export function discussionsRefusal(error: unknown): string | undefined {

interface Read {
found: Discussion[];
/** The first page of each one's comments, where they were asked for. */
first: Map<string, Page<GraphComment>>;
}

Expand Down Expand Up @@ -240,10 +233,6 @@ export async function discussionCommentsByNode(
return found;
}

/** Every top-level comment and reply of a discussion, parents before their
* replies; none where GitHub no longer shows the discussion. Where the first
* page of comments came with the discussion, it is read from there and only
* what lies beyond it is asked for. */
export async function commentsOf(
octokit: Client,
discussion: { node: string; repository: Repository },
Expand Down Expand Up @@ -301,9 +290,6 @@ export async function commentsOf(
}
}

/** A repository's discussions, newest change first, down to `since` where
* one is given, each with the first page of its comments. A repository
* with Discussions turned off lists none. */
export async function listDiscussions(
octokit: Client,
owner: string,
Expand Down Expand Up @@ -355,8 +341,7 @@ export async function listDiscussions(
}
}

/** Whether a repository has Discussions turned on, asked with the token that
* reads them. False where GitHub does not show the repository to it. */
// False where GitHub does not show the repository to the token.
async function discussionsOn(
octokit: Client,
fullName: string,
Expand Down Expand Up @@ -445,7 +430,7 @@ const mutations = {

type Closing = "RESOLVED" | "OUTDATED" | "DUPLICATE";

/** A create is never retried blind: one that landed would be made twice. */
// A create is never retried blind: one that landed would be made twice.
const once = { request: { retries: 0 } };

export async function createDiscussion(
Expand Down Expand Up @@ -525,9 +510,7 @@ export async function updateDiscussionComment(
return answered(answer.updateDiscussionComment.comment);
}

/** GraphQL answers NOT_FOUND alike for a comment gone and for one it will
* not let the App touch, so it counts as gone only where the comment no
* longer reads in a repository that still does. */
// GraphQL answers NOT_FOUND alike for a gone comment and one the App may not touch: gone only where the comment no longer reads in a repository that still does.
export async function deleteDiscussionComment(
octokit: Client,
id: string,
Expand All @@ -553,7 +536,6 @@ type Reading = Pick<
"upsert" | "linked" | "linkedEach" | "archive" | "log" | "hints"
>;

/** The links of the comments and replies Marfa holds under a discussion. */
async function heldComments(
context: Pick<Reading, "linked" | "linkedEach">,
discussion: string,
Expand All @@ -579,9 +561,7 @@ async function heldComments(
return held;
}

/** The discussions Marfa holds in a repository, each with the links of the
* comments and replies it holds under it. Rows written by this run have no
* connection yet, so this is read before anything is written. */
// Read before anything is written: rows written by this run have no connection yet.
export async function heldIn(
context: Pick<Reading, "linked" | "linkedEach">,
node: string,
Expand Down Expand Up @@ -625,8 +605,6 @@ async function write(
);
}

/** The comments held under discussions that were read in full, which that
* read did not return, each with its discussion. */
function absentFrom(
held: ReadonlyMap<string, readonly string[]>,
comments: ReadonlyMap<string, readonly DiscussionComment[]>,
Expand All @@ -640,9 +618,7 @@ function absentFrom(
return absent;
}

/** Those of these comments that a lookup by their own node does not find
* either. A comment that was deleted but has replies is returned, blank, and
* is not among them. */
// A comment deleted but with replies is returned, blank, so is not among them.
async function confirmedGone(
octokit: Client,
absent: readonly string[],
Expand All @@ -661,13 +637,7 @@ async function missingComments(
return confirmedGone(octokit, [...absentFrom(held, comments).keys()]);
}

/** Reads a repository's discussions with every comment and reply, and writes
* them. Down to the saved time it lists only what changed; a first read and
* the daily check list them all, which also archives what GitHub no longer
* returns, a discussion or a comment, once a lookup by its own node agrees.
* An edit to a comment does not move its discussion's time, so only that
* full read and a delivery find the edit on a discussion otherwise quiet.
* Returns the time the next read lists down to. */
// An edit to a comment does not move its discussion's time, so only the full read and a delivery find it.
export async function syncDiscussions(
context: Reading,
octokit: Client,
Expand Down Expand Up @@ -743,20 +713,6 @@ async function archiveGone(
}
}

/** The discussions a delivery named, read in full where GitHub shows them in
* a synced repository. Each one read in full also has archived the comments
* the delivery named that Marfa holds and it no longer returns, if a lookup
* by the comment's own node agrees. A discussion GitHub shows nowhere, with
* nothing deferred and its repository still reading, is archived if Marfa
* holds no comment under it; one that does is left to the daily check.
* Nothing is archived while the repository has Discussions turned off, nor
* once any lookup was refused: the discussion may be there, and the
* scheduled read says the refusal for the repository.
*
* Returns the discussions not shown yet because a limit deferred the look,
* and the comments the delivery named that this read dealt with: read in
* full, confirmed gone, or left on purpose to the daily check. A caller
* must not judge those as issue comments. */
export async function readNamedDiscussions(
context: Reading,
ids: ReadonlySet<string>,
Expand All @@ -778,9 +734,7 @@ export async function readNamedDiscussions(
for (const link of links) if (named.has(link)) handled.add(link);
};
const switches = new Map<string, boolean>();
// A repository is judged by what its discussions leave out only while
// GitHub says it has Discussions on; a repository it does not show is not
// proven on.
// A repository is judged by what its discussions leave out only while GitHub says it has Discussions on.
const switchedOn = async (
octokit: Client,
fullName: string,
Expand Down Expand Up @@ -889,10 +843,7 @@ export async function readNamedDiscussions(
if (discussionsRefusal(error) === undefined) throw error;
continue;
}
// A run for deliveries archives only what a delivery named, and a
// discussion's own delivery names none of its comments. Archiving the
// discussion alone would leave them out of the daily check's sight, so a
// discussion with any waits for that check, which archives both.
// A delivery archives only what it named and names none of a discussion's comments: a discussion with any waits for the daily check.
await context.archive(
discussionType,
gone.filter((link) => (held.get(link) ?? []).length === 0),
Expand Down
Loading
Loading