Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
srinivasupadhya authored and sriniup committed May 21, 2015
1 parent 7cc8e0b commit 5aac00e
Showing 1 changed file with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,25 @@

@Extension
public class GitHubPRBuildPlugin implements GoPlugin {
private static Logger LOGGER = Logger.getLoggerFor(GitHubPRBuildPlugin.class);

public static final String EXTENSION_NAME = "scm";
private static final List<String> goSupportedVersions = asList("1.0");

public static final String REQUEST_SCM_CONFIGURATION = "scm-configuration";
public static final String REQUEST_SCM_VIEW = "scm-view";
public static final String REQUEST_VALIDATE_SCM_CONFIGURATION = "validate-scm-configuration";
public static final String REQUEST_CHECK_SCM_CONNECTION = "check-scm-connection";
public static final String REQUEST_LATEST_REVISION = "latest-revision";
public static final String REQUEST_LATEST_REVISIONS_SINCE = "latest-revisions-since";
public static final String REQUEST_CHECKOUT = "checkout";
public static final int SUCCESS_RESPONSE_CODE = 200;
public static final int INTERNAL_ERROR_RESPONSE_CODE = 500;

public static final String BRANCH_TO_REVISION_MAP = "BRANCH_TO_REVISION_MAP";
private static final List<String> goSupportedVersions = asList("1.0");
private static final String DATE_PATTERN = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
private static Logger LOGGER = Logger.getLoggerFor(GitHubPRBuildPlugin.class);

public static final int SUCCESS_RESPONSE_CODE = 200;
public static final int NOT_FOUND_RESPONSE_CODE = 404;
public static final int INTERNAL_ERROR_RESPONSE_CODE = 500;

private Provider provider;

Expand Down Expand Up @@ -71,7 +76,7 @@ public GoPluginApiResponse handle(GoPluginApiRequest goPluginApiRequest) {
return handleSCMView();
} catch (IOException e) {
String message = "Failed to find template: " + e.getMessage();
return renderJSON(500, message);
return renderJSON(INTERNAL_ERROR_RESPONSE_CODE, message);
}
} else if (goPluginApiRequest.requestName().equals(REQUEST_VALIDATE_SCM_CONFIGURATION)) {
return handleSCMValidation(goPluginApiRequest);
Expand All @@ -84,7 +89,7 @@ public GoPluginApiResponse handle(GoPluginApiRequest goPluginApiRequest) {
} else if (goPluginApiRequest.requestName().equals(REQUEST_CHECKOUT)) {
return handleCheckout(goPluginApiRequest);
}
return null;
return renderJSON(NOT_FOUND_RESPONSE_CODE, null);
}

@Override
Expand All @@ -107,7 +112,7 @@ private GoPluginApiResponse handleSCMConfiguration() {
private GoPluginApiResponse handleSCMView() throws IOException {
Map<String, Object> response = new HashMap<String, Object>();
response.put("displayValue", provider.getName());
response.put("template", IOUtils.toString(getClass().getResourceAsStream("/scm.template.html"), "UTF-8"));
response.put("template", getFileContents("/scm.template.html"));
return renderJSON(SUCCESS_RESPONSE_CODE, response);
}

Expand Down Expand Up @@ -347,6 +352,10 @@ public void checkConnection(GitConfig gitConfig, Map<String, Object> response, L
}
}

private String getFileContents(String filePath) throws IOException {
return IOUtils.toString(getClass().getResourceAsStream(filePath), "UTF-8");
}

GoPluginApiResponse renderJSON(final int responseCode, Object response) {
final String json = response == null ? null : JSONUtils.toJSON(response);
return new GoPluginApiResponse() {
Expand Down

0 comments on commit 5aac00e

Please sign in to comment.