-
Notifications
You must be signed in to change notification settings - Fork 0
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 #4 from vistaprint/master
Issue 5: Allow passing in of variables to octopus deployment
- Loading branch information
Showing
16 changed files
with
288 additions
and
94 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1,92 @@ | ||
package com.octopusdeploy.api; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
/** | ||
* Parses errors from Octopus html/javascript responses | ||
* @author jlabroad | ||
*/ | ||
public class ErrorParser { | ||
|
||
/** Find a group of messages in the format: "Errors":["error message 1", "error message 2", "error message 3"] */ | ||
protected static final String errDetailsOutsideString = "(?:\\\"Errors\\\")(?:[^\\[]\\[)(?<fullDetailString>[^\\]]+)"; | ||
protected static Pattern errDetailsOutsidePattern = Pattern.compile(errDetailsOutsideString); | ||
|
||
/** Parse each individual message from "error message 1", "error message 2", "error message 3" */ | ||
protected static final String errDetailsInsideString = "(?:\\\")(?<singleError>[^\\\"]+)*(?:\\\")"; | ||
protected static Pattern errDetailsInsidePattern = Pattern.compile(errDetailsInsideString); | ||
|
||
/** | ||
* Parse any errors from the returned HTML/javascript from Octopus | ||
* @param response The Octopus html response that may include error data | ||
* @return A list of error strings | ||
*/ | ||
public static String getErrorsFromResponse(String response) { | ||
List<String> errorStrings = new ArrayList<String>(); | ||
|
||
//Get the error title and main message | ||
String errorTitle = getErrorDataByFieldName("title", response); | ||
if (!errorTitle.isEmpty()) { | ||
errorStrings.add(String.format("%s", errorTitle)); | ||
} | ||
|
||
//Get the error details | ||
String errorDetailMessage = getErrorDataByFieldName("ErrorMessage", response); | ||
if (!errorDetailMessage.isEmpty()) { | ||
errorStrings.add("\t" + errorDetailMessage); | ||
} | ||
errorStrings.addAll(getErrorDetails(response)); | ||
|
||
String errorMsg = ""; | ||
for (String err : errorStrings) { | ||
errorMsg += String.format("%s\n", err); | ||
} | ||
|
||
return errorMsg; | ||
} | ||
|
||
/** | ||
* Grabs a single error data field from an Octopus html response | ||
* @param fieldName The field name of the error string | ||
* @param response The field data | ||
* @return The error data | ||
*/ | ||
protected static String getErrorDataByFieldName(String fieldName, String response) { | ||
//Get the next string in script parameter list: "var errorData = {<fieldName>:"Field value", ... | ||
final String patternString = String.format("(?:errorData.+)(?:\"%s\")(?:[:\\[\"]+)(?<fieldValue>[^\"]+)", fieldName); | ||
|
||
Pattern pattern = Pattern.compile(patternString); | ||
Matcher matcher = pattern.matcher(response); | ||
String errData = ""; | ||
if (matcher.find() && matcher.groupCount() > 0) { | ||
errData = matcher.group("fieldValue"); | ||
} | ||
return errData; | ||
} | ||
|
||
/** | ||
* Returns a list of "Errors" values from Octopus html response | ||
* @param response The full Octopus html response | ||
* @return | ||
*/ | ||
protected static List<String> getErrorDetails(String response) { | ||
List<String> errorList = new ArrayList<String>(); | ||
|
||
Matcher m = errDetailsOutsidePattern.matcher(response); | ||
if (m.find() && m.groupCount() > 0) { | ||
//Split up the list of error messages into individual messages | ||
String errors = m.group("fullDetailString"); | ||
m = errDetailsInsidePattern.matcher(errors); | ||
while (m.find() && m.groupCount() > 0) { | ||
errorList.add("\t" + m.group("singleError")); | ||
} | ||
} | ||
return errorList; | ||
} | ||
} | ||
package com.octopusdeploy.api; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
import org.apache.commons.lang.StringEscapeUtils; | ||
|
||
/** | ||
* Parses errors from Octopus html/javascript responses | ||
* @author jlabroad | ||
*/ | ||
public class ErrorParser { | ||
|
||
/** Find a group of messages in the format: "Errors":["error message 1", "error message 2", "error message 3"] */ | ||
protected static final String errDetailsOutsideString = "(?:\\\"Errors\\\")(?:[^\\[]\\[)(?<fullDetailString>[^\\]]+)"; | ||
protected static Pattern errDetailsOutsidePattern = Pattern.compile(errDetailsOutsideString); | ||
|
||
/** Parse each individual message from "error message 1", "error message 2", "error message 3" */ | ||
protected static final String errDetailsInsideString = "(?:\\\")(?<singleError>[^\\\"]+)*(?:\\\")"; | ||
protected static Pattern errDetailsInsidePattern = Pattern.compile(errDetailsInsideString); | ||
|
||
/** | ||
* Parse any errors from the returned HTML/javascript from Octopus | ||
* @param response The Octopus html response that may include error data | ||
* @return A list of error strings | ||
*/ | ||
public static String getErrorsFromResponse(String response) { | ||
List<String> errorStrings = new ArrayList<String>(); | ||
|
||
//Get the error title and main message | ||
String errorTitle = getErrorDataByFieldName("title", response); | ||
if (!errorTitle.isEmpty()) { | ||
errorStrings.add(String.format("%s", errorTitle)); | ||
} | ||
|
||
//Get the error details | ||
String errorDetailMessage = getErrorDataByFieldName("ErrorMessage", response); | ||
if (!errorDetailMessage.isEmpty()) { | ||
errorStrings.add("\t" + errorDetailMessage); | ||
} | ||
errorStrings.addAll(getErrorDetails(response)); | ||
|
||
String errorMsg = ""; | ||
for (String err : errorStrings) { | ||
errorMsg += String.format("%s\n", err); | ||
} | ||
|
||
return errorMsg; | ||
} | ||
|
||
/** | ||
* Grabs a single error data field from an Octopus html response | ||
* @param fieldName The field name of the error string | ||
* @param response The field data | ||
* @return The error data | ||
*/ | ||
protected static String getErrorDataByFieldName(String fieldName, String response) { | ||
//Get the next string in script parameter list: "var errorData = {<fieldName>:"Field value", ... | ||
final String patternString = String.format("(?:errorData.+)(?:\"%s\")(?:[:\\[\"]+)(?<fieldValue>[^\"]+)", fieldName); | ||
|
||
Pattern pattern = Pattern.compile(patternString); | ||
Matcher matcher = pattern.matcher(response); | ||
String errData = ""; | ||
if (matcher.find() && matcher.groupCount() > 0) { | ||
errData = matcher.group("fieldValue"); | ||
} | ||
return errData; | ||
} | ||
|
||
/** | ||
* Returns a list of "Errors" values from Octopus html response | ||
* @param response The full Octopus html response | ||
* @return | ||
*/ | ||
protected static List<String> getErrorDetails(String response) { | ||
List<String> errorList = new ArrayList<String>(); | ||
|
||
Matcher m = errDetailsOutsidePattern.matcher(response); | ||
if (m.find() && m.groupCount() > 0) { | ||
//Split up the list of error messages into individual messages | ||
String errors = m.group("fullDetailString"); | ||
m = errDetailsInsidePattern.matcher(errors); | ||
while (m.find() && m.groupCount() > 0) { | ||
String singleError = StringEscapeUtils.unescapeJava(m.group("singleError")); | ||
errorList.add("\t" + singleError); | ||
} | ||
} | ||
return errorList; | ||
} | ||
} |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.octopusdeploy.api; | ||
|
||
/** | ||
* Represents a variable that will be passed to a deployment. | ||
*/ | ||
public class Variable { | ||
private final String name; | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
private final String value; | ||
public String getValue() { | ||
return value; | ||
} | ||
|
||
private final String id; | ||
public String getId() { | ||
return id; | ||
} | ||
|
||
private final String description; | ||
public String getDescription() { | ||
return description; | ||
} | ||
|
||
public Variable(String id, String name, String value, String description) | ||
{ | ||
this.id = id; | ||
this.name = name; | ||
this.value = value; | ||
this.description = description; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Variable [name=" + name + ", value=" + value + ", id=" + id + ", description=" + description + "]"; | ||
} | ||
|
||
} |
Oops, something went wrong.