@effected/github 0.28.0 → 0.29.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.
package/GitCommit.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { GitHubClient } from "./GitHubClient.js";
2
+ import { GitHubError } from "./GitHubError.js";
2
3
  import { unstubbed } from "./internal/unstubbed.js";
3
4
  import { Repo } from "./Repo.js";
4
5
  import { Context, Effect, Layer, Schema } from "effect";
@@ -59,6 +60,22 @@ var CommitRef = class extends Schema.Class("CommitRef")({
59
60
  parents: Schema.Array(Schema.String)
60
61
  }) {};
61
62
  /**
63
+ * A commit just created through the Git Database API: its sha and the URL
64
+ * GitHub reports for viewing it.
65
+ *
66
+ * @remarks
67
+ * `htmlUrl` is the `html_url` of the creation reply, so it carries the right
68
+ * host on GitHub Enterprise Server with no host arithmetic.
69
+ *
70
+ * @public
71
+ */
72
+ var CreatedCommit = class extends Schema.Class("CreatedCommit")({
73
+ /** The new commit's sha. */
74
+ sha: Schema.String,
75
+ /** The commit's web URL, as GitHub reported it. */
76
+ htmlUrl: Schema.String
77
+ }) {};
78
+ /**
62
79
  * Read commits and build trees and commits through GitHub's Git Database API,
63
80
  * including a one-call "commit these files onto a branch".
64
81
  *
@@ -92,7 +109,9 @@ var GitCommit = class GitCommit extends Context.Service()("@effected/github/GitC
92
109
  get: overrides.get ?? (() => dies("get")),
93
110
  createTree: overrides.createTree ?? (() => dies("createTree")),
94
111
  createCommit: overrides.createCommit ?? (() => dies("createCommit")),
95
- commitFiles: overrides.commitFiles ?? (() => dies("commitFiles"))
112
+ createCommitWithUrl: overrides.createCommitWithUrl ?? (() => dies("createCommitWithUrl")),
113
+ commitFiles: overrides.commitFiles ?? (() => dies("commitFiles")),
114
+ commitFilesWithUrl: overrides.commitFilesWithUrl ?? (() => dies("commitFilesWithUrl"))
96
115
  });
97
116
  /** {@link GitCommit.makeTest} behind a `Layer`. */
98
117
  static layerTest = (overrides = {}) => Layer.succeed(GitCommit, GitCommit.makeTest(overrides));
@@ -143,59 +162,74 @@ const make = (client) => {
143
162
  ...options.baseTree !== void 0 ? { base_tree: options.baseTree } : {}
144
163
  })).sha;
145
164
  });
