Skip to content

Commit a7d01ea

Browse files
authored
Merge pull request #738 from Dohbedoh/JENKINS-72030
[JENKINS-72030] Add checkbox to enable/disable Avatar retrieval
2 parents 0484147 + 8cc08ab commit a7d01ea

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed

src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigator.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ public class GitHubSCMNavigator extends SCMNavigator {
128128
@CheckForNull
129129
private String credentialsId;
130130
/** The behavioural traits to apply. */
131+
132+
/**
133+
* Whether to enable the retrieval of the Organization avatar. If false, then the default GitHub logo will be used.
134+
*/
135+
private Boolean enableAvatar;
136+
131137
@NonNull
132138
private List<SCMTrait<? extends SCMTrait<?>>> traits;
133139

@@ -302,6 +308,27 @@ public void setCredentialsId(@CheckForNull String credentialsId) {
302308
this.credentialsId = Util.fixEmpty(credentialsId);
303309
}
304310

311+
/**
312+
* Return if the avatar retrieval is enabled.
313+
*
314+
* @return true is enabled, false otherwise
315+
*/
316+
@NonNull
317+
@SuppressWarnings("unused") // stapler
318+
public boolean isEnableAvatar() {
319+
return Boolean.TRUE.equals(enableAvatar);
320+
}
321+
322+
/**
323+
* Enable retrieval of the organization avatar.
324+
*
325+
* @param enableAvatar true to enable, false to disable
326+
*/
327+
@DataBoundSetter
328+
public void setEnableAvatar(boolean enableAvatar) {
329+
this.enableAvatar = enableAvatar;
330+
}
331+
305332
/**
306333
* Gets the name of the owner who's repositories will be navigated.
307334
*
@@ -365,6 +392,9 @@ private Object readResolve() {
365392
if (scanCredentialsId != null) {
366393
credentialsId = scanCredentialsId;
367394
}
395+
if (enableAvatar == null) {
396+
enableAvatar = Boolean.TRUE;
397+
}
368398
if (traits == null) {
369399
boolean buildOriginBranch = this.buildOriginBranch == null || this.buildOriginBranch;
370400
boolean buildOriginBranchWithPR = this.buildOriginBranchWithPR == null || this.buildOriginBranchWithPR;
@@ -1531,7 +1561,7 @@ public List<Action> retrieveActions(
15311561
Connector.lookupScanCredentials((Item) owner, getApiUri(), credentialsId, repoOwner);
15321562
GitHub hub = Connector.connect(getApiUri(), credentials);
15331563
Connector.configureLocalRateLimitChecker(listener, hub);
1534-
boolean privateMode = determinePrivateMode(apiUri);
1564+
boolean privateMode = !isEnableAvatar() || determinePrivateMode(apiUri);
15351565
try {
15361566
GHUser u = hub.getUser(getRepoOwner());
15371567
String objectUrl = u.getHtmlUrl() == null ? null : u.getHtmlUrl().toExternalForm();

src/main/resources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigator/config.jelly

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
<f:entry title="${%Owner}" field="repoOwner">
2020
<f:textbox/>
2121
</f:entry>
22+
<f:entry title="${%Enable Avatar}" field="enableAvatar">
23+
<f:checkbox/>
24+
</f:entry>
2225
<f:entry title="${%Behaviours}">
2326
<scm:traits field="traits"/>
2427
</f:entry>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<div>
2+
<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>
3+
<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>
4+
</div>

src/test/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,18 @@ public void appliesFilters() throws Exception {
427427

428428
@Test
429429
public void fetchActions() throws Exception {
430+
assertThat(
431+
navigator.fetchActions(Mockito.mock(SCMNavigatorOwner.class), null, null),
432+
Matchers.containsInAnyOrder(
433+
Matchers.is(
434+
new ObjectMetadataAction("CloudBeers, Inc.", null, "https://github.com/cloudbeers")),
435+
Matchers.is(new GitHubOrgMetadataAction((String) null)),
436+
Matchers.is(new GitHubLink("icon-github-logo", "https://github.com/cloudbeers"))));
437+
}
438+
439+
@Test
440+
public void fetchActionsWithAvatar() throws Exception {
441+
navigator.setEnableAvatar(true);
430442
assertThat(
431443
navigator.fetchActions(Mockito.mock(SCMNavigatorOwner.class), null, null),
432444
Matchers.containsInAnyOrder(

0 commit comments

Comments
 (0)