f8bb46d810
This tasks file was removed when we rewrote the gitea management into python. Unfortunately our gitea rename project tasks rely on this tasks file to create new orgs if they are needed to rename a project. Restore this file so that we can rename projects in this manner. Note we move it into playbooks/ and rename it to gitea-rename-setup-org.yaml to make it clear that the gitea management role doesn't use this set of tasks, only the gitea project rename playbook does. Change-Id: I782f6e56cad18bdcbf9504d51af15caa950a5752
69 lines
2.3 KiB
YAML
69 lines
2.3 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 }}/{{ oldorg }}/{{ oldproj }}/settings"
|
|
validate_certs: false
|
|
user: root
|
|
password: "{{ gitea_root_password }}"
|
|
force_basic_auth: true
|
|
status_code: 302
|
|
method: POST
|
|
body_format: form-urlencoded
|
|
body:
|
|
_csrf: "{{ gitea_token }}"
|
|
action: transfer
|
|
repo_name: "{{ oldproj }}"
|
|
new_owner_name: "{{ neworg }}"
|
|
- name: "Update repo name from {{ neworg }}/{{ oldproj }} to {{ neworg }}/{{ newproj }}"
|
|
when: "oldproj != newproj"
|
|
uri:
|
|
url: "{{ gitea_url }}/{{ neworg }}/{{ oldproj }}/settings"
|
|
validate_certs: false
|
|
user: root
|
|
password: "{{ gitea_root_password }}"
|
|
force_basic_auth: true
|
|
status_code: 302
|
|
method: POST
|
|
body_format: form-urlencoded
|
|
body:
|
|
_csrf: "{{ gitea_token }}"
|
|
action: update
|
|
repo_name: "{{ newproj }}"
|
|
description: "{{ gitea_repo.json.description }}"
|
|
website: "{{ gitea_repo.json.website }}"
|