Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-72030] Add checkbox to enable/disable Avatar retrieval #738

Merged
merged 8 commits into from
Dec 18, 2023
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() {
Dohbedoh marked this conversation as resolved.
Show resolved Hide resolved
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) {
Dohbedoh marked this conversation as resolved.
Show resolved Hide resolved
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);
Dohbedoh marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -437,8 +437,8 @@ public void fetchActions() throws Exception {
}

@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(
Expand Down