Skip to content

Commit a153cda

Browse files
authored
Merge pull request #706 from janfaracik/use-github-logo
Use the GitHub logo instead of other icons
2 parents f92428e + e0ad7a7 commit a153cda

File tree

9 files changed

+19
-95
lines changed

9 files changed

+19
-95
lines changed

pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@
5959
<groupId>io.jenkins.plugins</groupId>
6060
<artifactId>caffeine-api</artifactId>
6161
</dependency>
62+
<dependency>
63+
<groupId>io.jenkins.plugins</groupId>
64+
<artifactId>ionicons-api</artifactId>
65+
</dependency>
6266
<dependency>
6367
<groupId>io.jenkins.plugins</groupId>
6468
<artifactId>jjwt-api</artifactId>

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

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -27,34 +27,24 @@
2727
import edu.umd.cs.findbugs.annotations.NonNull;
2828
import hudson.model.Action;
2929
import java.net.URL;
30-
import jenkins.model.Jenkins;
31-
import org.apache.commons.jelly.JellyContext;
32-
import org.jenkins.ui.icon.Icon;
33-
import org.jenkins.ui.icon.IconSet;
3430
import org.jenkins.ui.icon.IconSpec;
35-
import org.kohsuke.stapler.Stapler;
3631

3732
/**
3833
* Link to GitHub
3934
*
4035
* @author Kohsuke Kawaguchi
4136
*/
4237
public class GitHubLink implements Action, IconSpec {
43-
/** The icon class name to use. */
44-
@NonNull
45-
private final String iconClassName;
46-
4738
/** Target of the hyperlink to take the user to. */
4839
@NonNull
4940
private final String url;
5041

51-
public GitHubLink(@NonNull String iconClassName, @NonNull String url) {
52-
this.iconClassName = iconClassName;
42+
public GitHubLink(@NonNull String url) {
5343
this.url = url;
5444
}
5545

56-
public GitHubLink(String iconClassName, URL url) {
57-
this(iconClassName, url.toExternalForm());
46+
public GitHubLink(URL url) {
47+
this(url.toExternalForm());
5848
}
5949

6050
@NonNull
@@ -64,21 +54,12 @@ public String getUrl() {
6454

6555
@Override
6656
public String getIconClassName() {
67-
return iconClassName;
57+
return "symbol-logo-github plugin-ionicons-api";
6858
}
6959

7060
@Override
7161
public String getIconFileName() {
72-
String iconClassName = getIconClassName();
73-
if (iconClassName != null) {
74-
Icon icon = IconSet.icons.getIconByClassSpec(iconClassName + " icon-md");
75-
if (icon != null) {
76-
JellyContext ctx = new JellyContext();
77-
ctx.setVariable("resURL", Stapler.getCurrentRequest().getContextPath() + Jenkins.RESOURCE_PATH);
78-
return icon.getQualifiedUrl(ctx);
79-
}
80-
}
81-
return null;
62+
return getIconClassName();
8263
}
8364

8465
@Override
@@ -102,21 +83,16 @@ public boolean equals(Object o) {
10283

10384
GitHubLink that = (GitHubLink) o;
10485

105-
if (!iconClassName.equals(that.iconClassName)) {
106-
return false;
107-
}
10886
return url.equals(that.url);
10987
}
11088

11189
@Override
11290
public int hashCode() {
113-
int result = iconClassName.hashCode();
114-
result = 31 * result + url.hashCode();
115-
return result;
91+
return 31 * url.hashCode();
11692
}
11793

11894
@Override
11995
public String toString() {
120-
return "GitHubLink{" + "iconClassName='" + iconClassName + '\'' + ", url='" + url + '\'' + '}';
96+
return "GitHubLink{" + "url='" + url + '\'' + '}';
12197
}
12298
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public String getAvatarImageOf(String size) {
9191
/** {@inheritDoc} */
9292
@Override
9393
public String getAvatarIconClassName() {
94-
return avatar == null ? "icon-github-logo" : null;
94+
return avatar == null ? "symbol-logo-github plugin-ionicons-api" : null;
9595
}
9696

9797
/** {@inheritDoc} */

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

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,7 +1571,7 @@ public List<Action> retrieveActions(
15711571
} else {
15721572
result.add(new GitHubOrgMetadataAction(u));
15731573
}
1574-
result.add(new GitHubLink("icon-github-logo", u.getHtmlUrl()));
1574+
result.add(new GitHubLink(u.getHtmlUrl()));
15751575
if (objectUrl == null) {
15761576
listener.getLogger().println("Organization URL: unspecified");
15771577
} else {
@@ -1913,27 +1913,6 @@ public List<SCMTrait<? extends SCMTrait<?>>> getTraitsDefaults() {
19131913
"plugin/github-branch-source/images/svgs/github-scmnavigator.svg",
19141914
Icon.ICON_XLARGE_STYLE));
19151915

1916-
IconSet.icons.addIcon(new Icon(
1917-
"icon-github-logo icon-sm",
1918-
"plugin/github-branch-source/images/svgs/sprite-github.svg#github-logo",
1919-
Icon.ICON_SMALL_STYLE,
1920-
IconFormat.EXTERNAL_SVG_SPRITE));
1921-
IconSet.icons.addIcon(new Icon(
1922-
"icon-github-logo icon-md",
1923-
"plugin/github-branch-source/images/svgs/sprite-github.svg#github-logo",
1924-
Icon.ICON_MEDIUM_STYLE,
1925-
IconFormat.EXTERNAL_SVG_SPRITE));
1926-
IconSet.icons.addIcon(new Icon(
1927-
"icon-github-logo icon-lg",
1928-
"plugin/github-branch-source/images/svgs/sprite-github.svg#github-logo",
1929-
Icon.ICON_LARGE_STYLE,
1930-
IconFormat.EXTERNAL_SVG_SPRITE));
1931-
IconSet.icons.addIcon(new Icon(
1932-
"icon-github-logo icon-xlg",
1933-
"plugin/github-branch-source/images/svgs/sprite-github.svg#github-logo",
1934-
Icon.ICON_XLARGE_STYLE,
1935-
IconFormat.EXTERNAL_SVG_SPRITE));
1936-
19371916
IconSet.icons.addIcon(new Icon(
19381917
"icon-github-repo icon-sm",
19391918
"plugin/github-branch-source/images/svgs/sprite-github.svg#github-repo",
@@ -1954,27 +1933,6 @@ public List<SCMTrait<? extends SCMTrait<?>>> getTraitsDefaults() {
19541933
"plugin/github-branch-source/images/svgs/sprite-github.svg#github-repo",
19551934
Icon.ICON_XLARGE_STYLE,
19561935
IconFormat.EXTERNAL_SVG_SPRITE));
1957-
1958-
IconSet.icons.addIcon(new Icon(
1959-
"icon-github-branch icon-sm",
1960-
"plugin/github-branch-source/images/svgs/sprite-github.svg#git-branch",
1961-
Icon.ICON_SMALL_STYLE,
1962-
IconFormat.EXTERNAL_SVG_SPRITE));
1963-
IconSet.icons.addIcon(new Icon(
1964-
"icon-github-branch icon-md",
1965-
"plugin/github-branch-source/images/svgs/sprite-github.svg#git-branch",
1966-
Icon.ICON_MEDIUM_STYLE,
1967-
IconFormat.EXTERNAL_SVG_SPRITE));
1968-
IconSet.icons.addIcon(new Icon(
1969-
"icon-github-branch icon-lg",
1970-
"plugin/github-branch-source/images/svgs/sprite-github.svg#git-branch",
1971-
Icon.ICON_LARGE_STYLE,
1972-
IconFormat.EXTERNAL_SVG_SPRITE));
1973-
IconSet.icons.addIcon(new Icon(
1974-
"icon-github-branch icon-xlg",
1975-
"plugin/github-branch-source/images/svgs/sprite-github.svg#git-branch",
1976-
Icon.ICON_XLARGE_STYLE,
1977-
IconFormat.EXTERNAL_SVG_SPRITE));
19781936
}
19791937
}
19801938

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1924,7 +1924,7 @@ protected List<Action> retrieveActions(
19241924
url = repoLink.getUrl() + "/tree/" + head.getName();
19251925
metadataAction = new ObjectMetadataAction(head.getName(), null, url);
19261926
}
1927-
result.add(new GitHubLink("icon-github-branch", url));
1927+
result.add(new GitHubLink(url));
19281928
result.add(metadataAction);
19291929
}
19301930
if (head instanceof BranchSCMHead) {
@@ -1970,7 +1970,7 @@ protected List<Action> retrieveActions(@CheckForNull SCMSourceEvent event, @NonN
19701970
}
19711971
result.add(new ObjectMetadataAction(
19721972
null, ghRepository.getDescription(), Util.fixEmpty(ghRepository.getHomepage())));
1973-
result.add(new GitHubLink("icon-github-repo", ghRepository.getHtmlUrl()));
1973+
result.add(new GitHubLink(ghRepository.getHtmlUrl()));
19741974
if (StringUtils.isNotBlank(ghRepository.getDefaultBranch())) {
19751975
result.add(new GitHubDefaultBranch(getRepoOwner(), repository, ghRepository.getDefaultBranch()));
19761976
}
Lines changed: 1 addition & 7 deletions
Loading
Lines changed: 0 additions & 8 deletions
Loading

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ public void fetchActions() throws Exception {
433433
Matchers.is(
434434
new ObjectMetadataAction("CloudBeers, Inc.", null, "https://github.com/cloudbeers")),
435435
Matchers.is(new GitHubOrgMetadataAction((String) null)),
436-
Matchers.is(new GitHubLink("icon-github-logo", "https://github.com/cloudbeers"))));
436+
Matchers.is(new GitHubLink("https://github.com/cloudbeers"))));
437437
}
438438

439439
@Test
@@ -445,7 +445,7 @@ public void fetchActionsWithAvatar() throws Exception {
445445
Matchers.is(
446446
new ObjectMetadataAction("CloudBeers, Inc.", null, "https://github.com/cloudbeers")),
447447
Matchers.is(new GitHubOrgMetadataAction("https://avatars.githubusercontent.com/u/4181899?v=3")),
448-
Matchers.is(new GitHubLink("icon-github-logo", "https://github.com/cloudbeers"))));
448+
Matchers.is(new GitHubLink("https://github.com/cloudbeers"))));
449449
}
450450

451451
@Test

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ public void fetchActions() throws Exception {
703703
Matchers.is(new ObjectMetadataAction(null, "You only live once", "http://yolo.example.com")),
704704
Matchers.is(new GitHubDefaultBranch("cloudbeers", "yolo", "master")),
705705
instanceOf(GitHubRepoMetadataAction.class),
706-
Matchers.is(new GitHubLink("icon-github-repo", "https://github.com/cloudbeers/yolo"))));
706+
Matchers.is(new GitHubLink("https://github.com/cloudbeers/yolo"))));
707707
}
708708

709709
@Test

0 commit comments

Comments
 (0)