diff --git a/playbooks/roles/gitea-git-repos/library/gitea_create_repos.py b/playbooks/roles/gitea-git-repos/library/gitea_create_repos.py index c323538eb5..3936a442bc 100755 --- a/playbooks/roles/gitea-git-repos/library/gitea_create_repos.py +++ b/playbooks/roles/gitea-git-repos/library/gitea_create_repos.py @@ -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, diff --git a/playbooks/test-gitea.yaml b/playbooks/test-gitea.yaml index 54e48b1aea..3d496f6b0c 100644 --- a/playbooks/test-gitea.yaml +++ b/playbooks/test-gitea.yaml @@ -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' diff --git a/playbooks/test-update-zuul-description.yaml b/playbooks/test-update-zuul-description.yaml new file mode 100644 index 0000000000..b5c4ee95cf --- /dev/null +++ b/playbooks/test-update-zuul-description.yaml @@ -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" diff --git a/zuul.d/system-config-run.yaml b/zuul.d/system-config-run.yaml index 8cb8205b5b..78112673f0 100644 --- a/zuul.d/system-config-run.yaml +++ b/zuul.d/system-config-run.yaml @@ -507,8 +507,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: