@noldova/git.hosting.protocol 0.0.0-stage → 0.0.2
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/LICENSE +21 -0
- package/README.md +6 -2
- package/package.json +35 -4
- package/src/api/index.d.ts +1472 -0
- package/src/api/index.js +27 -0
- package/src/enums/check-state.js +14 -0
- package/src/enums/reference-kind.js +11 -0
- package/src/enums/reference-state.js +15 -0
- package/src/enums/sign-in-failure.js +16 -0
- package/src/enums/sign-in-state.js +12 -0
- package/src/exceptions/hosting-argument.exception.js +18 -0
- package/src/exceptions/hosting-field.exception.js +18 -0
- package/src/exceptions/hosting-protocol.exception.js +13 -0
- package/src/models/branch-pull-request.js +40 -0
- package/src/models/branch-query.js +41 -0
- package/src/models/device-code.js +36 -0
- package/src/models/field-check.js +63 -0
- package/src/models/host-account.js +43 -0
- package/src/models/host-changes.js +49 -0
- package/src/models/host-check.js +34 -0
- package/src/models/host-item.js +80 -0
- package/src/models/host-person.js +34 -0
- package/src/models/host-reference.js +43 -0
- package/src/models/host-sign-in.js +57 -0
- package/src/models/hosting-names.js +21 -0
- package/src/models/pull-request-draft.js +53 -0
- package/src/resources.js +85 -0
package/src/api/index.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
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 { CheckState } from "../enums/check-state.js";
|
|
9
|
+
export { ReferenceKind } from "../enums/reference-kind.js";
|
|
10
|
+
export { ReferenceState } from "../enums/reference-state.js";
|
|
11
|
+
export { SignInFailure } from "../enums/sign-in-failure.js";
|
|
12
|
+
export { SignInState } from "../enums/sign-in-state.js";
|
|
13
|
+
export { HostingArgumentException } from "../exceptions/hosting-argument.exception.js";
|
|
14
|
+
export { HostingFieldException } from "../exceptions/hosting-field.exception.js";
|
|
15
|
+
export { HostingProtocolException } from "../exceptions/hosting-protocol.exception.js";
|
|
16
|
+
export { BranchPullRequest } from "../models/branch-pull-request.js";
|
|
17
|
+
export { BranchQuery } from "../models/branch-query.js";
|
|
18
|
+
export { DeviceCode } from "../models/device-code.js";
|
|
19
|
+
export { HostAccount } from "../models/host-account.js";
|
|
20
|
+
export { HostChanges } from "../models/host-changes.js";
|
|
21
|
+
export { HostCheck } from "../models/host-check.js";
|
|
22
|
+
export { HostItem } from "../models/host-item.js";
|
|
23
|
+
export { HostPerson } from "../models/host-person.js";
|
|
24
|
+
export { HostReference } from "../models/host-reference.js";
|
|
25
|
+
export { HostSignIn } from "../models/host-sign-in.js";
|
|
26
|
+
export { HostingNames } from "../models/hosting-names.js";
|
|
27
|
+
export { PullRequestDraft } from "../models/pull-request-draft.js";
|
|
@@ -0,0 +1,14 @@
|
|
|
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 CheckState = {
|
|
9
|
+
Queued: "Queued",
|
|
10
|
+
Running: "Running",
|
|
11
|
+
Succeeded: "Succeeded",
|
|
12
|
+
Failed: "Failed",
|
|
13
|
+
Neutral: "Neutral"
|
|
14
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
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 ReferenceKind = {
|
|
9
|
+
PullRequest: "PullRequest",
|
|
10
|
+
Issue: "Issue"
|
|
11
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
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 ReferenceState = {
|
|
9
|
+
Open: "Open",
|
|
10
|
+
Draft: "Draft",
|
|
11
|
+
Merged: "Merged",
|
|
12
|
+
Closed: "Closed",
|
|
13
|
+
ClosedDone: "ClosedDone",
|
|
14
|
+
ClosedNotPlanned: "ClosedNotPlanned"
|
|
15
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
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 SignInFailure = {
|
|
9
|
+
Expired: "Expired",
|
|
10
|
+
Denied: "Denied",
|
|
11
|
+
Revoked: "Revoked",
|
|
12
|
+
Unreachable: "Unreachable",
|
|
13
|
+
Refused: "Refused",
|
|
14
|
+
Unkept: "Unkept",
|
|
15
|
+
Unforgotten: "Unforgotten"
|
|
16
|
+
};
|
|
@@ -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 SignInState = {
|
|
9
|
+
SignedOut: "SignedOut",
|
|
10
|
+
Waiting: "Waiting",
|
|
11
|
+
SignedIn: "SignedIn"
|
|
12
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
import { Resources } from "../resources.js";
|
|
9
|
+
import { HostingProtocolException } from "./hosting-protocol.exception.js";
|
|
10
|
+
export class HostingArgumentException extends HostingProtocolException {
|
|
11
|
+
parameterName;
|
|
12
|
+
expectation;
|
|
13
|
+
constructor(parameterName, expectation) {
|
|
14
|
+
super(Resources.formatInvalidArgument(parameterName, expectation));
|
|
15
|
+
this.parameterName = parameterName;
|
|
16
|
+
this.expectation = expectation;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
import { Resources } from "../resources.js";
|
|
9
|
+
import { HostingProtocolException } from "./hosting-protocol.exception.js";
|
|
10
|
+
export class HostingFieldException extends HostingProtocolException {
|
|
11
|
+
field;
|
|
12
|
+
expectation;
|
|
13
|
+
constructor(field, expectation) {
|
|
14
|
+
super(Resources.formatInvalidField(field, expectation));
|
|
15
|
+
this.field = field;
|
|
16
|
+
this.expectation = expectation;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
import { Exception } from "@noldova/context.exceptions";
|
|
9
|
+
export class HostingProtocolException extends Exception {
|
|
10
|
+
constructor(message, options) {
|
|
11
|
+
super(message, options);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
import { JsonReader } from "@noldova/context.json";
|
|
9
|
+
import { CheckState } from "../enums/check-state.js";
|
|
10
|
+
import { ReferenceKind } from "../enums/reference-kind.js";
|
|
11
|
+
import { Resources } from "../resources.js";
|
|
12
|
+
import { FieldCheck } from "./field-check.js";
|
|
13
|
+
import { HostCheck } from "./host-check.js";
|
|
14
|
+
import { HostItem } from "./host-item.js";
|
|
15
|
+
export class BranchPullRequest {
|
|
16
|
+
static FIELDS = [Resources.pullRequestField, Resources.checksField];
|
|
17
|
+
static WORST_FIRST = [CheckState.Failed, CheckState.Running, CheckState.Queued, CheckState.Succeeded,
|
|
18
|
+
CheckState.Neutral];
|
|
19
|
+
pullRequest;
|
|
20
|
+
checks;
|
|
21
|
+
constructor(pullRequest, checks, reader) {
|
|
22
|
+
if (pullRequest !== null && pullRequest.kind !== ReferenceKind.PullRequest)
|
|
23
|
+
FieldCheck.fail(Resources.pullRequestField, Resources.pullRequestExpected, reader);
|
|
24
|
+
if (pullRequest === null && checks.length > 0)
|
|
25
|
+
FieldCheck.fail(Resources.checksField, Resources.checksExpected, reader);
|
|
26
|
+
this.pullRequest = pullRequest;
|
|
27
|
+
this.checks = [...checks];
|
|
28
|
+
}
|
|
29
|
+
get checksState() {
|
|
30
|
+
return BranchPullRequest.WORST_FIRST.find(t => this.checks.some(check => check.state === t)) ?? null;
|
|
31
|
+
}
|
|
32
|
+
static fromJson(value, path) {
|
|
33
|
+
const reader = JsonReader.fromValue(value, path);
|
|
34
|
+
FieldCheck.refuseUnknownFields(reader, BranchPullRequest.FIELDS);
|
|
35
|
+
return new BranchPullRequest(FieldCheck.readNullableModel(reader, Resources.pullRequestField, HostItem.fromJson), reader.readObjectArray(Resources.checksField).map(t => HostCheck.fromJson(t.toJson(), t.path)), reader);
|
|
36
|
+
}
|
|
37
|
+
toJson() {
|
|
38
|
+
return { [Resources.pullRequestField]: this.pullRequest?.toJson() ?? null, [Resources.checksField]: this.checks.map(t => t.toJson()) };
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
import { JsonReader } from "@noldova/context.json";
|
|
9
|
+
import { Resources } from "../resources.js";
|
|
10
|
+
import { FieldCheck } from "./field-check.js";
|
|
11
|
+
export class BranchQuery {
|
|
12
|
+
static FIELDS = [Resources.hostField, Resources.pathField, Resources.branchField, Resources.headCommitField];
|
|
13
|
+
host;
|
|
14
|
+
path;
|
|
15
|
+
branch;
|
|
16
|
+
headCommit;
|
|
17
|
+
constructor(host, path, branch, headCommit, reader) {
|
|
18
|
+
FieldCheck.requireText(host, Resources.hostField, reader);
|
|
19
|
+
FieldCheck.requirePath(path, Resources.pathField, reader);
|
|
20
|
+
FieldCheck.requireText(branch, Resources.branchField, reader);
|
|
21
|
+
if (headCommit !== null)
|
|
22
|
+
FieldCheck.requireCommit(headCommit, Resources.headCommitField, reader);
|
|
23
|
+
this.host = host;
|
|
24
|
+
this.path = path;
|
|
25
|
+
this.branch = branch;
|
|
26
|
+
this.headCommit = headCommit;
|
|
27
|
+
}
|
|
28
|
+
static fromJson(value, path) {
|
|
29
|
+
const reader = JsonReader.fromValue(value, path);
|
|
30
|
+
FieldCheck.refuseUnknownFields(reader, BranchQuery.FIELDS);
|
|
31
|
+
return new BranchQuery(reader.readString(Resources.hostField), reader.readString(Resources.pathField), reader.readString(Resources.branchField), reader.readNullableString(Resources.headCommitField), reader);
|
|
32
|
+
}
|
|
33
|
+
toJson() {
|
|
34
|
+
return {
|
|
35
|
+
[Resources.hostField]: this.host,
|
|
36
|
+
[Resources.pathField]: this.path,
|
|
37
|
+
[Resources.branchField]: this.branch,
|
|
38
|
+
[Resources.headCommitField]: this.headCommit
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
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
|
+
import { JsonReader } from "@noldova/context.json";
|
|
9
|
+
import { Resources } from "../resources.js";
|
|
10
|
+
import { FieldCheck } from "./field-check.js";
|
|
11
|
+
export class DeviceCode {
|
|
12
|
+
static FIELDS = [Resources.userCodeField, Resources.verificationUriField, Resources.expiresAtField];
|
|
13
|
+
userCode;
|
|
14
|
+
verificationUri;
|
|
15
|
+
expiresAt;
|
|
16
|
+
constructor(userCode, verificationUri, expiresAt, reader) {
|
|
17
|
+
FieldCheck.requireText(userCode, Resources.userCodeField, reader);
|
|
18
|
+
FieldCheck.requireHttps(verificationUri, Resources.verificationUriField, reader);
|
|
19
|
+
FieldCheck.requirePositive(expiresAt, Resources.expiresAtField, reader);
|
|
20
|
+
this.userCode = userCode;
|
|
21
|
+
this.verificationUri = verificationUri;
|
|
22
|
+
this.expiresAt = expiresAt;
|
|
23
|
+
}
|
|
24
|
+
static fromJson(value, path) {
|
|
25
|
+
const reader = JsonReader.fromValue(value, path);
|
|
26
|
+
FieldCheck.refuseUnknownFields(reader, DeviceCode.FIELDS);
|
|
27
|
+
return new DeviceCode(reader.readString(Resources.userCodeField), reader.readString(Resources.verificationUriField), reader.readInteger(Resources.expiresAtField), reader);
|
|
28
|
+
}
|
|
29
|
+
toJson() {
|
|
30
|
+
return {
|
|
31
|
+
[Resources.userCodeField]: this.userCode,
|
|
32
|
+
[Resources.verificationUriField]: this.verificationUri,
|
|
33
|
+
[Resources.expiresAtField]: this.expiresAt
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
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
|
+
import { HostingArgumentException } from "../exceptions/hosting-argument.exception.js";
|
|
9
|
+
import { HostingFieldException } from "../exceptions/hosting-field.exception.js";
|
|
10
|
+
import { Resources } from "../resources.js";
|
|
11
|
+
export class FieldCheck {
|
|
12
|
+
static fail(field, expectation, reader) {
|
|
13
|
+
if (reader === undefined)
|
|
14
|
+
throw new HostingArgumentException(field, expectation);
|
|
15
|
+
throw new HostingFieldException(Resources.formatFieldPath(reader.path, field), expectation);
|
|
16
|
+
}
|
|
17
|
+
static refuseUnknownFields(reader, known) {
|
|
18
|
+
for (const field of Object.keys(reader.toJson()))
|
|
19
|
+
if (!known.includes(field))
|
|
20
|
+
FieldCheck.fail(field, Resources.unknownField, reader);
|
|
21
|
+
}
|
|
22
|
+
static readNullableModel(reader, field, fromJson) {
|
|
23
|
+
const child = reader.readNullableObject(field);
|
|
24
|
+
return child === null ? null : fromJson(child.toJson(), child.path);
|
|
25
|
+
}
|
|
26
|
+
static readNullableMember(reader, field, members) {
|
|
27
|
+
return reader.readValue(field) === null ? null : reader.readOneOf(field, members);
|
|
28
|
+
}
|
|
29
|
+
static requireText(value, field, reader) {
|
|
30
|
+
if (value.trim().length === 0)
|
|
31
|
+
FieldCheck.fail(field, Resources.nonBlankTextExpected, reader);
|
|
32
|
+
}
|
|
33
|
+
static requirePositive(value, field, reader) {
|
|
34
|
+
if (!Number.isSafeInteger(value) || value < 1)
|
|
35
|
+
FieldCheck.fail(field, Resources.positiveExpected, reader);
|
|
36
|
+
}
|
|
37
|
+
static requireCount(value, field, reader) {
|
|
38
|
+
if (!Number.isSafeInteger(value) || value < 0)
|
|
39
|
+
FieldCheck.fail(field, Resources.countExpected, reader);
|
|
40
|
+
}
|
|
41
|
+
static requireName(value, field, reader) {
|
|
42
|
+
if (!Resources.namePattern.test(value))
|
|
43
|
+
FieldCheck.fail(field, Resources.nameExpected, reader);
|
|
44
|
+
}
|
|
45
|
+
static requirePath(value, field, reader) {
|
|
46
|
+
if (!Resources.pathPattern.test(value))
|
|
47
|
+
FieldCheck.fail(field, Resources.pathExpected, reader);
|
|
48
|
+
}
|
|
49
|
+
static requireCommit(value, field, reader) {
|
|
50
|
+
if (!Resources.commitPattern.test(value))
|
|
51
|
+
FieldCheck.fail(field, Resources.commitExpected, reader);
|
|
52
|
+
}
|
|
53
|
+
static requireAvatar(value, field, reader) {
|
|
54
|
+
const payload = Resources.avatarPattern.exec(value)?.[1];
|
|
55
|
+
if (payload === undefined || payload.length === 0 || payload.length > Resources.maximumAvatarLength)
|
|
56
|
+
FieldCheck.fail(field, Resources.avatarExpected, reader);
|
|
57
|
+
}
|
|
58
|
+
static requireHttps(value, field, reader) {
|
|
59
|
+
const url = URL.parse(value);
|
|
60
|
+
if (url === null || url.protocol !== Resources.httpsProtocol || url.username.length > 0 || url.password.length > 0)
|
|
61
|
+
FieldCheck.fail(field, Resources.httpsAddressExpected, reader);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
import { JsonReader } from "@noldova/context.json";
|
|
9
|
+
import { Resources } from "../resources.js";
|
|
10
|
+
import { FieldCheck } from "./field-check.js";
|
|
11
|
+
export class HostAccount {
|
|
12
|
+
static FIELDS = [Resources.loginField, Resources.nameField, Resources.avatarField, Resources.scopesField];
|
|
13
|
+
login;
|
|
14
|
+
name;
|
|
15
|
+
avatar;
|
|
16
|
+
scopes;
|
|
17
|
+
constructor(login, name, avatar, scopes, reader) {
|
|
18
|
+
FieldCheck.requireText(login, Resources.loginField, reader);
|
|
19
|
+
if (name !== null)
|
|
20
|
+
FieldCheck.requireText(name, Resources.nameField, reader);
|
|
21
|
+
if (avatar !== null)
|
|
22
|
+
FieldCheck.requireAvatar(avatar, Resources.avatarField, reader);
|
|
23
|
+
for (const scope of scopes)
|
|
24
|
+
FieldCheck.requireText(scope, Resources.scopesField, reader);
|
|
25
|
+
this.login = login;
|
|
26
|
+
this.name = name;
|
|
27
|
+
this.avatar = avatar;
|
|
28
|
+
this.scopes = [...scopes];
|
|
29
|
+
}
|
|
30
|
+
static fromJson(value, path) {
|
|
31
|
+
const reader = JsonReader.fromValue(value, path);
|
|
32
|
+
FieldCheck.refuseUnknownFields(reader, HostAccount.FIELDS);
|
|
33
|
+
return new HostAccount(reader.readString(Resources.loginField), reader.readNullableString(Resources.nameField), reader.readNullableString(Resources.avatarField), reader.readStringArray(Resources.scopesField), reader);
|
|
34
|
+
}
|
|
35
|
+
toJson() {
|
|
36
|
+
return {
|
|
37
|
+
[Resources.loginField]: this.login,
|
|
38
|
+
[Resources.nameField]: this.name,
|
|
39
|
+
[Resources.avatarField]: this.avatar,
|
|
40
|
+
[Resources.scopesField]: [...this.scopes]
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
import { JsonReader } from "@noldova/context.json";
|
|
9
|
+
import { Resources } from "../resources.js";
|
|
10
|
+
import { FieldCheck } from "./field-check.js";
|
|
11
|
+
export class HostChanges {
|
|
12
|
+
static FIELDS = [Resources.additionsField, Resources.deletionsField, Resources.changedFilesField,
|
|
13
|
+
Resources.headBranchField, Resources.baseBranchField, Resources.headCommitField];
|
|
14
|
+
additions;
|
|
15
|
+
deletions;
|
|
16
|
+
changedFiles;
|
|
17
|
+
headBranch;
|
|
18
|
+
baseBranch;
|
|
19
|
+
headCommit;
|
|
20
|
+
constructor(additions, deletions, changedFiles, headBranch, baseBranch, headCommit, reader) {
|
|
21
|
+
FieldCheck.requireCount(additions, Resources.additionsField, reader);
|
|
22
|
+
FieldCheck.requireCount(deletions, Resources.deletionsField, reader);
|
|
23
|
+
FieldCheck.requireCount(changedFiles, Resources.changedFilesField, reader);
|
|
24
|
+
FieldCheck.requireText(headBranch, Resources.headBranchField, reader);
|
|
25
|
+
FieldCheck.requireText(baseBranch, Resources.baseBranchField, reader);
|
|
26
|
+
FieldCheck.requireCommit(headCommit, Resources.headCommitField, reader);
|
|
27
|
+
this.additions = additions;
|
|
28
|
+
this.deletions = deletions;
|
|
29
|
+
this.changedFiles = changedFiles;
|
|
30
|
+
this.headBranch = headBranch;
|
|
31
|
+
this.baseBranch = baseBranch;
|
|
32
|
+
this.headCommit = headCommit;
|
|
33
|
+
}
|
|
34
|
+
static fromJson(value, path) {
|
|
35
|
+
const reader = JsonReader.fromValue(value, path);
|
|
36
|
+
FieldCheck.refuseUnknownFields(reader, HostChanges.FIELDS);
|
|
37
|
+
return new HostChanges(reader.readInteger(Resources.additionsField), reader.readInteger(Resources.deletionsField), reader.readInteger(Resources.changedFilesField), reader.readString(Resources.headBranchField), reader.readString(Resources.baseBranchField), reader.readString(Resources.headCommitField), reader);
|
|
38
|
+
}
|
|
39
|
+
toJson() {
|
|
40
|
+
return {
|
|
41
|
+
[Resources.additionsField]: this.additions,
|
|
42
|
+
[Resources.deletionsField]: this.deletions,
|
|
43
|
+
[Resources.changedFilesField]: this.changedFiles,
|
|
44
|
+
[Resources.headBranchField]: this.headBranch,
|
|
45
|
+
[Resources.baseBranchField]: this.baseBranch,
|
|
46
|
+
[Resources.headCommitField]: this.headCommit
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
import { JsonReader } from "@noldova/context.json";
|
|
9
|
+
import { CheckState } from "../enums/check-state.js";
|
|
10
|
+
import { Resources } from "../resources.js";
|
|
11
|
+
import { FieldCheck } from "./field-check.js";
|
|
12
|
+
export class HostCheck {
|
|
13
|
+
static FIELDS = [Resources.nameField, Resources.stateField, Resources.urlField];
|
|
14
|
+
static STATES = Object.values(CheckState);
|
|
15
|
+
name;
|
|
16
|
+
state;
|
|
17
|
+
url;
|
|
18
|
+
constructor(name, state, url, reader) {
|
|
19
|
+
FieldCheck.requireText(name, Resources.nameField, reader);
|
|
20
|
+
if (url !== null)
|
|
21
|
+
FieldCheck.requireHttps(url, Resources.urlField, reader);
|
|
22
|
+
this.name = name;
|
|
23
|
+
this.state = state;
|
|
24
|
+
this.url = url;
|
|
25
|
+
}
|
|
26
|
+
static fromJson(value, path) {
|
|
27
|
+
const reader = JsonReader.fromValue(value, path);
|
|
28
|
+
FieldCheck.refuseUnknownFields(reader, HostCheck.FIELDS);
|
|
29
|
+
return new HostCheck(reader.readString(Resources.nameField), reader.readOneOf(Resources.stateField, HostCheck.STATES), reader.readNullableString(Resources.urlField), reader);
|
|
30
|
+
}
|
|
31
|
+
toJson() {
|
|
32
|
+
return { [Resources.nameField]: this.name, [Resources.stateField]: this.state, [Resources.urlField]: this.url };
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
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
|
+
import { JsonReader } from "@noldova/context.json";
|
|
9
|
+
import { ReferenceKind } from "../enums/reference-kind.js";
|
|
10
|
+
import { ReferenceState } from "../enums/reference-state.js";
|
|
11
|
+
import { Resources } from "../resources.js";
|
|
12
|
+
import { FieldCheck } from "./field-check.js";
|
|
13
|
+
import { HostChanges } from "./host-changes.js";
|
|
14
|
+
import { HostPerson } from "./host-person.js";
|
|
15
|
+
import { HostReference } from "./host-reference.js";
|
|
16
|
+
export class HostItem {
|
|
17
|
+
static FIELDS = [Resources.referenceField, Resources.kindField, Resources.stateField, Resources.titleField,
|
|
18
|
+
Resources.urlField, Resources.authorField, Resources.createdAtField, Resources.closedAtField, Resources.commentsField, Resources.changesField];
|
|
19
|
+
static KINDS = Object.values(ReferenceKind);
|
|
20
|
+
static STATES = Object.values(ReferenceState);
|
|
21
|
+
static PULL_REQUEST_STATES = [ReferenceState.Open, ReferenceState.Draft, ReferenceState.Merged,
|
|
22
|
+
ReferenceState.Closed];
|
|
23
|
+
static ISSUE_STATES = [ReferenceState.Open, ReferenceState.ClosedDone, ReferenceState.ClosedNotPlanned];
|
|
24
|
+
static OPEN_STATES = [ReferenceState.Open, ReferenceState.Draft];
|
|
25
|
+
reference;
|
|
26
|
+
kind;
|
|
27
|
+
state;
|
|
28
|
+
title;
|
|
29
|
+
url;
|
|
30
|
+
author;
|
|
31
|
+
createdAt;
|
|
32
|
+
closedAt;
|
|
33
|
+
comments;
|
|
34
|
+
changes;
|
|
35
|
+
constructor(reference, kind, state, title, url, author, createdAt, closedAt, comments, changes, reader) {
|
|
36
|
+
const isPullRequest = kind === ReferenceKind.PullRequest;
|
|
37
|
+
if (!(isPullRequest ? HostItem.PULL_REQUEST_STATES : HostItem.ISSUE_STATES).includes(state))
|
|
38
|
+
FieldCheck.fail(Resources.stateField, isPullRequest ? Resources.pullRequestStateExpected : Resources.issueStateExpected, reader);
|
|
39
|
+
FieldCheck.requireText(title, Resources.titleField, reader);
|
|
40
|
+
FieldCheck.requireHttps(url, Resources.urlField, reader);
|
|
41
|
+
FieldCheck.requirePositive(createdAt, Resources.createdAtField, reader);
|
|
42
|
+
if (HostItem.OPEN_STATES.includes(state) !== (closedAt === null))
|
|
43
|
+
FieldCheck.fail(Resources.closedAtField, Resources.closedAtExpected, reader);
|
|
44
|
+
if (closedAt !== null)
|
|
45
|
+
FieldCheck.requirePositive(closedAt, Resources.closedAtField, reader);
|
|
46
|
+
FieldCheck.requireCount(comments, Resources.commentsField, reader);
|
|
47
|
+
if (isPullRequest !== (changes !== null))
|
|
48
|
+
FieldCheck.fail(Resources.changesField, Resources.changesExpected, reader);
|
|
49
|
+
this.reference = reference;
|
|
50
|
+
this.kind = kind;
|
|
51
|
+
this.state = state;
|
|
52
|
+
this.title = title;
|
|
53
|
+
this.url = url;
|
|
54
|
+
this.author = author;
|
|
55
|
+
this.createdAt = createdAt;
|
|
56
|
+
this.closedAt = closedAt;
|
|
57
|
+
this.comments = comments;
|
|
58
|
+
this.changes = changes;
|
|
59
|
+
}
|
|
60
|
+
static fromJson(value, path) {
|
|
61
|
+
const reader = JsonReader.fromValue(value, path);
|
|
62
|
+
FieldCheck.refuseUnknownFields(reader, HostItem.FIELDS);
|
|
63
|
+
const reference = reader.readObject(Resources.referenceField);
|
|
64
|
+
return new HostItem(HostReference.fromJson(reference.toJson(), reference.path), reader.readOneOf(Resources.kindField, HostItem.KINDS), reader.readOneOf(Resources.stateField, HostItem.STATES), reader.readString(Resources.titleField), reader.readString(Resources.urlField), FieldCheck.readNullableModel(reader, Resources.authorField, HostPerson.fromJson), reader.readInteger(Resources.createdAtField), reader.readNullableInteger(Resources.closedAtField), reader.readInteger(Resources.commentsField), FieldCheck.readNullableModel(reader, Resources.changesField, HostChanges.fromJson), reader);
|
|
65
|
+
}
|
|
66
|
+
toJson() {
|
|
67
|
+
return {
|
|
68
|
+
[Resources.referenceField]: this.reference.toJson(),
|
|
69
|
+
[Resources.kindField]: this.kind,
|
|
70
|
+
[Resources.stateField]: this.state,
|
|
71
|
+
[Resources.titleField]: this.title,
|
|
72
|
+
[Resources.urlField]: this.url,
|
|
73
|
+
[Resources.authorField]: this.author?.toJson() ?? null,
|
|
74
|
+
[Resources.createdAtField]: this.createdAt,
|
|
75
|
+
[Resources.closedAtField]: this.closedAt,
|
|
76
|
+
[Resources.commentsField]: this.comments,
|
|
77
|
+
[Resources.changesField]: this.changes?.toJson() ?? null
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
import { JsonReader } from "@noldova/context.json";
|
|
9
|
+
import { Resources } from "../resources.js";
|
|
10
|
+
import { FieldCheck } from "./field-check.js";
|
|
11
|
+
export class HostPerson {
|
|
12
|
+
static FIELDS = [Resources.loginField, Resources.avatarField, Resources.urlField];
|
|
13
|
+
login;
|
|
14
|
+
avatar;
|
|
15
|
+
url;
|
|
16
|
+
constructor(login, avatar, url, reader) {
|
|
17
|
+
FieldCheck.requireText(login, Resources.loginField, reader);
|
|
18
|
+
if (avatar !== null)
|
|
19
|
+
FieldCheck.requireAvatar(avatar, Resources.avatarField, reader);
|
|
20
|
+
if (url !== null)
|
|
21
|
+
FieldCheck.requireHttps(url, Resources.urlField, reader);
|
|
22
|
+
this.login = login;
|
|
23
|
+
this.avatar = avatar;
|
|
24
|
+
this.url = url;
|
|
25
|
+
}
|
|
26
|
+
static fromJson(value, path) {
|
|
27
|
+
const reader = JsonReader.fromValue(value, path);
|
|
28
|
+
FieldCheck.refuseUnknownFields(reader, HostPerson.FIELDS);
|
|
29
|
+
return new HostPerson(reader.readString(Resources.loginField), reader.readNullableString(Resources.avatarField), reader.readNullableString(Resources.urlField), reader);
|
|
30
|
+
}
|
|
31
|
+
toJson() {
|
|
32
|
+
return { [Resources.loginField]: this.login, [Resources.avatarField]: this.avatar, [Resources.urlField]: this.url };
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
import { JsonReader } from "@noldova/context.json";
|
|
9
|
+
import { Resources } from "../resources.js";
|
|
10
|
+
import { FieldCheck } from "./field-check.js";
|
|
11
|
+
export class HostReference {
|
|
12
|
+
static FIELDS = [Resources.hostField, Resources.ownerField, Resources.repositoryField, Resources.numberField];
|
|
13
|
+
host;
|
|
14
|
+
owner;
|
|
15
|
+
repository;
|
|
16
|
+
number;
|
|
17
|
+
constructor(host, owner, repository, number, reader) {
|
|
18
|
+
FieldCheck.requireText(host, Resources.hostField, reader);
|
|
19
|
+
FieldCheck.requirePath(owner, Resources.ownerField, reader);
|
|
20
|
+
FieldCheck.requireName(repository, Resources.repositoryField, reader);
|
|
21
|
+
FieldCheck.requirePositive(number, Resources.numberField, reader);
|
|
22
|
+
this.host = host;
|
|
23
|
+
this.owner = owner;
|
|
24
|
+
this.repository = repository;
|
|
25
|
+
this.number = number;
|
|
26
|
+
}
|
|
27
|
+
get text() {
|
|
28
|
+
return Resources.formatReference(this.owner, this.repository, this.number);
|
|
29
|
+
}
|
|
30
|
+
static fromJson(value, path) {
|
|
31
|
+
const reader = JsonReader.fromValue(value, path);
|
|
32
|
+
FieldCheck.refuseUnknownFields(reader, HostReference.FIELDS);
|
|
33
|
+
return new HostReference(reader.readString(Resources.hostField), reader.readString(Resources.ownerField), reader.readString(Resources.repositoryField), reader.readInteger(Resources.numberField), reader);
|
|
34
|
+
}
|
|
35
|
+
toJson() {
|
|
36
|
+
return {
|
|
37
|
+
[Resources.hostField]: this.host,
|
|
38
|
+
[Resources.ownerField]: this.owner,
|
|
39
|
+
[Resources.repositoryField]: this.repository,
|
|
40
|
+
[Resources.numberField]: this.number
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
}
|