diff --git a/src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigator.java b/src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigator.java index d2adf273b..4cb595e13 100644 --- a/src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigator.java +++ b/src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigator.java @@ -128,6 +128,12 @@ public class GitHubSCMNavigator extends SCMNavigator { @CheckForNull private String credentialsId; /** The behavioural traits to apply. */ + + /** + * Whether to enable the retrieval of the Organization avatar. If false, then the default GitHub logo will be used. + */ + private Boolean enableAvatar; + @NonNull private List>> traits; @@ -302,6 +308,27 @@ public void setCredentialsId(@CheckForNull String credentialsId) { this.credentialsId = Util.fixEmpty(credentialsId); } + /** + * Return if the avatar retrieval is enabled. + * + * @return true is enabled, false otherwise + */ + @NonNull + @SuppressWarnings("unused") // stapler + public boolean isEnableAvatar() { + return Boolean.TRUE.equals(enableAvatar); + } + + /** + * Enable retrieval of the organization avatar. + * + * @param enableAvatar true to enable, false to disable + */ + @DataBoundSetter + public void setEnableAvatar(boolean enableAvatar) { + this.enableAvatar = enableAvatar; + } + /** * Gets the name of the owner who's repositories will be navigated. * @@ -365,6 +392,9 @@ private Object readResolve() { if (scanCredentialsId != null) { credentialsId = scanCredentialsId; } + if (enableAvatar == null) { + enableAvatar = Boolean.TRUE; + } if (traits == null) { boolean buildOriginBranch = this.buildOriginBranch == null || this.buildOriginBranch; boolean buildOriginBranchWithPR = this.buildOriginBranchWithPR == null || this.buildOriginBranchWithPR; @@ -1531,7 +1561,7 @@ public List retrieveActions( Connector.lookupScanCredentials((Item) owner, getApiUri(), credentialsId, repoOwner); GitHub hub = Connector.connect(getApiUri(), credentials); Connector.configureLocalRateLimitChecker(listener, hub); - boolean privateMode = determinePrivateMode(apiUri); + boolean privateMode = !isEnableAvatar() || determinePrivateMode(apiUri); try { GHUser u = hub.getUser(getRepoOwner()); String objectUrl = u.getHtmlUrl() == null ? null : u.getHtmlUrl().toExternalForm(); diff --git a/src/main/resources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigator/config.jelly b/src/main/resources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigator/config.jelly index 96550402f..35e97264d 100644 --- a/src/main/resources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigator/config.jelly +++ b/src/main/resources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigator/config.jelly @@ -19,6 +19,9 @@ + + + diff --git a/src/main/resources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigator/help-enableAvatar.html b/src/main/resources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigator/help-enableAvatar.html new file mode 100644 index 000000000..3bea92d90 --- /dev/null +++ b/src/main/resources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigator/help-enableAvatar.html @@ -0,0 +1,4 @@ +
+

Whether to use the GitHub Organization or GitHub User Account avatar as icon (only possible if private mode is disabled).

+

Note: this consumes an anonymous call to check if private mode is enabled. Although the result of this check is cached for some time (20 hours by default), this can block operations in some environments. See JENKINS-72030

+
diff --git a/src/test/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTest.java b/src/test/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTest.java index 856d087b9..c8e35ad3b 100644 --- a/src/test/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTest.java +++ b/src/test/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTest.java @@ -427,6 +427,18 @@ public void appliesFilters() throws Exception { @Test public void fetchActions() throws Exception { + assertThat( + navigator.fetchActions(Mockito.mock(SCMNavigatorOwner.class), null, null), + Matchers.containsInAnyOrder( + Matchers.is( + new ObjectMetadataAction("CloudBeers, Inc.", null, "https://github.com/cloudbeers")), + Matchers.is(new GitHubOrgMetadataAction((String) null)), + Matchers.is(new GitHubLink("icon-github-logo", "https://github.com/cloudbeers")))); + } + + @Test + public void fetchActionsWithAvatar() throws Exception { + navigator.setEnableAvatar(true); assertThat( navigator.fetchActions(Mockito.mock(SCMNavigatorOwner.class), null, null), Matchers.containsInAnyOrder(