Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,14 @@
</profiles>

<build>
<finalName>${plugin.name}-${version}</finalName>
<finalName>${plugin.name}-${project.version}</finalName>
<resources>
<resource>
<directory>src/main/resources/views</directory>
</resource>
<resource>
<directory>${resource.directory}</directory>
<filtering>true</filtering>
</resource>
</resources>

Expand Down
29 changes: 18 additions & 11 deletions src/main/java/in/ashwanthkumar/gocd/github/GitHubPRBuildPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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'";
Expand Down Expand Up @@ -249,22 +251,27 @@ private GoPluginApiResponse handleCheckout(GoPluginApiRequest goPluginApiRequest
String destinationFolder = (String) requestBodyMap.get("destination-folder");
Map<String, Object> revisionMap = (Map<String, Object>) 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 out of %s", destinationFolder, revision, attempt, CHECKOUT_ATTEMPTS));

try {
try {
GitHelper git = HelperFactory.gitCmd(gitConfig, new File(destinationFolder));
git.cloneOrFetch(provider.getRefSpec());
git.resetHard(revision);
git.cloneOrFetch(provider.getRefSpec());
git.resetHard(revision);

Map<String, Object> response = new HashMap<String, Object>();
response.put("status", "success");
response.put("messages", Arrays.asList(String.format("Checked out to revision %s", revision)));
Map<String, Object> response = new HashMap<String, Object>();
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 out of %s, checkout: ", attempt, CHECKOUT_ATTEMPTS), t);
if (attempt >= CHECKOUT_ATTEMPTS) {
return renderJSON(INTERNAL_ERROR_RESPONSE_CODE, t.getMessage());
}
}
}
return renderJSON(INTERNAL_ERROR_RESPONSE_CODE, "Checkout failed");
}

GitConfig getGitConfig(Map<String, String> configuration) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/gerrit/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<go-plugin id="gerrit.cs" version="1">
<about>
<name>Gerrit Change Set plugin</name>
<version>1.2.2</version>
<version>${project.version}</version>
<target-go-version>15.1.0</target-go-version>
<description>Provides ability to do change set builds for Gerrit repository</description>
<vendor>
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/git/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<go-plugin id="git.fb" version="1">
<about>
<name>Git Feature Branch plugin</name>
<version>1.2.2</version>
<version>${project.version}</version>
<target-go-version>15.1.0</target-go-version>
<description>Provides ability to do feature branch builds for Git repository</description>
<vendor>
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/github/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<go-plugin id="github.pr" version="1">
<about>
<name>Github Pull Requests Builder</name>
<version>1.2.2</version>
<version>${project.version}</version>
<target-go-version>15.1.0</target-go-version>
<description>Plugin that polls a GitHub repository for pull requests and triggers a build for each of them</description>
<vendor>
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/stash/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<go-plugin id="stash.pr" version="1">
<about>
<name>Stash Pull Requests Builder</name>
<version>1.2.2</version>
<version>${project.version}</version>
<target-go-version>15.1.0</target-go-version>
<description>Plugin that polls a Stash repository for pull requests and triggers a build for each of them</description>
<vendor>
Expand Down