ensemble-review 1.0.35 → 1.0.37
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/api/plugins/rate-limit.js +22 -0
- package/dist/api/routes/releases.js +181 -0
- package/dist/app.js +3 -0
- package/dist/coding/story-build/base-refs.js +10 -2
- package/dist/coding/story-build/loop/driver.js +1 -1
- package/dist/coding/story-build/loop/routes.js +9 -1
- package/dist/coding/story-build/persist.js +53 -7
- package/dist/coding/story-build/plan-persist.js +1 -1
- package/dist/coding/story-build/push-hotfix.js +293 -0
- package/dist/coding/story-build/push.js +5 -0
- package/dist/coding/story-build/routes-build.js +25 -3
- package/dist/db/erase-account.js +14 -0
- package/dist/db/hotfix-bases.js +31 -0
- package/dist/db/migrations/0195_releases.sql +128 -0
- package/dist/db/migrations/0196_story_build_hotfix.sql +54 -0
- package/dist/db/migrations/0197_release_items_live_tag.sql +11 -0
- package/dist/db/migrations/0198_story_build_port_report.sql +7 -0
- package/dist/db/migrations/meta/_journal.json +28 -0
- package/dist/db/queries.js +21 -0
- package/dist/db/release-check.js +378 -0
- package/dist/db/release-settings.js +94 -0
- package/dist/db/repo-tags.js +82 -0
- package/dist/db/schema.sqlite.js +246 -0
- package/dist/github/mutations.js +67 -0
- package/dist/github/queries.js +5 -0
- package/dist/github/settle-query.js +11 -1
- package/dist/github/tag-queries.js +101 -0
- package/dist/releases/create.js +539 -0
- package/dist/releases/github.js +78 -0
- package/dist/releases/notes.js +152 -0
- package/dist/releases/refresh.js +43 -0
- package/dist/sandbox/session/manager.js +207 -12
- package/dist/sandbox/session/plan.js +19 -7
- package/dist/sandbox/session/routes.js +12 -2
- package/dist/sandbox/workspace/hotfix.js +30 -0
- package/dist/sandbox/workspace/index.js +38 -2
- package/dist/sandbox/workspace/port-report.js +137 -0
- package/dist/sandbox/workspace/seed.js +40 -0
- package/dist/shared/hotfix.js +165 -0
- package/dist/shared/index.js +4 -0
- package/dist/shared/release-check.js +528 -0
- package/dist/shared/release-write.js +264 -0
- package/dist/shared/releases.js +89 -0
- package/dist/shared/story-build.js +2 -0
- package/dist/sync/repo-tags.js +368 -0
- package/dist/sync/settle-sweep.js +47 -2
- package/dist/sync/sync-repo.js +12 -0
- package/dist/sync/tag-ranges.js +350 -0
- package/dist/sync/tags-step.js +77 -0
- package/dist/sync/upsert.js +23 -0
- package/package.json +5 -2
- package/public/assets/{AiFixTab-CVIZl9I8.js → AiFixTab-BC3tDZ3z.js} +1 -1
- package/public/assets/{PrBotBehaviourTab-q0M7RU1e.js → PrBotBehaviourTab-C5j5uhLn.js} +1 -1
- package/public/assets/index-BrjUDY3j.js +138 -0
- package/public/assets/index-D1zhsqSF.css +1 -0
- package/public/index.html +2 -2
- package/dist/ai/check-tool.js +0 -6
- package/dist/api/routes/auth.js +0 -194
- package/dist/api/routes/billing.js +0 -209
- package/dist/api/routes/claude-review.js +0 -522
- package/dist/api/routes/contact.js +0 -318
- package/dist/api/routes/feed.js +0 -21
- package/dist/api/routes/inbox.js +0 -45
- package/dist/api/routes/mentions.js +0 -22
- package/dist/api/routes/teams.js +0 -150
- package/dist/api/routes/webhooks.js +0 -181
- package/dist/coding/activity.js +0 -80
- package/dist/coding/agent.js +0 -147
- package/dist/coding/ai-fix/checks-preview.js +0 -58
- package/dist/coding/ai-fix/comment-seed.js +0 -519
- package/dist/coding/ai-fix/prompts.js +0 -283
- package/dist/coding/ai-resolve/prompt.js +0 -161
- package/dist/coding/ai-resolve/routes.js +0 -97
- package/dist/coding/ai-resolve/run.js +0 -343
- package/dist/coding/ai-resolve/schema.js +0 -26
- package/dist/coding/ai-resolve/validate.js +0 -136
- package/dist/coding/checks/deny-scan.js +0 -75
- package/dist/coding/checks/discover.js +0 -541
- package/dist/coding/checks/docker.js +0 -38
- package/dist/coding/checks/env.js +0 -88
- package/dist/coding/checks/hooks.js +0 -91
- package/dist/coding/checks/index.js +0 -8
- package/dist/coding/checks/local.js +0 -40
- package/dist/coding/checks/sandbox.js +0 -206
- package/dist/coding/checks/session.js +0 -518
- package/dist/coding/checks/spawn.js +0 -123
- package/dist/coding/checks/spec.js +0 -140
- package/dist/coding/checks/types.js +0 -6
- package/dist/coding/partial-spend.js +0 -19
- package/dist/coding/safe-path.js +0 -75
- package/dist/coding/story-build/build-prompts.js +0 -178
- package/dist/coding/story-build/build.js +0 -332
- package/dist/coding/story-build/checkouts.js +0 -66
- package/dist/coding/story-build/docs-runner.js +0 -178
- package/dist/coding/story-build/docs.js +0 -334
- package/dist/coding/story-build/manager.js +0 -999
- package/dist/coding/story-build/plan-agent.js +0 -190
- package/dist/coding/story-build/plan.js +0 -338
- package/dist/coding/story-build/prompts.js +0 -147
- package/dist/coding/story-build/routes-docs.js +0 -113
- package/dist/coding/story-build/routes.js +0 -295
- package/dist/coding/story-build/schema.js +0 -53
- package/dist/db/automation-output.js +0 -349
- package/dist/db/credits.js +0 -79
- package/dist/db/schema.js +0 -321
- package/dist/db/schema.pg.js +0 -2197
- package/dist/db/sprint-repo-suggest.js +0 -257
- package/dist/db/sprint-stories.js +0 -42
- package/dist/db/sprint-story.js +0 -505
- package/dist/db/sprint-ticket-repos.js +0 -195
- package/dist/db/story-selection.js +0 -270
- package/dist/db/team-comparison.js +0 -124
- package/dist/db/workspace-comparison.js +0 -98
- package/dist/feed/fyi-provider.js +0 -10
- package/dist/github/local-user.js +0 -92
- package/dist/github/repo-files.js +0 -26
- package/dist/ml/worker.js +0 -31
- package/dist/platform/advisor/discovery/tier2.js +0 -88
- package/dist/platform/advisor/discovery/tier3.js +0 -57
- package/dist/platform/advisor/emitters/adapter.js +0 -5
- package/dist/platform/advisor/emitters/coderabbit.js +0 -175
- package/dist/platform/advisor/emitters/copilot-prose.js +0 -118
- package/dist/platform/advisor/emitters/greptile.js +0 -176
- package/dist/platform/advisor/emitters/lint.js +0 -37
- package/dist/platform/advisor/emitters/manifest.js +0 -239
- package/dist/platform/advisor/emitters/prose.js +0 -183
- package/dist/platform/advisor/emitters/registry.js +0 -20
- package/dist/platform/advisor/emitters/yaml-doc.js +0 -95
- package/dist/platform/advisor/evidence.js +0 -79
- package/dist/platform/advisor/findings.js +0 -15
- package/dist/platform/advisor/intents.js +0 -269
- package/dist/platform/advisor/measure/effect.js +0 -18
- package/dist/platform/advisor/outputs/brief.js +0 -68
- package/dist/platform/advisor/outputs/config-pr.js +0 -156
- package/dist/platform/advisor/refine/diff-guard.js +0 -38
- package/dist/platform/advisor/refine/refine.js +0 -35
- package/dist/platform/advisor/retro-check.js +0 -98
- package/dist/platform/advisor/routes.js +0 -648
- package/dist/platform/advisor/store.js +0 -321
- package/dist/platform/advisor/taxonomy.js +0 -67
- package/dist/platform/annotations/prompts.js +0 -84
- package/dist/platform/annotations/routes.js +0 -86
- package/dist/platform/annotations/runner.js +0 -234
- package/dist/platform/annotations/targets.js +0 -203
- package/dist/platform/insights/grounded-figures.js +0 -162
- package/dist/platform/insights/period-questions.js +0 -235
- package/dist/platform/work-plan/hash.js +0 -99
- package/dist/platform/work-plan/prompt.js +0 -209
- package/dist/platform/work-plan/routes.js +0 -350
- package/dist/pro/bind.js +0 -309
- package/dist/pro/contract.js +0 -36
- package/dist/pro/event-hooks.js +0 -37
- package/dist/pro/migrate.js +0 -64
- package/dist/review/events.js +0 -24
- package/dist/review/local-settings.js +0 -78
- package/dist/review/memory/capture.js +0 -0
- package/dist/review/memory/retrieval.js +0 -272
- package/dist/review/memory/routes.js +0 -78
- package/dist/review/persist.js +0 -203
- package/dist/review/plugin-providers.js +0 -12
- package/dist/review/prompt.js +0 -264
- package/dist/review/review-manager.js +0 -259
- package/dist/review/routing.js +0 -164
- package/dist/review/sprint-assess/agent.js +0 -145
- package/dist/review/sprint-assess/manager.js +0 -382
- package/dist/review/sprint-assess/prompts.js +0 -99
- package/dist/review/sprint-assess/routes.js +0 -109
- package/dist/review/sprint-assess/schema.js +0 -70
- package/dist/review/sprint-assess/validate.js +0 -180
- package/dist/review/sprint-story/manager.js +0 -98
- package/dist/review/sprint-story/prompt.js +0 -45
- package/dist/review/sprint-story/validate.js +0 -127
- package/dist/review/story-docs/build-prompts.js +0 -153
- package/dist/review/story-docs/build-validate.js +0 -162
- package/dist/review/story-report/agent.js +0 -203
- package/dist/review/story-report/fingerprint.js +0 -45
- package/dist/review/story-report/manager.js +0 -287
- package/dist/review/story-report/routes.js +0 -154
- package/dist/review/story-report/story-detail.js +0 -148
- package/dist/review/story-report/validate.js +0 -105
- package/dist/review/ticket-review/sweep-waits.js +0 -20
- package/dist/review/write-deny.js +0 -170
- package/dist/shared/conflict-ai.js +0 -24
- package/dist/sync/benchmark-rollup.js +0 -50
- package/public/assets/index-CbEfmqOD.css +0 -1
- package/public/assets/index-DBK4RWQu.js +0 -136
|
@@ -0,0 +1,539 @@
|
|
|
1
|
+
// CREATING A RELEASE (docs/RELEASES.md § Releases tab 5–7). Two entry points:
|
|
2
|
+
//
|
|
3
|
+
// previewRelease POST /api/releases/preview — the dialog: the snapshot Confirm sends back, the notes
|
|
4
|
+
// (code-built; a model summary per story when AI is on), the comment preview and the
|
|
5
|
+
// selection problems. Reads the DB (and the model); never GitHub or the tracker.
|
|
6
|
+
// createRelease POST /api/releases — Confirm. FIRST re-reads every ticket in the release from the
|
|
7
|
+
// tracker (the reader's press: the documented exception to "read when RECEIVED, never
|
|
8
|
+
// when VIEWED", docs/TRACKERS.md § Releases) and re-checks each version tag's commit on
|
|
9
|
+
// GitHub; ANY change stops it and returns the changes — NOTHING is written. Then, in
|
|
10
|
+
// order:
|
|
11
|
+
// 1. an annotated release tag per repo (a name that exists is REFUSED, never moved);
|
|
12
|
+
// 2. a GitHub pre-release on each tag that landed, carrying that repo's notes;
|
|
13
|
+
// 3. a tracker comment per shipped ticket whose repos ALL tagged in this release
|
|
14
|
+
// (Jira; other trackers: "not supported yet", recorded per ticket);
|
|
15
|
+
// 4. settle-and-verify: the tags step re-reads each tagged repo's tags.
|
|
16
|
+
//
|
|
17
|
+
// ⚠ CLAIM BEFORE WRITE, NEVER RETRIED: every write's row is moved 'pending' → 'claimed' by
|
|
18
|
+
// compare-and-set BEFORE the network call, and its outcome recorded; a failure stays failed. The
|
|
19
|
+
// PARTIAL UNIQUE (account, repo, release_tag_name) index on release_items' LIVE rows (pending /
|
|
20
|
+
// claimed / done, migration 0197) makes a second press for the same tag a no-op (the claim is the
|
|
21
|
+
// row), and a ticket is commented on only when its repos tagged in THIS release — so pressing again
|
|
22
|
+
// writes nothing new. A FAILED or REFUSED row holds no name: a later press (a reader's press, never an
|
|
23
|
+
// automatic retry) is a new claim on a new row. A press where no repo gets a row records no release.
|
|
24
|
+
// ⚠ The check is folded over the WHOLE workspace, the selection applied after (`releasable`,
|
|
25
|
+
// `releaseShippedTickets`, `releaseSelectionProblems`) — a ticket's other repos must be seen.
|
|
26
|
+
// ⚠ One failure never undoes the steps that worked.
|
|
27
|
+
// ⚠ No transaction spans a network call: `runTransaction` only for the rows written before the writes.
|
|
28
|
+
import { and, asc, eq, inArray } from 'drizzle-orm';
|
|
29
|
+
import { RELEASE_NOTES_SECTION_MAX, foldReleaseCheck, parseTicketIdent, releaseCommentLines, releaseCommentWiki, releaseFinalState, releaseNotesDocument, releaseNotesInputOf, releaseNotesSection, releaseSelectionProblems, releaseSettingsConfigured, releaseShippedTickets, releaseSnapshotChanges, releaseSnapshotOf, releaseStepLines, releaseTagMessage, } from '../shared/index.js';
|
|
30
|
+
import { db, runTransaction, schema } from '../db/client.js';
|
|
31
|
+
import { resolveWorkspaceScope } from '../db/queries.js';
|
|
32
|
+
import { loadReleaseCheckInput } from '../db/release-check.js';
|
|
33
|
+
import { getReleaseSettings } from '../db/release-settings.js';
|
|
34
|
+
import { storySummaries, storySummaryInputs, summariesAvailable } from './notes.js';
|
|
35
|
+
const { releases, releaseItems, releaseTicketComments, repos, repoTags, accounts } = schema;
|
|
36
|
+
/** A refusal before anything is read or written (400 / 404). */
|
|
37
|
+
export class ReleaseRequestError extends Error {
|
|
38
|
+
status;
|
|
39
|
+
code;
|
|
40
|
+
constructor(status, code, message) {
|
|
41
|
+
super(message);
|
|
42
|
+
this.status = status;
|
|
43
|
+
this.code = code;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const splitFullName = (fullName) => {
|
|
47
|
+
const i = fullName.indexOf('/');
|
|
48
|
+
return { owner: fullName.slice(0, i), name: fullName.slice(i + 1) };
|
|
49
|
+
};
|
|
50
|
+
export async function defaultCheck(accountId, workspaceId, repoIds, settings) {
|
|
51
|
+
const input = await loadReleaseCheckInput(accountId, workspaceId, repoIds, settings);
|
|
52
|
+
return {
|
|
53
|
+
result: foldReleaseCheck(input),
|
|
54
|
+
repoNames: new Map(input.repos.map((r) => [r.repoId, splitFullName(r.fullName)])),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
export function defaultReleaseWriteDeps() {
|
|
58
|
+
return {
|
|
59
|
+
now: () => new Date(),
|
|
60
|
+
check: defaultCheck,
|
|
61
|
+
async rereadTicket(accountId, a) {
|
|
62
|
+
const prId = a.prIds[0];
|
|
63
|
+
if (prId == null)
|
|
64
|
+
return false;
|
|
65
|
+
// LAZY: tracker/runtime.ts opens the database at import.
|
|
66
|
+
const [{ trackerContext }, { syncOnePrNow }] = await Promise.all([import('../tracker/runtime.js'), import('../tracker/worker.js')]);
|
|
67
|
+
try {
|
|
68
|
+
const stats = await syncOnePrNow(trackerContext(), accountId, prId, [a.key], { force: true });
|
|
69
|
+
return stats.fetched > 0 && stats.failed === 0;
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
async github(accountId) {
|
|
76
|
+
const [{ getAccessToken }, { releaseGithubFor }] = await Promise.all([import('../auth/account.js'), import('./github.js')]);
|
|
77
|
+
return releaseGithubFor(await getAccessToken(accountId));
|
|
78
|
+
},
|
|
79
|
+
async postComment(accountId, a) {
|
|
80
|
+
const [{ trackerContext }, { postTicketComment }] = await Promise.all([
|
|
81
|
+
import('../tracker/runtime.js'),
|
|
82
|
+
import('../tracker/ticket-update.js'),
|
|
83
|
+
]);
|
|
84
|
+
const out = await postTicketComment(trackerContext(), { accountId, ...a });
|
|
85
|
+
return out.ok ? { ok: true } : { ok: false, message: out.message };
|
|
86
|
+
},
|
|
87
|
+
async settleTags(accountId, repo) {
|
|
88
|
+
try {
|
|
89
|
+
const [{ getAccessToken }, { runTagsStep }] = await Promise.all([import('../auth/account.js'), import('../sync/tags-step.js')]);
|
|
90
|
+
await runTagsStep({ ...repo, accountId, token: await getAccessToken(accountId) });
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
// Non-fatal: the settle sweep finds the tag push later.
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
async approverName(accountId) {
|
|
97
|
+
const row = (await db.select({ displayName: accounts.displayName, login: accounts.githubLogin }).from(accounts).where(eq(accounts.id, accountId)).execute())[0];
|
|
98
|
+
return row?.displayName?.trim() || row?.login || 'the release manager';
|
|
99
|
+
},
|
|
100
|
+
summariesAvailable,
|
|
101
|
+
async trackerSite(accountId, workspaceId) {
|
|
102
|
+
const { workspaceSite } = await import('../db/stories.js');
|
|
103
|
+
return workspaceSite(accountId, workspaceId);
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
async function scoped(accountId, rawWorkspace, repoIds) {
|
|
108
|
+
const scope = await resolveWorkspaceScope(accountId, rawWorkspace);
|
|
109
|
+
const settings = (await getReleaseSettings(accountId, scope.workspaceId)) ?? { releaseSuffix: null, hotfixSuffix: null };
|
|
110
|
+
if (!releaseSettingsConfigured(settings)) {
|
|
111
|
+
throw new ReleaseRequestError(400, 'ReleasesNotSet', 'Set the release suffix and the hotfix suffix first.');
|
|
112
|
+
}
|
|
113
|
+
const members = new Set(scope.repoIds);
|
|
114
|
+
const included = [...new Set(repoIds)].filter((id) => members.has(id));
|
|
115
|
+
if (included.length === 0)
|
|
116
|
+
throw new ReleaseRequestError(400, 'NothingToRelease', 'Choose at least one repository to release.');
|
|
117
|
+
return { workspaceId: scope.workspaceId, settings, included, all: [...scope.repoIds] };
|
|
118
|
+
}
|
|
119
|
+
/** The repos of the selection that can be released: a candidate and write access. */
|
|
120
|
+
function releasable(result, included) {
|
|
121
|
+
const inc = new Set(included);
|
|
122
|
+
return result.repos.filter((r) => inc.has(r.repoId) && r.candidate != null && r.writable).map((r) => r.repoId);
|
|
123
|
+
}
|
|
124
|
+
// ── Preview ─────────────────────────────────────────────────────────────────────────────────────
|
|
125
|
+
export async function previewRelease(accountId, rawWorkspace, body, deps = defaultReleaseWriteDeps()) {
|
|
126
|
+
const s = await scoped(accountId, rawWorkspace, body.repoIds);
|
|
127
|
+
const { result } = await deps.check(accountId, s.workspaceId, s.all, s.settings);
|
|
128
|
+
const included = releasable(result, s.included);
|
|
129
|
+
const shipped = releaseShippedTickets(result, included);
|
|
130
|
+
const ai = shipped.length > 0 && (await deps.summariesAvailable());
|
|
131
|
+
let summaries = new Map();
|
|
132
|
+
if (ai) {
|
|
133
|
+
const prsByIdent = new Map();
|
|
134
|
+
for (const r of releaseNotesInputOf(result, included))
|
|
135
|
+
for (const st of r.stories)
|
|
136
|
+
prsByIdent.set(st.ident, st.prs.map((p) => p.id));
|
|
137
|
+
const inputs = await storySummaryInputs(accountId, shipped.map((t) => ({ ident: t.ident, key: t.key, title: t.title, prIds: prsByIdent.get(t.ident) ?? [] })), await deps.trackerSite(accountId, s.workspaceId));
|
|
138
|
+
summaries = await storySummaries(accountId, inputs, deps.summarise ? { summarise: deps.summarise } : {});
|
|
139
|
+
}
|
|
140
|
+
const facts = releaseNotesInputOf(result, included, summaries);
|
|
141
|
+
const sections = facts.map((r) => ({ repoId: r.repoId, repoName: r.repoName, releaseTagName: r.releaseTagName, markdown: releaseNotesSection(r) }));
|
|
142
|
+
const first = shipped[0];
|
|
143
|
+
let commentPreview = null;
|
|
144
|
+
if (first != null) {
|
|
145
|
+
const tags = facts
|
|
146
|
+
.filter((r) => first.repos.some((x) => x.repoId === r.repoId && x.state === 'in_candidate'))
|
|
147
|
+
.map((r) => ({ repoName: r.repoName, releaseTagName: r.releaseTagName }));
|
|
148
|
+
const lines = releaseCommentLines({ approverName: await deps.approverName(accountId), at: deps.now(), tags, notesUrl: null });
|
|
149
|
+
commentPreview = [...lines, 'Release notes: (the link to the GitHub pre-release)'].join('\n');
|
|
150
|
+
}
|
|
151
|
+
const written = [...summaries.values()].filter((v) => v != null).length;
|
|
152
|
+
return {
|
|
153
|
+
workspaceId: s.workspaceId,
|
|
154
|
+
snapshot: releaseSnapshotOf(result, included),
|
|
155
|
+
sections,
|
|
156
|
+
notesMarkdown: releaseNotesDocument(sections.map((x) => x.markdown)),
|
|
157
|
+
commentPreview,
|
|
158
|
+
problems: releaseSelectionProblems(result, included),
|
|
159
|
+
summaries: { written, missing: shipped.length - written, ai },
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
// ── Create ──────────────────────────────────────────────────────────────────────────────────────
|
|
163
|
+
/** The repos and tickets the re-check must cover: the snapshot's plus what the check ships now. */
|
|
164
|
+
function ticketsToReread(result, included, snapshot) {
|
|
165
|
+
const byIdent = new Map(result.tickets.map((t) => [t.ident, t]));
|
|
166
|
+
const out = new Map();
|
|
167
|
+
const add = (ident, key) => {
|
|
168
|
+
if (out.has(ident))
|
|
169
|
+
return;
|
|
170
|
+
const t = byIdent.get(ident);
|
|
171
|
+
const prIds = t == null ? [] : [...new Set(t.repos.flatMap((r) => r.prIds))];
|
|
172
|
+
if (prIds.length === 0) {
|
|
173
|
+
for (const p of result.prs)
|
|
174
|
+
if (p.ticketIdents.includes(ident))
|
|
175
|
+
prIds.push(p.id);
|
|
176
|
+
}
|
|
177
|
+
out.set(ident, { ident, key: t?.key ?? key, prIds });
|
|
178
|
+
};
|
|
179
|
+
for (const t of snapshot.tickets)
|
|
180
|
+
add(t.ident, t.key);
|
|
181
|
+
for (const t of releaseShippedTickets(result, included))
|
|
182
|
+
add(t.ident, t.key);
|
|
183
|
+
return [...out.values()];
|
|
184
|
+
}
|
|
185
|
+
async function pool(items, n, fn) {
|
|
186
|
+
let next = 0;
|
|
187
|
+
await Promise.all(Array.from({ length: Math.min(n, items.length) }, async () => {
|
|
188
|
+
while (next < items.length)
|
|
189
|
+
await fn(items[next++]);
|
|
190
|
+
}));
|
|
191
|
+
}
|
|
192
|
+
const TRACKER_WORDS = { github: 'GitHub Issues', linear: 'Linear', notion: 'Notion' };
|
|
193
|
+
export async function createRelease(accountId, rawWorkspace, body, deps = defaultReleaseWriteDeps()) {
|
|
194
|
+
const s = await scoped(accountId, rawWorkspace, body.repoIds);
|
|
195
|
+
const snapshot = body.snapshot;
|
|
196
|
+
// ── 1. The re-check: tickets from the tracker, then the fold, then each version tag on GitHub ──
|
|
197
|
+
const before = await deps.check(accountId, s.workspaceId, s.all, s.settings);
|
|
198
|
+
const toRead = ticketsToReread(before.result, s.included, snapshot);
|
|
199
|
+
const unread = [];
|
|
200
|
+
await pool(toRead, 4, async (t) => {
|
|
201
|
+
if (!(await deps.rereadTicket(accountId, t)))
|
|
202
|
+
unread.push({ ident: t.ident, key: t.key });
|
|
203
|
+
});
|
|
204
|
+
const after = await deps.check(accountId, s.workspaceId, s.all, s.settings);
|
|
205
|
+
const included = releasable(after.result, s.included);
|
|
206
|
+
const gh = await deps.github(accountId);
|
|
207
|
+
const liveShaChanged = [];
|
|
208
|
+
const extraChanges = [];
|
|
209
|
+
const existsLive = new Set();
|
|
210
|
+
const nameOf = (id) => after.result.repos.find((r) => r.repoId === id)?.name ?? after.repoNames.get(id)?.name ?? 'a repository';
|
|
211
|
+
for (const r of snapshot.repos) {
|
|
212
|
+
const names = after.repoNames.get(r.repoId);
|
|
213
|
+
if (names == null)
|
|
214
|
+
continue;
|
|
215
|
+
try {
|
|
216
|
+
const live = await gh.readTagSha(names.owner, names.name, r.tagName);
|
|
217
|
+
if (live !== r.sha)
|
|
218
|
+
liveShaChanged.push({ repoId: r.repoId, tagName: r.tagName });
|
|
219
|
+
}
|
|
220
|
+
catch {
|
|
221
|
+
extraChanges.push(`${r.tagName} in ${nameOf(r.repoId)} could not be checked on GitHub.`);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
const snapRepoIds = new Set(snapshot.repos.map((r) => r.repoId));
|
|
225
|
+
for (const id of included)
|
|
226
|
+
if (!snapRepoIds.has(id))
|
|
227
|
+
extraChanges.push(`${nameOf(id)} now has a version tag to release.`);
|
|
228
|
+
for (const p of releaseSelectionProblems(after.result, included)) {
|
|
229
|
+
extraChanges.push(`${p.key} also needs ${p.missingRepoIds.map(nameOf).join(' and ')}.`);
|
|
230
|
+
}
|
|
231
|
+
const changes = [
|
|
232
|
+
...releaseSnapshotChanges({ repos: snapshot.repos.filter((r) => s.included.includes(r.repoId)), tickets: snapshot.tickets }, after.result, { liveShaChanged, unread }),
|
|
233
|
+
...extraChanges,
|
|
234
|
+
];
|
|
235
|
+
if (changes.length > 0)
|
|
236
|
+
return { workspaceId: s.workspaceId, outcome: 'stopped', changes, release: null };
|
|
237
|
+
if (included.length === 0)
|
|
238
|
+
throw new ReleaseRequestError(400, 'NothingToRelease', 'There is no version tag to release.');
|
|
239
|
+
// The release tag names that exist on GitHub already: refused for that repo, the others go ahead.
|
|
240
|
+
const repoChecks = after.result.repos.filter((r) => included.includes(r.repoId));
|
|
241
|
+
for (const r of repoChecks) {
|
|
242
|
+
const names = after.repoNames.get(r.repoId);
|
|
243
|
+
try {
|
|
244
|
+
if ((await gh.readTagSha(names.owner, names.name, r.candidate.releaseTagName)) != null)
|
|
245
|
+
existsLive.add(r.repoId);
|
|
246
|
+
}
|
|
247
|
+
catch {
|
|
248
|
+
// Unknown: the ref write answers it (a 422 for a name that exists).
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
// ── 2. The rows, then the writes ──
|
|
252
|
+
const now = deps.now();
|
|
253
|
+
const edited = new Map((body.sections ?? []).map((x) => [x.repoId, x.markdown.slice(0, RELEASE_NOTES_SECTION_MAX)]));
|
|
254
|
+
const facts = releaseNotesInputOf(after.result, included);
|
|
255
|
+
const sectionOf = new Map(facts.map((f) => [f.repoId, edited.get(f.repoId) ?? releaseNotesSection(f)]));
|
|
256
|
+
const login = (await db.select({ login: accounts.githubLogin }).from(accounts).where(eq(accounts.id, accountId)).execute())[0]?.login ?? null;
|
|
257
|
+
const earlier = [];
|
|
258
|
+
const ITEM_WORDS = {
|
|
259
|
+
done: 'was already made by an earlier release',
|
|
260
|
+
claimed: 'is being made by an earlier release, or that release stopped part way (check GitHub)',
|
|
261
|
+
pending: 'is being made by an earlier release',
|
|
262
|
+
};
|
|
263
|
+
const releaseId = await runTransaction(async (tx) => {
|
|
264
|
+
const [rel] = await tx
|
|
265
|
+
.insert(releases)
|
|
266
|
+
.values({
|
|
267
|
+
accountId,
|
|
268
|
+
workspaceId: s.workspaceId,
|
|
269
|
+
createdByLogin: login,
|
|
270
|
+
createdAt: now,
|
|
271
|
+
releaseSuffix: s.settings.releaseSuffix,
|
|
272
|
+
notesMarkdown: releaseNotesDocument(repoChecks.map((r) => sectionOf.get(r.repoId) ?? '')),
|
|
273
|
+
state: 'writing',
|
|
274
|
+
})
|
|
275
|
+
.returning({ id: releases.id })
|
|
276
|
+
.execute();
|
|
277
|
+
let inserted = 0;
|
|
278
|
+
for (const r of repoChecks) {
|
|
279
|
+
// The tag name is in an EARLIER release's LIVE row (pending / claimed / done — the partial unique
|
|
280
|
+
// index, migration 0197): that press owns it (claimed, never retried) — nothing is recorded for
|
|
281
|
+
// it here. A failed or refused row holds no name, so a new press is a new claim on a new row.
|
|
282
|
+
const livePrior = async () => (await tx
|
|
283
|
+
.select({ tagState: releaseItems.tagState })
|
|
284
|
+
.from(releaseItems)
|
|
285
|
+
.where(and(eq(releaseItems.accountId, accountId), eq(releaseItems.repoId, r.repoId), eq(releaseItems.releaseTagName, r.candidate.releaseTagName), inArray(releaseItems.tagState, ['pending', 'claimed', 'done'])))
|
|
286
|
+
.limit(1)
|
|
287
|
+
.execute())[0]?.tagState ?? null;
|
|
288
|
+
const owned = (state) => {
|
|
289
|
+
const words = ITEM_WORDS[state ?? 'done'] ?? ITEM_WORDS.done;
|
|
290
|
+
earlier.push(`${r.name} ${r.candidate.releaseTagName} ${words}. Nothing was written for it.`);
|
|
291
|
+
};
|
|
292
|
+
const prior = await livePrior();
|
|
293
|
+
if (prior != null) {
|
|
294
|
+
owned(prior);
|
|
295
|
+
continue;
|
|
296
|
+
}
|
|
297
|
+
const got = await tx
|
|
298
|
+
.insert(releaseItems)
|
|
299
|
+
.values({
|
|
300
|
+
accountId,
|
|
301
|
+
releaseId: rel.id,
|
|
302
|
+
repoId: r.repoId,
|
|
303
|
+
versionTag: r.candidate.name,
|
|
304
|
+
sha: r.candidate.sha,
|
|
305
|
+
releaseTagName: r.candidate.releaseTagName,
|
|
306
|
+
notesMarkdown: sectionOf.get(r.repoId) ?? '',
|
|
307
|
+
tagState: existsLive.has(r.repoId) ? 'refused' : 'pending',
|
|
308
|
+
prereleaseState: existsLive.has(r.repoId) ? 'skipped' : 'pending',
|
|
309
|
+
error: existsLive.has(r.repoId) ? 'the tag already exists' : null,
|
|
310
|
+
updatedAt: now,
|
|
311
|
+
})
|
|
312
|
+
.onConflictDoNothing()
|
|
313
|
+
.returning({ id: releaseItems.id })
|
|
314
|
+
.execute();
|
|
315
|
+
if (got.length === 0)
|
|
316
|
+
owned(await livePrior());
|
|
317
|
+
else
|
|
318
|
+
inserted += 1;
|
|
319
|
+
}
|
|
320
|
+
// Nothing of this press holds a row: no release is recorded (it would become the tab's "latest").
|
|
321
|
+
if (inserted === 0) {
|
|
322
|
+
await tx.delete(releases).where(and(eq(releases.id, rel.id), eq(releases.accountId, accountId))).execute();
|
|
323
|
+
return null;
|
|
324
|
+
}
|
|
325
|
+
return rel.id;
|
|
326
|
+
});
|
|
327
|
+
if (releaseId == null)
|
|
328
|
+
return { workspaceId: s.workspaceId, outcome: 'stopped', changes: earlier, release: null };
|
|
329
|
+
const items = await db
|
|
330
|
+
.select()
|
|
331
|
+
.from(releaseItems)
|
|
332
|
+
.where(and(eq(releaseItems.accountId, accountId), eq(releaseItems.releaseId, releaseId)))
|
|
333
|
+
.execute();
|
|
334
|
+
/** Compare-and-set one column of one item. True = this call owns the write. */
|
|
335
|
+
const claimItem = async (id, col) => {
|
|
336
|
+
const set = col === 'tag' ? { tagState: 'claimed', updatedAt: deps.now() } : { prereleaseState: 'claimed', updatedAt: deps.now() };
|
|
337
|
+
const where = col === 'tag' ? eq(releaseItems.tagState, 'pending') : eq(releaseItems.prereleaseState, 'pending');
|
|
338
|
+
return (await db.update(releaseItems).set(set).where(and(eq(releaseItems.id, id), eq(releaseItems.accountId, accountId), where)).returning({ id: releaseItems.id }).execute()).length === 1;
|
|
339
|
+
};
|
|
340
|
+
// 2.1 The annotated release tags.
|
|
341
|
+
const tagged = new Set();
|
|
342
|
+
for (const it of items) {
|
|
343
|
+
if (it.tagState !== 'pending' || !(await claimItem(it.id, 'tag')))
|
|
344
|
+
continue;
|
|
345
|
+
const names = after.repoNames.get(it.repoId);
|
|
346
|
+
let out;
|
|
347
|
+
try {
|
|
348
|
+
out = await gh.createReleaseTag(names.owner, names.name, {
|
|
349
|
+
tag: it.releaseTagName,
|
|
350
|
+
sha: it.sha,
|
|
351
|
+
message: releaseTagMessage(names.name, it.releaseTagName, it.versionTag),
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
catch {
|
|
355
|
+
out = { ok: false, exists: false, message: 'GitHub could not be reached' };
|
|
356
|
+
}
|
|
357
|
+
if (out.ok)
|
|
358
|
+
tagged.add(it.repoId);
|
|
359
|
+
await db
|
|
360
|
+
.update(releaseItems)
|
|
361
|
+
.set(out.ok
|
|
362
|
+
? { tagState: 'done', tagObjectOid: out.tagObjectOid, updatedAt: deps.now() }
|
|
363
|
+
: { tagState: out.exists ? 'refused' : 'failed', error: out.message, updatedAt: deps.now() })
|
|
364
|
+
.where(and(eq(releaseItems.id, it.id), eq(releaseItems.accountId, accountId)))
|
|
365
|
+
.execute();
|
|
366
|
+
}
|
|
367
|
+
// 2.2 The pre-releases (only on a tag that landed in THIS release).
|
|
368
|
+
const releaseUrl = new Map();
|
|
369
|
+
for (const it of items) {
|
|
370
|
+
if (!tagged.has(it.repoId)) {
|
|
371
|
+
await db
|
|
372
|
+
.update(releaseItems)
|
|
373
|
+
.set({ prereleaseState: 'skipped', updatedAt: deps.now() })
|
|
374
|
+
.where(and(eq(releaseItems.id, it.id), eq(releaseItems.accountId, accountId), eq(releaseItems.prereleaseState, 'pending')))
|
|
375
|
+
.execute();
|
|
376
|
+
continue;
|
|
377
|
+
}
|
|
378
|
+
if (!(await claimItem(it.id, 'prerelease')))
|
|
379
|
+
continue;
|
|
380
|
+
const names = after.repoNames.get(it.repoId);
|
|
381
|
+
let out;
|
|
382
|
+
try {
|
|
383
|
+
out = await gh.createPrerelease(names.owner, names.name, {
|
|
384
|
+
tag: it.releaseTagName,
|
|
385
|
+
title: `${names.name} ${it.releaseTagName}`,
|
|
386
|
+
body: it.notesMarkdown,
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
catch {
|
|
390
|
+
out = { ok: false, message: 'GitHub could not be reached' };
|
|
391
|
+
}
|
|
392
|
+
if (out.ok)
|
|
393
|
+
releaseUrl.set(it.repoId, out.url);
|
|
394
|
+
await db
|
|
395
|
+
.update(releaseItems)
|
|
396
|
+
.set(out.ok
|
|
397
|
+
? { prereleaseState: 'done', githubReleaseId: out.id, githubReleaseUrl: out.url, updatedAt: deps.now() }
|
|
398
|
+
: { prereleaseState: 'failed', error: out.message, updatedAt: deps.now() })
|
|
399
|
+
.where(and(eq(releaseItems.id, it.id), eq(releaseItems.accountId, accountId)))
|
|
400
|
+
.execute();
|
|
401
|
+
}
|
|
402
|
+
// 2.3 The tracker comments: a shipped ticket whose repos ALL tagged in this release.
|
|
403
|
+
const shipped = releaseShippedTickets(after.result, included);
|
|
404
|
+
const approver = shipped.length > 0 ? await deps.approverName(accountId) : '';
|
|
405
|
+
const repoById = new Map(after.result.repos.map((r) => [r.repoId, r]));
|
|
406
|
+
for (const t of shipped) {
|
|
407
|
+
const its = t.repos
|
|
408
|
+
.filter((r) => r.state === 'in_candidate' && included.includes(r.repoId))
|
|
409
|
+
.sort((a, b) => (repoById.get(a.repoId)?.name ?? '').localeCompare(repoById.get(b.repoId)?.name ?? ''));
|
|
410
|
+
const provider = parseTicketIdent(t.ident)?.provider ?? (/^([a-z]+):/.exec(t.ident)?.[1] ?? null);
|
|
411
|
+
const [row] = await db
|
|
412
|
+
.insert(releaseTicketComments)
|
|
413
|
+
.values({ accountId, releaseId, ticketKey: t.key, trackerKind: provider, state: 'pending' })
|
|
414
|
+
.onConflictDoNothing()
|
|
415
|
+
.returning({ id: releaseTicketComments.id })
|
|
416
|
+
.execute();
|
|
417
|
+
if (row == null)
|
|
418
|
+
continue;
|
|
419
|
+
const settle = async (set, from) => (await db
|
|
420
|
+
.update(releaseTicketComments)
|
|
421
|
+
.set(set)
|
|
422
|
+
.where(and(eq(releaseTicketComments.id, row.id), eq(releaseTicketComments.accountId, accountId), eq(releaseTicketComments.state, from)))
|
|
423
|
+
.returning({ id: releaseTicketComments.id })
|
|
424
|
+
.execute()).length === 1;
|
|
425
|
+
const notTagged = its.filter((r) => !tagged.has(r.repoId)).map((r) => repoById.get(r.repoId)?.name ?? 'a repository');
|
|
426
|
+
if (notTagged.length > 0) {
|
|
427
|
+
await settle({ state: 'skipped', error: `${notTagged.join(' and ')} ${notTagged.length > 1 ? 'were' : 'was'} not tagged` }, 'pending');
|
|
428
|
+
continue;
|
|
429
|
+
}
|
|
430
|
+
if (provider !== 'jira') {
|
|
431
|
+
await settle({ state: 'skipped', error: `comments on ${TRACKER_WORDS[provider ?? ''] ?? 'this tracker'} are not supported yet` }, 'pending');
|
|
432
|
+
continue;
|
|
433
|
+
}
|
|
434
|
+
if (!(await settle({ state: 'claimed', claimedAt: deps.now() }, 'pending')))
|
|
435
|
+
continue;
|
|
436
|
+
const wiki = releaseCommentWiki({
|
|
437
|
+
approverName: approver,
|
|
438
|
+
at: now,
|
|
439
|
+
tags: its.map((r) => {
|
|
440
|
+
const rc = repoById.get(r.repoId);
|
|
441
|
+
return { repoName: rc.name, releaseTagName: rc.candidate.releaseTagName };
|
|
442
|
+
}),
|
|
443
|
+
notesUrl: its.map((r) => releaseUrl.get(r.repoId)).find((u) => u != null) ?? null,
|
|
444
|
+
});
|
|
445
|
+
let out;
|
|
446
|
+
try {
|
|
447
|
+
out = await deps.postComment(accountId, { workspaceId: s.workspaceId, ident: t.ident, wiki });
|
|
448
|
+
}
|
|
449
|
+
catch {
|
|
450
|
+
out = { ok: false, message: 'the tracker could not be reached' };
|
|
451
|
+
}
|
|
452
|
+
await settle(out.ok ? { state: 'posted', postedAt: deps.now() } : { state: 'failed', error: out.message }, 'claimed');
|
|
453
|
+
}
|
|
454
|
+
// ── 3. Settle and verify: re-read the tagged repos' tags (the new tags become the baseline) ──
|
|
455
|
+
const unverified = [];
|
|
456
|
+
await Promise.all([...tagged].map(async (repoId) => {
|
|
457
|
+
const names = after.repoNames.get(repoId);
|
|
458
|
+
await deps.settleTags(accountId, { repoId, ...names });
|
|
459
|
+
const it = items.find((i) => i.repoId === repoId);
|
|
460
|
+
if (!(await releaseTagStored(accountId, repoId, it.releaseTagName, it.sha))) {
|
|
461
|
+
unverified.push(`${names.name} ${it.releaseTagName} is on GitHub. It will show up here shortly.`);
|
|
462
|
+
}
|
|
463
|
+
}));
|
|
464
|
+
const detail = (await getReleaseDetail(accountId, releaseId));
|
|
465
|
+
const state = releaseFinalState(detail);
|
|
466
|
+
await db
|
|
467
|
+
.update(releases)
|
|
468
|
+
.set({ state, finishedAt: deps.now() })
|
|
469
|
+
.where(and(eq(releases.id, releaseId), eq(releases.accountId, accountId)))
|
|
470
|
+
.execute();
|
|
471
|
+
return {
|
|
472
|
+
workspaceId: s.workspaceId,
|
|
473
|
+
outcome: 'written',
|
|
474
|
+
changes: [],
|
|
475
|
+
release: { ...detail, state, steps: [...detail.steps, ...earlier.map((text) => ({ ok: false, text })), ...unverified.map((text) => ({ ok: true, text }))] },
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
/** GET /api/releases/:id — the stored release, this account only (null ⇒ 404). */
|
|
479
|
+
export async function getReleaseDetail(accountId, releaseId) {
|
|
480
|
+
const rel = (await db.select().from(releases).where(and(eq(releases.id, releaseId), eq(releases.accountId, accountId))).execute())[0];
|
|
481
|
+
if (rel == null)
|
|
482
|
+
return null;
|
|
483
|
+
const itemRows = await db
|
|
484
|
+
.select()
|
|
485
|
+
.from(releaseItems)
|
|
486
|
+
.where(and(eq(releaseItems.accountId, accountId), eq(releaseItems.releaseId, releaseId)))
|
|
487
|
+
.orderBy(asc(releaseItems.id))
|
|
488
|
+
.execute();
|
|
489
|
+
const repoRows = itemRows.length === 0
|
|
490
|
+
? []
|
|
491
|
+
: await db
|
|
492
|
+
.select({ id: repos.id, name: repos.name })
|
|
493
|
+
.from(repos)
|
|
494
|
+
.where(and(eq(repos.accountId, accountId), inArray(repos.id, itemRows.map((i) => i.repoId))))
|
|
495
|
+
.execute();
|
|
496
|
+
const nameOf = new Map(repoRows.map((r) => [r.id, r.name]));
|
|
497
|
+
const commentRows = await db
|
|
498
|
+
.select()
|
|
499
|
+
.from(releaseTicketComments)
|
|
500
|
+
.where(and(eq(releaseTicketComments.accountId, accountId), eq(releaseTicketComments.releaseId, releaseId)))
|
|
501
|
+
.orderBy(asc(releaseTicketComments.ticketKey))
|
|
502
|
+
.execute();
|
|
503
|
+
const items = itemRows
|
|
504
|
+
.map((i) => ({
|
|
505
|
+
repoId: i.repoId,
|
|
506
|
+
repoName: nameOf.get(i.repoId) ?? '',
|
|
507
|
+
versionTag: i.versionTag,
|
|
508
|
+
sha: i.sha,
|
|
509
|
+
releaseTagName: i.releaseTagName,
|
|
510
|
+
tagState: i.tagState,
|
|
511
|
+
prereleaseState: i.prereleaseState,
|
|
512
|
+
releaseUrl: i.githubReleaseUrl,
|
|
513
|
+
error: i.error,
|
|
514
|
+
}))
|
|
515
|
+
.sort((a, b) => a.repoName.localeCompare(b.repoName));
|
|
516
|
+
const comments = commentRows.map((c) => ({ ticketKey: c.ticketKey, state: c.state, error: c.error }));
|
|
517
|
+
return {
|
|
518
|
+
id: rel.id,
|
|
519
|
+
workspaceId: rel.workspaceId,
|
|
520
|
+
createdAt: rel.createdAt.toISOString(),
|
|
521
|
+
createdBy: rel.createdByLogin,
|
|
522
|
+
state: rel.state,
|
|
523
|
+
releaseSuffix: rel.releaseSuffix,
|
|
524
|
+
notesMarkdown: rel.notesMarkdown,
|
|
525
|
+
items,
|
|
526
|
+
comments,
|
|
527
|
+
steps: releaseStepLines({ items, comments }),
|
|
528
|
+
};
|
|
529
|
+
}
|
|
530
|
+
/** Verify after the settle: the release tag is stored at its commit. Used by the tests and the log. */
|
|
531
|
+
export async function releaseTagStored(accountId, repoId, name, sha) {
|
|
532
|
+
const row = (await db
|
|
533
|
+
.select({ sha: repoTags.sha })
|
|
534
|
+
.from(repoTags)
|
|
535
|
+
.where(and(eq(repoTags.accountId, accountId), eq(repoTags.repoId, repoId), eq(repoTags.name, name)))
|
|
536
|
+
.execute())[0];
|
|
537
|
+
return row?.sha === sha;
|
|
538
|
+
}
|
|
539
|
+
//# sourceMappingURL=create.js.map
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// THE RELEASE WRITES' GITHUB CALLS (docs/RELEASES.md § Releases tab 6). REST, under the READER'S
|
|
2
|
+
// token (auth/account.ts `getAccessToken`, through the per-account `ghRest*For` factories — no cached
|
|
3
|
+
// token). The caller (releases/create.ts) CLAIMS each write before calling and never retries.
|
|
4
|
+
//
|
|
5
|
+
// readTagSha GET git/ref/tags/<name> (EXACT: `ref`, never `matching-refs`), peeled through an
|
|
6
|
+
// annotated tag object → the commit sha, or null when the tag does not exist.
|
|
7
|
+
// createReleaseTag POST git/tags (the annotated tag object on the commit) then POST git/refs
|
|
8
|
+
// (`refs/tags/<name>`). A 422 on the ref = the name already exists → `exists`:
|
|
9
|
+
// REFUSED, never moved (there is no PATCH anywhere here).
|
|
10
|
+
// createPrerelease POST releases `{tag_name, name, body, prerelease: true}`.
|
|
11
|
+
// The two writes live in github/mutations.ts (`createAnnotatedReleaseTag`, `createGithubPrerelease`),
|
|
12
|
+
// through `limnWrite` with the 'reader' origin: the reader's press, under the reader's account.
|
|
13
|
+
import { ghRestGetFor } from '../github/client.js';
|
|
14
|
+
import { createAnnotatedReleaseTag, createGithubPrerelease } from '../github/mutations.js';
|
|
15
|
+
const statusOf = (err) => {
|
|
16
|
+
const s = err?.status;
|
|
17
|
+
return typeof s === 'number' ? s : null;
|
|
18
|
+
};
|
|
19
|
+
/** One short sentence for a GitHub refusal — never the response body. */
|
|
20
|
+
export function githubFailureWords(err) {
|
|
21
|
+
const s = statusOf(err);
|
|
22
|
+
if (s === 403 || s === 404)
|
|
23
|
+
return 'GitHub refused it (no write access)';
|
|
24
|
+
if (s === 422)
|
|
25
|
+
return 'GitHub refused it';
|
|
26
|
+
if (s === 429)
|
|
27
|
+
return 'GitHub rate limit';
|
|
28
|
+
if (s != null && s >= 500)
|
|
29
|
+
return 'GitHub did not answer';
|
|
30
|
+
return 'GitHub could not be reached';
|
|
31
|
+
}
|
|
32
|
+
const seg = (s) => encodeURIComponent(s);
|
|
33
|
+
const refPath = (tag) => tag.split('/').map(seg).join('/');
|
|
34
|
+
export function releaseGithubFor(token) {
|
|
35
|
+
return {
|
|
36
|
+
async readTagSha(owner, name, tag) {
|
|
37
|
+
let ref;
|
|
38
|
+
try {
|
|
39
|
+
ref = await ghRestGetFor(token, `/repos/${seg(owner)}/${seg(name)}/git/ref/tags/${refPath(tag)}`);
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
if (statusOf(err) === 404)
|
|
43
|
+
return null;
|
|
44
|
+
throw err;
|
|
45
|
+
}
|
|
46
|
+
let obj = ref.object;
|
|
47
|
+
// An annotated tag (possibly a tag of a tag): peel, at most a few levels.
|
|
48
|
+
for (let i = 0; i < 4 && obj?.type === 'tag' && obj.sha; i += 1) {
|
|
49
|
+
const t = await ghRestGetFor(token, `/repos/${seg(owner)}/${seg(name)}/git/tags/${seg(obj.sha)}`);
|
|
50
|
+
obj = t.object;
|
|
51
|
+
}
|
|
52
|
+
return obj?.type === 'commit' && typeof obj.sha === 'string' ? obj.sha : null;
|
|
53
|
+
},
|
|
54
|
+
async createReleaseTag(owner, name, a) {
|
|
55
|
+
try {
|
|
56
|
+
const out = await createAnnotatedReleaseTag(token, { owner, name, tag: a.tag, sha: a.sha, message: a.message }, 'reader');
|
|
57
|
+
return { ok: true, tagObjectOid: out.tagObjectOid };
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
// 422 on the REF ("Reference already exists"): the name is taken — refused, never moved.
|
|
61
|
+
const onRef = err?.stage === 'ref';
|
|
62
|
+
if (onRef && statusOf(err) === 422)
|
|
63
|
+
return { ok: false, exists: true, message: 'the tag already exists' };
|
|
64
|
+
return { ok: false, exists: false, message: githubFailureWords(err) };
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
async createPrerelease(owner, name, a) {
|
|
68
|
+
try {
|
|
69
|
+
const r = await createGithubPrerelease(token, { owner, name, tag: a.tag, title: a.title, body: a.body }, 'reader');
|
|
70
|
+
return { ok: true, id: r.id, url: r.url };
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
return { ok: false, message: githubFailureWords(err) };
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=github.js.map
|