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 #85 from jenkinsci/jenkins-39062
[JENKINS-39062] Move the GitHubRepositoryDescription column to github branch source
- Loading branch information
Showing
6 changed files
with
324 additions
and
0 deletions.
There are no files selected for viewing
118 changes: 118 additions & 0 deletions
118
src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubOrgAction.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,118 @@ | ||
/* | ||
* 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.Util; | ||
import hudson.model.InvisibleAction; | ||
import java.io.IOException; | ||
import java.io.ObjectStreamException; | ||
import java.net.URL; | ||
import jenkins.branch.OrganizationFolder; | ||
import org.apache.commons.lang.StringUtils; | ||
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 = Util.fixEmpty(name); | ||
this.avatar = Util.fixEmpty(avatar); | ||
} | ||
|
||
public GitHubOrgAction(GitHubOrgAction that) { | ||
this(that.getUrl(), that.getName(), that.getAvatar()); | ||
} | ||
|
||
private Object readResolve() throws ObjectStreamException { | ||
if ((name != null && StringUtils.isBlank(name)) | ||
|| (avatar != null && StringUtils.isBlank(avatar))) | ||
return new GitHubOrgAction(this); | ||
return this; | ||
} | ||
|
||
public URL getUrl() { | ||
return url; | ||
} | ||
|
||
public String getName() { | ||
return Util.fixEmpty(name); | ||
} | ||
|
||
public String getAvatar() { | ||
return Util.fixEmpty(avatar); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
|
||
GitHubOrgAction that = (GitHubOrgAction) o; | ||
|
||
return getUrl() != null ? getUrl().equals(that.getUrl()) : that.getUrl() == null; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public int hashCode() { | ||
return getUrl() != null ? getUrl().hashCode() : 0; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public String toString() { | ||
return "GitHubOrgAction{" + | ||
"url=" + url + | ||
", name='" + name + '\'' + | ||
", avatar='" + avatar + '\'' + | ||
"}"; | ||
} | ||
|
||
|
||
} |
116 changes: 116 additions & 0 deletions
116
src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubRepoAction.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,116 @@ | ||
/* | ||
* 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.Util; | ||
import hudson.model.InvisibleAction; | ||
import java.io.ObjectStreamException; | ||
import java.net.URL; | ||
import jenkins.branch.MultiBranchProject; | ||
import org.apache.commons.lang.StringUtils; | ||
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 = Util.fixEmpty(description); | ||
this.homepage = Util.fixEmpty(homepage); | ||
} | ||
|
||
public GitHubRepoAction(GitHubRepoAction that) { | ||
this(that.getUrl(), that.getDescription(), that.getHomepage()); | ||
} | ||
|
||
private Object readResolve() throws ObjectStreamException { | ||
if ((description != null && StringUtils.isBlank(description)) | ||
|| (homepage != null && StringUtils.isBlank(homepage))) | ||
return new GitHubRepoAction(this); | ||
return this; | ||
} | ||
|
||
public URL getUrl() { | ||
return url; | ||
} | ||
|
||
public String getDescription() { | ||
return description; | ||
} | ||
|
||
public String getHomepage() { | ||
return homepage; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
|
||
GitHubRepoAction that = (GitHubRepoAction) o; | ||
|
||
return getUrl() != null ? getUrl().equals(that.getUrl()) : that.getUrl() == null; | ||
|
||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public int hashCode() { | ||
return getUrl() != null ? getUrl().hashCode() : 0; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public String toString() { | ||
return "GitHubRepoAction{" + | ||
"url=" + url + | ||
", description='" + description + '\'' + | ||
", homepage='" + homepage + '\'' + | ||
"}"; | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
...in/java/org/jenkinsci/plugins/github_branch_source/GitHubRepositoryDescriptionColumn.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,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 com.cloudbees.hudson.plugins.folder.Folder; | ||
import hudson.Extension; | ||
import hudson.model.Actionable; | ||
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 Actionable) { | ||
return ((Actionable) 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; | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...org/jenkinsci/plugins/github_branch_source/GitHubRepositoryDescriptionColumn/column.jelly
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,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> |
4 changes: 4 additions & 0 deletions
4
...nkinsci/plugins/github_branch_source/GitHubRepositoryDescriptionColumn/columnHeader.jelly
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,4 @@ | ||
<?jelly escape-by-default='true'?> | ||
<j:jelly xmlns:j="jelly:core"> | ||
<th>${%Description}</th> | ||
</j:jelly> |
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