177edc0abb
I ran our global gitea project sync playbook across all eight gitea hosts and one failed with a 404 against a specific project. Rerunning the playbook against that one gitea server worked fine. Until we sort out why this might happen lets retry our HTTP POSTs up to 3 times until they succeed. Some numbers: We have ~2k repos and 8 servers and make two http requests per repo for a total of 32k requests. If one fails out of that the success rate is very high so retrying a few times should be fine. Change-Id: I937a4f852f6713a419c03a17c3b4984a97eae0d8
99 lines
3.5 KiB
YAML
99 lines
3.5 KiB
YAML
- name: debug
|
|
debug:
|
|
msg: "{{ project }}"
|
|
- name: Parse project name
|
|
set_fact:
|
|
org: "{{ project.project | regex_replace('^(.*)/(.*)$', '\\1') }}"
|
|
repo: "{{ project.project | regex_replace('^(.*)/(.*)$', '\\2') }}"
|
|
- name: Create repo
|
|
when: project.project not in gitea_repos
|
|
uri:
|
|
url: "{{ gitea_url }}/api/v1/org/{{ org }}/repos"
|
|
user: root
|
|
password: "{{ gitea_root_password }}"
|
|
force_basic_auth: true
|
|
validate_certs: false
|
|
status_code: 201
|
|
method: POST
|
|
body_format: json
|
|
body:
|
|
auto_init: true
|
|
description: "{{ (project.description | default(''))[:255] }}"
|
|
name: "{{ repo }}"
|
|
private: false
|
|
readme: Default
|
|
register: create_repo_result
|
|
|
|
- name: Set storyboard tracker url
|
|
when: "'use-storyboard' in project and project['use-storyboard']"
|
|
set_fact:
|
|
external_tracker_url: "https://storyboard.openstack.org/#!/project/{{ org }}/{{ repo }}"
|
|
- name: Set storyboard tracker url format
|
|
when: "'use-storyboard' in project and project['use-storyboard']"
|
|
set_fact:
|
|
tracker_url_format: "https://storyboard.openstack.org/#!/story/{index}"
|
|
- name: Set launchpad tracker url
|
|
when: "('use-storyboard' not in project or not project['use-storyboard']) and ('groups' not in project or not project['groups'])"
|
|
set_fact:
|
|
external_tracker_url: "https://bugs.launchpad.net/{{ repo }}"
|
|
- name: Set launchpad tracker url format
|
|
when: "('use-storyboard' not in project or not project['use-storyboard']) and ('groups' not in project or not project['groups'])"
|
|
set_fact:
|
|
tracker_url_format: "https://bugs.launchpad.net/{{ repo }}/+bug/{index}"
|
|
- name: Set launchpad tracker url if group set
|
|
when: "('use-storyboard' not in project or not project['use-storyboard']) and ('groups' in project and project['groups'])"
|
|
set_fact:
|
|
external_tracker_url: "https://bugs.launchpad.net/{{ project.groups[0] }}"
|
|
- name: Set launchpad tracker url format if group set
|
|
when: "('use-storyboard' not in project or not project['use-storyboard']) and ('groups' in project and project['groups'])"
|
|
set_fact:
|
|
tracker_url_format: "https://bugs.launchpad.net/{{ project.groups[0] }}/+bug/{index}"
|
|
|
|
- name: Adjust repo settings
|
|
when: gitea_always_update or project.project not in gitea_repos
|
|
register: result
|
|
retries: 3
|
|
until: result is succeeded
|
|
delay: 5
|
|
uri:
|
|
url: "{{ gitea_url }}/{{ org }}/{{ repo }}/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: advanced
|
|
# enable_pulls is not provided, which disables it
|
|
# enable_wiki is not provided, which disables it
|
|
enable_external_wiki: false
|
|
external_wiki_url:
|
|
# enable_issues is on so that issue links work
|
|
enable_issues: on
|
|
enable_external_tracker: true
|
|
external_tracker_url: "{{ external_tracker_url }}"
|
|
tracker_url_format: "{{ tracker_url_format }}"
|
|
tracker_issue_style: numeric
|
|
- name: Set default branch
|
|
when: gitea_always_update or project.project not in gitea_repos
|
|
register: result
|
|
retries: 3
|
|
until: result is succeeded
|
|
delay: 5
|
|
uri:
|
|
url: "{{ gitea_url }}/{{ org }}/{{ repo }}/settings/branches"
|
|
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: default_branch
|
|
branch: master
|