-
Notifications
You must be signed in to change notification settings - Fork 1
/
gitlab.js
61 lines (55 loc) · 2.69 KB
/
gitlab.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
61
const gitlab = require("gitlab");
const config = require("./config");
const GitlabHelper = class GitlabHelper {
constructor() {
this.api = new gitlab.Gitlab(config.gitlab.initOptions);
}
testCommit() {
this.api.Commits.create(config.gitlab.projectID, "master", "Test commit", [{
action: 'create',
filePath: 'test.txt',
content: 'Hello World!'
}]);
}
commitPackage(subpackage) {
var commitJson;
if (subpackage.type == 'new' || subpackage.type === undefined /* In the case of no type, assume new */) { //TODO Updates
commitJson = {package: subpackage.package, info: subpackage.info, changelog: "", assets: []};
}
let commitFiles = [{action: 'create', filePath: subpackage.package + '/pkgbuild.json', content: ''}];
subpackage.assets.forEach(asset => {
switch (asset.type) {
case 'icon':
case 'screen':
case 'screenshot':
if (asset.format == 'url')
{
commitJson.assets.push({url: asset.data, type: asset.type});
}else if (asset.format == 'base64') {
commitJson.assets.push({url: asset.type + '.png', type: asset.type});
commitFiles.push({action: 'create', filePath: subpackage.package + '/' + asset.type + '.png', encoding: 'base64', content: asset.data.substr(22)});
}
break;
case 'zip':
case 'update':
case 'get':
case 'local':
case 'extract':
commitJson.assets.push(asset);
break;
}
});
commitFiles[0].content = JSON.stringify(commitJson, null, 1);
return this.api.Commits.create(config.gitlab.projectIDs[subpackage.console], "master", `${subpackage.type}: ${subpackage.package} (${subpackage.info.version})`, commitFiles, {author_email: "[email protected]", author_name: "Dragonite Bot"});
}
commitReview(review) {
let commitFiles = [{action: 'create', filePath: '/_data/reviews/' + review.uuid + '.json', content: ''}];
commitFiles[0].content = JSON.stringify(review, null, 1);
return this.api.Commits.create(config.gitlab.qaID, "master", `[QA] ${review.accept} ${review.package.info.title}`, commitFiles, {author_email: "[email protected]", author_name: "Dragonite Bot"});
}
async checkPipeline(repo) {
var pipes = await this.api.Pipelines.all(config.gitlab.projectIDs[repo]);
return pipes[0].status === 'success';
}
}
module.exports = GitlabHelper;