diff --git a/pom.xml b/pom.xml
index 81dca95..fc885ac 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
4.0.0
in.ashwanthkumar
gocd-github-pr-material
- 1.6.0
+ 1.6.1_migr1
UTF-8
diff --git a/src/main/java/in/ashwanthkumar/gocd/github/GitHubPRBuildPlugin.java b/src/main/java/in/ashwanthkumar/gocd/github/GitHubPRBuildPlugin.java
index 01e9e22..95f3f4f 100644
--- a/src/main/java/in/ashwanthkumar/gocd/github/GitHubPRBuildPlugin.java
+++ b/src/main/java/in/ashwanthkumar/gocd/github/GitHubPRBuildPlugin.java
@@ -15,6 +15,7 @@
import com.tw.go.plugin.util.ListUtil;
import com.tw.go.plugin.util.StringUtil;
import in.ashwanthkumar.gocd.github.provider.Provider;
+import in.ashwanthkumar.gocd.github.provider.github.GitHubProvider;
import in.ashwanthkumar.gocd.github.settings.scm.PluginConfigurationView;
import in.ashwanthkumar.gocd.github.util.BranchFilter;
import in.ashwanthkumar.gocd.github.util.ExtendedGitCmdHelper;
@@ -227,7 +228,12 @@ GoPluginApiResponse handleGetLatestRevision(GoPluginApiRequest goPluginApiReques
}
// Remove all other branches from the response to ensure the next time those will be picked up by GoCD
- branchToRevisionMap.entrySet().removeIf(entry -> !Objects.equals(entry.getKey(), newerRevision.getKey()));
+ if (provider instanceof GitHubProvider) {
+ LOGGER.info("Storing all seen PRs for initial GitHub PR material load.");
+ }
+ else {
+ branchToRevisionMap.entrySet().removeIf(entry -> !Objects.equals(entry.getKey(), newerRevision.getKey()));
+ }
Revision revision = git.getDetailsForRevision(newerRevision.getValue());
String branch = newerRevision.getKey();
diff --git a/src/test/java/in/ashwanthkumar/gocd/github/GitHubPRBuildPluginTest.java b/src/test/java/in/ashwanthkumar/gocd/github/GitHubPRBuildPluginTest.java
index 05b39a8..e4fc2c0 100644
--- a/src/test/java/in/ashwanthkumar/gocd/github/GitHubPRBuildPluginTest.java
+++ b/src/test/java/in/ashwanthkumar/gocd/github/GitHubPRBuildPluginTest.java
@@ -13,6 +13,7 @@
import in.ashwanthkumar.gocd.github.provider.git.GitProvider;
import in.ashwanthkumar.gocd.github.provider.github.GHUtils;
import in.ashwanthkumar.gocd.github.provider.github.GitHubProvider;
+import in.ashwanthkumar.gocd.github.provider.stash.StashProvider;
import in.ashwanthkumar.gocd.github.util.ExtendedGitCmdHelper;
import in.ashwanthkumar.gocd.github.util.GitFactory;
import in.ashwanthkumar.gocd.github.util.GitFolderFactory;
@@ -372,7 +373,7 @@ public void handleGetLatestRevisionShouldReturnASingleBranch() {
mockGitRevisions(gitFactory, revisions);
GitFolderFactory gitFolderFactory = mock(GitFolderFactory.class);
- Provider provider = new TestProvider();
+ Provider provider = new StashProvider();
GitHubPRBuildPlugin plugin = new GitHubPRBuildPlugin(
provider,
gitFactory,
@@ -395,6 +396,39 @@ public void handleGetLatestRevisionShouldReturnASingleBranch() {
assertEquals("test2abcd11111111", revision.get("revision"));
}
+ @Test
+ public void handleGetLatestRevisionShouldReturnAllBranchesForGitHub() {
+ GitFactory gitFactory = mock(GitFactory.class);
+
+ Map revisions = new HashMap<>();
+ revisions.put("test-1", "test1abcd11111111");
+ revisions.put("test-2", "test2abcd11111111");
+ mockGitRevisions(gitFactory, revisions);
+
+ GitFolderFactory gitFolderFactory = mock(GitFolderFactory.class);
+ Provider provider = new GitHubProvider();
+ GitHubPRBuildPlugin plugin = new GitHubPRBuildPlugin(
+ provider,
+ gitFactory,
+ gitFolderFactory,
+ mockGoApplicationAccessor()
+ );
+ GitHubPRBuildPlugin pluginSpy = spy(plugin);
+
+ GoPluginApiRequest request = mock(GoPluginApiRequest.class);
+ when(request.requestBody()).thenReturn("{scm-configuration: {url: {value: \"https://github.com/mdaliejaz/samplerepo.git\"}}, flyweight-folder: \"" + TEST_DIR + "\"}");
+
+ GoPluginApiResponse response = pluginSpy.handleGetLatestRevision(request);
+ Map responseBody =
+ (Map) JSONUtils.fromJSON(response.responseBody());
+
+ String branchToRevisionMap = (String) ((Map)responseBody.get("scm-data")).get("BRANCH_TO_REVISION_MAP");
+ assertEquals("{\"test-2\":\"test2abcd11111111\",\"test-1\":\"test1abcd11111111\"}", branchToRevisionMap);
+
+ Map revision = (Map) responseBody.get("revision");
+ assertEquals("test2abcd11111111", revision.get("revision"));
+ }
+
@Test
public void keyValuePairs_should_extract_values_from_nested_maps() {
Map keyValuePairs = GitHubPRBuildPlugin.keyValuePairs(