Skip to content

Commit

Permalink
wip2
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandro Heinzelmann committed Aug 19, 2024
1 parent 1c1dba9 commit 431e0e8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,6 @@ GoPluginApiResponse handleGetLatestRevision(GoPluginApiRequest goPluginApiReques
Map<String, Object> requestBodyMap = fromJSON(goPluginApiRequest.requestBody(), REQUEST_BODY_TYPE);
Map<String, String> configuration = keyValuePairs(requestBodyMap, "scm-configuration");
GitConfig gitConfig = getGitConfig(configuration);
String revisionMapBehavior = configuration.get("revisionMapBehavior");
LOGGER.info("revisionMapBehavior: " + revisionMapBehavior); // TODO debug
String flyweightFolder = (String) requestBodyMap.get("flyweight-folder");
LOGGER.info(String.format("Flyweight: %s", flyweightFolder));

Expand All @@ -237,14 +235,7 @@ GoPluginApiResponse handleGetLatestRevision(GoPluginApiRequest goPluginApiReques
return buildLatestRevisionResponse(null, branchToRevisionMap);
}


if ("store_all".equals(revisionMapBehavior)) {
// Remove nothing from the map, meaning store all new PRs. So they're all marked as done.
}
else { // also covers "clear_all"
// 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()));
}
// Remove nothing from the map, meaning store all new PRs. So they're all marked as done.

Revision revision = git.getDetailsForRevision(newerRevision.getValue());
String branch = newerRevision.getKey();
Expand Down Expand Up @@ -276,8 +267,9 @@ GoPluginApiResponse handleLatestRevisionSince(GoPluginApiRequest goPluginApiRequ
Map<String, Object> requestBodyMap = fromJSON(goPluginApiRequest.requestBody(), REQUEST_BODY_TYPE);
Map<String, String> configuration = keyValuePairs(requestBodyMap, "scm-configuration");
final GitConfig gitConfig = getGitConfig(configuration);
String revisionMapBehavior = configuration.get("revisionMapBehavior");
LOGGER.info("revisionMapBehavior: " + revisionMapBehavior); // TODO debug
Map<String, String> previousRevision = (Map<String, String>) requestBodyMap.get("previous-revision");
String previousSourceUrl = previousRevision != null ? previousRevision.get("PR_SOURCE_URL") : null;
boolean sourceUrlChanged = !Objects.equals(previousSourceUrl, gitConfig.getUrl());
Map<String, String> scmData = (Map<String, String>) requestBodyMap.get("scm-data");
Map<String, String> oldPrRevisionMap = fromJSON(scmData.get(BRANCH_TO_REVISION_MAP), REVISION_MAP_TYPE);
String flyweightFolder = (String) requestBodyMap.get("flyweight-folder");
Expand All @@ -293,8 +285,7 @@ GoPluginApiResponse handleLatestRevisionSince(GoPluginApiRequest goPluginApiRequ
if (newerRevision == null) {
LOGGER.debug(String.format("No updated PRs found for %s. Old: %s New: %s", gitConfig.getUrl(), oldPrRevisionMap,
newPrToRevisionMap));
return buildLatestRevisionsResponse(null,
"clear_all".equals(revisionMapBehavior) ? emptyMap() : newPrToRevisionMap);
return buildLatestRevisionsResponse(null, newPrToRevisionMap);
}

String pr = newerRevision.getKey();
Expand All @@ -307,15 +298,12 @@ GoPluginApiResponse handleLatestRevisionSince(GoPluginApiRequest goPluginApiRequ

Map<String, String> updatedPrToRevisionMap = new HashMap<>();

if ("store_all".equals(revisionMapBehavior)) {
if (sourceUrlChanged) {
// Store all new PRs. So they're all marked as done.
LOGGER.info(String.format("Source URL changed from %s to %s. Storing all pending PRs.",
previousSourceUrl, gitConfig.getUrl()));
updatedPrToRevisionMap.putAll(newPrToRevisionMap);
}
else if ("clear_all".equals(revisionMapBehavior)) {
// Only store the PR we're building, so all other (old) PRs
// are marked as unbuilt.
updatedPrToRevisionMap.put(pr, latestSHA);
}
else {
// Default behavior: keep the old PRs, only update the one we're building.
// So any other new PRs will be built in future executions.
Expand Down Expand Up @@ -496,6 +484,7 @@ Map<String, Object> populateRevisionMap(GitConfig gitConfig, String branch, Revi
provider.populateRevisionData(gitConfig, branch, revision.getRevision(), customDataBag);

customDataBag.put("PR_CHECKOUT_BRANCH", determineCheckoutBranch(customDataBag));
customDataBag.put("PR_SOURCE_URL", gitConfig.getUrl());

response.put("data", customDataBag);
return response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public Map<String, Object> fields() {
response.put("password", FieldFactory.createForScm("Password", null, false, false, true, "2"));
response.put("defaultBranch", FieldFactory.createForScm("Default Branch", "master", false, false, false, "3"));
response.put("shallowClone", FieldFactory.createForScm("Default Clone Behavior", "false", false, false, false, "4"));
response.put("revisionMapBehavior", FieldFactory.createForScm("Revision Map Behavior", null, false, false, false, "5"));
return response;
}

Expand Down
5 changes: 0 additions & 5 deletions src/main/resources/views/scm.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,3 @@
<input type="text" ng-model="defaultBranch" ng-required="false"/>
<span class="form_error" ng-show="GOINPUTNAME[defaultBranch].$error.server">{{ GOINPUTNAME[defaultBranch].$error.server }}</span>
</div>
<div class="form_item_block">
<label>Revision Map Behavior:</label>
<input type="text" ng-model="revisionMapBehavior" ng-required="false"/>
<span class="form_error" ng-show="GOINPUTNAME[revisionMapBehavior].$error.server">{{ GOINPUTNAME[revisionMapBehavior].$error.server }}</span>
</div>

0 comments on commit 431e0e8

Please sign in to comment.