ruby-on-railsgitlabgitlab-apigitlab-omnibus

how to create a project using gitlab-rails console?


I try to create a gitlab project using gitlab-rails console but i did not find how to do that.

I found how to create a user :

u = User.new(username: 'name', email: 'name@example.com', name: 'Name name', password: 'password1234', password_confirmation: 'password1234', admin: true)
u.skip_confirmation!
u.save! 

But does someone know how to create project ? Or best where can i find a documentation about gitlab-rails objects ? Something like a javadoc would be helpfull ...

Sincerly


Solution

  • I did not find how to create a project using gitlab-rails console, but I found a solution:

    ruby script:

    u = User.new(username: 'aName', email: 'aName@example.com', name: 'aName lastName ', password: 'password', password_confirmation: 'passworx', admin: true)                                          
    u.skip_confirmation!
    u.save!
    token = u.personal_access_tokens.create(scopes: ['api','admin_mode'], name: 'install_token', expires_at: 365.days.from_now)
    token.set_token('abcd1234')
    token.save!
    

    API request to create the project:

    curl -k --request POST --header 'PRIVATE-TOKEN: abcd1234' --header 'Content-Type: application/json' --data  '{"name\": "aName", "description": "example","namespace": "name", "initialize_with_readme": "true"}' --url 'https://www.example.com/api/v4/projects/'