Skip to content

Commit

Permalink
Make copr project creation more robust
Browse files Browse the repository at this point in the history
There was a regression in copr (https://pagure.io/copr/copr/issue/1922)
which caused the error message received when a repository already exists
to change. Rather than checking the error message and ignoring it, check
in advance if the project exists and only try to create a new one if it
does not.

Signed-off-by: František Nečas <fnecas@redhat.com>
  • Loading branch information
František Nečas authored and FrNecas committed Sep 27, 2021
1 parent cec2517 commit c1b0c2d
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions rebasehelper/helpers/copr_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
from typing import cast

import pyquery # type: ignore
from copr.v3 import Client, CoprConfigException, CoprNoConfigException, CoprRequestException # type: ignore
from copr.v3 import ( # type: ignore
Client, CoprConfigException, CoprNoConfigException, CoprRequestException, CoprNoResultException)


from rebasehelper.exceptions import RebaseHelperError
from rebasehelper.helpers.download_helper import DownloadHelper
Expand All @@ -55,24 +57,23 @@ def get_client(cls):
@classmethod
def create_project(cls, client, project, chroots, description, instructions, permanent=False, hide=True):
try:
client.project_proxy.add(ownername=client.config.get('username'),
projectname=project,
chroots=chroots,
delete_after_days=None if permanent else cls.DELETE_PROJECT_AFTER,
unlisted_on_hp=hide,
description=description,
instructions=instructions)
except CoprRequestException as e:
error = e.result.error
client.project_proxy.get(ownername=client.config.get('username'), projectname=project)
# Project found, reuse it
except CoprNoResultException:
try:
[[error]] = error.values()
except AttributeError:
pass

if error.startswith('You already have project named'):
# reuse existing project
pass
else:
client.project_proxy.add(ownername=client.config.get('username'),
projectname=project,
chroots=chroots,
delete_after_days=None if permanent else cls.DELETE_PROJECT_AFTER,
unlisted_on_hp=hide,
description=description,
instructions=instructions)
except CoprRequestException as e:
error = e.result.error
try:
[[error]] = error.values()
except AttributeError:
pass
raise RebaseHelperError('Failed to create copr project. Reason: {}'.format(error)) from e

@classmethod
Expand Down

0 comments on commit c1b0c2d

Please sign in to comment.