Skip to content

Commit

Permalink
[JENKINS-72030] Enable for existing items. Default to disable for new…
Browse files Browse the repository at this point in the history
… items.
  • Loading branch information
Dohbedoh committed Oct 9, 2023
1 parent 7b720fb commit 1646ef2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public class GitHubSCMNavigator extends SCMNavigator {
/**
* Whether to enable the retrieval of the Organization avatar. If false, then the default GitHub logo will be used.
*/
private boolean enableAvatar;
private Boolean enableAvatar;

@NonNull
private List<SCMTrait<? extends SCMTrait<?>>> traits;
Expand Down Expand Up @@ -227,7 +227,6 @@ public class GitHubSCMNavigator extends SCMNavigator {
public GitHubSCMNavigator(String repoOwner) {
this.repoOwner = StringUtils.defaultString(repoOwner);
this.traits = new ArrayList<>();
this.enableAvatar = false;
}

/**
Expand Down Expand Up @@ -314,7 +313,8 @@ public void setCredentialsId(@CheckForNull String credentialsId) {
*
* @return true is enabled, false otherwise
*/
public boolean isEnableAvatar() {
@CheckForNull
public Boolean getEnableAvatar() {
return enableAvatar;
}

Expand All @@ -324,7 +324,7 @@ public boolean isEnableAvatar() {
* @param enableAvatar true to enable, false to disable
*/
@DataBoundSetter
public void setEnableAvatar(boolean enableAvatar) {
public void setEnableAvatar(Boolean enableAvatar) {
this.enableAvatar = enableAvatar;
}

Expand Down Expand Up @@ -391,6 +391,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 @@ -1557,7 +1560,7 @@ public List<Action> retrieveActions(
Connector.lookupScanCredentials((Item) owner, getApiUri(), credentialsId, repoOwner);
GitHub hub = Connector.connect(getApiUri(), credentials);
Connector.configureLocalRateLimitChecker(listener, hub);
boolean privateMode = !enableAvatar || determinePrivateMode(apiUri);
boolean privateMode = !Boolean.TRUE.equals(enableAvatar) || 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 @@ -20,7 +20,7 @@
<f:textbox/>
</f:entry>
<f:entry title="${%Enable Avatar}" field="enableAvatar">
<f:checkbox default="false"/>
<f:checkbox/>
</f:entry>
<f:entry title="${%Behaviours}">
<scm:traits field="traits"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,19 +432,19 @@ public void fetchActions() throws Exception {
Matchers.containsInAnyOrder(
Matchers.is(
new ObjectMetadataAction("CloudBeers, Inc.", null, "https://github.com/cloudbeers")),
Matchers.is(new GitHubOrgMetadataAction((String) null)),
Matchers.is(new GitHubOrgMetadataAction("https://avatars.githubusercontent.com/u/4181899?v=3")),
Matchers.is(new GitHubLink("icon-github-logo", "https://github.com/cloudbeers"))));
}

@Test
public void fetchActionsWithAvatar() throws Exception {
navigator.setEnableAvatar(true);
public void fetchActionsWithoutAvatar() throws Exception {
navigator.setEnableAvatar(false);
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("https://avatars.githubusercontent.com/u/4181899?v=3")),
Matchers.is(new GitHubOrgMetadataAction((String) null)),
Matchers.is(new GitHubLink("icon-github-logo", "https://github.com/cloudbeers"))));
}

Expand Down

0 comments on commit 1646ef2

Please sign in to comment.