-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Repository.py
2031 lines (1884 loc) · 82.3 KB
/
Repository.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
############################ Copyrights and license ############################
# #
# Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> #
# Copyright 2012 Zearin <zearin@gonk.net> #
# Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> #
# Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> #
# Copyright 2015 Christopher Wilcox <git@crwilcox.com> #
# Copyright 2015 Dan Vanderkam <danvdk@gmail.com> #
# Copyright 2015 Enix Yu <enix223@163.com> #
# Copyright 2015 Kyle Hornberg <khornberg@users.noreply.github.com> #
# Copyright 2015 Uriel Corfa <uriel@corfa.fr> #
# Copyright 2016 @tmshn <tmshn@r.recruit.co.jp> #
# Copyright 2016 Enix Yu <enix223@163.com> #
# Copyright 2016 Jannis Gebauer <ja.geb@me.com> #
# Copyright 2016 Jimmy Zelinskie <jimmyzelinskie@gmail.com> #
# Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> #
# Copyright 2018 AetherDeity <aetherdeity+github@gmail.com> #
# Copyright 2018 Alice GIRARD <bouhahah@gmail.com> #
# Copyright 2018 Benoit Latinier <benoit@latinier.fr> #
# Copyright 2018 Hayden Fuss <wifu1234@gmail.com> #
# Copyright 2018 Iraquitan Cordeiro Filho <iraquitanfilho@gmail.com> #
# Copyright 2018 Jacopo Notarstefano <jacopo.notarstefano@gmail.com> #
# Copyright 2018 Maarten Fonville <mfonville@users.noreply.github.com> #
# Copyright 2018 Mateusz Loskot <mateusz@loskot.net> #
# Copyright 2018 Raihaan <31362124+res0nance@users.noreply.github.com> #
# Copyright 2018 Shinichi TAMURA <shnch.tmr@gmail.com> #
# Copyright 2018 Steve Kowalik <steven@wedontsleep.org> #
# Copyright 2018 Victor Granic <vmg@boreal321.com> #
# Copyright 2018 Wan Liuyang <tsfdye@gmail.com> #
# Copyright 2018 Will Yardley <wyardley@users.noreply.github.com> #
# Copyright 2018 sfdye <tsfdye@gmail.com> #
# Copyright 2019 Steve Kowalik <steven@wedontsleep.org> #
# Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com>#
# Copyright 2019 Tim Gates <tim.gates@iress.com> #
# Copyright 2019 Wan Liuyang <tsfdye@gmail.com> #
# Copyright 2019 Will Li <cuichen.li94@gmail.com> #
# Copyright 2020 Chris de Graaf <chrisadegraaf@gmail.com> #
# Copyright 2020 Florent Clarret <florent.clarret@gmail.com> #
# Copyright 2020 Glenn McDonald <testworksau@users.noreply.github.com> #
# Copyright 2020 Huw Jones <huwcbjones@outlook.com> #
# Copyright 2020 Pascal Hofmann <mail@pascalhofmann.de> #
# Copyright 2020 Steve Kowalik <steven@wedontsleep.org> #
# Copyright 2020 ton-katsu <sakamoto.yoshihisa@gmail.com> #
# Copyright 2021 Chris Keating <christopherkeating@gmail.com> #
# Copyright 2021 Steve Kowalik <steven@wedontsleep.org> #
# Copyright 2021 karsten-wagner <39054096+karsten-wagner@users.noreply.github.com>#
# Copyright 2021 xmo-odoo <xmo@odoo.com> #
# Copyright 2022 Eric Nieuwland <eric.nieuwland@gmail.com> #
# Copyright 2022 Ibrahim Hussaini <ibrahimhussainialias@outlook.com> #
# Copyright 2022 KimSia Sim <245021+simkimsia@users.noreply.github.com> #
# Copyright 2022 Marco Köpcke <hello@parakoopa.de> #
# Copyright 2023 Andrew Dawes <53574062+AndrewJDawes@users.noreply.github.com> #
# Copyright 2023 Armen Martirosyan <armartirosyan@gmail.com> #
# Copyright 2023 BradChengIRESS <49461141+BradChengIRESS@users.noreply.github.com>#
# Copyright 2023 Enrico Minack <github@enrico.minack.dev> #
# Copyright 2023 Felipe Peter <mr-peipei@web.de> #
# Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> #
# Copyright 2023 Jonathan Greg <31892308+jmgreg31@users.noreply.github.com> #
# Copyright 2023 Mauricio Alejandro Martínez Pacheco <mauricio.martinez@premise.com>#
# Copyright 2023 Mauricio Alejandro Martínez Pacheco <n_othing@hotmail.com> #
# Copyright 2023 Max Mehl <6170081+mxmehl@users.noreply.github.com> #
# Copyright 2023 Roberto Pastor Muela <37798125+RobPasMue@users.noreply.github.com>#
# Copyright 2023 Trim21 <trim21.me@gmail.com> #
# Copyright 2023 Wojciech Barczyński <104033489+WojciechBarczynski@users.noreply.github.com>#
# #
# This file is part of PyGithub. #
# http://pygithub.readthedocs.io/ #
# #
# PyGithub is free software: you can redistribute it and/or modify it under #
# the terms of the GNU Lesser General Public License as published by the Free #
# Software Foundation, either version 3 of the License, or (at your option) #
# any later version. #
# #
# PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY #
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more #
# details. #
# #
# You should have received a copy of the GNU Lesser General Public License #
# along with PyGithub. If not, see <http://www.gnu.org/licenses/>. #
# #
################################################################################
from datetime import date, datetime, timezone
from unittest import mock
import github
from . import Framework
class Repository(Framework.TestCase):
def setUp(self):
super().setUp()
self.user = self.g.get_user()
self.repo = self.user.get_repo("PyGithub")
def testAttributes(self):
self.assertEqual(self.repo.clone_url, "https://github.com/jacquev6/PyGithub.git")
self.assertEqual(
self.repo.created_at,
datetime(2012, 2, 25, 12, 53, 47, tzinfo=timezone.utc),
)
self.assertEqual(self.repo.description, "Python library implementing the full Github API v3")
self.assertFalse(self.repo.fork)
self.assertEqual(self.repo.forks, 3)
self.assertEqual(self.repo.full_name, "jacquev6/PyGithub")
self.assertEqual(self.repo.git_url, "git://github.com/jacquev6/PyGithub.git")
self.assertTrue(self.repo.has_downloads)
self.assertTrue(self.repo.has_issues)
self.assertEqual(
self.repo.deployments_url,
"https://api.github.com/repos/jacquev6/PyGithub/deployments",
)
self.assertFalse(self.repo.has_pages)
self.assertEqual(
self.repo.releases_url,
"https://api.github.com/repos/jacquev6/PyGithub/releases{/id}",
)
self.assertFalse(self.repo.has_wiki)
self.assertEqual(self.repo.homepage, "http://vincent-jacques.net/PyGithub")
self.assertEqual(self.repo.html_url, "https://github.com/jacquev6/PyGithub")
self.assertEqual(self.repo.id, 3544490)
self.assertIs(self.repo.is_template, None)
self.assertEqual(self.repo.language, "Python")
self.assertEqual(self.repo.license.spdx_id, "LGPL-3.0")
self.assertEqual(self.repo.master_branch, None)
self.assertEqual(self.repo.name, "PyGithub")
self.assertEqual(self.repo.open_issues, 16)
self.assertEqual(self.repo.organization, None)
self.assertEqual(self.repo.owner.login, "jacquev6")
self.assertEqual(self.repo.parent, None)
self.assertTrue(self.repo.permissions.admin)
self.assertTrue(self.repo.permissions.pull)
self.assertTrue(self.repo.permissions.push)
self.assertFalse(self.repo.private)
self.assertEqual(
self.repo.pushed_at,
datetime(2012, 5, 27, 6, 0, 28, tzinfo=timezone.utc),
)
self.assertEqual(self.repo.size, 308)
self.assertEqual(self.repo.source, None)
self.assertEqual(self.repo.ssh_url, "git@github.com:jacquev6/PyGithub.git")
self.assertEqual(self.repo.svn_url, "https://github.com/jacquev6/PyGithub")
self.assertEqual(
self.repo.updated_at,
datetime(2012, 5, 27, 6, 55, 28, tzinfo=timezone.utc),
)
self.assertEqual(self.repo.url, "https://api.github.com/repos/jacquev6/PyGithub")
self.assertEqual(self.repo.watchers, 15)
self.assertEqual(repr(self.repo), 'Repository(full_name="jacquev6/PyGithub")')
self.assertTrue(self.repo.permissions.admin)
self.assertTrue(self.repo.permissions.push)
self.assertTrue(self.repo.permissions.pull)
# Allow None or any boolean value for backwards compatibility
self.assertIn(self.repo.permissions.maintain, [None, False, True])
self.assertIn(self.repo.permissions.triage, [None, False, True])
self.assertTrue(self.repo.use_squash_pr_title_as_default)
self.assertEqual(self.repo.squash_merge_commit_title, "PR_TITLE")
self.assertEqual(self.repo.squash_merge_commit_message, "COMMIT_MESSAGES")
self.assertEqual(self.repo.merge_commit_title, "PR_TITLE")
self.assertEqual(self.repo.merge_commit_message, "PR_BODY")
self.assertTrue(self.repo.web_commit_signoff_required)
def testEditWithoutArguments(self):
self.repo.edit("PyGithub")
def testEditWithAllArguments(self):
self.repo.edit(
"PyGithub",
"Description edited by PyGithub",
"http://vincent-jacques.net/PyGithub",
private=True,
has_issues=True,
has_projects=False,
has_wiki=False,
allow_auto_merge=True,
allow_forking=True,
allow_update_branch=True,
allow_squash_merge=True,
allow_merge_commit=True,
allow_rebase_merge=True,
delete_branch_on_merge=True,
use_squash_pr_title_as_default=True,
is_template=True,
squash_merge_commit_title="PR_TITLE",
squash_merge_commit_message="COMMIT_MESSAGES",
merge_commit_title="PR_TITLE",
merge_commit_message="PR_BODY",
web_commit_signoff_required=True,
)
self.assertEqual(self.repo.description, "Description edited by PyGithub")
self.repo.edit("PyGithub", "Python library implementing the full Github API v3")
self.assertEqual(self.repo.description, "Python library implementing the full Github API v3")
self.assertFalse(self.repo.archived)
self.assertTrue(self.repo.allow_update_branch)
self.assertTrue(self.repo.has_issues)
self.assertFalse(self.repo.has_projects)
self.assertFalse(self.repo.has_wiki)
self.assertTrue(self.repo.allow_auto_merge)
self.assertTrue(self.repo.allow_forking)
self.assertTrue(self.repo.allow_squash_merge)
self.assertTrue(self.repo.allow_merge_commit)
self.assertTrue(self.repo.allow_rebase_merge)
self.assertTrue(self.repo.delete_branch_on_merge)
self.assertTrue(self.repo.use_squash_pr_title_as_default)
self.assertEqual(self.repo.squash_merge_commit_title, "PR_TITLE")
self.assertEqual(self.repo.squash_merge_commit_message, "COMMIT_MESSAGES")
self.assertEqual(self.repo.merge_commit_title, "PR_TITLE")
self.assertEqual(self.repo.merge_commit_message, "PR_BODY")
self.assertTrue(self.repo.web_commit_signoff_required)
def testEditWithDefaultBranch(self):
self.assertEqual(self.repo.master_branch, None)
self.repo.edit("PyGithub", default_branch="master")
self.assertEqual(self.repo.master_branch, "master")
def testDelete(self):
repo = self.g.get_user().get_repo("TestPyGithub")
repo.delete()
def testGetContributors(self):
self.assertListKeyEqual(
self.repo.get_contributors(),
lambda c: (c.login, c.contributions),
[("jacquev6", 355)],
)
def testCreateMilestone(self):
milestone = self.repo.create_milestone(
"Milestone created by PyGithub",
state="open",
description="Description created by PyGithub",
due_on=date(2012, 6, 15),
)
self.assertEqual(milestone.number, 5)
def testCreateMilestoneWithMinimalArguments(self):
milestone = self.repo.create_milestone("Milestone also created by PyGithub")
self.assertEqual(milestone.number, 6)
def testCreateIssue(self):
issue = self.repo.create_issue("Issue created by PyGithub")
self.assertEqual(issue.number, 28)
def testCreateIssueWithAllArguments(self):
user = self.g.get_user("jacquev6")
milestone = self.repo.get_milestone(2)
question = self.repo.get_label("Question")
issue = self.repo.create_issue(
"Issue also created by PyGithub",
"Body created by PyGithub",
user,
milestone,
[question],
["jacquev6", "stuglaser"],
)
self.assertEqual(issue.number, 30)
def testCreateIssueWithAllArgumentsStringLabel(self):
user = self.g.get_user("jacquev6")
milestone = self.repo.get_milestone(2)
issue = self.repo.create_issue(
"Issue also created by PyGithub",
"Body created by PyGithub",
user,
milestone,
["Question"],
["jacquev6", "stuglaser"],
)
self.assertEqual(issue.number, 30)
def testCreateLabel(self):
label = self.repo.create_label(
"Label with silly name % * + created by PyGithub",
"00ff00",
"Description of label with silly name",
)
self.assertEqual(label.color, "00ff00")
self.assertEqual(label.description, "Description of label with silly name")
self.assertEqual(label.name, "Label with silly name % * + created by PyGithub")
self.assertEqual(
label.url,
"https://api.github.com/repos/jacquev6/PyGithub/labels/Label+with+silly+name+%25+%2A+%2B+created+by+PyGithub",
)
def testGetLabel(self):
label = self.repo.get_label("Label with silly name % * + created by PyGithub")
self.assertEqual(label.color, "00ff00")
self.assertEqual(label.name, "Label with silly name % * + created by PyGithub")
self.assertEqual(
label.url,
"https://api.github.com/repos/jacquev6/PyGithub/labels/Label+with+silly+name+%25+%2A+%2B+created+by+PyGithub",
)
def testCreateHookWithMinimalParameters(self):
hook = self.repo.create_hook("web", {"url": "http://foobar.com"})
self.assertEqual(hook.id, 257967)
def testCreateHookWithAllParameters(self):
hook = self.repo.create_hook("web", {"url": "http://foobar.com"}, ["fork"], False)
self.assertTrue(hook.active) # WTF
self.assertEqual(hook.id, 257993)
def testCreateGitRef(self):
ref = self.repo.create_git_ref(
"refs/heads/BranchCreatedByPyGithub",
"4303c5b90e2216d927155e9609436ccb8984c495",
)
self.assertEqual(
ref.url,
"https://api.github.com/repos/jacquev6/PyGithub/git/refs/heads/BranchCreatedByPyGithub",
)
def testCreateAutolink(self):
key = self.repo.create_autolink("DUMMY-", "https://github.com/PyGithub/PyGithub/issues/<num>")
self.assertEqual(key.id, 209614)
def testCreateGitBlob(self):
blob = self.repo.create_git_blob("Blob created by PyGithub", "latin1")
self.assertEqual(blob.sha, "5dd930f591cd5188e9ea7200e308ad355182a1d8")
def testCreateGitTree(self):
tree = self.repo.create_git_tree(
[github.InputGitTreeElement("Foobar.txt", "100644", "blob", content="File created by PyGithub")]
)
self.assertEqual(tree.sha, "41cf8c178c636a018d537cb20daae09391efd70b")
def testCreateGitTreeWithBaseTree(self):
base_tree = self.repo.get_git_tree("41cf8c178c636a018d537cb20daae09391efd70b", recursive=False)
tree = self.repo.create_git_tree(
[
github.InputGitTreeElement(
"Barbaz.txt",
"100644",
"blob",
content="File also created by PyGithub",
)
],
base_tree,
)
self.assertEqual(tree.sha, "107139a922f33bab6fbeb9f9eb8787e7f19e0528")
def testCreateGitTreeWithSha(self):
tree = self.repo.create_git_tree(
[
github.InputGitTreeElement(
"Barbaz.txt",
"100644",
"blob",
sha="5dd930f591cd5188e9ea7200e308ad355182a1d8",
)
]
)
self.assertEqual(tree.sha, "fae707821159639589bf94f3fb0a7154ec5d441b")
def testCreateGitTreeWithNullSha(self):
tree = self.repo.create_git_tree(
[
github.InputGitTreeElement(
"Baz.bar",
"100644",
"blob",
sha=None,
)
]
)
self.assertEqual(tree.sha, "9b8166fc80d0f0fe9192d4bf1dbaa87f194e012f")
def testCreateGitCommit(self):
tree = self.repo.get_git_tree("107139a922f33bab6fbeb9f9eb8787e7f19e0528")
commit = self.repo.create_git_commit("Commit created by PyGithub", tree, [])
self.assertEqual(commit.sha, "0b820628236ab8bab3890860fc414fa757ca15f4")
def testCreateGitCommitWithParents(self):
parents = [
self.repo.get_git_commit("7248e66831d4ffe09ef1f30a1df59ec0a9331ece"),
self.repo.get_git_commit("12d427464f8d91c8e981043a86ba8a2a9e7319ea"),
]
tree = self.repo.get_git_tree("fae707821159639589bf94f3fb0a7154ec5d441b")
commit = self.repo.create_git_commit("Commit created by PyGithub", tree, parents)
self.assertEqual(commit.sha, "6adf9ea25ff8a8f2a42bcb1c09e42526339037cd")
def testCreateGitCommitWithAllArguments(self):
tree = self.repo.get_git_tree("107139a922f33bab6fbeb9f9eb8787e7f19e0528")
commit = self.repo.create_git_commit(
"Commit created by PyGithub",
tree,
[],
github.InputGitAuthor("John Doe", "j.doe@vincent-jacques.net", "2008-07-09T16:13:30+12:00"),
github.InputGitAuthor("John Doe", "j.doe@vincent-jacques.net", "2008-07-09T16:13:30+12:00"),
)
self.assertEqual(commit.sha, "526946197ae9da59c6507cacd13ad6f1cfb686ea")
def testCreateGitRelease(self):
release = self.repo.create_git_release(
"vX.Y.Z-by-PyGithub-acctest",
"vX.Y.Z: PyGithub acctest",
"This release is created by PyGithub",
)
self.assertEqual(release.tag_name, "vX.Y.Z-by-PyGithub-acctest")
self.assertEqual(release.title, "vX.Y.Z: PyGithub acctest")
self.assertEqual(release.body, "This release is created by PyGithub")
self.assertEqual(release.draft, False)
self.assertEqual(release.prerelease, False)
def testCreateGitReleaseWithAllArguments(self):
release = self.repo.create_git_release(
"vX.Y.Z-by-PyGithub-acctest2",
"vX.Y.Z: PyGithub acctest2",
"This release is also created by PyGithub",
False,
True,
False,
"da9a285fd8b782461e56cba39ae8d2fa41ca7cdc",
)
self.assertEqual(release.tag_name, "vX.Y.Z-by-PyGithub-acctest2")
self.assertEqual(release.title, "vX.Y.Z: PyGithub acctest2")
self.assertEqual(release.body, "This release is also created by PyGithub")
self.assertEqual(release.draft, False)
self.assertEqual(release.prerelease, True)
tag = [tag for tag in self.repo.get_tags() if tag.name == "vX.Y.Z-by-PyGithub-acctest2"].pop()
self.assertEqual(tag.commit.sha, "da9a285fd8b782461e56cba39ae8d2fa41ca7cdc")
def testCreateGitTag(self):
tag = self.repo.create_git_tag(
"TaggedByPyGithub",
"Tag created by PyGithub",
"0b820628236ab8bab3890860fc414fa757ca15f4",
"commit",
)
self.assertEqual(tag.sha, "5ba561eaa2b7ca9015662510157b15d8f3b0232a")
def testCreateGitTagWithAllArguments(self):
tag = self.repo.create_git_tag(
"TaggedByPyGithub2",
"Tag also created by PyGithub",
"526946197ae9da59c6507cacd13ad6f1cfb686ea",
"commit",
github.InputGitAuthor("John Doe", "j.doe@vincent-jacques.net", "2008-07-09T16:13:30+12:00"),
)
self.assertEqual(tag.sha, "f0e99a8335fbc84c53366c4a681118468f266625")
def testCreateKey(self):
key = self.repo.create_key(
"Key added through PyGithub",
"ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA2Mm0RjTNAYFfSCtUpO54usdseroUSIYg5KX4JoseTpqyiB/hqewjYLAdUq/tNIQzrkoEJWSyZrQt0ma7/YCyMYuNGd3DU6q6ZAyBeY3E9RyCiKjO3aTL2VKQGFvBVVmGdxGVSCITRphAcsKc/PF35/fg9XP9S0anMXcEFtdfMHz41SSw+XtE+Vc+6cX9FuI5qUfLGbkv8L1v3g4uw9VXlzq4GfTA+1S7D6mcoGHopAIXFlVr+2RfDKdSURMcB22z41fljO1MW4+zUS/4FyUTpL991es5fcwKXYoiE+x06VJeJJ1Krwx+DZj45uweV6cHXt2JwJEI9fWB6WyBlDejWw== vincent@IDEE",
)
self.assertEqual(key.id, 2626761)
def testCreateSourceImport(self):
import_repo = self.g.get_user("brix4dayz").get_repo("source-import-test")
source_import = import_repo.create_source_import("mercurial", "https://bitbucket.org/hfuss/source-import-test")
self.assertEqual(source_import.authors_count, 0)
self.assertEqual(
source_import.authors_url,
"https://api.github.com/repos/brix4dayz/source-import-test/import/authors",
)
self.assertEqual(
source_import.html_url,
"https://github.com/brix4dayz/source-import-test/import",
)
self.assertEqual(
source_import.repository_url,
"https://api.github.com/repos/brix4dayz/source-import-test",
)
self.assertEqual(source_import.status, "importing")
self.assertEqual(source_import.status_text, "Importing...")
self.assertEqual(
source_import.url,
"https://api.github.com/repos/brix4dayz/source-import-test/import",
)
self.assertEqual(source_import.vcs, "mercurial")
self.assertEqual(source_import.vcs_url, "https://bitbucket.org/hfuss/source-import-test")
def testCreateRepositoryDispatch(self):
with_payload = self.repo.create_repository_dispatch("type", {"foo": "bar"})
self.assertTrue(with_payload)
without_payload = self.repo.create_repository_dispatch("type")
self.assertTrue(without_payload)
@mock.patch("github.PublicKey.encrypt")
def testCreateSecret(self, encrypt):
# encrypt returns a non-deterministic value, we need to mock it so the replay data matches
encrypt.return_value = "M+5Fm/BqTfB90h3nC7F3BoZuu3nXs+/KtpXwxm9gG211tbRo0F5UiN0OIfYT83CKcx9oKES9Va4E96/b"
secret = self.repo.create_secret("secret-name", "secret-value")
self.assertIsNotNone(secret)
@mock.patch("github.PublicKey.encrypt")
def testRepoSecrets(self, encrypt):
# encrypt returns a non-deterministic value, we need to mock it so the replay data matches
encrypt.return_value = "M+5Fm/BqTfB90h3nC7F3BoZuu3nXs+/KtpXwxm9gG211tbRo0F5UiN0OIfYT83CKcx9oKES9Va4E96/b"
# GitHub will always capitalize the secret name
secrets = (("SECRET_NAME_ONE", "secret-value-one"), ("SECRET_NAME_TWO", "secret-value-two"))
repo = self.g.get_repo("AndrewJDawes/PyGithub")
for matched_repo_secret in secrets:
repo.create_secret(matched_repo_secret[0], matched_repo_secret[1])
repo.update()
repo_secrets = repo.get_secrets()
matched_repo_secrets = []
for matched_repo_secret in secrets:
for repo_secret in repo_secrets:
# GitHub will always capitalize the secret name, may be best to uppercase test data for comparison
if repo_secret.name == matched_repo_secret[0].upper():
matched_repo_secrets.append(repo_secret)
break
self.assertEqual(len(matched_repo_secrets), len(secrets))
for matched_repo_secret in matched_repo_secrets:
matched_repo_secret.delete()
def testCodeScanAlerts(self):
codescan_alerts = self.repo.get_codescan_alerts()
self.assertListKeyEqual(
codescan_alerts,
lambda c: c.number,
[
6,
],
)
codescan_alert = codescan_alerts[0]
self.assertEqual(repr(codescan_alert), "CodeScanAlert(number=6)")
self.assertEqual(codescan_alert.state, "open")
self.assertEqual(
codescan_alert.url,
"https://api.github.com/repos/jacquev6/PyGithub/code-scanning/alerts/6",
)
self.assertEqual(
codescan_alert.created_at,
datetime(2021, 6, 29, 12, 28, 30, tzinfo=timezone.utc),
)
self.assertEqual(
codescan_alert.dismissed_at,
datetime(2021, 6, 30, 5, 5, 5, tzinfo=timezone.utc),
)
self.assertEqual(codescan_alert.dismissed_reason, "Won't tell")
dismissed_by = codescan_alert.dismissed_by
self.assertEqual(dismissed_by.login, "dismisser.login")
instance = codescan_alert.most_recent_instance
self.assertEqual(
repr(instance),
"CodeScanAlertInstance("
'ref="refs/heads/master", '
'analysis_key=".github/workflows/codeql-analysis.yml:analyze"'
")",
)
self.assertEqual(instance.ref, "refs/heads/master")
self.assertEqual(instance.analysis_key, ".github/workflows/codeql-analysis.yml:analyze")
self.assertEqual(instance.environment, "{language:python}")
self.assertEqual(instance.state, "open")
self.assertListEqual(instance.classifications, ["stupid typo"])
self.assertDictEqual(instance.message, {"text": "Awful stuff might happen."})
self.assertEqual(instance.commit_sha, "deadbeef")
location = instance.location
self.assertEqual(
str(location),
"tests/ReplayData/Repository.testCodeScanAlerts.txt @ l10:c2-l10:c48",
)
self.assertEqual(
repr(location),
"CodeScanAlertInstanceLocation("
"start_line=10, start_column=2, "
'path="tests/ReplayData/Repository.testCodeScanAlerts.txt", '
"end_line=10, end_column=48"
")",
)
self.assertEqual(location.path, "tests/ReplayData/Repository.testCodeScanAlerts.txt")
self.assertEqual(location.start_line, 10)
self.assertEqual(location.start_column, 2)
self.assertEqual(location.end_line, 10)
self.assertEqual(location.end_column, 48)
rule = codescan_alert.rule
self.assertEqual(repr(rule), 'CodeScanRule(name="py/rule-name", id="py/rule-id")')
self.assertEqual(rule.id, "py/rule-id")
self.assertEqual(rule.name, "py/rule-name")
self.assertEqual(rule.security_severity_level, "high")
self.assertEqual(rule.severity, "warning")
self.assertEqual(rule.description, "Bad practice")
tool = codescan_alert.tool
self.assertEqual(repr(tool), 'CodeScanTool(version="2.5.7", name="CodeQL", guid=None)')
self.assertEqual(tool.guid, None)
self.assertEqual(tool.name, "CodeQL")
self.assertEqual(tool.version, "2.5.7")
instances = list(codescan_alert.get_instances())
self.assertEqual(len(instances), 2)
#
instance = instances[0]
self.assertEqual(instance.ref, "instances[0].ref")
self.assertEqual(instance.analysis_key, "instances[0].analysis_key")
self.assertEqual(instance.environment, "instances[0].environment")
self.assertEqual(instance.state, "instances[0].state")
self.assertListEqual(instance.classifications, ["instances[0].classifications"])
self.assertDictEqual(instance.message, {"text": "instances[0].message"})
self.assertEqual(instance.commit_sha, "instances[0].commit_sha")
location = instance.location
self.assertEqual(location.path, "tests/ReplayData/Repository.testCodeScanAlerts.txt")
self.assertEqual(location.start_line, 10)
self.assertEqual(location.start_column, 2)
self.assertEqual(location.end_line, 10)
self.assertEqual(location.end_column, 48)
#
instance = instances[1]
self.assertEqual(instance.ref, "instances[1].ref")
self.assertEqual(instance.analysis_key, "instances[1].analysis_key")
self.assertEqual(instance.environment, "instances[1].environment")
self.assertEqual(instance.state, "instances[1].state")
self.assertListEqual(instance.classifications, ["instances[1].classifications"])
self.assertDictEqual(instance.message, {"text": "instances[1].message"})
self.assertEqual(instance.commit_sha, "instances[1].commit_sha")
location = instance.location
self.assertEqual(location.path, "tests/ReplayData/Repository.testCodeScanAlerts.txt")
self.assertEqual(location.start_line, 20)
self.assertEqual(location.start_column, 17)
self.assertEqual(location.end_line, 20)
self.assertEqual(location.end_column, 42)
def testCollaborators(self):
lyloa = self.g.get_user("Lyloa")
self.assertFalse(self.repo.has_in_collaborators(lyloa))
self.repo.add_to_collaborators(lyloa)
self.assertTrue(self.repo.has_in_collaborators(lyloa))
collaborators = self.repo.get_collaborators()
self.assertListKeyEqual(collaborators, lambda u: u.login, ["jacquev6", "Lyloa"])
jacquev6 = [u for u in collaborators if u.login == "jacquev6"][0]
self.assertTrue(jacquev6.permissions.admin, True)
self.assertTrue(jacquev6.permissions.pull, True)
self.assertTrue(jacquev6.permissions.push, True)
self.assertFalse(jacquev6.site_admin)
self.repo.remove_from_collaborators(lyloa)
self.assertFalse(self.repo.has_in_collaborators(lyloa))
def testCollaboratorPermission(self):
self.assertEqual(self.repo.get_collaborator_permission("jacquev6"), "admin")
def testGetPendingInvitations(self):
lyloa = self.g.get_user("Lyloa")
self.repo.add_to_collaborators(lyloa)
invitations = self.repo.get_pending_invitations()
self.assertListKeyEqual(invitations, lambda u: u.invitee.login, ["Lyloa"])
def testRemoveInvitation(self):
self.repo.remove_invitation(17285388)
def testRemoveAutolink(self):
self.repo.remove_autolink(209611)
def testCollaboratorPermissionNoPushAccess(self):
with self.assertRaises(github.GithubException) as raisedexp:
self.repo.get_collaborator_permission("lyloa")
self.assertEqual(raisedexp.exception.status, 403)
self.assertEqual(
raisedexp.exception.data,
{
"documentation_url": "https://developer.github.com/v3/repos/collaborators/#review-a-users-permission-level",
"message": "Must have push access to view collaborator permission.",
},
)
def testCompare(self):
comparison = self.repo.compare("v0.6", "v0.7")
self.assertEqual(comparison.status, "ahead")
self.assertEqual(comparison.ahead_by, 4)
self.assertEqual(comparison.behind_by, 0)
self.assertEqual(
comparison.diff_url,
"https://github.com/jacquev6/PyGithub/compare/v0.6...v0.7.diff",
)
self.assertEqual(
comparison.html_url,
"https://github.com/jacquev6/PyGithub/compare/v0.6...v0.7",
)
self.assertEqual(
comparison.url,
"https://api.github.com/repos/jacquev6/PyGithub/compare/v0.6...v0.7",
)
self.assertEqual(
comparison.patch_url,
"https://github.com/jacquev6/PyGithub/compare/v0.6...v0.7.patch",
)
self.assertEqual(
comparison.permalink_url,
"https://github.com/jacquev6/PyGithub/compare/jacquev6:4303c5b...jacquev6:ecda065",
)
self.assertEqual(comparison.total_commits, 4)
self.assertListKeyEqual(
comparison.files,
lambda f: f.filename,
[
"ReferenceOfClasses.md",
"github/Github.py",
"github/Requester.py",
"setup.py",
],
)
self.assertEqual(comparison.base_commit.sha, "4303c5b90e2216d927155e9609436ccb8984c495")
self.assertListKeyEqual(
comparison.commits,
lambda c: c.sha,
[
"5bb654d26dd014d36794acd1e6ecf3736f12aad7",
"cb0313157bf904f2d364377d35d9397b269547a5",
"0cec0d25e606c023a62a4fc7cdc815309ebf6d16",
"ecda065e01876209d2bdf5fe4e91cee8ffaa9ff7",
],
)
def testCompareCommitPagination(self):
gh = github.Github(
auth=self.oauth_token,
per_page=4,
retry=self.retry,
pool_size=self.pool_size,
seconds_between_requests=self.seconds_between_requests,
seconds_between_writes=self.seconds_between_writes,
)
repo = gh.get_repo("PyGithub/PyGithub")
comparison = repo.compare("v1.54", "v1.54.1")
self.assertEqual(comparison.status, "ahead")
self.assertEqual(comparison.ahead_by, 10)
self.assertEqual(comparison.behind_by, 0)
self.assertEqual(comparison.total_commits, 10)
self.assertEqual(len(comparison.files), 228)
self.assertEqual(comparison.commits.totalCount, 10)
self.assertListKeyEqual(
comparison.commits,
lambda c: c.sha,
[
"fab682a5ccfc275c31ec37f1f541254c7bd780f3",
"9ee3afb1716c559a0b3b44e097c05f4b14ae2ab8",
"a806b5233f6423e0f8dacc4d04b6d81a72689bed",
"63e4fae997a9a5dc8c2b56907c87c565537bb28f",
"82c349ce3e1c556531110753831b3133334c19b7",
"2432cffd3b2f1a8e0b6b96d69b3dd4ded148a9f7",
"e113e37de1ec687c68337d777f3629251b35ab28",
"f299699ccd75910593d5ddf7cc6212f70c5c28b1",
"31a1c007808a4205bdae691385d2627c561e69ed",
"34d097ce473601624722b90fc5d0396011dd3acb",
],
)
def testGetComments(self):
self.assertListKeyEqual(
self.repo.get_comments(),
lambda c: c.body,
[
"probably a noob question: does this completion refer to autocompletion in IDE's/editors? \nI have observed that this is pretty erratic sometimes. I'm using PyDev+Eclipse.\nFor example, in the tutorial from the readme, `g.get_u` gets autocompleted correctly, but `g.get_user().get_r` (or any method or attribute applicable to NamedUsers/AuthenticatedUser, really) does not show autocompletion to `g.get_user().get_repo()`. Is that by design? It makes exploring the library/API a bit cumbersome. ",
"No, it has nothing to do with auto-completion in IDEs :D\n\nGithub API v3 sends only the main part of objects in reply to some requests. So, if the user wants an attribute that has not been received yet, I have to do another request to complete the object.\n\nYet, in version 1.0 (see the milesone), my library will be much more readable for IDEs and their auto-completion mechanisms, because I am giving up the meta-description that I used until 0.6, and I'm now generating much more traditional code, that you will be able to explore as if it was written manually.\n\nIf you want to take the time to open an issue about auto-completion in IDEs, I'll deal with it in milestone 1.0.\n\nThanks !",
"Ah, thanks for the clarification. :blush:\n\nI made issue #27 for the autocompletion. I already suspected something like this meta-description magic, since I tried to read some of the code and it was pretty arcane. I attributed that to my pythonic noobness, though. Thank you. ",
"Comment created by PyGithub",
],
)
def testGetCommits(self):
self.assertListKeyBegin(
self.repo.get_commits(),
lambda c: c.sha,
[
"ecda065e01876209d2bdf5fe4e91cee8ffaa9ff7",
"0cec0d25e606c023a62a4fc7cdc815309ebf6d16",
"cb0313157bf904f2d364377d35d9397b269547a5",
"5bb654d26dd014d36794acd1e6ecf3736f12aad7",
"4303c5b90e2216d927155e9609436ccb8984c495",
"2a7e80e6421c5d4d201d60619068dea6bae612cb",
"0af24499a98e85f8ab2191898e8b809e5cebd4c5",
"e5ae923a68a9ae295ce5aa20b1227253de60e918",
"2f64b625f7e2afc9bef61d0decb459e2ef65c550",
"590798d349cba7de6e83b43aa5d4f8b0a38e685d",
"e7dca9143a23b8e2045a4a910a4a329007b10086",
"ab3f9b422cb3043d35cf6002fc9c042f8ead8c2a",
"632d8b63c32a2b79e87eb3b93e1ad228724de4bd",
"64c6a1e975e61b9c1449bed016cd19f33ee4b1c5",
"99963536fc81db3b9986c761b9dd08de22089aa2",
"8d57522bbd15d1fb6b616fae795cd8721deb1c4d",
"1140a91f3e45d09bc15463724f178a7ebf8e3149",
"936f4a97f1a86392637ec002bbf89ff036a5062d",
"e10470481795506e2c232720e2a9ecf588c8b567",
"e456549e5265406f8090ae5145255c8ca9ea5e4e",
"a91131be42eb328ae030f584af500f56aa08424b",
"2469c6e1aeb7919126a8271f6980b555b167e8b0",
"a655d0424135befd3a0d53f3f7eff2d1c754854f",
"ce62e91268aa34dad0ba0dbee4769933e3a71e50",
"1c88ee221b7f995855a1fdfac7d0ba19db918739",
"bd1a5dff3c547c634b2d89f5847218820e343883",
"b226b5b4e2f44107dde674e7a5d3e88d4e3518df",
"25dbd4053e982402c7d92139f167dbe46008c932",
"a0cc821c1beada4aa9ca0d5218664c5372720936",
"c1440bdf20bfeb62684c6d1779448719dce9d2df",
"1095d304b7fab3818dcb4c42093c8c56d3ac05e4",
"bd39726f7cf86ea7ffb33b5718241fdab5fc8f53",
"1d2b27824d20612066d84be42d6691c66bb18ef4",
"6af2bfd0d46bc0eeb8c37b85c7b3003e0e4ae297",
"a475d685d8ae709095d09094ea0962ac182d33f0",
"a85de99ea5b5e7b38bd68e076d09c49207b8687e",
"d24cf209ddd1758188c5f35344f76df818d09a46",
"0909fec395bb1f97e2580d6a029cfc64b352aff9",
"6e421e9e85e12008758870bc046bc2c6120af72a",
"32ed0ebc377efbed5b482b3d49ff54bf1715d55a",
"8213df1d744f251aa8e52229643a9f6ce352f3c0",
"69cc298fd159f19eb204dd09f17d31dc4abc3d41",
"85eef756353e13efcb24c726320cd2617c2a7bd8",
"50ac55b25ceba555b84709839f80447552450697",
"767d75a580279e457f9bc52bc308a17ff8ea0509",
"75e72ffa3066693291f7da03070666e8f885097a",
"504047e218e6b34a3828ccc408431634f17b9504",
"960db1d5c9853e9f5fbbc9237c2c166ceef1f080",
"877dde23e140bbf038f9a2d8f0f07b4e3a965c61",
"1c95ddfa09ec0aa1f07ee9ad50a77be1dd74b55e",
"99564c1cab139d1e4678f5f83f60d26f1210db7e",
"231926207709ceaa61e87b64e34e17d85adecd9c",
"fb722625dddb9a32f75190723f7da12683b7c4b2",
"cab9d71603e127bdd1f600a759dccea1781fa1ab",
"e648e5aeb5edc1fbf83e9d37d2a3cb57c005019a",
"4a5cf98e7f959f1b5d9af484760c25cd27d9180d",
"5d1add448e0b0b1dadb8c6094a9e5e19b255f67e",
"0d9fc99a4b5d1ec6473c9c81c888917c132ffa65",
"b56aa09011378b014221f86dffb8304957a9e6bd",
"3e8169c0a98ce1e2c6a32ae1256ae0f735065df5",
"378558f6cac6183b4a7100c0ce5eaad1cfff6717",
"58b4396aa0e7cb72911b75cb035798143a06e0ee",
"a3be28756101370fbc689eec3a7825c4c385a6c9",
"3d6bd49ce229243fea4bb46a937622d0ec7d4d1c",
"58cb0dbdef9765e0e913c726f923a47315aaf80e",
"7b7ac20c6fa27f72a24483c73ab1bf4deffc89f0",
"97f308e67383368a2d15788cac28e126c8528bb2",
"fc33a6de4f0e08d7ff2de05935517ec3932d212e",
"cc6d0fc044eadf2e6fde5da699f61654c1e691f3",
"2dd71f3777b87f2ba61cb20d2c67f10401e3eb2c",
"366ca58ca004b9129f9d435db8204ce0f5bc57c3",
"0d3b3ffd1e5c143af8725fdee808101f626f683d",
"157f9c13275738b6b39b8d7a874f5f0aee47cb18",
],
)
def testGetCommitsWithArguments(self):
self.assertListKeyEqual(
self.repo.get_commits("topic/RewriteWithGeneratedCode", "codegen/GenerateCode.py"),
lambda c: c.sha,
[
"de386d5dc9cf103c90c4128eeca0e6abdd382065",
"5b44982f6111bff2454243869df2e1c3086ccbba",
"d6835ff949141957a733c8ddfa147026515ae493",
"075d3d961d4614a2a0835d5583248adfc0687a7d",
"8956796e7f462a49f499eac52fab901cdb59abdb",
"283da5e7de6a4a3b6aaae7045909d70b643ad380",
"d631e83b7901b0a0b6061b361130700a79505319",
],
)
def testGetCommitsWithSinceUntil(self):
self.assertListKeyEqual(
self.repo.get_commits(
since=datetime(2013, 3, 1),
until=datetime(2013, 3, 31),
),
lambda c: c.sha,
[
"db5560bd658b5d8057a864f7037ace4d5f618f1b",
"f266fed520fea4f683caabe0b38e1f758cfc5cff",
"dff094650011398fd8f0a57bf2668a066fb2cbcb",
"c1d747a9133a1c6cae1f0e11105a5f490f65fda6",
"0bc368973acfb50a531329b6c196ba92e0a81890",
"7b3e4c15ed6182963d66ffa9f0522acd0765275c",
"4df3a7eb47888f38c4c6dae50573f030a0a3f1e1",
"e0db8cad4ec01c65e5e0eb50e11765e425e88ef9",
"1c47be4e895b823baf907b25c647e43ab63c16dd",
"8a9afbb1aa36c6ba04142c6e6c1cfbd7de982a6a",
"1c67359a318f05e50bf457818e1983ce95aa5946",
"1d18bd66f3a4a4225435bd38df04b8a227b5e821",
"b9d71fa787a2ffb99b6631e4bd6df932a4d4adbb",
"f5d8e221d116b74a200d87afca32247f01204ba1",
"dc96fef052f2b5c6adb34da65169e8df3f35f611",
"c85af79db11ed1d2f93261ea4069a23ff1709125",
"0dd1adb4f06f45d554d12083b312fcdb6f6be8d1",
"b7e4000450e89b8c6e947e3a1e52fb06da7c9621",
"1d9ad14fa918866c418067e774f65cede8e38682",
"1bb05fef01d0a040cb2b931a4d44392784a2f0c1",
"d9b29851ddccc907f71f1ae662e57f2cd7c7dc71",
"f962bc71fee609cd54fe69c956c8b81703d2c19a",
"7a9c0b916c632be8d6a65bc1b6f558508f04bb22",
"82ce7b1ee30d308b48bdac6d8737dbca70500462",
"1e99e7d5b21c71bf68cc5cc21faec30ee603b8b8",
"a397fac6db9f87a903ec3ede9643cb2b4224ed82",
"109495175e926731703a55cafd8b542a07366513",
"da6bbdb69485fc3256030d8296589d4c2fb5df21",
"34c18342dcce9697abc6f522c3506485202e6e7e",
"ee29deddd27480401db484733ecde9e7b1df5eda",
"0901df1a2bed3f993cfe6e0d4cff5923bbf6ce32",
"edcf40bc7f25d1aff5c404406fbb37ad1bcf691e",
"f25c54e1d4eefb11c18f3de85270a4b19edea3ce",
"23d668f11bdd806a871e0979bf5295d001f66ef2",
"50a243671f1fa139cb1186c4a44c1e96b8cd5749",
"6a3a384fd0decac1203db6c2bddc58039b0390bc",
"82f5b4c61f86ae8c7cc85a31cb1a31180eeae32f",
"6ac783974d3985dd0c162c1e8d1150615cc0082e",
"0f9bb5d9fd2dcfbf03f094362e86323c9ef915e6",
"e25a6a49d1ab1a10c84db9b6722a6186ff6dfcbd",
"4f1780f427eba400cbc06897e69eda0ecdecd887",
"28648a51a15e430b85d6fe8f2514e1cb06bc76b8",
"a39f421ca24bd7aae984f8703159c7e30798a121",
"86fe370b97b62548317cb35bc02ece3fabb7fa03",
"03a256a4052cacea998d8205a83d5b5465f31e18",
"9e6b086c2db5e4884484a04934f6f2e53e3f441b",
"0ddb34d987b5a03813fdfa2fac13c933834a4804",
],
)
def testGetCommitsWithAuthor(self):
self.g.per_page = 5
akfish = self.g.get_user("AKFish")
self.assertListKeyBegin(
self.repo.get_commits(author=self.user),
lambda c: c.sha,
["54f718a15770579a37ffbe7ae94ad30003407786"],
)
self.assertListKeyBegin(
self.repo.get_commits(author=akfish),
lambda c: c.sha,
["38b137fb37c0fdc74f8802a4184518e105db9121"],
)
self.assertListKeyBegin(
self.repo.get_commits(author="m.ki2@laposte.net"),
lambda c: c.sha,
["ab674dfcbc86c70bc32d9ecbe171b48a5694c337"],
)
def testGetDownloads(self):
self.assertListKeyEqual(self.repo.get_downloads(), lambda d: d.id, [245143])
def testGetEvents(self):
self.assertListKeyBegin(
self.repo.get_events(),
lambda e: e.type,
[
"DownloadEvent",
"DownloadEvent",
"PushEvent",
"IssuesEvent",
"MemberEvent",
"MemberEvent",
],
)
def testGetForks(self):
self.assertListKeyEqual(self.repo.get_forks(), lambda r: r.owner.login, ["abersager"])
def testCreateFork(self):
self.assertEqual(self.repo.create_fork("prtg-dev").full_name, "prtg-dev/PyGithub")
def testCreateForkOrg(self):
c = self.g.get_organization("prtg-dev")
self.assertEqual(self.repo.create_fork(c).full_name, "prtg-dev/PyGithub")
def testGetGitRefs(self):
self.assertListKeyEqual(
self.repo.get_git_refs(),
lambda r: r.ref,
[
"refs/heads/develop",
"refs/heads/master",
"refs/heads/topic/DependencyGraph",
"refs/heads/topic/RewriteWithGeneratedCode",
"refs/tags/v0.1",
"refs/tags/v0.2",
"refs/tags/v0.3",
"refs/tags/v0.4",
"refs/tags/v0.5",
"refs/tags/v0.6",
"refs/tags/v0.7",
],
)
def testGetGitRef(self):
self.assertTrue(self.g.FIX_REPO_GET_GIT_REF)
self.assertEqual(
self.repo.get_git_ref("heads/master").object.sha,
"31110327ec45f3138e58ed247b2cf420fee481ec",
)
def testGetGitRefWithIssue102Reverted(self):
self.g.FIX_REPO_GET_GIT_REF = False
self.assertFalse(self.g.FIX_REPO_GET_GIT_REF)
self.assertEqual(
self.repo.get_git_ref("refs/heads/master").object.sha,
"31110327ec45f3138e58ed247b2cf420fee481ec",
)
self.g.FIX_REPO_GET_GIT_REF = True
self.assertTrue(self.g.FIX_REPO_GET_GIT_REF)
def testGetGitTreeWithRecursive(self):
tree = self.repo.get_git_tree("f492784d8ca837779650d1fb406a1a3587a764ad", True)
self.assertEqual(len(tree.tree), 90)
self.assertEqual(tree.tree[50].path, "github/GithubObjects/Gist.py")
def testGetHooks(self):
self.assertListKeyEqual(self.repo.get_hooks(), lambda h: h.id, [257993])
def testGetHookDelivery(self):
delivery = self.repo.get_hook_delivery(257993, 12345)
self.assertEqual(delivery.id, 12345)
self.assertEqual(delivery.guid, "abcde-12345")