Skip to content

Commit

Permalink
[MCHANGES-431] Replace GitHub client with recommended client from docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Giovds authored and slawekjaranowski committed Nov 22, 2024
1 parent 6b49fea commit 71415d8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 35 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,9 @@ under the License.

<!-- github dependencies -->
<dependency>
<groupId>org.eclipse.mylyn.github</groupId>
<artifactId>org.eclipse.egit.github.core</artifactId>
<version>2.1.5</version>
<groupId>org.kohsuke</groupId>
<artifactId>github-api</artifactId>
<version>1.326</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
Expand Down
42 changes: 19 additions & 23 deletions src/main/java/org/apache/maven/plugins/github/GitHubDownloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Collection;
import java.util.List;
import java.util.Map;

import org.apache.maven.plugin.logging.Log;
import org.apache.maven.plugins.issues.Issue;
Expand All @@ -35,9 +34,10 @@
import org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest;
import org.apache.maven.settings.crypto.SettingsDecrypter;
import org.apache.maven.settings.crypto.SettingsDecryptionResult;
import org.eclipse.egit.github.core.Label;
import org.eclipse.egit.github.core.client.GitHubClient;
import org.eclipse.egit.github.core.service.IssueService;
import org.kohsuke.github.GHIssue;
import org.kohsuke.github.GHIssueState;
import org.kohsuke.github.GHLabel;
import org.kohsuke.github.GitHubBuilder;

/**
* @since 2.8
Expand All @@ -47,7 +47,7 @@ public class GitHubDownloader {
/**
* The github client.
*/
private GitHubClient client;
private GitHubBuilder client;

/**
* A boolean to indicate if we should include open issues as well
Expand Down Expand Up @@ -80,7 +80,7 @@ public GitHubDownloader(
int githubPort,
boolean includeOpenIssues,
boolean onlyMilestoneIssues)
throws MalformedURLException {
throws IOException {
this.includeOpenIssues = includeOpenIssues;
this.onlyMilestoneIssues = onlyMilestoneIssues;

Expand All @@ -89,9 +89,9 @@ public GitHubDownloader(
// The githubclient prefers to connect to 'github.com' using the api domain, unlike github enterprise
// which can connect fine using its domain, so for github.com use empty constructor
if (githubURL.getHost().equalsIgnoreCase("github.com")) {
this.client = new GitHubClient();
this.client = new GitHubBuilder();
} else {
this.client = new GitHubClient(githubURL.getHost(), githubPort, githubScheme);
this.client = new GitHubBuilder().withEndpoint(githubScheme + githubURL.getHost() + githubPort);
}

this.githubIssueURL = project.getIssueManagement().getUrl();
Expand Down Expand Up @@ -119,7 +119,7 @@ public GitHubDownloader(
this.githubRepo = urlPathParts[1];
}

protected Issue createIssue(org.eclipse.egit.github.core.Issue githubIssue) {
protected Issue createIssue(GHIssue githubIssue) throws IOException {
Issue issue = new Issue();

issue.setKey(String.valueOf(githubIssue.getNumber()));
Expand Down Expand Up @@ -155,9 +155,9 @@ protected Issue createIssue(org.eclipse.egit.github.core.Issue githubIssue) {
issue.setStatus("open");
}

List<Label> labels = githubIssue.getLabels();
final Collection<GHLabel> labels = githubIssue.getLabels();
if (labels != null && !labels.isEmpty()) {
issue.setType(labels.get(0).getName());
issue.setType(labels.stream().findAny().get().getName());
}

return issue;
Expand All @@ -166,24 +166,20 @@ protected Issue createIssue(org.eclipse.egit.github.core.Issue githubIssue) {
public List<Issue> getIssueList() throws IOException {
List<Issue> issueList = new ArrayList<>();

IssueService service = new IssueService(client);
Map<String, String> issueFilter = new HashMap<>();

if (includeOpenIssues) {
// Adding open issues

for (org.eclipse.egit.github.core.Issue issue : service.getIssues(githubOwner, githubRepo, issueFilter)) {
final List<GHIssue> openIssues =
client.build().getRepository(githubOwner + "/" + githubRepo).getIssues(GHIssueState.OPEN);
for (final GHIssue issue : openIssues) {
if (!onlyMilestoneIssues || issue.getMilestone() != null) {
issueList.add(createIssue(issue));
}
}
}

// Adding closed issues

issueFilter.put("state", "closed");
final List<GHIssue> closedIssues =
client.build().getRepository(githubOwner + "/" + githubRepo).getIssues(GHIssueState.CLOSED);

for (org.eclipse.egit.github.core.Issue issue : service.getIssues(githubOwner, githubRepo, issueFilter)) {
for (final GHIssue issue : closedIssues) {
if (!onlyMilestoneIssues || issue.getMilestone() != null) {
issueList.add(createIssue(issue));
}
Expand All @@ -207,7 +203,7 @@ public void configureAuthentication(
server = result.getServer();
String user = server.getUsername();
String password = server.getPassword();
this.client.setCredentials(user, password);
this.client.withPassword(user, password);

configured = true;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package org.apache.maven.plugins.github;

import java.io.IOException;
import java.net.MalformedURLException;
import java.util.Collections;
import java.util.List;

Expand All @@ -37,7 +36,8 @@
import org.apache.maven.settings.crypto.SettingsDecrypter;
import org.apache.maven.settings.crypto.SettingsDecryptionRequest;
import org.apache.maven.settings.crypto.SettingsDecryptionResult;
import org.eclipse.egit.github.core.User;
import org.kohsuke.github.GHIssue;
import org.kohsuke.github.GHUser;
import org.mockito.ArgumentCaptor;

import static org.mockito.Mockito.any;
Expand All @@ -51,12 +51,11 @@ public void testCreateIssue() throws IOException {
IssueManagement issueManagement = newGitHubIssueManagement();
GitHubDownloader gitHubDownloader = newGitHubDownloader(issueManagement);

org.eclipse.egit.github.core.Issue githubIssue = new org.eclipse.egit.github.core.Issue();
githubIssue.setNumber(1);
githubIssue.setBody("Body");
githubIssue.setTitle("Title");
User user = new User();
githubIssue.setUser(user);
GHIssue githubIssue = mock(GHIssue.class);
when(githubIssue.getNumber()).thenReturn(1);
when(githubIssue.getTitle()).thenReturn("Title");
when(githubIssue.getBody()).thenReturn("Body");
when(githubIssue.getUser()).thenReturn(new GHUser());

Issue issue = gitHubDownloader.createIssue(githubIssue);

Expand Down Expand Up @@ -118,7 +117,7 @@ private Server newServer(String id) {
return server;
}

private GitHubDownloader newGitHubDownloader(IssueManagement issueManagement) throws MalformedURLException {
private GitHubDownloader newGitHubDownloader(IssueManagement issueManagement) throws IOException {
MavenProject mavenProject = new MavenProject();
mavenProject.setIssueManagement(issueManagement);
return new GitHubDownloader(mavenProject, "https", 80, true, false);
Expand Down

0 comments on commit 71415d8

Please sign in to comment.