@effected/github 0.30.0 → 0.31.0

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.
@@ -0,0 +1,358 @@
1
+ import { GitHubClient } from "./GitHubClient.js";
2
+ import { GitHubGraphQLError, GraphQLDocument } from "./GraphQL.js";
3
+ import { unstubbed } from "./internal/unstubbed.js";
4
+ import { Repo } from "./Repo.js";
5
+ import { Context, Effect, Exit, Layer, Option, Request, RequestResolver, Schema } from "effect";
6
+
7
+ // src/ChangelogInfo.ts
8
+ /**
9
+ * A changelog lookup was handed a commit sha or pull request number it cannot
10
+ * send.
11
+ *
12
+ * @remarks
13
+ * The batch names each lookup by an alias built from its input
14
+ * (`commit__<sha>`, `pull__<number>`), so the input must be something a
15
+ * GraphQL alias can carry: a hexadecimal sha of 4 to 64 characters, or a
16
+ * positive integer. Nothing is sent when this fails.
17
+ *
18
+ * @public
19
+ */
20
+ var InvalidChangelogRefError = class extends Schema.TaggedError()("InvalidChangelogRefError", {
21
+ /** Which lookup refused it. */
22
+ ref: Schema.Literals(["commit", "pull"]),
23
+ /** What was handed in, as text. */
24
+ input: Schema.String
25
+ }) {
26
+ get message() {
27
+ return this.ref === "commit" ? `not a hexadecimal commit sha of 4 to 64 characters: ${JSON.stringify(this.input)}` : `not a positive pull request number: ${this.input}`;
28
+ }
29
+ };
30
+ /**
31
+ * What a changelog line says about one commit.
32
+ *
33
+ * @remarks
34
+ * The shape `@changesets/get-github-info`'s `getInfo` returns, with every
35
+ * value that can be missing as an `Option`. The links are markdown, in
36
+ * upstream's exact format: the short sha in a code span linked to the commit
37
+ * URL, `[#42](https://github.com/acme/widget/pull/42)` and
38
+ * `[@octocat](https://github.com/octocat)`. Every URL is the one GitHub answered with, so on
39
+ * GitHub Enterprise Server the links name that server; nothing here builds a
40
+ * URL from a configured host.
41
+ *
42
+ * @public
43
+ */
44
+ var CommitChangelogInfo = class extends Schema.Class("CommitChangelogInfo")({
45
+ /**
46
+ * The login to credit: the pull request's author when the commit has one,
47
+ * otherwise the GitHub user the commit's author maps to.
48
+ */
49
+ user: Schema.Option(Schema.String),
50
+ /** The pull request the commit landed through: the earliest-merged one, else the first GitHub lists. */
51
+ pull: Schema.Option(Schema.Int),
52
+ /** Markdown links for the line. */
53
+ links: Schema.Struct({
54
+ /** The first 7 characters of the sha asked for, in a code span, linked to the commit URL. */
55
+ commit: Schema.String,
56
+ /** `#` and the number, linked to the pull request URL, when there is a pull request. */
57
+ pull: Schema.Option(Schema.String),
58
+ /** `@` and the login, linked to the user's URL, when there is a user. */
59
+ user: Schema.Option(Schema.String)
60
+ })
61
+ }) {};
62
+ /**
63
+ * What a changelog line says about one pull request.
64
+ *
65
+ * @remarks
66
+ * The shape `@changesets/get-github-info`'s `getInfoFromPullRequest` returns,
67
+ * for a changeset that names its pull request (`pr: #42`) instead of leaving
68
+ * it to the commit. Links are in the same format as
69
+ * {@link CommitChangelogInfo}'s, from the URLs GitHub answered with.
70
+ *
71
+ * @public
72
+ */
73
+ var PullRequestChangelogInfo = class extends Schema.Class("PullRequestChangelogInfo")({
74
+ /** The pull request author's login. */
75
+ user: Schema.Option(Schema.String),
76
+ /** The merge commit's abbreviated sha, once the pull request has merged. */
77
+ commit: Schema.Option(Schema.String),
78
+ /** Markdown links for the line. */
79
+ links: Schema.Struct({
80
+ /** The first 7 characters of the abbreviated merge sha, in a code span, linked to the commit URL, once merged. */
81
+ commit: Schema.Option(Schema.String),
82
+ /** `#` and the number, linked to the pull request URL. */
83
+ pull: Schema.String,
84
+ /** `@` and the login, linked to the user's URL, when the author still exists. */
85
+ user: Schema.Option(Schema.String)
86
+ })
87
+ }) {};
88
+ /**
89
+ * The commit and pull request facts a changelog line credits, batched into
90
+ * one GraphQL query.
91
+ *
92
+ * @remarks
93
+ * The kit's `@changesets/get-github-info`. The token and the server come from
94
+ * the `GitHubClient` the layer is built over, and the repository from `Repo`;
95
+ * nothing is read from the environment. The query is upstream's, alias for
96
+ * alias, so concurrent lookups cost one round trip per 50.
97
+ *
98
+ * Two answers differ from upstream's, both toward the lookup convention: a
99
+ * pull request number the repository does not have is `Option.none()` (GitHub
100
+ * reports it as an error, which upstream throws for the whole batch), and a
101
+ * sha naming a tree or blob is `Option.none()` (upstream builds links to
102
+ * `undefined`). A missing repository still fails, with `kind: "notFound"`.
103
+ *
104
+ * Batching happens within one built service: each `ChangelogInfo.layer`
105
+ * build owns its own resolver, and nothing is cached across batches.
106
+ *
107
+ * @example
108
+ * ```ts
109
+ * import { ChangelogInfo } from "@effected/github";
110
+ * import { Effect, Option } from "effect";
111
+ *
112
+ * const lines = (shas: ReadonlyArray<string>) =>
113
+ * Effect.gen(function* () {
114
+ * const info = yield* ChangelogInfo;
115
+ * const found = yield* Effect.forEach(shas, info.commit, { concurrency: "unbounded" });
116
+ * return found.flatMap((entry) =>
117
+ * Option.match(entry, {
118
+ * onNone: () => [],
119
+ * onSome: ({ links }) => [`${Option.getOrElse(links.pull, () => links.commit)} Thanks ${Option.getOrElse(links.user, () => "")}`],
120
+ * }),
121
+ * );
122
+ * });
123
+ * ```
124
+ *
125
+ * @public
126
+ */
127
+ var ChangelogInfo = class ChangelogInfo extends Context.Service()("@effected/github/ChangelogInfo") {
128
+ /** The live service, built over a `GitHubClient`. */
129
+ static layer = Layer.effect(this, Effect.map(GitHubClient, (client) => make(client)));
130
+ /** An in-memory double; an unstubbed member dies when run, naming itself. */
131
+ static makeTest = (overrides = {}) => ({
132
+ commit: overrides.commit ?? (() => dies("commit")),
133
+ pullRequest: overrides.pullRequest ?? (() => dies("pullRequest"))
134
+ });
135
+ /** {@link ChangelogInfo.makeTest} behind a `Layer`. */
136
+ static layerTest = (overrides = {}) => Layer.succeed(ChangelogInfo, ChangelogInfo.makeTest(overrides));
137
+ };
138
+ const dies = unstubbed("ChangelogInfo.makeTest");
139
+ /** Upstream's batch size (its dataloader's `maxBatchSize`). */
140
+ const BATCH_SIZE = 50;
141
+ /** The one repository alias a batch uses: a batch is always one repository. */
142
+ const REPO_ALIAS = "repo__0";
143
+ const SHA = /^[0-9a-f]{4,64}$/i;
144
+ const CommitLookup = Request.tagged("CommitLookup");
145
+ const PullLookup = Request.tagged("PullLookup");
146
+ const aliasOf = (lookup) => lookup._tag === "CommitLookup" ? `commit__${lookup.sha}` : `pull__${lookup.number}`;
147
+ const Actor = Schema.Struct({
148
+ login: Schema.String,
149
+ url: Schema.String
150
+ });
151
+ const AssociatedPull = Schema.Struct({
152
+ number: Schema.Int,
153
+ url: Schema.String,
154
+ mergedAt: Schema.NullOr(Schema.String),
155
+ author: Schema.NullOr(Actor)
156
+ });
157
+ const CommitNode = Schema.Struct({
158
+ commitUrl: Schema.String,
159
+ associatedPullRequests: Schema.NullOr(Schema.Struct({ nodes: Schema.NullOr(Schema.Array(Schema.NullOr(AssociatedPull))) })),
160
+ author: Schema.NullOr(Schema.Struct({ user: Schema.NullOr(Actor) }))
161
+ });
162
+ /** `object(expression:)` answers `{}` when the sha names a tree or blob: `... on Commit` selects nothing. */
163
+ const NotACommit = Schema.Record(Schema.String, Schema.Never);
164
+ const PullNode = Schema.Struct({
165
+ url: Schema.String,
166
+ author: Schema.NullOr(Actor),
167
+ mergeCommit: Schema.NullOr(Schema.Struct({
168
+ commitUrl: Schema.String,
169
+ abbreviatedOid: Schema.String
170
+ }))
171
+ });
172
+ const COMMIT_FRAGMENT = `\
173
+ fragment CommitFragment on Commit {
174
+ commitUrl
175
+ associatedPullRequests(first: 50) {
176
+ nodes {
177
+ number
178
+ url
179
+ mergedAt
180
+ author {
181
+ login
182
+ url
183
+ }
184
+ }
185
+ }
186
+ author {
187
+ user {
188
+ login
189
+ url
190
+ }
191
+ }
192
+ }
193
+ `;
194
+ const PULL_FRAGMENT = `\
195
+ fragment PullFragment on PullRequest {
196
+ url
197
+ author {
198
+ login
199
+ url
200
+ }
201
+ mergeCommit {
202
+ commitUrl
203
+ abbreviatedOid
204
+ }
205
+ }
206
+ `;
207
+ /**
208
+ * Upstream's `makeQuery` for one repository, character for character.
209
+ *
210
+ * @remarks
211
+ * Values are inlined, as upstream does, and that is safe only because of what
212
+ * reaches here: owner and name through `JSON.stringify` (a JSON string literal
213
+ * is a GraphQL string literal), a sha that matched {@link SHA} and a positive
214
+ * integer. Aliases are built from the same validated values.
215
+ */
216
+ const queryFor = (owner, repo, lookups) => {
217
+ let query = `query {\n ${REPO_ALIAS}: repository(\n owner: ${JSON.stringify(owner)},\n name: ${JSON.stringify(repo)}\n ) {\n`;
218
+ for (const lookup of lookups) query += lookup._tag === "CommitLookup" ? ` ${aliasOf(lookup)}: object(expression: ${JSON.stringify(lookup.sha)}) {\n ... on Commit {\n ...CommitFragment\n }\n }\n` : ` ${aliasOf(lookup)}: pullRequest(number: ${JSON.stringify(lookup.number)}) {\n ...PullFragment\n }\n`;
219
+ query += " }\n}\n";
220
+ if (lookups.some((lookup) => lookup._tag === "CommitLookup")) query += COMMIT_FRAGMENT;
221
+ if (lookups.some((lookup) => lookup._tag === "PullLookup")) query += PULL_FRAGMENT;
222
+ return query;
223
+ };
224
+ /** The whole answer: one repository alias holding one field per lookup alias, each decoded on its own. */
225
+ const BatchResponse = Schema.Struct({ [REPO_ALIAS]: Schema.NullOr(Schema.Record(Schema.String, Schema.Unknown)) });
226
+ const documentFor = (owner, repo, lookups) => GraphQLDocument.make({
227
+ name: "changelogInfo",
228
+ document: queryFor(owner, repo, lookups),
229
+ response: BatchResponse
230
+ })();
231
+ const decodeCommit = Schema.decodeUnknownEffect(Schema.NullOr(Schema.Union([CommitNode, NotACommit])));
232
+ const decodePull = Schema.decodeUnknownEffect(Schema.NullOr(PullNode));
233
+ /**
234
+ * The pull request aliases GitHub reported as not found, when that is all it
235
+ * reported; `undefined` when any entry is something else, such as the
236
+ * repository itself being missing.
237
+ */
238
+ const missingPulls = (error, lookups) => {
239
+ if (error.kind !== "notFound" || error.errors.length === 0) return void 0;
240
+ const pulls = new Set(lookups.filter((lookup) => lookup._tag === "PullLookup").map(aliasOf));
241
+ const missing = /* @__PURE__ */ new Set();
242
+ for (const entry of error.errors) {
243
+ const [repoStep, fieldStep, ...rest] = entry.path ?? [];
244
+ if (entry.type !== "NOT_FOUND" || repoStep !== REPO_ALIAS || rest.length > 0) return void 0;
245
+ if (typeof fieldStep !== "string" || !pulls.has(fieldStep)) return void 0;
246
+ missing.add(fieldStep);
247
+ }
248
+ return missing;
249
+ };
250
+ /** Earliest `mergedAt` first, unmerged last, ties in GitHub's order: upstream's sort. */
251
+ const byMergedAt = (a, b) => {
252
+ if (a.mergedAt === null && b.mergedAt === null) return 0;
253
+ if (a.mergedAt === null) return 1;
254
+ if (b.mergedAt === null) return -1;
255
+ return new Date(a.mergedAt).getTime() - new Date(b.mergedAt).getTime();
256
+ };
257
+ const isCommit = (answer) => "commitUrl" in answer;
258
+ const commitInfo = (sha, answer) => {
259
+ if (answer === null || !isCommit(answer)) return Option.none();
260
+ const node = answer;
261
+ const pulls = (node.associatedPullRequests?.nodes ?? []).filter((pull) => pull !== null);
262
+ const pull = Option.fromNullishOr([...pulls].sort(byMergedAt)[0]);
263
+ const author = Option.orElse(Option.flatMap(pull, (found) => Option.fromNullishOr(found.author)), () => Option.fromNullishOr(node.author?.user));
264
+ return Option.some(CommitChangelogInfo.make({
265
+ user: Option.map(author, (actor) => actor.login),
266
+ pull: Option.map(pull, (found) => found.number),
267
+ links: {
268
+ commit: `[\`${sha.slice(0, 7)}\`](${node.commitUrl})`,
269
+ pull: Option.map(pull, (found) => `[#${found.number}](${found.url})`),
270
+ user: Option.map(author, (actor) => `[@${actor.login}](${actor.url})`)
271
+ }
272
+ }));
273
+ };
274
+ const pullInfo = (number, answer) => {
275
+ if (answer === null) return Option.none();
276
+ const author = Option.fromNullishOr(answer.author);
277
+ const merge = Option.fromNullishOr(answer.mergeCommit);
278
+ return Option.some(PullRequestChangelogInfo.make({
279
+ user: Option.map(author, (actor) => actor.login),
280
+ commit: Option.map(merge, (commit) => commit.abbreviatedOid),
281
+ links: {
282
+ commit: Option.map(merge, (commit) => `[\`${commit.abbreviatedOid.slice(0, 7)}\`](${commit.commitUrl})`),
283
+ pull: `[#${number}](${answer.url})`,
284
+ user: Option.map(author, (actor) => `[@${actor.login}](${actor.url})`)
285
+ }
286
+ }));
287
+ };
288
+ const make = (client) => {
289
+ /**
290
+ * Every alias's answer, `null` for a missing one. A batch whose only errors
291
+ * are missing pull requests is sent again without them, so each round drops
292
+ * at least one lookup and the loop ends.
293
+ */
294
+ const answers = (owner, repo, lookups) => lookups.length === 0 ? Effect.succeed(/* @__PURE__ */ new Map()) : client.graphql(documentFor(owner, repo, lookups), {}).pipe(Effect.map((data) => new Map(Object.entries(data[REPO_ALIAS] ?? {}))), Effect.catchTag("GitHubGraphQLError", (error) => {
295
+ const missing = missingPulls(error, lookups);
296
+ if (missing === void 0) return Effect.fail(error);
297
+ return Effect.map(answers(owner, repo, lookups.filter((lookup) => !missing.has(aliasOf(lookup)))), (found) => new Map([...found, ...[...missing].map((alias) => [alias, null])]));
298
+ }));
299
+ const resolver = RequestResolver.makeGrouped({
300
+ key: ({ request }) => `${request.owner}/${request.repo}`,
301
+ resolver: (entries) => Effect.gen(function* () {
302
+ const { owner, repo } = entries[0].request;
303
+ const distinct = [...new Map(entries.map((entry) => [aliasOf(entry.request), entry.request])).values()];
304
+ yield* Effect.annotateCurrentSpan({
305
+ owner,
306
+ repo,
307
+ lookups: distinct.length
308
+ });
309
+ const found = yield* answers(owner, repo, distinct);
310
+ const decoded = /* @__PURE__ */ new Map();
311
+ for (const lookup of distinct) {
312
+ const alias = aliasOf(lookup);
313
+ const raw = found.get(alias) ?? null;
314
+ const info = lookup._tag === "CommitLookup" ? yield* Effect.map(decodeCommit(raw), (answer) => commitInfo(lookup.sha, answer)) : yield* Effect.map(decodePull(raw), (answer) => pullInfo(lookup.number, answer));
315
+ decoded.set(alias, info);
316
+ }
317
+ for (const entry of entries) entry.completeUnsafe(Exit.succeed(decoded.get(aliasOf(entry.request)) ?? Option.none()));
318
+ }).pipe(Effect.catchTag("SchemaError", (error) => Effect.fail(GitHubGraphQLError.decode("changelogInfo", "response did not match its schema", error))), Effect.withSpan("ChangelogInfo.batch"))
319
+ }).pipe(RequestResolver.batchN(BATCH_SIZE));
320
+ return {
321
+ commit: Effect.fn("ChangelogInfo.commit")(function* (sha) {
322
+ if (!SHA.test(sha)) return yield* new InvalidChangelogRefError({
323
+ ref: "commit",
324
+ input: sha
325
+ });
326
+ const { owner, repo } = yield* Repo;
327
+ yield* Effect.annotateCurrentSpan({
328
+ owner,
329
+ repo,
330
+ sha
331
+ });
332
+ return yield* Effect.request(CommitLookup({
333
+ owner,
334
+ repo,
335
+ sha
336
+ }), resolver);
337
+ }),
338
+ pullRequest: Effect.fn("ChangelogInfo.pullRequest")(function* (number) {
339
+ if (!Number.isSafeInteger(number) || number < 1) return yield* new InvalidChangelogRefError({
340
+ ref: "pull",
341
+ input: String(number)
342
+ });
343
+ const { owner, repo } = yield* Repo;
344
+ yield* Effect.annotateCurrentSpan({
345
+ owner,
346
+ repo,
347
+ number
348
+ });
349
+ return yield* Effect.request(PullLookup({
350
+ owner,
351
+ repo,
352
+ number
353
+ }), resolver);
354
+ })
355
+ };
356
+ };
357
+
358
+ export { ChangelogInfo, CommitChangelogInfo, InvalidChangelogRefError, PullRequestChangelogInfo };
package/GraphQL.js CHANGED
@@ -12,7 +12,17 @@ var GraphQLErrorEntry = class extends Schema.Class("GraphQLErrorEntry")({
12
12
  /** GitHub's prose. */
13
13
  message: Schema.String,
14
14
  /** GitHub's own classification, e.g. `"NOT_FOUND"` or `"FORBIDDEN"`. */
15
- type: Schema.optionalKey(Schema.String)
15
+ type: Schema.optionalKey(Schema.String),
16
+ /**
17
+ * Where in the response the entry applies: field names (aliases, when the
18
+ * document aliases) and list indexes, outermost first.
19
+ *
20
+ * @remarks
21
+ * This is what tells a batched document which aliased lookup GitHub could
22
+ * not resolve: a missing pull request in a batch reports
23
+ * `["repo__0", "pull__42"]`, a missing repository `["repo__0"]`.
24
+ */
25
+ path: Schema.optionalKey(Schema.Array(Schema.Union([Schema.String, Schema.Number])))
16
26
  }) {};
