Skip to content

Commit

Permalink
fix: upgrade github-wrapper and only merge a pr if all checks are a s…
Browse files Browse the repository at this point in the history
…uccess
  • Loading branch information
hfreire committed Feb 25, 2020
1 parent ff2b120 commit aa4ca84
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 106 deletions.
111 changes: 11 additions & 100 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"homepage": "https://github.com/hfreire/github-handyman#readme",
"dependencies": {
"@dog-ai/github-wrapper": "2.0.16",
"@dog-ai/github-wrapper": "2.0.17",
"lodash.words": "4.2.0"
},
"devDependencies": {
Expand Down
17 changes: 12 additions & 5 deletions src/github-handyman.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,21 @@ const findGreenkeeperCommentAboutLatestVersion = (comments) => {
return decodeURIComponent(encodedHead)
}

const isCombinedStatusAndAllChecksSuccessful = (pull) => {
const isCombinedStatusSuccess = pull.combinedStatus.state === 'success'
const areAllChecksSuccessful = _.find(pull.checks.check_runs, ({ conclusion }) => conclusion !== 'success')

return isCombinedStatusSuccess && areAllChecksSuccessful
}

const mergeDependabotPullRequest = async function (user, owner, repo, pull) {
if (!isDependabotPull(pull)) {
return
}

const isSuccess = pull.combinedStatus.state === 'success'
const isMergeable = isCombinedStatusAndAllChecksSuccessful(pull)

if (isSuccess) {
if (isMergeable) {
const reviews = await this._github.listPullRequestReviews(owner, repo, pull.number)
if (!_.find(reviews, { user: { login: user } })) {
await this._github.requestPullRequestReview(owner, repo, pull.number, [ user ])
Expand All @@ -93,16 +100,16 @@ const mergeGreenkeeperPullRequest = async function (user, owner, repo, pull) {
return
}

const isSuccess = pull.combinedStatus.state === 'success'
const isMergeable = isCombinedStatusAndAllChecksSuccessful(pull)

if (isSuccess) {
if (isMergeable) {
await this._github.mergePullRequest(owner, repo, pull.number, pull.head.sha)
this.emit('pulls:merge', owner, repo, pull.number, pull.head.sha, 'squash')

return
}

if (!isSuccess && isGreenkeeperPull(pull)) {
if (!isMergeable && isGreenkeeperPull(pull)) {
const comments = await this._github.getPullRequestComments(owner, repo, pull.number)
const head = findGreenkeeperCommentAboutLatestVersion(comments)

Expand Down

0 comments on commit aa4ca84

Please sign in to comment.