Comments (5)
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))
from gitlab.
ah, nope. thanks!
from gitlab.
Sweet :)
from gitlab.
I've been having problems with Promises as well...
Added the commitActions
method to repository. Please let's get this method added! Help me out :) This is a nightmare/jungle. Spent all day...
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:
{ Gitlab400Error: You can only create or edit files when you are on a branch
at Gitlab.RESTFulClient.handleResult (/Users/kristianmandrup/repos/tecla5/gitlab/node_modules/restful-client/lib/client.js:86:11)
at /Users/kristianmandrup/repos/tecla5/gitlab/node_modules/restful-client/lib/client.js:166:10
at done (/Users/kristianmandrup/repos/tecla5/gitlab/node_modules/urllib/lib/urllib.js:266:5)
at /Users/kristianmandrup/repos/tecla5/gitlab/node_modules/urllib/lib/urllib.js:440:9
at IncomingMessage.<anonymous> (/Users/kristianmandrup/repos/tecla5/gitlab/node_modules/urllib/lib/urllib.js:416:7)
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 client.promise.repository.commitActions
ensuring the commitActions
was added to repositories
object of properties.js
to be picked up by promisifyAll
My before
and after
to create and cleanup test project (i.e client.id
)
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.
from gitlab.
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 :)
from gitlab.
Related Issues (20)
- Support to create hooks with SSL verification disabled
- Acesss all projects by admin
- Replace native-or-bluebird with any-promise HOT 1
- Merge request bad URL HOT 1
- namespaces()
- Please support commit multiple files API method :) HOT 1
- Running tests on own/custom repo? HOT 3
- Add support for Runners
- Add support for Contributors HOT 2
- Is there a possibility to set header?
- remounitng issue
- Client side usage
- How to update the content of gitlab repository file with encoding utf-8 HOT 1
- Protected branches Error
- Support for GitLab api v4 HOT 4
- import not work on Meteor JS? HOT 1
- Enquiry about RepositoryFiles section from the node-gitlab package HOT 1
- How to fetch + merge?
- How to delete an issue
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gitlab.