n8n
Workflow
Get Contributors Information From Github In Slack
This n8n workflow automates tasks using Slack. Get Contributors Information From Github In Slack - ready to import and run in your n8n instance.
n8n
workflow.json
About This Script
This n8n workflow automates tasks using Slack. Get Contributors Information From Github In Slack - ready to import and run in your n8n instance.
Features:
- Receives webhook events
- Custom JavaScript function processing
- Integrates with Slack
- Retrieves data from external sources
Source Code
{
"nodes": [
{
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"position": [
300,
300
],
"webhookId": "dacd64a7-a83e-4492-b8fe-363453906d0d",
"parameters": {
"path": "dacd64a7-a83e-4492-b8fe-363453906d0d",
"options": [],
"httpMethod": "POST"
},
"typeVersion": 1,
"id": "c6af0a4d-779e-444d-84db-8e657d035da0"
},
{
"name": "GraphQL",
"type": "n8n-nodes-base.graphql",
"position": [
500,
300
],
"parameters": {
"query": "=query {\nuser(login:\"{{$node[\"Webhook\"].json[\"body\"][\"text\"]}}\"){\nname\ncompany\nlocation\navatarUrl\nemail\npullRequests(last: 25) {\nedges {\nnode {\ncommits(last:25) {\nnodes {\ncommit {\nauthor {\nemail\nname\n}\n}\n}\n}\n}\n}\n}\n}\n}",
"endpoint": "https://api.github.com/graphql",
"requestFormat": "json",
"responseFormat": "string",
"headerParametersUi": {
"parameter": [
{
"name": "User-Agent",
"value": "n8n"
},
{
"name": "Authorization",
"value": "bearer <Personal Token>"
}
]
}
},
"typeVersion": 1,
"id": "34c09b23-46fc-40ec-8284-c3c1a01dec2c"
},
{
"name": "Function",
"type": "n8n-nodes-base.function",
"position": [
700,
300
],
"parameters": {
"functionCode": "let emails = [];\nlet tempEmails = [];\nconst name = $node[\"GraphQL\"].json[\"data\"][\"data\"][\"user\"][\"name\"];\nconst publicEmail = $node[\"GraphQL\"].json[\"data\"][\"data\"][\"user\"][\"email\"];\nconst username = $node[\"Webhook\"].json[\"body\"][\"text\"];\nconst nameRegex = new RegExp(name,\"g\")\n\nif(publicEmail){\n// if public email address exists, push it to the tempEmails array\n tempEmails.push(publicEmail)\n}\n\n// looping through the pull requests\nfor(const edge of items[0].json.data.data.user.pullRequests.edges){\n // looping through the commits\n for(node of edge.node.commits.nodes){\n\n // Checks the name associated with the email address\n if(nameRegex.test(node.commit.author.name)|| node.commit.author.name == username) {\n // if name equals to contributors name or username, push the email address in tempEmails\n tempEmails.push(node.commit.author.email)\n }\n }\n}\n\n// Remove duplicates\nemails = [...new Set(tempEmails)]\n\n// RegEx Pattern for email address generated by GitHub\nlet re = /^\\w+(.)*@users.noreply.github.com/\n\n// Remove the email addresses Generated by GitHub\nemails = emails.filter(email => !re.test(email))\n\n\nreturn [{json:{emails,}}]\n"
},
"typeVersion": 1,
"id": "e23e46e4-4d4b-4a52-b943-8deb546e975f"
},
{
"name": "Slack",
"type": "n8n-nodes-base.slack",
"position": [
900,
300
],
"parameters": {
"channel": "={{$node[\"Webhook\"].json[\"body\"][\"channel_id\"]}}",
"attachments": [
{
"title": "=GitHub Details for: {{$node[\"Webhook\"].json[\"body\"][\"text\"]}}"
},
{
"text": "=*Name:* {{$node[\"GraphQL\"].json[\"data\"][\"data\"][\"user\"][\"name\"]}}\n*Email:* {{$node[\"Function\"].json[\"emails\"].join(', ')}}\n*Company:* {{$node[\"GraphQL\"].json[\"data\"][\"data\"][\"user\"][\"company\"]}}\n*Location:* {{$node[\"GraphQL\"].json[\"data\"][\"data\"][\"user\"][\"location\"]}}"
},
{
"thumb_url": "={{$node[\"GraphQL\"].json[\"data\"][\"data\"][\"user\"][\"avatarUrl\"]}}"
}
],
"otherOptions": [],
"authentication": "oAuth2"
},
"credentials": {
"slackOAuth2Api": "Slack OAuth2"
},
"typeVersion": 1,
"id": "4747245c-b583-40c5-99a5-eed1b7498ac8"
}
],
"connections": {
"GraphQL": {
"main": [
[
{
"node": "Function",
"type": "main",
"index": 0
}
]
]
},
"Webhook": {
"main": [
[
{
"node": "GraphQL",
"type": "main",
"index": 0
}
]
]
},
"Function": {
"main": [
[
{
"node": "Slack",
"type": "main",
"index": 0
}
]
]
}
},
"n8n_version": "1.5.0"
}
Requirements
n8n instance, Slack API credentials
Tags
#n8n
#automation
#workflow