Skip to content

Commit 8f79bce

Browse files
committed
Fix git credentials
1 parent 30f2ce3 commit 8f79bce

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

src/aieng_bot_maintain/auto_merger/workflow_client.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ def _manual_rebase(self, pr: PRQueueItem) -> bool:
265265
env=env,
266266
)
267267

268-
# Configure git user for commits
268+
# Configure git user and credentials for commits
269269
subprocess.run(
270270
["git", "config", "user.name", "aieng-bot-maintain[bot]"],
271271
cwd=repo_dir,
@@ -284,6 +284,31 @@ def _manual_rebase(self, pr: PRQueueItem) -> bool:
284284
capture_output=True,
285285
)
286286

287+
# Configure git to use GH_TOKEN for authentication
288+
# This sets up credential helper to use the token for HTTPS pushes
289+
subprocess.run(
290+
[
291+
"git",
292+
"config",
293+
"credential.helper",
294+
"store --file=/dev/null", # Don't persist credentials
295+
],
296+
cwd=repo_dir,
297+
check=True,
298+
capture_output=True,
299+
)
300+
301+
# Set remote URL to include token for authentication
302+
remote_url = (
303+
f"https://x-access-token:{self.gh_token}@github.com/{pr.repo}.git"
304+
)
305+
subprocess.run(
306+
["git", "remote", "set-url", "origin", remote_url],
307+
cwd=repo_dir,
308+
check=True,
309+
capture_output=True,
310+
)
311+
287312
# Fetch the PR branch
288313
log_info(f" Fetching branch {head_ref}...")
289314
subprocess.run(

tests/auto_merger/test_workflow_client.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,10 @@ def test_trigger_rebase_precommit_success(
217217
MagicMock(returncode=0, stdout=""),
218218
# git config user.email
219219
MagicMock(returncode=0, stdout=""),
220+
# git config credential.helper
221+
MagicMock(returncode=0, stdout=""),
222+
# git remote set-url
223+
MagicMock(returncode=0, stdout=""),
220224
# git fetch origin head_ref
221225
MagicMock(returncode=0, stdout=""),
222226
# git checkout
@@ -233,7 +237,7 @@ def test_trigger_rebase_precommit_success(
233237

234238
assert result is True
235239
# Should make multiple git-related calls
236-
assert mock_run.call_count == 9
240+
assert mock_run.call_count == 11
237241

238242
@patch("subprocess.run")
239243
def test_trigger_rebase_precommit_failure(
@@ -253,6 +257,10 @@ def test_trigger_rebase_precommit_failure(
253257
MagicMock(returncode=0, stdout=""),
254258
# git config user.email
255259
MagicMock(returncode=0, stdout=""),
260+
# git config credential.helper
261+
MagicMock(returncode=0, stdout=""),
262+
# git remote set-url
263+
MagicMock(returncode=0, stdout=""),
256264
# git fetch origin head_ref
257265
MagicMock(returncode=0, stdout=""),
258266
# git checkout

0 commit comments

Comments
 (0)