+/**
+ * Fetch all existing project issues from GitLab - assigns gitLab.gitlabIssues
+ */
+function getGitLabProjectIssues() {
+ return getRemainingGitLabProjectIssues(0, 100)
+ .then(function(result) {
+ log_progress("Fetched " + result.length + " GitLab issues.");
+ var issues = _.indexBy(result, 'iid');
+ return gitLab.gitlabIssues = issues;
+ });
+}
+
+/**
+ * Recursively fetch the remaining issues in the project
+ * @param page
+ * @param per_page
+ */
+function getRemainingGitLabProjectIssues(page, per_page) {
+ var from = page * per_page;
+ log_progress("Fetching Project Issues from GitLab [" + (from + 1) + "-" + (from + per_page) + "]...");
+ var url = gitlabAPIURLBase + '/projects/' + gitLab.project.id + "/issues";
+ var data = {
+ page: page,
+ per_page: per_page,
+ // FIXME: schnalke
+ //order_by: 'id',
+ private_token: gitlabAdminPrivateToken, sudo: gitlabSudo };
+
+ return rest.get(url, {data: data})
+ return rest.get(url, {data: data})
+ .fail(function(err) {
+ console.log(err);
+ })
+ .then(function(issues) {
+ if(issues.length < per_page) {
+ return issues;
+ }
+ return getRemainingGitLabProjectIssues(page+1, per_page)
+ .then(function(remainingIssues) {
+ return issues.concat(remainingIssues);
+ });
+ }, function(error) {
+ throw new Error('Cannot get list of issues from gitlab: ' + url + " page=" + page);
+ });
+}
+
+function getUserByMantisUsername(username) {
+ return (username && config.users[username]) || config.users[""] || null;