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
This commit is contained in:
Clark Boylan 2020-09-22 16:11:14 -07:00
parent 6fc894b26b
commit fe097e52a3
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() gitea_data = self.get(endpoint, *args, params=params, **kwargs).json()
return results return results
def patch(self, endpoint, *args, **kwargs):
return self.request('PATCH', endpoint, *args, **kwargs)
def post(self, endpoint, *args, **kwargs): def post(self, endpoint, *args, **kwargs):
return self.request('POST', endpoint, *args, **kwargs) return self.request('POST', endpoint, *args, **kwargs)
@ -200,6 +203,20 @@ class Gitea(object):
time.sleep(3) time.sleep(3)
raise Exception("Could not update branch settings") 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, def make_projects(self, projects, gitea_repos, csrf_token,
settings_thread_pool, branches_thread_pool, futures): settings_thread_pool, branches_thread_pool, futures):
for project in projects: for project in projects:
@ -219,6 +236,12 @@ class Gitea(object):
# TODO: use threadpool when we're running with # TODO: use threadpool when we're running with
# https://github.com/go-gitea/gitea/pull/7493 # https://github.com/go-gitea/gitea/pull/7493
self.make_gitea_project(project, csrf_token) 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: if create or self.always_update:
futures.append(settings_thread_pool.submit( futures.append(settings_thread_pool.submit(
self.update_gitea_project_settings, self.update_gitea_project_settings,

View File

@ -10,3 +10,9 @@
url: "https://localhost:3000/zuul/zuul" url: "https://localhost:3000/zuul/zuul"
validate_certs: false validate_certs: false
status_code: 200 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

@ -507,8 +507,11 @@
- playbooks/service-gitea-lb.yaml - playbooks/service-gitea-lb.yaml
- playbooks/service-gitea.yaml - playbooks/service-gitea.yaml
- playbooks/manage-projects.yaml - playbooks/manage-projects.yaml
- playbooks/test-update-zuul-description.yaml
# Run twice to ensure that we noop properly when # 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 - playbooks/manage-projects.yaml
run_test_playbook: playbooks/test-gitea.yaml run_test_playbook: playbooks/test-gitea.yaml
host-vars: host-vars: