Update scripts

This commit is contained in:
Nick Cipollo
2019-12-12 18:46:17 -05:00
parent 7319d490c8
commit 455687cd65
6 changed files with 85 additions and 17 deletions

View File

@@ -9,6 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const ErrorMessage_1 = require("./ErrorMessage");
class Action {
constructor(inputs, releases, uploader) {
this.inputs = inputs;
@@ -17,12 +18,45 @@ class Action {
}
perform() {
return __awaiter(this, void 0, void 0, function* () {
const createResult = yield this.releases.create(this.inputs.tag, this.inputs.body, this.inputs.commit, this.inputs.draft, this.inputs.name);
const uploadUrl = yield this.createOrUpdateRelease();
const artifacts = this.inputs.artifacts;
if (artifacts.length > 0) {
yield this.uploader.uploadArtifacts(artifacts, createResult.data.upload_url);
yield this.uploader.uploadArtifacts(artifacts, uploadUrl);
}
});
}
createOrUpdateRelease() {
return __awaiter(this, void 0, void 0, function* () {
try {
return yield this.createRelease();
}
catch (error) {
if (this.releaseAlreadyExisted(error) && this.inputs.allowUpdates) {
return this.updateRelease();
}
else {
throw error;
}
}
});
}
createRelease() {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.releases.create(this.inputs.tag, this.inputs.body, this.inputs.commit, this.inputs.draft, this.inputs.name);
return response.data.upload_url;
});
}
releaseAlreadyExisted(error) {
const errorMessage = new ErrorMessage_1.ErrorMessage(error);
return errorMessage.hasErrorWithCode('already_exists');
}
updateRelease() {
return __awaiter(this, void 0, void 0, function* () {
const getResponse = yield this.releases.getByTag(this.inputs.tag);
const id = getResponse.data.id;
const response = yield this.releases.update(id, this.inputs.tag, this.inputs.body, this.inputs.commit, this.inputs.draft, this.inputs.name);
return response.data.upload_url;
});
}
}
exports.Action = Action;