Friday, 11 October 2013

RubyMine GitLab Integration

I setup the community version of GitLab so I can have locally controlled projects.
Since I use RubyMine as my IDE, the integration with both github and gitlab was a bit convoluted.

First I couldn't get ssh to work, so I used http (since it was on my home network) to get the push/pull working.
(There are links to pages explaining how to fix that at the end of this post)

One you have GitLab running, you can create a project.
After doing that, you get to see a page with boxes telling you how to connect using git from the command line.

One thing to note is that there are two commands to set your `user.name` and `user.email`.
The key is that they use `--global` which is problematic.

So. Let's say you have created a project called `test`. Do this:

cd [your projects folder]
mkdir test
cd test
git init
git config --local user.name "YOUR_NAME"
git config --local user.email "YOUR_GITLAB_ACCOUNT_EMAIL"
git remote add origin [HTTP_URL_PROVIDED_BY_GITLAB]
touch README.md
git add README.md
git commit -m 'Initial'
git push -u origin master

You can have 'port' and 'groups' so the url could look like this:

http://gitlab.local:8080/home_projects/testing.git

Ok. What about task management integration?

Fiddly, but doable.

First, you have to use the GitLab API.
And for that you need your private key AND know the project number.

When you issue a curl request you get back JSON:

curl http://gitlab.local:8080/api/v3/projects/3/issues?private_token=YOUR_API_TOKEN
[
    {
        "id": 4,
        "project_id": 3,
        "title": "Some task",
        "description": "Some description",
        "labels": ["Enhancement"],
        "milestone": null,
        "assignee": {
            "id": 4,
            "username": "bill",
            "email": "bill@bill.com.au",
            "name": "Bill Bloggs",
            "state": "active",
            "created_at": "2013-10-10T22:59:26Z"
        },
        "author": {
            "id": 4,
            "username": "bill",
            "email": "bill@bill.com.au",
            "name": "Bill Bloggs",
            "state": "active",
            "created_at": "2013-10-10T22:59:26Z"
        },
        "state": "opened",
        "updated_at": "2013-10-11T01:07:50Z",
        "created_at": "2013-10-11T01:07:19Z"
    }
    ,
    {
        "id": 3,
        "project_id": 3,
        "title": "Another task",
        "description": "Another description",
        "labels": ["Bug"],
        "milestone": null,
        "assignee": {
            "id": 5,
            "username": "bill",
            "email": "bill@bill.com.au",
            "name": "Bill Bloggs",
            "state": "active",
            "created_at": "2013-10-10T23:00:19Z"
        },
        "author": {
            "id": 4,
            "username": "bill",
            "email": "bill@bill.com.au",
            "name": "Bill Bloggs",
            "state": "active",
            "created_at": "2013-10-10T22:59:26Z"
        },
        "state": "opened",
        "updated_at": "2013-10-11T01:07:59Z",
        "created_at": "2013-10-11T01:06:54Z"
    }
]

So how to get RubyMine to use this?

1. Open preferences -> tasks
2. Change 'Changelist name format' to {project}-#{number} {summary}

Under Servers, add a 'generic' server

In the general tab:

1. Change the server URL to http://YOUR_SERVER/YOUR_REPO_WITHOUT_DOT_GIT
2. Insert your username and password
3. Click 'Use HTTP Authentication'

Go to the gitlab server and under your account settings, there is an input box with your private key.

Copy it.

In the additional tab:

1. Add the URL: http://YOUR_SERVER/api/v3/projects/PROJECT_NUMBER/issues?private_token=YOUR_PRIVATE_KEY
2. Check the 'JSON' option
3. In the Task pattern insert: "id":({id}.?+),.+?,"title":"({summary}.+?)"

Hit test.

You should see 'Connection is successful'.

From now on you should be able to use the tasks drop down.

FYI When creating tasks in gitlab, there is an irritating anti-feature for assigning labels.
You have to type them in.
The set I use is:

Enhancement
Bug
New Feature
Quick Fix
Duplicate
Invalid
Question
No Fix
Documentation
Presentation

I still need to figure out how to have GitLab return the project name ala TestProject-#{number} {summary} format.

Off-topic: Go read
https://wiki.archlinux.org/index.php/Gitlab#Backup_and_restore
and https://github.com/gitlabhq/gitlab-recipes
and http://api.gitlab.org/
and https://github.com/gitlabhq/gitlab-public-wiki/wiki/Trouble-Shooting-Guide
and https://groups.google.com/forum/#!forum/gitlabhq

No comments:

Post a Comment