This repository has been archived by the owner on Jun 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: report errors on unknown event types (#45)
Fixes #4
- Loading branch information
1 parent
5572f59
commit 7b3720b
Showing
15 changed files
with
259 additions
and
225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/*! | ||
* Copyright 2019 Omar Tawfik. Please see LICENSE file at the root of this repository. | ||
*/ | ||
|
||
import { BoundNodeVisitor } from "../binding/bound-node-visitor"; | ||
import { DiagnosticBag } from "../util/diagnostics"; | ||
import { BoundDocument, BoundResolves, BoundSecrets, BoundOn, BoundEnv } from "../binding/bound-nodes"; | ||
import { MAXIMUM_SUPPORTED_SECRETS } from "../util/constants"; | ||
import * as webhooks from "@octokit/webhooks-definitions"; | ||
|
||
export function analyzeProperties(document: BoundDocument, actions: ReadonlySet<string>, bag: DiagnosticBag): void { | ||
new PropertiesAnalyzer(document, actions, bag); | ||
} | ||
|
||
class PropertiesAnalyzer extends BoundNodeVisitor { | ||
private exceededMaximum = false; | ||
private allSecrets = new Set<string>(); | ||
|
||
public constructor( | ||
document: BoundDocument, | ||
private readonly actions: ReadonlySet<string>, | ||
private readonly bag: DiagnosticBag, | ||
) { | ||
super(); | ||
this.visit(document); | ||
} | ||
|
||
protected visitResolves(node: BoundResolves): void { | ||
for (const action of node.actions) { | ||
if (!this.actions.has(action.value)) { | ||
this.bag.actionDoesNotExist(action.value, action.syntax.range); | ||
} | ||
} | ||
} | ||
|
||
protected visitSecrets(node: BoundSecrets): void { | ||
const localSecrets = new Set<string>(); | ||
for (const secret of node.secrets) { | ||
if (localSecrets.has(secret.value)) { | ||
this.bag.duplicateSecrets(secret.value, secret.syntax.range); | ||
} else { | ||
localSecrets.add(secret.value); | ||
} | ||
} | ||
|
||
if (!this.exceededMaximum) { | ||
for (const secret of node.secrets) { | ||
this.allSecrets.add(secret.value); | ||
if (this.allSecrets.size > MAXIMUM_SUPPORTED_SECRETS) { | ||
this.bag.tooManySecrets(secret.syntax.range); | ||
this.exceededMaximum = true; | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
||
protected visitOn(node: BoundOn): void { | ||
if (node.event && !webhooks.some(definition => definition.name === node.event!.value)) { | ||
this.bag.unrecognizedEvent(node.event.value, node.event.syntax.range); | ||
} | ||
} | ||
|
||
protected visitEnv(node: BoundEnv): void { | ||
for (const variable of node.variables) { | ||
if (variable.name.startsWith("GITHUB_")) { | ||
this.bag.reservedEnvironmentVariable(variable.syntax.name.range); | ||
} | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.