Skip to content

Commit

Permalink
fix: update probot to 10 (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpoehnelt authored Sep 15, 2020
1 parent d9b2d6e commit b2a85a0
Show file tree
Hide file tree
Showing 7 changed files with 815 additions and 466 deletions.
1,208 changes: 769 additions & 439 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"gitdiff-parser": "^0.2.2",
"js-yaml": "^3.14.0",
"minimatch": "^3.0.4",
"probot": "^9.13.0"
"probot": "^10.2.0"
},
"devDependencies": {
"@rollup/plugin-node-resolve": "^9.0.0",
Expand Down
3 changes: 1 addition & 2 deletions src/annotate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { annotate, getLevelFromAnnotations } from "./annotate";

import { DEFAULT_CONFIGURATION } from "./config";
import { Level } from "./rules";
import { Octokit } from "@octokit/rest/";
import fs from "fs";
import { parse } from "./parse";

Expand Down Expand Up @@ -83,6 +82,6 @@ test("should get correct level from annotations", () => {
{ annotation_level: "notice" },
{ annotation_level: "warning" },
{ annotation_level: "failure" },
] as Octokit.ChecksUpdateParamsOutputAnnotations[])
] as any)
).toBe(Level.FAILURE);
});
20 changes: 15 additions & 5 deletions src/annotate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,28 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { Configuration } from "./config";
import { File } from "gitdiff-parser";
import { Level } from "./rules";
import { Octokit } from "@octokit/rest/";
import minimatch from "minimatch";

export type ChecksUpdateParamsOutputAnnotations = {
path: string;
start_line: number;
end_line: number;
start_column?: number;
end_column?: number;
annotation_level: "notice" | "warning" | "failure";
message: string;
title?: string;
raw_details?: string;
};

export const annotate = (
config: Configuration,
files: File[]
): Octokit.ChecksUpdateParamsOutputAnnotations[] => {
const annotations: Octokit.ChecksUpdateParamsOutputAnnotations[] = [];
): ChecksUpdateParamsOutputAnnotations[] => {
const annotations: ChecksUpdateParamsOutputAnnotations[] = [];

for (const f of files) {
if (
Expand Down Expand Up @@ -69,7 +79,7 @@ export const annotate = (
const levels = [Level.OFF, Level.NOTICE, Level.WARNING, Level.FAILURE];

export const getLevelFromAnnotations = (
annotations: Octokit.ChecksUpdateParamsOutputAnnotations[]
annotations: ChecksUpdateParamsOutputAnnotations[]
): Level => {
let level = Level.OFF;

Expand Down
11 changes: 5 additions & 6 deletions src/solidarity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@

import { Conclusion, OutputTitle, Solidarity } from "./solidarity";

import { Context } from "probot";
import { DEFAULT_CONFIGURATION } from "./config";
import { LoggerWithTarget } from "probot/lib/wrap-logger";
import { Logger } from "probot";
import fs from "fs";
import { parse } from "./parse";

Expand All @@ -29,8 +28,8 @@ const failingDIff = parse(

test("solidarity should run check on failing diff", async () => {
const s = new Solidarity(
{ name: "foo", id: "bar", payload: payload } as Context,
({ info: jest.fn() } as unknown) as LoggerWithTarget
{ name: "foo", id: "bar", payload: payload } as any,
({ info: jest.fn() } as unknown) as Logger
);

s.diff = jest.fn().mockReturnValue(failingDIff);
Expand All @@ -44,8 +43,8 @@ test("solidarity should run check on failing diff", async () => {

test("solidarity should have correct properties from payload", async () => {
const s = new Solidarity(
{ name: "foo", id: "bar", payload: payload } as Context,
({ info: jest.fn() } as unknown) as LoggerWithTarget
{ name: "foo", id: "bar", payload: payload } as any,
({ info: jest.fn() } as unknown) as Logger
);
expect(s.owner).toEqual("jpoehnelt");
expect(s.repo).toEqual("in-solidarity-bot");
Expand Down
35 changes: 23 additions & 12 deletions src/solidarity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,28 @@
* limitations under the License.
*/

import {
ChecksUpdateParamsOutputAnnotations,
annotate,
getLevelFromAnnotations,
} from "./annotate";
import { Configuration, InvalidConfigError, getConfig } from "./config";
import { annotate, getLevelFromAnnotations } from "./annotate";
import { Context, Logger } from "probot";

import { Context } from "probot";
import { File } from "gitdiff-parser";
import { Level } from "./rules";
import { LoggerWithTarget } from "probot/lib/wrap-logger";
import { Octokit } from "@octokit/rest/";
import { RestEndpointMethodTypes } from "@octokit/plugin-rest-endpoint-methods";
import fs from "fs";
import { parse } from "./parse";

type ChecksCreateParams = RestEndpointMethodTypes["checks"]["create"]["parameters"];

export type ChecksUpdateParamsOutput = {
title: string;
summary: string;
annotations?: ChecksUpdateParamsOutputAnnotations[];
};

const SUMMARY = fs.readFileSync("./static/HELP.md", "utf8");
const CHECK_NAME = "Inclusive Language";

Expand All @@ -48,11 +59,11 @@ export enum OutputTitle {

export class Solidarity {
private context: Context;
private logger: LoggerWithTarget;
private logger: Logger;
private checkId?: number;
config?: Configuration;

constructor(context: Context, logger: LoggerWithTarget) {
constructor(context: Context, logger: Logger) {
this.context = context;
this.logger = logger;
}
Expand All @@ -73,7 +84,7 @@ export class Solidarity {
return this.context.payload.number;
}

get checkOptions(): Octokit.ChecksCreateParams {
get checkOptions(): ChecksCreateParams {
return {
owner: this.owner,
repo: this.repo,
Expand All @@ -84,14 +95,14 @@ export class Solidarity {

async run(): Promise<void> {
let conclusion: Conclusion = Conclusion.NEUTRAL;
let output: Octokit.ChecksUpdateParamsOutput;
let output: { title: string; summary: string };

await this.start();
await this.update("in_progress");

try {
this.config = await getConfig(this.context);
this.logger.info(this.config);
this.logger.info(this.config, "Loaded config");
} catch (e) {
if (e instanceof InvalidConfigError) {
conclusion = Conclusion.FAILURE;
Expand Down Expand Up @@ -170,7 +181,7 @@ export class Solidarity {
async update(
status: "queued" | "in_progress" | "completed",
conclusion?: Conclusion,
output?: Octokit.ChecksUpdateParamsOutput,
output?: ChecksUpdateParamsOutput,
details_url?: string
): Promise<void> {
try {
Expand Down Expand Up @@ -205,10 +216,10 @@ export class Solidarity {

async check(): Promise<{
conclusion: Conclusion;
output: Octokit.ChecksUpdateParamsOutput;
output: ChecksUpdateParamsOutput;
}> {
let conclusion: Conclusion;
const output: Octokit.ChecksUpdateParamsOutput = {
const output: ChecksUpdateParamsOutput = {
title: CHECK_NAME,
summary: SUMMARY,
};
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"noImplicitAny": false,
"esModuleInterop": true,
"declaration": true,
"resolveJsonModule": true
"resolveJsonModule": true,
},
"include": [
"src/**/*"
Expand Down

0 comments on commit b2a85a0

Please sign in to comment.