Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pull request comment #16

Merged
merged 2 commits into from
Feb 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ inputs:
includeCommitMessage:
description: 'Include commit message'
required: false
default: 'true'
debug:
description: 'Output debug info'
required: false
required: false,
default: 'false'
artifactName:
description: 'Artifact to download when running in workflow_run'
required: false
Expand Down
41 changes: 28 additions & 13 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49714,44 +49714,59 @@ function extractParams(context) {
*/

function extractPullRequestParams(context, token, includeCommitMessage) {
var _a, _b, _c;
var _a, _b, _c, _d;

return params_awaiter(this, void 0, void 0, function () {
var payload, repo, pullRequest, commitMessage, octokit, commit, branch, pr;
return params_generator(this, function (_d) {
switch (_d.label) {
var payload, repo, pullRequest, commitMessage, octokit, err_1, commit, branch, pr;
return params_generator(this, function (_e) {
switch (_e.label) {
case 0:
payload = context.payload, repo = context.repo;
pullRequest = payload.pull_request;
if (!includeCommitMessage) return [3
/*break*/
, 3];
, 5];
logger.debug("Fetching commit message for '".concat(repo.owner, "/").concat(repo.repo, "#").concat((_a = pullRequest === null || pullRequest === void 0 ? void 0 : pullRequest.head) === null || _a === void 0 ? void 0 : _a.sha, "'"));
if (!!token) return [3
/*break*/
, 1];
logger.error('"token" input is required when "includeCommitMessage" is true');
return [3
/*break*/
, 3];
, 5];

case 1:
octokit = github.getOctokit(token);
_e.label = 2;

case 2:
_e.trys.push([2, 4,, 5]);

return [4
/*yield*/
, getGitHubCommitMessage({
octokit: octokit,
owner: repo.owner,
repo: repo.repo,
ref: (_a = pullRequest === null || pullRequest === void 0 ? void 0 : pullRequest.head) === null || _a === void 0 ? void 0 : _a.sha
ref: (_b = pullRequest === null || pullRequest === void 0 ? void 0 : pullRequest.head) === null || _b === void 0 ? void 0 : _b.sha
})];

case 2:
commitMessage = _d.sent();
_d.label = 3;

case 3:
commit = (_b = pullRequest === null || pullRequest === void 0 ? void 0 : pullRequest.head) === null || _b === void 0 ? void 0 : _b.sha;
branch = (_c = pullRequest === null || pullRequest === void 0 ? void 0 : pullRequest.head) === null || _c === void 0 ? void 0 : _c.ref;
commitMessage = _e.sent();
return [3
/*break*/
, 5];

case 4:
err_1 = _e.sent();
logger.error("Error fetching commit data: ".concat(err_1.message));
return [3
/*break*/
, 5];

case 5:
commit = (_c = pullRequest === null || pullRequest === void 0 ? void 0 : pullRequest.head) === null || _c === void 0 ? void 0 : _c.sha;
branch = (_d = pullRequest === null || pullRequest === void 0 ? void 0 : pullRequest.head) === null || _d === void 0 ? void 0 : _d.ref;
pr = pullRequest === null || pullRequest === void 0 ? void 0 : pullRequest.number;
return [2
/*return*/
Expand Down
19 changes: 12 additions & 7 deletions src/params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,22 @@ export async function extractPullRequestParams(
let commitMessage;

if (includeCommitMessage) {
logger.debug(`Fetching commit message for '${repo.owner}/${repo.repo}#${pullRequest?.head?.sha}'`);

if (!token) {
logger.error('"token" input is required when "includeCommitMessage" is true');
} else {
const octokit = github.getOctokit(token);

commitMessage = await getGitHubCommitMessage({
octokit,
owner: repo.owner,
repo: repo.repo,
ref: pullRequest?.head?.sha,
});
try {
commitMessage = await getGitHubCommitMessage({
octokit,
owner: repo.owner,
repo: repo.repo,
ref: pullRequest?.head?.sha,
});
} catch (err) {
logger.error(`Error fetching commit data: ${err.message}`);
}
}
}

Expand Down