Skip to content

Commit

Permalink
Minor check_suite changes
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalgn committed Mar 15, 2020
1 parent 104d878 commit 135f0bd
Showing 1 changed file with 39 additions and 39 deletions.
78 changes: 39 additions & 39 deletions lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,34 +89,33 @@ async function handlePullRequestUpdate(context, eventName, event) {

async function handleCheckUpdate(context, eventName, event) {
const { action } = event;
const { octokit } = context;
const payload = eventName === 'check_suite' ? event.check_suite : event.check_run;
if (action !== "completed") {
logger.info("A status check is not yet complete:", eventName);
throw new NeutralExitError();
} else {
const payload =
eventName === "check_suite" ? event.check_suite : event.check_run;
if (payload.conclusion === "success") {
logger.info("Check has successfully completed - trying to Merge")
const checkPullRequest = payload.pull_requests[0]
logger.info("Status check completed successfully");
const checkPullRequest = payload.pull_requests[0];
if (checkPullRequest != null) {
const { data: pullRequest } = await octokit.request( checkPullRequest.url)
logger.trace("PullrequestData ",pullRequest)

const { octokit } = context;
const { data: pullRequest } = await octokit.request(
checkPullRequest.url
);
logger.trace("PR:", pullRequest);

await update(context, pullRequest);
await merge(context, pullRequest);
} else {
const branchName = payload.head_branch
if (branchName != null ) {
logger.info("Going into the branch listing")
await checkPullRequestsForBranches(context,event, branchName)
const branchName = payload.head_branch;
if (branchName != null) {
await checkPullRequestsForBranches(context, event, branchName);
} else {
logger.info("Could not find Pull Request Data in this status check result");
throw new NeutralExitError();
logger.info("Could not find branch name in this status check result");
}
}
} else {
logger.info("A status check completed unsuccessfully:", eventName);
throw new NeutralExitError();
}
}
}
Expand Down Expand Up @@ -149,38 +148,39 @@ async function handleStatusUpdate(context, eventName, event) {
}

for (const branch of branches) {
await checkPullRequestsForBranches(context,event,branch.name)
await checkPullRequestsForBranches(context, event, branch.name);
}
}

async function checkPullRequestsForBranches(context,event,branchName) {
async function checkPullRequestsForBranches(context, event, branchName) {
const { octokit } = context;
logger.debug("Listing pull requests for", branchName, "...");
const { data: pullRequests } = await octokit.pulls.list({
owner: event.repository.owner.login,
repo: event.repository.name,
state: "open",
head: `${event.repository.owner.login}:${branchName}`,
sort: "updated",
direction: "desc",
per_page: MAX_PR_COUNT
});
const { data: pullRequests } = await octokit.pulls.list({
owner: event.repository.owner.login,
repo: event.repository.name,
state: "open",
head: `${event.repository.owner.login}:${branchName}`,
sort: "updated",
direction: "desc",
per_page: MAX_PR_COUNT
});

logger.trace("PR list:", pullRequests);
logger.trace("PR list:", pullRequests);

let updated = 0;
for (const pullRequest of pullRequests) {
try {
await update(context, pullRequest);
await merge(context, pullRequest);
++updated;
} catch (e) {
logger.error(e);
}
}
if (updated === 0) {
logger.info("No PRs have been updated/merged");
let updated = 0;
for (const pullRequest of pullRequests) {
try {
await update(context, pullRequest);
await merge(context, pullRequest);
++updated;
} catch (e) {
logger.error(e);
}
}

if (updated === 0) {
logger.info("No PRs have been updated/merged");
}
}

async function handleBranchUpdate(context, eventName, event) {
Expand Down

0 comments on commit 135f0bd

Please sign in to comment.