146
- const createCommit = Effect.fn("GitCommit.createCommit")(function* (options) {
165
+ const createRaw = Effect.fn("GitCommit.createCommit")(function* (options) {
147
166
  const { owner, repo } = yield* Repo;
148
167
  yield* Effect.annotateCurrentSpan({
149
168
  owner,
150
169
  repo,
151
170
  tree: options.tree
152
171
  });
153
- return (yield* client.request("POST /repos/{owner}/{repo}/git/commits", {
172
+ const commit = yield* client.request("POST /repos/{owner}/{repo}/git/commits", {
154
173
  owner,
155
174
  repo,
156
175
  message: options.message,
157
176
  tree: options.tree,
158
177
  parents: [...options.parents]
159
- })).sha;
178
+ });
179
+ return {
180
+ sha: commit.sha,
181
+ htmlUrl: commit.html_url
182
+ };
183
+ });
184
+ const commitFilesRaw = Effect.fn("GitCommit.commitFiles")(function* (options) {
185
+ const { owner, repo } = yield* Repo;
186
+ const short = options.branch.replace(/^refs\/heads\//, "").replace(/^heads\//, "");
187
+ yield* Effect.annotateCurrentSpan({
188
+ owner,
189
+ repo,
190
+ branch: short,
191
+ changes: options.changes.length
192
+ });
193
+ const ref = yield* client.request("GET /repos/{owner}/{repo}/git/ref/{ref}", {
194
+ owner,
195
+ repo,
196
+ ref: `heads/${short}`
197
+ });
198
+ const head = yield* get(ref.object.sha);
199
+ const tree = yield* createTree({
200
+ changes: options.changes,
201
+ baseTree: head.treeSha
202
+ });
203
+ const commit = yield* createRaw({
204
+ message: options.message,
205
+ tree,
206
+ parents: [head.sha]
207
+ });
208
+ yield* client.request("PATCH /repos/{owner}/{repo}/git/refs/{ref}", {
209
+ owner,
210
+ repo,
211
+ ref: `heads/${short}`,
212
+ sha: commit.sha,
213
+ force: false
214
+ });
215
+ return commit;
160
216
  });
217
+ /**
218
+ * The URL check, run after the work (and for `commitFiles`, the ref move) is
219
+ * done: a reply without `html_url` leaves a real commit, so the failure names it.
220
+ */
221
+ const withUrl = (operation, created) => typeof created.htmlUrl === "string" ? Effect.succeed(CreatedCommit.make({
222
+ sha: created.sha,
223
+ htmlUrl: created.htmlUrl
224
+ })) : Effect.fail(GitHubError.decode(operation, `the commit ${created.sha} was created, but GitHub's reply carried no html_url`));
161
225
  return {
162
226
  get,
163
227
  createTree,
164
- createCommit,
165
- commitFiles: Effect.fn("GitCommit.commitFiles")(function* (options) {
166
- const { owner, repo } = yield* Repo;
167
- const short = options.branch.replace(/^refs\/heads\//, "").replace(/^heads\//, "");
168
- yield* Effect.annotateCurrentSpan({
169
- owner,
170
- repo,
171
- branch: short,
172
- changes: options.changes.length
173
- });
174
- const ref = yield* client.request("GET /repos/{owner}/{repo}/git/ref/{ref}", {
175
- owner,
176
- repo,
177
- ref: `heads/${short}`
178
- });
179
- const head = yield* get(ref.object.sha);
180
- const tree = yield* createTree({
181
- changes: options.changes,
182
- baseTree: head.treeSha
183
- });
184
- const commit = yield* createCommit({
185
- message: options.message,
186
- tree,
187
- parents: [head.sha]
188
- });
189
- yield* client.request("PATCH /repos/{owner}/{repo}/git/refs/{ref}", {
190
- owner,
191
- repo,
192
- ref: `heads/${short}`,
193
- sha: commit,
194
- force: false
195
- });
196
- return commit;
197
- })
228
+ createCommit: (options) => Effect.map(createRaw(options), (commit) => commit.sha),
229
+ createCommitWithUrl: (options) => Effect.flatMap(createRaw(options), (commit) => withUrl("GitCommit.createCommitWithUrl", commit)),
230
+ commitFiles: (options) => Effect.map(commitFilesRaw(options), (commit) => commit.sha),
231
+ commitFilesWithUrl: (options) => Effect.flatMap(commitFilesRaw(options), (commit) => withUrl("GitCommit.commitFilesWithUrl", commit))
198
232
  };
199
233
  };
200
234
 
201
- export { CommitRef, FileChange, FileContent, FileDeletion, FileMode, GitCommit };
235
+ export { CommitRef, CreatedCommit, FileChange, FileContent, FileDeletion, FileMode, GitCommit };
package/index.d.ts CHANGED
@@ -805,6 +805,12 @@ interface GitHubClientShape {
805
805
  * route that resolves to another origin, fails `kind: "rejected"` with no
806
806
  * status and nothing sent.
807
807
  *
808
+ * **Interrupting aborts the fetch.** The fiber's `AbortSignal` reaches the
809
+ * fetch, so an interrupt (an `Effect.timeout`, a cancelled caller) cancels the
810
+ * in-flight HTTP request, a body read included, and the attempt is not
811
+ * retried. A `fetch` option that ignores its signal still releases the caller
812
+ * at once, while that request runs on.
813
+ *
808
814
  * @example
809
815
  * ```ts
810
816
  * import { GitHubClient } from "@effected/github";
@@ -852,6 +858,12 @@ interface GitHubClientShape {
852
858
  * header whose next page names another origin fails the walk
853
859
  * `kind: "rejected"` before that page is requested, rather than sending the
854
860
  * token there or ending the walk early as if the collection were complete.
861
+ *
862
+ * **Interrupting aborts the fetch.** The fiber's `AbortSignal` reaches the
863
+ * fetch, so an interrupt (an `Effect.timeout`, a cancelled caller) cancels the
864
+ * in-flight HTTP request, a body read included, and the attempt is not
865
+ * retried. A `fetch` option that ignores its signal still releases the caller
866
+ * at once, while that request runs on.
855
867
  */
856
868
  readonly paginate: <R extends PaginatingRoute>(route: R, params: Params<R>, options?: PageOptions) => Effect.Effect<ReadonlyArray<Item<R>>, GitHubError>;
857
869
  /**
@@ -861,6 +873,12 @@ interface GitHubClientShape {
861
873
  * Lazy in requests: a downstream `Stream.take` stops the walk rather than
862
874
  * filtering pages that were already fetched. Confined to the configured
863
875
  * host exactly as {@link GitHubClientShape.paginate} is.
876
+ *
877
+ * **Interrupting aborts the fetch.** The fiber's `AbortSignal` reaches the
878
+ * fetch, so an interrupt (an `Effect.timeout`, a cancelled caller) cancels the
879
+ * in-flight HTTP request, a body read included, and the attempt is not
880
+ * retried. A `fetch` option that ignores its signal still releases the caller
881
+ * at once, while that request runs on.
864
882
  */
865
883
  readonly paginateStream: <R extends PaginatingRoute>(route: R, params: Params<R>, options?: PageOptions) => Stream.Stream<Item<R>, GitHubError>;
866
884
  /** Run an owned GraphQL document and decode its answer. */
@@ -2381,6 +2399,23 @@ declare const CommitRef_base: Schema.Class<CommitRef, Schema.Struct<{
2381
2399
  * @public
2382
2400
  */
2383
2401
  export declare class CommitRef extends CommitRef_base {}
2402
+ declare const CreatedCommit_base: Schema.Class<CreatedCommit, Schema.Struct<{
2403
+ /** The new commit's sha. */
2404
+ readonly sha: Schema.String;
2405
+ /** The commit's web URL, as GitHub reported it. */
2406
+ readonly htmlUrl: Schema.String;
2407
+ }>, {}>;
2408
+ /**
2409
+ * A commit just created through the Git Database API: its sha and the URL
2410
+ * GitHub reports for viewing it.
2411
+ *
2412
+ * @remarks
2413
+ * `htmlUrl` is the `html_url` of the creation reply, so it carries the right
2414
+ * host on GitHub Enterprise Server with no host arithmetic.
2415
+ *
2416
+ * @public
2417
+ */
2418
+ export declare class CreatedCommit extends CreatedCommit_base {}
2384
2419
  /**
2385
2420
  * Commits and trees in GitHub's Git Database API.
2386
2421
  *
@@ -2400,6 +2435,12 @@ interface GitCommitShape {
2400
2435
  readonly tree: string;
2401
2436
  readonly parents: ReadonlyArray<string>;
2402
2437
  }) => Effect.Effect<string, GitHubError, Repo>;
2438
+ /** {@link GitCommitShape.createCommit}, also returning the commit's `html_url`. */
2439
+ readonly createCommitWithUrl: (options: {
2440
+ readonly message: string;
2441
+ readonly tree: string;
2442
+ readonly parents: ReadonlyArray<string>;
2443
+ }) => Effect.Effect<CreatedCommit, GitHubError, Repo>;
2403
2444
  /**
2404
2445
  * Write `changes` onto `branch` as one commit, returning its sha.
2405
2446
  *
@@ -2425,6 +2466,12 @@ interface GitCommitShape {
2425
2466
  readonly message: string;
2426
2467
  readonly changes: ReadonlyArray<FileChange>;
2427
2468
  }) => Effect.Effect<string, GitHubError, Repo>;
2469
+ /** {@link GitCommitShape.commitFiles}, also returning the commit's `html_url`. */
2470
+ readonly commitFilesWithUrl: (options: {
2471
+ readonly branch: string;
2472
+ readonly message: string;
2473
+ readonly changes: ReadonlyArray<FileChange>;
2474
+ }) => Effect.Effect<CreatedCommit, GitHubError, Repo>;
2428
2475
  }
2429
2476
  declare const GitCommit_base: Context.ServiceClass<GitCommit, "@effected/github/GitCommit", GitCommitShape>;
2430
2477
  /**
package/index.js CHANGED
@@ -6,7 +6,7 @@ import { Annotation, AnnotationLevel, CheckConclusion, CheckRun, CheckRunOutput,
6
6
  import { CodeScanning } from "./CodeScanning.js";
7
7
  import { DeploymentEnvironment } from "./DeploymentEnvironment.js";
8
8
  import { GitBranch } from "./GitBranch.js";
9
- import { CommitRef, FileChange, FileContent, FileDeletion, FileMode, GitCommit } from "./GitCommit.js";
9
+ import { CommitRef, CreatedCommit, FileChange, FileContent, FileDeletion, FileMode, GitCommit } from "./GitCommit.js";
10
10
  import { AppIdentity, BotIdentity, BotUser, GitHubApp, GitHubAppError, Installation, InstallationToken } from "./GitHubApp.js";
11
11
  import { GitHubClient, GitHubFixtures, RawFailure } from "./GitHubClient.js";
12
12
  import { CommitComparison, CommitFile, CommitSummary, FileStatus, GitHubCommit } from "./GitHubCommit.js";
@@ -31,4 +31,4 @@ import { ExtraPermission, PermissionGap, PermissionLevel, PermissionResult, Toke
31
31
  import { DispatchedRun, WorkflowDispatch, WorkflowRunStatus } from "./WorkflowDispatch.js";
32
32
  import { CLOSING_KEYWORDS, harvestIssueReferences, parseBareLineReference } from "@effected/github-references";
33
33
 
34
- 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, DeliveryAttempt, DeploymentEnvironment, DispatchedRun, ExtraPermission, FileChange, FileContent, FileDeletion, FileMode, FileStatus, GRAPHQL_ONLY_SETTINGS, GitBranch, GitCommit, GitHubApp, GitHubAppError, GitHubClient, GitHubCommit, GitHubContent, GitHubError, GitHubErrorKind, GitHubFixtures, GitHubGraphQLError, GitHubIssue, GitHubRelease, GitHubRepository, GitHubValidationCode, GitHubValidationEntry, GitTag, GraphQLDocument, GraphQLErrorEntry, Installation, InstallationToken, InstallationTokenStore, InvalidRepoRefError, IssueInfo, LinkedIssue, MergeMethod, 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 };
34
+ 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, ExtraPermission, FileChange, FileContent, FileDeletion, FileMode, FileStatus, GRAPHQL_ONLY_SETTINGS, GitBranch, GitCommit, GitHubApp, GitHubAppError, GitHubClient, GitHubCommit, GitHubContent, GitHubError, GitHubErrorKind, GitHubFixtures, GitHubGraphQLError, GitHubIssue, GitHubRelease, GitHubRepository, GitHubValidationCode, GitHubValidationEntry, GitTag, GraphQLDocument, GraphQLErrorEntry, Installation, InstallationToken, InstallationTokenStore, InvalidRepoRefError, IssueInfo, LinkedIssue, MergeMethod, 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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effected/github",
3
- "version": "0.28.0",
3
+ "version": "0.29.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.0",
44
44
  "@effected/oidc": "^0.4.0",
45
- "@effected/semver": "^0.21.0",
45
+ "@effected/semver": "^0.22.0",
46
46
  "@octokit/core": "^7.0.6",
47
47
  "@octokit/plugin-paginate-rest": "^16.0.0",
48
48
  "@octokit/types": "^18.0.0",