Giter Club home page Giter Club logo

node-gitlab's Introduction

node-gitlab's People

Contributors

aheber avatar cmbankester avatar dave-irvine avatar glavin001 avatar hereandnow avatar hessph avatar huhgawz avatar jjimenezlopez avatar ksopyla avatar luispmiranda avatar luoqpolyvi avatar marcus-darden avatar maxcnunes avatar mdsb100 avatar mkkalinowski avatar moul avatar mrawdon avatar nalabjp avatar nogs avatar pavelpower avatar peteward44 avatar pgorecki avatar sakp avatar sennav avatar spruce avatar steve-norman-rft avatar vagh27 avatar varunkumar avatar vvvsrx avatar walac avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-gitlab's Issues

diffCommit api doesn't work as expect

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'?

Use headers instead of query string for private token

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 ?= {}

  • opts.__query.private_token = @options.token
  • opts.headers = { 'PRIVATE-TOKEN': @options.token }
    return opts

Should we parse the output of the API?

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?

Interface is not suitable

One

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

Two

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

There are many interfaces is not suitable, I think. Please check all of interfaces. Keep the same code style, at least.

accessLevel is undefined

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

Fork api missing.

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

.js examples on README do not work

All of the .js examples on the README, cause errors.

Problems:

  • extra ) in the handler for gitlab.users.all()
    • user is undefined inside same handler
    • throws error see #1 below
  • .project is undefined inside handler for gitlab.projects.all()

Error thrown for 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)

Error thrown for 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)

Entire 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);
  }
});

master & develop branches out of sync

@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.

Why #{parseInt groupId} ?

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?

Project Hooks unable to configure hooked events

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.

Project search endpoint?

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

Just moved to dedicated `node-gitlab` organization

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

  • README.md
  • package.json
  • Travis-CI service
  • SourceGraph service
  • npmjs.org package (need a new release)

can't create gitlab instance

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

Some method of discussing project?

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 :)

How do I get errors passed back to my callbacks?

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.

Roadmap?

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! :)

Handle Unauthorized Error

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
  });

create project for user

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.

Wrong implementation in merge_requests add

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:

  • 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)
  • labels (optional) - Labels for MR as a comma-separated list

assignee_id should be optional. But passing a undefined into parseInt returns NaN, which would be a wrong parameter to call the API.

`url` property clarification...

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 ๐Ÿ˜‰

node-gitlab 2.0 refactor

We're considering the following for a 2.0 refactor that will break backwards compatibility:

  • Deep refactoring of library structure to use dependency injection.
  • All library calls can return Promises, or take a callback argument.
  • In the case of a callback argument, the callback should follow the node.js convention of function (err, result).
  • All functions will take options parameter, rather than mixing up what parameters they take. See #72 for more details.
  • On successful API calls, we will parse the JSON response and return class Instances to the Promise or callback. See #65 for a more detailed explanation.

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.

Milestones

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)

How do I set a proxy?

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?

Unable to contribute

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?

API document request

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.

Id or object parameter

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 the builds api implemented?

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

Assuming projectId is numeric

Wherever we use projectId we assume it's numeric. It can actually be a namespace.

I've got a commit ready to go for this, just need to wait for #21 and #22 to land so I can rebase.

Why throw 400 error directly?

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 are thrown winthin callback - cannot be caught

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.

Missing Models

Missing Modules/Models:

  • Issues
  • ProjectIssues

How to reproduce:

$ 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)

Further Observations

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.

how do I enable debugging?

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.