Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ private List<Commit> gatherCommits(Git git, FillExtension extension) {

final List<BuildResponse> builds = this.fetchPreviousBuilds(extension);
if (!builds.isEmpty()) {
if (hasLatestBuildWithEmptyCommits(builds)) {
return commits;
}

// not every build might have commits, we have to find the last one that did have some
BuildResponse lastBuildWithCommits = null;
for (final BuildResponse build : builds) {
Expand Down Expand Up @@ -242,6 +246,11 @@ private List<Commit> gatherCommits(Git git, FillExtension extension) {
return commits;
}

@VisibleForTesting
static boolean hasLatestBuildWithEmptyCommits(final List<BuildResponse> builds) {
return !builds.isEmpty() && builds.getFirst().commits().isEmpty();
}

private boolean tryMarkPreviousBuildCommit(final Git git, final RevWalk revWalk, final RevCommit currentCommit, final Commit lastCommit) throws IOException {
final ObjectId lastBuildObjectId = git.getRepository().resolve(lastCommit.sha());
if (lastBuildObjectId == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright 2024 PaperMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.papermc.fill.gradle.task;

import io.papermc.fill.model.BuildChannel;
import io.papermc.fill.model.response.v3.BuildResponse;
import java.time.Instant;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

class PublishToFillTaskTests {
@Test
void latestBuildWithEmptyCommitsReturnsTrue() {
final BuildResponse latest = new BuildResponse(2, Instant.EPOCH, BuildChannel.STABLE, List.of(), Map.of());
final BuildResponse older = new BuildResponse(1, Instant.EPOCH, BuildChannel.STABLE, List.of(), Map.of());

assertTrue(PublishToFillTask.hasLatestBuildWithEmptyCommits(List.of(latest, older)));
}

@Test
void latestBuildWithCommitsReturnsFalse() {
final BuildResponse latest = new BuildResponse(2, Instant.EPOCH, BuildChannel.STABLE, List.of(
new io.papermc.fill.model.Commit("abc", Instant.EPOCH, "msg")
), Map.of());

assertFalse(PublishToFillTask.hasLatestBuildWithEmptyCommits(List.of(latest)));
}

@Test
void emptyBuildListReturnsFalse() {
assertFalse(PublishToFillTask.hasLatestBuildWithEmptyCommits(List.of()));
}
}