Skip to content

Commit

Permalink
Always fetch PR data (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalgn authored Jul 26, 2020
1 parent c14757b commit fc82815
Showing 1 changed file with 31 additions and 15 deletions.
46 changes: 31 additions & 15 deletions lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,14 @@ async function handlePullRequestUpdate(context, eventName, event) {
return;
}

await update(context, event.pull_request);
await merge(context, event.pull_request);
const pullRequest = await fetchPullRequest(
context,
event.pull_request.base.repo,
event.pull_request
);

await update(context, pullRequest);
await merge(context, pullRequest);
}

async function handleCheckUpdate(context, eventName, event) {
Expand Down Expand Up @@ -126,8 +132,13 @@ async function handlePullRequestReviewUpdate(context, eventName, event) {
const { action, review } = event;
if (action === "submitted") {
if (review.state === "approved") {
await update(context, event.pull_request);
await merge(context, event.pull_request);
const pullRequest = await fetchPullRequest(
context,
event.pull_request.base.repo,
event.pull_request
);
await update(context, pullRequest);
await merge(context, pullRequest);
} else {
logger.info("Review state is not approved:", review.state);
logger.info("Action ignored:", eventName, action);
Expand Down Expand Up @@ -280,17 +291,7 @@ async function handleIssueComment(context, eventName, event) {
if (issue.pull_request == null) {
logger.info("Comment not on a PR, skipping");
} else {
const { octokit } = context;

logger.debug("Getting pull request info for", issue.number, "...");
let { data: pullRequest } = await octokit.pulls.get({
owner: repository.owner.login,
repo: repository.name,
pull_number: issue.number
});

logger.trace("Full PR:", pullRequest);

const pullRequest = await fetchPullRequest(context, repository, issue);
await update(context, pullRequest);
await merge(context, pullRequest);
}
Expand All @@ -299,4 +300,19 @@ async function handleIssueComment(context, eventName, event) {
}
}

async function fetchPullRequest(context, repository, issue) {
const { octokit } = context;
const { number } = issue;

logger.debug("Getting pull request info for", number, "...");
let { data: pullRequest } = await octokit.pulls.get({
owner: repository.owner.login,
repo: repository.name,
pull_number: number
});

logger.trace("Full PR:", pullRequest);
return pullRequest;
}

module.exports = { executeLocally, executeGitHubAction };

0 comments on commit fc82815

Please sign in to comment.