moul / node-gitlab

DEPRECATED, see https://github.com/node-gitlab/node-gitlab
https://npmjs.org/package/gitlab
Other
470 stars 140 forks source link

Did not understand how to fetch branches for a project #187

Closed akarsh closed 7 years ago

akarsh commented 7 years ago

Hi,

Can you please provide some example on how to fetch branches for a project. I am trying but the console output is not giving me what i was looking. gitlab.projects.repository.listBranches(1)

Thank you

akarsh commented 7 years ago

I was able to solve the issue by creating a function getGitLabBranches

Here is the working code for this function

// Global variables
var storeProjectId; // Project Id
var storeBranches = [];  //Branches

 // Listing projects
gitlab.projects.all(function (projects) {
       var i, len, project;
            for (i = 0, len = projects.length; i < len; i++) {
                project = projects[i];
                storeProjectId = project.id;
                getGitLabBranches(storeProjectId);
                return storeProjectId;
            }
});
// Listing branches based on project id
        function getGitLabBranches(storeProjectId) {
            gitlab.projects.repository.listBranches(storeProjectId, function (branches) {
                for (var k = 0; k < branches.length; k++) {
                    obj = branches[k];
                    storeBranches.push(obj.name);
                }
            })
        }