Skip to content

Commit

Permalink
Merge pull request #38 from manics/noref
Browse files Browse the repository at this point in the history
Handle empty ref
  • Loading branch information
manics authored Feb 10, 2021
2 parents 98300ea + 449c623 commit 1a08fa6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
7 changes: 6 additions & 1 deletion __tests__/main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ test("Unsupported prerelease tag", async () => {
test("Not a tag", async () => {
await expect(
calculateTags("TOKEN", "owner", "repo", "something/else", "")
).rejects.toEqual(new Error("Not a tag: something/else"));
).rejects.toEqual(new Error("Not a tag or branch: something/else"));
});

test("Invalid semver tag", async () => {
Expand All @@ -145,6 +145,11 @@ test("Invalid semver tag", async () => {
).rejects.toEqual(new Error("Invalid semver tag: v1"));
});

test("No ref", async () => {
const tags = await calculateTags("TOKEN", "owner", "repo", null, "");
expect(tags).toEqual([]);
});

test("Prefix", async () => {
const scope = nock("https://api.github.com")
.get("/repos/owner/repo/tags")
Expand Down
8 changes: 6 additions & 2 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@ function supportedPrerelease(pre) {
async function calculateTags(token, owner, repo, ref, prefix) {
core.debug(`ref: ${ref}`);

if (!ref) {
core.debug("No ref");
return [];
}
if (ref.startsWith("refs/heads/")) {
const branch = ref.substring(11);
core.debug(`Branch: branch`);
core.debug(`Branch: ${branch}`);
return [`${prefix}${branch}`];
}
if (!ref.startsWith("refs/tags/")) {
throw new Error(`Not a tag: ${ref}`);
throw new Error(`Not a tag or branch: ${ref}`);
}

const currentTag = ref.substring(10);
Expand Down

0 comments on commit 1a08fa6

Please sign in to comment.