|
29 | 29 | import java.util.List;
|
30 | 30 | import java.util.Locale;
|
31 | 31 | import java.util.Map;
|
| 32 | +import java.util.Optional; |
32 | 33 | import java.util.concurrent.TimeUnit;
|
33 | 34 | import java.util.logging.Level;
|
34 | 35 | import java.util.logging.Logger;
|
| 36 | +import java.util.stream.Collectors; |
35 | 37 | import jenkins.scm.api.SCMSource;
|
36 | 38 | import jenkins.security.SlaveToMasterCallable;
|
37 | 39 | import jenkins.util.JenkinsJVM;
|
@@ -61,7 +63,7 @@ public class GitHubAppCredentials extends BaseStandardCredentials implements Sta
|
61 | 63 | private static final String ERROR_NOT_INSTALLED = ERROR_AUTHENTICATING_GITHUB_APP + NOT_INSTALLED;
|
62 | 64 | private static final String ERROR_NO_OWNER_MATCHING =
|
63 | 65 | "Found multiple installations for GitHub app ID %s but none match credential owner \"%s\". "
|
64 |
| - + "Set the right owner in the credential advanced options"; |
| 66 | + + "Set the right owner in the credential advanced options to one of: %s"; |
65 | 67 |
|
66 | 68 | /**
|
67 | 69 | * When a new {@link AppInstallationToken} is generated, wait this many seconds before continuing.
|
@@ -227,15 +229,21 @@ static AppInstallationToken generateAppInstallationToken(
|
227 | 229 | appInstallation = appInstallations.get(0);
|
228 | 230 | } else {
|
229 | 231 | final String ownerOrEmpty = owner != null ? owner : "";
|
230 |
| - appInstallation = appInstallations.stream() |
| 232 | + Optional<GHAppInstallation> appInstallationOptional = appInstallations.stream() |
231 | 233 | .filter(installation -> installation
|
232 | 234 | .getAccount()
|
233 | 235 | .getLogin()
|
234 | 236 | .toLowerCase(Locale.ROOT)
|
235 | 237 | .equals(ownerOrEmpty.toLowerCase(Locale.ROOT)))
|
236 |
| - .findAny() |
237 |
| - .orElseThrow(() -> new IllegalArgumentException( |
238 |
| - String.format(ERROR_NO_OWNER_MATCHING, appId, ownerOrEmpty))); |
| 238 | + .findAny(); |
| 239 | + if (appInstallationOptional.isEmpty()) { |
| 240 | + String logins = appInstallations.stream() |
| 241 | + .map(installation -> installation.getAccount().getLogin()) |
| 242 | + .collect(Collectors.joining(", ")); |
| 243 | + throw new IllegalArgumentException( |
| 244 | + String.format(ERROR_NO_OWNER_MATCHING, appId, ownerOrEmpty, logins)); |
| 245 | + } |
| 246 | + appInstallation = appInstallationOptional.get(); |
239 | 247 | }
|
240 | 248 |
|
241 | 249 | GHAppInstallationToken appInstallationToken = appInstallation
|
|
0 commit comments