Skip to content

Commit

Permalink
[JENKINS-39067] Move the GitHub icons to the github-branch-source plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenc committed Oct 18, 2016
1 parent 0b13cf6 commit 298e343
Show file tree
Hide file tree
Showing 21 changed files with 357 additions and 0 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;
}
}
@@ -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();
}
}
}
@@ -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();
}
}
}
Expand Up @@ -475,6 +475,57 @@ public FormValidation doCheckBuildOriginPRHead(@QueryParameter boolean buildOrig
new Icon("icon-github-scm-navigator icon-xlg",
"plugin/github-branch-source/images/48x48/github-scmnavigator.png",
Icon.ICON_XLARGE_STYLE));

IconSet.icons.addIcon(
new Icon("icon-github-logo icon-sm",
"plugin/github-branch-source/images/16x16/github-logo.png",
Icon.ICON_SMALL_STYLE));
IconSet.icons.addIcon(
new Icon("icon-github-logo icon-md",
"plugin/github-branch-source/images/24x24/github-logo.png",
Icon.ICON_MEDIUM_STYLE));
IconSet.icons.addIcon(
new Icon("icon-github-logo icon-lg",
"plugin/github-branch-source/images/32x32/github-logo.png",
Icon.ICON_LARGE_STYLE));
IconSet.icons.addIcon(
new Icon("icon-github-logo icon-xlg",
"plugin/github-branch-source/images/48x48/github-logo.png",
Icon.ICON_XLARGE_STYLE));

IconSet.icons.addIcon(
new Icon("icon-github-repo icon-sm",
"plugin/github-branch-source/images/16x16/github-repo.png",
Icon.ICON_SMALL_STYLE));
IconSet.icons.addIcon(
new Icon("icon-github-repo icon-md",
"plugin/github-branch-source/images/24x24/github-repo.png",
Icon.ICON_MEDIUM_STYLE));
IconSet.icons.addIcon(
new Icon("icon-github-repo icon-lg",
"plugin/github-branch-source/images/32x32/github-repo.png",
Icon.ICON_LARGE_STYLE));
IconSet.icons.addIcon(
new Icon("icon-github-repo icon-xlg",
"plugin/github-branch-source/images/48x48/github-repo.png",
Icon.ICON_XLARGE_STYLE));

IconSet.icons.addIcon(
new Icon("icon-github-branch icon-sm",
"plugin/github-branch-source/images/16x16/github-branch.png",
Icon.ICON_SMALL_STYLE));
IconSet.icons.addIcon(
new Icon("icon-github-branch icon-md",
"plugin/github-branch-source/images/24x24/github-branch.png",
Icon.ICON_MEDIUM_STYLE));
IconSet.icons.addIcon(
new Icon("icon-github-branch icon-lg",
"plugin/github-branch-source/images/32x32/github-branch.png",
Icon.ICON_LARGE_STYLE));
IconSet.icons.addIcon(
new Icon("icon-github-branch icon-xlg",
"plugin/github-branch-source/images/48x48/github-branch.png",
Icon.ICON_XLARGE_STYLE));
}
}

Expand Down
Expand Up @@ -10,8 +10,16 @@ GitHubBuildStatusNotification.CommitStatus.Pending=This commit is being built
GitHubBuildStatusNotification.CommitStatus.Queued=This commit is scheduled to be built
GitHubBuildStatusNotification.CommitStatusSet=GitHub has been notified of this commit\u2019s build result

GitHubLink.DisplayName=GitHub

GitHubOrgIcon.Description=GitHub
GitHubOrgIcon.DisplayName=GitHub Organization Avatar

GitHubPullRequestFilter.DisplayName=GitHub Pull Request Jobs Only

GitHubRepoIcon.Description=Repository
GitHubRepoIcon.DisplayName=GitHub Repository Icon

GitHubRepositoryDescriptionColumn.DisplayName=GitHub Repository Description

GitHubSCMNavigator.DisplayName=GitHub Organization
Expand Down
Binary file added src/main/webapp/images/16x16/github-branch.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/webapp/images/16x16/github-logo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/webapp/images/16x16/github-repo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/webapp/images/24x24/github-branch.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/webapp/images/24x24/github-logo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/webapp/images/24x24/github-repo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/webapp/images/32x32/github-branch.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/webapp/images/32x32/github-logo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/webapp/images/32x32/github-repo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/webapp/images/48x48/github-branch.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/webapp/images/48x48/github-logo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/webapp/images/48x48/github-repo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 298e343

Please sign in to comment.