17
27
  /**
18
28
  * A GraphQL call failed.
@@ -111,9 +121,11 @@ const readEntries = (value) => {
111
121
  if (record === void 0) continue;
112
122
  const message = typeof record.message === "string" ? record.message : String(raw);
113
123
  const type = typeof record.type === "string" ? record.type : void 0;
124
+ const path = Array.isArray(record.path) ? record.path.filter((step) => typeof step === "string" || typeof step === "number") : void 0;
114
125
  entries.push(GraphQLErrorEntry.make({
115
126
  message,
116
- ...type !== void 0 ? { type } : {}
127
+ ...type !== void 0 ? { type } : {},
128
+ ...path !== void 0 ? { path } : {}
117
129
  }));
118
130
  }
119
131
  return entries;
package/index.d.ts CHANGED
@@ -398,6 +398,16 @@ declare const GraphQLErrorEntry_base: Schema.Class<GraphQLErrorEntry, Schema.Str
398
398
  readonly message: Schema.String;
399
399
  /** GitHub's own classification, e.g. `"NOT_FOUND"` or `"FORBIDDEN"`. */
400
400
  readonly type: Schema.optionalKey<Schema.String>;
401
+ /**
402
+ * Where in the response the entry applies: field names (aliases, when the
403
+ * document aliases) and list indexes, outermost first.
404
+ *
405
+ * @remarks
406
+ * This is what tells a batched document which aliased lookup GitHub could
407
+ * not resolve: a missing pull request in a batch reports
408
+ * `["repo__0", "pull__42"]`, a missing repository `["repo__0"]`.
409
+ */
410
+ readonly path: Schema.optionalKey<Schema.$Array<Schema.Union<readonly [Schema.String, Schema.Number]>>>;
401
411
  }>, {}>;
