Skip to content

Commit

Permalink
fix: restore lock state only when needed
Browse files Browse the repository at this point in the history
Closes #23.
  • Loading branch information
dessant committed Jun 6, 2023
1 parent 24337be commit 8ebc35d
Showing 1 changed file with 24 additions and 20 deletions.
44 changes: 24 additions & 20 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 8ebc35d

Please sign in to comment.