Skip to content

Instantly share code, notes, and snippets.

@pimterry
Created October 14, 2016 12:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pimterry/fe731b0efe3f93a665d308e9415926aa to your computer and use it in GitHub Desktop.
Save pimterry/fe731b0efe3f93a665d308e9415926aa to your computer and use it in GitHub Desktop.
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