From 39bcee3931bb2d8bc1ef4b8adf333fa621499dfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Thu, 4 Apr 2024 12:13:35 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=B7=20Add=20bundle=20check=20workflow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/issue_automation.yml | 101 +++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 .github/workflows/issue_automation.yml diff --git a/.github/workflows/issue_automation.yml b/.github/workflows/issue_automation.yml new file mode 100644 index 0000000..6fdb006 --- /dev/null +++ b/.github/workflows/issue_automation.yml @@ -0,0 +1,101 @@ +name: "Issue Automation" +on: + issues: + types: [opened, edited, closed, reopened, labeled, unlabeled] + +jobs: + issue-automation: + runs-on: ubuntu-latest + steps: + - uses: actions/github-script@v7 + env: + REMINDER: > + Hi @${{ github.event.issue.user.login }}! + + + It looks like you didn't upload a [system info bundle](https://community.octoprint.org/t/29887) as requested by the template. + A bundle is required to further process your issue. It contains important logs and + system information to be able to put your issue into context and give pointers as to + what has happened. + + + Please **edit your original post above** and upload **a bundle zip file**. Actually upload the file please and + do not paste some link to a cloud provider, we want to have everything in one place here. Also do + not unpack, repack or otherwise modify the bundle or its name, share it **exactly** like you get it from OctoPrint. + + + Without the availability of a bundle, your issue will have to be closed. + + + Thank you for your collaboration. + THANKYOU: > + Thank you @${{ github.event.issue.user.login }} for adding a bundle! Now this can actually get looked at. + with: + script: | + const { REMINDER, THANKYOU } = process.env; + const bundleRegex = /\[(octoprint-systeminfo-\d{14}\.zip)\]\(([^)]+)\)/g; + const marker = ""; + + const issueLabels = await github.rest.issues.listLabelsOnIssue({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number + }); + let labels = issueLabels.data.map(label => label.name); + + const comments = await github.rest.issues.listComments({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + }) + const comment = comments.data.find(c => c.user.login === "github-actions[bot]" && c.body.includes(marker)); + if (comment) { + console.log("Found comment, id=" + comment.id); + } else { + console.log("No comment found"); + } + + if (!labels.includes("triage") || !labels.includes("bug") || labels.includes("approved")) { + console.log("Deleting comment if it exists..."); + if (comment) { + await github.rest.issues.deleteComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: comment.id, + }) + } + return; + } + + const found = !!context.payload.issue.body.match(bundleRegex); + + if (!found) { + console.log("No bundle found, posting/updating reminder"); + const text = REMINDER + "\n" + marker; + if (!comment) { + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + body: text + }); + } else if (comment.body !== text) { + await github.rest.issues.updateComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: comment.id, + body: text + }); + } + } else if (found && comment) { + console.log("Bundle found, saying thanks"); + const text = REMINDER.split("\n\n").map(line => `~~${line.trim()}~~`).join("\n\n") + "\n\n" + THANKYOU + "\n" + marker; + if (comment.body !== text) { + await github.rest.issues.updateComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: comment.id, + body: text + }); + } + }