From 8ebc35d98bf4a8c61d6066fe76c310200e89a7f6 Mon Sep 17 00:00:00 2001 From: dessant Date: Tue, 6 Jun 2023 20:16:52 +0300 Subject: [PATCH] fix: restore lock state only when needed Closes #23. --- src/index.js | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/src/index.js b/src/index.js index 579710e..9308c11 100644 --- a/src/index.js +++ b/src/index.js @@ -78,13 +78,15 @@ class App { }; } - const lock = { - active: threadData.locked, - reason: threadData.active_lock_reason - }; - if (actions.comment) { core.debug('Commenting'); + + const lock = { + active: threadData.locked, + reason: threadData.active_lock_reason, + restoreLock: !actions.unlock + }; + await this.ensureUnlock({issue, discussion}, lock, async () => { for (let commentBody of actions.comment) { commentBody = commentBody.replace( @@ -303,22 +305,24 @@ class App { actionError = err; } - if (issue) { - if (lock.reason) { - issue = { - ...issue, - lock_reason: lock.reason, - headers: { - Accept: 'application/vnd.github.sailor-v-preview+json' - } - }; - } + if (lock.restoreLock) { + if (issue) { + if (lock.reason) { + issue = { + ...issue, + lock_reason: lock.reason, + headers: { + Accept: 'application/vnd.github.sailor-v-preview+json' + } + }; + } - await this.client.rest.issues.lock(issue); - } else { - await this.client.graphql(lockLockableQuery, { - lockableId: discussion.node_id - }); + await this.client.rest.issues.lock(issue); + } else { + await this.client.graphql(lockLockableQuery, { + lockableId: discussion.node_id + }); + } } if (actionError) {