Skip to content
Merged
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 @@ -46,6 +46,7 @@
import hudson.util.ListBoxModel;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.EnumSet;
Expand Down Expand Up @@ -1574,15 +1575,21 @@ public List<Action> retrieveActions(
// trusted source
listener.getLogger().printf("Looking up details of %s...%n", getRepoOwner());
List<Action> result = new ArrayList<>();
String apiUri = Util.fixEmptyAndTrim(getApiUri());
StandardCredentials credentials =
Connector.lookupScanCredentials((Item) owner, getApiUri(), credentialsId);
GitHub hub = Connector.connect(getApiUri(), credentials);
Connector.lookupScanCredentials((Item) owner, apiUri, credentialsId);
GitHub hub = Connector.connect(apiUri, credentials);
boolean privateMode = determinePrivateMode(apiUri);
try {
Connector.configureLocalRateLimitChecker(listener, hub);
GHUser u = hub.getUser(getRepoOwner());
String objectUrl = u.getHtmlUrl() == null ? null : u.getHtmlUrl().toExternalForm();
result.add(new ObjectMetadataAction(Util.fixEmpty(u.getName()), null, objectUrl));
result.add(new GitHubOrgMetadataAction(u));
if (privateMode) {
result.add(new GitHubOrgMetadataAction((String) null));
} else {
result.add(new GitHubOrgMetadataAction(u));
}
result.add(new GitHubLink("icon-github-logo", u.getHtmlUrl()));
if (objectUrl == null) {
listener.getLogger().println("Organization URL: unspecified");
Expand All @@ -1600,6 +1607,23 @@ public List<Action> retrieveActions(
}
}

private static boolean determinePrivateMode(String apiUri) {
if (apiUri == null || apiUri.equals(GitHubServerConfig.GITHUB_URL)) {
return false;
}
try {
GitHub.connectToEnterpriseAnonymously(apiUri).checkApiUrlValidity();
} catch (MalformedURLException e) {
// URL is bogus so there is never going to be an avatar - or anything else come to think of it
return true;
} catch (IOException e) {
if (e.getMessage().contains("private mode enabled")) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return true;
}
}
return false;
}

/** {@inheritDoc} */
@Override
public void afterSave(@NonNull SCMNavigatorOwner owner) {
Expand Down