Skip to content

Commit

Permalink
Merge pull request #706 from janfaracik/use-github-logo
Browse files Browse the repository at this point in the history
Use the GitHub logo instead of other icons
  • Loading branch information
jtnord authored Mar 11, 2024
2 parents f92428e + e0ad7a7 commit a153cda
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 95 deletions.
4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@
<groupId>io.jenkins.plugins</groupId>
<artifactId>caffeine-api</artifactId>
</dependency>
<dependency>
<groupId>io.jenkins.plugins</groupId>
<artifactId>ionicons-api</artifactId>
</dependency>
<dependency>
<groupId>io.jenkins.plugins</groupId>
<artifactId>jjwt-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,24 @@
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.model.Action;
import java.net.URL;
import jenkins.model.Jenkins;
import org.apache.commons.jelly.JellyContext;
import org.jenkins.ui.icon.Icon;
import org.jenkins.ui.icon.IconSet;
import org.jenkins.ui.icon.IconSpec;
import org.kohsuke.stapler.Stapler;

/**
* Link to GitHub
*
* @author Kohsuke Kawaguchi
*/
public class GitHubLink implements Action, IconSpec {
/** The icon class name to use. */
@NonNull
private final String iconClassName;

/** Target of the hyperlink to take the user to. */
@NonNull
private final String url;

public GitHubLink(@NonNull String iconClassName, @NonNull String url) {
this.iconClassName = iconClassName;
public GitHubLink(@NonNull String url) {
this.url = url;
}

public GitHubLink(String iconClassName, URL url) {
this(iconClassName, url.toExternalForm());
public GitHubLink(URL url) {
this(url.toExternalForm());
}

@NonNull
Expand All @@ -64,21 +54,12 @@ public String getUrl() {

@Override
public String getIconClassName() {
return iconClassName;
return "symbol-logo-github plugin-ionicons-api";
}

@Override
public String getIconFileName() {
String iconClassName = getIconClassName();
if (iconClassName != null) {
Icon icon = IconSet.icons.getIconByClassSpec(iconClassName + " icon-md");
if (icon != null) {
JellyContext ctx = new JellyContext();
ctx.setVariable("resURL", Stapler.getCurrentRequest().getContextPath() + Jenkins.RESOURCE_PATH);
return icon.getQualifiedUrl(ctx);
}
}
return null;
return getIconClassName();
}

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

GitHubLink that = (GitHubLink) o;

if (!iconClassName.equals(that.iconClassName)) {
return false;
}
return url.equals(that.url);
}

@Override
public int hashCode() {
int result = iconClassName.hashCode();
result = 31 * result + url.hashCode();
return result;
return 31 * url.hashCode();
}

@Override
public String toString() {
return "GitHubLink{" + "iconClassName='" + iconClassName + '\'' + ", url='" + url + '\'' + '}';
return "GitHubLink{" + "url='" + url + '\'' + '}';

Check warning on line 96 in src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubLink.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 57-96 are not covered by tests
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public String getAvatarImageOf(String size) {
/** {@inheritDoc} */
@Override
public String getAvatarIconClassName() {
return avatar == null ? "icon-github-logo" : null;
return avatar == null ? "symbol-logo-github plugin-ionicons-api" : null;

Check warning on line 94 in src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubOrgMetadataAction.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 94 is not covered by tests
}

/** {@inheritDoc} */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1571,7 +1571,7 @@ public List<Action> retrieveActions(
} else {
result.add(new GitHubOrgMetadataAction(u));
}
result.add(new GitHubLink("icon-github-logo", u.getHtmlUrl()));
result.add(new GitHubLink(u.getHtmlUrl()));
if (objectUrl == null) {
listener.getLogger().println("Organization URL: unspecified");
} else {
Expand Down Expand Up @@ -1913,27 +1913,6 @@ public List<SCMTrait<? extends SCMTrait<?>>> getTraitsDefaults() {
"plugin/github-branch-source/images/svgs/github-scmnavigator.svg",
Icon.ICON_XLARGE_STYLE));

IconSet.icons.addIcon(new Icon(
"icon-github-logo icon-sm",
"plugin/github-branch-source/images/svgs/sprite-github.svg#github-logo",
Icon.ICON_SMALL_STYLE,
IconFormat.EXTERNAL_SVG_SPRITE));
IconSet.icons.addIcon(new Icon(
"icon-github-logo icon-md",
"plugin/github-branch-source/images/svgs/sprite-github.svg#github-logo",
Icon.ICON_MEDIUM_STYLE,
IconFormat.EXTERNAL_SVG_SPRITE));
IconSet.icons.addIcon(new Icon(
"icon-github-logo icon-lg",
"plugin/github-branch-source/images/svgs/sprite-github.svg#github-logo",
Icon.ICON_LARGE_STYLE,
IconFormat.EXTERNAL_SVG_SPRITE));
IconSet.icons.addIcon(new Icon(
"icon-github-logo icon-xlg",
"plugin/github-branch-source/images/svgs/sprite-github.svg#github-logo",
Icon.ICON_XLARGE_STYLE,
IconFormat.EXTERNAL_SVG_SPRITE));

IconSet.icons.addIcon(new Icon(
"icon-github-repo icon-sm",
"plugin/github-branch-source/images/svgs/sprite-github.svg#github-repo",
Expand All @@ -1954,27 +1933,6 @@ public List<SCMTrait<? extends SCMTrait<?>>> getTraitsDefaults() {
"plugin/github-branch-source/images/svgs/sprite-github.svg#github-repo",
Icon.ICON_XLARGE_STYLE,
IconFormat.EXTERNAL_SVG_SPRITE));

IconSet.icons.addIcon(new Icon(
"icon-github-branch icon-sm",
"plugin/github-branch-source/images/svgs/sprite-github.svg#git-branch",
Icon.ICON_SMALL_STYLE,
IconFormat.EXTERNAL_SVG_SPRITE));
IconSet.icons.addIcon(new Icon(
"icon-github-branch icon-md",
"plugin/github-branch-source/images/svgs/sprite-github.svg#git-branch",
Icon.ICON_MEDIUM_STYLE,
IconFormat.EXTERNAL_SVG_SPRITE));
IconSet.icons.addIcon(new Icon(
"icon-github-branch icon-lg",
"plugin/github-branch-source/images/svgs/sprite-github.svg#git-branch",
Icon.ICON_LARGE_STYLE,
IconFormat.EXTERNAL_SVG_SPRITE));
IconSet.icons.addIcon(new Icon(
"icon-github-branch icon-xlg",
"plugin/github-branch-source/images/svgs/sprite-github.svg#git-branch",
Icon.ICON_XLARGE_STYLE,
IconFormat.EXTERNAL_SVG_SPRITE));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1924,7 +1924,7 @@ protected List<Action> retrieveActions(
url = repoLink.getUrl() + "/tree/" + head.getName();
metadataAction = new ObjectMetadataAction(head.getName(), null, url);
}
result.add(new GitHubLink("icon-github-branch", url));
result.add(new GitHubLink(url));

Check warning on line 1927 in src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMSource.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 1927 is not covered by tests
result.add(metadataAction);
}
if (head instanceof BranchSCMHead) {
Expand Down Expand Up @@ -1970,7 +1970,7 @@ protected List<Action> retrieveActions(@CheckForNull SCMSourceEvent event, @NonN
}
result.add(new ObjectMetadataAction(
null, ghRepository.getDescription(), Util.fixEmpty(ghRepository.getHomepage())));
result.add(new GitHubLink("icon-github-repo", ghRepository.getHtmlUrl()));
result.add(new GitHubLink(ghRepository.getHtmlUrl()));
if (StringUtils.isNotBlank(ghRepository.getDefaultBranch())) {
result.add(new GitHubDefaultBranch(getRepoOwner(), repository, ghRepository.getDefaultBranch()));
}
Expand Down
8 changes: 1 addition & 7 deletions src/main/webapp/images/svgs/github-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 0 additions & 8 deletions src/main/webapp/images/svgs/sprite-github.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ public void fetchActions() throws Exception {
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"))));
Matchers.is(new GitHubLink("https://github.com/cloudbeers"))));
}

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

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ public void fetchActions() throws Exception {
Matchers.is(new ObjectMetadataAction(null, "You only live once", "http://yolo.example.com")),
Matchers.is(new GitHubDefaultBranch("cloudbeers", "yolo", "master")),
instanceOf(GitHubRepoMetadataAction.class),
Matchers.is(new GitHubLink("icon-github-repo", "https://github.com/cloudbeers/yolo"))));
Matchers.is(new GitHubLink("https://github.com/cloudbeers/yolo"))));
}

@Test
Expand Down

0 comments on commit a153cda

Please sign in to comment.