Skip to content

Commit

Permalink
Merge pull request #68 from indix/s3fetch-plugin-fix
Browse files Browse the repository at this point in the history
Resolves fetch plugin incompatibility with gocd > 18.10
  • Loading branch information
brewkode authored Jan 30, 2019
2 parents 636708b + 2192df2 commit f0464e2
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 9 deletions.
4 changes: 4 additions & 0 deletions fetch/src/main/java/com/indix/gocd/s3fetch/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class Config {
private final String source;
private final String sourcePrefix;
private final String destination;
private final String jobName;

public String getMaterialType() {
return materialType;
Expand Down Expand Up @@ -52,6 +53,8 @@ public String getDestination() {
return destination;
}

public String getJobName() { return jobName; }

public Config(Map config) {
materialType = getValue(config, MATERIAL_TYPE);
repo = getValue(config, REPO);
Expand All @@ -62,6 +65,7 @@ public Config(Map config) {
source = getValue(config, SOURCE);
sourcePrefix = getValue(config, SOURCE_PREFIX);
destination = getValue(config, DESTINATION);
jobName = getValue(config, JOB_NAME);
}

private String escapeEnvironmentVariable(String value) {
Expand Down
5 changes: 5 additions & 0 deletions fetch/src/main/java/com/indix/gocd/s3fetch/FetchTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ private GoPluginApiResponse handleGetConfigRequest() {
destination.put("required", false);
config.put(Constants.DESTINATION, destination);

HashMap jobName = new HashMap();
jobName.put("default-value", "");
jobName.put("required", false);
config.put(Constants.JOB_NAME, jobName);

return createResponse(DefaultGoPluginApiResponse.SUCCESS_RESPONSE_CODE, config);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected String getArtifactsLocationTemplate(Config config, GoEnvironment env)
String pipelineCounter = locatorParts[1];
String stage = locatorParts[2];
String stageCounter = locatorParts[3];
String job = config.getJob();
String job = config.getJobName();

return env.artifactsLocationTemplate(pipeline, stage, job, pipelineCounter, stageCounter);
}
Expand All @@ -33,8 +33,8 @@ public Map<String, String> validate(Config config) {
if (StringUtils.isBlank(config.getMaterial())) {
errors.put(Constants.MATERIAL, Constants.REQUIRED_FIELD_MESSAGE);
}
if (StringUtils.isBlank(config.getJob())) {
errors.put(Constants.JOB, Constants.REQUIRED_FIELD_MESSAGE);
if (StringUtils.isBlank(config.getJobName())) {
errors.put(Constants.JOB_NAME, Constants.REQUIRED_FIELD_MESSAGE);
}
return errors;
}
Expand Down
5 changes: 3 additions & 2 deletions fetch/src/main/resources/views/task.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
</div>
<div class="form_item_block" ng-show="MaterialType == 'Pipeline'">
<label>Job:<span class="asterisk">*</span></label>
<input type="text" ng-model="Job" ng-required="true">
<span class="form_error" ng-show="GOINPUTNAME[Job].$error.server">{{ GOINPUTNAME[Job].$error.server }}</span>
<input type="text" ng-model="JobName" ng-required="true">
<span class="form_error" ng-show="GOINPUTNAME[JobName].$error.server">{{ GOINPUTNAME[JobName].$error.server }}</span>
</div>

<!-- Stage fields -->
Expand Down Expand Up @@ -85,6 +85,7 @@
this.Repo = null;
this.Package = null;
this.Material = null;
this.JobName = null;
this.clearStageFields();
};
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void setUp() throws Exception {
config = new Config(Maps.builder()
.with(Constants.MATERIAL_TYPE, Maps.builder().with("value", "Pipeline").build())
.with(Constants.MATERIAL, Maps.builder().with("value", "mymaterial").build())
.with(Constants.JOB, Maps.builder().with("value", "job").build())
.with(Constants.JOB_NAME, Maps.builder().with("value", "job").build())
.with(Constants.DESTINATION, Maps.builder().with("value", "artifacts").build())
.build());

Expand Down Expand Up @@ -105,7 +105,7 @@ public void shouldBeAbleToHandleTaskConfigEntriesWithDashesInTheName() {

config = new Config(Maps.builder()
.with(Constants.MATERIAL, Maps.builder().with("value", "my-material").build())
.with(Constants.JOB, Maps.builder().with("value", "job").build())
.with(Constants.JOB_NAME, Maps.builder().with("value", "job").build())
.with(Constants.DESTINATION, Maps.builder().with("value", "artifacts").build())
.build());
TaskExecutionResult result = fetchExecutor.execute(config, mockContext(mockVariables));
Expand All @@ -125,7 +125,7 @@ public void shouldBeAbleToHandleTaskConfigEntriesWithPeriodsInTheName() {

config = new Config(Maps.builder()
.with(Constants.MATERIAL, Maps.builder().with("value", "my.material").build())
.with(Constants.JOB, Maps.builder().with("value", "job").build())
.with(Constants.JOB_NAME, Maps.builder().with("value", "job").build())
.with(Constants.DESTINATION, Maps.builder().with("value", "artifacts").build())
.build());
TaskExecutionResult result = fetchExecutor.execute(config, mockContext(mockVariables));
Expand All @@ -145,7 +145,7 @@ public void shouldBeAbleToHandleTaskConfigEntriesWithSpecialCharactersInTheName(

config = new Config(Maps.builder()
.with(Constants.MATERIAL, Maps.builder().with("value", "my`~!@#$%^&*()-+=[{]}\\|;:'\",<.>/?material").build())
.with(Constants.JOB, Maps.builder().with("value", "job").build())
.with(Constants.JOB_NAME, Maps.builder().with("value", "job").build())
.with(Constants.DESTINATION, Maps.builder().with("value", "artifacts").build())
.build());
TaskExecutionResult result = fetchExecutor.execute(config, mockContext(mockVariables));
Expand Down
1 change: 1 addition & 0 deletions utils/src/main/java/com/indix/gocd/utils/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class Constants {
public static final String SOURCE = "Source";
public static final String SOURCE_PREFIX = "SourcePrefix";
public static final String DESTINATION = "Destination";
public static final String JOB_NAME = "JobName";

public static final String REQUIRED_FIELD_MESSAGE = "This field is required";
}

0 comments on commit f0464e2

Please sign in to comment.