Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JENKINS-34395] Support for tag discovery
- Loading branch information
Showing
9 changed files
with
522 additions
and
9 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
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
306 changes: 302 additions & 4 deletions
306
src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMSource.java
Large diffs are not rendered by default.
Oops, something went wrong.
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
29 changes: 29 additions & 0 deletions
29
src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubTagSCMHead.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,29 @@ | ||
package org.jenkinsci.plugins.github_branch_source; | ||
|
||
import edu.umd.cs.findbugs.annotations.NonNull; | ||
import jenkins.scm.api.SCMHead; | ||
import jenkins.scm.api.mixin.TagSCMHead; | ||
|
||
public class GitHubTagSCMHead extends SCMHead implements TagSCMHead { | ||
|
||
private final long timestamp; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param name the name. | ||
* @param timestamp the tag timestamp; | ||
*/ | ||
public GitHubTagSCMHead(@NonNull String name, long timestamp) { | ||
super(name); | ||
this.timestamp = timestamp; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public long getTimestamp() { | ||
return timestamp; | ||
} | ||
} |
149 changes: 149 additions & 0 deletions
149
src/main/java/org/jenkinsci/plugins/github_branch_source/TagDiscoveryTrait.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,149 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright (c) 2017, 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 edu.umd.cs.findbugs.annotations.NonNull; | ||
import hudson.Extension; | ||
import hudson.util.ListBoxModel; | ||
import jenkins.scm.api.SCMHead; | ||
import jenkins.scm.api.SCMHeadCategory; | ||
import jenkins.scm.api.SCMHeadOrigin; | ||
import jenkins.scm.api.SCMRevision; | ||
import jenkins.scm.api.SCMSource; | ||
import jenkins.scm.api.trait.SCMHeadAuthority; | ||
import jenkins.scm.api.trait.SCMHeadAuthorityDescriptor; | ||
import jenkins.scm.api.trait.SCMHeadFilter; | ||
import jenkins.scm.api.trait.SCMSourceContext; | ||
import jenkins.scm.api.trait.SCMSourceRequest; | ||
import jenkins.scm.api.trait.SCMSourceTrait; | ||
import jenkins.scm.api.trait.SCMSourceTraitDescriptor; | ||
import jenkins.scm.impl.ChangeRequestSCMHeadCategory; | ||
import jenkins.scm.impl.TagSCMHeadCategory; | ||
import jenkins.scm.impl.trait.Discovery; | ||
import org.kohsuke.accmod.Restricted; | ||
import org.kohsuke.accmod.restrictions.NoExternalUse; | ||
import org.kohsuke.github.GHPullRequest; | ||
import org.kohsuke.github.GHRepository; | ||
import org.kohsuke.stapler.DataBoundConstructor; | ||
|
||
/** | ||
* A {@link Discovery} trait for GitHub that will discover tags on the repository. | ||
* | ||
* @since TODO | ||
*/ | ||
public class TagDiscoveryTrait extends SCMSourceTrait { | ||
/** | ||
* Constructor for stapler. | ||
*/ | ||
@DataBoundConstructor | ||
public TagDiscoveryTrait() { | ||
|
||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
protected void decorateContext(SCMSourceContext<?, ?> context) { | ||
GitHubSCMSourceContext ctx = (GitHubSCMSourceContext) context; | ||
ctx.wantTags(true); | ||
ctx.withAuthority(new TagSCMHeadAuthority()); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public boolean includeCategory(@NonNull SCMHeadCategory category) { | ||
return category instanceof TagSCMHeadCategory; | ||
} | ||
|
||
/** | ||
* Our descriptor. | ||
*/ | ||
@Extension | ||
@Discovery | ||
public static class DescriptorImpl extends SCMSourceTraitDescriptor { | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public String getDisplayName() { | ||
return Messages.TagDiscoveryTrait_displayName(); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public Class<? extends SCMSourceContext> getContextClass() { | ||
return GitHubSCMSourceContext.class; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public Class<? extends SCMSource> getSourceClass() { | ||
return GitHubSCMSource.class; | ||
} | ||
|
||
} | ||
|
||
/** | ||
* Trusts branches from the origin repository. | ||
*/ | ||
public static class TagSCMHeadAuthority extends SCMHeadAuthority<SCMSourceRequest, GitHubTagSCMHead, SCMRevision> { | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
protected boolean checkTrusted(@NonNull SCMSourceRequest request, @NonNull GitHubTagSCMHead head) { | ||
return true; | ||
} | ||
|
||
/** | ||
* Out descriptor. | ||
*/ | ||
@Extension | ||
public static class DescriptorImpl extends SCMHeadAuthorityDescriptor { | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public String getDisplayName() { | ||
return Messages.TagDiscoveryTrait_authorityDisplayName(); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public boolean isApplicableToOrigin(@NonNull Class<? extends SCMHeadOrigin> originClass) { | ||
return SCMHeadOrigin.Default.class.isAssignableFrom(originClass); | ||
} | ||
} | ||
} | ||
} |
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
5 changes: 5 additions & 0 deletions
5
src/main/resources/org/jenkinsci/plugins/github_branch_source/TagDiscoveryTrait/config.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,5 @@ | ||
<?jelly escape-by-default='true'?> | ||
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:c="/lib/credentials" | ||
xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" | ||
xmlns:f2="/org/jenkinsci/plugins/github_branch_source/form"> | ||
</j:jelly> |
3 changes: 3 additions & 0 deletions
3
src/main/resources/org/jenkinsci/plugins/github_branch_source/TagDiscoveryTrait/help.html
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,3 @@ | ||
<div> | ||
Discovers tags on the repository. | ||
</div> |