Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions check_bugowner.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def _gitea_cache_dir(self):
raise ValueError("Set the OSRT_BUGOWNER_CACHE_HOME variable to a directory where check_bugowner can write its cache")

def _gitea_checkout(
self, owner: str, repo: str, revision: str, revision_name=None, remote="origin", remote_url=None
self, owner: str, repo: str, revision: str, revision_name=None, remote="origin", remote_url=None, fetch=True
):
local_dir = Path(self._gitea_cache_dir(), owner, repo)
self.logger.debug(f"Cache directory: {local_dir}")
Expand All @@ -142,7 +142,7 @@ def _gitea_checkout(
)
else:
return self.scm.checkout_revision(
local_dir, revision, revision_name=revision_name, remote=remote, remote_url=remote_url
local_dir, revision, revision_name=revision_name, remote=remote, remote_url=remote_url, fetch=fetch
)

def _git_remote_name(self, repo, project: str, url: str) -> str:
Expand Down Expand Up @@ -266,6 +266,8 @@ def _gitea_validate(
revision_name=head_revision_name,
remote=head_project,
remote_url=self.scm.package_url(head_project, head_package),
# No need to re-fetch, as we just did to produce the diff.
fetch=False
)
# Read _maintainership.json and whitelist.json after checking out HEAD
self._init_maintainership(repo)
Expand Down Expand Up @@ -314,6 +316,7 @@ def _ldap_active_user(self, email):
for e in email:
if e:
if e not in self._cache(self.ldap_cache).keys():
self.logger.debug(f"LDAP cache miss for {e}")
result = instance.search_st(
"OU=User accounts,DC=corp,DC=suse,DC=com",
ldap.SCOPE_SUBTREE,
Expand All @@ -340,6 +343,8 @@ def _ldap_active_user(self, email):
self._cache_set(self.ldap_cache, e, attrs)
else:
self._cache_set(self.ldap_cache, e, None)
else:
self.logger.debug(f"LDAP cache hit for {e}")

active_statuses.append(self._cache_get(self.ldap_cache, e))

Expand Down Expand Up @@ -432,7 +437,7 @@ def _gitea_check_source_submission(
if self.request.actions[0].src_branch:
head_revision = self.request.actions[0].src_branch

head_revision_name = f"{head_project}_{head_package}_{head_revision.replace("/", "_")}"
head_revision_name = f"{head_project}_{head_package}_{head_revision.replace('/', '_')}"

referenced_prs = [
line
Expand Down Expand Up @@ -484,7 +489,8 @@ def _gitea_check_source_submission(
# Cleanup branches
self.scm.checkout_revision(repo, base_revision)
repo.git.branch("-D", head_revision_name)
repo.git.branch("-D", "-r", f"{head_remote_name}/{head_revision}")
if f"{head_remote_name}/{head_revision}" in {ref for ref in repo.git.branch('-r').split('\n')}:
repo.git.branch("-D", "-r", f"{head_remote_name}/{head_revision}")

return is_valid

Expand Down
17 changes: 8 additions & 9 deletions scm/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,22 @@ def checkout_revision(repo, revision: str, revision_name=None, remote="origin",
if not isinstance(repo, git.Repo):
repo = git.Repo(repo)

branch_names = {b.name for b in repo.branches}

if fetch and revision in branch_names:
if fetch:
if remote_url and remote not in set(r.name for r in repo.remotes):
repo.create_remote(remote, remote_url)

current_revision = repo.git.rev_parse("--abbrev-ref", "HEAD")
if current_revision == revision:
if current_revision == revision and revision_name is None:
repo.remote(remote).pull(revision)
else:
repo.remote(remote).fetch([f"{revision}:{revision}"])
if revision_name is not None:
to_fetch = f"{revision}:{revision_name}"
else:
to_fetch = f"{revision}:{revision}"
repo.remote(remote).fetch([to_fetch])

if revision_name is not None:
if revision_name not in branch_names:
repo.git.checkout("-b", revision_name, f"{remote}/{revision}")
else:
repo.git.switch(revision_name)
repo.git.switch(revision_name)
else:
repo.git.checkout(revision, "--")

Expand Down
Loading