Skip to content

Commit

Permalink
use decoder from io-ts
Browse files Browse the repository at this point in the history
  • Loading branch information
XVincentX committed May 2, 2020
1 parent 49c4663 commit d5dffbc
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ COPY src ./src
COPY tsconfig.json tsconfig.json

RUN yarn
RUN yarn build || true
RUN yarn build

###############################################################

Expand Down
18 changes: 9 additions & 9 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as t from 'io-ts';
import * as D from 'io-ts/lib/Decoder';

export const Config = t.strict({
GITHUB_EVENT_PATH: t.string,
INPUT_REPO_TOKEN: t.string,
GITHUB_WORKSPACE: t.string,
INPUT_FILE_GLOB: t.string,
INPUT_EVENT_NAME: t.string,
INPUT_SPECTRAL_RULESET: t.string,
export const Config = D.type({
GITHUB_EVENT_PATH: D.string,
INPUT_REPO_TOKEN: D.string,
GITHUB_WORKSPACE: D.string,
INPUT_FILE_GLOB: D.string,
INPUT_EVENT_NAME: D.string,
INPUT_SPECTRAL_RULESET: D.string,
});

export type Config = t.TypeOf<typeof Config>;
export type Config = D.TypeOf<typeof Config>;
5 changes: 2 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { join } from 'path';
import { DiagnosticSeverity } from '@stoplight/types';
import { warning } from '@actions/core';
import { EOL } from 'os';
import { promises as fs } from 'fs';
import { array } from 'fp-ts/lib/Array';
import { flatten } from 'lodash';
Expand All @@ -16,7 +15,7 @@ import * as IO from 'fp-ts/lib/IO';
import * as TE from 'fp-ts/lib/TaskEither';
import * as T from 'fp-ts/lib/Task';
import * as E from 'fp-ts/lib/Either';
import { failure } from 'io-ts/lib/PathReporter';
import { draw } from 'io-ts/lib/Tree';
import { pipe } from 'fp-ts/lib/pipeable';
import { identity } from 'lodash';
import { ChecksUpdateParamsOutputAnnotations } from '@octokit/rest';
Expand Down Expand Up @@ -110,7 +109,7 @@ const getEnv = IO.of(process.env);
const decodeConfig = (env: NodeJS.ProcessEnv) =>
pipe(
Config.decode(env),
E.mapLeft(e => new Error(failure(e).join(EOL)))
E.mapLeft(e => new Error(draw(e)))
);

const createConfigFromEnv = pipe(
Expand Down
20 changes: 10 additions & 10 deletions src/octokit.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { GitHub } from '@actions/github';
import * as TE from 'fp-ts/lib/TaskEither';
import * as E from 'fp-ts/lib/Either';
import * as D from 'io-ts/lib/Decoder';
import { draw } from 'io-ts/lib/Tree';
import { Do } from 'fp-ts-contrib/lib/Do';
import * as t from 'io-ts';
import { ChecksCreateResponse, ChecksUpdateParamsOutputAnnotations, ChecksUpdateParams, Response } from '@octokit/rest';
import { pipe } from 'fp-ts/lib/pipeable';
import { failure } from 'io-ts/lib/PathReporter';

const EventDecoder = t.strict({
after: t.string,
repository: t.strict({
name: t.string,
owner: t.strict({
login: t.string,
const EventDecoder = D.type({
after: D.string,
repository: D.type({
name: D.string,
owner: D.type({
login: D.string,
}),
}),
});

type Event = t.TypeOf<typeof EventDecoder>;
type Event = D.TypeOf<typeof EventDecoder>;

export const createOctokitInstance = (token: string) => TE.fromEither(E.tryCatch(() => new GitHub(token), E.toError));

Expand Down Expand Up @@ -68,7 +68,7 @@ const parseEventFile = (eventPath: string) =>
E.chain(event =>
pipe(
EventDecoder.decode(event),
E.mapLeft(errors => new Error(failure(errors).join(';')))
E.mapLeft(errors => new Error(draw(errors)))
)
)
);
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"resolveJsonModule": true
"resolveJsonModule": true,
"skipLibCheck": true
}
}

0 comments on commit d5dffbc

Please sign in to comment.