-
Notifications
You must be signed in to change notification settings - Fork 0
/
gitlabRequest.js
40 lines (34 loc) · 1.13 KB
/
gitlabRequest.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
.pragma library
var privtoken;
var giturl;
function gitlabRequest(command , onDoneCallback) {
var httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = function() {
if (httpRequest.readyState == XMLHttpRequest.DONE) {
var text = httpRequest.responseText;
//console.log("Response: " + text);
if (text) {
var json = JSON.parse(text);
onDoneCallback(json);
}
}
}
var u = giturl + "/api/v4/" + command;
console.log("Request: " + u);
httpRequest.open("GET", u);
httpRequest.setRequestHeader("PRIVATE-TOKEN", privtoken);
httpRequest.send();
}
function getProjects(projectId, resultCallback)
{
gitlabRequest("projects/" + projectId, resultCallback);
}
function getBranches(projectId, resultCallback)
{
gitlabRequest("projects/" + projectId + "/repository/branches?per_page=100", resultCallback);
}
function getCommit(projectId, branch, resultCallback)
{
var encodedBranch = encodeURIComponent(branch);
gitlabRequest("projects/" + projectId + "/repository/branches/" + encodedBranch, resultCallback)
}