Skip to content

Commit

Permalink
put line numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
XVincentX committed Feb 17, 2019
1 parent 75b7703 commit 1179564
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 12 deletions.
21 changes: 21 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
},
"dependencies": {
"@octokit/rest": "^16.15.0",
"@stoplight/json": "^1.5.0",
"@stoplight/spectral": "^1.0.2",
"@types/node": "^11.9.4",
"funfix": "^7.0.1",
Expand Down
33 changes: 21 additions & 12 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import * as Octokit from '@octokit/rest'
import { Spectral } from '@stoplight/spectral'
import { join } from 'path'
import { pathToPointer } from "@stoplight/json";
import { parseWithPointers } from "@stoplight/json/parseWithPointers";
import { readFileSync } from 'fs'
import { oas2Functions, oas2Rules } from '@stoplight/spectral/rulesets/oas2';
import { oas3Functions, oas3Rules } from '@stoplight/spectral/rulesets/oas3';
import { ValidationSeverity } from '@stoplight/types/validations';
Expand All @@ -26,20 +29,26 @@ if (!GITHUB_EVENT_PATH || !GITHUB_TOKEN || !GITHUB_SHA || !GITHUB_WORKSPACE || !
spectral.addRules(oas3Rules());


const payload = require(join(GITHUB_WORKSPACE, SPECTRAL_FILE_PATH))
const { results } = spectral.run(payload);
const fileContent = readFileSync(join(GITHUB_WORKSPACE, SPECTRAL_FILE_PATH), { encoding: 'utf8' })
const parsed = parseWithPointers(fileContent);
const { results } = spectral.run(parsed.data);

// @ts-ignore
const annotations: Octokit.ChecksListAnnotationsParams[] = results.map(validationResult => ({
annotation_level: validationResult.severity === ValidationSeverity.Error ? 'failure' : validationResult.severity === ValidationSeverity.Warn ? 'warning' : 'notice',
message: validationResult.summary,
title: validationResult.name,
start_line: validationResult.location ? validationResult.location.start.line : 0,
end_line: validationResult.location && validationResult.location.end ? validationResult.location.end.line : 0,
start_column: validationResult.location ? validationResult.location.start.column : undefined,
end_column: validationResult.location && validationResult.location.end && validationResult.location.end.column ? validationResult.location.end.column : undefined,
path: join(GITHUB_WORKSPACE, SPECTRAL_FILE_PATH),
}));
const annotations: Octokit.ChecksListAnnotationsParams[] = results.map(validationResult => {
const path = pathToPointer(validationResult.path as string[]).slice(1);
const position = parsed.pointers[path];

return {
annotation_level: validationResult.severity === ValidationSeverity.Error ? 'failure' : validationResult.severity === ValidationSeverity.Warn ? 'warning' : 'notice',
message: validationResult.summary,
title: validationResult.name,
start_line: position ? position.start.line : 0,
end_line: position && position.end ? position.end.line : 0,
start_column: position && position.start.column ? position.start.column : undefined,
end_column: position && position.end && position.end.column ? position.end.column : undefined,
path: join(GITHUB_WORKSPACE, SPECTRAL_FILE_PATH),
}
});

// @ts-ignore
return octokit.checks.update({
Expand Down

0 comments on commit 1179564

Please sign in to comment.