moul / node-gitlab

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

Problem creating Labels/Tags #151

Closed jacob418 closed 5 years ago

jacob418 commented 8 years ago

I tried to write a script to Transfer labels from one project to another. Reading the labels from the API works fine, but i cant recreate them.

The function returns true but the label is not created. Am i missing something?

here is my code:

var gitlab = require("gitlab")({
        url:        "http://gitlab.sense-it.gmbh" ,
        token:  "***secret***"
    }) ;

var listProjects = function(){
    gitlab.projects.all(function(result){
            if(Array.isArray(result)){
                console.log("ID\tNamespace/Name") ;
                console.log("**********************\n") ;
                for(var i = 0; i < result.length; i++){
                    console.log(result[i].id + "\t" + result[i].namespace.name + "/" + result[i].name) ;
                }
            }else{
                console.log(result.message + "\n") ;
            }
        }) ;
}

var transferLabels = function(projA, projB){
    gitlab.projects.labels.all(projA, {}, function(result){
            if(Array.isArray(result)){
                console.log("Transfering labels from " + projA + " to " + projB) ;
                console.log("**********************\n") ;
                for(var i = 0; i < result.length; i++){
                    var data = {
                                name: result[i].name ,
                                color: result[i].color ,
                                description: result[i].description
                            } ;

                    gitlab.labels.create(projB, data, function(response){
                                if(response){ // always TRUE even if nothing happend in GitLab
                                    console.log("...created label\n") ;
                                    //console.log("created label: \"" + data.name + "\" (" + data.color + "), description: \"" + data.description + "\"") ;
                                }else{
                                    console.log("...error creating label\n") ;
                                    //console.log("error creating label: \"" + data.name + "\" (" + data.color + "), description: \"" + data.description + "\"") ;
                                }
                        }) ;
                }
            }else{
                console.log(result.message + "\n") ;
            }
        }) ;
}

switch(process.argv[2]){
    case "listProjects":
        listProjects() ;
        break ;
    case "transferLabels":
        transferLabels(parseInt(process.argv[3]), parseInt(process.argv[4])) ;
        break ;
}
jdalrymple commented 7 years ago

Im getting the same result when i try creating a project :(