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
Merged
Show file tree
Hide file tree
Changes from 3 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 @@
@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,26 @@
this.credentialsId = Util.fixEmpty(credentialsId);
}

/**
* Return if the avatar retrieval is enabled.
*
* @return true is enabled, false otherwise
*/
@CheckForNull
public Boolean getEnableAvatar() {
Dohbedoh marked this conversation as resolved.
Show resolved Hide resolved
return enableAvatar;

Check warning on line 318 in src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigator.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 318 is not covered by tests
}

/**
* Enable retrieval of the organization avatar.
*
* @param enableAvatar true to enable, false to disable
*/
@DataBoundSetter
public void setEnableAvatar(Boolean enableAvatar) {
Dohbedoh marked this conversation as resolved.
Show resolved Hide resolved
this.enableAvatar = enableAvatar;
}

/**
* Gets the name of the owner who's repositories will be navigated.
*
Expand Down Expand Up @@ -365,6 +391,9 @@
if (scanCredentialsId != null) {
credentialsId = scanCredentialsId;
}
if (enableAvatar == null) {

Check warning on line 394 in src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigator.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 394 is only partially covered, one branch is missing
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 +1560,7 @@
Connector.lookupScanCredentials((Item) owner, getApiUri(), credentialsId, repoOwner);
GitHub hub = Connector.connect(getApiUri(), credentials);
Connector.configureLocalRateLimitChecker(listener, hub);
boolean privateMode = determinePrivateMode(apiUri);
boolean privateMode = !Boolean.TRUE.equals(enableAvatar) || determinePrivateMode(apiUri);

Check warning on line 1563 in src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigator.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 1563 is only partially covered, 3 branches are missing
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 @@ -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 fetchActionsWithoutAvatar() throws Exception {
navigator.setEnableAvatar(false);
assertThat(
navigator.fetchActions(Mockito.mock(SCMNavigatorOwner.class), null, null),
Matchers.containsInAnyOrder(
Expand Down