402
412
  /**
403
413
  * One entry from a GraphQL response's `errors` array.
@@ -1645,6 +1655,160 @@ export declare class AuthenticatedApp extends AuthenticatedApp_base {
1645
1655
  /** {@link AuthenticatedApp.makeTest} behind a `Layer`. */
1646
1656
  static readonly layerTest: (overrides?: Partial<AuthenticatedAppShape>) => Layer.Layer<AuthenticatedApp>;
1647
1657
  }
1658
+ declare const InvalidChangelogRefError_base: Schema.Class<InvalidChangelogRefError, Schema.TaggedStruct<"InvalidChangelogRefError", {
1659
+ /** Which lookup refused it. */
1660
+ readonly ref: Schema.Literals<readonly ["commit", "pull"]>;
1661
+ /** What was handed in, as text. */
1662
+ readonly input: Schema.String;
1663
+ }>, import("effect/Cause").YieldableError>;
1664
+ /**
1665
+ * A changelog lookup was handed a commit sha or pull request number it cannot
1666
+ * send.
1667
+ *
1668
+ * @remarks
1669
+ * The batch names each lookup by an alias built from its input
1670
+ * (`commit__<sha>`, `pull__<number>`), so the input must be something a
1671
+ * GraphQL alias can carry: a hexadecimal sha of 4 to 64 characters, or a
1672
+ * positive integer. Nothing is sent when this fails.
1673
+ *
1674
+ * @public
1675
+ */
1676
+ export declare class InvalidChangelogRefError extends InvalidChangelogRefError_base {
1677
+ get message(): string;
1678
+ }
1679
+ declare const CommitChangelogInfo_base: Schema.Class<CommitChangelogInfo, Schema.Struct<{
1680
+ /**
1681
+ * The login to credit: the pull request's author when the commit has one,
1682
+ * otherwise the GitHub user the commit's author maps to.
1683
+ */
1684
+ readonly user: Schema.Option<Schema.String>;
1685
+ /** The pull request the commit landed through: the earliest-merged one, else the first GitHub lists. */
1686
+ readonly pull: Schema.Option<Schema.Int>;
1687
+ /** Markdown links for the line. */
1688
+ readonly links: Schema.Struct<{
1689
+ /** The first 7 characters of the sha asked for, in a code span, linked to the commit URL. */
1690
+ readonly commit: Schema.String;
1691
+ /** `#` and the number, linked to the pull request URL, when there is a pull request. */
1692
+ readonly pull: Schema.Option<Schema.String>;
1693
+ /** `@` and the login, linked to the user's URL, when there is a user. */
1694
+ readonly user: Schema.Option<Schema.String>;
1695
+ }>;
1696
+ }>, {}>;
1697
+ /**
1698
+ * What a changelog line says about one commit.
1699
+ *
1700
+ * @remarks
1701
+ * The shape `@changesets/get-github-info`'s `getInfo` returns, with every
1702
+ * value that can be missing as an `Option`. The links are markdown, in
1703
+ * upstream's exact format: the short sha in a code span linked to the commit
1704
+ * URL, `[#42](https://github.com/acme/widget/pull/42)` and
1705
+ * `[@octocat](https://github.com/octocat)`. Every URL is the one GitHub answered with, so on
1706
+ * GitHub Enterprise Server the links name that server; nothing here builds a
1707
+ * URL from a configured host.
1708
+ *
1709
+ * @public
1710
+ */
1711
+ export declare class CommitChangelogInfo extends CommitChangelogInfo_base {}
1712
+ declare const PullRequestChangelogInfo_base: Schema.Class<PullRequestChangelogInfo, Schema.Struct<{
1713
+ /** The pull request author's login. */
1714
+ readonly user: Schema.Option<Schema.String>;
1715
+ /** The merge commit's abbreviated sha, once the pull request has merged. */
1716
+ readonly commit: Schema.Option<Schema.String>;
1717
+ /** Markdown links for the line. */
1718
+ readonly links: Schema.Struct<{
1719
+ /** The first 7 characters of the abbreviated merge sha, in a code span, linked to the commit URL, once merged. */
1720
+ readonly commit: Schema.Option<Schema.String>;
1721
+ /** `#` and the number, linked to the pull request URL. */
1722
+ readonly pull: Schema.String;
1723
+ /** `@` and the login, linked to the user's URL, when the author still exists. */
1724
+ readonly user: Schema.Option<Schema.String>;
1725
+ }>;
1726
+ }>, {}>;
1727
+ /**
1728
+ * What a changelog line says about one pull request.
1729
+ *
1730
+ * @remarks
1731
+ * The shape `@changesets/get-github-info`'s `getInfoFromPullRequest` returns,
1732
+ * for a changeset that names its pull request (`pr: #42`) instead of leaving
1733
+ * it to the commit. Links are in the same format as
1734
+ * {@link CommitChangelogInfo}'s, from the URLs GitHub answered with.
1735
+ *
1736
+ * @public
1737
+ */
1738
+ export declare class PullRequestChangelogInfo extends PullRequestChangelogInfo_base {}
1739
+ /**
1740
+ * The commit and pull request facts a changelog line credits.
1741
+ *
1742
+ * @public
1743
+ */
1744
+ interface ChangelogInfoShape {
1745
+ /**
1746
+ * What to credit for a commit of the surrounding `Repo`.
1747
+ *
1748
+ * @remarks
1749
+ * `Option.none()` when the repository has no such commit (or the sha names
1750
+ * something that is not a commit). Lookups that run concurrently are sent as
1751
+ * one aliased GraphQL query, up to 50 per query: run them with
1752
+ * `Effect.forEach(..., { concurrency: "unbounded" })` to get the batch.
1753
+ */
1754
+ readonly commit: (sha: string) => Effect.Effect<Option.Option<CommitChangelogInfo>, GitHubGraphQLError | InvalidChangelogRefError, Repo>;
1755
+ /**
1756
+ * What to credit for a pull request of the surrounding `Repo`.
1757
+ *
1758
+ * @remarks
1759
+ * `Option.none()` when the repository has no such pull request. Batched with
1760
+ * concurrent {@link ChangelogInfoShape.commit} lookups into the same query.
1761
+ */
1762
+ readonly pullRequest: (number: number) => Effect.Effect<Option.Option<PullRequestChangelogInfo>, GitHubGraphQLError | InvalidChangelogRefError, Repo>;
1763
+ }
1764
+ declare const ChangelogInfo_base: Context.ServiceClass<ChangelogInfo, "@effected/github/ChangelogInfo", ChangelogInfoShape>;
1765
+ /**
1766
+ * The commit and pull request facts a changelog line credits, batched into
1767
+ * one GraphQL query.
1768
+ *
1769
+ * @remarks
1770
+ * The kit's `@changesets/get-github-info`. The token and the server come from
1771
+ * the `GitHubClient` the layer is built over, and the repository from `Repo`;
1772
+ * nothing is read from the environment. The query is upstream's, alias for
1773
+ * alias, so concurrent lookups cost one round trip per 50.
1774
+ *
1775
+ * Two answers differ from upstream's, both toward the lookup convention: a
1776
+ * pull request number the repository does not have is `Option.none()` (GitHub
1777
+ * reports it as an error, which upstream throws for the whole batch), and a
1778
+ * sha naming a tree or blob is `Option.none()` (upstream builds links to
1779
+ * `undefined`). A missing repository still fails, with `kind: "notFound"`.
1780
+ *
1781
+ * Batching happens within one built service: each `ChangelogInfo.layer`
1782
+ * build owns its own resolver, and nothing is cached across batches.
1783
+ *
1784
+ * @example
1785
+ * ```ts
1786
+ * import { ChangelogInfo } from "@effected/github";
1787
+ * import { Effect, Option } from "effect";
1788
+ *
1789
+ * const lines = (shas: ReadonlyArray<string>) =>
1790
+ * Effect.gen(function* () {
1791
+ * const info = yield* ChangelogInfo;
1792
+ * const found = yield* Effect.forEach(shas, info.commit, { concurrency: "unbounded" });
1793
+ * return found.flatMap((entry) =>
1794
+ * Option.match(entry, {
1795
+ * onNone: () => [],
1796
+ * onSome: ({ links }) => [`${Option.getOrElse(links.pull, () => links.commit)} Thanks ${Option.getOrElse(links.user, () => "")}`],
1797
+ * }),
1798
+ * );
1799
+ * });
1800
+ * ```
1801
+ *
1802
+ * @public
1803
+ */
1804
+ export declare class ChangelogInfo extends ChangelogInfo_base {
1805
+ /** The live service, built over a `GitHubClient`. */
1806
+ static readonly layer: Layer.Layer<ChangelogInfo, never, GitHubClient>;
1807
+ /** An in-memory double; an unstubbed member dies when run, naming itself. */
1808
+ static readonly makeTest: (overrides?: Partial<ChangelogInfoShape>) => ChangelogInfoShape;
1809
+ /** {@link ChangelogInfo.makeTest} behind a `Layer`. */
1810
+ static readonly layerTest: (overrides?: Partial<ChangelogInfoShape>) => Layer.Layer<ChangelogInfo>;
1811
+ }
1648
1812
  /** How a check run finished. @public */
