Add gitea to project rename playbook
Change-Id: Idca623ff59f3318c762ffd5c65e3c739fac819af Story: 2004627 Task: 29706
This commit is contained in:
parent
1a3bd75521
commit
7da7002dc1
51
playbooks/gitea-rename-tasks.yaml
Normal file
51
playbooks/gitea-rename-tasks.yaml
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
# 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 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 }}"
|
@ -34,6 +34,28 @@
|
|||||||
- [ '/var/lib/git/' ]
|
- [ '/var/lib/git/' ]
|
||||||
- "{{ repos }}"
|
- "{{ repos }}"
|
||||||
|
|
||||||
|
- hosts: gitea
|
||||||
|
gather_facts: False
|
||||||
|
vars:
|
||||||
|
gitea_url: http://localhost:3000
|
||||||
|
tasks:
|
||||||
|
- name: Get a CSRF token
|
||||||
|
uri:
|
||||||
|
url: "{{ gitea_url }}/"
|
||||||
|
validate_certs: false
|
||||||
|
user: root
|
||||||
|
password: "{{ gitea_root_password }}"
|
||||||
|
force_basic_auth: true
|
||||||
|
register: gitea_token
|
||||||
|
- name: Parse CSRF taken
|
||||||
|
set_fact:
|
||||||
|
gitea_token: "{{ gitea_token.cookies._csrf|regex_replace('%3D','=') }}"
|
||||||
|
- name: Move gitea repo
|
||||||
|
include_tasks: gitea-rename-tasks.yaml
|
||||||
|
loop: "{{ repos }}"
|
||||||
|
loop_control:
|
||||||
|
loop_var: repo
|
||||||
|
|
||||||
- hosts: storyboard.openstack.org
|
- hosts: storyboard.openstack.org
|
||||||
gather_facts: False
|
gather_facts: False
|
||||||
remote_user: root
|
remote_user: root
|
||||||
|
Loading…
Reference in New Issue
Block a user