Skip to content

Commit

Permalink
modrinth: report error when project version not available for request…
Browse files Browse the repository at this point in the history
…ed constraints (#384)
  • Loading branch information
itzg authored Jan 27, 2024
1 parent 1c228be commit 36ea8a0
Show file tree
Hide file tree
Showing 4 changed files with 1,174 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/main/java/me/itzg/helpers/modrinth/ModrinthCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,12 @@ private Stream<Path> processProject(ModrinthApiClient modrinthApiClient, Project
.map(versionFile -> download(project.getProjectType(), versionFile))
.flatMap(this::expandIfZip);
}
else {
throw new InvalidParameterException(
String.format("Project %s does not have any matching versions for loader %s, game version %s",
projectRef, loader, gameVersion
));
}
}
return Stream.empty();
}
Expand Down
37 changes: 35 additions & 2 deletions src/test/java/me/itzg/helpers/modrinth/ModrinthCommandTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package me.itzg.helpers.modrinth;

import static com.github.tomakehurst.wiremock.client.WireMock.*;
import static com.github.tomakehurst.wiremock.client.WireMock.getRequestedFor;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
import static org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric;
Expand All @@ -12,9 +11,9 @@
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.github.tomakehurst.wiremock.extension.responsetemplating.ResponseTemplateTransformer;
import com.github.tomakehurst.wiremock.junit5.WireMockExtension;
import com.github.tomakehurst.wiremock.matching.RequestPatternBuilder;
import java.nio.file.Path;
import java.util.function.Consumer;
import com.github.tomakehurst.wiremock.matching.RequestPatternBuilder;
import me.itzg.helpers.json.ObjectMappers;
import me.itzg.helpers.modrinth.ModrinthCommand.DownloadDependencies;
import org.assertj.core.api.AbstractPathAssert;
Expand Down Expand Up @@ -150,6 +149,40 @@ else if (downloadDependencies == DownloadDependencies.OPTIONAL) {
}
}

@Test
void errorWhenNoApplicableVersion(@TempDir Path tempDir) {
stubFor(
get(urlPathMatching("/v2/projects"))
.withQueryParam("ids", equalTo("[\"geyser\"]"))
.willReturn(aResponse()
.withHeader("Content-Type", "application/json")
.withBodyFile("bulk-geyser.json")
)
);
stubFor(
get(urlPathMatching("/v2/project/wKkoqHrH/version"))
.withQueryParam("loaders", equalTo("[\"fabric\"]"))
.withQueryParam("game_versions", equalTo("[\"1.20.4\"]"))
.willReturn(aResponse()
.withHeader("Content-Type", "application/json")
.withBodyFile("project-geyser-only-betas.json")
)
);

final int exitCode = new CommandLine(
new ModrinthCommand()
)
.execute(
"--api-base-url", wm.getRuntimeInfo().getHttpBaseUrl(),
"--output-directory", tempDir.toString(),
"--game-version", "1.20.4",
"--loader", "fabric",
"--projects", "geyser"
);

assertThat(exitCode).isNotEqualTo(ExitCode.OK);
}

