3 var StatusError = require('statuserror');
4 var wrap = require('./github-cache-wrapper');
5 var tentacles = require('./tentacles-client');
6 var userTokenSelector = require('./user-token-selector').full;
8 function standardizeResponse(response) {
12 title: response.title,
14 state: response.state,
15 labels: (response.labels || []).map(function(label) {
18 author: response.user && {
20 username: response.user.login,
22 avatarUrl: response.user.avatar_url
24 assignee: response.assignee && {
25 id: response.assignee.id,
26 username: response.assignee.login,
28 avatarUrl: response.assignee.avatar_url
30 createdAt: response.created_at,
31 updatedAt: response.updated_at
35 function GitHubIssueService(user) {
37 this.accessToken = userTokenSelector(user);
40 GitHubIssueService.prototype.getIssue = function(repo, issueNumber) {
41 return tentacles.issue
42 .get(repo, issueNumber, { accessToken: this.accessToken })
45 return standardizeResponse(response);
48 throw new StatusError(404, `Unable to fetch GitHub issue ${repo}#${issueNumber}`);
52 module.exports = wrap(GitHubIssueService, function() {
53 return [this.accessToken || ''];