Skip to content

Instantly share code, notes, and snippets.

@Artistan
Last active January 8, 2021 11:41
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save Artistan/2ef25b25655360c4e1c06e2d59f62178 to your computer and use it in GitHub Desktop.
Save Artistan/2ef25b25655360c4e1c06e2d59f62178 to your computer and use it in GitHub Desktop.
Add gitlab labels to your repo from admin labels

in addition to @Xunnamius package. you may use the dbconsole if your are feeling brave and want to check and update just the labels that are off in color or case. Also, I deleted only the labels that did not exist in the admin labels, and then ren teh gitlab-fix-labels ... add all to add the missing labels to all our projects.

login to your server

sudo gitlab-rails dbconsole

template (admin) labels.

check the current admin level labels...

select  t.title as template_title, t.color as template_color
from labels as t
 where t.template='t'
 ORDER BY template_title;

check how many labels on repos are different

select p.title, t.title as template_title, p.color, t.color as template_color
from labels as t INNER JOIN labels as p ON 1=1
 where p.title ILIKE t.title AND t.template='t' AND p.template='f'
 AND ( t.title != p.title OR t.color NOT ILIKE p.color )
 ORDER BY template_title;

update similar titles from the template (admin) labels.

UPDATE labels AS p
SET title = t.title, color = t.color
from labels as t
 where p.title ILIKE t.title AND t.template='t' AND p.template='f'
 AND ( t.title != p.title OR t.color NOT ILIKE p.color );

check for labels that do not conform to the templates

select p.title
from labels p
 where p.template='f' AND p.title NOT IN (
     select t.title from labels as t where t.template='t'
 );

NOT USED labels

check for NOT USED labels that do not conform to the template (admin) labels.

select title
from labels as p
where p.template='f' AND p.title NOT IN (
    select t.title from labels as t where t.template='t'
) AND p.id NOT IN (
      select label_id from label_links
  );

DELETE NOT USED labels that do not conform to the template (admin) labels.

delete
from labels as p
 where p.template='f' AND p.title NOT IN (
     select t.title from labels as t where t.template='t'
 ) AND p.id NOT IN (
       select label_id from label_links
   );

ADD labels that do not yet exist.

https://www.npmjs.com/package/gitlab-fix-labels

npm install -g gitlab-fix-labels
# mac os x symlink...
ln -s /usr/local/bin/node /usr/local/bin/nodejs
# add labels...
gitlab-fix-labels https://git.ddd.net/api/v3/ ###################### add all

related discussion

trickle down labels

I would like to reiterate that having the admin labels be global would be extremely beneficial. It would reduce the database size by a great deal.

basic nesting

groups (namespaces) and repositories (projects)

  • admin (global)
    • group A
      • repo A.1
      • repo A.2
      • sub-group A.A
        • repo A.A.1
        • repo A.A.2
      • subgroup A.B
        • repo A.A.1
        • repo A.A.2

access labels from above (trickle down)

Repo A.A.2 would have all it's own labels plus labels from

  • subgroup A.B,
  • group A
  • admin

interface

  • adding labels to repo A.A.2 would default option to "self"
  • additional options depend on access rights of user
    • add to subgroup A.A
    • add to group A
    • add to admin
    • lock option, if admin, allow to lock to that

why?

this would greatly diminish the size of the database for large implementations of gitlabs!

Project Group Links

  • project_group_links.project_id
  • project_group_links.group_id

Namespaces

a.k.a. groups.... (not confusing at all... LOL)

  • namespaces.id
  • namespaces.parent_id

Labels

  • labels.group_id
  • labels.id
  • labels.project_id
  • labels.type (ProjectLabel,'')

Projects

  • projects.namespace_id

add

  • prevent labels from delete if ...
  • any board is using it, add_foreign_key "lists", "labels", name: "fk_7a5553d60f", on_delete: :restrict
  • add a locking mechanism to the labels to prevent duplication below that level
  • labels.lock (boolean)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment