From a3cf05202ca505e6a3b0c5154b10367275eadd55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Fri, 22 Jan 2021 17:33:13 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=B7=20Add=20bundle=20linkifier?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Will come in handy once OctoPrint 1.6.0 comes out. --- .github/workflows/linkify_bundles.yml | 47 +++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 .github/workflows/linkify_bundles.yml diff --git a/.github/workflows/linkify_bundles.yml b/.github/workflows/linkify_bundles.yml new file mode 100644 index 000000000..3c36edfb2 --- /dev/null +++ b/.github/workflows/linkify_bundles.yml @@ -0,0 +1,47 @@ +name: "Linkify systeminfo bundles" +on: + issue_comment: + types: [created, edited] + +jobs: + linkifyBundles: + runs-on: ubuntu-latest + steps: + - uses: actions/github-script@v2 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + let comment = context.payload.comment.body; + + const botMarker = ""; + const botWasHere = comment.indexOf(botMarker); + if (botWasHere !== -1) { + comment = comment.substring(0, botWasHere); + }; + + const bundleRegex = /\[(octoprint-systeminfo-\d{14}\.zip)\]\(([^)]+)\)/g; + + const bundles = []; + const seen = []; + const matches = comment.matchAll(bundleRegex); + for (const match of matches) { + if (!seen.includes(match[1])) { + bundles.push({filename: match[1], link: match[2], match: match[0]}); + seen.push(match[1]); + } + }; + + if (bundles) { + let text = comment + botMarker + "\n\n---\n\n\nBundles:\n\n"; + bundles.forEach((bundle) => { + text += " * [" + bundle.filename + "](https://bundleviewer.octoprint.org/?url=" + encodeURIComponent(bundle.link) + ")\n" + }); + text += "\n*edited by @github-actions to add bundle viewer links*\n"; + + github.issues.updateComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: context.payload.comment.id, + body: text + }); + }