Skip to content

Commit

Permalink
feat(user-created-pr): add payment status if required
Browse files Browse the repository at this point in the history
  • Loading branch information
Realtin authored and christophwitzko committed Jul 7, 2017
1 parent 8e01e6d commit 3963a07
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion jobs/github-event/pull_request/opened.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
const dbs = require('../../../lib/dbs')
const getConfig = require('../../../lib/get-config')
const { hasBilling } = require('../../../lib/payments')
const githubQueue = require('../../../lib/github-queue')

module.exports = async function (data) {
const { repositories } = await dbs()
const { pull_request: pullRequest, repository } = data
const { pull_request: pullRequest, repository, installation } = data
const repositoryId = String(repository.id)
const prDocId = `${repositoryId}:pr:${pullRequest.id}`
const repoDoc = await repositories.get(repositoryId)
const [owner, repo] = repository.full_name.split('/')
const config = getConfig(repoDoc)

const wasCreatedByGreenkeeper = pullRequest.user.type === 'Bot' && pullRequest.user.login.substr(0, 11) === 'greenkeeper'
Expand All @@ -30,4 +33,18 @@ module.exports = async function (data) {
createdByUser: true
}
)
const ghqueue = githubQueue(installation.id)

const accountHasBilling = await hasBilling(repository.owner.id)
if (repoDoc.private && !accountHasBilling) {
await ghqueue.write(github => github.repos.createStatus({
owner,
repo,
sha: pullRequest.head.sha,
state: 'pending',
context: 'greenkeeper/payment',
description: 'Payment required, merging will have no effect',
target_url: 'https://account.greenkeeper.io/'
}))
}
}

0 comments on commit 3963a07

Please sign in to comment.