Skip to content

Commit

Permalink
chore: 🚧 Fix badge
Browse files Browse the repository at this point in the history
  • Loading branch information
robvanderleek committed Dec 2, 2024
1 parent b45b1fa commit c0b814f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
21 changes: 15 additions & 6 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46807,7 +46807,10 @@ var require_github2 = __commonJS({
owner,
repo,
ref: `refs/heads/${branchName}`,
path
path,
headers: {
"Accept": "application/vnd.github.object+json"
}
});
sha = res.data.sha;
} catch (e) {
Expand Down Expand Up @@ -48824,12 +48827,14 @@ function makeResponse(message, color) {
};
return (0, badge_maker_1.makeBadge)(badge);
}
function getBadgeContent() {
const report = fs_1.default.readFileSync(".codelimit_cache/codelimit.json", "utf8");
if (!report) {
function getReportContent() {
return fs_1.default.readFileSync(".codelimit_cache/codelimit.json", "utf8");
}
function getBadgeContent(reportContent) {
if (!reportContent) {
return makeResponse("Not found", "grey");
} else {
const reportJson = JSON.parse(report);
const reportJson = JSON.parse(reportContent);
const profile = reportJson.codebase.tree["./"].profile;
if (profile[3] > 0) {
return makeResponse("Needs refactoring", "red");
Expand All @@ -48856,7 +48861,11 @@ function main() {
process.exit(1);
}
yield createReportsBranchIfNotExists(octokit, owner, repo);
yield (0, github_2.createOrUpdateFile)(octokit, owner, repo, "_codelimit_reports", "main/badge.svg", getBadgeContent());
const reportContent = getReportContent();
yield (0, github_2.createOrUpdateFile)(octokit, owner, repo, "_codelimit_reports", "main/badge.svg", getBadgeContent(reportContent));
if (reportContent) {
yield (0, github_2.createOrUpdateFile)(octokit, owner, repo, "_codelimit_reports", "main/report.json", reportContent);
}
let exitCode = 0;
if (doUpload) {
console.log("Uploading results...");
Expand Down
19 changes: 13 additions & 6 deletions src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {getInput} from "@actions/core";
import {promisify} from "util";
import {context} from "@actions/github";
import {Octokit} from "@octokit/action";
import {branchExists, createBranch, createOrUpdateFile, createInitialCommit, getRepoName, getRepoOwner} from "./github";
import {branchExists, createBranch, createInitialCommit, createOrUpdateFile, getRepoName, getRepoOwner} from "./github";
import {exec} from "@actions/exec";
import {makeBadge} from "badge-maker";

Expand Down Expand Up @@ -110,12 +110,15 @@ function makeResponse(message: string, color: 'red' | 'orange' | 'green' | 'grey
return makeBadge(badge);
}

function getBadgeContent(): string {
const report = fs.readFileSync('.codelimit_cache/codelimit.json', 'utf8');
if (!report) {
function getReportContent(): string | undefined {
return fs.readFileSync('.codelimit_cache/codelimit.json', 'utf8');
}

function getBadgeContent(reportContent: string | undefined): string {
if (!reportContent) {
return makeResponse('Not found', 'grey');
} else {
const reportJson = JSON.parse(report);
const reportJson = JSON.parse(reportContent);
const profile = reportJson.codebase.tree['./'].profile
if (profile[3] > 0) {
return makeResponse('Needs refactoring', 'red');
Expand All @@ -141,7 +144,11 @@ async function main() {
process.exit(1);
}
await createReportsBranchIfNotExists(octokit, owner, repo);
await createOrUpdateFile(octokit, owner, repo, '_codelimit_reports', 'main/badge.svg', getBadgeContent());
const reportContent = getReportContent();
await createOrUpdateFile(octokit, owner, repo, '_codelimit_reports', 'main/badge.svg', getBadgeContent(reportContent));
if (reportContent) {
await createOrUpdateFile(octokit, owner, repo, '_codelimit_reports', 'main/report.json', reportContent);
}
let exitCode = 0;
if (doUpload) {
console.log('Uploading results...');
Expand Down
5 changes: 4 additions & 1 deletion src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ export async function createOrUpdateFile(octokit: Octokit, owner: string, repo:
owner: owner,
repo: repo,
ref: `refs/heads/${branchName}`,
path: path
path: path,
headers: {
"Accept": "application/vnd.github.object+json"
}
});
sha = (res.data as any).sha;
} catch (e) {
Expand Down

0 comments on commit c0b814f

Please sign in to comment.