Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check that user lists contain at least 1 user #4233

Merged
merged 2 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,20 @@ public void verify(HostingRequest request, HashSet<VerificationMessage> hostingI
String forkFrom = request.getRepositoryUrl();
List<String> users = request.getGithubUsers();

if (users != null && !users.isEmpty()) {
if (!users.isEmpty()) {
List<String> invalidUsers = new ArrayList<>();
for (String user : users) {
if (StringUtils.isBlank(user)) {
continue;
}

try {
GHUser ghUser = github.getUser(user.trim());
if (ghUser == null || !ghUser.getType().equalsIgnoreCase("user")) {
invalidUsers.add(user.trim());
}
} catch(IOException e) {
} catch (IOException e) {
invalidUsers.add(user.trim());
}
}

if (invalidUsers.size() > 0) {
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)));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ public void checkRequest(int issueID) throws IOException {
.append("\nHosting team members can host this request with `/hosting host`");
}

LOGGER.info(msg.toString());
if (!debug) {
LOGGER.info(msg.toString());
GitHub github = GitHub.connect();
GHIssue issue = github.getRepository(HOSTING_REPO_SLUG).getIssue(issueID);
issue.comment(msg.toString());
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 @@ -3,6 +3,7 @@
import io.jenkins.infra.repository_permissions_updater.KnownUsers;
import java.io.IOException;
import java.util.HashSet;
import java.util.List;
import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;

Expand All @@ -11,18 +12,23 @@ public class JenkinsProjectUserVerifier implements Verifier{
@Override
public void verify(HostingRequest request, HashSet<VerificationMessage> hostingIssues) throws IOException {

String missingInArtifactory = request.getJenkinsProjectUsers()
.stream().filter(user -> !KnownUsers.existsInArtifactory(user))
.collect(Collectors.joining(", "));
String missingInJira = request.getJenkinsProjectUsers()
.stream().filter(user -> !KnownUsers.existsInJira(user))
.collect(Collectors.joining(", "));
List<String> jenkinsProjectUsers = request.getJenkinsProjectUsers();
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));
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