Skip to content

Commit 7e985db

Browse files
authored
Merge pull request #111 from xocasdashdash/improve-collaborator-check
Improved how it checks for github collaborator access
2 parents d766e30 + 9440018 commit 7e985db

File tree

2 files changed

+6
-14
lines changed

2 files changed

+6
-14
lines changed

src/main/java/org/jenkinsci/plugins/pipeline/github/GitHubHelper.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,17 @@ private GitHubHelper() {
3636
// go away
3737
}
3838

39-
public static List<String> getCollaborators(@Nonnull final Job<?,?> job) {
39+
public static Boolean isAuthorized(@Nonnull final Job<?,?> job, @Nonnull final String User) {
4040
ExtendedGitHubClient client = getGitHubClient(job);
4141
RepositoryId repository = getRepositoryId(job);
4242
CollaboratorService collaboratorService = new CollaboratorService(client);
4343

4444
try {
45-
return collaboratorService.getCollaborators(repository)
46-
.stream()
47-
.map(User::getLogin)
48-
.collect(Collectors.toList());
45+
return collaboratorService.isCollaborator(repository, User);
4946
} catch (final IOException e) {
50-
LOG.debug("Received an exception while trying to retrieve the collaborators for the repository: {}",
51-
repository, e);
52-
return Collections.emptyList();
47+
LOG.debug("Received an exception while trying to check if user {} is a collaborator of repository: {}",
48+
User, repository, e);
49+
return false;
5350
}
5451
}
5552

src/main/java/org/jenkinsci/plugins/pipeline/github/trigger/GitHubEventSubscriber.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,7 @@ private void handleIssueComment(final GHSubscriberEvent event) {
172172
}
173173

174174
private boolean isAuthorized(final WorkflowJob job, final String commentAuthor) {
175-
return GitHubHelper.getCollaborators(job)
176-
.stream()
177-
.filter(commentAuthor::equals)
178-
.findAny()
179-
.map(a -> Boolean.TRUE)
180-
.orElse(Boolean.FALSE);
175+
return GitHubHelper.isAuthorized(job, commentAuthor);
181176
}
182177

183178
private boolean triggerMatches(final IssueCommentTrigger trigger,

0 commit comments

Comments
 (0)