Skip to content

Commit

Permalink
combine thread and issue labeled process functions
Browse files Browse the repository at this point in the history
  • Loading branch information
mfix22 committed Feb 21, 2022
1 parent 510dbd6 commit 827f7e2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
5 changes: 2 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,14 @@ module.exports = async ({ app, getRouter }) => {
}))
try {
switch (job.data.action) {
case COMMENT:
return await threadLabeled.process(app)(job)
case MERGE:
return await pullLabeled.process(app)(job)
case LOCK:
return await threadClosed.process(app)(job)
case COMMENT:
case CLOSE:
default:
return await issueLabeled.process(app)(job)
return await threadLabeled.process(app)(job)
}
} catch (error) {
if (process.env.NODE_ENV !== 'test') {
Expand Down
11 changes: 0 additions & 11 deletions src/issue/labeled.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const ms = require('ms')

const { getLabelConfig, getEffectiveLabel, labelsByAction } = require('../thread/util')
const { getId } = require('../util')
const { closeIssue } = require('../api')
const getConfig = require('../config')
const { CLOSE } = require('../constants')
const analytics = require('../analytics')
Expand Down Expand Up @@ -65,13 +64,3 @@ module.exports = (queue) => async (context) => {
// If closable labels are removed, delete job for this issue
return queue.removeJob(ID)
}

module.exports.process = (robot) => async ({ data /* id */ }) => {
const github = await robot.auth(data.installation_id)
return await closeIssue(github, {
...data,
number: undefined,
// TODO change this to just use number
issue_number: data.issue_number || data.number,
})
}
29 changes: 22 additions & 7 deletions src/thread/labeled.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ const ms = require('ms')

const { getId, executeAction } = require('../util')
const getConfig = require('../config')
const { COMMENT } = require('../constants')
const { COMMENT, CLOSE } = require('../constants')
const { timeToNumber, getLabelConfig, labelToAction } = require('./util')
const analytics = require('../analytics')
const { closeIssue } = require('../api')

module.exports = (queue) => async (context) => {
const thread = context.payload.pull_request || context.payload.issue
Expand Down Expand Up @@ -73,10 +74,24 @@ module.exports = (queue) => async (context) => {

module.exports.process = (robot) => async ({ data /* id */ }) => {
const github = await robot.auth(data.installation_id)
return await github.issues.createComment({
...data,
number: undefined,
// TODO change this to just use number
issue_number: data.issue_number || data.number,
})

switch (data.action) {
case CLOSE: {
return await closeIssue(github, {
...data,
number: undefined,
// TODO change this to just use number
issue_number: data.issue_number || data.number,
})
}
case COMMENT:
default: {
return await github.issues.createComment({
...data,
number: undefined,
// TODO change this to just use number
issue_number: data.issue_number || data.number,
})
}
}
}

0 comments on commit 827f7e2

Please # to comment.