Ian Wienand 2d9c8b620f gitea: set custom avatars for orgs
Over a few upgrades, we've managed to break some of the default avatar
logos you see when browsing code on opendev.org.

After investigating ways to fix this up, we established that there
isn't an exposed API for setting these, but we can do a simple query
to point to logo files on disk.  This implements that.

One caveat is that the logos should be PNG files; particiularly we
note that SVG files don't work reliably because they don't get served
with the image/svg+xml mime-type.

Change-Id: Ie6799de2fb27e09f936c488258dc1bd1c638c370
2022-03-18 11:06:09 +11:00

49 lines
1.5 KiB
YAML

- 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 }}'