@noldova/git.hosting.protocol 0.0.3 → 0.0.5
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/package.json +4 -4
- package/src/api/index.d.ts +53 -11
- package/src/api/index.js +1 -0
- package/src/enums/review-decision.js +12 -0
- package/src/models/branch-pull-request.js +16 -4
- package/src/resources.js +2 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@noldova/git.hosting.protocol",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "The hosting protocol that each of Git's host modules implements: a reference to an issue or pull request, the item and its checks, a branch's pull request, a pull request draft, and the sign-in's account and device code.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"registry": "https://registry.npmjs.org/"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"@noldova/context.exceptions": ">=0.0.
|
|
34
|
-
"@noldova/context.json": ">=0.0.
|
|
33
|
+
"@noldova/context.exceptions": ">=0.0.9 <0.1.0",
|
|
34
|
+
"@noldova/context.json": ">=0.0.9 <0.1.0"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "ad122e1fee34ab2f437734bf34705ce9c1cac445"
|
|
37
37
|
}
|
package/src/api/index.d.ts
CHANGED
|
@@ -212,6 +212,40 @@ export declare const CheckState: {
|
|
|
212
212
|
*/
|
|
213
213
|
export type CheckState = (typeof CheckState)[keyof typeof CheckState];
|
|
214
214
|
|
|
215
|
+
/**
|
|
216
|
+
* Where a pull request's review stands, from each reviewer's latest review that approves or requests changes.
|
|
217
|
+
* A host counts the reviewers it takes to speak for the repository; GitHub's module takes its owner, members and collaborators, which is close to
|
|
218
|
+
* the people with write access but not exact.
|
|
219
|
+
*
|
|
220
|
+
* @example
|
|
221
|
+
* ```ts
|
|
222
|
+
* import { ReviewDecision } from "@noldova/git.hosting.protocol";
|
|
223
|
+
*
|
|
224
|
+
* console.log(ReviewDecision.ChangesRequested);
|
|
225
|
+
* ```
|
|
226
|
+
*/
|
|
227
|
+
export declare const ReviewDecision: {
|
|
228
|
+
/**
|
|
229
|
+
* No reviewer's latest review approves or requests changes.
|
|
230
|
+
*/
|
|
231
|
+
readonly Waiting: "Waiting";
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* A reviewer's latest review requests changes.
|
|
235
|
+
*/
|
|
236
|
+
readonly ChangesRequested: "ChangesRequested";
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* A reviewer's latest review approves, and none requests changes.
|
|
240
|
+
*/
|
|
241
|
+
readonly Approved: "Approved";
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Where a pull request's review stands.
|
|
246
|
+
*/
|
|
247
|
+
export type ReviewDecision = (typeof ReviewDecision)[keyof typeof ReviewDecision];
|
|
248
|
+
|
|
215
249
|
|
|
216
250
|
/**
|
|
217
251
|
* The base of the hosting protocol's own exceptions; catch it to catch them all.
|
|
@@ -1272,7 +1306,7 @@ export declare class BranchQuery {
|
|
|
1272
1306
|
}
|
|
1273
1307
|
|
|
1274
1308
|
/**
|
|
1275
|
-
* A branch's pull request on a host, or none,
|
|
1309
|
+
* A branch's pull request on a host, or none, the checks on its commit and where its review stands.
|
|
1276
1310
|
*
|
|
1277
1311
|
* @example
|
|
1278
1312
|
* ```ts
|
|
@@ -1294,16 +1328,22 @@ export declare class BranchPullRequest {
|
|
|
1294
1328
|
*/
|
|
1295
1329
|
public readonly checks: readonly HostCheck[];
|
|
1296
1330
|
|
|
1331
|
+
/**
|
|
1332
|
+
* Where the pull request's review stands, or null when there is no pull request.
|
|
1333
|
+
*/
|
|
1334
|
+
public readonly reviewDecision: ReviewDecision | null;
|
|
1335
|
+
|
|
1297
1336
|
/**
|
|
1298
1337
|
* Makes an answer from its parts.
|
|
1299
1338
|
*
|
|
1300
1339
|
* @param pullRequest The pull request, an item of the kind `PullRequest`, or null.
|
|
1301
1340
|
* @param checks The checks, none when the pull request is null.
|
|
1341
|
+
* @param reviewDecision Where the review stands, null exactly when the pull request is; `Waiting` for a pull request, and null without one, by default.
|
|
1302
1342
|
* @param reader The reader the values came from, so an error names the field by its path; omitted for values that didn't come from JSON.
|
|
1303
|
-
* @throws {HostingArgumentException} Without a reader, when the item isn't a pull request
|
|
1304
|
-
* as the parameter, `pullRequest` or `
|
|
1305
|
-
* @throws {HostingFieldException} With a reader, when the item isn't a pull request
|
|
1306
|
-
* field by its path, such as `$.checks`.
|
|
1343
|
+
* @throws {HostingArgumentException} Without a reader, when the item isn't a pull request, there are checks with no pull request, or the review
|
|
1344
|
+
* decision is null for a pull request or set without one, naming the field as the parameter, `pullRequest`, `checks` or `reviewDecision`.
|
|
1345
|
+
* @throws {HostingFieldException} With a reader, when the item isn't a pull request, there are checks with no pull request, or the review
|
|
1346
|
+
* decision is null for a pull request or set without one, naming the field by its path, such as `$.checks`.
|
|
1307
1347
|
* @example
|
|
1308
1348
|
* ```ts
|
|
1309
1349
|
* import { BranchPullRequest } from "@noldova/git.hosting.protocol";
|
|
@@ -1311,7 +1351,7 @@ export declare class BranchPullRequest {
|
|
|
1311
1351
|
* const none = new BranchPullRequest(null, []);
|
|
1312
1352
|
* ```
|
|
1313
1353
|
*/
|
|
1314
|
-
public constructor(pullRequest: HostItem | null, checks: readonly HostCheck[], reader?: JsonReader);
|
|
1354
|
+
public constructor(pullRequest: HostItem | null, checks: readonly HostCheck[], reviewDecision?: ReviewDecision | null, reader?: JsonReader);
|
|
1315
1355
|
|
|
1316
1356
|
/**
|
|
1317
1357
|
* The worst state among the checks, in the order `Failed`, `Running`, `Queued`, `Succeeded` and `Neutral`, or null when there are no checks.
|
|
@@ -1330,12 +1370,14 @@ export declare class BranchPullRequest {
|
|
|
1330
1370
|
/**
|
|
1331
1371
|
* Reads an answer from its JSON.
|
|
1332
1372
|
*
|
|
1333
|
-
* @param value The JSON, with
|
|
1373
|
+
* @param value The JSON, with the fields `toJson` writes; without `reviewDecision`, as an older module answers, a pull request's review reads as
|
|
1374
|
+
* `Waiting`.
|
|
1334
1375
|
* @param path The JSON's path, `$` by default.
|
|
1335
1376
|
* @returns The answer.
|
|
1336
|
-
* @throws {JsonException} When the value isn't an object,
|
|
1337
|
-
*
|
|
1338
|
-
*
|
|
1377
|
+
* @throws {JsonException} When the value isn't an object, a field is missing or of the wrong type, or the review decision isn't one of
|
|
1378
|
+
* `ReviewDecision`'s; it comes from `@noldova/context.json`.
|
|
1379
|
+
* @throws {HostingFieldException} When the value holds an unknown field, a field is out of its range, the item isn't a pull request,
|
|
1380
|
+
* there are checks with no pull request, or the review decision is null for a pull request or set without one.
|
|
1339
1381
|
* @example
|
|
1340
1382
|
* ```ts
|
|
1341
1383
|
* import { BranchPullRequest } from "@noldova/git.hosting.protocol";
|
|
@@ -1346,7 +1388,7 @@ export declare class BranchPullRequest {
|
|
|
1346
1388
|
public static fromJson(value: unknown, path?: string): BranchPullRequest;
|
|
1347
1389
|
|
|
1348
1390
|
/**
|
|
1349
|
-
* Writes the answer as JSON: `pullRequest`, null when there is none, and `
|
|
1391
|
+
* Writes the answer as JSON: `pullRequest`, null when there is none, `checks` and `reviewDecision`, null without a pull request.
|
|
1350
1392
|
*
|
|
1351
1393
|
* @returns The JSON.
|
|
1352
1394
|
* @example
|
package/src/api/index.js
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
export { CheckState } from "../enums/check-state.js";
|
|
9
9
|
export { ReferenceKind } from "../enums/reference-kind.js";
|
|
10
10
|
export { ReferenceState } from "../enums/reference-state.js";
|
|
11
|
+
export { ReviewDecision } from "../enums/review-decision.js";
|
|
11
12
|
export { SignInFailure } from "../enums/sign-in-failure.js";
|
|
12
13
|
export { SignInState } from "../enums/sign-in-state.js";
|
|
13
14
|
export { HostingArgumentException } from "../exceptions/hosting-argument.exception.js";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
export const ReviewDecision = {
|
|
9
|
+
Waiting: "Waiting",
|
|
10
|
+
ChangesRequested: "ChangesRequested",
|
|
11
|
+
Approved: "Approved"
|
|
12
|
+
};
|
|
@@ -8,23 +8,29 @@
|
|
|
8
8
|
import { JsonReader } from "@noldova/context.json";
|
|
9
9
|
import { CheckState } from "../enums/check-state.js";
|
|
10
10
|
import { ReferenceKind } from "../enums/reference-kind.js";
|
|
11
|
+
import { ReviewDecision } from "../enums/review-decision.js";
|
|
11
12
|
import { Resources } from "../resources.js";
|
|
12
13
|
import { FieldCheck } from "./field-check.js";
|
|
13
14
|
import { HostCheck } from "./host-check.js";
|
|
14
15
|
import { HostItem } from "./host-item.js";
|
|
15
16
|
export class BranchPullRequest {
|
|
16
|
-
static FIELDS = [Resources.pullRequestField, Resources.checksField];
|
|
17
|
+
static FIELDS = [Resources.pullRequestField, Resources.checksField, Resources.reviewDecisionField];
|
|
18
|
+
static DECISIONS = Object.values(ReviewDecision);
|
|
17
19
|
static WORST_FIRST = [CheckState.Failed, CheckState.Running, CheckState.Queued, CheckState.Succeeded,
|
|
18
20
|
CheckState.Neutral];
|
|
19
21
|
pullRequest;
|
|
20
22
|
checks;
|
|
21
|
-
|
|
23
|
+
reviewDecision;
|
|
24
|
+
constructor(pullRequest, checks, reviewDecision = pullRequest === null ? null : ReviewDecision.Waiting, reader) {
|
|
22
25
|
if (pullRequest !== null && pullRequest.kind !== ReferenceKind.PullRequest)
|
|
23
26
|
FieldCheck.fail(Resources.pullRequestField, Resources.pullRequestExpected, reader);
|
|
24
27
|
if (pullRequest === null && checks.length > 0)
|
|
25
28
|
FieldCheck.fail(Resources.checksField, Resources.checksExpected, reader);
|
|
29
|
+
if ((pullRequest === null) !== (reviewDecision === null))
|
|
30
|
+
FieldCheck.fail(Resources.reviewDecisionField, Resources.reviewDecisionExpected, reader);
|
|
26
31
|
this.pullRequest = pullRequest;
|
|
27
32
|
this.checks = [...checks];
|
|
33
|
+
this.reviewDecision = reviewDecision;
|
|
28
34
|
}
|
|
29
35
|
get checksState() {
|
|
30
36
|
return BranchPullRequest.WORST_FIRST.find(t => this.checks.some(check => check.state === t)) ?? null;
|
|
@@ -32,9 +38,15 @@ export class BranchPullRequest {
|
|
|
32
38
|
static fromJson(value, path) {
|
|
33
39
|
const reader = JsonReader.fromValue(value, path);
|
|
34
40
|
FieldCheck.refuseUnknownFields(reader, BranchPullRequest.FIELDS);
|
|
35
|
-
|
|
41
|
+
const pullRequest = FieldCheck.readNullableModel(reader, Resources.pullRequestField, HostItem.fromJson);
|
|
42
|
+
return new BranchPullRequest(pullRequest, reader.readObjectArray(Resources.checksField).map(t => HostCheck.fromJson(t.toJson(), t.path)), reader.hasField(Resources.reviewDecisionField) ? FieldCheck.readNullableMember(reader, Resources.reviewDecisionField, BranchPullRequest.DECISIONS)
|
|
43
|
+
: pullRequest === null ? null : ReviewDecision.Waiting, reader);
|
|
36
44
|
}
|
|
37
45
|
toJson() {
|
|
38
|
-
return {
|
|
46
|
+
return {
|
|
47
|
+
[Resources.pullRequestField]: this.pullRequest?.toJson() ?? null,
|
|
48
|
+
[Resources.checksField]: this.checks.map(t => t.toJson()),
|
|
49
|
+
[Resources.reviewDecisionField]: this.reviewDecision
|
|
50
|
+
};
|
|
39
51
|
}
|
|
40
52
|
}
|
package/src/resources.js
CHANGED
|
@@ -21,6 +21,7 @@ export class Resources {
|
|
|
21
21
|
static changesExpected = "changes exactly for a pull request";
|
|
22
22
|
static pullRequestExpected = "a pull request";
|
|
23
23
|
static checksExpected = "no checks, since there is no pull request";
|
|
24
|
+
static reviewDecisionExpected = "a review decision exactly for a pull request";
|
|
24
25
|
static otherBranchExpected = "a branch other than the head branch";
|
|
25
26
|
static commitPattern = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/;
|
|
26
27
|
static avatarExpected = "a PNG, JPEG, GIF or WebP image of at most 64 KiB as a base64 data address";
|
|
@@ -65,6 +66,7 @@ export class Resources {
|
|
|
65
66
|
static branchField = "branch";
|
|
66
67
|
static pullRequestField = "pullRequest";
|
|
67
68
|
static checksField = "checks";
|
|
69
|
+
static reviewDecisionField = "reviewDecision";
|
|
68
70
|
static bodyField = "body";
|
|
69
71
|
static isDraftField = "isDraft";
|
|
70
72
|
static formatFieldPath(parent, field) {
|