42 cards
View
Posted 6 months ago. Visible to the public.

GitLab: Rails Console Tasks

Sometimes you might need to do some task in GitLab which would be tedious if you'd have to do it via the Browser.

There is also an API which you could maybe use!

You can connect to the GitLab internal Rails with executing gitlab-rails console. It might be slow at times, especially if you use a lot of Tab for complex structures, so be aware of this.

The following code listings are expected to be entered inside the gitlab-rails console.

Remove GitLab Labels from already closed Issues

Copy
p = Project.find_by_id(1) labels_to_remove = [3, 4, 1, 84, 86] # Scheduled, Active, This Week, One Week, Two Weeks # for every issue p.issues.each do |issue| # we edit only closed issues if issue.closed? # remove our unwanted labels issue.label_ids -= labels_to_remove if issue.valid? # and save the issue issue.save end end end

Hint: The Issue ID we know is to be found as iid in GitLab.

First we need to find our project. In our case, this is the makandra-ops/puppet project, which as it happens, was the first project in this GitLab:

Copy
p = Project.first

Now we have a filter and we're able to see only issues that concern us. You can take a look in all supported methods of the issue Object without having to wait for tab completion by using this line:

Copy
i = p.issues.find_by_iid(4042) puts i.public_methods.sort

Maybe you want to save this list to be able to search for stuff in it.

Here we want to remove labels from issues they no longer need. These are the Labels Scheduled, Active, This Week, One Week, Two Weeks with the respective label ids 3, 4, 1, 84, 86 which leads to the above code snipped.

Owner of this card:

Avatar
Marius Schuller
Last edit:
6 months ago
by Marius Schuller
This website uses cookies to improve usability and analyze traffic.
Accept or learn more