Skip to content

Commit

Permalink
feat: ✨ Do not update report branch for fork PRs
Browse files Browse the repository at this point in the history
  • Loading branch information
robvanderleek committed Dec 6, 2024
1 parent 05c195d commit 98e35fa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
10 changes: 8 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46753,6 +46753,7 @@ var require_github2 = __commonJS({
exports2.createPRComment = createPRComment;
exports2.updateComment = updateComment;
exports2.isPullRequest = isPullRequest;
exports2.isPullRequestFromFork = isPullRequestFromFork;
exports2.getSourceBranch = getSourceBranch;
exports2.createBranchIfNotExists = createBranchIfNotExists;
var github_12 = require_github();
Expand Down Expand Up @@ -46887,6 +46888,10 @@ var require_github2 = __commonJS({
function isPullRequest() {
return github_12.context.eventName === "pull_request";
}
function isPullRequestFromFork() {
var _a, _b;
return isPullRequest() && ((_b = (_a = github_12.context.payload.pull_request) === null || _a === void 0 ? void 0 : _a.head.repo) === null || _b === void 0 ? void 0 : _b.fork) === true;
}
function getSourceBranch() {
if (isPullRequest()) {
return process.env.GITHUB_HEAD_REF;
Expand Down Expand Up @@ -49110,18 +49115,19 @@ function checkChangedFiles(octokit, clBinary) {
function main() {
return __awaiter(this, void 0, void 0, function* () {
console.log(`Code Limit action, version: ${version_1.version.revision}`);
console.log(JSON.stringify(github_1.context));
let exitCode = 0;
const clBinary = yield (0, codelimit_1.downloadCodeLimitBinary)();
console.log("Scanning codebase...");
yield (0, exec_1.exec)(clBinary, ["scan", "."]);
const markdownReport = yield generateMarkdownReport(clBinary);
const octokit = new action_1.Octokit({ auth: (0, core_1.getInput)("token") });
yield updateReportsBranch(octokit, markdownReport);
const doCheck = (0, core_1.getInput)("check") || true;
if (doCheck) {
exitCode = yield checkChangedFiles(octokit, clBinary);
}
if (!(0, github_2.isPullRequestFromFork)()) {
yield updateReportsBranch(octokit, markdownReport);
}
fs_1.default.unlinkSync(clBinary);
console.log("Done!");
process.exit(exitCode);
Expand Down
7 changes: 4 additions & 3 deletions src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
getRepoName,
getRepoOwner,
getSourceBranch,
isPullRequest, updateComment
isPullRequest, isPullRequestFromFork, updateComment
} from "./github";
import {exec, getExecOutput} from "@actions/exec";
import {downloadCodeLimitBinary, getBadgeContent, getReportContent} from "./codelimit";
Expand Down Expand Up @@ -82,18 +82,19 @@ async function checkChangedFiles(octokit: Octokit, clBinary: string): Promise<nu

async function main() {
console.log(`Code Limit action, version: ${version.revision}`);
console.log(JSON.stringify(context));
let exitCode = 0;
const clBinary = await downloadCodeLimitBinary();
console.log('Scanning codebase...');
await exec(clBinary, ['scan', '.']);
const markdownReport = await generateMarkdownReport(clBinary);
const octokit = new Octokit({auth: getInput('token')});
await updateReportsBranch(octokit, markdownReport);
const doCheck = getInput('check') || true;
if (doCheck) {
exitCode = await checkChangedFiles(octokit, clBinary);
}
if (!isPullRequestFromFork()) {
await updateReportsBranch(octokit, markdownReport);
}
fs.unlinkSync(clBinary);
console.log('Done!');
process.exit(exitCode);
Expand Down
4 changes: 4 additions & 0 deletions src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ export function isPullRequest() {
return context.eventName === 'pull_request';
}

export function isPullRequestFromFork() {
return isPullRequest() && context.payload.pull_request?.head.repo?.fork === true;
}

export function getSourceBranch() {
if (isPullRequest()) {
return process.env.GITHUB_HEAD_REF;
Expand Down

0 comments on commit 98e35fa

Please sign in to comment.