Skip to content

Commit

Permalink
Merge pull request #86 from jenkinsci/jenkins-39067
Browse files Browse the repository at this point in the history
[JENKINS-39067] Move the GitHub icons to the github-branch-source plugin
  • Loading branch information
stephenc committed Oct 19, 2016
2 parents f5dd525 + 20448a9 commit d6f5dfa
Show file tree
Hide file tree
Showing 23 changed files with 361 additions and 4 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Expand Up @@ -37,6 +37,12 @@
<artifactId>scm-api</artifactId>
<version>1.4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>cloudbees-folder</artifactId>
<version>5.14-SNAPSHOT</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>branch-api</artifactId>
Expand Down
54 changes: 54 additions & 0 deletions src/images/github-branch.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/images/github-logo.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
53 changes: 53 additions & 0 deletions src/images/github-repo.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,68 @@
package org.jenkinsci.plugins.github_branch_source;

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.
*/
private final String iconClassName;

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

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

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

public String getUrl() {
return url;
}

@Override
public String getIconClassName() {
return iconClassName;
}

@Override
public String getIconFileName() {
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;
}

@Override
public String getDisplayName() {
return Messages.GitHubLink_DisplayName();
}

@Override
public String getUrlName() {
return url;
}
}
Expand Up @@ -91,15 +91,15 @@ public boolean equals(Object o) {

GitHubOrgAction that = (GitHubOrgAction) o;

return getUrl() != null ? getUrl().equals(that.getUrl()) : that.getUrl() == null;
return getUrl() != null ? getUrl().toExternalForm().equals(that.getUrl().toExternalForm()) : that.getUrl() == null;
}

/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
return getUrl() != null ? getUrl().hashCode() : 0;
return getUrl() != null ? getUrl().toExternalForm().hashCode() : 0;
}

/**
Expand Down
@@ -0,0 +1,72 @@
package org.jenkinsci.plugins.github_branch_source;

import com.cloudbees.hudson.plugins.folder.AbstractFolder;
import com.cloudbees.hudson.plugins.folder.FolderIcon;
import com.cloudbees.hudson.plugins.folder.FolderIconDescriptor;
import hudson.Extension;
import hudson.model.Hudson;
import org.jenkins.ui.icon.Icon;
import org.jenkins.ui.icon.IconSet;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.Stapler;

/**
* Shows Avatar icon from GitHub organization/user.
*
* @author Kohsuke Kawaguchi
*/
public class GitHubOrgIcon extends FolderIcon {
private AbstractFolder<?> folder;

@DataBoundConstructor
public GitHubOrgIcon() {
}

@Override
protected void setOwner(AbstractFolder<?> folder) {
this.folder = folder;
}

@Override
public String getImageOf(String size) {
String url = getAvatarUrl();
if (url==null) {
// fall back to the generic github org icon
String image = iconClassNameImageOf(size);
return image != null
? image
: (Stapler.getCurrentRequest().getContextPath() + Hudson.RESOURCE_PATH
+ "/plugin/github-branch-source/images/" + size + "/github-logo.png");
} else {
String[] xy = size.split("x");
if (xy.length==0) return url;
if (url.contains("?")) return url+"&s="+xy[0];
else return url+"?s="+xy[0];
}
}

@Override
public String getIconClassName() {
return getAvatarUrl() == null ? "icon-github-logo" : null;
}

@Override
public String getDescription() {
return folder!=null ? folder.getName() : Messages.GitHubOrgIcon_Description();
}

private String getAvatarUrl() {
if (folder==null) return null;
GitHubOrgAction p = folder.getAction(GitHubOrgAction.class);
if (p==null) return null;
return p.getAvatar();
}

@Extension(optional = true)
public static class DescriptorImpl extends FolderIconDescriptor {
@Override
public String getDisplayName() {
return Messages.GitHubOrgIcon_DisplayName();
}
}
}
Expand Up @@ -90,7 +90,7 @@ public boolean equals(Object o) {

GitHubRepoAction that = (GitHubRepoAction) o;

return getUrl() != null ? getUrl().equals(that.getUrl()) : that.getUrl() == null;
return getUrl() != null ? getUrl().toExternalForm().equals(that.getUrl().toExternalForm()) : that.getUrl() == null;

}

Expand All @@ -99,7 +99,7 @@ public boolean equals(Object o) {
*/
@Override
public int hashCode() {
return getUrl() != null ? getUrl().hashCode() : 0;
return getUrl() != null ? getUrl().toExternalForm().hashCode() : 0;
}

/**
Expand Down
@@ -0,0 +1,44 @@
package org.jenkinsci.plugins.github_branch_source;

import com.cloudbees.hudson.plugins.folder.FolderIcon;
import com.cloudbees.hudson.plugins.folder.FolderIconDescriptor;
import hudson.Extension;
import hudson.model.Hudson;
import org.jenkins.ui.icon.Icon;
import org.jenkins.ui.icon.IconSet;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.Stapler;

/**
* {@link FolderIcon} that shows the github repository icon.
*
* @author Kohsuke Kawaguchi
*/
public class GitHubRepoIcon extends FolderIcon {
@DataBoundConstructor
public GitHubRepoIcon() {
}

@Override
public String getIconClassName() {
return "icon-github-repo";
}

@Override
public String getImageOf(String size) {
return iconClassNameImageOf(size);
}

@Override
public String getDescription() {
return Messages.GitHubRepoIcon_Description();
}

@Extension(optional = true)
public static class DescriptorImpl extends FolderIconDescriptor {
@Override
public String getDisplayName() {
return Messages.GitHubRepoIcon_DisplayName();
}
}
}

0 comments on commit d6f5dfa

Please sign in to comment.