-
Notifications
You must be signed in to change notification settings - Fork 736
/
GHRepository.java
3438 lines (3147 loc) · 104 KB
/
GHRepository.java
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
/*
* The MIT License
*
* Copyright (c) 2010, Kohsuke Kawaguchi
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.kohsuke.github;
import com.fasterxml.jackson.annotation.JsonProperty;
import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import org.apache.commons.lang3.StringUtils;
import org.kohsuke.github.function.InputStreamFunction;
import org.kohsuke.github.internal.EnumUtils;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.InterruptedIOException;
import java.io.Reader;
import java.net.URL;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.WeakHashMap;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import static java.util.Arrays.asList;
import static java.util.Objects.requireNonNull;
// TODO: Auto-generated Javadoc
/**
* A repository on GitHub.
*
* @author Kohsuke Kawaguchi
*/
@SuppressWarnings({ "UnusedDeclaration" })
@SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD" },
justification = "JSON API")
public class GHRepository extends GHObject {
/**
* Create default GHRepository instance
*/
public GHRepository() {
}
private String nodeId, description, homepage, name, full_name;
private String html_url; // this is the UI
/*
* The license information makes use of the preview API.
*
* See: https://developer.github.com/v3/licenses/
*/
private GHLicense license;
private String git_url, ssh_url, clone_url, svn_url, mirror_url;
private GHUser owner; // not fully populated. beware.
private boolean has_issues, has_wiki, fork, has_downloads, has_pages, archived, disabled, has_projects;
private boolean allow_squash_merge;
private boolean allow_merge_commit;
private boolean allow_rebase_merge;
private boolean allow_forking;
private boolean delete_branch_on_merge;
@JsonProperty("private")
private boolean _private;
private String visibility;
private int forks_count, stargazers_count, watchers_count, size, open_issues_count, subscribers_count;
private String pushed_at;
private Map<Integer, GHMilestone> milestones = Collections.synchronizedMap(new WeakHashMap<>());
private String default_branch, language;
private GHRepository template_repository;
private Map<String, GHCommit> commits = Collections.synchronizedMap(new WeakHashMap<>());
@SkipFromToString
private GHRepoPermission permissions;
private GHRepository source, parent;
private Boolean isTemplate;
private boolean compareUsePaginatedCommits;
/**
* Read.
*
* @param root
* the root
* @param owner
* the owner
* @param name
* the name
* @return the GH repository
* @throws IOException
* Signals that an I/O exception has occurred.
*/
static GHRepository read(GitHub root, String owner, String name) throws IOException {
return root.createRequest().withUrlPath("/repos/" + owner + '/' + name).fetch(GHRepository.class);
}
/**
* Create deployment gh deployment builder.
*
* @param ref
* the ref
* @return the gh deployment builder
*/
public GHDeploymentBuilder createDeployment(String ref) {
return new GHDeploymentBuilder(this, ref);
}
/**
* List deployments paged iterable.
*
* @param sha
* the sha
* @param ref
* the ref
* @param task
* the task
* @param environment
* the environment
* @return the paged iterable
*/
public PagedIterable<GHDeployment> listDeployments(String sha, String ref, String task, String environment) {
return root().createRequest()
.with("sha", sha)
.with("ref", ref)
.with("task", task)
.with("environment", environment)
.withUrlPath(getApiTailUrl("deployments"))
.toIterable(GHDeployment[].class, item -> item.wrap(this));
}
/**
* Obtains a single {@link GHDeployment} by its ID.
*
* @param id
* the id
* @return the deployment
* @throws IOException
* the io exception
*/
public GHDeployment getDeployment(long id) throws IOException {
return root().createRequest()
.withUrlPath(getApiTailUrl("deployments/" + id))
.fetch(GHDeployment.class)
.wrap(this);
}
static class GHRepoPermission {
boolean pull, push, admin;
}
/**
* Gets node id.
*
* @return the node id
*/
public String getNodeId() {
return nodeId;
}
/**
* Gets description.
*
* @return the description
*/
public String getDescription() {
return description;
}
/**
* Gets homepage.
*
* @return the homepage
*/
public String getHomepage() {
return homepage;
}
/**
* Gets the git:// URL to this repository, such as "git://github.com/kohsuke/jenkins.git" This URL is read-only.
*
* @return the git transport url
*/
public String getGitTransportUrl() {
return git_url;
}
/**
* Gets the HTTPS URL to this repository, such as "https://github.com/kohsuke/jenkins.git" This URL is read-only.
*
* @return the http transport url
*/
public String getHttpTransportUrl() {
return clone_url;
}
/**
* Gets the Subversion URL to access this repository: https://github.com/rails/rails
*
* @return the svn url
*/
public String getSvnUrl() {
return svn_url;
}
/**
* Gets the Mirror URL to access this repository: https://github.com/apache/tomee mirrored from
* git://git.apache.org/tomee.git
*
* @return the mirror url
*/
public String getMirrorUrl() {
return mirror_url;
}
/**
* Gets the SSH URL to access this repository, such as [email protected]:rails/rails.git
*
* @return the ssh url
*/
public String getSshUrl() {
return ssh_url;
}
/**
* Gets the html url.
*
* @return the html url
*/
public URL getHtmlUrl() {
return GitHubClient.parseURL(html_url);
}
/**
* Short repository name without the owner. For example 'jenkins' in case of http://github.com/jenkinsci/jenkins
*
* @return the name
*/
public String getName() {
return name;
}
/**
* Full repository name including the owner or organization. For example 'jenkinsci/jenkins' in case of
* http://github.com/jenkinsci/jenkins
*
* @return the full name
*/
public String getFullName() {
return full_name;
}
/**
* Has pull access boolean.
*
* @return the boolean
*/
public boolean hasPullAccess() {
return permissions != null && permissions.pull;
}
/**
* Has push access boolean.
*
* @return the boolean
*/
public boolean hasPushAccess() {
return permissions != null && permissions.push;
}
/**
* Has admin access boolean.
*
* @return the boolean
*/
public boolean hasAdminAccess() {
return permissions != null && permissions.admin;
}
/**
* Gets the primary programming language.
*
* @return the language
*/
public String getLanguage() {
return language;
}
/**
* Gets owner.
*
* @return the owner
* @throws IOException
* the io exception
*/
@SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected behavior")
public GHUser getOwner() throws IOException {
return isOffline() ? owner : root().getUser(getOwnerName()); // because 'owner' isn't fully populated
}
/**
* Gets issue.
*
* @param id
* the id
* @return the issue
* @throws IOException
* the io exception
*/
public GHIssue getIssue(int id) throws IOException {
return root().createRequest().withUrlPath(getApiTailUrl("issues/" + id)).fetch(GHIssue.class).wrap(this);
}
/**
* Create issue gh issue builder.
*
* @param title
* the title
* @return the gh issue builder
*/
public GHIssueBuilder createIssue(String title) {
return new GHIssueBuilder(this, title);
}
/**
* Gets issues.
*
* @param state
* the state
* @return the issues
* @throws IOException
* the io exception
*/
public List<GHIssue> getIssues(GHIssueState state) throws IOException {
return queryIssues().state(state).list().toList();
}
/**
* Gets issues.
*
* @param state
* the state
* @param milestone
* the milestone
* @return the issues
* @throws IOException
* the io exception
*/
public List<GHIssue> getIssues(GHIssueState state, GHMilestone milestone) throws IOException {
return queryIssues().milestone(milestone == null ? "none" : "" + milestone.getNumber())
.state(state)
.list()
.toList();
}
/**
* Retrieves issues.
*
* @return the gh issue query builder
*/
public GHIssueQueryBuilder.ForRepository queryIssues() {
return new GHIssueQueryBuilder.ForRepository(this);
}
/**
* Create release gh release builder.
*
* @param tag
* the tag
* @return the gh release builder
*/
public GHReleaseBuilder createRelease(String tag) {
return new GHReleaseBuilder(this, tag);
}
/**
* Creates a named ref, such as tag, branch, etc.
*
* @param name
* The name of the fully qualified reference (ie: refs/heads/main). If it doesn't start with 'refs' and
* have at least two slashes, it will be rejected.
* @param sha
* The SHA1 value to set this reference to
* @return the gh ref
* @throws IOException
* the io exception
*/
public GHRef createRef(String name, String sha) throws IOException {
return root().createRequest()
.method("POST")
.with("ref", name)
.with("sha", sha)
.withUrlPath(getApiTailUrl("git/refs"))
.fetch(GHRef.class);
}
/**
* Gets release.
*
* @param id
* the id
* @return the release
* @throws IOException
* the io exception
*/
public GHRelease getRelease(long id) throws IOException {
try {
return root().createRequest()
.withUrlPath(getApiTailUrl("releases/" + id))
.fetch(GHRelease.class)
.wrap(this);
} catch (FileNotFoundException e) {
return null; // no release for this id
}
}
/**
* Gets release by tag name.
*
* @param tag
* the tag
* @return the release by tag name
* @throws IOException
* the io exception
*/
public GHRelease getReleaseByTagName(String tag) throws IOException {
try {
return root().createRequest()
.withUrlPath(getApiTailUrl("releases/tags/" + tag))
.fetch(GHRelease.class)
.wrap(this);
} catch (FileNotFoundException e) {
return null; // no release for this tag
}
}
/**
* Gets latest release.
*
* @return the latest release
* @throws IOException
* the io exception
*/
public GHRelease getLatestRelease() throws IOException {
try {
return root().createRequest()
.withUrlPath(getApiTailUrl("releases/latest"))
.fetch(GHRelease.class)
.wrap(this);
} catch (FileNotFoundException e) {
return null; // no latest release
}
}
/**
* List releases paged iterable.
*
* @return the paged iterable
* @throws IOException
* the io exception
*/
public PagedIterable<GHRelease> listReleases() throws IOException {
return root().createRequest()
.withUrlPath(getApiTailUrl("releases"))
.toIterable(GHRelease[].class, item -> item.wrap(this));
}
/**
* List tags paged iterable.
*
* @return the paged iterable
* @throws IOException
* the io exception
*/
public PagedIterable<GHTag> listTags() throws IOException {
return root().createRequest()
.withUrlPath(getApiTailUrl("tags"))
.toIterable(GHTag[].class, item -> item.wrap(this));
}
/**
* List languages for the specified repository. The value on the right of a language is the number of bytes of code
* written in that language. { "C": 78769, "Python": 7769 }
*
* @return the map
* @throws IOException
* the io exception
*/
public Map<String, Long> listLanguages() throws IOException {
HashMap<String, Long> result = new HashMap<>();
root().createRequest().withUrlPath(getApiTailUrl("languages")).fetch(HashMap.class).forEach((key, value) -> {
Long addValue = -1L;
if (value instanceof Integer) {
addValue = Long.valueOf((Integer) value);
}
result.put(key.toString(), addValue);
});
return result;
}
/**
* Gets owner name.
*
* @return the owner name
*/
public String getOwnerName() {
// consistency of the GitHub API is super... some serialized forms of GHRepository populate
// a full GHUser while others populate only the owner and email. This later form is super helpful
// in putting the login in owner.name not owner.login... thankfully we can easily identify this
// second set because owner.login will be null
return owner.login != null ? owner.login : owner.name;
}
/**
* Has issues boolean.
*
* @return the boolean
*/
public boolean hasIssues() {
return has_issues;
}
/**
* Has projects boolean.
*
* @return the boolean
*/
public boolean hasProjects() {
return has_projects;
}
/**
* Has wiki boolean.
*
* @return the boolean
*/
public boolean hasWiki() {
return has_wiki;
}
/**
* Is fork boolean.
*
* @return the boolean
*/
public boolean isFork() {
return fork;
}
/**
* Is archived boolean.
*
* @return the boolean
*/
public boolean isArchived() {
return archived;
}
/**
* Is disabled boolean.
*
* @return the boolean
*/
public boolean isDisabled() {
return disabled;
}
/**
* Is allow squash merge boolean.
*
* @return the boolean
*/
public boolean isAllowSquashMerge() {
return allow_squash_merge;
}
/**
* Is allow merge commit boolean.
*
* @return the boolean
*/
public boolean isAllowMergeCommit() {
return allow_merge_commit;
}
/**
* Is allow rebase merge boolean.
*
* @return the boolean
*/
public boolean isAllowRebaseMerge() {
return allow_rebase_merge;
}
/**
* Is allow private forks
*
* @return the boolean
*/
public boolean isAllowForking() {
return allow_forking;
}
/**
* Automatically deleting head branches when pull requests are merged.
*
* @return the boolean
*/
public boolean isDeleteBranchOnMerge() {
return delete_branch_on_merge;
}
/**
* Returns the number of all forks of this repository. This not only counts direct forks, but also forks of forks,
* and so on.
*
* @return the forks
*/
public int getForksCount() {
return forks_count;
}
/**
* Gets stargazers count.
*
* @return the stargazers count
*/
public int getStargazersCount() {
return stargazers_count;
}
/**
* Is private boolean.
*
* @return the boolean
*/
public boolean isPrivate() {
return _private;
}
/**
* Visibility of a repository.
*/
public enum Visibility {
/** The public. */
PUBLIC,
/** The internal. */
INTERNAL,
/** The private. */
PRIVATE,
/**
* Placeholder for unexpected data values.
*
* This avoids throwing exceptions during data binding or reading when the list of allowed values returned from
* GitHub is expanded.
*
* Do not pass this value to any methods. If this value is returned during a request, check the log output and
* report an issue for the missing value.
*/
UNKNOWN;
/**
* From.
*
* @param value
* the value
* @return the visibility
*/
public static Visibility from(String value) {
return EnumUtils.getNullableEnumOrDefault(Visibility.class, value, Visibility.UNKNOWN);
}
/**
* To string.
*
* @return the string
*/
@Override
public String toString() {
return name().toLowerCase(Locale.ROOT);
}
}
/**
* Gets the visibility of the repository.
*
* @return the visibility
*/
public Visibility getVisibility() {
if (visibility == null) {
try {
populate();
} catch (final IOException e) {
// Convert this to a runtime exception to avoid messy method signature
throw new GHException("Could not populate the visibility of the repository", e);
}
}
return Visibility.from(visibility);
}
/**
* Is template boolean.
*
* @return the boolean
*/
public boolean isTemplate() {
if (isTemplate == null) {
try {
populate();
} catch (IOException e) {
// Convert this to a runtime exception to avoid messy method signature
throw new GHException("Could not populate the template setting of the repository", e);
}
// if this somehow is not populated, set it to false;
isTemplate = Boolean.TRUE.equals(isTemplate);
}
return isTemplate;
}
/**
* Has downloads boolean.
*
* @return the boolean
*/
public boolean hasDownloads() {
return has_downloads;
}
/**
* Has pages boolean.
*
* @return the boolean
*/
public boolean hasPages() {
return has_pages;
}
/**
* Gets the count of watchers.
*
* @return the watchers
*/
public int getWatchersCount() {
return watchers_count;
}
/**
* Gets open issue count.
*
* @return the open issue count
*/
public int getOpenIssueCount() {
return open_issues_count;
}
/**
* Gets subscribers count.
*
* @return the subscribers count
*/
public int getSubscribersCount() {
return subscribers_count;
}
/**
* Gets pushed at.
*
* @return null if the repository was never pushed at.
*/
public Date getPushedAt() {
return GitHubClient.parseDate(pushed_at);
}
/**
* Returns the primary branch you'll configure in the "Admin > Options" config page.
*
* @return This field is null until the user explicitly configures the default branch.
*/
public String getDefaultBranch() {
return default_branch;
}
/**
* Get Repository template was the repository created from.
*
* @return the repository template
*/
@SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected")
public GHRepository getTemplateRepository() {
return (GHRepository) template_repository;
}
/**
* Gets size.
*
* @return the size
*/
public int getSize() {
return size;
}
/**
* Affiliation of a repository collaborator.
*/
public enum CollaboratorAffiliation {
/** The all. */
ALL,
/** The direct. */
DIRECT,
/** The outside. */
OUTSIDE
}
/**
* Gets the collaborators on this repository. This set always appear to include the owner.
*
* @return the collaborators
* @throws IOException
* the io exception
*/
public GHPersonSet<GHUser> getCollaborators() throws IOException {
return new GHPersonSet<GHUser>(listCollaborators().toList());
}
/**
* Lists up the collaborators on this repository.
*
* @return Users paged iterable
* @throws IOException
* the io exception
*/
public PagedIterable<GHUser> listCollaborators() throws IOException {
return listUsers("collaborators");
}
/**
* Lists up the collaborators on this repository.
*
* @param affiliation
* Filter users by affiliation
* @return Users paged iterable
* @throws IOException
* the io exception
*/
public PagedIterable<GHUser> listCollaborators(CollaboratorAffiliation affiliation) throws IOException {
return listUsers(root().createRequest().with("affiliation", affiliation), "collaborators");
}
/**
* Lists all
* <a href= "https://help.github.com/articles/assigning-issues-and-pull-requests-to-other-github-users/">the
* available assignees</a> to which issues may be assigned.
*
* @return the paged iterable
* @throws IOException
* the io exception
*/
public PagedIterable<GHUser> listAssignees() throws IOException {
return listUsers("assignees");
}
/**
* Checks if the given user is an assignee for this repository.
*
* @param u
* the u
* @return the boolean
* @throws IOException
* the io exception
*/
public boolean hasAssignee(GHUser u) throws IOException {
return root().createRequest().withUrlPath(getApiTailUrl("assignees/" + u.getLogin())).fetchHttpStatusCode()
/ 100 == 2;
}
/**
* Gets the names of the collaborators on this repository. This method deviates from the principle of this library
* but it works a lot faster than {@link #getCollaborators()}.
*
* @return the collaborator names
* @throws IOException
* the io exception
*/
public Set<String> getCollaboratorNames() throws IOException {
Set<String> r = new HashSet<>();
// no initializer - we just want to the logins
PagedIterable<GHUser> users = root().createRequest()
.withUrlPath(getApiTailUrl("collaborators"))
.toIterable(GHUser[].class, null);
for (GHUser u : users.toArray()) {
r.add(u.login);
}
return r;
}
/**
* Gets the names of the collaborators on this repository. This method deviates from the principle of this library
* but it works a lot faster than {@link #getCollaborators()}.
*
* @param affiliation
* Filter users by affiliation
* @return the collaborator names
* @throws IOException
* the io exception
*/
public Set<String> getCollaboratorNames(CollaboratorAffiliation affiliation) throws IOException {
Set<String> r = new HashSet<>();
// no initializer - we just want to the logins
PagedIterable<GHUser> users = root().createRequest()
.withUrlPath(getApiTailUrl("collaborators"))
.with("affiliation", affiliation)
.toIterable(GHUser[].class, null);
for (GHUser u : users.toArray()) {
r.add(u.login);
}
return r;
}
/**
* Checks if the given user is a collaborator for this repository.
*
* @param user
* a {@link GHUser}
* @return true if the user is a collaborator for this repository
* @throws IOException
* the io exception
*/
public boolean isCollaborator(GHUser user) throws IOException {
return root().createRequest()
.withUrlPath(getApiTailUrl("collaborators/" + user.getLogin()))
.fetchHttpStatusCode() == 204;
}
/**
* Obtain permission for a given user in this repository.
*
* @param user
* a {@link GHUser#getLogin}
* @return the permission
* @throws IOException
* the io exception
*/
public GHPermissionType getPermission(String user) throws IOException {
GHPermission perm = root().createRequest()
.withUrlPath(getApiTailUrl("collaborators/" + user + "/permission"))
.fetch(GHPermission.class);