Skip to content
This repository was archived by the owner on Jun 15, 2021. It is now read-only.

Commit ac44cf3

Browse files
committed
feat: support workflow on=schedule values (#89)
Closes #84
1 parent 62d1b73 commit ac44cf3

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

src/binding/binder.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ import { TokenKind } from "../scanning/tokens";
3333
import * as webhooks from "@octokit/webhooks-definitions";
3434
import { MAXIMUM_SUPPORTED_VERSION, USES_REGEX } from "../util/constants";
3535

36+
const ON_SCHEDULE_REGEX = /schedule\(.+\)/;
37+
3638
export function bindDocument(root: DocumentSyntax, bag: DiagnosticBag): BoundDocument {
3739
let version: BoundVersion | undefined;
3840
const workflows = Array<BoundWorkflow>();
@@ -96,8 +98,11 @@ export function bindDocument(root: DocumentSyntax, bag: DiagnosticBag): BoundDoc
9698
bag.propertyAlreadyDefined(property.key);
9799
} else {
98100
on = new BoundOn(bindString(property), property);
99-
if (on.event && !webhooks.some(definition => definition.name === on!.event!.value)) {
100-
bag.unrecognizedEvent(on.event.value, on.event.syntax.range);
101+
if (on.event) {
102+
const { value } = on.event;
103+
if (!webhooks.some(definition => definition.name === value) && !ON_SCHEDULE_REGEX.test(value)) {
104+
bag.unrecognizedEvent(value, on.event.syntax.range);
105+
}
101106
}
102107
}
103108
break;

src/util/diagnostics.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ export class DiagnosticBag {
314314
code: DiagnosticCode.UnrecognizedEvent,
315315
source: LANGUAGE_NAME,
316316
severity: DiagnosticSeverity.Error,
317-
message: `The event '${event}' is not a known event type.`,
317+
message: `The event '${event}' is not a known event type or a schedule.`,
318318
});
319319
}
320320

test/binding.spec.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,13 +257,44 @@ workflow "y" {
257257
on = "unknown"
258258
}`).toMatchInlineSnapshot(`
259259
"
260-
ERROR: The event 'unknown' is not a known event type.
260+
ERROR: The event 'unknown' is not a known event type or a schedule.
261261
4 | }
262262
5 | workflow \\"y\\" {
263263
6 | on = \\"unknown\\"
264264
| ^^^^^^^^^
265265
7 | }
266266
"
267+
`);
268+
});
269+
270+
it("does not report errors on schedule values", () => {
271+
expectDiagnostics(`
272+
workflow "a" {
273+
on = "schedule(*/15 * * * *)"
274+
}
275+
workflow "b" {
276+
on = "schedule()"
277+
}
278+
workflow "c" {
279+
on = " schedule ( ) "
280+
}
281+
`).toMatchInlineSnapshot(`
282+
"
283+
ERROR: The event 'schedule()' is not a known event type or a schedule.
284+
4 | }
285+
5 | workflow \\"b\\" {
286+
6 | on = \\"schedule()\\"
287+
| ^^^^^^^^^^^^
288+
7 | }
289+
8 | workflow \\"c\\" {
290+
ERROR: The event ' schedule ( ) ' is not a known event type or a schedule.
291+
7 | }
292+
8 | workflow \\"c\\" {
293+
9 | on = \\" schedule ( ) \\"
294+
| ^^^^^^^^^^^^^^^^^^^^
295+
10 | }
296+
11 |
297+
"
267298
`);
268299
});
269300
});

0 commit comments

Comments
 (0)