1649
1813
  export declare const CheckConclusion: Schema.Literals<readonly ["success", "failure", "neutral", "cancelled", "timed_out", "action_required", "skipped"]>;
1650
1814
  /**
@@ -5609,5 +5773,5 @@ export declare class WorkflowDispatch extends WorkflowDispatch_base {
5609
5773
  /** {@link WorkflowDispatch.makeTest} behind a `Layer`. */
5610
5774
  static readonly layerTest: (overrides?: Partial<WorkflowDispatchShape>) => Layer.Layer<WorkflowDispatch>;
5611
5775
  }
5612
- export { type ActionsOidcVerifyOptions, type AppCredentials, type AppliedSettings, type ApplySettingsOptions, type ArtifactMetadataShape, type AttestationShape, type AuthenticatedAppShape, type BareLineReference, type BotUserRequest, type BranchOutcome, CLOSING_KEYWORDS, type CachedToken, type CachedTokenRequest, type CheckRunShape, type ClosingKeyword, type CodeScanningSetup, type CodeScanningShape, type CompleteCheckRunOptions, type ConcludeCheckRun, type CreateCheckRunOptions, type DeliveriesOptions, type DeploymentEnvironmentInfo, type DeploymentEnvironmentShape, type GitBranchShape, type GitCommitShape, type GitHubAppOptions, type GitHubAppShape, type GitHubClientOptions, type GitHubClientShape, type GitHubCommitShape, type GitHubContentShape, type GitHubIssueShape, type GitHubReleaseShape, type GitHubRepositoryShape, type GitHubUserAuthError, type GitHubUserAuthOptions, type GitHubUserAuthShape, type GitTagShape, type InstallationTokenStoreShape, type IssueReference, type LatestSemverOptions, type ListCheckRunsOptions, type OwnerType, type PollOptions, type PullRequestCommentShape, type PullRequestShape, type RecordedCall, type RepositoryPatch, type RepositoryPatchDraft, type RepositoryPatchExtra, type RepositoryPatchOptions, type RepositoryPatchReservedKey, type RepositorySecretShape, type RepositorySecurityShape, type RepositorySettings, type RepositoryVariableShape, type Data as RestData, type RequestExtras as RestExtras, type Item as RestItem, type PaginatingRoute as RestPaginatingRoute, type Params as RestParams, type Response as RestResponse, type Route as RestRoute, type RetryableFailure, type RulesetInfo, type RulesetPayload, type RulesetShape, type SecretInfo, type SecretScope, type TokenRequest, type UpdateCheckRunOptions, type UpsertedPullRequest, type UserAuthExchangeRequest, type UserAuthRefreshRequest, type UserAuthRevokeRequest, type VariableInfo, type VersionFromTag, type WorkflowDispatchShape, type WorkflowInfo, harvestIssueReferences, parseBareLineReference };
5776
+ export { type ActionsOidcVerifyOptions, type AppCredentials, type AppliedSettings, type ApplySettingsOptions, type ArtifactMetadataShape, type AttestationShape, type AuthenticatedAppShape, type BareLineReference, type BotUserRequest, type BranchOutcome, CLOSING_KEYWORDS, type CachedToken, type CachedTokenRequest, type ChangelogInfoShape, type CheckRunShape, type ClosingKeyword, type CodeScanningSetup, type CodeScanningShape, type CompleteCheckRunOptions, type ConcludeCheckRun, type CreateCheckRunOptions, type DeliveriesOptions, type DeploymentEnvironmentInfo, type DeploymentEnvironmentShape, type GitBranchShape, type GitCommitShape, type GitHubAppOptions, type GitHubAppShape, type GitHubClientOptions, type GitHubClientShape, type GitHubCommitShape, type GitHubContentShape, type GitHubIssueShape, type GitHubReleaseShape, type GitHubRepositoryShape, type GitHubUserAuthError, type GitHubUserAuthOptions, type GitHubUserAuthShape, type GitTagShape, type InstallationTokenStoreShape, type IssueReference, type LatestSemverOptions, type ListCheckRunsOptions, type OwnerType, type PollOptions, type PullRequestCommentShape, type PullRequestShape, type RecordedCall, type RepositoryPatch, type RepositoryPatchDraft, type RepositoryPatchExtra, type RepositoryPatchOptions, type RepositoryPatchReservedKey, type RepositorySecretShape, type RepositorySecurityShape, type RepositorySettings, type RepositoryVariableShape, type Data as RestData, type RequestExtras as RestExtras, type Item as RestItem, type PaginatingRoute as RestPaginatingRoute, type Params as RestParams, type Response as RestResponse, type Route as RestRoute, type RetryableFailure, type RulesetInfo, type RulesetPayload, type RulesetShape, type SecretInfo, type SecretScope, type TokenRequest, type UpdateCheckRunOptions, type UpsertedPullRequest, type UserAuthExchangeRequest, type UserAuthRefreshRequest, type UserAuthRevokeRequest, type VariableInfo, type VersionFromTag, type WorkflowDispatchShape, type WorkflowInfo, harvestIssueReferences, parseBareLineReference };
5613
5777
  //# sourceMappingURL=index.d.ts.map
