diff --git a/playbooks/roles/gitea-git-repos/tasks/main.yaml b/playbooks/roles/gitea-git-repos/tasks/main.yaml index a007f9017c..9d2fa7c541 100644 --- a/playbooks/roles/gitea-git-repos/tasks/main.yaml +++ b/playbooks/roles/gitea-git-repos/tasks/main.yaml @@ -6,3 +6,7 @@ # Lookup runs locally on the calling machine, so doesn't need # project-config remotely projects: "{{ lookup('file', project_config_src + '/gerrit/projects.yaml') | from_yaml }}" + +- name: Setup logos + include_role: + name: gitea-set-org-logos diff --git a/playbooks/roles/gitea-set-org-logos/README.rst b/playbooks/roles/gitea-set-org-logos/README.rst new file mode 100644 index 0000000000..74e7f8cf1b --- /dev/null +++ b/playbooks/roles/gitea-set-org-logos/README.rst @@ -0,0 +1,7 @@ +Set custom logos for organisations in gitea + +Note that logos should be a PNG file. We've standardised on a 400x400 +to keep it simple. + +Images should respect the limits set by gitea; see +``_ diff --git a/playbooks/roles/gitea-set-org-logos/files/airship.png b/playbooks/roles/gitea-set-org-logos/files/airship.png new file mode 100644 index 0000000000..1a8858a448 Binary files /dev/null and b/playbooks/roles/gitea-set-org-logos/files/airship.png differ diff --git a/playbooks/roles/gitea-set-org-logos/files/default.png b/playbooks/roles/gitea-set-org-logos/files/default.png new file mode 100644 index 0000000000..5ec6daec7c Binary files /dev/null and b/playbooks/roles/gitea-set-org-logos/files/default.png differ diff --git a/playbooks/roles/gitea-set-org-logos/files/opendev.png b/playbooks/roles/gitea-set-org-logos/files/opendev.png new file mode 100644 index 0000000000..bb9b57f26b Binary files /dev/null and b/playbooks/roles/gitea-set-org-logos/files/opendev.png differ diff --git a/playbooks/roles/gitea-set-org-logos/files/openstack.png b/playbooks/roles/gitea-set-org-logos/files/openstack.png new file mode 100644 index 0000000000..bf13b9f6fa Binary files /dev/null and b/playbooks/roles/gitea-set-org-logos/files/openstack.png differ diff --git a/playbooks/roles/gitea-set-org-logos/files/starlingx.png b/playbooks/roles/gitea-set-org-logos/files/starlingx.png new file mode 100644 index 0000000000..a2608d6c22 Binary files /dev/null and b/playbooks/roles/gitea-set-org-logos/files/starlingx.png differ diff --git a/playbooks/roles/gitea-set-org-logos/files/vexxhost.png b/playbooks/roles/gitea-set-org-logos/files/vexxhost.png new file mode 100644 index 0000000000..fd48be0ca7 Binary files /dev/null and b/playbooks/roles/gitea-set-org-logos/files/vexxhost.png differ diff --git a/playbooks/roles/gitea-set-org-logos/files/zuul.png b/playbooks/roles/gitea-set-org-logos/files/zuul.png new file mode 100644 index 0000000000..e6c2d58c12 Binary files /dev/null and b/playbooks/roles/gitea-set-org-logos/files/zuul.png differ diff --git a/playbooks/roles/gitea-set-org-logos/tasks/main.yaml b/playbooks/roles/gitea-set-org-logos/tasks/main.yaml new file mode 100644 index 0000000000..222e956eef --- /dev/null +++ b/playbooks/roles/gitea-set-org-logos/tasks/main.yaml @@ -0,0 +1,48 @@ +- name: Get list of orgs + uri: + url: 'https://localhost:3000/api/v1/orgs' + method: GET + user: root + password: '{{ gitea_root_password }}' + return_content: yes + validate_certs: false + status_code: 200 + body_format: json + register: _org_list_raw + no_log: True + +- name: Filter org list + set_fact: + _org_list: '{{ _org_list_raw.json | map(attribute="username") | list }}' + +- name: Copy org logos + copy: + src: '{{ lookup("first_found", _org_logos) }}' + dest: '/var/gitea/data/gitea/avatars/{{ item }}' + owner: 1000 + group: 1000 + mode: 0644 + vars: + _org_logos: + - '{{ item }}.png' + - 'default.png' + loop: '{{ _org_list }}' + register: _logos_updated + +- name: Get changed logos + set_fact: + _changed_logos: '{{ _logos_updated.results | selectattr("changed", "equalto", true) | map(attribute="item") | list }}' + +# NOTE(ianw) 2022-03-17 There is currently no API to update avatar +# logos with gitea, so we direct update for now. +# * orgs are just entries in the "users" table +# * the "avatar" field is a plain-text name of a file in +# /var/gitea/data/gitea/avatars +- name: Run update query + shell: >- + /usr/local/bin/docker-compose -f /etc/gitea-docker/docker-compose.yaml + exec mariadb bash -c 'mysql -uroot -p"$MYSQL_ROOT_PASSWORD" -e + "USE gitea; UPDATE user SET avatar = '\''{{ item }}'\'', use_custom_avatar = 1 WHERE name = '\''{{ item }}'\''"' + args: + executable: '/bin/bash' + loop: '{{ _changed_logos }}' diff --git a/testinfra/test_gitea.py b/testinfra/test_gitea.py index cd919bacf4..5e83a37878 100644 --- a/testinfra/test_gitea.py +++ b/testinfra/test_gitea.py @@ -93,7 +93,12 @@ def test_gitea_screenshots(host): ('https://localhost:3081/opendev/system-config', None, 'gitea-project-system-config.png'), ('https://localhost:3081/opendev/disk-image-builder', None, - 'gitea-project-dib.png') + 'gitea-project-dib.png'), + ('https://localhost:3081/opendev/', None, + 'gitea-org-opendev.png'), + ('https://localhost:3081/explore/organizations', None, + 'gitea-org-expore.png'), ) take_screenshots(host, shots) +