forked from techx/hackmit-hackbot
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgithub.coffee
More file actions
41 lines (35 loc) · 1.09 KB
/
github.coffee
File metadata and controls
41 lines (35 loc) · 1.09 KB
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
# Description:
# GitHub stuff.
#
# Configuration:
# HUBOT_GITHUB_USERNAME
# HUBOT_GITHUB_PASSWORD
# HUBOT_GITHUB_ORGANIZATION
#
# Commands:
# hubot github issue create <repo> "<title>" "<description>"
#
# Author:
# anishathalye
GitHubApi = require('github')
module.exports = (robot) ->
config = require('hubot-conf')('github', robot)
github = () ->
user = config 'username'
pass = config 'password'
gh = new GitHubApi(version: '3.0.0')
gh.authenticate type: 'basic', username: user, password: pass
gh
# using '[\s\S]' to match multiline (instead of just '.')
robot.respond /github issue create ([A-Za-z0-9_.-]+) "(.+)" "([\s\S]+)"/i, (res) ->
creator = res.message.user.name
repo = res.match[1]
title = res.match[2]
desc = "#{res.match[3]}\n\n(submitted by #{creator})"
org = config 'organization'
issues = github().issues
issues.create user: org, repo: repo, title: title, body: desc, (err, data) ->
if not err
res.send "Created issue ##{data.number} in #{org}/#{repo}."
else
res.send "Error creating issue."