Cleanup error classes and CI
This commit is contained in:
28
.github/workflows/build.yml
vendored
Normal file
28
.github/workflows/build.yml
vendored
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
name: "PR Checks"
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
check_pr:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v1
|
||||||
|
|
||||||
|
- name: "yarn install"
|
||||||
|
run: yarn install
|
||||||
|
|
||||||
|
- name: "yarn build"
|
||||||
|
run: yarn build
|
||||||
|
|
||||||
|
- name: "check for uncommitted changes"
|
||||||
|
# Ensure no changes, but ignore node_modules dir since dev/fresh ci deps installed.
|
||||||
|
run: |
|
||||||
|
git diff --exit-code --stat -- . ':!node_modules' \
|
||||||
|
|| (echo "##[error] found changed files after build. please 'yarn build && npm run format'" \
|
||||||
|
"and check in all changes" \
|
||||||
|
&& exit 1)
|
||||||
25
.github/workflows/checkin.yml
vendored
25
.github/workflows/checkin.yml
vendored
@@ -1,25 +0,0 @@
|
|||||||
name: "PR Checks"
|
|
||||||
on: [pull_request, push]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
check_pr:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v1
|
|
||||||
|
|
||||||
- name: "yarn install"
|
|
||||||
run: yarn install
|
|
||||||
|
|
||||||
- name: "yarn build"
|
|
||||||
run: yarn build
|
|
||||||
|
|
||||||
- name: "yarn test"
|
|
||||||
run: yarn test
|
|
||||||
|
|
||||||
- name: "check for uncommitted changes"
|
|
||||||
# Ensure no changes, but ignore node_modules dir since dev/fresh ci deps installed.
|
|
||||||
run: |
|
|
||||||
git diff --exit-code --stat -- . ':!node_modules' \
|
|
||||||
|| (echo "##[error] found changed files after build. please 'yarn build && npm run format'" \
|
|
||||||
"and check in all changes" \
|
|
||||||
&& exit 1)
|
|
||||||
14
.github/workflows/test.yml
vendored
Normal file
14
.github/workflows/test.yml
vendored
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
name: "Test"
|
||||||
|
on: [push, pull_request]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
check_pr:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v1
|
||||||
|
|
||||||
|
- name: "yarn install"
|
||||||
|
run: yarn install
|
||||||
|
|
||||||
|
- name: "yarn test"
|
||||||
|
run: yarn test
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
import { ErrorMessage } from "../src/ErrorMessage"
|
|
||||||
|
|
||||||
describe('ErrorMessage', () => {
|
|
||||||
|
|
||||||
describe('has error with code', () => {
|
|
||||||
const error = {
|
|
||||||
message: 'something bad happened',
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
code: 'missing',
|
|
||||||
resource: 'release'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: 'already_exists',
|
|
||||||
resource: 'release'
|
|
||||||
}
|
|
||||||
],
|
|
||||||
status: 422
|
|
||||||
}
|
|
||||||
|
|
||||||
it('does not have error', () => {
|
|
||||||
const errorMessage = new ErrorMessage(error)
|
|
||||||
expect(errorMessage.hasErrorWithCode('missing_field')).toBeFalsy()
|
|
||||||
})
|
|
||||||
|
|
||||||
it('has error', () => {
|
|
||||||
const errorMessage = new ErrorMessage(error)
|
|
||||||
expect(errorMessage.hasErrorWithCode('missing')).toBeTruthy()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
it('generates message with errors', () => {
|
|
||||||
const error = {
|
|
||||||
message: 'something bad happened',
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
code: 'missing',
|
|
||||||
resource: 'release'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: 'already_exists',
|
|
||||||
resource: 'release'
|
|
||||||
}
|
|
||||||
],
|
|
||||||
status: 422
|
|
||||||
}
|
|
||||||
|
|
||||||
const errorMessage = new ErrorMessage(error)
|
|
||||||
|
|
||||||
const expectedString = "Error 422: something bad happened\nErrors:\n- release does not exist.\n- release already exists."
|
|
||||||
expect(errorMessage.toString()).toBe(expectedString)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('generates message without errors', () => {
|
|
||||||
const error = {
|
|
||||||
message: 'something bad happened',
|
|
||||||
status: 422
|
|
||||||
}
|
|
||||||
|
|
||||||
const errorMessage = new ErrorMessage(error)
|
|
||||||
|
|
||||||
expect(errorMessage.toString()).toBe('Error 422: something bad happened')
|
|
||||||
})
|
|
||||||
|
|
||||||
it('provides error status', () => {
|
|
||||||
const error = { status: 404 }
|
|
||||||
const errorMessage = new ErrorMessage(error)
|
|
||||||
expect(errorMessage.status).toBe(404)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
@@ -1,99 +1,70 @@
|
|||||||
import { GithubError } from "../src/GithubError"
|
import { GithubError } from "../src/GithubError"
|
||||||
|
|
||||||
describe('GithubError', () => {
|
describe('ErrorMessage', () => {
|
||||||
|
|
||||||
it('provides error code', () => {
|
describe('has error with code', () => {
|
||||||
const error = {
|
const error = {
|
||||||
code: "missing"
|
message: 'something bad happened',
|
||||||
|
errors: [
|
||||||
|
{
|
||||||
|
code: 'missing',
|
||||||
|
resource: 'release'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
code: 'already_exists',
|
||||||
|
resource: 'release'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
status: 422
|
||||||
}
|
}
|
||||||
|
|
||||||
const githubError = new GithubError(error)
|
it('does not have error', () => {
|
||||||
|
|
||||||
expect(githubError.code).toBe('missing')
|
|
||||||
})
|
|
||||||
|
|
||||||
it('generates missing resource error message', () => {
|
|
||||||
const resource = "release"
|
|
||||||
const error = {
|
|
||||||
code: "missing",
|
|
||||||
resource: resource
|
|
||||||
}
|
|
||||||
|
|
||||||
const githubError = new GithubError(error)
|
|
||||||
const message = githubError.toString()
|
|
||||||
|
|
||||||
expect(message).toBe(`${resource} does not exist.`)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('generates missing field error message', () => {
|
|
||||||
const resource = "release"
|
|
||||||
const field = "body"
|
|
||||||
const error = {
|
|
||||||
code: "missing_field",
|
|
||||||
field: field,
|
|
||||||
resource: resource
|
|
||||||
}
|
|
||||||
|
|
||||||
const githubError = new GithubError(error)
|
|
||||||
const message = githubError.toString()
|
|
||||||
|
|
||||||
expect(message).toBe(`The ${field} field on ${resource} is missing.`)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('generates invalid field error message', () => {
|
|
||||||
const resource = "release"
|
|
||||||
const field = "body"
|
|
||||||
const error = {
|
|
||||||
code: "invalid",
|
|
||||||
field: field,
|
|
||||||
resource: resource
|
|
||||||
}
|
|
||||||
|
|
||||||
const githubError = new GithubError(error)
|
|
||||||
const message = githubError.toString()
|
|
||||||
|
|
||||||
expect(message).toBe(`The ${field} field on ${resource} is an invalid format.`)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('generates resource already exists error message', () => {
|
|
||||||
const resource = "release"
|
|
||||||
const field = "body"
|
|
||||||
const error = {
|
|
||||||
code: "already_exists",
|
|
||||||
resource: resource
|
|
||||||
}
|
|
||||||
|
|
||||||
const githubError = new GithubError(error)
|
|
||||||
const message = githubError.toString()
|
|
||||||
|
|
||||||
expect(message).toBe(`${resource} already exists.`)
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('generates custom error message', () => {
|
|
||||||
it('with documentation url', () => {
|
|
||||||
const url = "https://api.example.com"
|
|
||||||
const error = {
|
|
||||||
code: "custom",
|
|
||||||
message: "foo",
|
|
||||||
documentation_url: url
|
|
||||||
}
|
|
||||||
|
|
||||||
const githubError = new GithubError(error)
|
const githubError = new GithubError(error)
|
||||||
const message = githubError.toString()
|
expect(githubError.hasErrorWithCode('missing_field')).toBeFalsy()
|
||||||
|
|
||||||
expect(message).toBe(`foo\nPlease see ${url}.`)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('without documentation url', () => {
|
it('has error', () => {
|
||||||
const error = {
|
|
||||||
code: "custom",
|
|
||||||
message: "foo"
|
|
||||||
}
|
|
||||||
|
|
||||||
const githubError = new GithubError(error)
|
const githubError = new GithubError(error)
|
||||||
const message = githubError.toString()
|
expect(githubError.hasErrorWithCode('missing')).toBeTruthy()
|
||||||
|
|
||||||
expect(message).toBe('foo')
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('generates message with errors', () => {
|
||||||
|
const error = {
|
||||||
|
message: 'something bad happened',
|
||||||
|
errors: [
|
||||||
|
{
|
||||||
|
code: 'missing',
|
||||||
|
resource: 'release'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
code: 'already_exists',
|
||||||
|
resource: 'release'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
status: 422
|
||||||
|
}
|
||||||
|
|
||||||
|
const githubError = new GithubError(error)
|
||||||
|
|
||||||
|
const expectedString = "Error 422: something bad happened\nErrors:\n- release does not exist.\n- release already exists."
|
||||||
|
expect(githubError.toString()).toBe(expectedString)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('generates message without errors', () => {
|
||||||
|
const error = {
|
||||||
|
message: 'something bad happened',
|
||||||
|
status: 422
|
||||||
|
}
|
||||||
|
|
||||||
|
const githubError = new GithubError(error)
|
||||||
|
|
||||||
|
expect(githubError.toString()).toBe('Error 422: something bad happened')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('provides error status', () => {
|
||||||
|
const error = { status: 404 }
|
||||||
|
const githubError = new GithubError(error)
|
||||||
|
expect(githubError.status).toBe(404)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
98
__tests__/GithubErrorDetail.test.ts
Normal file
98
__tests__/GithubErrorDetail.test.ts
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
import { GithubErrorDetail } from "../src/GithubErrorDetail"
|
||||||
|
|
||||||
|
describe('GithubErrorDetail', () => {
|
||||||
|
|
||||||
|
it('provides error code', () => {
|
||||||
|
const error = {
|
||||||
|
code: "missing"
|
||||||
|
}
|
||||||
|
|
||||||
|
const detail = new GithubErrorDetail(error)
|
||||||
|
|
||||||
|
expect(detail.code).toBe('missing')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('generates missing resource error message', () => {
|
||||||
|
const resource = "release"
|
||||||
|
const error = {
|
||||||
|
code: "missing",
|
||||||
|
resource: resource
|
||||||
|
}
|
||||||
|
|
||||||
|
const detail = new GithubErrorDetail(error)
|
||||||
|
const message = detail.toString()
|
||||||
|
|
||||||
|
expect(message).toBe(`${resource} does not exist.`)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('generates missing field error message', () => {
|
||||||
|
const resource = "release"
|
||||||
|
const field = "body"
|
||||||
|
const error = {
|
||||||
|
code: "missing_field",
|
||||||
|
field: field,
|
||||||
|
resource: resource
|
||||||
|
}
|
||||||
|
|
||||||
|
const detail = new GithubErrorDetail(error)
|
||||||
|
const message = detail.toString()
|
||||||
|
|
||||||
|
expect(message).toBe(`The ${field} field on ${resource} is missing.`)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('generates invalid field error message', () => {
|
||||||
|
const resource = "release"
|
||||||
|
const field = "body"
|
||||||
|
const error = {
|
||||||
|
code: "invalid",
|
||||||
|
field: field,
|
||||||
|
resource: resource
|
||||||
|
}
|
||||||
|
|
||||||
|
const detail = new GithubErrorDetail(error)
|
||||||
|
const message = detail.toString()
|
||||||
|
|
||||||
|
expect(message).toBe(`The ${field} field on ${resource} is an invalid format.`)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('generates resource already exists error message', () => {
|
||||||
|
const resource = "release"
|
||||||
|
const error = {
|
||||||
|
code: "already_exists",
|
||||||
|
resource: resource
|
||||||
|
}
|
||||||
|
|
||||||
|
const detail = new GithubErrorDetail(error)
|
||||||
|
const message = detail.toString()
|
||||||
|
|
||||||
|
expect(message).toBe(`${resource} already exists.`)
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('generates custom error message', () => {
|
||||||
|
it('with documentation url', () => {
|
||||||
|
const url = "https://api.example.com"
|
||||||
|
const error = {
|
||||||
|
code: "custom",
|
||||||
|
message: "foo",
|
||||||
|
documentation_url: url
|
||||||
|
}
|
||||||
|
|
||||||
|
const detail = new GithubErrorDetail(error)
|
||||||
|
const message = detail.toString()
|
||||||
|
|
||||||
|
expect(message).toBe(`foo\nPlease see ${url}.`)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('without documentation url', () => {
|
||||||
|
const error = {
|
||||||
|
code: "custom",
|
||||||
|
message: "foo"
|
||||||
|
}
|
||||||
|
|
||||||
|
const detail = new GithubErrorDetail(error)
|
||||||
|
const message = detail.toString()
|
||||||
|
|
||||||
|
expect(message).toBe('foo')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -20,8 +20,8 @@ describe.skip('Integration Test', () => {
|
|||||||
const releases = new GithubReleases(inputs, git)
|
const releases = new GithubReleases(inputs, git)
|
||||||
const uploader = new GithubArtifactUploader(
|
const uploader = new GithubArtifactUploader(
|
||||||
releases,
|
releases,
|
||||||
|
inputs.replacesArtifacts,
|
||||||
inputs.artifactErrorsFailBuild,
|
inputs.artifactErrorsFailBuild,
|
||||||
inputs.replacesArtifacts
|
|
||||||
)
|
)
|
||||||
action = new Action(inputs, releases, uploader)
|
action = new Action(inputs, releases, uploader)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.Action = void 0;
|
exports.Action = void 0;
|
||||||
const ErrorMessage_1 = require("./ErrorMessage");
|
const GithubError_1 = require("./GithubError");
|
||||||
class Action {
|
class Action {
|
||||||
constructor(inputs, releases, uploader) {
|
constructor(inputs, releases, uploader) {
|
||||||
this.inputs = inputs;
|
this.inputs = inputs;
|
||||||
@@ -55,8 +55,8 @@ class Action {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
static noPublishedRelease(error) {
|
static noPublishedRelease(error) {
|
||||||
const errorMessage = new ErrorMessage_1.ErrorMessage(error);
|
const githubError = new GithubError_1.GithubError(error);
|
||||||
return errorMessage.status == 404;
|
return githubError.status == 404;
|
||||||
}
|
}
|
||||||
updateDraftOrCreateRelease() {
|
updateDraftOrCreateRelease() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
|||||||
@@ -1,40 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
|
||||||
exports.ErrorMessage = void 0;
|
|
||||||
const GithubError_1 = require("./GithubError");
|
|
||||||
class ErrorMessage {
|
|
||||||
constructor(error) {
|
|
||||||
this.error = error;
|
|
||||||
this.githubErrors = this.generateGithubErrors();
|
|
||||||
}
|
|
||||||
generateGithubErrors() {
|
|
||||||
const errors = this.error.errors;
|
|
||||||
if (errors instanceof Array) {
|
|
||||||
return errors.map((err) => new GithubError_1.GithubError(err));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
get status() {
|
|
||||||
return this.error.status;
|
|
||||||
}
|
|
||||||
hasErrorWithCode(code) {
|
|
||||||
return this.githubErrors.some((err) => err.code == code);
|
|
||||||
}
|
|
||||||
toString() {
|
|
||||||
const message = this.error.message;
|
|
||||||
const errors = this.githubErrors;
|
|
||||||
const status = this.status;
|
|
||||||
if (errors.length > 0) {
|
|
||||||
return `Error ${status}: ${message}\nErrors:\n${this.errorBulletedList(errors)}`;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return `Error ${status}: ${message}`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
errorBulletedList(errors) {
|
|
||||||
return errors.map((err) => `- ${err}`).join("\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
exports.ErrorMessage = ErrorMessage;
|
|
||||||
@@ -1,57 +1,40 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.GithubError = void 0;
|
exports.GithubError = void 0;
|
||||||
|
const GithubErrorDetail_1 = require("./GithubErrorDetail");
|
||||||
class GithubError {
|
class GithubError {
|
||||||
constructor(error) {
|
constructor(error) {
|
||||||
this.error = error;
|
this.error = error;
|
||||||
|
this.githubErrors = this.generateGithubErrors();
|
||||||
}
|
}
|
||||||
get code() {
|
generateGithubErrors() {
|
||||||
return this.error.code;
|
const errors = this.error.errors;
|
||||||
}
|
if (errors instanceof Array) {
|
||||||
toString() {
|
return errors.map((err) => new GithubErrorDetail_1.GithubErrorDetail(err));
|
||||||
const code = this.error.code;
|
|
||||||
switch (code) {
|
|
||||||
case 'missing':
|
|
||||||
return this.missingResourceMessage();
|
|
||||||
case 'missing_field':
|
|
||||||
return this.missingFieldMessage();
|
|
||||||
case 'invalid':
|
|
||||||
return this.invalidFieldMessage();
|
|
||||||
case 'already_exists':
|
|
||||||
return this.resourceAlreadyExists();
|
|
||||||
default:
|
|
||||||
return this.customErrorMessage();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
customErrorMessage() {
|
|
||||||
const message = this.error.message;
|
|
||||||
const documentation = this.error.documentation_url;
|
|
||||||
let documentationMessage;
|
|
||||||
if (documentation) {
|
|
||||||
documentationMessage = `\nPlease see ${documentation}.`;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
documentationMessage = "";
|
return [];
|
||||||
}
|
}
|
||||||
return `${message}${documentationMessage}`;
|
|
||||||
}
|
}
|
||||||
invalidFieldMessage() {
|
get status() {
|
||||||
const resource = this.error.resource;
|
return this.error.status;
|
||||||
const field = this.error.field;
|
|
||||||
return `The ${field} field on ${resource} is an invalid format.`;
|
|
||||||
}
|
}
|
||||||
missingResourceMessage() {
|
hasErrorWithCode(code) {
|
||||||
const resource = this.error.resource;
|
return this.githubErrors.some((err) => err.code == code);
|
||||||
return `${resource} does not exist.`;
|
|
||||||
}
|
}
|
||||||
missingFieldMessage() {
|
toString() {
|
||||||
const resource = this.error.resource;
|
const message = this.error.message;
|
||||||
const field = this.error.field;
|
const errors = this.githubErrors;
|
||||||
return `The ${field} field on ${resource} is missing.`;
|
const status = this.status;
|
||||||
|
if (errors.length > 0) {
|
||||||
|
return `Error ${status}: ${message}\nErrors:\n${this.errorBulletedList(errors)}`;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return `Error ${status}: ${message}`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
resourceAlreadyExists() {
|
errorBulletedList(errors) {
|
||||||
const resource = this.error.resource;
|
return errors.map((err) => `- ${err}`).join("\n");
|
||||||
return `${resource} already exists.`;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.GithubError = GithubError;
|
exports.GithubError = GithubError;
|
||||||
|
|||||||
57
lib/GithubErrorDetail.js
Normal file
57
lib/GithubErrorDetail.js
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.GithubErrorDetail = void 0;
|
||||||
|
class GithubErrorDetail {
|
||||||
|
constructor(error) {
|
||||||
|
this.error = error;
|
||||||
|
}
|
||||||
|
get code() {
|
||||||
|
return this.error.code;
|
||||||
|
}
|
||||||
|
toString() {
|
||||||
|
const code = this.error.code;
|
||||||
|
switch (code) {
|
||||||
|
case 'missing':
|
||||||
|
return this.missingResourceMessage();
|
||||||
|
case 'missing_field':
|
||||||
|
return this.missingFieldMessage();
|
||||||
|
case 'invalid':
|
||||||
|
return this.invalidFieldMessage();
|
||||||
|
case 'already_exists':
|
||||||
|
return this.resourceAlreadyExists();
|
||||||
|
default:
|
||||||
|
return this.customErrorMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
customErrorMessage() {
|
||||||
|
const message = this.error.message;
|
||||||
|
const documentation = this.error.documentation_url;
|
||||||
|
let documentationMessage;
|
||||||
|
if (documentation) {
|
||||||
|
documentationMessage = `\nPlease see ${documentation}.`;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
documentationMessage = "";
|
||||||
|
}
|
||||||
|
return `${message}${documentationMessage}`;
|
||||||
|
}
|
||||||
|
invalidFieldMessage() {
|
||||||
|
const resource = this.error.resource;
|
||||||
|
const field = this.error.field;
|
||||||
|
return `The ${field} field on ${resource} is an invalid format.`;
|
||||||
|
}
|
||||||
|
missingResourceMessage() {
|
||||||
|
const resource = this.error.resource;
|
||||||
|
return `${resource} does not exist.`;
|
||||||
|
}
|
||||||
|
missingFieldMessage() {
|
||||||
|
const resource = this.error.resource;
|
||||||
|
const field = this.error.field;
|
||||||
|
return `The ${field} field on ${resource} is missing.`;
|
||||||
|
}
|
||||||
|
resourceAlreadyExists() {
|
||||||
|
const resource = this.error.resource;
|
||||||
|
return `${resource} already exists.`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exports.GithubErrorDetail = GithubErrorDetail;
|
||||||
@@ -35,7 +35,7 @@ const Releases_1 = require("./Releases");
|
|||||||
const Action_1 = require("./Action");
|
const Action_1 = require("./Action");
|
||||||
const ArtifactUploader_1 = require("./ArtifactUploader");
|
const ArtifactUploader_1 = require("./ArtifactUploader");
|
||||||
const ArtifactGlobber_1 = require("./ArtifactGlobber");
|
const ArtifactGlobber_1 = require("./ArtifactGlobber");
|
||||||
const ErrorMessage_1 = require("./ErrorMessage");
|
const GithubError_1 = require("./GithubError");
|
||||||
function run() {
|
function run() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
try {
|
try {
|
||||||
@@ -43,8 +43,8 @@ function run() {
|
|||||||
yield action.perform();
|
yield action.perform();
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
const errorMessage = new ErrorMessage_1.ErrorMessage(error);
|
const githubError = new GithubError_1.GithubError(error);
|
||||||
core.setFailed(errorMessage.toString());
|
core.setFailed(githubError.toString());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -55,7 +55,7 @@ function createAction() {
|
|||||||
const globber = new ArtifactGlobber_1.FileArtifactGlobber();
|
const globber = new ArtifactGlobber_1.FileArtifactGlobber();
|
||||||
const inputs = new Inputs_1.CoreInputs(globber, context);
|
const inputs = new Inputs_1.CoreInputs(globber, context);
|
||||||
const releases = new Releases_1.GithubReleases(inputs, git);
|
const releases = new Releases_1.GithubReleases(inputs, git);
|
||||||
const uploader = new ArtifactUploader_1.GithubArtifactUploader(releases, inputs.replacesArtifacts);
|
const uploader = new ArtifactUploader_1.GithubArtifactUploader(releases, inputs.replacesArtifacts, inputs.artifactErrorsFailBuild);
|
||||||
return new Action_1.Action(inputs, releases, uploader);
|
return new Action_1.Action(inputs, releases, uploader);
|
||||||
}
|
}
|
||||||
run();
|
run();
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import {Inputs} from "./Inputs";
|
import {Inputs} from "./Inputs";
|
||||||
import {CreateReleaseResponse, Releases, UpdateReleaseResponse} from "./Releases";
|
import {CreateReleaseResponse, Releases, UpdateReleaseResponse} from "./Releases";
|
||||||
import {ArtifactUploader} from "./ArtifactUploader";
|
import {ArtifactUploader} from "./ArtifactUploader";
|
||||||
import {ErrorMessage} from "./ErrorMessage";
|
import {GithubError} from "./GithubError";
|
||||||
|
|
||||||
export class Action {
|
export class Action {
|
||||||
private inputs: Inputs
|
private inputs: Inputs
|
||||||
@@ -55,8 +55,8 @@ export class Action {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static noPublishedRelease(error: any): boolean {
|
private static noPublishedRelease(error: any): boolean {
|
||||||
const errorMessage = new ErrorMessage(error)
|
const githubError = new GithubError(error)
|
||||||
return errorMessage.status == 404
|
return githubError.status == 404
|
||||||
}
|
}
|
||||||
|
|
||||||
private async updateDraftOrCreateRelease(): Promise<CreateReleaseResponse | UpdateReleaseResponse> {
|
private async updateDraftOrCreateRelease(): Promise<CreateReleaseResponse | UpdateReleaseResponse> {
|
||||||
|
|||||||
@@ -1,44 +0,0 @@
|
|||||||
import {GithubError} from "./GithubError"
|
|
||||||
|
|
||||||
export class ErrorMessage {
|
|
||||||
private error: any
|
|
||||||
private githubErrors: GithubError[]
|
|
||||||
|
|
||||||
constructor(error: any) {
|
|
||||||
this.error = error
|
|
||||||
this.githubErrors = this.generateGithubErrors()
|
|
||||||
}
|
|
||||||
|
|
||||||
private generateGithubErrors(): GithubError[] {
|
|
||||||
const errors = this.error.errors
|
|
||||||
if (errors instanceof Array) {
|
|
||||||
return errors.map((err) => new GithubError(err))
|
|
||||||
} else {
|
|
||||||
return []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
get status(): number {
|
|
||||||
return this.error.status
|
|
||||||
}
|
|
||||||
|
|
||||||
hasErrorWithCode(code: String): boolean {
|
|
||||||
return this.githubErrors.some((err) => err.code == code)
|
|
||||||
}
|
|
||||||
|
|
||||||
toString(): string {
|
|
||||||
const message = this.error.message
|
|
||||||
const errors = this.githubErrors
|
|
||||||
const status = this.status
|
|
||||||
if (errors.length > 0) {
|
|
||||||
return `Error ${status}: ${message}\nErrors:\n${this.errorBulletedList(errors)}`
|
|
||||||
} else {
|
|
||||||
return `Error ${status}: ${message}`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private errorBulletedList(errors: GithubError[]): string {
|
|
||||||
return errors.map((err) => `- ${err}`).join("\n")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,65 +1,44 @@
|
|||||||
|
import {GithubErrorDetail} from "./GithubErrorDetail"
|
||||||
|
|
||||||
export class GithubError {
|
export class GithubError {
|
||||||
private error: any;
|
private error: any
|
||||||
|
private readonly githubErrors: GithubErrorDetail[]
|
||||||
|
|
||||||
constructor(error: any) {
|
constructor(error: any) {
|
||||||
this.error = error
|
this.error = error
|
||||||
|
this.githubErrors = this.generateGithubErrors()
|
||||||
}
|
}
|
||||||
|
|
||||||
get code(): string {
|
private generateGithubErrors(): GithubErrorDetail[] {
|
||||||
return this.error.code
|
const errors = this.error.errors
|
||||||
|
if (errors instanceof Array) {
|
||||||
|
return errors.map((err) => new GithubErrorDetail(err))
|
||||||
|
} else {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
get status(): number {
|
||||||
|
return this.error.status
|
||||||
|
}
|
||||||
|
|
||||||
|
hasErrorWithCode(code: String): boolean {
|
||||||
|
return this.githubErrors.some((err) => err.code == code)
|
||||||
}
|
}
|
||||||
|
|
||||||
toString(): string {
|
toString(): string {
|
||||||
const code = this.error.code
|
const message = this.error.message
|
||||||
switch (code) {
|
const errors = this.githubErrors
|
||||||
case 'missing':
|
const status = this.status
|
||||||
return this.missingResourceMessage()
|
if (errors.length > 0) {
|
||||||
case 'missing_field':
|
return `Error ${status}: ${message}\nErrors:\n${this.errorBulletedList(errors)}`
|
||||||
return this.missingFieldMessage()
|
|
||||||
case 'invalid':
|
|
||||||
return this.invalidFieldMessage()
|
|
||||||
case 'already_exists':
|
|
||||||
return this.resourceAlreadyExists()
|
|
||||||
default:
|
|
||||||
return this.customErrorMessage()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private customErrorMessage(): string {
|
|
||||||
const message = this.error.message;
|
|
||||||
const documentation = this.error.documentation_url
|
|
||||||
|
|
||||||
let documentationMessage: string
|
|
||||||
if (documentation) {
|
|
||||||
documentationMessage = `\nPlease see ${documentation}.`
|
|
||||||
} else {
|
} else {
|
||||||
documentationMessage = ""
|
return `Error ${status}: ${message}`
|
||||||
}
|
}
|
||||||
|
|
||||||
return `${message}${documentationMessage}`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private invalidFieldMessage(): string {
|
private errorBulletedList(errors: GithubErrorDetail[]): string {
|
||||||
const resource = this.error.resource
|
return errors.map((err) => `- ${err}`).join("\n")
|
||||||
const field = this.error.field
|
|
||||||
|
|
||||||
return `The ${field} field on ${resource} is an invalid format.`
|
|
||||||
}
|
|
||||||
|
|
||||||
private missingResourceMessage(): string {
|
|
||||||
const resource = this.error.resource
|
|
||||||
return `${resource} does not exist.`
|
|
||||||
}
|
|
||||||
|
|
||||||
private missingFieldMessage(): string {
|
|
||||||
const resource = this.error.resource
|
|
||||||
const field = this.error.field
|
|
||||||
|
|
||||||
return `The ${field} field on ${resource} is missing.`
|
|
||||||
}
|
|
||||||
|
|
||||||
private resourceAlreadyExists(): string {
|
|
||||||
const resource = this.error.resource
|
|
||||||
return `${resource} already exists.`
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
65
src/GithubErrorDetail.ts
Normal file
65
src/GithubErrorDetail.ts
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
export class GithubErrorDetail {
|
||||||
|
private error: any;
|
||||||
|
|
||||||
|
constructor(error: any) {
|
||||||
|
this.error = error
|
||||||
|
}
|
||||||
|
|
||||||
|
get code(): string {
|
||||||
|
return this.error.code
|
||||||
|
}
|
||||||
|
|
||||||
|
toString(): string {
|
||||||
|
const code = this.error.code
|
||||||
|
switch (code) {
|
||||||
|
case 'missing':
|
||||||
|
return this.missingResourceMessage()
|
||||||
|
case 'missing_field':
|
||||||
|
return this.missingFieldMessage()
|
||||||
|
case 'invalid':
|
||||||
|
return this.invalidFieldMessage()
|
||||||
|
case 'already_exists':
|
||||||
|
return this.resourceAlreadyExists()
|
||||||
|
default:
|
||||||
|
return this.customErrorMessage()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private customErrorMessage(): string {
|
||||||
|
const message = this.error.message;
|
||||||
|
const documentation = this.error.documentation_url
|
||||||
|
|
||||||
|
let documentationMessage: string
|
||||||
|
if (documentation) {
|
||||||
|
documentationMessage = `\nPlease see ${documentation}.`
|
||||||
|
} else {
|
||||||
|
documentationMessage = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
return `${message}${documentationMessage}`
|
||||||
|
}
|
||||||
|
|
||||||
|
private invalidFieldMessage(): string {
|
||||||
|
const resource = this.error.resource
|
||||||
|
const field = this.error.field
|
||||||
|
|
||||||
|
return `The ${field} field on ${resource} is an invalid format.`
|
||||||
|
}
|
||||||
|
|
||||||
|
private missingResourceMessage(): string {
|
||||||
|
const resource = this.error.resource
|
||||||
|
return `${resource} does not exist.`
|
||||||
|
}
|
||||||
|
|
||||||
|
private missingFieldMessage(): string {
|
||||||
|
const resource = this.error.resource
|
||||||
|
const field = this.error.field
|
||||||
|
|
||||||
|
return `The ${field} field on ${resource} is missing.`
|
||||||
|
}
|
||||||
|
|
||||||
|
private resourceAlreadyExists(): string {
|
||||||
|
const resource = this.error.resource
|
||||||
|
return `${resource} already exists.`
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,15 +5,15 @@ import { GithubReleases } from './Releases';
|
|||||||
import { Action } from './Action';
|
import { Action } from './Action';
|
||||||
import { GithubArtifactUploader } from './ArtifactUploader';
|
import { GithubArtifactUploader } from './ArtifactUploader';
|
||||||
import { FileArtifactGlobber } from './ArtifactGlobber';
|
import { FileArtifactGlobber } from './ArtifactGlobber';
|
||||||
import { ErrorMessage } from './ErrorMessage';
|
import { GithubError } from './GithubError';
|
||||||
|
|
||||||
async function run() {
|
async function run() {
|
||||||
try {
|
try {
|
||||||
const action = createAction()
|
const action = createAction()
|
||||||
await action.perform()
|
await action.perform()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const errorMessage = new ErrorMessage(error)
|
const githubError = new GithubError(error)
|
||||||
core.setFailed(errorMessage.toString());
|
core.setFailed(githubError.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user