forked from piceaTech/node-gitlab-2-github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgitlabHelper.js
More file actions
79 lines (72 loc) · 1.92 KB
/
gitlabHelper.js
File metadata and controls
79 lines (72 loc) · 1.92 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import * as settings from './settings';
export default class GitlabHelper {
constructor(gitlabApi, gitlabSettings) {
this.gitlabApi = gitlabApi;
this.gitlabUrl = gitlabSettings.url;
this.gitlabToken = gitlabSettings.token;
this.gitlabProjectId = gitlabSettings.projectId;
}
/**
* List all projects that the GitLab user is associated with.
*/
async listProjects() {
try {
const projects = await this.gitlabApi.Projects.all({ membership: true });
// print each project with info
for (let i = 0; i < projects.length; i++) {
console.log(
projects[i].id.toString(),
'\t',
projects[i].name,
'\t--\t',
projects[i].description
);
}
// instructions for user
console.log('\n\n');
console.log(
'Select which project ID should be transported to github. Edit the settings.js accordingly. (gitlab.projectID)'
);
console.log('\n\n');
} catch (err) {
console.error('An Error occured while fetching all GitLab projects:');
console.error(err);
}
}
/**
* Gets all notes for a given issue.
*/
async getIssueNotes(issueIid) {
try {
return await this.gitlabApi.IssueNotes.all(
this.gitlabProjectId,
issueIid
);
} catch (err) {
console.error(`Could not fetch notes for GitLab issue #${issueIid}.`);
return [];
}
}
/**
* Gets all branches.
*/
async getAllBranches() {
return await this.gitlabApi.Branches.all(this.gitlabProjectId);
}
/**
* Gets all notes for a given merge request.
*/
async getAllMergeRequestNotes(pullRequestIid) {
try {
return this.gitlabApi.MergeRequestNotes.all(
this.gitlabProjectId,
pullRequestIid
);
} catch (err) {
console.error(
`Could not fetch notes for GitLab merge request #${pullRequestIid}.`
);
return [];
}
}
}