Created
October 14, 2016 12:04
-
-
Save pimterry/ef8c8cf2471160bffc29afc0906b26f8 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
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