Skip to content

Commit b50b71c

Browse files
authored
Fix featured mod deployment (#627)
* Fix casting int to short * Fix deployment text too long
1 parent d1b1b43 commit b50b71c

File tree

6 files changed

+27
-24
lines changed

6 files changed

+27
-24
lines changed

src/main/java/com/faforever/api/deployment/GitHubDeploymentService.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,11 @@ private void performDeployment(GHDeployment ghDeployment, GHRepository repositor
9898
@SneakyThrows
9999
private void updateDeploymentStatus(long deploymentId, GHRepository repository, GHDeploymentState state, String description) {
100100
log.debug("Updating deployment status to '{}' with description: {}", state, description);
101-
repository.getDeployment(deploymentId)
102-
.createStatus(state)
101+
if (description.length() > 140) {
102+
log.info("Deployment Status description too long truncating");
103+
description = description.substring(0, 140);
104+
}
105+
repository.getDeployment(deploymentId).createStatus(state)
103106
.description(description)
104107
.create();
105108
}

src/main/java/com/faforever/api/deployment/LegacyFeaturedModDeploymentTask.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public void run() {
9797
String branch = featuredMod.getGitBranch();
9898
boolean allowOverride = Optional.ofNullable(featuredMod.isAllowOverride()).orElse(false);
9999
String modFilesExtension = featuredMod.getFileExtension();
100-
Map<String, Short> fileIds = featuredModService.getFileIds(modName);
100+
Map<String, Integer> fileIds = featuredModService.getFileIds(modName);
101101

102102
log.info("Starting deployment of '{}' from '{}', branch '{}', allowOverride '{}', modFilesExtension '{}'",
103103
modName, repositoryUrl, branch, allowOverride, modFilesExtension);
@@ -147,9 +147,9 @@ void invokeDeploymentWebhook(FeaturedMod featuredMod) {
147147
* featured mod.
148148
*/
149149
@SneakyThrows
150-
private Optional<StagedFile> createPatchedExe(short version, Map<String, Short> fileIds, Path targetFolder) {
150+
private Optional<StagedFile> createPatchedExe(short version, Map<String, Integer> fileIds, Path targetFolder) {
151151
String clientFileName = "ForgedAlliance.exe";
152-
Short fileId = fileIds.get(clientFileName);
152+
Integer fileId = fileIds.get(clientFileName);
153153
if (fileId == null) {
154154
log.debug("Skipping '{}' because there's no file ID available", clientFileName);
155155
return Optional.empty();
@@ -210,7 +210,7 @@ private void updateStatus(String message) {
210210
*/
211211
@SneakyThrows
212212
@SuppressWarnings("unchecked")
213-
private List<StagedFile> packageFiles(Path repositoryDirectory, short version, Map<String, Short> fileIds, Path targetFolder) {
213+
private List<StagedFile> packageFiles(Path repositoryDirectory, short version, Map<String, Integer> fileIds, Path targetFolder) {
214214
updateStatus("Packaging files");
215215
try (Stream<Path> stream = Files.list(repositoryDirectory)) {
216216
return stream
@@ -248,14 +248,14 @@ private StagedFile finalizeFile(StagedFile file) {
248248
* content of the directory. If no file ID is available, an empty optional is returned.
249249
*/
250250
@SneakyThrows
251-
private Optional<StagedFile> packDirectory(Path directory, Short version, Path targetFolder, Map<String, Short> fileIds) {
251+
private Optional<StagedFile> packDirectory(Path directory, Short version, Path targetFolder, Map<String, Integer> fileIds) {
252252
String directoryName = directory.getFileName().toString();
253253
Path targetNxtFile = targetFolder.resolve(String.format("%s.%d.%s", directoryName, version, featuredMod.getFileExtension()));
254254
Path tmpNxtFile = toTmpFile(targetNxtFile);
255255

256256
// E.g. "effects.nx2"
257257
String clientFileName = String.format("%s.%s", directoryName, featuredMod.getFileExtension());
258-
Short fileId = fileIds.get(clientFileName);
258+
Integer fileId = fileIds.get(clientFileName);
259259
if (fileId == null) {
260260
log.debug("Skipping folder '{}' because there's no file ID available", directoryName);
261261
return Optional.empty();
@@ -275,14 +275,14 @@ private Optional<StagedFile> packDirectory(Path directory, Short version, Path t
275275
* content of the directory. If no file ID is available, an empty optional is returned.
276276
*/
277277
@SneakyThrows
278-
private Optional<StagedFile> packFile(Path file, Short version, Path targetFolder, Map<String, Short> fileIds) {
278+
private Optional<StagedFile> packFile(Path file, Short version, Path targetFolder, Map<String, Integer> fileIds) {
279279
String fullFileName = file.getFileName().toString();
280280
String baseName = FilenameUtils.getBaseName(fullFileName);
281281
String extension = FilenameUtils.getExtension(fullFileName);
282282
Path targetFile = targetFolder.resolve(String.format("%s_%d.%s", baseName, version, extension));
283283
Path tmpFile = toTmpFile(targetFile);
284284

285-
Short fileId = fileIds.get(fullFileName);
285+
Integer fileId = fileIds.get(fullFileName);
286286
if (fileId == null) {
287287
log.debug("Skipping file '{}' because there's no file ID available", fullFileName);
288288
return Optional.empty();
@@ -360,7 +360,7 @@ private record StagedFile(
360360
/**
361361
* ID of the file as stored in the database.
362362
*/
363-
short fileId,
363+
int fileId,
364364
/**
365365
* The staged file, already in the correct location, that is ready to be renamed.
366366
*/

src/main/java/com/faforever/api/featuredmods/FeaturedModFile.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class FeaturedModFile {
2727
// Enriched in FeaturedModFileEnricher
2828
private String url;
2929
private String folderName;
30-
private short fileId;
30+
private int fileId;
3131

3232
@Id
3333
@Column(name = "id")
@@ -69,7 +69,7 @@ public int getVersion() {
6969
}
7070

7171
@Column(name = "fileId")
72-
public short getFileId() {
72+
public int getFileId() {
7373
return fileId;
7474
}
7575

src/main/java/com/faforever/api/featuredmods/FeaturedModService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public void save(String modName, short version, List<FeaturedModFile> featuredMo
4040
legacyFeaturedModFileRepository.save(modName, version, featuredModFiles);
4141
}
4242

43-
public Map<String, Short> getFileIds(String modName) {
43+
public Map<String, Integer> getFileIds(String modName) {
4444
return legacyFeaturedModFileRepository.getFileIds(modName);
4545
}
4646

src/main/java/com/faforever/api/featuredmods/LegacyFeaturedModFileRepository.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,15 @@ public void save(String modName, short version, List<FeaturedModFile> featuredMo
103103
}
104104

105105
@SuppressWarnings("unchecked")
106-
public Map<String, Short> getFileIds(String modName) {
106+
public Map<String, Integer> getFileIds(String modName) {
107107
// Please shoot me.
108108
String innerModName = "ladder1v1".equals(modName) ? "faf" : modName;
109109
verifyModName(innerModName);
110110

111111
Query query = entityManager.createNativeQuery(String.format("SELECT id, filename FROM updates_%s", innerModName));
112112

113113
return ((List<Object[]>) query.getResultList()).stream()
114-
.collect(Collectors.toMap(row -> (String) row[1], row -> (short) row[0]));
114+
.collect(Collectors.toMap(row -> (String) row[1], row -> (int) row[0]));
115115
}
116116

117117
private void verifyModName(String modName) {

src/test/java/com/faforever/api/deployment/LegacyFeaturedModDeploymentTaskTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ public void testRun() throws Exception {
138138
new FeaturedMod().setTechnicalName("faf")
139139
));
140140
when(featuredModService.getFileIds("faf")).thenReturn(Map.of(
141-
"ForgedAlliance.exe", (short) 1,
142-
"someDir.nx3", (short) 2
141+
"ForgedAlliance.exe", 1,
142+
"someDir.nx3", 2
143143
));
144144

145145
Path dummyExe = repositoriesFolder.resolve("TemplateForgedAlliance.exe");
@@ -156,13 +156,13 @@ public void testRun() throws Exception {
156156

157157
assertThat(files, containsInAnyOrder(
158158
allOf(
159-
hasProperty("fileId", is((short) 1)),
159+
hasProperty("fileId", is(1)),
160160
hasProperty("md5", is("47df959058cb52fe966ea5936dbd8f4c")),
161161
hasProperty("name", is("ForgedAlliance.1337.exe")),
162162
hasProperty("version", is(1337))
163163
),
164164
allOf(
165-
hasProperty("fileId", is((short) 2)),
165+
hasProperty("fileId", is(2)),
166166
hasProperty("md5", is(notNullValue())),
167167
hasProperty("name", is("someDir.1337.nx3")),
168168
hasProperty("version", is(1337))
@@ -203,8 +203,8 @@ public void testHashEquality() throws Exception {
203203
new FeaturedMod().setTechnicalName("faf")
204204
));
205205
when(featuredModService.getFileIds("faf")).thenReturn(Map.of(
206-
"ForgedAlliance.exe", (short) 1,
207-
"someDir.nx3", (short) 2
206+
"ForgedAlliance.exe", 1,
207+
"someDir.nx3", 2
208208
));
209209

210210
Path dummyExe = repositoriesFolder.resolve("TemplateForgedAlliance.exe");
@@ -245,8 +245,8 @@ public void testHashEquality() throws Exception {
245245
new FeaturedMod().setTechnicalName("faf")
246246
));
247247
when(featuredModService.getFileIds("faf")).thenReturn(Map.of(
248-
"ForgedAlliance.exe", (short) 1,
249-
"someDir.nx3", (short) 2
248+
"ForgedAlliance.exe", 1,
249+
"someDir.nx3", 2
250250
));
251251

252252
dummyExe = repositoriesFolder.resolve("TemplateForgedAlliance.exe");

0 commit comments

Comments
 (0)