Skip to content

Commit

Permalink
Merge pull request #7 from sarthak-saxena/fix/running-action-on-merge…
Browse files Browse the repository at this point in the history
…-branch

Fix: Running on a branch fails as octokit not able to comment
  • Loading branch information
sarthak-saxena authored Apr 21, 2020
2 parents 61e5a48 + 2feaf2d commit 5c1e63b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 32 deletions.
42 changes: 18 additions & 24 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 [email protected]:${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"),
Expand Down Expand Up @@ -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";
Expand All @@ -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) {
Expand Down
26 changes: 18 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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) {
Expand Down

0 comments on commit 5c1e63b

Please sign in to comment.