8000 Fix create comment TODO by mfix22 · Pull Request #105 · reporanger/ranger · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix create comment TODO #105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ module.exports = {
env: {
es6: true,
node: true,
jest: true
jest: true,
},
extends: ['eslint:recommended'],
parserOptions: {
ecmaVersion: 10
ecmaVersion: 10,
},
plugins: ['import'],
rules: {
'import/no-unresolved': 'error',
'no-duplicate-imports': 'error'
}
'no-duplicate-imports': 'error',
'no-console': ['error', { allow: ['warn', 'error'] }],
},
}
6 changes: 3 additions & 3 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ exports.closeIssue = function closeIssue(github, data) {
})
.then((_) => _.data)
.catch((e) => {
console.log(e, data)
console.error(e, data)
throw e
})
}
Expand All @@ -32,7 +32,7 @@ exports.getPullRequest = function getPullRequest(github, data) {
})
.then((_) => _.data)
.catch((e) => {
console.log(e, data)
console.error(e, data)
throw e
})
}
Expand Down Expand Up @@ -62,7 +62,7 @@ exports.addLabels = function addLabels(github, { labels, ...data }) {
},
})
.catch((e) => {
console.log(e, data)
console.error(e, data)
throw e
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const ms = require('ms')
const Sentry = require('@sentry/node')
const ms = require('ms')

const { CLOSE, MERGE } = require('./constants')

Expand Down
2 changes: 1 addition & 1 deletion src/installation/added.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const Sentry = require('@sentry/node')
const { createLabel } = require('../api')
const analytics = require('../analytics')

Expand Down Expand Up @@ -85,7 +86,6 @@ module.exports = (robot) => async (context) => {
},
})
} catch (e) {
const Sentry = require('@sentry/node')
Sentry.configureScope((scope) => {
scope.setUser({
id: context.payload.installation.id,
Expand Down
2 changes: 1 addition & 1 deletion src/pull/labeled.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const Sentry = require('@sentry/node')
const ms = require('ms')

const { getId } = require('../util')
Expand Down Expand Up @@ -93,7 +94,6 @@ module.exports.process = (robot) => async ({

pull = await getPullRequest(github, { owner, repo, pull_number: the_number })
} catch (error) {
const Sentry = require('@sentry/node')
Sentry.configureScope((scope) => {
scope.setUser({ username: owner, id: installation_id })
Sentry.captureException(error)
Expand Down
37 changes: 18 additions & 19 deletions src/thread/labeled.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,31 @@ module.exports = (queue) => async (context) => {

if (!action) return false

const { delay, message, comment } = getLabelConfig(config, label.name, action)
const time = timeToNumber(delay, 0)

function getCommentBody(string) {
if (!string || string.trim() === 'false') return ''

return string
.replace('$DELAY', time == null ? '' : ms(time, { long: true }))
.replace('$LABEL', label.name)
.replace('$AUTHOR', thread.user.login)
}

async function handleUpdateThread() {
const ID = getId(context, { action })

const { delay, comment } = getLabelConfig(config, label.name, action)
const time = timeToNumber(delay, -1)

const jobExists = await queue.getJob(ID)
if (!jobExists) {
// TODO refactor this file to use a shared "createComment" function
if (comment && comment.trim() !== 'false') {
const body = comment
.replace('$DELAY', time == null ? '' : ms(time, { long: true }))
.replace('$LABEL', label.name)
.replace('$AUTHOR', thread.user.login)
const body = getCommentBody(comment)
if (body) {
await context.octokit.issues.createComment(context.issue({ body }))
}
}

const time = timeToNumber(delay, -1)

if (time >= 0) {
return queue
.createJob(
Expand Down Expand Up @@ -89,16 +96,8 @@ module.exports = (queue) => async (context) => {

// Don't create a comment if one already exists
if (!jobExists) {
const { message, delay } = getLabelConfig(config, label.name, COMMENT)

const time = timeToNumber(delay, 0)

if (message && message.trim() !== 'false') {
const body = message
.replace('$LABEL', label.name)
.replace('$DELAY', ms(time, { long: true }))
.replace('$AUTHOR', thread.user.login)

const body = getCommentBody(message)
if (body) {
return queue
.createJob(
context.issue({
Expand Down
2 changes: 1 addition & 1 deletion src/verify-payment-plan.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// TODO add DEV flag
const Sentry = require('@sentry/node')
const r = require('rexrex')
const { OPEN_SOURCE } = require('./constants')

Expand Down Expand Up @@ -72,7 +73,6 @@ module.exports = async function verifyPaymentPlan(robot, context) {
} catch (error) {
if (error.status !== 404) {
robot.log.error(error, context.repo())
const Sentry = require('@sentry/node')
Sentry.configureScope((scope) => {
scope.setUser({ username: owner })
Sentry.captureException(error)
Expand Down
316E
0