Skip to content

Instantly share code, notes, and snippets.

@pimterry
Created October 14, 2016 12:04
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/ef8c8cf2471160bffc29afc0906b26f8 to your computer and use it in GitHub Desktop.
Save pimterry/ef8c8cf2471160bffc29afc0906b26f8 to your computer and use it in GitHub Desktop.
class Thread {
constructor (private github: any, private 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}`);
}
this.repo = new Repo(issueMatch[1], issueMatch[2]);
this.id = parseInt(issueMatch[3], 10);
// Note that this constructor returns a *promise*, not an instance
return <any> <Promise<Thread>> this.github.issues.getComments({
user: this.repo.user,
repo: this.repo.name,
number: this.id
}).then((comments) => {
this.comments = comments;
return this;
});
}
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