From 1a9b1fecb2c656026a41a1d4d17d713f1f01088b Mon Sep 17 00:00:00 2001 From: Rob van der Leek <5324924+robvanderleek@users.noreply.github.com> Date: Wed, 4 Dec 2024 11:56:20 +0100 Subject: [PATCH] =?UTF-8?q?refactor:=20=E2=99=BB=EF=B8=8F=20Refactor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 49 ++++++++++++++++++++++++++++------------------- action.yml | 4 ---- docs/logo.png | Bin 0 -> 9488 bytes src/action.ts | 52 +++++++++++++++++++++++--------------------------- src/utils.ts | 29 +++++++++++++++------------- 5 files changed, 69 insertions(+), 65 deletions(-) create mode 100644 docs/logo.png diff --git a/README.md b/README.md index e9b551a..4c268a7 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,30 @@ -# codelimit-action +# Code Limit GitHub Action +
+ +![Logo](docs/logo.png) + +
+ +
+ + *Your Refactoring Alarm 🔔 As a GitHub Action* + +
+ +
+ +[![main](https://github.com/getcodelimit/codelimit-action/actions/workflows/main.yml/badge.svg)](https://github.com/getcodelimit/codelimit-action/actions/workflows/main.yml) [![Checked with Code Limit](https://github.com/getcodelimit/codelimit-action/blob/_codelimit_reports/main/badge.svg)](https://github.com/getcodelimit/codelimit-action/blob/_codelimit_reports/main/codelimit.md) -To run Code Limit on every push and before every merge to main, append it to your GH Action workflow: +
+ +To run Code Limit on every push and before every merge to main, append it to +your GH Action workflow: ```yaml name: 'main' + on: push: branches: @@ -13,24 +32,14 @@ on: pull_request: branches: - main - jobs: - ci: - runs-on: ubuntu-latest - steps: - - name: 'Checkout sources' - uses: actions/checkout@v4 - - name: 'Run Code Limit' - uses: getcodelimit/codelimit-action@main -``` - -## Upload report -To upload the report to Code Limit, add the following step to your workflow: +jobs: + ci: + runs-on: ubuntu-latest + steps: + - name: 'Checkout sources' + uses: actions/checkout@v4 -```yaml - - name: 'Run Code Limit' - uses: getcodelimit/codelimit-action@main - with: - upload: true - token: ${{ secrets.GITHUB_TOKEN }} + - name: 'Run Code Limit' + uses: getcodelimit/codelimit-action@main ``` diff --git a/action.yml b/action.yml index c92abad..c2e6823 100644 --- a/action.yml +++ b/action.yml @@ -14,7 +14,3 @@ inputs: description: 'Checked changed files' default: 'true' required: false - upload: - description: 'Upload report to Code Limit' - default: 'false' - required: false diff --git a/docs/logo.png b/docs/logo.png new file mode 100644 index 0000000000000000000000000000000000000000..c6b4b52f6b00ec7bb16872174c757cf16ce00477 GIT binary patch literal 9488 zcmd6N`9G9h`2Rh|(j#k;ERjhMk3Cyttwxe0%aDD^o?RsCsFWo{A^TRA8s-tGdS55u>J`{l-{H%2eBVyg{yjK&t-Ot5mBxE|fF=I_ z{?~n*hKam@fs?mu?|OP%Bp*CpKl<&a=oE!UJ}{>N2~F)azz$Z@8S>SZRk*LOv`UV- z=#5-88rg`1Vz`Uy?<$x=0`CHM{^tGh+4921(9t24Cl*a#^0uY0BcVTSb)HDPpUAv{ zn#6E;3Z1F3tdd4qA;Pv^L^|^64}uvTPum|6r#mH%z;=8fLJnQ5SX4RGJXIMeh}G9ncpxQ3zFXF1M$#W> z34t6k={E5{3D~l8K?5fTTK2i;p1vMC_e6kIg+C?OPYfD^!t8(~9}ZK`nin@ttx8s| z^ur$l%F=qUWnC9XHe9K@IE0og5Q86q%wZQd9{B~?u{c?Sccj_DI(C)b?=^0n!j3KA zkCc=+>zVugEh*VExw^Rs6=cwDmOK0V`m}taqodUf4`tD9F8t*mcvZfvtZWmuke)Rq zUGCOMM9Dg~YZ22=3~Jn(-r3nPfvSlSa;5hX#+^+zHAv#(PdTXIk=u+}<-M0LPd&LL z!kN#4kt_EKkAVzi8~+|JnL&SzfXIj{q=D93F^Kk10Gj}He*3#oC?D@W&a zVo4#B`pVwE2|5#c<>Kv~XmFQ>fc-moic@P#9eXLWDNEM+jvMinvcf^QRo!?b2@%Pw zw|chy=4?<)q-l{`vI?t8wi)T|YUp;uwcizam2SjL=lAI+t+S39=3nv9U7GHP23YEp z#q_V-XtGgI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)g z(Mwl=4#r<+o69$RENlv@fE~EzjDfqVQ&p1>y^lbsOfp!$EaGAe4hCWt8zwZkrYk~i+i1h4#!RvAnT>rfV09yQ&4z;r=)D8WG zl>fab05Wg~Z`uh&0C1oB5sdGZ9f6CH8$castc<%;63N{oBsecDPINbAtM&3Sw*pX*ka{&IO2ai#3 zx7uc!py(&y-a<9-OD9I^a`*5kWS?6B0=a_ak-j7tlRK}jBS?5qU$KNQ>@VRmJpyh; ztZ%Uu6mZT(e*au_l6T@!KODa)!nQeb70{=yP$5g5&*}Ev7ZQe|kAI}chYHsgc~wXl z{(KA0izR^S7rD*W;J`gxFvqXLd2(r52YO*j>RDaD?bwR+7$hEWyi?r8c=Y_=zMvVV z$Vk9Ib@;g xjhg~@NOloVENE81{618 { + const changedFiles = await getChangedFiles(octokit); + console.log(`Number of files changed: ${changedFiles.length}`); + if (changedFiles.length === 0) { + console.log('No files changed, skipping Code Limit'); + return 0; + } else { + console.log('Running Code Limit...'); + return await exec(clBinary, ['check'].concat(changedFiles), {ignoreReturnCode: true}); } +} + +async function main() { + 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 === 0) { - const changedFiles = await getChangedFiles(token); - console.log(`Number of files changed: ${changedFiles.length}`); - if (changedFiles.length === 0) { - console.log('No files changed, skipping Code Limit'); - } else { - console.log('Running Code Limit...'); - exitCode = await exec(clBinary, ['check'].concat(changedFiles), {ignoreReturnCode: true}); - } + if (doCheck) { + exitCode = await checkChangedFiles(octokit, clBinary); } fs.unlinkSync(clBinary); console.log('Done!'); diff --git a/src/utils.ts b/src/utils.ts index 0c794c0..ee1f357 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,21 +1,11 @@ import {context} from "@actions/github"; import {Octokit} from "@octokit/action"; -export async function getChangedFiles(token: string) { - const eventName = context.eventName - if (eventName === undefined) { +export async function getChangedFiles(octokit: Octokit) { + if (context.eventName === undefined) { return ['.']; } - let base; - let head; - if (eventName === 'pull_request') { - base = context.payload.pull_request?.base?.sha - head = context.payload.pull_request?.head?.sha - } else { - base = context.payload.before - head = context.payload.after - } - const octokit = new Octokit({auth: token}); + const {base, head} = getShas(); const response = await octokit.repos.compareCommits({ base, head, owner: context.repo.owner, repo: context.repo.repo }); @@ -33,4 +23,17 @@ export async function getChangedFiles(token: string) { } } return result; +} + +function getShas(): { base: string, head: string } { + let base; + let head; + if (context.eventName === 'pull_request') { + base = context.payload.pull_request?.base?.sha + head = context.payload.pull_request?.head?.sha + } else { + base = context.payload.before + head = context.payload.after + } + return {base: base, head: head}; } \ No newline at end of file