Skip to content

Commit

Permalink
Copy authentication files in GitLocalPrMerge
Browse files Browse the repository at this point in the history
Signed-off-by: magic_rb <[email protected]>
  • Loading branch information
MagicRB committed Feb 12, 2025
1 parent 3f4d299 commit c06e3f0
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 31 deletions.
70 changes: 44 additions & 26 deletions buildbot_nix/buildbot_nix/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,7 @@ async def run_vc(
pr_head = build_props.getProperty("github.head.sha") or build_props.getProperty(
"head_sha"
)
auth_workdir = self._get_auth_data_workdir()

# Not a PR, fallback to default behavior
if merge_base is None or pr_head is None:
Expand All @@ -1005,33 +1006,42 @@ async def run_vc(
self.build.path_module.join(self.workdir, ".git")
)

if not has_git:
await self._dovccmd(["clone", "--recurse-submodules", self.repourl, "."])
try:
await self._git_auth.download_auth_files_if_needed(auth_workdir)

patched = await self.sourcedirIsPatched()
if not has_git:
await self._dovccmd(
["clone", "--recurse-submodules", self.repourl, "."]
)

if patched:
await self._dovccmd(["clean", "-f", "-f", "-d", "-x"])
patched = await self.sourcedirIsPatched()

await self._dovccmd(["fetch", "-f", "-t", self.repourl, merge_base, pr_head])
if patched:
await self._dovccmd(["clean", "-f", "-f", "-d", "-x"])

await self._dovccmd(["checkout", "--detach", "-f", pr_head])
await self._dovccmd(
["fetch", "-f", "-t", self.repourl, merge_base, pr_head]
)

await self._dovccmd(
[
"-c",
"[email protected]",
"-c",
"user.name=buildbot",
"merge",
"--no-ff",
"-m",
f"Merge {merge_base} into {pr_head}",
merge_base,
]
)
self.updateSourceProperty("got_revision", pr_head)
return await self.parseCommitDescription()
await self._dovccmd(["checkout", "--detach", "-f", pr_head])

await self._dovccmd(
[
"-c",
"[email protected]",
"-c",
"user.name=buildbot",
"merge",
"--no-ff",
"-m",
f"Merge {merge_base} into {pr_head}",
merge_base,
]
)
self.updateSourceProperty("got_revision", pr_head)
return await self.parseCommitDescription()
finally:
await self._git_auth.remove_auth_files_if_needed(auth_workdir)


def nix_eval_config(
Expand All @@ -1058,8 +1068,12 @@ def nix_eval_config(
submodules=True,
haltOnFailure=True,
logEnviron=False,
sshPrivateKey=project.private_key_path.read_text() if project.private_key_path else None,
sshKnownHosts=project.known_hosts_path.read_text() if project.known_hosts_path else None,
sshPrivateKey=project.private_key_path.read_text()
if project.private_key_path
else None,
sshKnownHosts=project.known_hosts_path.read_text()
if project.known_hosts_path
else None,
),
)
drv_gcroots_dir = util.Interpolate(
Expand Down Expand Up @@ -1416,8 +1430,12 @@ def buildbot_effects_config(
method="clean",
submodules=True,
haltOnFailure=True,
sshPrivateKey=project.private_key_path.read_text() if project.private_key_path else None,
sshKnownHosts=project.known_hosts_path.read_text() if project.known_hosts_path else None,
sshPrivateKey=project.private_key_path.read_text()
if project.private_key_path
else None,
sshKnownHosts=project.known_hosts_path.read_text()
if project.known_hosts_path
else None,
),
)
secrets_list = []
Expand Down
4 changes: 1 addition & 3 deletions buildbot_nix/buildbot_nix/gitea_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ def get_project_url(self) -> str:
url = urlparse(self.config.instance_url)
if self.config.ssh_private_key_file:
return self.data.ssh_url
else:
return f"{url.scheme}://git:%(secret:{self.config.token_file})s@{url.hostname}/{self.name}"
return f"{url.scheme}://git:%(secret:{self.config.token_file})s@{url.hostname}/{self.name}"

def create_change_source(self) -> ChangeSource | None:
return None
Expand Down Expand Up @@ -125,7 +124,6 @@ def known_hosts_path(self) -> Path | None:
return self.config.ssh_known_hosts_file



class GiteaBackend(GitBackend):
config: GiteaConfig
webhook_secret: str
Expand Down
2 changes: 1 addition & 1 deletion buildbot_nix/buildbot_nix/projects.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from abc import ABC, abstractmethod
from typing import Any
from pathlib import Path
from typing import Any

from buildbot.changes.base import ChangeSource
from buildbot.config.builder import BuilderConfig
Expand Down
2 changes: 1 addition & 1 deletion buildbot_nix/buildbot_nix/pull_based/project.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pathlib import Path
from typing import Any
from urllib.parse import ParseResult, urlparse
from pathlib import Path

from buildbot.changes.base import ChangeSource
from buildbot.changes.gitpoller import GitPoller
Expand Down

0 comments on commit c06e3f0

Please sign in to comment.