Skip to content
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 @@ -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<SCMTrait<? extends SCMTrait<?>>> traits;

Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1531,7 +1561,7 @@ public List<Action> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
<f:entry title="${%Owner}" field="repoOwner">
<f:textbox/>
</f:entry>
<f:entry title="${%Enable Avatar}" field="enableAvatar">
<f:checkbox/>
</f:entry>
<f:entry title="${%Behaviours}">
<scm:traits field="traits"/>
</f:entry>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div>
<p>Whether to use the <strong>GitHub Organization</strong> or <strong>GitHub User Account</strong> avatar as icon (only possible if private mode is disabled).</p>
<p>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 <a href="https://issues.jenkins.io/browse/JENKINS-72030">JENKINS-72030</a></p>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down