Skip to content

Commit

Permalink
Merge pull request #738 from Dohbedoh/JENKINS-72030
Browse files Browse the repository at this point in the history
[JENKINS-72030] Add checkbox to enable/disable Avatar retrieval
  • Loading branch information
jtnord authored Dec 18, 2023
2 parents 0484147 + 8cc08ab commit a7d01ea
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
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) {

Check warning on line 395 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 395 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 +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);

Check warning on line 1564 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 1564 is only partially covered, one branch is missing
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

0 comments on commit a7d01ea

Please sign in to comment.