Skip to content

Commit 8707866

Browse files
committed
fix: convert Copr project name into cached property
And also make it abstract property at the same time. Signed-off-by: Matej Focko <[email protected]>
1 parent 75002bb commit 8707866

File tree

3 files changed

+20
-25
lines changed

3 files changed

+20
-25
lines changed

src/validation/testcase/base.py

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,6 @@ def __init__(
4646
self._build = None
4747
self._statuses: list[GithubCheckRun] | list[CommitFlag] = []
4848

49-
@property
50-
def copr_project_name(self):
51-
"""
52-
Get the name of Copr project from id of the PR.
53-
54-
Returns:
55-
Copr project name.
56-
"""
57-
if self.pr and not self._copr_project_name:
58-
self._copr_project_name = self.construct_copr_project_name()
59-
return self._copr_project_name
60-
6149
async def run_test(self):
6250
"""
6351
Run all checks, if there is any failure message, send it to Sentry and in case of
@@ -379,7 +367,14 @@ async def watch_statuses(self):
379367
@abstractmethod
380368
def account_name(self):
381369
"""
382-
Get the name of the (bot) account in GitHub/GitLab.
370+
Name of the (bot) account in GitHub/GitLab.
371+
"""
372+
373+
@property
374+
@abstractmethod
375+
def copr_project_name(self):
376+
"""
377+
Name of Copr project from id of the PR.
383378
"""
384379

385380
@abstractmethod
@@ -418,12 +413,6 @@ def update_file_and_commit(self, path: str, commit_msg: str, content: str, branc
418413
Update a file via API (creates new commit).
419414
"""
420415

421-
@abstractmethod
422-
def construct_copr_project_name(self) -> str:
423-
"""
424-
Construct the Copr project name for the PR to check.
425-
"""
426-
427416
@abstractmethod
428417
def get_status_name(self, status: Union[GithubCheckRun, CommitFlag]) -> str:
429418
"""

src/validation/testcase/github.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#
33
# SPDX-License-Identifier: MIT
44

5+
from functools import cached_property
6+
57
from github import InputGitAuthor
68
from github.Commit import Commit
79
from ogr.services.github import GithubProject
@@ -22,12 +24,13 @@ class GithubTestcase(Testcase):
2224
def account_name(self):
2325
return self.deployment.github_bot_name
2426

27+
@cached_property
28+
def copr_project_name(self) -> str:
29+
return f"packit-hello-world-{self.pr.id}"
30+
2531
def get_status_name(self, status: GithubCheckRun) -> str:
2632
return status.name
2733

28-
def construct_copr_project_name(self) -> str:
29-
return f"packit-hello-world-{self.pr.id}"
30-
3134
def create_empty_commit(self, branch: str, commit_msg: str) -> str:
3235
contents = self.project.github_repo.get_contents("test.txt", ref=branch)
3336
# https://pygithub.readthedocs.io/en/latest/examples/Repository.html#update-a-file-in-the-repository

src/validation/testcase/gitlab.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#
33
# SPDX-License-Identifier: MIT
44

5+
from functools import cached_property
6+
57
from gitlab import GitlabGetError
68
from ogr.abstract import CommitFlag, CommitStatus
79
from ogr.services.gitlab import GitlabProject
@@ -16,12 +18,13 @@ class GitlabTestcase(Testcase):
1618
def account_name(self):
1719
return self.deployment.gitlab_account_name
1820

21+
@cached_property
22+
def copr_project_name(self) -> str:
23+
return f"{self.project.service.hostname}-{self.project.namespace}-hello-world-{self.pr.id}"
24+
1925
def get_status_name(self, status: CommitFlag) -> str:
2026
return status.context
2127

22-
def construct_copr_project_name(self) -> str:
23-
return f"{self.project.service.hostname}-{self.project.namespace}-hello-world-{self.pr.id}"
24-
2528
def create_file_in_new_branch(self, branch: str):
2629
self.pr_branch_ref = self.project.gitlab_repo.branches.create(
2730
{"branch": branch, "ref": "master"},

0 commit comments

Comments
 (0)