@NotNull
private static RequestPatternBuilder projectVersionsRequest(String projectId) {
return getRequestedFor(urlPathEqualTo("/v2/project/" + projectId + "/version"));
Expand Down
291 changes: 291 additions & 0 deletions src/test/resources/ModrinthCommandTest/__files/bulk-geyser.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,291 @@
[
{
"client_side": "unsupported",
"server_side": "required",
"game_versions": [
"1.19",
"1.19.1",
"1.19.2",
"1.19.3",
"1.19.4",
"1.20",
"1.20.1",
"1.20.2",
"1.20.4"
],
"id": "wKkoqHrH",
"slug": "geyser",
"project_type": "mod",
"team": "rttnZkSH",
"organization": "7LNvzkLC",
"title": "Geyser-Fabric",
"description": "A bridge/proxy allowing you to connect to Minecraft: Java Edition servers with Minecraft: Bedrock Edition.",
"body": "<img src=\"https://geysermc.org/img/geyser-1760-860.png\" alt=\"Geyser\" width=\"600\"/>\n\n[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)\n[![Discord](https://img.shields.io/discord/613163671870242838.svg?color=%237289da&label=discord)](https://discord.gg/geysermc)\n[![Crowdin](https://badges.crowdin.net/geyser/localized.svg)](https://translate.geysermc.org/)\n\nGeyser is a bridge between Minecraft: Bedrock Edition and Minecraft: Java Edition, closing the gap from those wanting to play true cross-platform.\n\nGeyser is an open collaboration project by [CubeCraft Games](https://cubecraft.net).\n\n## What is Geyser?\nGeyser is a proxy, bridging the gap between Minecraft: Bedrock Edition and Minecraft: Java Edition servers.\nThe ultimate goal of this project is to allow Minecraft: Bedrock Edition users to join Minecraft: Java Edition servers as seamlessly as possible. However, due to the nature of Geyser translating packets over the network of two different games, *do not expect everything to work perfectly!*\n\nSpecial thanks to the DragonProxy project for being a trailblazer in protocol translation and for all the team members who have joined us here!\n\n### Currently supporting Minecraft Bedrock 1.19.80 - 1.20.0 and Minecraft Java 1.20.\n\n## Setting Up\nTake a look [here](https://wiki.geysermc.org/geyser/setup/) for how to set up Geyser.\n\n## Links:\n- Website: https://geysermc.org\n- Docs: https://wiki.geysermc.org/geyser/\n- Download: https://geysermc.org/download\n- Discord: https://discord.gg/geysermc\n- Donate: https://opencollective.com/geysermc\n- Test Server: `test.geysermc.org` port `25565` for Java and `19132` for Bedrock\n\n## What's Left to be Added/Fixed\n- Near-perfect movement (to the point where anticheat on large servers is unlikely to ban you)\n- Some Entity Flags\n- Structure block UI\n\n## What can't be fixed\nThere are a few things Geyser is unable to support due to various differences between Minecraft Bedrock and Java. For a list of these limitations, see the [Current Limitations](https://wiki.geysermc.org/geyser/current-limitations/) page.\n\n## Compiling\n1. Clone the repo to your computer\n2. Navigate to the Geyser root directory and run `git submodule update --init --recursive`. This command downloads all the needed submodules for Geyser and is a crucial step in this process.\n3. Run `gradlew build` and locate to `bootstrap/build` folder.\n\n## Contributing\nAny contributions are appreciated. Please feel free to reach out to us on [Discord](http://discord.geysermc.org/) if\nyou're interested in helping out with Geyser.",
"body_url": null,
"published": "2023-03-20T15:01:56.168603Z",
"updated": "2024-01-24T21:32:12.693434Z",
"approved": "2023-03-21T00:30:34.368260Z",
"queued": null,
"status": "approved",
"requested_status": "approved",
"moderator_message": null,
"license": {
"id": "MIT",
"name": "MIT License",
"url": null
},
"downloads": 12064,
"followers": 105,
"categories": [
"utility"
],
"additional_categories": [],
"loaders": [
"fabric"
],
"versions": [
"PZN2OcFf",
"Qmuj4cNH",
"ZR8N1nOQ",
"LKHCewnr",
"uJD3KqaE",
"rkt4sqzT",
"O9opx8e8",
"agaRnGJF",
"iySYDKW1",
"VI8km42v",
"YrNIigJJ",
"KQHFwT8U",
"eCMP3Rmw",
"oOpL1Vg6",
"acVNETjd",
"FKGTtvbU",
"F6A4XHpJ",
"E0ooqeEI",
"fqyjtYx9",
"d9R9Wnm5",
"XVBM0wIS",
"SZZLbPLs",
"Gg6lDSj4",
"4BPdNcNE",
"ulJTTCwk",
"dD5q5kF5",
"5SzeBzmc",
"ocyBoFzs",
"jEY35kMl",
"FGokHtZB",
"HSdXf6bC",
"T9Csep2W",
"v4L9AK3q",
"fkpHkO6l",
"NnLQ5VGC",
"iXZpyB4G",
"MewkCTlE",
"GZAlOKWK",
"JzH9sLq8",
"PH0xOXBF",
"B4pDRBZQ",
"dhIo1LCg",
"CO51tZ7x",
"7PYEz1jJ",
"gEUH9pt9",
"WCxx8Joy",
"Fq3fdCoa",
"gXoeIUqM",
"w3qvISxF",
"FsIgTCtU",
"PY4UBHMZ",
"5xrY4AHx",
"HPcwTzCK",
"DjXuNXEX",
"j52cKYIm",
"tTMRAZZX",
"i6xcrlJj",
"YuJ1VE02",
"wTFbd8Bq",
"k1qyAqP7",
"DoZqN8Ux",
"9qhmMThm",
"Tu9HxE6g",
"ac8ZGJGR",
"HWKOI8OB",
"5fVTi5KK",
"qeOlLARa",
"9zFZKLLf",
"ueDXr92c",
"ibxx9JlB",
"hNl5VB7I",
"vVLn2JvM",
"Qh8rHv5J",
"CFHLAfGF",
"Oe7zbYEK",
"aAamXp5A",
"4irv4vya",
"XadFTzfO",
"j3tqU7J7",
"oQdBJoKu",
"hynglEVj",
"DqzGpUYn",
"n2LzPGZ1",
"b2uZXVDL",
"DcHazsOW",
"Ab9c2DHf",
"EULt2Ofa",
"j42QRdv2",
"t1WZksAQ",
"QdI3ES0t",
"LAjTvN3V",
"PB5gEZWM",
"4aMkwjSc",
"Pdh9MF9a",
"hJHbiwEZ",
"OLjN5DBb",
"TYQ0HhZO",
"W9AbnSU9",
"blAsO8oG",
"e8974G5Q",
"REEH9hDr",
"KNJpNAT2",
"g7BIKVIk",
"lKhmO46L",
"1Q9DeZOy",
"NbALGx1w",
"TX7I3O1W",
"T6JbjEA5",
"NwjkW9Gt",
"5MpmYhCz",
"KiIkKEqN",
"x4MhBYqy",
"NQgSDeCQ",
"3rPcBP1A",
"TxDJUYpA",
"6wDuTQIz",
"aVfRT0YQ",
"k1nGu5xY",
"kPbXbA3I",
"4e8KWs5U",
"b96XDXdH",
"2H7JGnJv",
"zewbHiry",
"w1sxXKlw",
"IQzllUlZ",
"AV9t6ECg",
"kdtLFahu",
"Kn2NCHTG",
"nB69Bnkh",
"hysFelsr",
"YEmzZq8u",
"kufpso3q",
"LJzc8W4u",
"oJkwAezD",
"PRvoucHK",
"I5a13tss",
"99LkWSxt",
"lDGwl8b1",
"p9BTKB0k",
"UIxo7yUH",
"YBcj97en",
"Bar0RTBa",
"SH2m9Swm",
"vL4BpUFd",
"OYpdORJi",
"jalfVNbi",
"TKRfkmjv",
"i2c7QP7a",
"Hp8abt4Z",
"OOMIFOUm",
"pi5KLwgx",
"xsXTS8qB",
"MYKO3Q6J",
"sxF4OIVL",
"LNDhVdUa",
"XO7UmzVl",
"EPEYIKCK",
"UICaZ805",
"QRByJoLR",
"6oQKUVFa",
"VgqScCva",
"3OISqdGk",
"rx9GEM4b",
"vthW1FvM",
"cGfy5JWP",
"mOaBnkWn",
"VNNG4Mzv",
"EYdRwbhz",
"SIJoRSbU",
"iSYh3lZP",
"8S7hg5hx",
"CNONDqIv",
"BcYI2PNY",
"RSkSqzEF",
"JBTvG8NN",
"A266ZoxQ",
"9QI3qRRa",
"uW3qaQ9k",
"wmz0wfe1",
"fDBy2u6V",
"DXSJXJIg",
"VYSeIToX",
"LSCFhXJ1",
"2GouLmJ7",
"KgcDbDOs",
"ccF3qRLj",
"EF8z6Ugq",
"dnRHg2Qz",
"bB5JDtO4",
"Hd73bX03",
"3oo00RLM",
"3LR6FrVD",
"QnrKSu3n",
"z3P5kTH9",
"jFkpMz8G",
"gRou6w5Y",
"NkDYFbF2",
"8uzilQvA",
"MN6Mtm3s",
"Ss995CvU",
"jIeAUEqH",
"Xj3N4L4M",
"eWvfkirQ",
"oenU3Vrw",
"Aro2EaGs",
"e8NbdxCH",
"xqeFi2YH",
"ujgeUEYK",
"7gmaiwsf",
"pyJsinIF",
"SsoQev3o",
"iJBTdBuT",
"WMP7Kk2S",
"RlqYWydp",
"9Z0RbBHK",
"qkubeexe",
"OaBcQzXw",
"hnCrxh7G",
"ecmeMita",
"2Wr1axtU",
"f2mwWV6L",
"j577GbLm",
"hnMqV7QV",
"7XD9YUuS",
"tCzwg9vf",
"CeSpw2Km"
],
"icon_url": "https://cdn.modrinth.com/data/wKkoqHrH/2dc273d840798d2784e8cafc3a697c20c8efecb9.png",
"issues_url": "https://github.com/GeyserMC/Geyser/issues",
"source_url": "https://github.com/GeyserMC/Geyser/",
"wiki_url": "https://wiki.geysermc.org",
"discord_url": "https://discord.gg/geysermc",
"donation_urls": [
{
"id": "other",
"platform": "Other",
"url": "https://opencollective.com/GeyserMC"
}
],
"gallery": [],
"color": 9213012,
"thread_id": "wKkoqHrH",
"monetization_status": "monetized"
}
]
Loading

0 comments on commit 36ea8a0

Please sign in to comment.