mirror of
https://github.com/golangci/golangci-lint-action.git
synced 2025-12-17 07:58:27 +00:00
Use default branch for only-new-issues when push event
This commit is contained in:
parent
fdf641b40e
commit
3de9823efc
4 changed files with 180 additions and 30 deletions
1
.tool-versions
Normal file
1
.tool-versions
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
nodejs lts
|
||||||
69
dist/post_run/index.js
vendored
69
dist/post_run/index.js
vendored
|
|
@ -67782,17 +67782,42 @@ function fetchPatch() {
|
||||||
return ``;
|
return ``;
|
||||||
}
|
}
|
||||||
const ctx = github.context;
|
const ctx = github.context;
|
||||||
if (ctx.eventName !== `pull_request`) {
|
let patch;
|
||||||
core.info(`Not fetching patch for showing only new issues because it's not a pull request context: event name is ${ctx.eventName}`);
|
if (ctx.eventName === `pull_request`) {
|
||||||
|
patch = yield patchFromPR(ctx);
|
||||||
|
}
|
||||||
|
else if (ctx.eventName === `push`) {
|
||||||
|
patch = yield patchFromPush(ctx);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
core.info(`Not fetching patch for showing only new issues because it's not a pull request or push context: event name is ${ctx.eventName}`);
|
||||||
return ``;
|
return ``;
|
||||||
}
|
}
|
||||||
|
if (!patch) {
|
||||||
|
core.info(`Not using patch for showing only new issues because it's empty`);
|
||||||
|
return ``;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const tempDir = yield createTempDir();
|
||||||
|
const patchPath = path.join(tempDir, "pull.patch");
|
||||||
|
core.info(`Writing patch to ${patchPath}`);
|
||||||
|
yield writeFile(patchPath, patch);
|
||||||
|
return patchPath;
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
console.warn(`failed to save pull request patch:`, err);
|
||||||
|
return ``; // don't fail the action, but analyze without patch
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function patchFromPR(ctx) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const pull = ctx.payload.pull_request;
|
const pull = ctx.payload.pull_request;
|
||||||
if (!pull) {
|
if (!pull) {
|
||||||
core.warning(`No pull request in context`);
|
core.warning(`No pull request in context`);
|
||||||
return ``;
|
return ``;
|
||||||
}
|
}
|
||||||
const octokit = github.getOctokit(core.getInput(`github-token`, { required: true }));
|
const octokit = github.getOctokit(core.getInput(`github-token`, { required: true }));
|
||||||
let patch;
|
|
||||||
try {
|
try {
|
||||||
const patchResp = yield octokit.rest.pulls.get({
|
const patchResp = yield octokit.rest.pulls.get({
|
||||||
owner: ctx.repo.owner,
|
owner: ctx.repo.owner,
|
||||||
|
|
@ -67807,21 +67832,45 @@ function fetchPatch() {
|
||||||
return ``; // don't fail the action, but analyze without patch
|
return ``; // don't fail the action, but analyze without patch
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
patch = patchResp.data;
|
return patchResp.data;
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
console.warn(`failed to fetch pull request patch:`, err);
|
console.warn(`failed to fetch pull request patch:`, err);
|
||||||
return ``; // don't fail the action, but analyze without patch
|
return ``; // don't fail the action, but analyze without patch
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function patchFromPush(ctx) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
const octokit = github.getOctokit(core.getInput(`github-token`, { required: true }));
|
||||||
try {
|
try {
|
||||||
const tempDir = yield createTempDir();
|
const repoResp = yield octokit.rest.repos.get({
|
||||||
const patchPath = path.join(tempDir, "pull.patch");
|
owner: ctx.repo.owner,
|
||||||
core.info(`Writing patch to ${patchPath}`);
|
repo: ctx.repo.repo,
|
||||||
yield writeFile(patchPath, patch);
|
});
|
||||||
return patchPath;
|
if (repoResp.status !== 200) {
|
||||||
|
core.warning(`failed to fetch repo: response status is ${repoResp.status}`);
|
||||||
|
return ``;
|
||||||
|
}
|
||||||
|
const defaultBranch = repoResp.data.default_branch;
|
||||||
|
const patchResp = yield octokit.rest.repos.compareCommits({
|
||||||
|
owner: ctx.repo.owner,
|
||||||
|
repo: ctx.repo.repo,
|
||||||
|
base: defaultBranch,
|
||||||
|
head: ctx.sha,
|
||||||
|
mediaType: {
|
||||||
|
format: `diff`,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (patchResp.status !== 200) {
|
||||||
|
core.warning(`failed to fetch pull request patch: response status is ${patchResp.status}`);
|
||||||
|
return ``; // don't fail the action, but analyze without patch
|
||||||
|
}
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
return patchResp.data;
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
console.warn(`failed to save pull request patch:`, err);
|
console.warn(`failed to fetch push patch:`, err);
|
||||||
return ``; // don't fail the action, but analyze without patch
|
return ``; // don't fail the action, but analyze without patch
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
69
dist/run/index.js
vendored
69
dist/run/index.js
vendored
|
|
@ -67782,17 +67782,42 @@ function fetchPatch() {
|
||||||
return ``;
|
return ``;
|
||||||
}
|
}
|
||||||
const ctx = github.context;
|
const ctx = github.context;
|
||||||
if (ctx.eventName !== `pull_request`) {
|
let patch;
|
||||||
core.info(`Not fetching patch for showing only new issues because it's not a pull request context: event name is ${ctx.eventName}`);
|
if (ctx.eventName === `pull_request`) {
|
||||||
|
patch = yield patchFromPR(ctx);
|
||||||
|
}
|
||||||
|
else if (ctx.eventName === `push`) {
|
||||||
|
patch = yield patchFromPush(ctx);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
core.info(`Not fetching patch for showing only new issues because it's not a pull request or push context: event name is ${ctx.eventName}`);
|
||||||
return ``;
|
return ``;
|
||||||
}
|
}
|
||||||
|
if (!patch) {
|
||||||
|
core.info(`Not using patch for showing only new issues because it's empty`);
|
||||||
|
return ``;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const tempDir = yield createTempDir();
|
||||||
|
const patchPath = path.join(tempDir, "pull.patch");
|
||||||
|
core.info(`Writing patch to ${patchPath}`);
|
||||||
|
yield writeFile(patchPath, patch);
|
||||||
|
return patchPath;
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
console.warn(`failed to save pull request patch:`, err);
|
||||||
|
return ``; // don't fail the action, but analyze without patch
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function patchFromPR(ctx) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const pull = ctx.payload.pull_request;
|
const pull = ctx.payload.pull_request;
|
||||||
if (!pull) {
|
if (!pull) {
|
||||||
core.warning(`No pull request in context`);
|
core.warning(`No pull request in context`);
|
||||||
return ``;
|
return ``;
|
||||||
}
|
}
|
||||||
const octokit = github.getOctokit(core.getInput(`github-token`, { required: true }));
|
const octokit = github.getOctokit(core.getInput(`github-token`, { required: true }));
|
||||||
let patch;
|
|
||||||
try {
|
try {
|
||||||
const patchResp = yield octokit.rest.pulls.get({
|
const patchResp = yield octokit.rest.pulls.get({
|
||||||
owner: ctx.repo.owner,
|
owner: ctx.repo.owner,
|
||||||
|
|
@ -67807,21 +67832,45 @@ function fetchPatch() {
|
||||||
return ``; // don't fail the action, but analyze without patch
|
return ``; // don't fail the action, but analyze without patch
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
patch = patchResp.data;
|
return patchResp.data;
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
console.warn(`failed to fetch pull request patch:`, err);
|
console.warn(`failed to fetch pull request patch:`, err);
|
||||||
return ``; // don't fail the action, but analyze without patch
|
return ``; // don't fail the action, but analyze without patch
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function patchFromPush(ctx) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
const octokit = github.getOctokit(core.getInput(`github-token`, { required: true }));
|
||||||
try {
|
try {
|
||||||
const tempDir = yield createTempDir();
|
const repoResp = yield octokit.rest.repos.get({
|
||||||
const patchPath = path.join(tempDir, "pull.patch");
|
owner: ctx.repo.owner,
|
||||||
core.info(`Writing patch to ${patchPath}`);
|
repo: ctx.repo.repo,
|
||||||
yield writeFile(patchPath, patch);
|
});
|
||||||
return patchPath;
|
if (repoResp.status !== 200) {
|
||||||
|
core.warning(`failed to fetch repo: response status is ${repoResp.status}`);
|
||||||
|
return ``;
|
||||||
|
}
|
||||||
|
const defaultBranch = repoResp.data.default_branch;
|
||||||
|
const patchResp = yield octokit.rest.repos.compareCommits({
|
||||||
|
owner: ctx.repo.owner,
|
||||||
|
repo: ctx.repo.repo,
|
||||||
|
base: defaultBranch,
|
||||||
|
head: ctx.sha,
|
||||||
|
mediaType: {
|
||||||
|
format: `diff`,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (patchResp.status !== 200) {
|
||||||
|
core.warning(`failed to fetch pull request patch: response status is ${patchResp.status}`);
|
||||||
|
return ``; // don't fail the action, but analyze without patch
|
||||||
|
}
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
return patchResp.data;
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
console.warn(`failed to save pull request patch:`, err);
|
console.warn(`failed to fetch push patch:`, err);
|
||||||
return ``; // don't fail the action, but analyze without patch
|
return ``; // don't fail the action, but analyze without patch
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
71
src/run.ts
71
src/run.ts
|
|
@ -1,5 +1,6 @@
|
||||||
import * as core from "@actions/core"
|
import * as core from "@actions/core"
|
||||||
import * as github from "@actions/github"
|
import * as github from "@actions/github"
|
||||||
|
import { Context } from '@actions/github/lib/context'
|
||||||
import { exec, ExecOptions } from "child_process"
|
import { exec, ExecOptions } from "child_process"
|
||||||
import * as fs from "fs"
|
import * as fs from "fs"
|
||||||
import * as path from "path"
|
import * as path from "path"
|
||||||
|
|
@ -29,17 +30,40 @@ async function fetchPatch(): Promise<string> {
|
||||||
}
|
}
|
||||||
|
|
||||||
const ctx = github.context
|
const ctx = github.context
|
||||||
if (ctx.eventName !== `pull_request`) {
|
let patch: string
|
||||||
core.info(`Not fetching patch for showing only new issues because it's not a pull request context: event name is ${ctx.eventName}`)
|
if (ctx.eventName === `pull_request`) {
|
||||||
|
patch = await patchFromPR(ctx)
|
||||||
|
} else if (ctx.eventName === `push`) {
|
||||||
|
patch = await patchFromPush(ctx)
|
||||||
|
} else {
|
||||||
|
core.info(`Not fetching patch for showing only new issues because it's not a pull request or push context: event name is ${ctx.eventName}`)
|
||||||
return ``
|
return ``
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!patch) {
|
||||||
|
core.info(`Not using patch for showing only new issues because it's empty`)
|
||||||
|
return ``
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const tempDir = await createTempDir()
|
||||||
|
const patchPath = path.join(tempDir, "pull.patch")
|
||||||
|
core.info(`Writing patch to ${patchPath}`)
|
||||||
|
await writeFile(patchPath, patch)
|
||||||
|
return patchPath
|
||||||
|
} catch (err) {
|
||||||
|
console.warn(`failed to save pull request patch:`, err)
|
||||||
|
return `` // don't fail the action, but analyze without patch
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function patchFromPR(ctx: Context): Promise<string> {
|
||||||
const pull = ctx.payload.pull_request
|
const pull = ctx.payload.pull_request
|
||||||
if (!pull) {
|
if (!pull) {
|
||||||
core.warning(`No pull request in context`)
|
core.warning(`No pull request in context`)
|
||||||
return ``
|
return ``
|
||||||
}
|
}
|
||||||
const octokit = github.getOctokit(core.getInput(`github-token`, { required: true }))
|
const octokit = github.getOctokit(core.getInput(`github-token`, { required: true }))
|
||||||
let patch: string
|
|
||||||
try {
|
try {
|
||||||
const patchResp = await octokit.rest.pulls.get({
|
const patchResp = await octokit.rest.pulls.get({
|
||||||
owner: ctx.repo.owner,
|
owner: ctx.repo.owner,
|
||||||
|
|
@ -56,20 +80,47 @@ async function fetchPatch(): Promise<string> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
patch = patchResp.data as any
|
return patchResp.data as any
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.warn(`failed to fetch pull request patch:`, err)
|
console.warn(`failed to fetch pull request patch:`, err)
|
||||||
return `` // don't fail the action, but analyze without patch
|
return `` // don't fail the action, but analyze without patch
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function patchFromPush(ctx: Context): Promise<string> {
|
||||||
|
const octokit = github.getOctokit(core.getInput(`github-token`, { required: true }))
|
||||||
try {
|
try {
|
||||||
const tempDir = await createTempDir()
|
const repoResp = await octokit.rest.repos.get({
|
||||||
const patchPath = path.join(tempDir, "pull.patch")
|
owner: ctx.repo.owner,
|
||||||
core.info(`Writing patch to ${patchPath}`)
|
repo: ctx.repo.repo,
|
||||||
await writeFile(patchPath, patch)
|
})
|
||||||
return patchPath
|
|
||||||
|
if (repoResp.status !== 200) {
|
||||||
|
core.warning(`failed to fetch repo: response status is ${repoResp.status}`)
|
||||||
|
return ``
|
||||||
|
}
|
||||||
|
|
||||||
|
const defaultBranch = repoResp.data.default_branch
|
||||||
|
|
||||||
|
const patchResp = await octokit.rest.repos.compareCommits({
|
||||||
|
owner: ctx.repo.owner,
|
||||||
|
repo: ctx.repo.repo,
|
||||||
|
base: defaultBranch,
|
||||||
|
head: ctx.sha,
|
||||||
|
mediaType: {
|
||||||
|
format: `diff`,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (patchResp.status !== 200) {
|
||||||
|
core.warning(`failed to fetch pull request patch: response status is ${patchResp.status}`)
|
||||||
|
return `` // don't fail the action, but analyze without patch
|
||||||
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
return patchResp.data as any
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.warn(`failed to save pull request patch:`, err)
|
console.warn(`failed to fetch push patch:`, err)
|
||||||
return `` // don't fail the action, but analyze without patch
|
return `` // don't fail the action, but analyze without patch
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue