Fixes #8 Add support for draft release updating

This commit is contained in:
Nick Cipollo
2020-01-02 22:03:30 -05:00
parent c8e9e33d90
commit 04d64ce68e
5 changed files with 131 additions and 36 deletions

View File

@@ -33,8 +33,8 @@ class Action {
return yield this.updateRelease(getResponse.data.id);
}
catch (error) {
if (this.noRelease(error)) {
return yield this.createRelease();
if (this.noPublishedRelease(error)) {
return yield this.updateDraftOrCreateRelease();
}
else {
throw error;
@@ -46,21 +46,42 @@ class Action {
}
});
}
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, this.inputs.prerelease);
return response.data.upload_url;
});
}
noRelease(error) {
const errorMessage = new ErrorMessage_1.ErrorMessage(error);
return errorMessage.status == 404;
}
updateRelease(id) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.releases.update(id, this.inputs.tag, this.inputs.body, this.inputs.commit, this.inputs.draft, this.inputs.name, this.inputs.prerelease);
return response.data.upload_url;
});
}
noPublishedRelease(error) {
const errorMessage = new ErrorMessage_1.ErrorMessage(error);
return errorMessage.status == 404;
}
updateDraftOrCreateRelease() {
return __awaiter(this, void 0, void 0, function* () {
const draftReleaseId = yield this.findMatchingDraftReleaseId();
if (draftReleaseId) {
return yield this.updateRelease(draftReleaseId);
}
else {
return yield this.createRelease();
}
});
}
findMatchingDraftReleaseId() {
var _a;
return __awaiter(this, void 0, void 0, function* () {
const tag = this.inputs.tag;
const response = yield this.releases.listReleases();
const releases = response.data;
const draftRelease = releases.find(release => release.draft && release.tag_name == tag);
return (_a = draftRelease) === null || _a === void 0 ? void 0 : _a.id;
});
}
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, this.inputs.prerelease);
return response.data.upload_url;
});
}
}
exports.Action = Action;

View File

@@ -28,6 +28,14 @@ class GithubReleases {
});
});
}
listReleases() {
return __awaiter(this, void 0, void 0, function* () {
return this.git.repos.listReleases({
owner: this.context.repo.owner,
repo: this.context.repo.repo
});
});
}
getByTag(tag) {
return __awaiter(this, void 0, void 0, function* () {
return this.git.repos.getReleaseByTag({