moul / node-gitlab Goto Github PK
View Code? Open in Web Editor NEWDEPRECATED, see https://github.com/node-gitlab/node-gitlab
Home Page: https://npmjs.org/package/gitlab
License: Other
DEPRECATED, see https://github.com/node-gitlab/node-gitlab
Home Page: https://npmjs.org/package/gitlab
License: Other
I published a new [email protected] of cli-gitlab. It use a map to create command https://github.com/mdsb100/cli-gitlab/blob/master/bin/worker.coffee
But I am not sure how to define parameter of many function. For example: "Users.create".
P.S, I test most function, they are OK!
The request url of diffCommit which is 'projects/#{Utils.parseProjectId projectId}/repository/branches/#{sha}"' seems wrong.
Should that be 'GET /projects/:id/repository/commits/:sha/diff'?
At the moment the code is passing the private token on the querystring which means that it can be logged into any number of log files (proxy server or the final web server). Gitlab itself does filter out the string in its own logs but I was seeing the private token in nginx logs which probably isn't a good thing.
I think it is a simple 1 line fix in the code and a move to a newer version of slumber (0.6 minimum, but I've been testing on 0.7 so far).
I would raise a merge request but my fork has a few other commits on the develop branch so that would confuse things. The commit I made is at steve-norman-rft@0b55895
Change is in ApiBaseHTTP.coffee:
prepare_opts: (opts) =>
opts.__query ?= {}
Hi,
When I try to create an issue with inexistent tags, I get a "true" answer from the issues.create method instead of an error.
At the moment we complete callbacks with the raw JSON output of the API... what about parsing the output?
This lets us call functions on the created objects:
This:
gitlab.projects.all (projects) ->
for project in projects
project.members.all (members) ->
console.log members
rather than:
gitlab.projects.all (projects) ->
for project in projects
gitlab.projects.members.list project.id, (members) ->
console.log members
Not the best example, but it seems simpler?
In api document:
Create repository branch
POST /projects/:id/repository/branches
Parameters:
id (required) - The ID of a project
branch_name (required) - The name of the branch
ref (required) - Create branch from commit SHA or existing branch
In interface:
createBranch: (params = {}, fn = null) =>
@debug "Projects::createBranch()", params
@post "projects/#{Utils.parseProjectId params.projectId}/repository/branches", params, (data) => fn data if fn
The parameters are required, so I think:
createBranch: (projectId, branchName, ref, fn = null) =>
params =
id: projectId
branch_name: brancheName
ref: ref
@post "projects/#{Utils.parseProjectId params.projectId}/repository/branches", params, (data) => fn data if fn
In api document:
Create MR
Creates a new merge request.
POST /projects/:id/merge_requests
Parameters:
id (required) - The ID of a project
source_branch (required) - The source branch
target_branch (required) - The target branch
assignee_id (optional) - Assignee user ID
title (required) - Title of MR
description (optional) - Description of MR
target_project_id (optional) - The target project (numeric id)
In interface:
add: (projectId, sourceBranch, targetBranch, assigneeId, title, fn = null) =>
@debug "Projects::addMergeRequest()"
params =
id: Utils.parseProjectId projectId
source_branch: sourceBranch
target_branch: targetBranch
assignee_id: parseInt assigneeId
title: title
@post "projects/#{Utils.parseProjectId projectId}/merge_requests", params, (data) => fn data if fn
I think this:
add: (projectId, sourceBranch, targetBranch, title, params = {}, fn = null) =>
@debug "Projects::addMergeRequest()"
params.id = Utils.parseProjectId projectId
params.source_branch = sourceBranch
params.target_branch = targetBranch
params.title = title
@post "projects/#{Utils.parseProjectId projectId}/merge_requests", params, (data) => fn data if fn
especially to fix the bugs?
This would make my|their
life much easier :)
gitlab.projects.create({
// ...
}, function onSuccess (err, result) {
if (err) {
// handle error here
}}
});
In ProjectHooks.coffee
update: (projectId, hookId, url, fn = null) =>
@debug "Projects::saveHook()"
params =
access_level: parseInt accessLevel
@put "projects/#{Utils.parseProjectId projectId}/hooks/#{parseInt hookId}", params, (data) => fn data if fn
is support call gitlab api with access_token?
Fork project api not implemented yet. Consider doing it myself tomorrow.
Forks a project into the user namespace of the authenticated user.
POST /projects/fork/:id
Parameters:
id (required) - The ID of the project to be forked
All of the .js
examples on the README, cause errors.
Problems:
)
in the handler for gitlab.users.all()
user
is undefined inside same handler.project
is undefined inside handler for gitlab.projects.all()
gitlab.users.all
TypeError: Cannot read property 'length' of null
at /home/chief/Code/gitlab/index.js:13:28
at /home/chief/Code/gitlab/node_modules/gitlab/lib/Models/Users.js:29:20
at /home/chief/Code/gitlab/node_modules/gitlab/lib/ApiBaseHTTP.js:81:22
at _Class.wrap_response (/home/chief/Code/gitlab/node_modules/gitlab/node_modules/slumber/lib/API.js:161:18)
at _Class.wrap_response (/home/chief/Code/gitlab/node_modules/gitlab/node_modules/slumber/lib/API.js:4:61)
at Request.handle [as _callback] (/home/chief/Code/gitlab/node_modules/gitlab/node_modules/slumber/lib/API.js:178:24)
at Request.self.callback (/home/chief/Code/gitlab/node_modules/gitlab/node_modules/slumber/node_modules/request/request.js:122:22)
at Request.EventEmitter.emit (events.js:98:17)
at Request.<anonymous> (/home/chief/Code/gitlab/node_modules/gitlab/node_modules/slumber/node_modules/request/request.js:888:14)
at Request.EventEmitter.emit (events.js:117:20)
gitlab.projects.all()
TypeError: Cannot read property 'length' of null
at gitlab.projects.all.i (/home/chief/Code/gitlab/index.js:13:28)
at /home/chief/Code/gitlab/node_modules/gitlab/lib/Models/Users.js:29:20
at /home/chief/Code/gitlab/node_modules/gitlab/lib/ApiBaseHTTP.js:81:22
at _Class.wrap_response (/home/chief/Code/gitlab/node_modules/gitlab/node_modules/slumber/lib/API.js:161:18)
at _Class.wrap_response (/home/chief/Code/gitlab/node_modules/gitlab/node_modules/slumber/lib/API.js:4:61)
at Request.handle [as _callback] (/home/chief/Code/gitlab/node_modules/gitlab/node_modules/slumber/lib/API.js:178:24)
at Request.self.callback (/home/chief/Code/gitlab/node_modules/gitlab/node_modules/slumber/node_modules/request/request.js:122:22)
at Request.EventEmitter.emit (events.js:98:17)
at Request.<anonymous> (/home/chief/Code/gitlab/node_modules/gitlab/node_modules/slumber/node_modules/request/request.js:888:14)
at Request.EventEmitter.emit (events.js:117:20)
index.js
file"use strict";
var fs = require('fs');
var token = fs.readFileSync('.token');
var gitlab = new (require('gitlab'))({
url: 'http://puturcodein.us',
token: token
});
// Listing users
gitlab.users.all(function(users) {
for (var i = 0; i < users.length; i++) {
console.log("#" + users[i].id + ": " + users[i].email + ", " + users[i].name + ", " + users[i].created_at);
}
});
// Listing projects
gitlab.projects.all(function(projects) {
for (var i = 0; i < projects.length; i++) {
console.log("#" + project.id + ": " + project.name + ", path: " + project.path + ", default_branch: " + project.default_branch + ", private: " + project["private"] + ", owner: " + project.owner.name + " (" + project.owner.email + "), date: " + project.created_at);
}
});
@moul What's the plan for the develop branch? You've release 0.8.6 to npm from the develop branch, I would have expected this to come from master.
Don't mind what you do, as long as the convention is clear so I don't merge stuff into master by accident (like #30) when it seems it belongs in develop.
In group.coffee, there are #{parseInt groupId}
here and there.
parseInt
stops me from passing a group name, however groupId
in '/gorups/:groupId' can be a group name as well.
Did I miss something?
In the API docs it specifies the ability to set which events are hooked when adding a hook to the system.
http://doc.gitlab.com/ce/api/projects.html
Add project hook
Adds a hook to project.
POST /projects/:id/hooks
Parameters:
id (required) - The ID or NAMESPACE/PROJECT_NAME of a project
url (required) - The hook URL
push_events - Trigger hook on push events
issues_events - Trigger hook on issues events
merge_requests_events - Trigger hook on merge_requests events
The current implementation only allows the URL to be passed. Please enhance the method to allow an object of options to be passed in. I am very new to GitLab, and your module, but imagine there are other places this would be appropriate behavior as well.
I realize this would break the current function, maybe there is a way to allow either or?
Thanks for this great module, it has already saved me a lot of time.
Hello,
Is there a command that wraps this endpoint to do search? I can't seem to find one in the source...
GET /projects/search/:query
Hello,
The command for does not seem to work.
GET /projects/search/:query
it hasn't support gitlab.projects.repository.contribute API.
it's in plan or what?
Hey,
i have more than 20 milestones. Problem is with current implementation one can only see the last 20. Like this.
Gonna submit a PR in some hours.
See: pyapi-gitlab/pyapi-gitlab#37
Hi, I just read this article, and I decided to move the repo to a dedicated organization
@dave-irvine is also admin of this organization
I updated some files and services but I can have missed some
fn_wrapper - There's an exception throwing inside a callback that cannot be caught in an external try-catch block (only within process.on('uncaughtException')
), but in Coffee's fn_wrapper no exception is thrown. The same thing in 1.4.0 tag.
Should be rebuilt, huh?
stacktrace
/xxx/node_modules/gitlab/lib/ApiV3.js:4
__bind = function(fn, me){ return function(){ return fn.apply(me, argument
^
TypeError: Cannot call method 'apply' of undefined
at /xxx/node_modules/gitlab/lib/ApiV3.js:4:61
at /xxx/node_modules/gitlab/lib/ApiBaseHTTP.js:4:61
at /xxx/node_modules/gitlab/lib/ApiBase.js:4:61
at ApiBase (/xxx/node_modules/gitlab/lib/ApiBase.js:13:12)
at ApiBaseHTTP (/xxx/node_modules/gitlab/lib/ApiBaseHTTP.js:29:48)
at ApiV3 (/xxx/node_modules/gitlab/lib/ApiV3.js:17:42)
at Object.<anonymous> (/xxx/main.js:1:35)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
my code
var gitlab = new require('gitlab')({
url: 'gitlab.com',
token: 'abcdefghij123456'
});
gitlab.users.show(1, function(user) {
console.dir(user);
});
I'm on node 0.10.18, node-gitlab 0.8.6
Quick one for @moul, do you think the project could do with some method (other than Github Issues) of discussing aspects of the work? Things to be done, coding styles, coffeescript advice, that sort of thing?
Suggesting https://gitter.im/ as a potential solution.
If you're happy with just making new Issues for these sorts of questions then I'm happy to stick with that :)
It seems that a potential error returned by the remote HTTP endpoint is never returned to the caller.
The wrapper around slumber return errors only if the argument length (arity) of the callback is as expected: https://github.com/node-gitlab/node-gitlab/blob/develop/src/ApiBaseHTTP.coffee#L41-L47
But the callback evaluated there is not the one supplied by the user. Random samples of some central models support this thesis and show that only a wrapper is ever seen by the lines of code quoted above:
https://github.com/node-gitlab/node-gitlab/blob/develop/src/Models/Projects.coffee#L42 (...)
https://github.com/node-gitlab/node-gitlab/blob/develop/src/Models/Groups.coffee#L38 (...)
My question is therefore, how do I get notified in case of errors. I need to ensure that my operations placed at the remote gitlab instance were carry out succesfully.
Not exactly an Issue, but couldn't think of a better way to contact you.
I see in src/APIBase.coffee commented out references to other Models that don't exist yet.
#@repositories = require('./Models/Repositories') @client
Is there a roadmap or something similar you are working to that I can follow as well to avoid duplicating work, or should I just hack away at whatever?
Thanks for your merges so far, CoffeeScript is not my native language so it has been a bit of a challenge! :)
Hi,
Seems the lib is not handling Unauthorized
errors. When I use an invalid token is not throwing any exception or returning a error parameter in the callback. In case of gitlab.projects.all
it is only returning a empty array.
var gitlab = require('gitlab')({
url: 'my-gitlab-url',
token: 'invalid-token'
});
// Listing projects
return gitlab.projects.all(function(err, resp, result) {
// many arguments on callback just to show
// is not returning the error in another argument
// err = []
// resp = undefined
// result = undefined
});
First of all thank you for writing this nice client
Now, coming to my query. I"m trying to create a new project using admin api-token for a user.
new_project = {
user_id : 22
, name: job.data.name
, description: "ishir user project"
, issues_enabled: false
, merge_requests_enabled: false
, wiki_enabled: false
, snippets_enabled: false
, public: false
,
}
gitlab.projects.create( new_project, function( result){
logger.debug( result);
})
Code does create a new project but for different user not the one specified in option(i.e 22).
It always choose user_id of admin user (whose token is used to make request). :(
Any help here would be great.
Needs to be implemented as far as I can see.
https://github.com/gitlabhq/gitlabhq/tree/master/doc/api#sudo
Maybe I can come up with a PR if I find the time to dive into coffeescript
Can we setup examples that lists all users, groups, repos, etc.
add: (projectId, sourceBranch, targetBranch, assigneeId, title, fn = null) =>
@debug "Projects::addMergeRequest()"
params =
id: Utils.parseProjectId projectId
source_branch: sourceBranch
target_branch: targetBranch
assignee_id: parseInt assigneeId
title: title
@post "projects/#{Utils.parseProjectId projectId}/merge_requests", params, (data) => fn data if fn
According to Gitlab API doc:
Parameters:
assignee_id should be optional. But passing a undefined into parseInt
returns NaN, which would be a wrong parameter to call the API.
I just ran into a problem where stuff was failing for inexplicable reasons, until I turned on DEBUG.
Absent any documentation to the contrary, I had assumed the url
property was meant to be the API endpoint for my GitLab installation:
var gl = require('gitlab')({
url: 'https://gitlab.mydomain.com/api/v3',
token: '12341234'
})
After scratching my head, I realized that /api/v3
was being appended to the url for me, so the fix was simple.
It'd be nice if a short note could be put in the README just clarifying this -- would probably save some people some confusion in future ๐
We're considering the following for a 2.0 refactor that will break backwards compatibility:
function (err, result)
.options
parameter, rather than mixing up what parameters they take. See #72 for more details.We'd like to get community thoughts on this refactor. We're considering maintaining a 1.x branch for a while to address any outstanding critical issues.
Are there any plans for adding milestones api? (List project milestones, Get single milestone,
ny plans for adding milestones api? (List project milestones, Get single milestone, Create new milestone, Edit milestone)
With jdalrymple/gitbeaker@0a1e5b4 I performed a merge commit rather than rebasing first. Now we have a messy git history.
Ideally I would reset to the last good commit jdalrymple/gitbeaker@4ebbde8 and do a force push but that can be bad in collaborative environment.
@moul How much do we care about clean git history? Worth a force push to clean up?
When I try following the startup example, my callback is never called at all when trying to list the users. First, it would be useful for there to be an error object like most node callbacks have. Second, b/c I'm behind a proxy I tend to assume that it's at fault when things like this go wrong. I tried setting the proxy by doing this:
var gitlab = new Gitlab({
url: 'https://mydomain.com/',
token: 'my user token',
request_opts : { proxy : process.env.HTTPS_PROXY}
});
based on what I read in your code.
However, as I said the callback is never called and after some amount of time I get an error that looks like this:
TypeError: Cannot read property 'statusCode' of undefined
at Request.handle [as _callback] (/Users/me/workspace/gitlab-proxy/node_modules/gitlab/node_modules/slumber/lib/API.js:175:38)
at self.callback (/Users/me/workspace/gitlab-proxy/node_modules/gitlab/node_modules/slumber/node_modules/request/request.js:122:22)
at Request.EventEmitter.emit (events.js:95:17)
at ClientRequest.self.clientErrorHandler (/Users/me/workspace/gitlab-proxy/node_modules/gitlab/node_modules/slumber/node_modules/request/request.js:231:10)
at ClientRequest.EventEmitter.emit (events.js:95:17)
at CleartextStream.socketErrorListener (http.js:1547:9)
at CleartextStream.EventEmitter.emit (events.js:95:17)
at Socket.onerror (tls.js:1445:17)
at Socket.EventEmitter.emit (events.js:117:20)
at net.js:441:14
That, because it's uncaught crashes the app.
Any advice?
I like what you guys are doing with this project. The lack of an API module for Node is a drag. I wish I could contribute, but i don't enjoy writing CoffeeScript. Are there any plans in the future to progress with pure javascript?
I could not find the API document for your wrapper. Is it elsewhere or not provided?
It's difficult to guess what API is corresponding to what.
Gitlab supports finding projects by /projects/{path_with_namespace}. Right now using the project we may try to use seach, but that will give all the project forks also.
Sometimes it is asked to pass either id or object as parameter.
For example when you call:
// it works
projects.show(idProject, cb)
// it doesn't work
project.all(idProject, cb)
To keep the example of the 'all' function, you must pass as parameter an object which look like that :
{
id: idProject
}
It could be simplified by apply the same prototypes everywhere. I will do a pull request to try to correct that.
Is there anything that is currently missing from GitLab API that could be developed out further?
For reference, GitLab API Docs here: http://demo.gitlab.com/help/api/README
I don't know coffeescript, but when I look around, it doesn't look like the api to query build status has been implemented. I want this functionality, and I'm willing to implement it, but I don't want to reinvent the wheel
I would like to know why Issues.all() function recursively calls api ?
I am not sure how to get commits from gitlab via node-gitlab?
Some time gitlab return 400 error( try to access unauthorised project ), why gitlab-node throw a error directly, this will cause a asynchronies uncaught exception, why not return the error via callback?
ApiBaseHTTP.prototype.fn_wrapper = function(fn) {
return (function(_this) {
return function(err, response, ret) {
var arity, ref;
if (err) {
debug('an error has occured', err);
if ((400 <= (ref = err.statusCode) && ref <= 499)) {
throw "Authorisation error. " + err.statusCode + ". Check your key.";
}
}
arity = fn.length;
switch (arity) {
case 1:
return fn(ret);
case 2:
return fn(err, ret || JSON.parse(response.body).message);
case 3:
return fn(err, response, ret);
}
};
Exceptions can be thrown and caught with a try-catch-block for synchronous call. For asynchronous methods, that except a callback, errors must not be thrown, but returned as first parameter of the callback. See http://stackoverflow.com/questions/7310521/node-js-best-practice-exception-handling.
The ApiBaseHTTP.js file throws an exception from a callback which cannot be detected. https://github.com/node-gitlab/node-gitlab/blob/develop/lib/ApiBaseHTTP.js#L77-79
Here is a simple example
try {
gitlab.projects.repository.showFile(1, {
ref: "master",
file_path: "nonExistingFile"
}, function(file, err) {
console.log(arguments);
// callback won't be invoked
});
} catch (e) {
// exception cannot be caught here
}
The only way to detect the exception is
process.on('uncaughtException', function(err) {
logger.fatal(err);
});
but, here the scope of e.g. a request/response function is not available.
All asynchronous errors must be passed to a callback instead of being thrown, otherwise the library is kind of not usable.
There are no .js files present in the distribution as fetched from npm.
$ cd examples
$ node list-projects
ApiV2> ApiBase::handleOptions()
ApiV2> ApiBaseHTTP::handleOptions()
ApiV2> ApiV2::handleOptions()
ApiV2> ApiBase::init()
module.js:340
throw err;
^
Error: Cannot find module './ProjectIssues'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Projects.module.exports.exports.load (/Users/glavin/Documents/Project Dev/node-gitlab/lib/Models/BaseModel.js:14:14)
at Projects.load (/Users/glavin/Documents/Project Dev/node-gitlab/lib/Models/BaseModel.js:3:63)
at Projects.init (/Users/glavin/Documents/Project Dev/node-gitlab/lib/Models/Projects.js:30:33)
at Projects.init (/Users/glavin/Documents/Project Dev/node-gitlab/lib/Models/Projects.js:4:61)
at Projects.module.exports.exports._init (/Users/glavin/Documents/Project Dev/node-gitlab/lib/Models/BaseModel.js:24:21)
at Projects._init (/Users/glavin/Documents/Project Dev/node-gitlab/lib/Models/BaseModel.js:3:63)
It appears that these files may have been created in comit 7f67cb4 however were not pushed (?). Hopefully this is an easy fix ๐.
I would like to help develop this a little further. I have never used Coffee Script before, so I will learn that first. Is there anything that is yet to be added for support on this?
Thanks for creating this project! I hope it continues to improve and be used.
I noticed that the debug
package is used by this node module. Can I enable debugging from my own Node.js code while I'm using this module? If so, how?
Pretty sure Travis errors like https://travis-ci.org/moul/node-gitlab/jobs/17053520 are due to trying to connect to the GitLab demo environment and it timing out.
Ideally we would use fixtures rather than actually connecting to a GitLab instance.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.