Notify me in Slack if I'm mentioned in a Github issue
@pravin
code:
data:privatelast updated:5 years ago
today
Build integrations remarkably fast!
You're viewing a public workflow template.
Sign up to customize, add steps, modify code and more.
Join 1,000,000+ developers using the Pipedream platform
steps.
trigger
HTTP API
Deploy to generate unique URL
This workflow runs on Pipedream's servers and is triggered by HTTP / Webhook requests.
steps.
detect_mention
auth
to use OAuth tokens and API keys in code via theauths object
params
Github username
 
string ·params.github_username
code
Write any Node.jscodeand use anynpm package. You can alsoexport datafor use in later steps via return or this.key = 'value', pass input data to your code viaparams, and maintain state across executions with$checkpoint.
async (event, steps, params) => {
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
}
80
const _ = require('lodash')

const mention = {
  issueNumber: '',
  issueTitle: '',
  issueUrl: '',
  found: false,
  label: '',
  type: '',
  by: '',
  content: '',
  notification: ''
}
mention.issueNumber = event.body.issue.number
mention.issueTitle = event.body.issue.title
mention.issueUrl = event.body.issue.url

if (_.get(event, 'body.action', '') === 'opened') {
  //process new issues -- check if username was mentioned in issue body
  console.log(event.body.issue.body)
  if (_.get(event,'body.issue.body','').includes(`@${params.github_username}`) === true) {
    //user was mentioned in the description of a new issue
    mention.found = true
    mention.label = 'issue description'
    mention.type = 'new issue'
    mention.by = _.get(event, 'body.issue.user.login', '')
    mention.content = _.get(event,'body.issue.body','')
  } else {
    //if the wasn't mentioned in the description, 
    //there should be no mention since this was a new issue
    mention.found = false
  }
} else {
  //process existing issues
  //first, check if the issue body was 
  if (_.get(event,'body.changes','') !== '' && _.get(event,'body.issue.body','').includes(`@${params.github_username}`) === true) {
    //the body was modified and the user is mentioned
    //check if the original issue body mentioned the user
    if (_.get(event,'body.changes.body.from','').includes(`@${params.github_username}`) ._
    === true) {
      //user was mentioned in the original body, but the content was updated
      mention.found = true
      mention.label = 'issue description'
      mention.type = 'content modified'
      mention.by = _.get(event, 'body.issue.user.login', '')
      mention.content = _.get(event,'body.issue.body','')
    } else {
      //user was not previously mentioned in the issue body
      mention.found = true
      mention.label = 'issue description'
      mention.type = 'new mention'
      mention.by = _.get(event, 'body.issue.user.login', '')
      mention.content = _.get(event,'body.issue.body','')
    }
  } else {
    //the user wasn't mentioned in the body
    //check if username was mentioned in issue comment
    if (_.get(event,'body.comment.body','').includes(`@${params.github_username}`) ._ 
    === true) {
      mention.found = true
      mention.label = 'comment'
      mention.type = 'new mention'
      mention.by = _.get(event, 'body.comment.user.login', '')
      mention.content = _.get(event,'body.comment.body','')
    } else {
      //the user wasn't mentioned in the comment
      mention.found = false
    }
  }
}
if(mention.found === true) {
  //construct the notification
  mention.notification = `*@${mention.by}* mentioned you `
  + `on Github: ${mention.content} `
  + `(Issue #${mention.issueNumber}:`
  + `${mention.issueTitle} ${mention.issueUrl})`
}
return mention
steps.
nodejs
auth
to use OAuth tokens and API keys in code via theauths object
code
Write any Node.jscodeand use anynpm package. You can alsoexport datafor use in later steps via return or this.key = 'value', pass input data to your code viaparams, and maintain state across executions with$checkpoint.
async (event, steps) => {
1
2
3
4
}
5
if (steps.detect_mention.found !== true) {
    $end('User not mentioned')
}
steps.
chat_post_message
Sends a message to a channel.
auth
(auths.slack)
params
Channel

Channel, private group, or IM channel to send message to. Can be an encoded ID, or a name. See below for more details.

 
C1234567890
string ·params.channel
Text

Text of the message to send. See below for an explanation of formatting. This field is usually required, unless you're providing only attachments instead. Provide no more than 40,000 characters or risk truncation.

 
Hello world
string ·params.text
Optional
code
async (params, auths) => {
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
}
29
const data = {
  channel: params.channel,
  text: params.text,
  as_user: params.as_user,
  attachments: params.attachments,
  blocks: params.blocks,
  icon_emoji: params.icon_emoji,
  icon_url: params.icon_url,
  link_names: params.link_names,
  mrkdwn: params.mrkdwn,
  parse: params.parse,
  reply_broadcast: params.reply_broadcast,
  thread_ts: params.thread_ts,
  unfurl_links: params.unfurl_links,
  unfurl_media: params.unfurl_media,
  username: params.username,
}
const config = {
  method: "post",
  url: `https://slack.com/api/chat.postMessage`,
  headers: {
    Authorization: `Bearer ${auths.slack.oauth_access_token}`,
  },
  data,
}
return await require("@pipedreamhq/platform").axios(this, config)