mirror of
https://github.com/dessant/label-actions.git
synced 2026-03-13 01:27:03 -04:00
17
README.md
17
README.md
@@ -77,16 +77,15 @@ pull requests or discussions by grouping them under the
|
||||
- Remove labels, value must be either a label or a list of labels
|
||||
- Optional, defaults to `''`
|
||||
- **`close`**
|
||||
- Close threads, value must be either `true` or `false`,
|
||||
ignored for discussions
|
||||
- Close threads, value must be either `true` or `false`
|
||||
- Optional, defaults to `false`
|
||||
- **`close-reason`**
|
||||
- Reason for closing threads, value must be
|
||||
either `completed` or `not planned`, ignored for discussions
|
||||
- Optional, defaults to `completed`
|
||||
- Reason for closing threads, value must be:
|
||||
- `completed` or `not planned` for issues
|
||||
- `duplicate`, `outdated` or `resolved` for discussions
|
||||
- Optional, defaults to `''`
|
||||
- **`reopen`**
|
||||
- Reopen threads, value must be either `true` or `false`,
|
||||
ignored for discussions
|
||||
- Reopen threads, value must be either `true` or `false`
|
||||
- Optional, defaults to `false`
|
||||
- **`lock`**
|
||||
- Lock threads, value must be either `true` or `false`
|
||||
@@ -263,6 +262,10 @@ wip:
|
||||
# The `solved` label is added to discussions
|
||||
solved:
|
||||
discussions:
|
||||
# Close the discussion
|
||||
close: true
|
||||
# Set a close reason
|
||||
close-reason: 'resolved'
|
||||
# Lock the discussion
|
||||
lock: true
|
||||
|
||||
|
||||
22
src/data.js
22
src/data.js
@@ -78,6 +78,26 @@ mutation ($labelableId: ID!, $labelIds: [ID!]!) {
|
||||
}
|
||||
`;
|
||||
|
||||
const closeDiscussionQuery = `
|
||||
mutation ($discussionId: ID!, $reason: DiscussionCloseReason) {
|
||||
closeDiscussion(input: {discussionId: $discussionId, reason: $reason}) {
|
||||
discussion {
|
||||
closed
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
const reopenDiscussionQuery = `
|
||||
mutation ($discussionId: ID!) {
|
||||
reopenDiscussion(input: {discussionId: $discussionId}) {
|
||||
discussion {
|
||||
closed
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
const lockLockableQuery = `
|
||||
mutation ($lockableId: ID!) {
|
||||
lockLockable(input: {lockableId: $lockableId}) {
|
||||
@@ -105,6 +125,8 @@ module.exports = {
|
||||
getDiscussionLabelsQuery,
|
||||
addLabelsToLabelableQuery,
|
||||
removeLabelsFromLabelableQuery,
|
||||
closeDiscussionQuery,
|
||||
reopenDiscussionQuery,
|
||||
lockLockableQuery,
|
||||
unlockLockableQuery
|
||||
};
|
||||
|
||||
43
src/index.js
43
src/index.js
@@ -10,6 +10,8 @@ const {
|
||||
getDiscussionLabelsQuery,
|
||||
addLabelsToLabelableQuery,
|
||||
removeLabelsFromLabelableQuery,
|
||||
closeDiscussionQuery,
|
||||
reopenDiscussionQuery,
|
||||
lockLockableQuery,
|
||||
unlockLockableQuery
|
||||
} = require('./data');
|
||||
@@ -205,25 +207,38 @@ class App {
|
||||
}
|
||||
}
|
||||
|
||||
if (threadType !== 'discussion') {
|
||||
if (
|
||||
actions.reopen &&
|
||||
threadData.state === 'closed' &&
|
||||
!threadData.merged
|
||||
) {
|
||||
core.debug('Reopening');
|
||||
if (actions.reopen && threadData.state === 'closed' && !threadData.merged) {
|
||||
core.debug('Reopening');
|
||||
|
||||
if (threadType === 'discussion') {
|
||||
await this.client.graphql(reopenDiscussionQuery, {
|
||||
discussionId: discussion.node_id
|
||||
});
|
||||
} else {
|
||||
await this.client.rest.issues.update({...issue, state: 'open'});
|
||||
}
|
||||
}
|
||||
|
||||
if (actions.close && threadData.state === 'open') {
|
||||
core.debug('Closing');
|
||||
if (actions.close && threadData.state === 'open') {
|
||||
core.debug('Closing');
|
||||
|
||||
await this.client.rest.issues.update({
|
||||
...issue,
|
||||
state: 'closed',
|
||||
state_reason: actions['close-reason']
|
||||
});
|
||||
const closeReason = actions['close-reason'];
|
||||
|
||||
if (threadType === 'discussion') {
|
||||
const params = {discussionId: discussion.node_id};
|
||||
if (closeReason) {
|
||||
params.reason = closeReason;
|
||||
}
|
||||
|
||||
await this.client.graphql(closeDiscussionQuery, params);
|
||||
} else {
|
||||
const params = {...issue, state: 'closed'};
|
||||
|
||||
if (closeReason) {
|
||||
params.state_reason = closeReason;
|
||||
}
|
||||
|
||||
await this.client.rest.issues.update(params);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,8 @@ const extendedJoi = Joi.extend(joi => {
|
||||
value = value.trim();
|
||||
if (value === 'not planned') {
|
||||
value = 'not_planned';
|
||||
} else if (['duplicate', 'outdated', 'resolved'].includes(value)) {
|
||||
value = value.toUpperCase();
|
||||
}
|
||||
|
||||
return {value};
|
||||
@@ -66,7 +68,19 @@ const configSchema = Joi.object({
|
||||
const actions = {
|
||||
close: Joi.boolean(),
|
||||
|
||||
'close-reason': extendedJoi.closeReason().valid('completed', 'not_planned'),
|
||||
'close-reason': Joi.alternatives().try(
|
||||
Joi.boolean().only(false),
|
||||
extendedJoi
|
||||
.closeReason()
|
||||
.valid(
|
||||
'completed',
|
||||
'not_planned',
|
||||
'DUPLICATE',
|
||||
'OUTDATED',
|
||||
'RESOLVED',
|
||||
''
|
||||
)
|
||||
),
|
||||
|
||||
reopen: Joi.boolean(),
|
||||
|
||||
@@ -113,7 +127,7 @@ const actionSchema = Joi.object()
|
||||
Joi.string().trim().max(51),
|
||||
Joi.object().keys({
|
||||
close: actions.close.default(false),
|
||||
'close-reason': actions['close-reason'].default('completed'),
|
||||
'close-reason': actions['close-reason'].default(''),
|
||||
reopen: actions.reopen.default(false),
|
||||
lock: actions.lock.default(false),
|
||||
unlock: actions.unlock.default(false),
|
||||
|
||||
Reference in New Issue
Block a user