From e0bec8b9ae97a72998b8d1b05c113860ba74ac26 Mon Sep 17 00:00:00 2001 From: Joscha <34318751+josxha@users.noreply.github.com> Date: Wed, 21 Feb 2024 09:25:53 +0100 Subject: [PATCH] chore: retain `waiting for user response` label if comment posted by user that added label (#1835) * Update issue-comment.yml * Update issue-comment.yml * Update issue-comment.yml * Update issue-comment.yml * Update issue-comment.yml * Update issue-comment.yml * Update issue-comment.yml * Update issue-comment.yml * Update issue-comment.yml * Update issue-comment.yml * Update issue-comment.yml * Update issue-comment.yml * Update issue-comment.yml --- .github/workflows/issue-comment.yml | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/.github/workflows/issue-comment.yml b/.github/workflows/issue-comment.yml index 8a62b924e..8a205df02 100644 --- a/.github/workflows/issue-comment.yml +++ b/.github/workflows/issue-comment.yml @@ -17,13 +17,27 @@ jobs: github-token: ${{ secrets.GITHUB_TOKEN }} script: | const { data: issue } = await github.rest.issues.get({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: context.issue.number + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number }); + const isStale = issue.labels.some(label => label.name === 'stale'); - const waitingResponse = issue.labels.some(label => label.name === 'waiting for user response'); - return !isStale && waitingResponse; + console.log("isStale: " + isStale); + if (isStale) return false; + + const { data: events } = await github.rest.issues.listEvents({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number + }); + const labelAddedEvent = events.findLast(event => event.event === 'labeled' && event.label.name === 'waiting for user response'); + if (!labelAddedEvent) return false; + const labelAddedDate = new Date(labelAddedEvent.created_at); + const now = new Date(); + const secondsSinceLabelAdded = (now - labelAddedDate) / 1000; + console.log(secondsSinceLabelAdded + "s") + return secondsSinceLabelAdded > 30; # only remove the label if the issue is not stale, this prevents that this # action removes the label when the automatic reminder message gets sent. - name: Remove `waiting for user response` label if exists @@ -37,4 +51,4 @@ jobs: repo: context.repo.repo, issue_number: context.issue.number, name: ["waiting for user response"] - }); \ No newline at end of file + });