1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-19 19:25:48 +00:00

Fixed contributors menu not showing everyone

This commit is contained in:
TheBusyBiscuit 2020-10-28 01:01:25 +01:00
parent b3befbda49
commit 232ee74ceb
5 changed files with 65 additions and 13 deletions

View File

@ -44,6 +44,7 @@
* Fixed a missing slot in the contributors menu
* Fixed color codes in script downloading screen
* Fixed #2505
* Fixed contributors not showing correctly
## Release Candidate 17 (17 Oct 2020)

View File

@ -16,11 +16,28 @@ import me.mrCookieSlime.Slimefun.api.Slimefun;
class ContributionsConnector extends GitHubConnector {
// GitHub Bots that do not count as Contributors
// (includes "invalid-email-address" because it is an invalid contributor)
private static final List<String> blacklist = Arrays.asList("invalid-email-address", "renovate-bot", "TheBusyBot", "ImgBotApp", "imgbot", "imgbot[bot]", "github-actions[bot]", "gitlocalize-app", "gitlocalize-app[bot]", "mt-gitlocalize");
/*
* @formatter:off
* GitHub Bots that do not count as Contributors
* (includes "invalid-email-address" because it is an invalid contributor)
*/
private static final List<String> blacklist = Arrays.asList(
"invalid-email-address",
"renovate-bot",
"TheBusyBot",
"ImgBotApp",
"imgbot",
"imgbot[bot]",
"github-actions[bot]",
"gitlocalize-app",
"gitlocalize-app[bot]",
"mt-gitlocalize"
);
// Matches a GitHub name with a Minecraft name.
/*
* @formatter:on
* Matches a GitHub name with a Minecraft name.
*/
private static final Map<String, String> aliases = new HashMap<>();
// Should probably be switched to UUIDs at some point...
@ -83,7 +100,15 @@ class ContributionsConnector extends GitHubConnector {
@Override
public String getEndpoint() {
return "/contributors?per_page=100&page=" + page;
return "/contributors";
}
@Override
public Map<String, Object> getParameters() {
Map<String, Object> parameters = new HashMap<>();
parameters.put("per_page", 100);
parameters.put("page", page);
return parameters;
}
private void computeContributors(@Nonnull JSONArray array) {

View File

@ -1,6 +1,8 @@
package io.github.thebusybiscuit.slimefun4.core.services.github;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNonnullByDefault;
@ -39,4 +41,9 @@ class GitHubActivityConnector extends GitHubConnector {
return "";
}
@Override
public Map<String, Object> getParameters() {
return new HashMap<>();
}
}

View File

@ -8,12 +8,12 @@ import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.logging.Level;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import kong.unirest.GetRequest;
import kong.unirest.HttpResponse;
import kong.unirest.JsonNode;
import kong.unirest.Unirest;
@ -32,10 +32,9 @@ import me.mrCookieSlime.Slimefun.api.Slimefun;
abstract class GitHubConnector {
private static final String API_URL = "https://api.github.com/";
private static final String HEADER = "Slimefun4 (https://github.com/Slimefun)";
private static final String USER_AGENT = "Slimefun4 (https://github.com/Slimefun)";
protected final GitHubService github;
private final String repository;
private final String url;
private File file;
@ -49,7 +48,6 @@ abstract class GitHubConnector {
*/
GitHubConnector(@Nonnull GitHubService github, @Nonnull String repository) {
this.github = github;
this.repository = repository;
this.url = API_URL + "repos/" + repository + getEndpoint();
}
@ -70,6 +68,14 @@ abstract class GitHubConnector {
@Nonnull
public abstract String getEndpoint();
/**
* This {@link Map} contains the query parameters for our {@link URL}.
*
* @return A {@link Map} with our query parameters
*/
@Nonnull
public abstract Map<String, Object> getParameters();
/**
* This method is called when the connection finished successfully.
*
@ -98,15 +104,19 @@ abstract class GitHubConnector {
}
try {
GetRequest request = Unirest.get(url).header("User-Agent", HEADER);
HttpResponse<JsonNode> response = request.asJson();
// @formatter:off
HttpResponse<JsonNode> response = Unirest.get(url)
.queryString(getParameters())
.header("User-Agent", USER_AGENT)
.asJson();
// @formatter:on
if (response.isSuccess()) {
onSuccess(response.getBody());
writeCacheFile(response.getBody());
} else {
if (github.isLoggingEnabled()) {
Slimefun.getLogger().log(Level.WARNING, "Failed to fetch {0}: {1} - {2}", new Object[] { repository + getEndpoint(), response.getStatus(), response.getBody() });
Slimefun.getLogger().log(Level.WARNING, "Failed to fetch {0}: {1} - {2}", new Object[] { url, response.getStatus(), response.getBody() });
}
// It has the cached file, let's just read that then

View File

@ -1,5 +1,7 @@
package io.github.thebusybiscuit.slimefun4.core.services.github;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import javax.annotation.Nonnull;
@ -51,7 +53,14 @@ class GitHubIssuesConnector extends GitHubConnector {
@Override
public String getEndpoint() {
return "/issues?per_page=100";
return "/issues";
}
@Override
public Map<String, Object> getParameters() {
Map<String, Object> parameters = new HashMap<>();
parameters.put("per_page", 100);
return parameters;
}
}