Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to octokit handling of Annotations #207

Closed
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
WHAT DO YOU SEEEEEE
thebeline committed Apr 5, 2021
commit 94f1966589c6498630ee692b20ca88a4354ff421
22 changes: 18 additions & 4 deletions dist/post_run/index.js
Original file line number Diff line number Diff line change
@@ -6852,16 +6852,29 @@ const logLintIssues = (issues) => {
});
};
function annotateLintIssues(issues) {
var _a;
var _a, _b;
return __awaiter(this, void 0, void 0, function* () {
if (!issues.length) {
return;
}
const ctx = github.context;
const ref = ctx.payload.after;
core.info(util_1.inspect({
ctx: ctx,
GITHUB_WORKFLOW: process.env["GITHUB_WORKFLOW"],
GITHUB_RUN_ID: process.env["GITHUB_RUN_ID"],
GITHUB_RUN_NUMBER: process.env["GITHUB_RUN_NUMBER"],
GITHUB_JOB: process.env["GITHUB_JOB"],
GITHUB_ACTION: process.env["GITHUB_ACTION"],
GITHUB_ACTIONS: process.env["GITHUB_ACTIONS"],
GITHUB_SHA: process.env["GITHUB_SHA"],
GITHUB_REF: process.env["GITHUB_REF"],
GITHUB_HEAD_REF: process.env["GITHUB_HEAD_REF"],
GITHUB_BASE_REF: process.env["GITHUB_BASE_REF"],
}, false, 4));
const ref = (_a = ctx.payload.after) !== null && _a !== void 0 ? _a : ctx.sha;
const octokit = github.getOctokit(core.getInput(`github-token`, { required: true }));
const checkRunsPromise = octokit.checks
.listForRef(Object.assign(Object.assign({}, ctx.repo), { ref, status: "in_progress" }))
.listForRef(Object.assign(Object.assign({}, ctx.repo), { ref, status: `in_progress`, filter: `latest` }))
.catch((e) => {
throw `Error getting Check Run Data: ${e}`;
});
@@ -6906,6 +6919,7 @@ function annotateLintIssues(issues) {
});
let checkRun;
const { data: checkRunsResponse } = yield checkRunsPromise;
core.info(util_1.inspect(checkRunsResponse, false, 4));
if (checkRunsResponse.check_runs.length === 0) {
throw `octokit.checks.listForRef(${ref}) returned no results`;
}
@@ -6915,7 +6929,7 @@ function annotateLintIssues(issues) {
if (!(checkRun === null || checkRun === void 0 ? void 0 : checkRun.id)) {
throw `Could not find current check run`;
}
const title = (_a = checkRun.output.title) !== null && _a !== void 0 ? _a : `GolangCI-Lint`;
const title = (_b = checkRun.output.title) !== null && _b !== void 0 ? _b : `GolangCI-Lint`;
const summary = `There are {issueCounts.failure} failures, {issueCounts.wairning} warnings, and {issueCounts.notice} notices.`;
Array.from({ length: Math.ceil(githubAnnotations.length / chunkSize) }, (v, i) => githubAnnotations.slice(i * chunkSize, i * chunkSize + chunkSize)).forEach((annotations) => {
octokit.checks
22 changes: 18 additions & 4 deletions dist/run/index.js
Original file line number Diff line number Diff line change
@@ -6862,16 +6862,29 @@ const logLintIssues = (issues) => {
});
};
function annotateLintIssues(issues) {
var _a;
var _a, _b;
return __awaiter(this, void 0, void 0, function* () {
if (!issues.length) {
return;
}
const ctx = github.context;
const ref = ctx.payload.after;
core.info(util_1.inspect({
ctx: ctx,
GITHUB_WORKFLOW: process.env["GITHUB_WORKFLOW"],
GITHUB_RUN_ID: process.env["GITHUB_RUN_ID"],
GITHUB_RUN_NUMBER: process.env["GITHUB_RUN_NUMBER"],
GITHUB_JOB: process.env["GITHUB_JOB"],
GITHUB_ACTION: process.env["GITHUB_ACTION"],
GITHUB_ACTIONS: process.env["GITHUB_ACTIONS"],
GITHUB_SHA: process.env["GITHUB_SHA"],
GITHUB_REF: process.env["GITHUB_REF"],
GITHUB_HEAD_REF: process.env["GITHUB_HEAD_REF"],
GITHUB_BASE_REF: process.env["GITHUB_BASE_REF"],
}, false, 4));
const ref = (_a = ctx.payload.after) !== null && _a !== void 0 ? _a : ctx.sha;
const octokit = github.getOctokit(core.getInput(`github-token`, { required: true }));
const checkRunsPromise = octokit.checks
.listForRef(Object.assign(Object.assign({}, ctx.repo), { ref, status: "in_progress" }))
.listForRef(Object.assign(Object.assign({}, ctx.repo), { ref, status: `in_progress`, filter: `latest` }))
.catch((e) => {
throw `Error getting Check Run Data: ${e}`;
});
@@ -6916,6 +6929,7 @@ function annotateLintIssues(issues) {
});
let checkRun;
const { data: checkRunsResponse } = yield checkRunsPromise;
core.info(util_1.inspect(checkRunsResponse, false, 4));
if (checkRunsResponse.check_runs.length === 0) {
throw `octokit.checks.listForRef(${ref}) returned no results`;
}
@@ -6925,7 +6939,7 @@ function annotateLintIssues(issues) {
if (!(checkRun === null || checkRun === void 0 ? void 0 : checkRun.id)) {
throw `Could not find current check run`;
}
const title = (_a = checkRun.output.title) !== null && _a !== void 0 ? _a : `GolangCI-Lint`;
const title = (_b = checkRun.output.title) !== null && _b !== void 0 ? _b : `GolangCI-Lint`;
const summary = `There are {issueCounts.failure} failures, {issueCounts.wairning} warnings, and {issueCounts.notice} notices.`;
Array.from({ length: Math.ceil(githubAnnotations.length / chunkSize) }, (v, i) => githubAnnotations.slice(i * chunkSize, i * chunkSize + chunkSize)).forEach((annotations) => {
octokit.checks
27 changes: 24 additions & 3 deletions src/run.ts
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ import { exec, ExecOptions } from "child_process"
import * as fs from "fs"
import * as path from "path"
import { dir } from "tmp"
import { promisify } from "util"
import { inspect, promisify } from "util"

import { restoreCache, saveCache } from "./cache"
import { installGo, installLint } from "./install"
@@ -236,13 +236,33 @@ async function annotateLintIssues(issues: LintIssue[]): Promise<void> {
return
}
const ctx = github.context
const ref = ctx.payload.after
core.info(
inspect(
{
ctx: ctx,
GITHUB_WORKFLOW: process.env["GITHUB_WORKFLOW"],
GITHUB_RUN_ID: process.env["GITHUB_RUN_ID"],
GITHUB_RUN_NUMBER: process.env["GITHUB_RUN_NUMBER"],
GITHUB_JOB: process.env["GITHUB_JOB"],
GITHUB_ACTION: process.env["GITHUB_ACTION"],
GITHUB_ACTIONS: process.env["GITHUB_ACTIONS"],
GITHUB_SHA: process.env["GITHUB_SHA"],
GITHUB_REF: process.env["GITHUB_REF"],
GITHUB_HEAD_REF: process.env["GITHUB_HEAD_REF"],
GITHUB_BASE_REF: process.env["GITHUB_BASE_REF"],
},
false,
4
)
)
const ref = ctx.payload.after ?? ctx.sha
const octokit = github.getOctokit(core.getInput(`github-token`, { required: true }))
const checkRunsPromise = octokit.checks
.listForRef({
...ctx.repo,
ref,
status: "in_progress",
status: `in_progress`,
filter: `latest`,
})
.catch((e) => {
throw `Error getting Check Run Data: ${e}`
@@ -293,6 +313,7 @@ async function annotateLintIssues(issues: LintIssue[]): Promise<void> {
)
let checkRun: CheckRun | undefined
const { data: checkRunsResponse } = await checkRunsPromise
core.info(inspect(checkRunsResponse, false, 4))
if (checkRunsResponse.check_runs.length === 0) {
throw `octokit.checks.listForRef(${ref}) returned no results`
} else {