From 0d36fac5fe0c7900f6cfefe4229c0a91b92c49a7 Mon Sep 17 00:00:00 2001 From: Clark Boylan Date: Tue, 3 Aug 2021 08:47:16 -0700 Subject: [PATCH] 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 --- playbooks/gitea-rename-tasks.yaml | 23 +++++++++-------------- playbooks/rename_repos.yaml | 11 ----------- 2 files changed, 9 insertions(+), 25 deletions(-) diff --git a/playbooks/gitea-rename-tasks.yaml b/playbooks/gitea-rename-tasks.yaml index 9520894cdc..72f0af40ef 100644 --- a/playbooks/gitea-rename-tasks.yaml +++ b/playbooks/gitea-rename-tasks.yaml @@ -36,33 +36,28 @@ - name: "Transfer repo ownership from {{ oldorg }}/{{ oldproj }} to {{ neworg }}/{{ oldproj }}" when: "oldorg != neworg" uri: - url: "{{ gitea_url }}/{{ oldorg }}/{{ oldproj }}/settings" + url: "{{ gitea_url }}/api/v1/repos/{{ oldorg }}/{{ oldproj }}/transfer" validate_certs: false user: root password: "{{ gitea_root_password }}" force_basic_auth: true - status_code: 302 + status_code: 202 method: POST - body_format: form-urlencoded + body_format: json body: - _csrf: "{{ gitea_token }}" - action: transfer - repo_name: "{{ oldproj }}" - new_owner_name: "{{ neworg }}" + new_owner: "{{ neworg }}" - name: "Update repo name from {{ neworg }}/{{ oldproj }} to {{ neworg }}/{{ newproj }}" when: "oldproj != newproj" uri: - url: "{{ gitea_url }}/{{ neworg }}/{{ oldproj }}/settings" + url: "{{ gitea_url }}/api/v1/repos/{{ neworg }}/{{ oldproj }}" validate_certs: false user: root password: "{{ gitea_root_password }}" force_basic_auth: true - status_code: 302 - method: POST - body_format: form-urlencoded + status_code: 200 + method: PATCH + body_format: json body: - _csrf: "{{ gitea_token }}" - action: update - repo_name: "{{ newproj }}" + name: "{{ newproj }}" description: "{{ gitea_repo.json.description }}" website: "{{ gitea_repo.json.website }}" diff --git a/playbooks/rename_repos.yaml b/playbooks/rename_repos.yaml index d517451a0f..93c4bd2c73 100644 --- a/playbooks/rename_repos.yaml +++ b/playbooks/rename_repos.yaml @@ -33,17 +33,6 @@ gitea_url: https://localhost:3000 tasks: - include_vars: "{{ repolist }}" - - 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 }}"