From 9870779db5174160fd0e245031fc92039adec6df Mon Sep 17 00:00:00 2001 From: Siarhei_Nekhviadovich Date: Fri, 28 Aug 2015 02:12:15 +0300 Subject: [PATCH 1/2] Add checkout attempts for stability and fix minor issues --- pom.xml | 3 +- .../gocd/github/GitHubPRBuildPlugin.java | 31 ++++++++++++------- src/main/resources/gerrit/plugin.xml | 2 +- src/main/resources/git/plugin.xml | 2 +- src/main/resources/github/plugin.xml | 2 +- src/main/resources/stash/plugin.xml | 2 +- 6 files changed, 25 insertions(+), 17 deletions(-) diff --git a/pom.xml b/pom.xml index 7605981..9419cff 100644 --- a/pom.xml +++ b/pom.xml @@ -90,13 +90,14 @@ - ${plugin.name}-${version} + ${plugin.name}-${project.version} src/main/resources/views ${resource.directory} + true diff --git a/src/main/java/in/ashwanthkumar/gocd/github/GitHubPRBuildPlugin.java b/src/main/java/in/ashwanthkumar/gocd/github/GitHubPRBuildPlugin.java index 8fdbc94..bc8be56 100644 --- a/src/main/java/in/ashwanthkumar/gocd/github/GitHubPRBuildPlugin.java +++ b/src/main/java/in/ashwanthkumar/gocd/github/GitHubPRBuildPlugin.java @@ -40,6 +40,8 @@ public class GitHubPRBuildPlugin implements GoPlugin { 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 CHECKOUT_ATTEMPTS = 3; public static final String BRANCH_TO_REVISION_MAP = "BRANCH_TO_REVISION_MAP"; private static final String DATE_PATTERN = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"; @@ -249,22 +251,27 @@ private GoPluginApiResponse handleCheckout(GoPluginApiRequest goPluginApiRequest String destinationFolder = (String) requestBodyMap.get("destination-folder"); Map revisionMap = (Map) requestBodyMap.get("revision"); String revision = (String) revisionMap.get("revision"); - LOGGER.info(String.format("destination: %s. commit: %s", destinationFolder, revision)); + for (int attempt = 0; attempt < CHECKOUT_ATTEMPTS; attempt++) { + LOGGER.info(String.format("destination: %s. commit: %s, attempt: %s", destinationFolder, revision, attempt)); - try { - GitHelper git = HelperFactory.git(gitConfig, new File(destinationFolder)); - git.cloneOrFetch(provider.getRefSpec()); - git.resetHard(revision); + try { + GitHelper git = HelperFactory.git(gitConfig, new File(destinationFolder)); + git.cloneOrFetch(provider.getRefSpec()); + git.resetHard(revision); - Map response = new HashMap(); - response.put("status", "success"); - response.put("messages", Arrays.asList(String.format("Checked out to revision %s", revision))); + Map response = new HashMap(); + response.put("status", "success"); + response.put("messages", Arrays.asList(String.format("Checked out to revision %s", revision))); - return renderJSON(SUCCESS_RESPONSE_CODE, response); - } catch (Throwable t) { - LOGGER.warn("checkout: ", t); - return renderJSON(INTERNAL_ERROR_RESPONSE_CODE, t.getMessage()); + return renderJSON(SUCCESS_RESPONSE_CODE, response); + } catch (Throwable t) { + LOGGER.warn(String.format("Attempt %s, checkout: ", attempt), t); + if (attempt >= CHECKOUT_ATTEMPTS) { + return renderJSON(INTERNAL_ERROR_RESPONSE_CODE, t.getMessage()); + } + } } + return renderJSON(INTERNAL_ERROR_RESPONSE_CODE, "Checkout failed"); } GitConfig getGitConfig(Map configuration) { diff --git a/src/main/resources/gerrit/plugin.xml b/src/main/resources/gerrit/plugin.xml index ccf24a3..ec3eafd 100644 --- a/src/main/resources/gerrit/plugin.xml +++ b/src/main/resources/gerrit/plugin.xml @@ -2,7 +2,7 @@ Gerrit Change Set plugin - 1.2 + ${project.version} 15.1.0 Provides ability to do change set builds for Gerrit repository diff --git a/src/main/resources/git/plugin.xml b/src/main/resources/git/plugin.xml index 87c2c47..254276c 100644 --- a/src/main/resources/git/plugin.xml +++ b/src/main/resources/git/plugin.xml @@ -2,7 +2,7 @@ Git Feature Branch plugin - 1.2 + ${project.version} 15.1.0 Provides ability to do feature branch builds for Git repository diff --git a/src/main/resources/github/plugin.xml b/src/main/resources/github/plugin.xml index 22080ca..fca3716 100644 --- a/src/main/resources/github/plugin.xml +++ b/src/main/resources/github/plugin.xml @@ -2,7 +2,7 @@ Github Pull Requests Builder - 1.2 + ${project.version} 15.1.0 Plugin that polls a GitHub repository for pull requests and triggers a build for each of them diff --git a/src/main/resources/stash/plugin.xml b/src/main/resources/stash/plugin.xml index 90d2752..1c1c487 100644 --- a/src/main/resources/stash/plugin.xml +++ b/src/main/resources/stash/plugin.xml @@ -2,7 +2,7 @@ Stash Pull Requests Builder - 1.2 + ${project.version} 15.1.0 Plugin that polls a Stash repository for pull requests and triggers a build for each of them From 6cef630a92c586d75d2f40181495e5bc6a009296 Mon Sep 17 00:00:00 2001 From: Siarhei_Nekhviadovich Date: Sun, 20 Sep 2015 20:00:48 +0300 Subject: [PATCH 2/2] Total checkout attempts added to log --- .../in/ashwanthkumar/gocd/github/GitHubPRBuildPlugin.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/in/ashwanthkumar/gocd/github/GitHubPRBuildPlugin.java b/src/main/java/in/ashwanthkumar/gocd/github/GitHubPRBuildPlugin.java index bc8be56..7dea59c 100644 --- a/src/main/java/in/ashwanthkumar/gocd/github/GitHubPRBuildPlugin.java +++ b/src/main/java/in/ashwanthkumar/gocd/github/GitHubPRBuildPlugin.java @@ -252,7 +252,7 @@ private GoPluginApiResponse handleCheckout(GoPluginApiRequest goPluginApiRequest Map revisionMap = (Map) requestBodyMap.get("revision"); String revision = (String) revisionMap.get("revision"); for (int attempt = 0; attempt < CHECKOUT_ATTEMPTS; attempt++) { - LOGGER.info(String.format("destination: %s. commit: %s, attempt: %s", destinationFolder, revision, attempt)); + LOGGER.info(String.format("destination: %s. commit: %s, attempt: %s out of %s", destinationFolder, revision, attempt, CHECKOUT_ATTEMPTS)); try { GitHelper git = HelperFactory.git(gitConfig, new File(destinationFolder)); @@ -265,7 +265,7 @@ private GoPluginApiResponse handleCheckout(GoPluginApiRequest goPluginApiRequest return renderJSON(SUCCESS_RESPONSE_CODE, response); } catch (Throwable t) { - LOGGER.warn(String.format("Attempt %s, checkout: ", attempt), t); + LOGGER.warn(String.format("Attempt %s out of %s, checkout: ", attempt, CHECKOUT_ATTEMPTS), t); if (attempt >= CHECKOUT_ATTEMPTS) { return renderJSON(INTERNAL_ERROR_RESPONSE_CODE, t.getMessage()); }