diff --git a/jobs/send-stale-initial-pr-reminder.js b/jobs/send-stale-initial-pr-reminder.js index c611057e..db36ff15 100644 --- a/jobs/send-stale-initial-pr-reminder.js +++ b/jobs/send-stale-initial-pr-reminder.js @@ -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') @@ -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('/') @@ -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, @@ -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') }