Skip to content

Commit

Permalink
frontend: better clone_url matching on webhooks
Browse files Browse the repository at this point in the history
Previously we just dropped ".git" suffix from git_cloneurl before
comparison, but not the trailing slashes.  We also did just
'rstrip(".git")', which would also remove strings like "tig.git",
potentially leading false-positive matches.

Fixes: #2772
  • Loading branch information
praiskup authored and FrostyX committed Jun 19, 2023
1 parent 5e4bc85 commit 6857443
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions frontend/coprs_frontend/coprs/logic/packages_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,16 @@ def get_or_create(cls, copr_dir, package_name, src_pkg):
db.session.add(package)
return package

@classmethod
def _normalize_git_clone_url(cls, clone_url):
normalized = clone_url.rstrip("/")
return normalized.removesuffix(".git")

@classmethod
def get_for_webhook_rebuild(
cls, copr_id, webhook_secret, clone_url, commits, ref_type, ref, pkg_name: Optional[str]
) -> List[Package]:
clone_url_stripped = clone_url.rstrip(".git")
clone_url_stripped = cls._normalize_git_clone_url(clone_url)

packages = (models.Package.query.join(models.Copr)
.filter(models.Copr.webhook_secret == webhook_secret)
Expand All @@ -184,7 +189,7 @@ def get_for_webhook_rebuild(
result = []
for package in packages:
package_clone_url = package.source_json_dict.get('clone_url', '')
package_clone_url_stripped = package_clone_url.rstrip(".git")
package_clone_url_stripped = cls._normalize_git_clone_url(package_clone_url)

if package_clone_url_stripped != clone_url_stripped:
continue
Expand Down

0 comments on commit 6857443

Please sign in to comment.