Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #86 from jenkinsci/jenkins-39067
[JENKINS-39067] Move the GitHub icons to the github-branch-source plugin
- Loading branch information
Showing
23 changed files
with
361 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
68 changes: 68 additions & 0 deletions
68
src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubLink.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubOrgIcon.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubRepoIcon.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} | ||
} |
Oops, something went wrong.