Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Find draft GitHub releases using tag #26

Merged
merged 2 commits into from
Nov 3, 2024
Merged
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
9 changes: 8 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
### Version 2.1.7

* [Fix] - Find draft GitHub releases using tag [#26](https://github.com/firstdarkdev/modpublisher/pull/26)

### Version 2.1.6

* [FEAT] Add support for our NightBloom download platform

### Version 2.1.5

* [FEAT] Add support for "draft" uploads for Modrinth and CurseForge - HypherionSA
* [FEAT] Add support for our NightBloom download platform

### Version 2.1.4

Expand Down
5 changes: 3 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
version_major=2
version_minor=1
version_patch=5
release_type=release
version_patch=7
version_build=0
release_type=snapshot

# Dependencies
curse4j=1.0.11
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;
Expand Down Expand Up @@ -95,7 +96,7 @@ public void upload() throws Exception {

// Try to find an existing release.
// If one is found, the file will be added onto it.
GHRelease ghRelease = ghRepository.getReleaseByTagName(tag);
GHRelease ghRelease = getRelease(ghRepository, tag);

UploadPreChecks.checkEmptyJar(extension, uploadFile, extension.getLoaders().get());

Expand Down Expand Up @@ -175,6 +176,24 @@ public void upload() throws Exception {
);
}

private static GHRelease getRelease(GHRepository repo, String tag) throws IOException {
// First, attempt to get the tag using the releases/tags/<tag> endpoint
GHRelease attempt1 = repo.getReleaseByTagName(tag);
if (attempt1 != null) {
return attempt1;
}

// For draft releases we need to do some additional work...
// Scan all releases for one with a matching tag name
for (GHRelease release : repo.listReleases()) {
if (Objects.equals(tag, release.getTagName())) {
return release;
}
}

return null;
}

/**
* Lookup whether the {@link GHRepository repo} has the specified {@code ref} or not.
*
Expand Down