Skip to content

Commit

Permalink
Fix dash
Browse files Browse the repository at this point in the history
  • Loading branch information
katydecorah committed Jun 6, 2024
1 parent 4312c1f commit 4dc13e0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
10 changes: 9 additions & 1 deletion src/__test__/list-playlists.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-var-requires */
import listPlaylists, { formatTracks } from "../list-playlists";
import listPlaylists, { formatName, formatTracks } from "../list-playlists";
import { getInput } from "@actions/core";
import SpotifyWebApi from "spotify-web-api-node";

Expand Down Expand Up @@ -233,3 +233,11 @@ describe("formatTracks", () => {
`);
});
});

describe("formatName", () => {
it("formats the name correctly", () => {
expect(formatName("2021 Fall")).toBe("2021-fall");
expect(formatName("2020/2021 Winter")).toBe("2020-2021-winter");
expect(formatName("2020 / 2021 Winter")).toBe("2020-2021-winter");
});
});
7 changes: 1 addition & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import updateMain from "./write-file";
import { setFailed, exportVariable, getInput, info } from "@actions/core";
import { setFailed, exportVariable, getInput } from "@actions/core";
import listPlaylists from "./list-playlists";
import * as github from "@actions/github";

Expand All @@ -23,14 +23,9 @@ export async function action() {
try {
const filename = getInput("filename");
const payload = github.context.payload.inputs;

const playlistName =
payload?.["playlist-name"] || getInput("playlist-name");

info(`payload: ${payload?.["playlist-name"]}`);
info(`action input: ${getInput("playlist-name")}`);
info(`playlistName: ${playlistName}`);

if (!playlistName) {
throw new Error("Playlist name is required");
}
Expand Down
3 changes: 2 additions & 1 deletion src/list-playlists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,10 @@ export function formatTracks({
};
}

function formatName(name: string): string {
export function formatName(name: string): string {
return name
.replace(/\s/g, "-")
.replace(/[/]/g, "-")
.replace(/[^a-zA-Z0-9-]/g, "")
.replace(/-+/g, "-")
.toLowerCase();
Expand Down

0 comments on commit 4dc13e0

Please sign in to comment.