Skip to content

Commit

Permalink
Fix Scm Config type not saved (riboseinc#42)
Browse files Browse the repository at this point in the history
* Fix document incomplete (riboseinc#53)

* update versions for release

* update for next development version

* Update permission list

* Update description in configure page

* Fix Git SCM Config unable to saved since the UI not send Json format

* Remove unused imports

* Fix Integration Test failed since short branch name is supported

* Update link build badge

* Test 2 threads only to reduce time
  • Loading branch information
phuonghuynh authored Jun 14, 2018
1 parent 3e6d06d commit 4f6cd87
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 12 deletions.
3 changes: 1 addition & 2 deletions README.adoc
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
= AWS CodeCommit Trigger Plugin

image:https://img.shields.io/travis/jenkinsci/aws-codecommit-trigger-plugin.svg?style=flat-square[link=https://travis-ci.org/jenkinsci/aws-codecommit-trigger-plugin]
image:https://img.shields.io/travis/jenkinsci/aws-codecommit-trigger-plugin.svg?style=flat-square[link=https://travis-ci.org/jenkinsci/aws-codecommit-trigger-plugin.svg?branch=master]
image:https://img.shields.io/:license-apache-blue.svg?style=flat-square[link=https://www.apache.org/licenses/LICENSE-2.0.html]


== Introduction

A Jenkins plugin that triggers jobs on repo update events by AWS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,19 @@ public static class DescriptorImpl extends Descriptor<SQSScmConfig> {

@Override
public SQSScmConfig newInstance(StaplerRequest req, @Nonnull JSONObject jsonObject) throws FormException {
JSONObject json = jsonObject.getJSONObject("type");
json.put("type", json.getString("value"));
json.remove("value");
return super.newInstance(req, json);//req.bindJSON(SQSScmConfig.class, json);
Object typeObject = jsonObject.get("type");
if (typeObject.getClass().isAssignableFrom(JSONObject.class)) {
JSONObject jsonType = jsonObject.getJSONObject("type");
jsonObject.put("type", jsonType.getString("value"));
}
return super.newInstance(req, jsonObject);
}

public FormValidation doCheckUrl(@QueryParameter final String url) {
if (StringUtils.isBlank(url)) {
return FormValidation.warning(Messages.warningBlankUrl());
}

return com.ribose.jenkins.plugin.awscodecommittrigger.utils.StringUtils.isCodeCommitRepo(url)
? FormValidation.ok()
: FormValidation.error(Messages.errorCodeCommitUrlInvalid());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@
import jenkins.model.Jenkins;
import net.sf.json.JSONObject;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.ListUtils;
import org.apache.commons.collections.Predicate;
import org.apache.commons.collections.Transformer;
import org.apache.commons.lang3.StringUtils;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.kohsuke.stapler.DataBoundConstructor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public interface Event {
*/
String getBranch();

String getNoPrefixBranch();

/**
* Returns a value indicating whether the specified URI matches the events host and path
* information.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,11 @@ private boolean matchesConfigs(final Event event, final List<RemoteConfig> confi
private boolean matchBranch(final Event event, final List<BranchSpec> branchSpecs) {//TODO use it
for (BranchSpec branchSpec : branchSpecs) {
if (branchSpec.matches(event.getBranch())) {
log.debug("Event %s matched branch %s", event.getArn(), branchSpec.getName());
log.debug("Event branch: %s matched branch: %s", event.getBranch(), branchSpec.getName());
return true;
}
else if (branchSpec.matches(event.getNoPrefixBranch())) {
log.debug("Event no-prefix-branch: %s matched branch: %s", event.getNoPrefixBranch(), branchSpec.getName());
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class CodeCommitEvent implements Event {
private final String host;
private final String path;
private final String branch;
private final String noPrefixBranch;
private final String arn;
private final String user;

Expand All @@ -44,6 +45,7 @@ public CodeCommitEvent(final Record record, final Reference reference) {
this.path = String.format(PATH, tokens[5]);

this.branch = reference.getName();
this.noPrefixBranch = reference.getName().replaceAll("(refs/heads|refs/remotes|remotes)", ""); //truncate all possible git remote prefix, ref hudson.plugins.git.BranchSpec.getPattern
this.user = record.getUserIdentityARN();
}

Expand All @@ -67,6 +69,11 @@ public String getBranch() {
return this.branch;
}

@Override
public String getNoPrefixBranch() {
return this.noPrefixBranch;
}

@Override
public boolean isMatch(final URIish uri) {
if (uri == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<f:entry>
<div>
<input type="button" value="${%clear}" class="yui-button validate-button"
onclick="validateButton('clear', '', this)"/>
onclick="validateButton('clear', '', this)" />
</div>
<div><!-- this is where the error message goes --></div>
<a href=""></a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<b>Multiple branches</b>
<div>
Tracks multiple branches in csv format
<br/>E.g. <code>development, master, *feature, feature/**</code>
<br/>E.g. <code>development, master, */master, *feature, feature/**</code>
</div>
</li>
<li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
<ul>
<li>sqs:ReceiveMessage</li>
<li>sqs:DeleteMessageBatch</li>
<li>sqs:GetQueueAttributes</li>
<li>sqs:ListQueues <b>(optional - to query ListQueues)</b></li>
</ul>
</f:block>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.ribose.jenkins.plugin.awscodecommittrigger.interfaces.Event;
import com.ribose.jenkins.plugin.awscodecommittrigger.model.entities.codecommit.Record;
import com.ribose.jenkins.plugin.awscodecommittrigger.utils.StringUtils;
import hudson.plugins.git.BranchSpec;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.ListUtils;
import org.apache.commons.collections.Predicate;
Expand Down Expand Up @@ -128,4 +129,12 @@ public boolean evaluate(Object o) {

Assertions.assertThat(sample).hasSize(1);
}

@Test
public void testGitBranchSpec() {
BranchSpec gitBranchSpec = new BranchSpec("master");
String fetchBranch = "refs/heads/master";
boolean matched = gitBranchSpec.matches(fetchBranch);
Assertions.assertThat(matched).isTrue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class JenkinsIT extends AbstractFreestyleIT {

public JenkinsIT() {
projectFixtures = new ArrayList<>();
for (int i = 0; i < 9; i++) {
for (int i = 0; i < 2; i++) {
String branch = String.format("%s_%s", i, UUID.randomUUID().toString());
projectFixtures.add(
new ProjectFixture()
Expand Down

0 comments on commit 4f6cd87

Please sign in to comment.