Skip to content

Commit

Permalink
Check that there are releases.
Browse files Browse the repository at this point in the history
Previously if there were no releases the user would get an error that
references must be not be empty. It took me awhile to realize that an
empty reference there was because there was no release. I incorrectly
assumed that tags = releases. Thats not the case. While tags show up as
releases, you have to create an actual release for getLatestRelease to
work.

Also fix some !! truthy/falsey comparsions.
  • Loading branch information
metcalfc committed Mar 29, 2020
1 parent 86c53b2 commit 09ec384
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,22 @@ async function run() {
const { owner, repo } = github.context.repo;
const regexp = /^[\.A-Za-z0-9_-]*$/;

if (!headRef) {
if (!!headRef) {
headRef = github.context.sha;
}

if (!baseRef) {
if (!!baseRef) {
const latestRelease = await octokit.repos.getLatestRelease({
owner: owner,
repo: repo
});
baseRef = latestRelease.data.tag_name;
if (!!latestRelease) {
baseRef = latestRelease.data.tag_name;
} else {
core.setFailed(
`There are no releases on ${owner}/${repo}. Tags are not releases.`
);
}
}

console.log(`head-ref: ${headRef}`);
Expand All @@ -36,9 +42,9 @@ async function run() {
) {
getChangelog(headRef, baseRef, owner + "/" + repo);
} else {
const regexError =
"Branch names must contain only numbers, strings, underscores, periods, and dashes.";
core.setFailed(regexError);
core.setFailed(
"Branch names must contain only numbers, strings, underscores, periods, and dashes."
);
}
} catch (error) {
core.setFailed(error.message);
Expand Down

0 comments on commit 09ec384

Please sign in to comment.