Skip to content

Commit c6bf11a

Browse files
authored
Fail check task on naming convention violations (#7)
1 parent 360f52b commit c6bf11a

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

src/index.ts

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type { Config, Context } from "@netlify/functions";
77
const linter = new Linter({cwd: '.',});
88

99
const apolloClient = new ApolloClient({
10-
uri: Netlify.env.get('APOLLO_STUDIO_URL') ?? 'https://graphql.api.apollographql.com/api/graphql',
10+
uri: Netlify.env.get('APOLLO_STUDIO_URL') ?? 'https://api.apollographql.com/api/graphql',
1111
cache: new InMemoryCache(),
1212
});
1313

@@ -21,9 +21,7 @@ const docQuery = gql`query Doc($graphId: ID!, $hash: SHA256) {
2121

2222
const customCheckCallbackMutation = gql`mutation CustomCheckCallback($input: CustomCheckCallbackInput!, $name: String!, $graphId: ID!) {
2323
graph(id: $graphId) {
24-
id
2524
variant(name: $name) {
26-
id
2725
customCheckCallback(input: $input) {
2826
__typename
2927
... on CustomCheckResult {
@@ -95,6 +93,25 @@ export default async (req: Request, context: Context) => {
9593

9694
console.log(`eslint messages: ${JSON.stringify(messages)}`);
9795

96+
const violations = messages.map(violation => ({
97+
// Fail check if a naming convention is violated
98+
level: violation.ruleId === '@graphql-eslint/naming-convention' ? 'ERROR' : 'WARNING',
99+
message: violation.message,
100+
rule: violation.ruleId ?? 'unknown',
101+
sourceLocations: {
102+
start: {
103+
byteOffset: 0,
104+
line: violation.line,
105+
column: violation.column,
106+
},
107+
end: {
108+
byteOffset: 0,
109+
line: violation.endLine,
110+
column: violation.endColumn,
111+
}
112+
}
113+
}));
114+
98115
const callbackResult = await apolloClient.mutate({
99116
mutation: customCheckCallbackMutation,
100117
variables: {
@@ -103,24 +120,8 @@ export default async (req: Request, context: Context) => {
103120
input: {
104121
taskId: event.checkStep.taskId,
105122
workflowId: event.checkStep.workflowId,
106-
status: 'SUCCESS',
107-
violations: messages.map(violation => ({
108-
level: "WARNING",
109-
message: violation.message,
110-
rule: violation.ruleId,
111-
sourceLocations: {
112-
start: {
113-
byteOffset: violation.column,
114-
line: violation.line,
115-
column: violation.column,
116-
},
117-
end: {
118-
byteOffset: violation.endColumn,
119-
line: violation.endLine,
120-
column: violation.endColumn,
121-
}
122-
}
123-
})),
123+
status: violations.find(violation => violation.level === 'ERROR') !== undefined ? 'FAILURE' : 'SUCCESS',
124+
violations: violations,
124125
}
125126
},
126127
context: {

0 commit comments

Comments
 (0)