Skip to content

Commit

Permalink
spread repo object, move labelName const into run()
Browse files Browse the repository at this point in the history
  • Loading branch information
naseemkullah committed Aug 5, 2021
1 parent e3b08c4 commit 81149dc
Showing 1 changed file with 12 additions and 20 deletions.
32 changes: 12 additions & 20 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,30 @@ import {promisify} from 'util';
const execP = promisify(exec);
const octokit = github.getOctokit(core.getInput('token'));
const context = github.context;
const {owner, repo} = context.repo;
const {repo} = context;
const event_type = context.eventName;

const labelName = 'lfs-detected!'

// most @actions toolkit packages have async methods
async function run() {
try {
const fsl = core.getInput('filesizelimit');

core.info(`Default configured filesizelimit is set to ${fsl} bytes...`);
core.info(`Name of Repository is ${repo} and the owner is ${owner}`);
core.info(`Name of Repository is ${repo.repo} and the owner is ${repo.owner}`);
core.info(`Triggered event is ${event_type}`);

const labelName = 'lfs-detected!'

// Get LFS Warning Label
try {
await octokit.rest.issues.getLabel({
owner,
repo,
...repo,
name: labelName,
});
} catch (error) {
if (error.message === 'Not Found') {
await octokit.rest.issues.createLabel({
owner,
repo,
...repo,
name: 'lfs-detected!',
color: 'ff1493',
description:
Expand All @@ -54,17 +52,15 @@ async function run() {
core.info(`The PR number is: ${pullRequestNumber}`);

const {data: files} = await octokit.rest.pulls.listFiles({
owner,
repo,
...repo,
pull_number: pullRequestNumber,
});

const prFilesWithBlobSize = await Promise.all(
files.map(async file => {
const {filename, sha, patch} = file;
const {data: blob} = await octokit.rest.git.getBlob({
owner,
repo,
...repo,
file_sha: sha,
});

Expand Down Expand Up @@ -129,15 +125,13 @@ async function run() {
}`;

await octokit.rest.issues.addLabels({
owner,
repo,
...repo,
issue_number: pullRequestNumber,
labels: [labelName],
});

await octokit.rest.issues.createComment({
owner,
repo,
...repo,
issue_number: pullRequestNumber,
body,
});
Expand All @@ -150,14 +144,12 @@ async function run() {
core.info('No large file(s) detected...');

const {data: labels} = await octokit.rest.issues.listLabelsOnIssue({
owner,
repo,
...repo,
issue_number: 1,
})
if (labels.map(l => l.name).includes(labelName)) {
await octokit.rest.issues.removeLabel({
owner,
repo,
...repo,
issue_number: 1,
name: labelName
});
Expand Down

0 comments on commit 81149dc

Please sign in to comment.