Address feedback

This commit is contained in:
Jacob Wallraff
2023-01-23 17:50:54 -08:00
parent af5c15a422
commit 58d92658b6
5 changed files with 19 additions and 23 deletions
@@ -1,4 +1,4 @@
import { isValidCron, getSchedule, getSentence } from "./cron"
import { isValidCron, getSchedule, getCronDescription } from "./cron"
describe("cron", () => {
describe("valid cron", () => {
@@ -145,13 +145,15 @@ describe("cron", () => {
}
})
describe("getSentence", () => {
describe("getCronDescription", () => {
it(`Produces a sentence for valid cron`, () => {
expect(getSentence("0 * * * *")).toEqual("Every hour")
expect(getCronDescription("0 * * * *")).toEqual("Runs every hour\n\n" +
"Actions schedules run at most every 5 minutes. [Learn more](https://docs.github.com/actions/using-workflows/workflow-syntax-for-github-actions#onschedule)"
)
})
it(`Returns nothing for invalid cron`, () => {
expect(getSentence("* * * * * *")).toBeUndefined()
expect(getCronDescription("* * * * * *")).toBeUndefined()
})
})
})
@@ -40,7 +40,7 @@ export function isValidCron(cron: string): boolean {
)
}
export function getSentence(cronspec: string): string | undefined {
export function getCronDescription(cronspec: string): string | undefined {
const schedule = getSchedule(cronspec)
if (!schedule) {
return
@@ -61,7 +61,10 @@ export function getSentence(cronspec: string): string | undefined {
}
// Make first character lowercase
return "Runs " + desc.charAt(0).toLowerCase() + desc.slice(1)
let result = "Runs " + desc.charAt(0).toLowerCase() + desc.slice(1)
result += "\n\nActions schedules run at most every 5 minutes." +
" [Learn more](https://docs.github.com/actions/using-workflows/workflow-syntax-for-github-actions#onschedule)";
return result
}
function parseCronPart(part: string, range: Range): number[] | undefined {
@@ -195,8 +198,6 @@ export function getSchedule(cron: string): Schedule | undefined {
}
}
// Helpers
// Converts a string integer or a short name to a number
function convertToNumber(value: string, names?: Record<string, number>): number {
if (names && names[value.toLowerCase()] !== undefined) {