From 133b4c2c2b00fdb27053eee78447876e0d67a65d Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Wed, 7 Oct 2020 23:04:15 +0530 Subject: [PATCH] Adds auto instructions reply bot for merged pull requests --- .github/workflows/bot.yml | 24 +++++++++++++++++++++++ scripts/action-utils.js | 8 ++++++++ scripts/reply.js | 40 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 .github/workflows/bot.yml create mode 100644 scripts/action-utils.js create mode 100644 scripts/reply.js diff --git a/.github/workflows/bot.yml b/.github/workflows/bot.yml new file mode 100644 index 000000000..a6f58b71d --- /dev/null +++ b/.github/workflows/bot.yml @@ -0,0 +1,24 @@ +name: Helper + +on: + pull_request_target: + types: + - closed + +jobs: + instructions: + name: instructions + runs-on: ubuntu-latest + if: + steps: + - uses: actions/checkout@v2 + - name: Comment + if: github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true + uses: actions/github-script@v3 + with: + github-token: ${{secrets.GITHUB_TOKEN}} + script: | + const { hasLabel } = require(`${process.env.GITHUB_WORKSPACE}/scripts/action-utils.js`); + const { instructions } = require(`${process.env.GITHUB_WORKSPACE}/scripts/reply.js`); + if (hasLabel(context, 'domain')) + await instructions(context, github); diff --git a/scripts/action-utils.js b/scripts/action-utils.js new file mode 100644 index 000000000..f4fde5761 --- /dev/null +++ b/scripts/action-utils.js @@ -0,0 +1,8 @@ +module.exports = { + hasLabel: (context, label) => { + const pr = context.payload.pull_request || context.payload.issue; + const { labels = [] } = pr; + + return !!labels.find(({ name }) => name === label); + }, +}; diff --git a/scripts/reply.js b/scripts/reply.js new file mode 100644 index 000000000..0f0054fbf --- /dev/null +++ b/scripts/reply.js @@ -0,0 +1,40 @@ + +const getInstructions = () => ` +The changes you have made will soon be reflected!! + +## Here\'s what you need to do next + +If your domain points to a server you own, add \`domain-name.is-a.dev\` to your server config. + +### For github pages users, +* Go to your github page repo (\`user/user.github.io\`) +* Open up the **settings** tab +* Scroll down to the **Github pages** section +* In the **Custom domain** text input, enter the domain you registered (\`domain-name.is-a.dev\`) +* Give it some time to reflect and you should be good to go + + +## Need support with your domain? +If you are having trouble setting up your domain, [create an issue](https://github.com/is-a-dev/register/issues/new/choose) and pick the \`support\` template. Describe any issue you are facing there. I\'ll try my best to get back to you asap! + + +## Love/Hate the service? +**Love it?** Leave it a **star**! Also consider **[donating](https://github.com/is-a-dev/register#donations)** so that I can keep this service running forever. + +**Hate it?** Please leave your feedback by [creating an issue](https://github.com/is-a-dev/register/issues/new/choose). I\'d really like to keep improving this service for developers. +`; + +module.exports = { + async instructions(context, github) { + const pr = context.payload.issue || context.payload.pull_request; + const { number } = pr; + + await github.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: number, + body: getInstructions(), + }); + } +}; +