Created
October 14, 2016 12:08
-
-
Save pimterry/fe731b0efe3f93a665d308e9415926aa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function getThread(github: any, url: string): Promise<Thread> { | |
let issueMatch = /api.github.com\/repos\/([\-\w]+)\/([\-\w]+)\/issues\/(\d+)/.exec(url); | |
if (!issueMatch) { | |
throw new Error(`Received issue notification that didn't match regex: ${url}`); | |
} | |
let repo = new Repo(issueMatch[1], issueMatch[2]); | |
let id = parseInt(issueMatch[3], 10); | |
let comments = await github.issues.getComments({ | |
user: repo.user, | |
repo: repo.name, | |
number: id | |
}); | |
return new Thread(github, url, repo, id, comments); | |
} | |
class Thread { | |
constructor (private github: any, | |
private url: string, | |
public repo: Repo, | |
public id: number, | |
public comments: any[]) { | |
} | |
comment(message: string): Promise<void> { | |
return this.github.issues.createComment({ | |
user: this.repo.user, | |
repo: this.repo.name, | |
number: this.id, | |
body: message | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment