@@ -1053,6 +1053,16 @@ def test_git_platform_backend_get_remote_url_https():
1053
1053
assert url == f"https://github.com/{ owner } /{ repo } .git"
1054
1054
1055
1055
1056
+ def test_git_platform_backend_get_remote_url_token ():
1057
+ owner = "OWNER"
1058
+ repo = "REPO"
1059
+ token = "TOKEN"
1060
+
1061
+ url = GitPlatformBackend .get_remote_url (owner , repo , GitConnectionMode .HTTPS , token )
1062
+
1063
+ assert url == f"https://{ token } @github.com/{ owner } /{ repo } .git"
1064
+
1065
+
1056
1066
def test_github_backend_from_token ():
1057
1067
token = "TOKEN"
1058
1068
@@ -1088,7 +1098,7 @@ def test_github_backend_token_to_hide(caplog, capfd, from_token: bool):
1088
1098
def test_github_backend_does_repository_exist (does_exist : bool ):
1089
1099
github3_client = MagicMock ()
1090
1100
1091
- backend = GitHubBackend (github3_client , MagicMock ())
1101
+ backend = GitHubBackend (github3_client , MagicMock (), "" )
1092
1102
1093
1103
github3_client .repository .return_value = MagicMock () if does_exist else None
1094
1104
@@ -1110,7 +1120,7 @@ def test_github_backend_fork_not_exists_repo_found(
1110
1120
repository = MagicMock ()
1111
1121
github3_client .repository .return_value = repository
1112
1122
1113
- backend = GitHubBackend (github3_client , MagicMock ())
1123
+ backend = GitHubBackend (github3_client , MagicMock (), "" )
1114
1124
user_mock .return_value = "USER"
1115
1125
backend .fork ("UPSTREAM-OWNER" , "REPO" )
1116
1126
@@ -1120,6 +1130,21 @@ def test_github_backend_fork_not_exists_repo_found(
1120
1130
sleep_mock .assert_called_once_with (5 )
1121
1131
1122
1132
1133
+ @mock .patch ("conda_forge_tick.git_utils.GitCli.push_to_url" )
1134
+ def test_github_backend_push_to_repository (push_to_url_mock : MagicMock ):
1135
+ backend = GitHubBackend .from_token ("THIS_IS_THE_TOKEN" )
1136
+
1137
+ git_dir = Path ("GIT_DIR" )
1138
+
1139
+ backend .push_to_repository ("OWNER" , "REPO" , git_dir , "BRANCH_NAME" )
1140
+
1141
+ push_to_url_mock .assert_called_once_with (
1142
+ git_dir ,
1143
+ "https://[email protected] /OWNER/REPO.git" ,
1144
+ "BRANCH_NAME" ,
1145
+ )
1146
+
1147
+
1123
1148
@pytest .mark .parametrize ("branch_already_synced" , [True , False ])
1124
1149
@mock .patch ("time.sleep" , return_value = None )
1125
1150
@mock .patch (
@@ -1158,7 +1183,7 @@ def get_repo(full_name: str):
1158
1183
upstream_repo .default_branch = "UPSTREAM_BRANCH_NAME"
1159
1184
fork_repo .default_branch = "FORK_BRANCH_NAME"
1160
1185
1161
- backend = GitHubBackend (MagicMock (), pygithub_client )
1186
+ backend = GitHubBackend (MagicMock (), pygithub_client , "" )
1162
1187
backend .fork ("UPSTREAM-OWNER" , "REPO" )
1163
1188
1164
1189
if not branch_already_synced :
@@ -1181,7 +1206,7 @@ def test_github_backend_remote_does_not_exist(
1181
1206
github3_client = MagicMock ()
1182
1207
github3_client .repository .return_value = None
1183
1208
1184
- backend = GitHubBackend (github3_client , MagicMock ())
1209
+ backend = GitHubBackend (github3_client , MagicMock (), "" )
1185
1210
1186
1211
user_mock .return_value = "USER"
1187
1212
@@ -1198,7 +1223,7 @@ def test_github_backend_user():
1198
1223
user .login = "USER"
1199
1224
pygithub_client .get_user .return_value = user
1200
1225
1201
- backend = GitHubBackend (MagicMock (), pygithub_client )
1226
+ backend = GitHubBackend (MagicMock (), pygithub_client , "" )
1202
1227
1203
1228
for _ in range (4 ):
1204
1229
# cached property
@@ -1213,7 +1238,7 @@ def test_github_backend_get_api_requests_left_github_exception(caplog):
1213
1238
"API Error"
1214
1239
)
1215
1240
1216
- backend = GitHubBackend (github3_client , MagicMock ())
1241
+ backend = GitHubBackend (github3_client , MagicMock (), "" )
1217
1242
1218
1243
assert backend .get_api_requests_left () is None
1219
1244
assert "API error while fetching" in caplog .text
@@ -1225,7 +1250,7 @@ def test_github_backend_get_api_requests_left_unexpected_response_schema(caplog)
1225
1250
github3_client = MagicMock ()
1226
1251
github3_client .rate_limit .return_value = {"some" : "gibberish data" }
1227
1252
1228
- backend = GitHubBackend (github3_client , MagicMock ())
1253
+ backend = GitHubBackend (github3_client , MagicMock (), "" )
1229
1254
1230
1255
assert backend .get_api_requests_left () is None
1231
1256
assert "API Error while parsing"
@@ -1237,7 +1262,7 @@ def test_github_backend_get_api_requests_left_nonzero():
1237
1262
github3_client = MagicMock ()
1238
1263
github3_client .rate_limit .return_value = {"resources" : {"core" : {"remaining" : 5 }}}
1239
1264
1240
- backend = GitHubBackend (github3_client , MagicMock ())
1265
+ backend = GitHubBackend (github3_client , MagicMock (), "" )
1241
1266
1242
1267
assert backend .get_api_requests_left () == 5
1243
1268
@@ -1249,7 +1274,7 @@ def test_github_backend_get_api_requests_left_zero_invalid_reset_time(caplog):
1249
1274
1250
1275
github3_client .rate_limit .return_value = {"resources" : {"core" : {"remaining" : 0 }}}
1251
1276
1252
- backend = GitHubBackend (github3_client , MagicMock ())
1277
+ backend = GitHubBackend (github3_client , MagicMock (), "" )
1253
1278
1254
1279
assert backend .get_api_requests_left () == 0
1255
1280
@@ -1269,7 +1294,7 @@ def test_github_backend_get_api_requests_left_zero_valid_reset_time(caplog):
1269
1294
"resources" : {"core" : {"remaining" : 0 , "reset" : reset_timestamp }}
1270
1295
}
1271
1296
1272
- backend = GitHubBackend (github3_client , MagicMock ())
1297
+ backend = GitHubBackend (github3_client , MagicMock (), "" )
1273
1298
1274
1299
assert backend .get_api_requests_left () == 0
1275
1300
@@ -1308,7 +1333,7 @@ def request_side_effect(method, _url, **_kwargs):
1308
1333
pygithub_mock = MagicMock ()
1309
1334
pygithub_mock .get_user .return_value .login = "CURRENT_USER"
1310
1335
1311
- backend = GitHubBackend (github3 .login (token = "TOKEN" ), pygithub_mock )
1336
+ backend = GitHubBackend (github3 .login (token = "TOKEN" ), pygithub_mock , "" )
1312
1337
1313
1338
pr_data = backend .create_pull_request (
1314
1339
"conda-forge" ,
@@ -1394,7 +1419,7 @@ def request_side_effect(method, url, **_kwargs):
1394
1419
1395
1420
request_mock .side_effect = request_side_effect
1396
1421
1397
- backend = GitHubBackend (github3 .login (token = "TOKEN" ), MagicMock ())
1422
+ backend = GitHubBackend (github3 .login (token = "TOKEN" ), MagicMock (), "" )
1398
1423
1399
1424
backend .comment_on_pull_request (
1400
1425
"conda-forge" ,
@@ -1426,7 +1451,7 @@ def request_side_effect(method, url, **_kwargs):
1426
1451
1427
1452
request_mock .side_effect = request_side_effect
1428
1453
1429
- backend = GitHubBackend (github3 .login (token = "TOKEN" ), MagicMock ())
1454
+ backend = GitHubBackend (github3 .login (token = "TOKEN" ), MagicMock (), "" )
1430
1455
1431
1456
with pytest .raises (RepositoryNotFoundError ):
1432
1457
backend .comment_on_pull_request (
@@ -1463,7 +1488,7 @@ def request_side_effect(method, url, **_kwargs):
1463
1488
assert False , f"Unexpected endpoint: { method } { url } "
1464
1489
1465
1490
request_mock .side_effect = request_side_effect
1466
- backend = GitHubBackend (github3 .login (token = "TOKEN" ), MagicMock ())
1491
+ backend = GitHubBackend (github3 .login (token = "TOKEN" ), MagicMock (), "" )
1467
1492
1468
1493
with pytest .raises (
1469
1494
GitPlatformError ,
@@ -1516,7 +1541,7 @@ def request_side_effect(method, url, **_kwargs):
1516
1541
1517
1542
request_mock .side_effect = request_side_effect
1518
1543
1519
- backend = GitHubBackend (github3 .login (token = "TOKEN" ), MagicMock ())
1544
+ backend = GitHubBackend (github3 .login (token = "TOKEN" ), MagicMock (), "" )
1520
1545
1521
1546
with pytest .raises (GitPlatformError , match = "Could not comment on pull request" ):
1522
1547
backend .comment_on_pull_request (
@@ -1528,7 +1553,7 @@ def request_side_effect(method, url, **_kwargs):
1528
1553
1529
1554
1530
1555
@pytest .mark .parametrize (
1531
- "backend" , [GitHubBackend (MagicMock (), MagicMock ()), DryRunBackend ()]
1556
+ "backend" , [GitHubBackend (MagicMock (), MagicMock (), "" ), DryRunBackend ()]
1532
1557
)
1533
1558
@mock .patch (
1534
1559
"conda_forge_tick.git_utils.GitHubBackend.user" , new_callable = mock .PropertyMock
@@ -1547,7 +1572,7 @@ def test_git_platform_backend_clone_fork_and_branch(
1547
1572
1548
1573
user_mock .return_value = "USER"
1549
1574
1550
- backend = GitHubBackend (MagicMock (), MagicMock ())
1575
+ backend = GitHubBackend (MagicMock (), MagicMock (), "" )
1551
1576
backend .clone_fork_and_branch (
1552
1577
upstream_owner , repo_name , target_dir , new_branch , base_branch
1553
1578
)
@@ -1584,6 +1609,21 @@ def test_dry_run_backend_does_repository_exist_other_repo():
1584
1609
)
1585
1610
1586
1611
1612
+ def test_dry_run_backend_push_to_repository (caplog ):
1613
+ caplog .set_level (logging .DEBUG )
1614
+
1615
+ backend = DryRunBackend ()
1616
+
1617
+ git_dir = Path ("GIT_DIR" )
1618
+
1619
+ backend .push_to_repository ("OWNER" , "REPO" , git_dir , "BRANCH_NAME" )
1620
+
1621
+ assert (
1622
+ "Dry Run: Pushing changes from GIT_DIR to OWNER/REPO on branch BRANCH_NAME"
1623
+ in caplog .text
1624
+ )
1625
+
1626
+
1587
1627
def test_dry_run_backend_fork (caplog ):
1588
1628
caplog .set_level (logging .DEBUG )
1589
1629
0 commit comments