-
Notifications
You must be signed in to change notification settings - Fork 1
/
api.js
36 lines (30 loc) · 902 Bytes
/
api.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
var config = {};
withOptions(function(items) {
config = {
teamCityUrl: items.teamcityUrl,
buildType: items.buildType
};
});
function Builds(api) {
this.getLastByBranchName = function (branchName, callback) {
api.get('builds?locator=buildType:' + config.buildType + ',branch:' + branchName + ',count:1', function (builds) {
var lastBuild = builds.build.length > 0 ? builds.build[0] : null;
callback(lastBuild);
});
};
return this;
}
function Api() {
this.get = function (path, callback) {
chrome.runtime.sendMessage({
action: 'xhttp',
url: config.teamCityUrl + 'httpAuth/app/rest/' + path
}, function (responseText) {
var json = JSON.parse(responseText);
callback(json);
});
};
this.builds = new Builds(this);
return this;
}
var api = new Api();