Clark Boylan 0fe4c04172 Aggregate all gitea repos and check against them
We are currently attempting to create repos which already exist. This
fails.

The reason for this is we set the gitea_org_repos fact for each org
overriding the last org. This means only the last org processed has any
projects in this list. We then check against this list when creating
projects so that we only create projects if they aren't in the list.
Meaning any project for repos not in the last org attempts to get
recreated.

We can address this by keeping a global list of repos regardless of org
then checking against that.

An alternative solution would be to process projects for each org
separately. Or to have gitea give us the global list so we don't have to
build it ourselves.

Change-Id: Id9a480634918dad2160a4e040a41ce6226ae67d8
2019-03-01 20:49:30 -08:00

57 lines
1.7 KiB
YAML

- name: Process org
debug:
msg: "Processing org {{ org }}"
- name: Create org
when: org not in gitea_orgs
uri:
url: "{{ gitea_url }}/api/v1/admin/users/root/orgs"
user: root
password: "{{ gitea_root_password }}"
force_basic_auth: true
validate_certs: false
status_code: 201
method: POST
body_format: json
body:
username: "{{ org }}"
- name: Get org team list
uri:
url: "{{ gitea_url }}/api/v1/orgs/{{ org }}/teams"
user: root
password: "{{ gitea_root_password }}"
force_basic_auth: true
validate_certs: false
status_code: 200
register: gitea_org_team_list
- name: Get org owners
uri:
url: "{{ gitea_url }}/api/v1/teams/{{ (gitea_org_team_list.json | selectattr('name', 'equalto', 'Owners') | list)[0]['id'] }}/members"
user: root
password: "{{ gitea_root_password }}"
force_basic_auth: true
validate_certs: false
status_code: 200
register: gitea_org_members
- name: Add Gerrit user to org
when: "'gerrit' not in gitea_org_members.json | map(attribute='username')"
uri:
url: "{{ gitea_url }}/api/v1/teams/{{ (gitea_org_team_list.json | selectattr('name', 'equalto', 'Owners') | list)[0]['id'] }}/members/gerrit"
user: root
password: "{{ gitea_root_password }}"
force_basic_auth: true
validate_certs: false
status_code: 204
method: PUT
- name: Get org repo list
uri:
url: "{{ gitea_url }}/api/v1/orgs/{{ org }}/repos"
user: root
password: "{{ gitea_root_password }}"
force_basic_auth: true
validate_certs: false
status_code: 200
register: gitea_org_repo_list
- name: Parse org repo list
set_fact:
gitea_repos: "{{ gitea_org_repo_list.json | map(attribute='full_name') | list + gitea_repos | default([]) }}"