From 4facb03968cb6b45c36f5c8d404bcfbbf1feb093 Mon Sep 17 00:00:00 2001 From: Katy DeCorah Date: Fri, 24 May 2024 21:02:55 -0400 Subject: [PATCH] Rename `isbn` input to `identifier` (#166) * Rename `isbn` input to `identifier` * Update documentation --------- Co-authored-by: GitHub Action --- .github/workflows/read-advanced.yml | 2 +- .github/workflows/read-thumbnail.yml | 2 +- .github/workflows/read.yml | 2 +- README.md | 8 +++---- src/__tests__/checkout-book.test.ts | 10 ++++----- src/__tests__/clean-book.test.ts | 30 +++++++++++++------------- src/__tests__/get-book.test.ts | 4 ++-- src/__tests__/index.test.ts | 32 ++++++++++++++++------------ src/__tests__/update-book.test.ts | 10 ++++----- src/__tests__/workflow.test.ts | 8 +++---- src/checkout-book.ts | 5 +++-- src/clean-book.ts | 12 +++++------ src/get-book.ts | 6 +++--- src/index.ts | 8 +++---- src/update-book.ts | 5 +++-- src/validate-payload.ts | 4 ++-- 16 files changed, 77 insertions(+), 71 deletions(-) diff --git a/.github/workflows/read-advanced.yml b/.github/workflows/read-advanced.yml index af877568..2687b889 100644 --- a/.github/workflows/read-advanced.yml +++ b/.github/workflows/read-advanced.yml @@ -23,7 +23,7 @@ on: date: description: Date to record the status of the book (YYYY-MM-DD). Leave blank for today. Optional. type: string - isbn: + identifier: description: The book's ISBN. Required. required: true type: string diff --git a/.github/workflows/read-thumbnail.yml b/.github/workflows/read-thumbnail.yml index d68e362e..b4db752e 100644 --- a/.github/workflows/read-thumbnail.yml +++ b/.github/workflows/read-thumbnail.yml @@ -9,7 +9,7 @@ permissions: on: workflow_dispatch: inputs: - isbn: + identifier: description: The book's ISBN. Required. required: true type: string diff --git a/.github/workflows/read.yml b/.github/workflows/read.yml index ea84881c..c330c013 100644 --- a/.github/workflows/read.yml +++ b/.github/workflows/read.yml @@ -9,7 +9,7 @@ permissions: on: workflow_dispatch: inputs: - isbn: + identifier: description: The book's ISBN. Required. required: true type: string diff --git a/README.md b/README.md index 817fe36f..5dd67bba 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ permissions: on: workflow_dispatch: inputs: - isbn: + identifier: description: The book's ISBN. Required. required: true type: string @@ -119,7 +119,7 @@ on: date: description: Date to record the status of the book (YYYY-MM-DD). Leave blank for today. Optional. type: string - isbn: + identifier: description: The book's ISBN. Required. required: true type: string @@ -215,7 +215,7 @@ permissions: on: workflow_dispatch: inputs: - isbn: + identifier: description: The book's ISBN. Required. required: true type: string @@ -306,7 +306,7 @@ To trigger the action, [create a workflow dispatch event](https://docs.github.co { "ref": "main", // Required. The git reference for the workflow, a branch or tag name. "inputs": { - "isbn": "", // Required. The book's ISBN. Required. + "identifier": "", // Required. The book's ISBN. Required. "book-status": "", // Required. What is the status of the book? Required. Default: `want to read`. "date": "", // Date to record the status of the book (YYYY-MM-DD). Leave blank for today. Optional. "notes": "", // Notes about the book. Optional. diff --git a/src/__tests__/checkout-book.test.ts b/src/__tests__/checkout-book.test.ts index 147a1f5b..f548cd29 100644 --- a/src/__tests__/checkout-book.test.ts +++ b/src/__tests__/checkout-book.test.ts @@ -23,7 +23,7 @@ describe("checkOutBook", () => { checkOutBook( { fileName: "my-library.yml", - bookIsbn: "9780525620792", + inputIdentifier: "9780525620792", dates: { dateAdded: undefined, dateStarted: undefined, @@ -50,7 +50,7 @@ describe("checkOutBook", () => { checkOutBook( { fileName: "my-library.yml", - bookIsbn: "9780525620792", + inputIdentifier: "9780525620792", dates: { dateAdded: undefined, dateStarted: undefined, @@ -70,7 +70,7 @@ describe("checkOutBook", () => { checkOutBook( { fileName: "my-library.yml", - bookIsbn: "9780525620792", + inputIdentifier: "9780525620792", tags: [""], dates: { dateAdded: undefined, @@ -91,7 +91,7 @@ describe("checkOutBook", () => { checkOutBook( { fileName: "my-library.yml", - bookIsbn: "12345", + inputIdentifier: "12345", dates: { dateAdded: undefined, dateStarted: undefined, @@ -110,7 +110,7 @@ describe("checkOutBook", () => { checkOutBook( { fileName: "my-library.yml", - bookIsbn: "12345", + inputIdentifier: "12345", dates: { dateAdded: undefined, dateStarted: undefined, diff --git a/src/__tests__/clean-book.test.ts b/src/__tests__/clean-book.test.ts index 69f4f7e6..27e73762 100644 --- a/src/__tests__/clean-book.test.ts +++ b/src/__tests__/clean-book.test.ts @@ -26,7 +26,7 @@ describe("cleanBook", () => { { dateType: { dateFinished: dateFinished }, notes: "I loved it!", - bookIsbn: "0525658181", + inputIdentifier: "0525658181", providers: [], bookStatus: "finished", filename: "_data/read.yml", @@ -67,7 +67,7 @@ describe("cleanBook", () => { { dateType: { dateFinished: dateFinished }, notes: "I loved it!", - bookIsbn: "0525658181", + inputIdentifier: "0525658181", providers: [], bookStatus: "finished", rating: "⭐️⭐️⭐️⭐️⭐️", @@ -109,7 +109,7 @@ describe("cleanBook", () => { cleanBook( { notes: "I loved it!", - bookIsbn: "0525658181", + inputIdentifier: "0525658181", providers: [], bookStatus: "finished", filename: "_data/read.yml", @@ -149,7 +149,7 @@ describe("cleanBook", () => { cleanBook( { dateType: { dateStarted: "2022-01-01" }, - bookIsbn: "1234597890", + inputIdentifier: "1234597890", providers: [], bookStatus: "started", filename: "_data/read.yml", @@ -182,7 +182,7 @@ describe("cleanBook", () => { "authors, description", ], [ - "BookIsbn", + "BookIdentifier", "1234597890", ], ] @@ -195,7 +195,7 @@ describe("cleanBook", () => { cleanBook( { dateType: { dateStarted: "2022-01-01" }, - bookIsbn: "1234597890", + inputIdentifier: "1234597890", providers: [], bookStatus: "started", filename: "_data/read.yml", @@ -229,7 +229,7 @@ describe("cleanBook", () => { "title", ], [ - "BookIsbn", + "BookIdentifier", "1234597890", ], ] @@ -242,7 +242,7 @@ describe("cleanBook", () => { cleanBook( { dateType: { dateStarted: "2022-01-01" }, - bookIsbn: "1234597890", + inputIdentifier: "1234597890", providers: [], bookStatus: "started", filename: "_data/read.yml", @@ -276,7 +276,7 @@ describe("cleanBook", () => { "description", ], [ - "BookIsbn", + "BookIdentifier", "1234597890", ], ] @@ -289,7 +289,7 @@ describe("cleanBook", () => { cleanBook( { dateType: { dateStarted: "2022-01-01" }, - bookIsbn: "1234597890", + inputIdentifier: "1234597890", providers: [], bookStatus: "started", filename: "_data/read.yml", @@ -321,7 +321,7 @@ describe("cleanBook", () => { "title, pageCount, authors, description", ], [ - "BookIsbn", + "BookIdentifier", "1234597890", ], ] @@ -339,7 +339,7 @@ describe("cleanBook", () => { cleanBook( { dateType: { dateStarted: "2022-01-01" }, - bookIsbn: "1234597890", + inputIdentifier: "1234597890", providers: [], bookStatus: "started", filename: "_data/read.yml", @@ -365,7 +365,7 @@ describe("cleanBook", () => { { dateType: { dateFinished: dateFinished }, notes: "I loved it!", - bookIsbn: "0525658181", + inputIdentifier: "0525658181", providers: [], bookStatus: "finished", filename: "_data/read.yml", @@ -409,7 +409,7 @@ describe("cleanBook", () => { { dateType: { dateFinished: dateFinished }, notes: "I loved it!", - bookIsbn: "0525658181", + inputIdentifier: "0525658181", providers: [], bookStatus: "finished", filename: "_data/read.yml", @@ -453,7 +453,7 @@ describe("cleanBook", () => { { dateType: { dateFinished }, notes: "I loved it!", - bookIsbn: "0525658181", + inputIdentifier: "0525658181", providers: [], bookStatus: "finished", filename: "_data/read.yml", diff --git a/src/__tests__/get-book.test.ts b/src/__tests__/get-book.test.ts index 9a138e56..67914d46 100644 --- a/src/__tests__/get-book.test.ts +++ b/src/__tests__/get-book.test.ts @@ -32,7 +32,7 @@ describe("getBook", () => { dateType: { dateFinished, }, - bookIsbn: "9780525658184", + inputIdentifier: "9780525658184", providers: ["google"], bookStatus: "finished", filename: "_data/read.yml", @@ -74,7 +74,7 @@ describe("getBook", () => { dateStarted: undefined, dateFinished, }, - bookIsbn: "9780525658184", + inputIdentifier: "9780525658184", providers: ["google"], bookStatus: "finished", filename: "_data/read.json", diff --git a/src/__tests__/index.test.ts b/src/__tests__/index.test.ts index 236e82af..d77bc892 100644 --- a/src/__tests__/index.test.ts +++ b/src/__tests__/index.test.ts @@ -65,7 +65,7 @@ describe("index", () => { value: { payload: { inputs: { - isbn: "9780385696005", + identifier: "9780385696005", "book-status": "started", date: "2022-01-02", }, @@ -88,7 +88,7 @@ describe("index", () => { "pageCount", ], [ - "BookIsbn", + "BookIdentifier", "9780385696005", ], [ @@ -177,7 +177,7 @@ describe("index", () => { value: { payload: { inputs: { - isbn: "9780525620792", + identifier: "9780525620792", "book-status": "finished", date: "2021-09-30", }, @@ -235,7 +235,7 @@ describe("index", () => { value: { payload: { inputs: { - isbn: "9780525511342", + identifier: "9780525511342", "book-status": "finished", date: "2022-08-02", }, @@ -323,7 +323,7 @@ describe("index", () => { value: { payload: { inputs: { - isbn: "9780385696005", + identifier: "9780385696005", "book-status": "want to read", }, }, @@ -345,7 +345,7 @@ describe("index", () => { "pageCount", ], [ - "BookIsbn", + "BookIdentifier", "9780385696005", ], [ @@ -422,10 +422,12 @@ describe("index", () => { }); await read(); - expect(setFailedSpy).toHaveBeenCalledWith("Missing `isbn` in payload"); + expect(setFailedSpy).toHaveBeenCalledWith( + "Missing `identifier` in payload" + ); }); - test("error, missing isbn", async () => { + test("error, missing identifier", async () => { const setFailedSpy = jest.spyOn(core, "setFailed"); Object.defineProperty(github, "context", { value: { @@ -438,7 +440,9 @@ describe("index", () => { }, }); await read(); - expect(setFailedSpy).toHaveBeenCalledWith("Missing `isbn` in payload"); + expect(setFailedSpy).toHaveBeenCalledWith( + "Missing `identifier` in payload" + ); }); test("error, setFailed", async () => { @@ -447,7 +451,7 @@ describe("index", () => { value: { payload: { inputs: { - isbn: "9780385696005", + identifier: "9780385696005", "book-status": "want to read", }, }, @@ -467,7 +471,7 @@ describe("index", () => { value: { payload: { inputs: { - isbn: "9780385696005", + identifier: "9780385696005", tags: "new, recommend", "book-status": "want to read", }, @@ -535,7 +539,7 @@ describe("index", () => { value: { payload: { inputs: { - isbn: "9780385696005", + identifier: "9780385696005", "book-status": "finished", date: "2022-02-02", }, @@ -552,7 +556,7 @@ describe("index", () => { value: { payload: { inputs: { - isbn: "9780385696005", + identifier: "9780385696005", "book-status": "finished", date: "1234", }, @@ -571,7 +575,7 @@ describe("index", () => { value: { payload: { inputs: { - isbn: "9780385696005", + identifier: "9780385696005", "book-status": "did not finish", }, }, diff --git a/src/__tests__/update-book.test.ts b/src/__tests__/update-book.test.ts index d51cd4b8..260544b8 100644 --- a/src/__tests__/update-book.test.ts +++ b/src/__tests__/update-book.test.ts @@ -25,7 +25,7 @@ describe("updateBook", () => { updateBook( { filename: "my-library.yml", - bookIsbn: "9780525620792", + inputIdentifier: "9780525620792", dateType: { dateFinished: "2022-02-02", }, @@ -71,7 +71,7 @@ describe("updateBook", () => { updateBook( { filename: "my-library.yml", - bookIsbn: "9780525620792", + inputIdentifier: "9780525620792", dateType: { dateFinished: "2022-02-02", }, @@ -106,7 +106,7 @@ describe("updateBook", () => { updateBook( { filename: "my-library.yml", - bookIsbn: "9780525620792", + inputIdentifier: "9780525620792", tags: [""], dateType: { dateFinished: "2022-02-02", @@ -151,7 +151,7 @@ describe("updateBook", () => { updateBook( { filename: "my-library.yml", - bookIsbn: "12345", + inputIdentifier: "12345", dateType: { dateFinished: "2022-02-02", }, @@ -187,7 +187,7 @@ describe("updateBook", () => { updateBook( { filename: "my-library.yml", - bookIsbn: "12345", + inputIdentifier: "12345", dateType: { dateFinished: "2022-02-02", }, diff --git a/src/__tests__/workflow.test.ts b/src/__tests__/workflow.test.ts index c7378b5b..b0196c63 100644 --- a/src/__tests__/workflow.test.ts +++ b/src/__tests__/workflow.test.ts @@ -47,7 +47,7 @@ describe("workflow", () => { value: { payload: { inputs: { - isbn: "9780385696005", + identifier: "9780385696005", "book-status": "want to read", }, }, @@ -115,7 +115,7 @@ describe("workflow", () => { value: { payload: { inputs: { - isbn: "9780385696005", + identifier: "9780385696005", "book-status": "started", date: "2022-10-02", }, @@ -180,7 +180,7 @@ describe("workflow", () => { value: { payload: { inputs: { - isbn: "9780385696005", + identifier: "9780385696005", "book-status": "finished", date: "2022-10-03", rating: "⭐️⭐️⭐️⭐️⭐️", @@ -229,7 +229,7 @@ describe("workflow", () => { value: { payload: { inputs: { - isbn: "9798374567144", + identifier: "9798374567144", "book-status": "want to read", }, }, diff --git a/src/checkout-book.ts b/src/checkout-book.ts index ec3c49a4..9e3233ae 100644 --- a/src/checkout-book.ts +++ b/src/checkout-book.ts @@ -5,8 +5,9 @@ export function checkOutBook( bookParams: BookParams, library: CleanBook[] ): boolean { - const { bookIsbn } = bookParams; + const { inputIdentifier } = bookParams; if (library === undefined || library.length === 0) return false; - if (library.filter((f) => f.isbn === bookIsbn).length === 0) return false; + if (library.filter((f) => f.isbn === inputIdentifier).length === 0) + return false; else return true; } diff --git a/src/clean-book.ts b/src/clean-book.ts index f6748e30..de424056 100644 --- a/src/clean-book.ts +++ b/src/clean-book.ts @@ -31,7 +31,7 @@ export type BookStatus = "want to read" | "started" | "finished" | "abandoned"; export default function cleanBook(options: BookParams, book: Book): CleanBook { const { notes, - bookIsbn, + inputIdentifier, dateType, bookStatus, rating, @@ -39,7 +39,7 @@ export default function cleanBook(options: BookParams, book: Book): CleanBook { thumbnailWidth, setImage, } = options; - checkMetadata(book, bookIsbn); + checkMetadata(book, inputIdentifier); const { title, authors, @@ -54,7 +54,7 @@ export default function cleanBook(options: BookParams, book: Book): CleanBook { } = book; return { - isbn: bookIsbn, + isbn: inputIdentifier, ...dateType, status: bookStatus, ...(rating && { rating }), @@ -79,7 +79,7 @@ export default function cleanBook(options: BookParams, book: Book): CleanBook { link, }), ...(setImage && { - image: `book-${bookIsbn}.png`, + image: `book-${inputIdentifier}.png`, }), }; } @@ -98,7 +98,7 @@ function handleThumbnail( return thumbnail; } -function checkMetadata(book: Book, bookIsbn: string) { +function checkMetadata(book: Book, inputIdentifier: string) { const missingMetadata: string[] = []; const requiredMetadata = getInput("required-metadata") .split(",") @@ -128,6 +128,6 @@ function checkMetadata(book: Book, bookIsbn: string) { warning(`Book does not have ${missingMetadata.join(", ")}`); exportVariable("BookNeedsReview", true); exportVariable("BookMissingMetadata", missingMetadata.join(", ")); - exportVariable("BookIsbn", bookIsbn); + exportVariable("BookIdentifier", inputIdentifier); } } diff --git a/src/get-book.ts b/src/get-book.ts index 41082cff..33afd22b 100644 --- a/src/get-book.ts +++ b/src/get-book.ts @@ -3,14 +3,14 @@ import { BookParams } from "."; import cleanBook, { CleanBook } from "./clean-book"; export default async function getBook(options: BookParams): Promise { - const { bookIsbn, providers } = options; + const { inputIdentifier, providers } = options; let book; try { const isbn = new Isbn(); isbn.provider(providers); - book = await isbn.resolve(bookIsbn); + book = await isbn.resolve(inputIdentifier); } catch (error) { - throw new Error(`Book (${bookIsbn}) not found. ${error.message}`); + throw new Error(`Book (${inputIdentifier}) not found. ${error.message}`); } const newBook: CleanBook = cleanBook(options, book); return newBook; diff --git a/src/index.ts b/src/index.ts index 60a93afe..e75d97b0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -14,7 +14,7 @@ export type BookPayload = { date: string | undefined; "book-status": BookStatus; notes?: string; - isbn: string; + identifier: string; rating?: string; tags?: string; }; @@ -30,7 +30,7 @@ export type ActionInputs = { export type BookParams = { filename: string; - bookIsbn: BookPayload["isbn"]; + inputIdentifier: BookPayload["identifier"]; dateType: { dateAdded?: string; dateStarted?: string; @@ -53,7 +53,7 @@ export async function read() { // Validate payload validatePayload(payload); const { - isbn: bookIsbn, + identifier: inputIdentifier, date, "book-status": bookStatus, notes, @@ -83,7 +83,7 @@ export async function read() { const bookParams: BookParams = { filename, - bookIsbn, + inputIdentifier, dateType, notes, bookStatus, diff --git a/src/update-book.ts b/src/update-book.ts index 4a846c8f..3d8e67e9 100644 --- a/src/update-book.ts +++ b/src/update-book.ts @@ -6,9 +6,10 @@ export async function updateBook( bookParams: BookParams, currentBooks: CleanBook[] ): Promise { - const { bookIsbn, dateType, bookStatus, notes, rating, tags } = bookParams; + const { inputIdentifier, dateType, bookStatus, notes, rating, tags } = + bookParams; return currentBooks.reduce((arr: CleanBook[], book) => { - if (book.isbn === bookIsbn) { + if (book.isbn === inputIdentifier) { exportVariable("BookTitle", book.title); book = { ...book, diff --git a/src/validate-payload.ts b/src/validate-payload.ts index cbc35698..b018bba0 100644 --- a/src/validate-payload.ts +++ b/src/validate-payload.ts @@ -4,8 +4,8 @@ import { BookPayload } from "./index"; import { BookStatus } from "./clean-book"; export function validatePayload(payload: BookPayload): void { - if (!payload || !payload["isbn"]) { - setFailed("Missing `isbn` in payload"); + if (!payload || !payload["identifier"]) { + setFailed("Missing `identifier` in payload"); } if (payload["date"] && !isDate(payload["date"])) {