Merge "Update gitea project descriptions"

This commit is contained in:
Zuul 2020-09-25 16:08:20 +00:00 committed by Gerrit Code Review
commit 56103264ad
4 changed files with 40 additions and 1 deletions

View File

@ -83,6 +83,9 @@ class Gitea(object):
gitea_data = self.get(endpoint, *args, params=params, **kwargs).json()
return results
def patch(self, endpoint, *args, **kwargs):
return self.request('PATCH', endpoint, *args, **kwargs)
def post(self, endpoint, *args, **kwargs):
return self.request('POST', endpoint, *args, **kwargs)
@ -200,6 +203,20 @@ class Gitea(object):
time.sleep(3)
raise Exception("Could not update branch settings")
def update_gitea_project_description(self, project, csrf_token):
org, repo = project['project'].split('/', 1)
description = project.get('description', '')[:255]
if description:
description_update = {
'description': description,
}
resp = self.patch(
'/api/v1/repos/{org}/{repo}'.format(org=org, repo=repo),
json=description_update)
# Commented out as there is no good way to log only those projects
# which have an updated description and as a result this is noisy.
#self.log("Set description for:", project['project'])
def make_projects(self, projects, gitea_repos, csrf_token,
settings_thread_pool, branches_thread_pool, futures):
for project in projects:
@ -219,6 +236,12 @@ class Gitea(object):
# TODO: use threadpool when we're running with
# https://github.com/go-gitea/gitea/pull/7493
self.make_gitea_project(project, csrf_token)
else:
# We don't need to create it but lets update descriptions
# since humans like that.
futures.append(settings_thread_pool.submit(
self.update_gitea_project_description,
project, csrf_token))
if create or self.always_update:
futures.append(settings_thread_pool.submit(
self.update_gitea_project_settings,

View File

@ -10,3 +10,9 @@
url: "https://localhost:3000/zuul/zuul"
validate_certs: false
status_code: 200
return_content: yes
register: zuul_content
- name: Assert description updated
fail:
msg: Zuul description was not updated
when: '"Zuuls new description" not in zuul_content.content'

View File

@ -0,0 +1,7 @@
- hosts: "bridge.openstack.org:!disabled"
tasks:
- name: Modify Zuuls description
lineinfile:
path: "{{ project_config_src }}/gerrit/projects.yaml"
regexp: "^ description: The Gatekeeper, or a project gating system"
line: " description: Zuuls new description"

View File

@ -515,8 +515,11 @@
- playbooks/service-gitea-lb.yaml
- playbooks/service-gitea.yaml
- playbooks/manage-projects.yaml
- playbooks/test-update-zuul-description.yaml
# Run twice to ensure that we noop properly when
# all projects are created in gitea.
# all projects are created in gitea. We also update
# zuul's description to ensure that descriptions are
# updated
- playbooks/manage-projects.yaml
run_test_playbook: playbooks/test-gitea.yaml
host-vars: