Skip to content

Commit d3cec0e

Browse files
committed
Handle empty ref
1 parent 98300ea commit d3cec0e

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

__tests__/main.test.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ test("Unsupported prerelease tag", async () => {
136136
test("Not a tag", async () => {
137137
await expect(
138138
calculateTags("TOKEN", "owner", "repo", "something/else", "")
139-
).rejects.toEqual(new Error("Not a tag: something/else"));
139+
).rejects.toEqual(new Error("Not a tag or branch: something/else"));
140140
});
141141

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

148+
test("No ref", async () => {
149+
const tags = await calculateTags("TOKEN", "owner", "repo", null, "");
150+
expect(tags).toEqual([]);
151+
});
152+
148153
test("Prefix", async () => {
149154
const scope = nock("https://api.github.com")
150155
.get("/repos/owner/repo/tags")

src/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,17 @@ function supportedPrerelease(pre) {
1414
async function calculateTags(token, owner, repo, ref, prefix) {
1515
core.debug(`ref: ${ref}`);
1616

17+
if (!ref) {
18+
core.debug("No ref");
19+
return [];
20+
}
1721
if (ref.startsWith("refs/heads/")) {
1822
const branch = ref.substring(11);
19-
core.debug(`Branch: branch`);
23+
core.debug(`Branch: ${branch}`);
2024
return [`${prefix}${branch}`];
2125
}
2226
if (!ref.startsWith("refs/tags/")) {
23-
throw new Error(`Not a tag: ${ref}`);
27+
throw new Error(`Not a tag or branch: ${ref}`);
2428
}
2529

2630
const currentTag = ref.substring(10);

0 commit comments

Comments
 (0)