forked from eMazeika/GitHub-Pull-Request-Metrics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
resources.js
60 lines (50 loc) · 2.39 KB
/
resources.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
angular
.module('myApp')
.constant('baseUrl', 'https://api.github.com/')
.factory('sharedData', function () {
return {
token: '',
organization: '',
repos: [
]
};
})
.factory('github.api', ['$resource', 'baseUrl', function ($resource, bu) {
return $resource(null, null, {
getPr: { url: bu + 'repos/:organization/:repo/pulls/:pull_number' },
getPrReviews: { url: bu + 'repos/:organization/:repo/pulls/:pull_number/reviews', isArray: true },
getPrComments: { url: bu + 'repos/:organization/:repo/pulls/:pull_number/comments', isArray: true },
getBasicComments: { url: bu + 'repos/:organization/:repo/issues/:pull_number/comments', isArray: true },
// methods for API testing
limit: { url: bu + 'rate_limit' },
repos: { url: bu + 'repos/:organization/hot-theme/issues', isArray: true }
});
}])
.service('searchService', ['$http', 'baseUrl', function ($http, bu) {
return {
prSearch: function (filter) {
var beginDate = moment(filter.startDate).format().slice(0, 10);
var endDate = filter.endDate ? moment(filter.endDate).format().slice(0, 10) : '*';
var queryFilter = '+repo:' + filter.organization + '/' + filter.repo + '+closed:' + beginDate + '..' + endDate;
return $http.get(bu + 'search/issues?per_page=100&page=' + filter.page + '&q=is:pr+is:merged' + queryFilter);
},
commitSearch: function (filter) {
var beginDate = moment(filter.startDate).format().slice(0, 10);
var queryFilter = 'repos/' + filter.organization + '/' + filter.repo + '/commits';
return $http.get(bu + queryFilter, {params: { since: beginDate }});
}
};
}])
.factory('httpErrorInterceptor', ['sharedData', function (sharedData) {
var httpErrorInterceptor = {};
httpErrorInterceptor.request = function (config) {
config.headers.Authorization = 'token ' + sharedData.token;
config.headers.Accept = 'application/vnd.github.v3+json';
return config;
};
return httpErrorInterceptor;
}])
.config(['$httpProvider', function ($httpProvider) {
$httpProvider.interceptors.push('httpErrorInterceptor');
}])
;