Skip to content

Commit e38281c

Browse files
Copilotjpenilla
andauthored
fix: use empty changelog when latest previous build has empty commits
Agent-Logs-Url: https://github.com/PaperMC/fill-gradle/sessions/e75bc6cb-6de8-4115-b965-68ba02ee0e7c Co-authored-by: jpenilla <11360596+jpenilla@users.noreply.github.com>
1 parent c957e83 commit e38281c

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

src/main/java/io/papermc/fill/gradle/task/PublishToFillTask.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,10 @@ private List<Commit> gatherCommits(Git git, FillExtension extension) {
212212

213213
final List<BuildResponse> builds = this.fetchPreviousBuilds(extension);
214214
if (!builds.isEmpty()) {
215+
if (hasLatestBuildWithEmptyCommits(builds)) {
216+
return commits;
217+
}
218+
215219
// not every build might have commits, we have to find the last one that did have some
216220
BuildResponse lastBuildWithCommits = null;
217221
for (final BuildResponse build : builds) {
@@ -242,6 +246,11 @@ private List<Commit> gatherCommits(Git git, FillExtension extension) {
242246
return commits;
243247
}
244248

249+
@VisibleForTesting
250+
static boolean hasLatestBuildWithEmptyCommits(final List<BuildResponse> builds) {
251+
return !builds.isEmpty() && builds.getFirst().commits().isEmpty();
252+
}
253+
245254
private boolean tryMarkPreviousBuildCommit(final Git git, final RevWalk revWalk, final RevCommit currentCommit, final Commit lastCommit) throws IOException {
246255
final ObjectId lastBuildObjectId = git.getRepository().resolve(lastCommit.sha());
247256
if (lastBuildObjectId == null) {
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright 2024 PaperMC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.papermc.fill.gradle.task;
17+
18+
import io.papermc.fill.model.BuildChannel;
19+
import io.papermc.fill.model.response.v3.BuildResponse;
20+
import java.time.Instant;
21+
import java.util.List;
22+
import java.util.Map;
23+
import org.junit.jupiter.api.Test;
24+
25+
import static org.junit.jupiter.api.Assertions.assertFalse;
26+
import static org.junit.jupiter.api.Assertions.assertTrue;
27+
28+
class PublishToFillTaskTests {
29+
@Test
30+
void latestBuildWithEmptyCommitsReturnsTrue() {
31+
final BuildResponse latest = new BuildResponse(2, Instant.EPOCH, BuildChannel.STABLE, List.of(), Map.of());
32+
final BuildResponse older = new BuildResponse(1, Instant.EPOCH, BuildChannel.STABLE, List.of(), Map.of());
33+
34+
assertTrue(PublishToFillTask.hasLatestBuildWithEmptyCommits(List.of(latest, older)));
35+
}
36+
37+
@Test
38+
void latestBuildWithCommitsReturnsFalse() {
39+
final BuildResponse latest = new BuildResponse(2, Instant.EPOCH, BuildChannel.STABLE, List.of(
40+
new io.papermc.fill.model.Commit("abc", Instant.EPOCH, "msg")
41+
), Map.of());
42+
43+
assertFalse(PublishToFillTask.hasLatestBuildWithEmptyCommits(List.of(latest)));
44+
}
45+
46+
@Test
47+
void emptyBuildListReturnsFalse() {
48+
assertFalse(PublishToFillTask.hasLatestBuildWithEmptyCommits(List.of()));
49+
}
50+
}

0 commit comments

Comments
 (0)