 class GithubIssue extends NotificationPlugin
   BASE_URL = "https://api.github.com"
 
-  @receiveEvent: (config, event, callback) ->
+  @issuesUrl: (config) -> "#{BASE_URL}/repos/#{config.repo}/issues"
+  @issueUrl: (config, issueNumber) -> "#{@issuesUrl(config)}/#{issueNumber}"
 
+  @githubRequest: (req, config) ->
+    req.timeout(4000).set("User-Agent", "Bugsnag")
+
+    if config.oauthToken
+      req.set("Authorization", "token #{config.oauthToken}")
+    else
+      req.auth(config.username, config.password)
+
+  @addCommentToIssue: (config, issueNumber, comment) ->
+    console.log "Add comment"
+    @githubRequest(@request.post("#{@issueUrl(config, issueNumber)}/comments"), config)
+      .send({body: comment})
+      .on "error", (err) ->
+        console.log err
+      .end (res) ->
+        console.log "Success comment!"
+
+  @ensureIssueOpen: (config, issueNumber, callback) ->
+    console.log "Ensure issue open"
+    @githubRequest(@request.patch(@issueUrl(config, issueNumber)), config)
+      .send({state: "open"})
+      .on "error", (err) ->
+        console.log err
+        callback(err)
+      .end (res) ->
+        console.log "Success open!"
+        callback(res.error)
+
+  @openIssue: (config, event, callback) ->
     # Create labels variable
     payloadLabels = (config?.labels || "bugsnag")
     # Check App Version Labeling

          number: res.body.number
          url: res.body.html_url

module.exports = GithubIssue
    payload =
      title: @title(event)
      body: @markdownBody(event)
      labels: payloadLabels.split(/\s*,\s*/).compact(true)

    @githubRequest(@request.post(@issuesUrl(config)), config)
      .send(payload)
      .on "error", (err) ->
        callback(err)
