system-config/playbooks/gitea-rename-tasks.yaml
Clark Boylan 0d36fac5fe Use the gitea api in the gitea renaming playbook
Previously we were hacking the gitea web ui to transfer repo ownership
and to rename repos within an org. We believe this was necessary because
there was no REST API ability to do this. Now we have the ability to do
this via the REST API and in addition a new Gitea release will break our
web ui hijacking.

Update the project renaming playbook to use the REST API as it is
simpler to use and should be more reliable over time as it is versioned.

Change-Id: Idd8326a4891df6bdd47422e2a73880aa053380f5
2021-08-03 08:47:16 -07:00

64 lines
2.1 KiB
YAML

# Note, if both the org and project names change, this script will
# perform the org transfer first, followed by the project name change.
# If there is already a project in the new org with the old name, it
# will fail.
- name: "Parse repo names for {{ repo.old }} -> {{ repo.new }}"
set_fact:
oldorg: "{{ repo.old.split('/')[0] }}"
neworg: "{{ repo.new.split('/')[0] }}"
oldproj: "{{ repo.old.split('/')[1] }}"
newproj: "{{ repo.new.split('/')[1] }}"
- name: Get Gitea org list
# We assume that all the orgs we are interested in are owned by root
uri:
url: "{{ gitea_url }}/api/v1/user/orgs"
user: root
password: "{{ gitea_root_password }}"
force_basic_auth: true
validate_certs: false
status_code: 200
register: gitea_org_list
- name: Parse Gitea org list
set_fact:
gitea_orgs: "{{ gitea_org_list.json | map(attribute='username') | list }}"
- name: "Make new gitea org"
include_tasks: gitea-rename-setup-org.yaml
vars:
org: "{{ neworg }}"
- name: "Get repo {{ oldorg }}/{{ oldproj }}"
uri:
url: "{{ gitea_url }}/api/v1/repos/{{ oldorg }}/{{ oldproj }}"
validate_certs: false
user: root
password: "{{ gitea_root_password }}"
force_basic_auth: true
register: gitea_repo
- name: "Transfer repo ownership from {{ oldorg }}/{{ oldproj }} to {{ neworg }}/{{ oldproj }}"
when: "oldorg != neworg"
uri:
url: "{{ gitea_url }}/api/v1/repos/{{ oldorg }}/{{ oldproj }}/transfer"
validate_certs: false
user: root
password: "{{ gitea_root_password }}"
force_basic_auth: true
status_code: 202
method: POST
body_format: json
body:
new_owner: "{{ neworg }}"
- name: "Update repo name from {{ neworg }}/{{ oldproj }} to {{ neworg }}/{{ newproj }}"
when: "oldproj != newproj"
uri:
url: "{{ gitea_url }}/api/v1/repos/{{ neworg }}/{{ oldproj }}"
validate_certs: false
user: root
password: "{{ gitea_root_password }}"
force_basic_auth: true
status_code: 200
method: PATCH
body_format: json
body:
name: "{{ newproj }}"
description: "{{ gitea_repo.json.description }}"
website: "{{ gitea_repo.json.website }}"