Code Monkey home page Code Monkey logo

Comments (5)

zivni avatar zivni commented on September 1, 2024

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.

konsumer avatar konsumer commented on September 1, 2024

ah, nope. thanks!

from gitlab.

kristianmandrup avatar kristianmandrup commented on September 1, 2024

Sweet :)

from gitlab.

kristianmandrup avatar kristianmandrup commented on September 1, 2024

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

my fork

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.

kristianmandrup avatar kristianmandrup commented on September 1, 2024

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)

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.