Skip to content

Commit

Permalink
trim list when assigning in HostingRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
mawinter69 committed Dec 20, 2024
1 parent 4d748e4 commit 5faf9ae
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,22 @@ public void verify(HostingRequest request, HashSet<VerificationMessage> hostingI
String forkFrom = request.getRepositoryUrl();
List<String> users = request.getGithubUsers();

if (users != null) {
users = users.stream().filter(it -> !it.trim().isEmpty()).toList();
if (!users.isEmpty()) {
List<String> invalidUsers = new ArrayList<>();
for (String user : users) {
try {
GHUser ghUser = github.getUser(user.trim());
if (ghUser == null || !ghUser.getType().equalsIgnoreCase("user")) {
invalidUsers.add(user.trim());
}
} catch (IOException e) {
if (!users.isEmpty()) {
List<String> invalidUsers = new ArrayList<>();
for (String user : users) {
try {
GHUser ghUser = github.getUser(user.trim());
if (ghUser == null || !ghUser.getType().equalsIgnoreCase("user")) {
invalidUsers.add(user.trim());
}
} catch (IOException e) {
invalidUsers.add(user.trim());
}
}

if (!invalidUsers.isEmpty()) {
hostingIssues.add(new VerificationMessage(VerificationMessage.Severity.REQUIRED, "The following usernames in 'GitHub Users to Authorize as Committers' are not valid GitHub usernames or are Organizations: %s", String.join(",", invalidUsers)));
}
} else {
hostingIssues.add(new VerificationMessage(VerificationMessage.Severity.REQUIRED, "The Github users list is empty. Please specify at least one user."));
if (!invalidUsers.isEmpty()) {
hostingIssues.add(new VerificationMessage(VerificationMessage.Severity.REQUIRED, "The following usernames in 'GitHub Users to Authorize as Committers' are not valid GitHub usernames or are Organizations: %s", String.join(",", invalidUsers)));
}
} else {
hostingIssues.add(new VerificationMessage(VerificationMessage.Severity.REQUIRED, "The Github users list is empty. Please specify at least one user."));
}

if (StringUtils.isNotBlank(forkFrom)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public HostingRequest(
) {
this.repositoryUrl = repositoryUrl;
this.newRepoName = newRepoName;
this.githubUsers = Collections.unmodifiableList(githubUsers);
this.jenkinsProjectUsers = Collections.unmodifiableList(jenkinsProjectUsers);
this.githubUsers = Collections.unmodifiableList(trimList(githubUsers));
this.jenkinsProjectUsers = Collections.unmodifiableList(trimList(jenkinsProjectUsers));
this.issueTracker = issueTracker;
}

Expand Down Expand Up @@ -59,4 +59,9 @@ public static IssueTracker fromString(String string) {
return string.toLowerCase(Locale.ROOT).contains("git") ? GITHUB : JIRA;
}
}

private List<String> trimList(List<String> users) {
return users.stream().filter(it -> !it.trim().isEmpty()).toList();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,19 @@ public class JenkinsProjectUserVerifier implements Verifier{
public void verify(HostingRequest request, HashSet<VerificationMessage> hostingIssues) throws IOException {

List<String> jenkinsProjectUsers = request.getJenkinsProjectUsers();
if (jenkinsProjectUsers != null) {
jenkinsProjectUsers = jenkinsProjectUsers.stream().filter(it -> !it.trim().isEmpty()).toList();
if (!jenkinsProjectUsers.isEmpty()) {
String missingInArtifactory = jenkinsProjectUsers
.stream().filter(user -> !KnownUsers.existsInArtifactory(user))
.collect(Collectors.joining(", "));
String missingInJira = jenkinsProjectUsers
.stream().filter(user -> !KnownUsers.existsInJira(user))
.collect(Collectors.joining(", "));
if (!jenkinsProjectUsers.isEmpty()) {
String missingInArtifactory = jenkinsProjectUsers
.stream().filter(user -> !KnownUsers.existsInArtifactory(user))
.collect(Collectors.joining(", "));
String missingInJira = jenkinsProjectUsers
.stream().filter(user -> !KnownUsers.existsInJira(user))
.collect(Collectors.joining(", "));

if (StringUtils.isNotBlank(missingInArtifactory)) {
hostingIssues.add(new VerificationMessage(VerificationMessage.Severity.REQUIRED, "The following usernames in 'Jenkins project users to have release permission' need to log into [Artifactory](https://repo.jenkins-ci.org/): %s (reports are re-synced hourly, wait to re-check for a bit after logging in)", missingInArtifactory));
}
if (StringUtils.isNotBlank(missingInJira)) {
hostingIssues.add(new VerificationMessage(VerificationMessage.Severity.REQUIRED, "The following usernames in 'Jenkins project users to have release permission' need to log into [Jira](https://issues.jenkins.io): %s (reports are re-synced hourly, wait to re-check for a bit after logging in)", missingInJira));
}
} else {
hostingIssues.add(new VerificationMessage(VerificationMessage.Severity.REQUIRED, "The Jenkins project users list is empty. Please specify at least one user."));
if (StringUtils.isNotBlank(missingInArtifactory)) {
hostingIssues.add(new VerificationMessage(VerificationMessage.Severity.REQUIRED, "The following usernames in 'Jenkins project users to have release permission' need to log into [Artifactory](https://repo.jenkins-ci.org/): %s (reports are re-synced hourly, wait to re-check for a bit after logging in)", missingInArtifactory));
}
if (StringUtils.isNotBlank(missingInJira)) {
hostingIssues.add(new VerificationMessage(VerificationMessage.Severity.REQUIRED, "The following usernames in 'Jenkins project users to have release permission' need to log into [Jira](https://issues.jenkins.io): %s (reports are re-synced hourly, wait to re-check for a bit after logging in)", missingInJira));
}
} else {
hostingIssues.add(new VerificationMessage(VerificationMessage.Severity.REQUIRED, "The Jenkins project users list is empty. Please specify at least one user."));
Expand Down

0 comments on commit 5faf9ae

Please sign in to comment.