Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[JENKINS-39062] Move the GitHubRepositoryDescription column to github…
… branch source
  • Loading branch information
stephenc committed Oct 18, 2016
1 parent 03f37a2 commit c74d2f5
Show file tree
Hide file tree
Showing 6 changed files with 225 additions and 0 deletions.
@@ -0,0 +1,69 @@
/*
* The MIT License
*
* Copyright 2016 CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package org.jenkinsci.plugins.github_branch_source;

import hudson.model.InvisibleAction;
import java.io.IOException;
import java.net.URL;
import jenkins.branch.OrganizationFolder;
import org.kohsuke.github.GHUser;

/**
* Invisible {@link OrganizationFolder} property that
* retains information about GitHub organization.
*
* @author Kohsuke Kawaguchi
*/
public class GitHubOrgAction extends InvisibleAction {
private final URL url;
private final String name;
private final String avatar;

public GitHubOrgAction(GHUser org) throws IOException {
this(org.getHtmlUrl(), org.getName(), org.getAvatarUrl());
}

public GitHubOrgAction(URL url, String name, String avatar) {
this.url = url;
this.name = name;
this.avatar = avatar;
}

public GitHubOrgAction(GitHubOrgAction that) {
this(that.getUrl(), that.getName(), that.getAvatar());
}

public URL getUrl() {
return url;
}

public String getName() {
return name;
}

public String getAvatar() {
return avatar;
}
}
@@ -0,0 +1,68 @@
/*
* The MIT License
*
* Copyright 2016 CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package org.jenkinsci.plugins.github_branch_source;

import hudson.model.InvisibleAction;
import java.net.URL;
import jenkins.branch.MultiBranchProject;
import org.kohsuke.github.GHRepository;

/**
* Invisible property on {@link MultiBranchProject}
* that retains information about GitHub repository.
*
* @author Kohsuke Kawaguchi
*/
public class GitHubRepoAction extends InvisibleAction {
private final URL url;
private final String description;
private final String homepage;

public GitHubRepoAction(GHRepository repo) {
this(repo.getHtmlUrl(), repo.getDescription(), repo.getHomepage());
}

public GitHubRepoAction(URL url, String description, String homepage) {
this.url = url;
this.description = description;
this.homepage = homepage;
}

public GitHubRepoAction(GitHubRepoAction that) {
this(that.getUrl(), that.getDescription(), that.getHomepage());
}

public URL getUrl() {
return url;
}

public String getDescription() {
return description;
}

public String getHomepage() {
return homepage;
}
}
@@ -0,0 +1,67 @@
/*
* The MIT License
*
* Copyright 2016 CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package org.jenkinsci.plugins.github_branch_source;

import hudson.Extension;
import hudson.model.Item;
import hudson.model.Job;
import hudson.views.ListViewColumn;
import hudson.views.ListViewColumnDescriptor;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.stapler.DataBoundConstructor;

/**
* {@link ListViewColumn} that shows the description text of repository.
*
* @author Kohsuke Kawaguchi
*/
public class GitHubRepositoryDescriptionColumn extends ListViewColumn {
@DataBoundConstructor
public GitHubRepositoryDescriptionColumn() {
}

@Restricted(NoExternalUse.class)
@SuppressWarnings("unused") // used via Jelly EL binding
public GitHubRepoAction getRepositoryOf(Item item) {
if (item instanceof Job) {
return ((Job) item).getAction(GitHubRepoAction.class);
}
return null;
}

@Extension
public static class DescriptorImpl extends ListViewColumnDescriptor {
@Override
public String getDisplayName() {
return Messages.GitHubRepositoryDescriptionColumn_DisplayName();
}

@Override
public boolean shownByDefault() {
return false;
}
}
}
@@ -0,0 +1,15 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core">
<td>
<j:set var="p" value="${col.getRepositoryOf(job)}"/>
<j:choose>
<j:when test="${p != null and p.homepage != null">
<a href="${p.homepage}">${p.description}</a>
</j:when>
<j:when test="${p != null and p.homepage == null}">
${p.description}
</j:when>
<j:otherwise/>
</j:choose>
</td>
</j:jelly>
@@ -0,0 +1,4 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core">
<th>${%Description}</th>
</j:jelly>
Expand Up @@ -12,6 +12,8 @@ GitHubBuildStatusNotification.CommitStatusSet=GitHub has been notified of this c

GitHubPullRequestFilter.DisplayName=GitHub Pull Request Jobs Only

GitHubRepositoryDescriptionColumn.DisplayName=GitHub Repository Description

GitHubSCMNavigator.DisplayName=GitHub Organization
GitHubSCMNavigator.Description=Scans a GitHub organization (or user account) for all repositories matching some defined markers.
GitHubSCMNavigator.Pronoun=Organization
Expand Down

0 comments on commit c74d2f5

Please sign in to comment.