Skip to content

Instantly share code, notes, and snippets.

@foosel
Last active January 27, 2021 04:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save foosel/5b72e343874d68fc821c8e4aa4ffa883 to your computer and use it in GitHub Desktop.
Save foosel/5b72e343874d68fc821c8e4aa4ffa883 to your computer and use it in GitHub Desktop.
NodeRed flow for GitHub Review Reminders

NodeRed flow for GitHub Review Reminders

Quick node setup to get notifications about requested reviews each workday morning.

Screenshot of the node setup

Flow json:

[{"id":"3ba912e4.896146","type":"http request","z":"8357254d.c82348","name":"Query","method":"GET","ret":"obj","paytoqs":"query","url":"","tls":"","persist":false,"proxy":"","authType":"","x":530,"y":880,"wires":[["fa377f9a.5a51a","872d9224.2341b8"]]},{"id":"fa377f9a.5a51a","type":"debug","z":"8357254d.c82348","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":750,"y":960,"wires":[]},{"id":"ea784988.39d24","type":"inject","z":"8357254d.c82348","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":140,"y":940,"wires":[["fef091db.f8a6c"]]},{"id":"fef091db.f8a6c","type":"function","z":"8357254d.c82348","name":"Prepare request","func":"let username = \"foosel\";\nlet query = `review-requested:${username} is:pr is:open`;\n\nreturn {\n    headers: {\n        \"Accept\": \"application/vnd.github.v3+json\",\n        \"User-Agent\": username,\n    },\n    url: \"http://api.github.com/search/issues\",\n    payload: {\n        q: query,\n    },\n    github_username: username,\n    github_query: query,\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":360,"y":880,"wires":[["3ba912e4.896146"]]},{"id":"52b97957.078a38","type":"http request","z":"8357254d.c82348","name":"Discord","method":"POST","ret":"txt","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","x":1220,"y":880,"wires":[[]]},{"id":"f923a83a.95c05","type":"function","z":"8357254d.c82348","name":"prepare discord","func":"let count = msg.payload.total_count;\nlet query = encodeURIComponent(msg.github_query);\nlet payload = {\n    content: `@here There are currently ${count} open review requests on GitHub`,\n    embeds: [{\n        title: \"Search PRs with requested reviews\",\n        url: `https://github.com/search?q=${query}`\n    }]\n};\nlet webhook = \"https://discord.com/api/webhooks/REDACTED\";\n\nreturn {\n    url: webhook,\n    payload: payload\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1000,"y":880,"wires":[["fc94956f.419cb","52b97957.078a38"]]},{"id":"fc94956f.419cb","type":"debug","z":"8357254d.c82348","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1210,"y":960,"wires":[]},{"id":"872d9224.2341b8","type":"switch","z":"8357254d.c82348","name":"Any found?","property":"payload.total_count","propertyType":"msg","rules":[{"t":"gt","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":770,"y":880,"wires":[["f923a83a.95c05"]]},{"id":"74c1a72d.e7f9a","type":"cronplus","z":"8357254d.c82348","name":"Every morning","outputField":"payload","timeZone":"","persistDynamic":false,"commandResponseMsgOutput":"output1","outputs":1,"options":[{"name":"Every morning","topic":"every morning","payloadType":"default","payload":"","expressionType":"cron","expression":"30 9 * * 1-5","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"}],"x":160,"y":880,"wires":[["fef091db.f8a6c"]]},{"id":"466ec4c8.adee24","type":"comment","z":"8357254d.c82348","name":"Review request reminder to Discord","info":"","x":200,"y":820,"wires":[]}]

Utilizes the cronplus node, so that needs to be installed first.

Usage

  1. Install cronplus
  2. Import the flow definition
  3. Edit "Prepare request" and adjust username to be your GitHub username.
  4. Edit "prepare discord" and adjust webhook to be your own Discord webhook URL (how to get one).
  5. Edit the cronplus node to your liking.
  6. Deploy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment