Skip to content

Commit

Permalink
fix(plugins): Set preferred release to false when upserting plugin in…
Browse files Browse the repository at this point in the history
…fo; fix semver validation on release version (#826)
  • Loading branch information
jonsie committed May 19, 2020
1 parent b971372 commit 94b40e3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void setReleaseByVersion(String version, Release release) {
/** A singular {@code PluginInfo} release. */
@Data
public static class Release {
public static final String VERSION_PATTERN = "^[1-9]\\d*\\.\\d+\\.\\d+(?:-[a-zA-Z0-9]+)?$";
public static final String VERSION_PATTERN = "^[0-9]\\d*\\.\\d+\\.\\d+(?:-[a-zA-Z0-9]+)?$";
public static final Pattern SUPPORTS_PATTERN =
Pattern.compile(
"^(?<service>[\\w\\-]+)(?<operator>[><=]{1,2})(?<version>[0-9]+\\.[0-9]+\\.[0-9]+)$");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,12 @@ public PluginInfo upsert(@Nonnull PluginInfo pluginInfo) {
validate(pluginInfo);

try {
// Because we first validate the plugin info, we can assume there will be only one preferred
// release
Optional<PluginInfo.Release> preferredRelease =
pluginInfo.getReleases().stream().filter(PluginInfo.Release::isPreferred).findFirst();

PluginInfo currentPluginInfo = repository.findById(pluginInfo.getId());
List<PluginInfo.Release> newReleases = new ArrayList<>(pluginInfo.getReleases());

// upsert plugin info is not an authorized endpoint, so preferred release must be false.
newReleases.forEach(it -> it.setPreferred(false));

List<PluginInfo.Release> oldReleases = new ArrayList<>(currentPluginInfo.getReleases());
newReleases.forEach(
release -> { // Raise an exception if old releases are being updated.
Expand All @@ -78,7 +77,6 @@ public PluginInfo upsert(@Nonnull PluginInfo pluginInfo) {
List<PluginInfo.Release> allReleases = new ArrayList<>();
Stream.of(oldReleases, newReleases).forEach(allReleases::addAll);
pluginInfo.setReleases(allReleases);
preferredRelease.ifPresent(release -> cleanupPreferredReleases(pluginInfo, release));

repository.update(pluginInfo.getId(), pluginInfo);
return pluginInfo;
Expand Down

0 comments on commit 94b40e3

Please sign in to comment.