-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Promises don't seem to work #32
Comments
Tested the following in node v7.4.0 and it works. did you use gitlab.createPromise? var gitlab = require('node-gitlab');
var client = gitlab.createPromise({
api: 'http://gitlab..../api/v3',
privateToken: 'z....m'
});
client.projects.list({})
.then(p => console.log(JSON.stringify(p)))
.catch(err => console.error(err)) |
ah, nope. thanks! |
Sweet :) |
I've been having problems with Promises as well... gitlabl: create a commit with multiple files and actions Finally got it working, but only in callback mode. I need promises to work with the rest of my code! it('should commit a list of actions', function (done) {
console.log(`repository.commitActions`, client.id)
let random = Math.floor((Math.random() * 1000) + 1)
client.repository.commitActions({
id: client.id,
// branch_name: 'develop', for v3 API
branch: 'develop',
actions: [{
action: 'create',
file_path: `foolish-${random}`,
content: 'some content'
// encoding: 'text'
}],
// author_email: '[email protected]',
// author_name: 'tester',
commit_message: 'goodies'
}, function (err, res) {
console.log('RETURNED', {
err,
res
})
should.not.exists(err);
should.exists(res);
done();
})
}) However if I wrap it in a Promise, I always get this error:
Even when wrapping manually: function errorAndReject(err, reject) {
console.error(err)
reject(err)
}
function commitActionsPromised(data) {
return new Promise((resolve, reject) => {
client.repository.commitActions(data, (err, result) => {
err ? reject(err, reject) : resolve(result)
})
})
}
// essentially should be same as:
// client.promise.repository.commitActions
commitActionsPromised({
id: client.id, Any idea? I also tried using My const cleanupTimeout = 1000
before(function (done) {
// use API v4 ??
// See: https://docs.gitlab.com/ce/api/v3_to_v4.html
// process.env.NODE_GITLAB_API = 'https://gitlab.com/api/v4'
console.log('before suite, create fresh test project to be used :)')
client.createProject(function (err) {
console.log(`test project created: ${client.id}`)
console.log(`Ready for action!`)
done();
});
});
// Seems to work only if I don't clean up (remove) project after.
// Looks like a race condition!?
after((done) => {
// Try cleanup 5secs after tests done
setTimeout(() => {
console.log(`Cleaning up!!!`)
client.removeProject()
console.log(`DONE Clean up!!!`)
done()
}, cleanupTimeout)
}); I also experienced racing condition on after cleanup, so I set a 1 sec wait. |
Turns out the weird error was most likely due to slow/bad wifi connection. When I moved my laptop closer to the router this morning, it all worked as expected :) |
In node v7.2.0, code like this works:
But with this:
I get this error:
It seems like promises don't work with several others, as well.
The text was updated successfully, but these errors were encountered: