diff --git a/dist/index.js b/dist/index.js index 0271b4d..46b63e6 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1397,22 +1397,6 @@ async function run() { const octokit = new github.GitHub(token); // --------------- End octokit initialization --------------- - // --------------- Checkout code --------------- // - // console.log("Checkout code"); - // - // await exec.exec( - // `git clone git@github.com:${github.context.repo.owner}/${ - // github.context.repo.repo - // }` - // ); - // - // const refBranch = github.context.ref; - // console.log("ref", refBranch); - // const branch = refBranch.split("refs/heads/")[1]; - // await exec.exec(`git checkout ${branch}`); - // - // End --------------- Checkout code --------------- // - // --------------- Build repo --------------- const bootstrap = core.getInput("bootstrap"), build_command = core.getInput("build_command"), @@ -1442,9 +1426,8 @@ async function run() { }; await exec.exec(`du ${dist_path}`, null, outputOptions); core.setOutput("size", sizeCalOutput); - const context = github.context, - pull_request_number = context.payload.pull_request.number; + pull_request = context.payload.pull_request; const arrayOutput = sizeCalOutput.split("\n"); let result = "Bundled size for the package is listed below: \n \n"; @@ -1455,12 +1438,23 @@ async function run() { } }); - octokit.issues.createComment( - Object.assign(Object.assign({}, context.repo), { - issue_number: pull_request_number, - body: result - }) - ); + if (pull_request) { + // on pull request commit push add comment to pull request + octokit.issues.createComment( + Object.assign(Object.assign({}, context.repo), { + issue_number: pull_request.number, + body: result + }) + ); + } else { + // on commit push add comment to commit + octokit.repos.createCommitComment( + Object.assign(Object.assign({}, context.repo), { + commit_sha: github.context.sha, + body: result + }) + ); + } // --------------- End Comment repo size --------------- } catch (error) { diff --git a/index.js b/index.js index 8688b7c..8472af1 100644 --- a/index.js +++ b/index.js @@ -45,9 +45,8 @@ async function run() { }; await exec.exec(`du ${dist_path}`, null, outputOptions); core.setOutput("size", sizeCalOutput); - const context = github.context, - pull_request_number = context.payload.pull_request.number; + pull_request = context.payload.pull_request; const arrayOutput = sizeCalOutput.split("\n"); let result = "Bundled size for the package is listed below: \n \n"; @@ -58,12 +57,23 @@ async function run() { } }); - octokit.issues.createComment( - Object.assign(Object.assign({}, context.repo), { - issue_number: pull_request_number, - body: result - }) - ); + if (pull_request) { + // on pull request commit push add comment to pull request + octokit.issues.createComment( + Object.assign(Object.assign({}, context.repo), { + issue_number: pull_request.number, + body: result + }) + ); + } else { + // on commit push add comment to commit + octokit.repos.createCommitComment( + Object.assign(Object.assign({}, context.repo), { + commit_sha: github.context.sha, + body: result + }) + ); + } // --------------- End Comment repo size --------------- } catch (error) {