Update gitea project descriptions

When we decide we don't need to create a project we set the project
description. The reason for this is that humans like to see their
project descriptions update when they change them.

Rather than get, compare, and set the descrition we just set it under
the assumption this will be fewer requests and thus quicker. The impact
on the db likely plays into this too but our gitea dbs are mostly idle
so should be fine.

Change-Id: I04bdd747f8934d0b35bf76aec5d70be01b921285
changes/64/753464/5
Clark Boylan 2 years ago
parent 6fc894b26b
commit fe097e52a3
  1. 23
      playbooks/roles/gitea-git-repos/library/gitea_create_repos.py
  2. 6
      playbooks/test-gitea.yaml
  3. 7
      playbooks/test-update-zuul-description.yaml
  4. 5
      zuul.d/system-config-run.yaml

@ -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,

@ -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'

@ -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"

@ -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:

Loading…
Cancel
Save