Skip to content

Commit

Permalink
feat: add logging to send-stale-initial-pr-reminder
Browse files Browse the repository at this point in the history
  • Loading branch information
janl authored and espy committed May 3, 2018
1 parent d6dd7d3 commit ad208da
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions jobs/send-stale-initial-pr-reminder.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const githubQueue = require('../lib/github-queue')
const dbs = require('../lib/dbs')
const Log = require('gk-log')
const upsert = require('../lib/upsert')
const statsd = require('../lib/statsd')
const staleInitialPRReminderComment = require('../content/stale-initial-pr-reminder')
Expand All @@ -11,13 +12,25 @@ module.exports = async function (
repositoryId = String(repositoryId)

const { installations, repositories } = await dbs()
const logs = dbs.getLogsDb()
const installation = await installations.get(accountId)
const repository = await repositories.get(repositoryId)
const installationId = installation.installation
const ghqueue = githubQueue(installationId)

if (repository.enabled) return
if (repository.staleInitialPRReminder) return
const log = Log({logsDb: logs, accountId, repoSlug: repository.fullName, context: 'send-stale-initial-pr-reminder'})

log.info('started')

if (repository.enabled) {
log.info('stopped: repository enabled')
return
}

if (repository.staleInitialPRReminder) {
log.info('stopped: stale PR reminder already sent')
return
}

const [owner, repo] = repository.fullName.split('/')

Expand All @@ -27,7 +40,10 @@ module.exports = async function (
number: prNumber
}))

if (issue.state !== 'open' || issue.locked) return
if (issue.state !== 'open' || issue.locked) {
log.info('stopped: issue closed or locked')
return
}

await ghqueue.write(github => github.issues.createComment({
owner,
Expand All @@ -36,9 +52,14 @@ module.exports = async function (
body: staleInitialPRReminderComment()
}))

await upsert(repositories, repositoryId, {
staleInitialPRReminder: true
})
try {
await upsert(repositories, repositoryId, {
staleInitialPRReminder: true
})
} catch (e) {
log.warn('db: upsert failed', { repositoryId })
throw e
}

statsd.increment('stale-initial-pr-reminder')
}

0 comments on commit ad208da

Please sign in to comment.