@andorra-labs/code 0.1.15 → 0.1.16
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/src/agent-definitions.js +29 -6
- package/dist/src/agent-execution.js +4 -2
- package/dist/src/agent-mcp.d.ts +1 -1
- package/dist/src/agent-mcp.js +13 -9
- package/dist/src/app-server/protocol.d.ts +4 -1
- package/dist/src/app-server/protocol.js +1 -1
- package/dist/src/app-server.d.ts +107 -0
- package/dist/src/app-server.js +893 -22
- package/dist/src/auth/deployment.js +2 -2
- package/dist/src/browser-runner.js +1 -0
- package/dist/src/browser-ui/style.css +3 -3
- package/dist/src/browser-ui/tokens.css +27 -16
- package/dist/src/claude-provider.js +3 -1
- package/dist/src/cli.js +22 -8
- package/dist/src/codex-errors.js +4 -1
- package/dist/src/command-screens.js +5 -3
- package/dist/src/commands.d.ts +2 -1
- package/dist/src/compaction-phrases.d.ts +4 -0
- package/dist/src/compaction-phrases.js +20 -0
- package/dist/src/context-compaction.js +2 -1
- package/dist/src/decision/DecisionManager.js +3 -2
- package/dist/src/decision/requestPhrases.d.ts +4 -0
- package/dist/src/decision/requestPhrases.js +23 -0
- package/dist/src/github-inbox.d.ts +55 -0
- package/dist/src/github-inbox.js +153 -0
- package/dist/src/graph-health.js +7 -3
- package/dist/src/graph-provider-portability.js +32 -10
- package/dist/src/graph-quota.d.ts +29 -2
- package/dist/src/graph-quota.js +68 -10
- package/dist/src/graph-runner.js +24 -7
- package/dist/src/graph-server.d.ts +1 -1
- package/dist/src/graph-server.js +9 -7
- package/dist/src/graph-ui/app.js +110 -33
- package/dist/src/graph-ui/controls.css +1 -0
- package/dist/src/graph-ui/embed.js +2 -2
- package/dist/src/graph-ui/icons.js +1 -0
- package/dist/src/graph-ui/index.html +1 -1
- package/dist/src/graph-ui/manager.css +1 -1
- package/dist/src/graph-ui/manager.js +2 -2
- package/dist/src/graph-ui/sidebar.js +30 -0
- package/dist/src/graph-ui/studio-canvas.js +26 -13
- package/dist/src/graph-ui/studio.css +15 -7
- package/dist/src/graph-ui/studio.js +11 -4
- package/dist/src/graph-ui/style.css +77 -45
- package/dist/src/graph-ui/theme.js +3 -36
- package/dist/src/graph-ui/tokens.css +27 -19
- package/dist/src/graphs.js +4 -3
- package/dist/src/membership.d.ts +20 -1
- package/dist/src/membership.js +29 -4
- package/dist/src/model-metadata.d.ts +1 -1
- package/dist/src/model-metadata.js +4 -2
- package/dist/src/plan-pass.d.ts +59 -0
- package/dist/src/plan-pass.js +165 -0
- package/dist/src/provider-engine.js +3 -0
- package/dist/src/providers.d.ts +17 -0
- package/dist/src/providers.js +68 -19
- package/dist/src/pull-request-checks.d.ts +26 -0
- package/dist/src/pull-request-checks.js +56 -0
- package/dist/src/pull-request-conversation.d.ts +134 -0
- package/dist/src/pull-request-conversation.js +221 -0
- package/dist/src/pull-request-create.d.ts +175 -0
- package/dist/src/pull-request-create.js +392 -0
- package/dist/src/pull-request-details.d.ts +242 -0
- package/dist/src/pull-request-details.js +614 -0
- package/dist/src/pull-request-edit.d.ts +23 -0
- package/dist/src/pull-request-edit.js +91 -0
- package/dist/src/pull-request-logs.d.ts +76 -0
- package/dist/src/pull-request-logs.js +172 -0
- package/dist/src/pull-request-merge.d.ts +112 -0
- package/dist/src/pull-request-merge.js +258 -0
- package/dist/src/pull-request-review.d.ts +137 -0
- package/dist/src/pull-request-review.js +401 -0
- package/dist/src/pull-requests.d.ts +43 -2
- package/dist/src/pull-requests.js +112 -21
- package/dist/src/react-runtime.js +37 -4
- package/dist/src/remote/engine-pool.js +16 -4
- package/dist/src/run-control.d.ts +10 -0
- package/dist/src/run-control.js +24 -0
- package/dist/src/run-progress.d.ts +10 -0
- package/dist/src/run-progress.js +122 -0
- package/dist/src/run-records.d.ts +2 -2
- package/dist/src/runtime.d.ts +5 -1
- package/dist/src/runtime.js +14 -2
- package/dist/src/subagent-run.js +1 -0
- package/dist/src/telemetry/capture-core.d.ts +17 -0
- package/dist/src/telemetry/capture-core.js +59 -1
- package/dist/src/telemetry/classify.d.ts +3 -1
- package/dist/src/telemetry/classify.js +37 -0
- package/dist/src/telemetry/emitter.d.ts +2 -0
- package/dist/src/telemetry/emitter.js +42 -5
- package/dist/src/telemetry/schema.d.ts +22 -0
- package/dist/src/telemetry/schema.js +68 -1
- package/dist/src/telemetry/surface.d.ts +1 -0
- package/dist/src/telemetry/uploader.d.ts +6 -1
- package/dist/src/telemetry/uploader.js +22 -3
- package/dist/src/terminal-ui.js +1 -1
- package/dist/src/transcript.js +8 -2
- package/dist/src/types.d.ts +7 -0
- package/dist/src/usage-analytics.js +18 -10
- package/package.json +1 -1
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
const QUEUE_STATES = { QUEUED: 'queued', AWAITING_CHECKS: 'awaiting-checks', MERGEABLE: 'mergeable', UNMERGEABLE: 'unmergeable', LOCKED: 'locked' };
|
|
2
|
+
const CHECK_CONTEXTS = 'contexts(first: 100) { nodes { __typename ... on CheckRun { name status conclusion isRequired(pullRequestNumber: $number) } ... on StatusContext { context state isRequired(pullRequestNumber: $number) } } }';
|
|
3
|
+
export const MERGE_CONTEXT_QUERY = `query($owner: String!, $name: String!, $number: Int!) { viewer { login } repository(owner: $owner, name: $name) { viewerPermission mergeCommitAllowed squashMergeAllowed rebaseMergeAllowed autoMergeAllowed deleteBranchOnMerge viewerDefaultMergeMethod pullRequest(number: $number) { id state isDraft isCrossRepository headRefName headRefOid baseRefName mergeable mergeStateStatus reviewDecision isMergeQueueEnabled mergeQueueEntry { position state } viewerCanMergeAsAdmin viewerCanUpdateBranch viewerCanDeleteHeadRef headRef { id } autoMergeRequest { mergeMethod enabledBy { login } } mergeHeadline: viewerMergeHeadlineText(mergeType: MERGE) mergeBody: viewerMergeBodyText(mergeType: MERGE) squashHeadline: viewerMergeHeadlineText(mergeType: SQUASH) squashBody: viewerMergeBodyText(mergeType: SQUASH) reviewThreads(first: 100) { nodes { isResolved } } commits(last: 1) { nodes { commit { statusCheckRollup { ${CHECK_CONTEXTS} } } } } } } }`;
|
|
4
|
+
const text = (value) => typeof value === 'string' && value !== '' ? value : undefined;
|
|
5
|
+
const record = (value) => typeof value === 'object' && value !== null && !Array.isArray(value) ? value : {};
|
|
6
|
+
const list = (value) => Array.isArray(value) ? value : [];
|
|
7
|
+
const loginOf = (value) => text(record(value).login)?.replace(/^app\//, '');
|
|
8
|
+
const METHODS = { MERGE: 'merge', SQUASH: 'squash', REBASE: 'rebase' };
|
|
9
|
+
const GITHUB_METHOD = { merge: 'MERGE', squash: 'SQUASH', rebase: 'REBASE' };
|
|
10
|
+
const MERGE_STATES = { CLEAN: 'clean', BLOCKED: 'blocked', BEHIND: 'behind', DIRTY: 'dirty', UNSTABLE: 'unstable', DRAFT: 'draft', HAS_HOOKS: 'has-hooks' };
|
|
11
|
+
const DECISIONS = { APPROVED: 'approved', CHANGES_REQUESTED: 'changes-requested', REVIEW_REQUIRED: 'review-required' };
|
|
12
|
+
const PERMISSIONS = { ADMIN: 'admin', MAINTAIN: 'maintain', WRITE: 'write', TRIAGE: 'triage', READ: 'read' };
|
|
13
|
+
// A check run that finished without one of these failed, as GitHub's branch protection counts it.
|
|
14
|
+
const PASSING = new Set(['SUCCESS', 'NEUTRAL', 'SKIPPED']);
|
|
15
|
+
/** How a required check stands: failed, still running, or neither (passed or skipped). */
|
|
16
|
+
function requiredCheck(node) {
|
|
17
|
+
if (node.isRequired !== true)
|
|
18
|
+
return undefined;
|
|
19
|
+
if (node.__typename === 'CheckRun') {
|
|
20
|
+
const name = text(node.name);
|
|
21
|
+
if (name === undefined)
|
|
22
|
+
return undefined;
|
|
23
|
+
if (node.status !== 'COMPLETED')
|
|
24
|
+
return { name, state: 'pending' };
|
|
25
|
+
return PASSING.has(String(node.conclusion)) ? undefined : { name, state: 'failed' };
|
|
26
|
+
}
|
|
27
|
+
const name = text(node.context);
|
|
28
|
+
if (name === undefined)
|
|
29
|
+
return undefined;
|
|
30
|
+
if (node.state === 'PENDING' || node.state === 'EXPECTED')
|
|
31
|
+
return { name, state: 'pending' };
|
|
32
|
+
return node.state === 'SUCCESS' ? undefined : { name, state: 'failed' };
|
|
33
|
+
}
|
|
34
|
+
/** `MERGE_CONTEXT_QUERY`'s answer, checked field by field. */
|
|
35
|
+
export function parseMergeContext(raw) {
|
|
36
|
+
const data = record(record(raw).data);
|
|
37
|
+
const repository = record(data.repository);
|
|
38
|
+
const pull = record(repository.pullRequest);
|
|
39
|
+
const viewer = loginOf(data.viewer);
|
|
40
|
+
const pullRequestId = text(pull.id);
|
|
41
|
+
const headSha = text(pull.headRefOid);
|
|
42
|
+
if (viewer === undefined || pullRequestId === undefined || headSha === undefined)
|
|
43
|
+
throw new Error('GraphQL: Could not resolve to a PullRequest (the merge state came back empty)');
|
|
44
|
+
const methods = [['merge', repository.mergeCommitAllowed], ['squash', repository.squashMergeAllowed], ['rebase', repository.rebaseMergeAllowed]]
|
|
45
|
+
.filter(([, allowed]) => allowed === true).map(([method]) => method);
|
|
46
|
+
const preferred = typeof repository.viewerDefaultMergeMethod === 'string' ? METHODS[repository.viewerDefaultMergeMethod] : undefined;
|
|
47
|
+
const messages = {};
|
|
48
|
+
if (typeof pull.mergeHeadline === 'string')
|
|
49
|
+
messages.merge = { title: pull.mergeHeadline, body: typeof pull.mergeBody === 'string' ? pull.mergeBody : '' };
|
|
50
|
+
if (typeof pull.squashHeadline === 'string')
|
|
51
|
+
messages.squash = { title: pull.squashHeadline, body: typeof pull.squashBody === 'string' ? pull.squashBody : '' };
|
|
52
|
+
const requiredFailed = [];
|
|
53
|
+
const requiredPending = [];
|
|
54
|
+
const contexts = list(record(record(record(record(list(record(pull.commits).nodes)[0]).commit).statusCheckRollup).contexts).nodes).map(record);
|
|
55
|
+
for (const node of contexts) {
|
|
56
|
+
const check = requiredCheck(node);
|
|
57
|
+
if (check === undefined)
|
|
58
|
+
continue;
|
|
59
|
+
(check.state === 'failed' ? requiredFailed : requiredPending).push(check.name);
|
|
60
|
+
}
|
|
61
|
+
const auto = record(pull.autoMergeRequest);
|
|
62
|
+
const autoMethod = typeof auto.mergeMethod === 'string' ? METHODS[auto.mergeMethod] : undefined;
|
|
63
|
+
const deletesBranch = repository.deleteBranchOnMerge === true;
|
|
64
|
+
const headRefId = text(record(pull.headRef).id);
|
|
65
|
+
const state = pull.state === 'MERGED' ? 'merged' : pull.state === 'CLOSED' ? 'closed' : pull.isDraft === true ? 'draft' : 'open';
|
|
66
|
+
const permission = typeof repository.viewerPermission === 'string' ? PERMISSIONS[repository.viewerPermission] ?? 'none' : 'none';
|
|
67
|
+
const crossRepository = pull.isCrossRepository === true;
|
|
68
|
+
// GitHub says the viewer may delete the head branch only once the PR is closed; before the merge, anyone
|
|
69
|
+
// who can push to a branch of this repository may delete it after.
|
|
70
|
+
const canDelete = pull.viewerCanDeleteHeadRef === true || (!crossRepository && (permission === 'admin' || permission === 'maintain' || permission === 'write'));
|
|
71
|
+
return {
|
|
72
|
+
viewer,
|
|
73
|
+
pullRequestId,
|
|
74
|
+
state,
|
|
75
|
+
headSha,
|
|
76
|
+
headRefName: text(pull.headRefName) ?? '',
|
|
77
|
+
baseRefName: text(pull.baseRefName) ?? '',
|
|
78
|
+
...(headRefId !== undefined && canDelete ? { headRefId } : {}),
|
|
79
|
+
methods,
|
|
80
|
+
defaultMethod: preferred !== undefined && methods.includes(preferred) ? preferred : methods[0] ?? 'merge',
|
|
81
|
+
messages,
|
|
82
|
+
mergeable: pull.mergeable === 'MERGEABLE' ? 'mergeable' : pull.mergeable === 'CONFLICTING' ? 'conflicting' : 'unknown',
|
|
83
|
+
mergeState: typeof pull.mergeStateStatus === 'string' ? MERGE_STATES[pull.mergeStateStatus] ?? 'unknown' : 'unknown',
|
|
84
|
+
...(typeof pull.reviewDecision === 'string' && DECISIONS[pull.reviewDecision] ? { reviewDecision: DECISIONS[pull.reviewDecision] } : {}),
|
|
85
|
+
requiredFailed,
|
|
86
|
+
requiredPending,
|
|
87
|
+
unresolvedThreads: list(record(pull.reviewThreads).nodes).filter(node => record(node).isResolved === false).length,
|
|
88
|
+
canUpdateBranch: pull.viewerCanUpdateBranch === true,
|
|
89
|
+
crossRepository,
|
|
90
|
+
canDeleteBranch: canDelete && headRefId !== undefined && !deletesBranch,
|
|
91
|
+
deletesBranch,
|
|
92
|
+
autoMergeAllowed: repository.autoMergeAllowed === true,
|
|
93
|
+
...(autoMethod === undefined ? {} : { autoMerge: { method: autoMethod, ...(loginOf(auto.enabledBy) === undefined ? {} : { by: loginOf(auto.enabledBy) }) } }),
|
|
94
|
+
mergeQueue: pull.isMergeQueueEnabled === true,
|
|
95
|
+
...queueEntry(pull.mergeQueueEntry),
|
|
96
|
+
canBypass: pull.viewerCanMergeAsAdmin === true,
|
|
97
|
+
permission,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
function queueEntry(value) {
|
|
101
|
+
const entry = record(value);
|
|
102
|
+
const state = typeof entry.state === 'string' ? QUEUE_STATES[entry.state] : undefined;
|
|
103
|
+
if (state === undefined)
|
|
104
|
+
return {};
|
|
105
|
+
const position = typeof entry.position === 'number' && Number.isSafeInteger(entry.position) && entry.position > 0 ? entry.position : undefined;
|
|
106
|
+
return { queued: { state, ...(position === undefined ? {} : { position }) } };
|
|
107
|
+
}
|
|
108
|
+
const COMPARE_QUERY = 'query($owner: String!, $name: String!, $base: String!, $head: String!) { repository(owner: $owner, name: $name) { ref(qualifiedName: $base) { compare(headRef: $head) { behindBy } } } }';
|
|
109
|
+
/**
|
|
110
|
+
* How far the branch is behind its base. GitHub's `viewerCanUpdateBranch` is true only where the
|
|
111
|
+
* repository asks for branches to be kept up to date, but GitHub updates any branch that is behind, so
|
|
112
|
+
* the tab offers it whenever the viewer can push to a branch of this repository and it is behind.
|
|
113
|
+
*/
|
|
114
|
+
export function withBehind(context, behindBy) {
|
|
115
|
+
if (behindBy === undefined)
|
|
116
|
+
return context;
|
|
117
|
+
const writable = context.permission === 'admin' || context.permission === 'maintain' || context.permission === 'write';
|
|
118
|
+
const open = context.state === 'open' || context.state === 'draft';
|
|
119
|
+
return { ...context, behindBy, canUpdateBranch: context.canUpdateBranch || (open && behindBy > 0 && !context.crossRepository && writable) };
|
|
120
|
+
}
|
|
121
|
+
function graphqlErrors(value) {
|
|
122
|
+
const errors = list(value.errors).map(entry => text(record(entry).message)).filter((message) => message !== undefined);
|
|
123
|
+
if (errors.length > 0)
|
|
124
|
+
throw new Error(`GraphQL: ${errors.join('; ')}`);
|
|
125
|
+
}
|
|
126
|
+
export async function readPullRequestMergeContext(gh, pullRequest) {
|
|
127
|
+
const raw = await gh(['api', 'graphql', '--hostname', 'github.com', '-f', `query=${MERGE_CONTEXT_QUERY}`, '-f', `owner=${pullRequest.owner}`, '-f', `name=${pullRequest.repo}`, '-F', `number=${pullRequest.number}`], { maxBuffer: 8 * 1024 * 1024 });
|
|
128
|
+
const value = JSON.parse(raw);
|
|
129
|
+
graphqlErrors(value);
|
|
130
|
+
const context = parseMergeContext(value);
|
|
131
|
+
if ((context.state !== 'open' && context.state !== 'draft') || context.crossRepository || context.headRefName === '' || context.baseRefName === '')
|
|
132
|
+
return context;
|
|
133
|
+
// A failed comparison leaves the update to what GitHub offers.
|
|
134
|
+
try {
|
|
135
|
+
const compared = JSON.parse(await gh(['api', 'graphql', '--hostname', 'github.com', '-f', `query=${COMPARE_QUERY}`, '-f', `owner=${pullRequest.owner}`, '-f', `name=${pullRequest.repo}`, '-f', `base=refs/heads/${context.baseRefName}`, '-f', `head=refs/heads/${context.headRefName}`]));
|
|
136
|
+
const behind = record(record(record(record(record(compared).data).repository).ref).compare).behindBy;
|
|
137
|
+
return withBehind(context, typeof behind === 'number' && Number.isSafeInteger(behind) && behind >= 0 ? behind : undefined);
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
return context;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/** One mutation, its variables in a JSON body on gh's standard input. GitHub's answer stays on a thrown error (`stdout`). */
|
|
144
|
+
async function mutate(gh, query, variables) {
|
|
145
|
+
const raw = await gh(['api', 'graphql', '--hostname', 'github.com', '--input', '-'], { input: JSON.stringify({ query, variables }) });
|
|
146
|
+
const value = JSON.parse(raw);
|
|
147
|
+
try {
|
|
148
|
+
graphqlErrors(value);
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
throw Object.assign(error, { stdout: raw });
|
|
152
|
+
}
|
|
153
|
+
return record(value.data);
|
|
154
|
+
}
|
|
155
|
+
/** The `data` of GitHub's answer that a failed gh call printed, if it printed one. */
|
|
156
|
+
function answeredData(error) {
|
|
157
|
+
const stdout = error?.stdout;
|
|
158
|
+
if (typeof stdout !== 'string')
|
|
159
|
+
return {};
|
|
160
|
+
try {
|
|
161
|
+
return record(record(JSON.parse(stdout)).data);
|
|
162
|
+
}
|
|
163
|
+
catch {
|
|
164
|
+
return {};
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/** The commit message a merge sends; a rebase sends none, and GitHub's own message is used when the person left it as it was. */
|
|
168
|
+
function message(method, commit) {
|
|
169
|
+
if (method === 'rebase')
|
|
170
|
+
return {};
|
|
171
|
+
return { ...(commit.title === undefined ? {} : { title: commit.title }), ...(commit.body === undefined ? {} : { body: commit.body }) };
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Merges the PR at `headSha`, the head the person read: GitHub refuses ("Head branch was modified") when
|
|
175
|
+
* someone pushed since, so nothing the person has not seen is merged.
|
|
176
|
+
*/
|
|
177
|
+
export async function mergePullRequest(gh, pullRequestId, merge) {
|
|
178
|
+
let data;
|
|
179
|
+
try {
|
|
180
|
+
data = await mutate(gh, 'mutation($pr: ID!, $method: PullRequestMergeMethod!, $head: GitObjectID!, $title: String, $body: String) { mergePullRequest(input: { pullRequestId: $pr, mergeMethod: $method, expectedHeadOid: $head, commitHeadline: $title, commitBody: $body }) { pullRequest { state mergeCommit { oid } } } }', { pr: pullRequestId, method: GITHUB_METHOD[merge.method], head: merge.headSha, ...message(merge.method, merge) });
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
// An error on a field of the answer does not undo a merge GitHub says it made.
|
|
184
|
+
const answered = record(record(answeredData(error).mergePullRequest).pullRequest);
|
|
185
|
+
if (answered.state !== 'MERGED')
|
|
186
|
+
throw error;
|
|
187
|
+
data = { mergePullRequest: { pullRequest: answered } };
|
|
188
|
+
}
|
|
189
|
+
const oid = text(record(record(record(data.mergePullRequest).pullRequest).mergeCommit).oid);
|
|
190
|
+
return oid === undefined ? {} : { mergeCommit: oid };
|
|
191
|
+
}
|
|
192
|
+
/** Sets the PR to merge by itself once its requirements pass (GitHub's auto-merge), with the chosen method and message. */
|
|
193
|
+
export async function enableAutoMerge(gh, pullRequestId, merge) {
|
|
194
|
+
await mutate(gh, 'mutation($pr: ID!, $method: PullRequestMergeMethod!, $head: GitObjectID, $title: String, $body: String) { enablePullRequestAutoMerge(input: { pullRequestId: $pr, mergeMethod: $method, expectedHeadOid: $head, commitHeadline: $title, commitBody: $body }) { pullRequest { autoMergeRequest { mergeMethod } } } }', { pr: pullRequestId, method: GITHUB_METHOD[merge.method], head: merge.headSha, ...message(merge.method, merge) });
|
|
195
|
+
}
|
|
196
|
+
/** Adds the PR to its base's merge queue at `headSha`, the head the person read; GitHub refuses one that moved. */
|
|
197
|
+
export async function enqueue(gh, pullRequestId, headSha) {
|
|
198
|
+
const data = await mutate(gh, 'mutation($pr: ID!, $head: GitObjectID) { enqueuePullRequest(input: { pullRequestId: $pr, expectedHeadOid: $head }) { mergeQueueEntry { position state } } }', { pr: pullRequestId, head: headSha });
|
|
199
|
+
const position = record(record(data.enqueuePullRequest).mergeQueueEntry).position;
|
|
200
|
+
return typeof position === 'number' && Number.isSafeInteger(position) && position > 0 ? { position } : {};
|
|
201
|
+
}
|
|
202
|
+
/** Takes the PR out of its base's merge queue. */
|
|
203
|
+
export async function dequeue(gh, pullRequestId) {
|
|
204
|
+
await mutate(gh, 'mutation($pr: ID!) { dequeuePullRequest(input: { id: $pr }) { mergeQueueEntry { id } } }', { pr: pullRequestId });
|
|
205
|
+
}
|
|
206
|
+
export async function deleteBranch(gh, refId) {
|
|
207
|
+
await mutate(gh, 'mutation($ref: ID!) { deleteRef(input: { refId: $ref }) { clientMutationId } }', { ref: refId });
|
|
208
|
+
}
|
|
209
|
+
/** Brings the head branch up to date with its base on GitHub, by a merge commit or a rebase. Refused when the head moved since `headSha`. */
|
|
210
|
+
export async function updateBranch(gh, pullRequestId, update) {
|
|
211
|
+
const data = await mutate(gh, 'mutation($pr: ID!, $head: GitObjectID, $method: PullRequestBranchUpdateMethod) { updatePullRequestBranch(input: { pullRequestId: $pr, expectedHeadOid: $head, updateMethod: $method }) { pullRequest { headRefOid } } }', { pr: pullRequestId, head: update.headSha, method: update.method === 'rebase' ? 'REBASE' : 'MERGE' });
|
|
212
|
+
const head = text(record(record(data.updatePullRequestBranch).pullRequest).headRefOid);
|
|
213
|
+
return head === undefined ? {} : { headSha: head };
|
|
214
|
+
}
|
|
215
|
+
/** Marks a draft ready for review, or converts an open PR back to a draft. */
|
|
216
|
+
export async function setReadyForReview(gh, pullRequestId, ready) {
|
|
217
|
+
const field = ready ? 'markPullRequestReadyForReview' : 'convertPullRequestToDraft';
|
|
218
|
+
await mutate(gh, `mutation($pr: ID!) { ${field}(input: { pullRequestId: $pr }) { pullRequest { isDraft } } }`, { pr: pullRequestId });
|
|
219
|
+
}
|
|
220
|
+
// What the app-server accepts for the writes, checked before anything reaches gh.
|
|
221
|
+
/** GitHub keeps a commit title to one line; this bounds what the tab sends. */
|
|
222
|
+
const TITLE_LIMIT = 1_000;
|
|
223
|
+
const BODY_LIMIT = 65_536;
|
|
224
|
+
export function mergeMethod(value) {
|
|
225
|
+
if (value === 'merge' || value === 'squash' || value === 'rebase')
|
|
226
|
+
return value;
|
|
227
|
+
throw new Error('method must be merge, squash or rebase');
|
|
228
|
+
}
|
|
229
|
+
export function updateMethod(value) {
|
|
230
|
+
if (value === 'merge' || value === 'rebase')
|
|
231
|
+
return value;
|
|
232
|
+
throw new Error('method must be merge or rebase');
|
|
233
|
+
}
|
|
234
|
+
export function headCommit(value, name = 'headSha') {
|
|
235
|
+
if (typeof value !== 'string' || !/^[0-9a-f]{40}$/i.test(value))
|
|
236
|
+
throw new Error(`${name} must be the full head commit the person read`);
|
|
237
|
+
return value.toLowerCase();
|
|
238
|
+
}
|
|
239
|
+
export function commitTitle(value) {
|
|
240
|
+
if (value === undefined || value === null)
|
|
241
|
+
return undefined;
|
|
242
|
+
if (typeof value !== 'string')
|
|
243
|
+
throw new Error('title must be text');
|
|
244
|
+
if (/[\r\n]/.test(value))
|
|
245
|
+
throw new Error('title must be one line');
|
|
246
|
+
if (value.length > TITLE_LIMIT)
|
|
247
|
+
throw new Error(`title is longer than ${TITLE_LIMIT} characters`);
|
|
248
|
+
return value.trim() === '' ? undefined : value;
|
|
249
|
+
}
|
|
250
|
+
export function commitBody(value) {
|
|
251
|
+
if (value === undefined || value === null)
|
|
252
|
+
return undefined;
|
|
253
|
+
if (typeof value !== 'string')
|
|
254
|
+
throw new Error('body must be text');
|
|
255
|
+
if (value.length > BODY_LIMIT)
|
|
256
|
+
throw new Error(`body is longer than ${BODY_LIMIT} characters`);
|
|
257
|
+
return value;
|
|
258
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import type { PullRequestCheck } from './pull-request-checks.js';
|
|
2
|
+
import { type PullRequestCommentAbilities, type PullRequestMeta, type PullRequestReaction, type PullRequestReviewBody, type PullRequestTimelineComment } from './pull-request-conversation.js';
|
|
3
|
+
import type { GhRunner, SessionPullRequest } from './pull-requests.js';
|
|
4
|
+
export type PullRequestDiffSide = 'left' | 'right';
|
|
5
|
+
export interface PullRequestThreadComment extends Partial<PullRequestCommentAbilities> {
|
|
6
|
+
id: string;
|
|
7
|
+
author: string;
|
|
8
|
+
body: string;
|
|
9
|
+
createdAt?: string;
|
|
10
|
+
url?: string;
|
|
11
|
+
/** The author's GitHub user id, for the co-author trailer of a suggestion committed from the tab. */
|
|
12
|
+
authorId?: number;
|
|
13
|
+
reactions?: PullRequestReaction[];
|
|
14
|
+
}
|
|
15
|
+
export interface PullRequestThread {
|
|
16
|
+
id: string;
|
|
17
|
+
path: string;
|
|
18
|
+
/** The line the thread sits on in the current diff; absent when that line is gone (outdated) or the thread is on the whole file. */
|
|
19
|
+
line?: number;
|
|
20
|
+
/** The first line of a thread on several lines. */
|
|
21
|
+
startLine?: number;
|
|
22
|
+
/** The line it was written on, for a thread whose line is gone. */
|
|
23
|
+
originalLine?: number;
|
|
24
|
+
side: PullRequestDiffSide;
|
|
25
|
+
/** A comment on the whole file rather than a line. */
|
|
26
|
+
onFile?: true;
|
|
27
|
+
resolved: boolean;
|
|
28
|
+
outdated: boolean;
|
|
29
|
+
resolvedBy?: string;
|
|
30
|
+
canReply: boolean;
|
|
31
|
+
canResolve: boolean;
|
|
32
|
+
canUnresolve: boolean;
|
|
33
|
+
comments: PullRequestThreadComment[];
|
|
34
|
+
/** Comments past the ones read, which the tab leaves to GitHub. */
|
|
35
|
+
moreComments?: number;
|
|
36
|
+
}
|
|
37
|
+
export type PullRequestViewedState = 'viewed' | 'unviewed' | 'dismissed';
|
|
38
|
+
export type PullRequestPermission = 'admin' | 'maintain' | 'write' | 'triage' | 'read' | 'none';
|
|
39
|
+
export interface PullRequestReviewer {
|
|
40
|
+
/** A user's login, or a team's slug. */
|
|
41
|
+
login: string;
|
|
42
|
+
/** A team's display name. */
|
|
43
|
+
name?: string;
|
|
44
|
+
team?: true;
|
|
45
|
+
}
|
|
46
|
+
export interface PullRequestReviewContext {
|
|
47
|
+
/** The login every write runs as: the account that read this. */
|
|
48
|
+
viewer: string;
|
|
49
|
+
/** The pull request's GraphQL node id, which the mutations name. */
|
|
50
|
+
pullRequestId: string;
|
|
51
|
+
viewerIsAuthor: boolean;
|
|
52
|
+
/** The viewer's permission on the repository; re-running jobs and requesting reviewers need write. */
|
|
53
|
+
permission: PullRequestPermission;
|
|
54
|
+
threads: PullRequestThread[];
|
|
55
|
+
/** Files the viewer marked viewed (`viewed`) or that changed since (`dismissed`), by path; every other file is unviewed. */
|
|
56
|
+
viewed: Record<string, PullRequestViewedState>;
|
|
57
|
+
requestedReviewers: PullRequestReviewer[];
|
|
58
|
+
suggestedReviewers: string[];
|
|
59
|
+
assignableUsers: string[];
|
|
60
|
+
/** A review the viewer started on github.com and has not submitted; a reply joins it until it is submitted. */
|
|
61
|
+
pendingReview?: {
|
|
62
|
+
id: string;
|
|
63
|
+
comments: number;
|
|
64
|
+
};
|
|
65
|
+
/** Teams with access to the repository, which can be asked to review; absent where the repository has none (a user's own). */
|
|
66
|
+
teams?: PullRequestReviewer[];
|
|
67
|
+
/** The repository belongs to an organization, so teams can be asked to review. */
|
|
68
|
+
organization?: true;
|
|
69
|
+
/** More threads or files than are read; the rest are on GitHub. */
|
|
70
|
+
truncated?: true;
|
|
71
|
+
/** The PR's timeline comments, oldest first (the newest 100); absent from an engine before phase 4. */
|
|
72
|
+
comments?: PullRequestTimelineComment[];
|
|
73
|
+
/** Older timeline comments than those read, which stay on GitHub. */
|
|
74
|
+
moreComments?: number;
|
|
75
|
+
/** Submitted reviews with their ids, reactions and what the viewer may do with them. */
|
|
76
|
+
reviewBodies?: PullRequestReviewBody[];
|
|
77
|
+
/** The PR's title, body, labels and assignees, and what the viewer may change. */
|
|
78
|
+
meta?: PullRequestMeta;
|
|
79
|
+
}
|
|
80
|
+
export declare const REVIEW_CONTEXT_QUERY = "query($owner: String!, $name: String!, $number: Int!) { viewer { login } repository(owner: $owner, name: $name) { viewerPermission owner { __typename } pullRequest(number: $number) { id viewerDidAuthor reviews(states: PENDING, first: 1) { nodes { id comments { totalCount } } } reviewRequests(first: 50) { nodes { requestedReviewer { __typename ... on User { login } ... on Bot { login } ... on Mannequin { login } ... on Team { slug name } } } } suggestedReviewers { reviewer { login } } files(first: 100) { pageInfo { hasNextPage endCursor } nodes { path viewerViewedState } } reviewThreads(first: 100) { pageInfo { hasNextPage endCursor } nodes { id isResolved isOutdated path line originalLine startLine diffSide subjectType viewerCanResolve viewerCanUnresolve viewerCanReply resolvedBy { login } comments(first: 50) { totalCount nodes { id body createdAt url author { login ... on User { databaseId } ... on Bot { databaseId } } viewerCanUpdate viewerCanDelete viewerCanReact reactionGroups { content viewerHasReacted reactors { totalCount } } } } } } title body viewerCanUpdate viewerCanClose viewerCanReopen headRefName headRefOid headRepository { nameWithOwner } reactionGroups { content viewerHasReacted reactors { totalCount } } labels(first: 50) { nodes { id name color description } } assignees(first: 20) { nodes { id login } } comments(last: 100) { totalCount nodes { id author { login } body createdAt lastEditedAt url isMinimized minimizedReason viewerDidAuthor viewerCanUpdate viewerCanDelete viewerCanReact reactionGroups { content viewerHasReacted reactors { totalCount } } } } timelineReviews: reviews(last: 100, states: [APPROVED, CHANGES_REQUESTED, COMMENTED, DISMISSED]) { nodes { id author { login } state body submittedAt url viewerDidAuthor viewerCanUpdate viewerCanReact comments { totalCount } reactionGroups { content viewerHasReacted reactors { totalCount } } } } } assignableUsers(first: 100) { nodes { id login } } labels(first: 100, orderBy: { field: NAME, direction: ASC }) { nodes { id name color description } } } }";
|
|
81
|
+
export declare function parseThread(value: unknown): PullRequestThread | undefined;
|
|
82
|
+
/** The first page of `REVIEW_CONTEXT_QUERY`, checked field by field. Later pages of threads and files are added by `readPullRequestReview`. */
|
|
83
|
+
export declare function parseReviewContext(raw: unknown): PullRequestReviewContext;
|
|
84
|
+
/**
|
|
85
|
+
* The teams with access to the repository (`GET /repos/{owner}/{repo}/teams`), which GitHub lets the PR
|
|
86
|
+
* ask to review. Teams the viewer cannot see are left out by GitHub.
|
|
87
|
+
*/
|
|
88
|
+
export declare function readRepositoryTeams(gh: GhRunner, pullRequest: Pick<SessionPullRequest, 'owner' | 'repo'>): Promise<PullRequestReviewer[]>;
|
|
89
|
+
export declare function readPullRequestReview(gh: GhRunner, pullRequest: Pick<SessionPullRequest, 'owner' | 'repo' | 'number'>): Promise<PullRequestReviewContext>;
|
|
90
|
+
/** Line comments join a pending review this many to a request, so a long review takes a few calls rather than one per comment. */
|
|
91
|
+
export declare const PENDING_COMMENT_BATCH = 10;
|
|
92
|
+
export declare function replyToThread(gh: GhRunner, threadId: string, body: string): Promise<void>;
|
|
93
|
+
export declare function setThreadResolved(gh: GhRunner, threadId: string, resolved: boolean): Promise<void>;
|
|
94
|
+
export declare function setFileViewed(gh: GhRunner, pullRequestId: string, path: string, viewed: boolean): Promise<void>;
|
|
95
|
+
export type PullRequestReviewEvent = 'comment' | 'approve' | 'request-changes';
|
|
96
|
+
/** A comment on one line (or a range ending at `line`) of the diff, sent with a review. */
|
|
97
|
+
export interface PullRequestDraftComment {
|
|
98
|
+
path: string;
|
|
99
|
+
line: number;
|
|
100
|
+
side: PullRequestDiffSide;
|
|
101
|
+
startLine?: number;
|
|
102
|
+
body: string;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Posts a review with its line comments. With no review pending on GitHub it is one call that creates
|
|
106
|
+
* and submits it at `commitOid` (the head the person read), so nothing is left half-posted. A review the
|
|
107
|
+
* person started on github.com is used instead: the comments join it and it is submitted.
|
|
108
|
+
*/
|
|
109
|
+
export declare function submitReview(gh: GhRunner, state: Pick<PullRequestReviewContext, 'pullRequestId' | 'pendingReview'>, review: {
|
|
110
|
+
event: PullRequestReviewEvent;
|
|
111
|
+
body?: string;
|
|
112
|
+
comments: readonly PullRequestDraftComment[];
|
|
113
|
+
commitOid?: string;
|
|
114
|
+
}): Promise<{
|
|
115
|
+
url?: string;
|
|
116
|
+
}>;
|
|
117
|
+
/** The GitHub Actions workflow runs behind the failed checks, in the PR's own repository; other checks cannot be re-run from here. */
|
|
118
|
+
export declare function failedRunIds(checks: readonly Pick<PullRequestCheck, 'state' | 'url'>[], pullRequest: Pick<SessionPullRequest, 'owner' | 'repo'>): string[];
|
|
119
|
+
export declare function rerunFailedJobs(gh: GhRunner, pullRequest: Pick<SessionPullRequest, 'owner' | 'repo'>, runId: string): Promise<void>;
|
|
120
|
+
/** Asks `add` (people) and `addTeams` (team slugs) to review and withdraws the requests of `remove` (users, or teams by slug). */
|
|
121
|
+
export declare function changeReviewers(gh: GhRunner, pullRequest: Pick<SessionPullRequest, 'owner' | 'repo' | 'number'>, change: {
|
|
122
|
+
add: readonly string[];
|
|
123
|
+
addTeams?: readonly string[];
|
|
124
|
+
remove: readonly PullRequestReviewer[];
|
|
125
|
+
}): Promise<void>;
|
|
126
|
+
/** GitHub's limit on a comment's body. */
|
|
127
|
+
export declare const COMMENT_BODY_LIMIT = 65536;
|
|
128
|
+
export declare function commentBody(value: unknown, name: string, required: boolean): string | undefined;
|
|
129
|
+
export declare function githubLogin(value: unknown, name: string): string;
|
|
130
|
+
export declare function nodeId(value: unknown, name: string): string;
|
|
131
|
+
export declare function reviewPath(value: unknown, name?: string): string;
|
|
132
|
+
export declare function reviewEvent(value: unknown): PullRequestReviewEvent;
|
|
133
|
+
export declare function draftComments(value: unknown): PullRequestDraftComment[];
|
|
134
|
+
export declare function reviewerLogins(value: unknown, name: string): string[];
|
|
135
|
+
export declare function reviewerEntries(value: unknown, name: string): PullRequestReviewer[];
|
|
136
|
+
export declare function teamSlugs(value: unknown, name: string): string[];
|
|
137
|
+
export declare function runIds(value: unknown): string[];
|