Skip to content
This repository has been archived by the owner on Nov 4, 2022. It is now read-only.

Commit

Permalink
feat(issue): add issue locking capability
Browse files Browse the repository at this point in the history
Allows for locking an issue and or adding a lock reason.

re #480
  • Loading branch information
Ryan Garant committed Nov 13, 2019
1 parent 7c48841 commit b9b8994
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/cmds/issue/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { assign } from './assign'
import { closeHandler } from './close'
import { openHandler } from './open'
import { search } from './search'
import { lockHandler } from './lock'

// -- Constants ------------------------------------------------------------------------------------
export const testing = process.env.NODE_ENV === 'testing'
Expand All @@ -40,6 +41,8 @@ export const DETAILS = {
labels: [String],
list: Boolean,
link: Boolean,
lock: Boolean,
'lock-reason': ['off-topic', 'too heated', 'resolved', 'spam'],
message: String,
milestone: [Number, String],
'no-milestone': Boolean,
Expand Down Expand Up @@ -97,7 +100,7 @@ export async function run(options, done) {
const payload = draft.argv.remain && draft.argv.remain.slice(1)

if (payload && payload[0]) {
if (/^\d+$/.test(payload[0])) {
if (options.argv.original.length === 2) {
draft.browser = true
draft.number = payload[0]
} else {
Expand Down Expand Up @@ -161,6 +164,14 @@ export async function run(options, done) {
} catch (err) {
throw new Error(`Error listing issues\n${err}`)
}
} else if (options.lock) {
logger.log(`Locking issue ${options.number} on ${options.userRepo}`)

try {
await lockHandler(options)
} catch (err) {
throw new Error(`Error locking issue\n${err}`)
}
} else if (options.new) {
await beforeHooks('issue.new', { options })

Expand Down
42 changes: 42 additions & 0 deletions src/cmds/issue/lock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* © 2013 Liferay, Inc. <https://liferay.com> and Node GH contributors
* (see file: README.md)
* SPDX-License-Identifier: BSD-3-Clause
*/

import { getIssue } from '.'
import * as logger from '../../logger'

export async function lockHandler(options) {
const {
data: { locked },
} = await getIssue(options)

if (!locked) {
var { status } = await lock(options)

logger.log(
status === 204
? logger.colors.green('Success locking issue.')
: logger.colors.green('Failed to lock issue.')
)
} else {
logger.log('Issue is already locked.')
}
}

function lock(options) {
const { number, user, repo, 'lock-reason': lockReason, GitHub } = options

const payload = {
repo,
owner: user,
issue_number: number,
...(lockReason ? { lock_reason: lockReason } : {}),
mediaType: {
previews: ['sailor-v-preview'],
},
}

return GitHub.issues.lock(payload)
}

0 comments on commit b9b8994

Please sign in to comment.