Skip to content

Commit

Permalink
Merge pull request #29 from wardellbagby/wardell/fix-tag-deletion
Browse files Browse the repository at this point in the history
Fix issue where deleting tags failed
  • Loading branch information
thadguidry authored Mar 24, 2023
2 parents 488bcdd + d416162 commit 7550ea1
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 28 deletions.
30 changes: 15 additions & 15 deletions dist/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7762,9 +7762,6 @@ Support boolean input list: \`true | True | TRUE | false | False | FALSE\``);
}
});

// utils.ts
var createTagRef = (tagName) => `refs/tags/${tagName}`;

// index.ts
var import_github = __toESM(require_github());
var import_core = __toESM(require_core());
Expand All @@ -7783,17 +7780,20 @@ function log(header, message, level = "default") {
}
}
async function deleteTag(octokit, { owner, repo }, tagName) {
const ref = createTagRef(tagName);
try {
await octokit.rest.git.deleteRef({
owner,
repo,
ref
ref: `tags/${tagName}`
});
log("\u2705", `"${tagName}" deleted successfully!`);
} catch (error2) {
if (error2 instanceof Error) {
log("\u{1F336}", `failed to delete ref "${ref}" <- ${error2.message}`, "error");
log(
"\u{1F6D1}",
`failed to delete tag "${tagName}" <- ${error2.message}`,
"error"
);
if (error2.message === "Reference does not exist") {
log(
"\u{1F615}",
Expand All @@ -7802,15 +7802,15 @@ async function deleteTag(octokit, { owner, repo }, tagName) {
);
} else {
log(
"\u{1F336}",
"\u{1F6D1}",
`An error occurred while deleting the tag "${tagName}"`,
"error"
);
process.exit(1);
}
} else {
log(
"\u{1F336}",
"\u{1F6D1}",
`An error occurred while deleting the tag "${tagName}"`,
"error"
);
Expand All @@ -7828,9 +7828,9 @@ async function deleteReleases(octokit, qualifiedRepo, tagName) {
releaseIds = (releases.data ?? []).filter(({ tag_name, draft }) => tag_name === tagName && !draft).map(({ id }) => id);
} catch (error2) {
if (error2 instanceof Error) {
log("\u{1F336}", `failed to get list of releases <- ${error2.message}`, "error");
log("\u{1F6D1}", `failed to get list of releases <- ${error2.message}`, "error");
} else {
log("\u{1F336}", `failed to get list of releases <- ${error2}`, "error");
log("\u{1F6D1}", `failed to get list of releases <- ${error2}`, "error");
}
process.exit(1);
return;
Expand All @@ -7849,13 +7849,13 @@ async function deleteReleases(octokit, qualifiedRepo, tagName) {
} catch (error2) {
if (error2 instanceof Error) {
log(
"\u{1F336}",
"\u{1F6D1}",
`failed to delete release with id "${release_id}" <- ${error2.message}`,
"error"
);
} else {
log(
"\u{1F336}",
"\u{1F6D1}",
`failed to delete release with id "${release_id}" <- ${error2}`,
"error"
);
Expand All @@ -7875,7 +7875,7 @@ function getRepo() {
};
} else if (inputRepo || inputOwner) {
log(
"\u{1F336}",
"\u{1F6D1}",
`a valid repo was not given. Expected "${inputRepoData}" to be in the form of "owner/repo"`
);
process.exit(1);
Expand All @@ -7898,7 +7898,7 @@ function getGitHubToken() {
return tokenFromEnv;
}
log(
"\u{1F336}",
"\u{1F6D1}",
'A valid GitHub token was not provided. Provide it as an input with the name "github_token"',
"error"
);
Expand Down Expand Up @@ -7928,7 +7928,7 @@ function getInputs() {
}
function validateInputField(isValid, invalidMessage) {
if (!isValid) {
log("\u{1F336}", invalidMessage, "error");
log("\u{1F6D1}", invalidMessage, "error");
process.exit(1);
}
}
Expand Down
6 changes: 3 additions & 3 deletions index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ describe("Delete tags and releases", () => {
expect(deleteRef).toHaveBeenCalledWith({
owner: "a-fake-user",
repo: "a-fake-repo",
ref: "refs/tags/a-fake-tag",
ref: "tags/a-fake-tag",
});
});

Expand Down Expand Up @@ -267,7 +267,7 @@ describe("Delete tags and releases", () => {
expect(deleteRef).toHaveBeenCalledWith({
owner: "a-fake-user",
repo: "a-fake-repo",
ref: "refs/tags/a-fake-tag",
ref: "tags/a-fake-tag",
});
expect(listReleases).toHaveBeenCalledTimes(1);
expect(listReleases).toBeCalledWith({
Expand Down Expand Up @@ -330,7 +330,7 @@ describe("Delete tags and releases", () => {
expect(deleteRef).toHaveBeenCalledWith({
owner: "a-fake-user",
repo: "a-fake-repo",
ref: "refs/tags/a-fake-tag",
ref: "tags/a-fake-tag",
});
expect(listReleases).toHaveBeenCalledTimes(1);
expect(listReleases).toBeCalledWith({
Expand Down
13 changes: 8 additions & 5 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { createTagRef } from "./utils";
import { context, getOctokit } from "@actions/github";
import {
error,
Expand Down Expand Up @@ -56,25 +55,29 @@ function log(
* @param octokit The Octokit instance to use for making API calls to GitHub.
* @param owner The owner of the repo with the releases to delete.
* @param repo The repo with the releases to delete.
* @param tagName
* @param tagName The name of the tag to delete. This is expected to be solely the tag name, not the name of a
* git reference.
*/
async function deleteTag(
octokit: Octokit,
{ owner, repo }: QualifiedRepo,
tagName: string
): Promise<void> {
const ref = createTagRef(tagName);
try {
await octokit.rest.git.deleteRef({
owner,
repo,
ref,
ref: `tags/${tagName}`,
});

log("✅", `"${tagName}" deleted successfully!`);
} catch (error) {
if (error instanceof Error) {
log("🛑", `failed to delete ref "${ref}" <- ${error.message}`, "error");
log(
"🛑",
`failed to delete tag "${tagName}" <- ${error.message}`,
"error"
);
if (error.message === "Reference does not exist") {
log(
"😕",
Expand Down
5 changes: 0 additions & 5 deletions utils.ts

This file was deleted.

0 comments on commit 7550ea1

Please sign in to comment.