Step 5 (Optional): Add an n8n automation to Slack
We are going to create a simple workflow that will send a daily reminder of how many PRs are currently open without a review.
- Go to n8n on port 5678
- Anywhere on a workflow page, paste the JSON below, it will create the workflow:
{
"nodes": [
{
"parameters": {
"endpoint": "http://hasura:8080/v1/graphql",
"allowUnauthorizedCerts": true,
"requestFormat": "json",
"query": "=query OpenPRWithoutReviews {\n vcs_PullRequest(where: {stateCategory: {_eq: \"Open\"}, _not: {vcs_PullRequestReviews: {}}}) {\n state\n stateCategory\n uid\n vcs_Repository {\n name\n }\n }\n}",
"headerParametersUi": {
"parameter": [
{
"name": "x-hasura-admin-secret",
"value": "admin"
}
]
}
},
"name": "GraphQL",
"type": "n8n-nodes-base.graphql",
"typeVersion": 1,
"position": [
540,
260
]
},
{
"parameters": {
"channel": "random",
"text": "=There are {{$json[\"numberOfPRs\"]}} PRs waiting for your attention.",
"jsonParameters": true,
"attachments": [],
"otherOptions": {}
},
"name": "Slack",
"type": "n8n-nodes-base.slack",
"typeVersion": 1,
"position": [
980,
260
],
"credentials": {
"slackApi": {
"id": "1",
"name": "Slack account"
}
}
},
{
"parameters": {
"functionCode": "// Code here will run only once, no matter how many input items there are.\n// More info and help: https://docs.n8n.io/nodes/n8n-nodes-base.function\n// Loop over inputs and add a new field called 'myNewField' to the JSON of each one\nfor (item of items) {\n item.json.numberOfPRs = item.json.data.vcs_PullRequest.length\n}\n// You can write logs to the browser console\nconsole.log('Done!');\n\nreturn items;"
},
"name": "Summarize",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
760,
260
]
},
{
"parameters": {
"triggerTimes": {
"item": [
{}
]
}
},
"name": "Cron",
"type": "n8n-nodes-base.cron",
"typeVersion": 1,
"position": [
320,
260
]
}
],
"connections": {
"GraphQL": {
"main": [
[
{
"node": "Summarize",
"type": "main",
"index": 0
}
]
]
},
"Summarize": {
"main": [
[
{
"node": "Slack",
"type": "main",
"index": 0
}
]
]
},
"Cron": {
"main": [
[
{
"node": "GraphQL",
"type": "main",
"index": 0
}
]
]
}
}
}
This example assumes you haven't changed the Hasura password.
Otherwise, please update the corresponding header in the GraphQL node.
What does each node do in our example?
The Cron node simply triggers the workflow at a regular interval.
The GraphQL node queries Hasura for PRs without reviews.
The Function node (named Summarize) extracts how many PRs are waiting a review.
The Slack node sends that information via Slack.
- Double click on the Slack node and add your slack credentials
What scopes for the Slack token should you use?
We suggest using a user (not a bot) access token with the following scopes:
channels:read
chat:write
users.profile:read
- (Optional) Double click on the Cron node and select the desired frequency and time
- (Optional) Test the workflow by clicking
Execute Workflow
- Click Save, and switch the workflow to Active
Get Oriented in n8n
n8n is a great open-source workflow engine. You can find its documentation here.
See also ๐ค Workflows in n8n for how it can be used in Faros CE.
Updated over 2 years ago