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

Commit b9b8994

Browse files
author
Ryan Garant
committed
feat(issue): add issue locking capability
Allows for locking an issue and or adding a lock reason. re #480
1 parent 7c48841 commit b9b8994

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

src/cmds/issue/index.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { assign } from './assign'
1919
import { closeHandler } from './close'
2020
import { openHandler } from './open'
2121
import { search } from './search'
22+
import { lockHandler } from './lock'
2223

2324
// -- Constants ------------------------------------------------------------------------------------
2425
export const testing = process.env.NODE_ENV === 'testing'
@@ -40,6 +41,8 @@ export const DETAILS = {
4041
labels: [String],
4142
list: Boolean,
4243
link: Boolean,
44+
lock: Boolean,
45+
'lock-reason': ['off-topic', 'too heated', 'resolved', 'spam'],
4346
message: String,
4447
milestone: [Number, String],
4548
'no-milestone': Boolean,
@@ -97,7 +100,7 @@ export async function run(options, done) {
97100
const payload = draft.argv.remain && draft.argv.remain.slice(1)
98101

99102
if (payload && payload[0]) {
100-
if (/^\d+$/.test(payload[0])) {
103+
if (options.argv.original.length === 2) {
101104
draft.browser = true
102105
draft.number = payload[0]
103106
} else {
@@ -161,6 +164,14 @@ export async function run(options, done) {
161164
} catch (err) {
162165
throw new Error(`Error listing issues\n${err}`)
163166
}
167+
} else if (options.lock) {
168+
logger.log(`Locking issue ${options.number} on ${options.userRepo}`)
169+
170+
try {
171+
await lockHandler(options)
172+
} catch (err) {
173+
throw new Error(`Error locking issue\n${err}`)
174+
}
164175
} else if (options.new) {
165176
await beforeHooks('issue.new', { options })
166177

src/cmds/issue/lock.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* © 2013 Liferay, Inc. <https://liferay.com> and Node GH contributors
3+
* (see file: README.md)
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
7+
import { getIssue } from '.'
8+
import * as logger from '../../logger'
9+
10+
export async function lockHandler(options) {
11+
const {
12+
data: { locked },
13+
} = await getIssue(options)
14+
15+
if (!locked) {
16+
var { status } = await lock(options)
17+
18+
logger.log(
19+
status === 204
20+
? logger.colors.green('Success locking issue.')
21+
: logger.colors.green('Failed to lock issue.')
22+
)
23+
} else {
24+
logger.log('Issue is already locked.')
25+
}
26+
}
27+
28+
function lock(options) {
29+
const { number, user, repo, 'lock-reason': lockReason, GitHub } = options
30+
31+
const payload = {
32+
repo,
33+
owner: user,
34+
issue_number: number,
35+
...(lockReason ? { lock_reason: lockReason } : {}),
36+
mediaType: {
37+
previews: ['sailor-v-preview'],
38+
},
39+
}
40+
41+
return GitHub.issues.lock(payload)
42+
}

0 commit comments

Comments
 (0)