package/index.js CHANGED
@@ -2,6 +2,7 @@ import { ActionsOidc, ActionsOidcClaims, ActionsOidcClaimsFromWire } from "./Act
2
2
  import { ArtifactMetadata, StorageRecordInput } from "./ArtifactMetadata.js";
3
3
  import { Attestation, AttestationListEntry, AttestationRecord } from "./Attestation.js";
4
4
  import { AppInfo, AuthenticatedApp, DeliveryAttempt } from "./AuthenticatedApp.js";
5
+ import { ChangelogInfo, CommitChangelogInfo, InvalidChangelogRefError, PullRequestChangelogInfo } from "./ChangelogInfo.js";
5
6
  import { Annotation, AnnotationLevel, CheckConclusion, CheckRun, CheckRunOutput, CheckRunRef, CheckRunStatus, ReportedCheckConclusion, ReportedCheckRunOutput } from "./CheckRun.js";
6
7
  import { CodeScanning } from "./CodeScanning.js";
7
8
  import { DeploymentEnvironment } from "./DeploymentEnvironment.js";
@@ -32,4 +33,4 @@ import { ExtraPermission, PermissionGap, PermissionLevel, PermissionResult, Toke
32
33
  import { DispatchedRun, WorkflowDispatch, WorkflowRunStatus } from "./WorkflowDispatch.js";
33
34
  import { CLOSING_KEYWORDS, harvestIssueReferences, parseBareLineReference } from "@effected/github-references";
34
35
 
35
- export { ActionsOidc, ActionsOidcClaims, ActionsOidcClaimsFromWire, Annotation, AnnotationLevel, AppIdentity, AppInfo, ArtifactMetadata, Attestation, AttestationListEntry, AttestationRecord, AuthenticatedApp, BotIdentity, BotUser, CLOSING_KEYWORDS, CheckConclusion, CheckRun, CheckRunOutput, CheckRunRef, CheckRunStatus, CodeScanning, CommentMarker, CommentOnceResult, CommentRecord, CommitComparison, CommitFile, CommitRef, CommitSummary, CreatedCommit, DeliveryAttempt, DeploymentEnvironment, DispatchedRun, ExpiringUserTokens, ExtraPermission, FileChange, FileContent, FileDeletion, FileMode, FileStatus, GRAPHQL_ONLY_SETTINGS, GitBranch, GitCommit, GitHubApp, GitHubAppError, GitHubClient, GitHubCommit, GitHubContent, GitHubError, GitHubErrorKind, GitHubFixtures, GitHubGraphQLError, GitHubIssue, GitHubRelease, GitHubRepository, GitHubUserAuth, GitHubUserAuthFinal, GitHubUserAuthOperation, GitHubUserAuthTemporary, GitHubUserTokens, GitHubValidationCode, GitHubValidationEntry, GitTag, GraphQLDocument, GraphQLErrorEntry, Installation, InstallationToken, InstallationTokenStore, InvalidRepoRefError, IssueInfo, LinkedIssue, MergeMethod, NonExpiringUserTokens, PageOptions, PermissionGap, PermissionLevel, PermissionResult, PullRequest, PullRequestComment, PullRequestInfo, RateLimitSnapshot, RawFailure, ReleaseAsset, ReleaseInfo, Repo, RepoRef, ReportedCheckConclusion, ReportedCheckRunOutput, RepositorySecret, RepositorySecurity, RepositoryVariable, RetryPolicy, Ruleset, SECURITY_ANALYSIS_STATUS_FIELDS, SemverTag, StorageRecordInput, TagRef, TokenPermissionError, TokenPermissions, WorkflowDispatch, WorkflowRunStatus, harvestIssueReferences, parseBareLineReference, repositoryPatch, transformSecurityAndAnalysis, versionFromTag };
36
+ export { ActionsOidc, ActionsOidcClaims, ActionsOidcClaimsFromWire, Annotation, AnnotationLevel, AppIdentity, AppInfo, ArtifactMetadata, Attestation, AttestationListEntry, AttestationRecord, AuthenticatedApp, BotIdentity, BotUser, CLOSING_KEYWORDS, ChangelogInfo, CheckConclusion, CheckRun, CheckRunOutput, CheckRunRef, CheckRunStatus, CodeScanning, CommentMarker, CommentOnceResult, CommentRecord, CommitChangelogInfo, CommitComparison, CommitFile, CommitRef, CommitSummary, CreatedCommit, DeliveryAttempt, DeploymentEnvironment, DispatchedRun, ExpiringUserTokens, ExtraPermission, FileChange, FileContent, FileDeletion, FileMode, FileStatus, GRAPHQL_ONLY_SETTINGS, GitBranch, GitCommit, GitHubApp, GitHubAppError, GitHubClient, GitHubCommit, GitHubContent, GitHubError, GitHubErrorKind, GitHubFixtures, GitHubGraphQLError, GitHubIssue, GitHubRelease, GitHubRepository, GitHubUserAuth, GitHubUserAuthFinal, GitHubUserAuthOperation, GitHubUserAuthTemporary, GitHubUserTokens, GitHubValidationCode, GitHubValidationEntry, GitTag, GraphQLDocument, GraphQLErrorEntry, Installation, InstallationToken, InstallationTokenStore, InvalidChangelogRefError, InvalidRepoRefError, IssueInfo, LinkedIssue, MergeMethod, NonExpiringUserTokens, PageOptions, PermissionGap, PermissionLevel, PermissionResult, PullRequest, PullRequestChangelogInfo, PullRequestComment, PullRequestInfo, RateLimitSnapshot, RawFailure, ReleaseAsset, ReleaseInfo, Repo, RepoRef, ReportedCheckConclusion, ReportedCheckRunOutput, RepositorySecret, RepositorySecurity, RepositoryVariable, RetryPolicy, Ruleset, SECURITY_ANALYSIS_STATUS_FIELDS, SemverTag, StorageRecordInput, TagRef, TokenPermissionError, TokenPermissions, WorkflowDispatch, WorkflowRunStatus, harvestIssueReferences, parseBareLineReference, repositoryPatch, transformSecurityAndAnalysis, versionFromTag };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effected/github",
3
- "version": "0.30.0",
3
+ "version": "0.31.0",
4
4
  "private": false,
5
5
  "description": "Typed GitHub REST and GraphQL services over the octokit core request surface, with app auth and resource helpers.",
6
6
  "keywords": [
@@ -42,7 +42,7 @@
42
42
  "@effected/github-references": "^0.14.0",
43
43
  "@effected/jwt": "^0.9.1",
44
44
  "@effected/oidc": "^0.4.0",
45
- "@effected/semver": "^0.22.0",
45
+ "@effected/semver": "^0.23.0",
46
46
  "@octokit/core": "^7.0.6",
47
47
  "@octokit/plugin-paginate-rest": "^16.0.0",
48
48
  "@octokit/types": "^18.0.0",