Skip to content

Commit

Permalink
Merge 0da5006 into f0fdc6b
Browse files Browse the repository at this point in the history
  • Loading branch information
k1LoW committed Jul 2, 2018
2 parents f0fdc6b + 0da5006 commit 7f85858
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 24 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@
"@octokit/rest": "^15.2.6",
"ajv": "^6.1.0",
"ajv-keywords": "^3.0.0",
"axios": "^0.17.1",
"axios": "^0.18.0",
"bluebird": "^3.5.1",
"gitlab": "^1.7.1",
"gitlab": "^3.4.4",
"http-errors": "^1.6.2",
"js-sha256": "^0.9.0",
"js-yaml": "^3.10.0",
"json-schema-deref-sync": "^0.4.0",
"middy": "^0.12.1",
"middy": "^0.15.7",
"moment": "^2.20.1",
"moment-timezone": "^0.5.14",
"url-template": "^2.0.8"
Expand All @@ -60,7 +60,7 @@
"coveralls": "^3.0.0",
"intelli-espower-loader": "^1.0.1",
"mocha": "^5.0.0",
"nyc": "^11.4.1",
"nyc": "^12.0.2",
"octopublish": "^0.6.0",
"power-assert": "^1.4.3",
"serverless": "^1.24.1",
Expand Down
53 changes: 33 additions & 20 deletions src/lib/notifications/gitlab.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const gitlab = require('gitlab');
const Gitlab = require('gitlab/dist/es5').default;
const messageBuilder = require('../messageBuilder');

module.exports = (n, errorData) => {
Expand All @@ -10,7 +10,7 @@ module.exports = (n, errorData) => {
endpoint = n.endpoint;
}

const g = gitlab({
const g = new Gitlab({
url: endpoint,
token: n.personalAccessToken
});
Expand All @@ -37,45 +37,58 @@ module.exports = (n, errorData) => {
labels = n.labels.join(',');
}
const body = messageBuilder.body(n, errorData);
g.projects.all((projects) => {
let project = projects.find((project) => {
return (project.path_with_namespace == `${n.owner}/${n.repo}`);
});
g.projects.issues.list(project.id, {
search: title,
per_page: 1
}, (issues) => {

let project = null;

g.Projects.all({owned:true})
.then((projects) => {
project = projects.find((project) => {
return (project.path_with_namespace == `${n.owner}/${n.repo}`);
});
return g.Issues.all(project.id, {
search: title,
maxPages: 1
});
})
.then((issues) => {
let issue = issues.find((issue) => {
return (issue.title == title);
});
if (issue) {
const promises = [];
if (isReopen()) {
if (isUpdate()) {
g.issues.edit(project.id, issue.id, {
state_event: 'reopen',
promises.push(g.Issues.edit(project.id, issue.iid, {
stateEvent: 'reopen',
title: title,
labels: labels,
body: body + messageBuilder.footer(n, errorData)
});
}));
} else {
g.issues.edit(project.id, issue.id, {
state_event: 'reopen'
});
promises.push(g.Issues.edit(project.id, issue.iid, {
stateEvent: 'reopen'
}));
}
}
if (isComment()) {
g.notes.create(project.id, issue.id, {
promises.push(g.IssueNotes.create(project.id, issue.iid, {
body: body + messageBuilder.commentFooter(n, errorData)
});
}));
}
return Promise.all(promises);
} else {
// Create issue
g.issues.create(project.id, {
return g.Issues.create(project.id, {
title: title,
description: body + messageBuilder.footer(n, errorData),
labels: labels
});
}
})
.then(() => {
})
.catch((err) => {
console.error(err);
});
});

};

0 comments on commit 7f85858

Please sign in to comment.