Skip to content

Commit 71415d8

Browse files
Giovdsslawekjaranowski
authored andcommitted
[MCHANGES-431] Replace GitHub client with recommended client from docs
1 parent 6b49fea commit 71415d8

File tree

3 files changed

+30
-35
lines changed

3 files changed

+30
-35
lines changed

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,9 @@ under the License.
262262

263263
<!-- github dependencies -->
264264
<dependency>
265-
<groupId>org.eclipse.mylyn.github</groupId>
266-
<artifactId>org.eclipse.egit.github.core</artifactId>
267-
<version>2.1.5</version>
265+
<groupId>org.kohsuke</groupId>
266+
<artifactId>github-api</artifactId>
267+
<version>1.326</version>
268268
</dependency>
269269
<dependency>
270270
<groupId>com.google.code.gson</groupId>

src/main/java/org/apache/maven/plugins/github/GitHubDownloader.java

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@
2222
import java.net.MalformedURLException;
2323
import java.net.URL;
2424
import java.util.ArrayList;
25-
import java.util.HashMap;
25+
import java.util.Collection;
2626
import java.util.List;
27-
import java.util.Map;
2827

2928
import org.apache.maven.plugin.logging.Log;
3029
import org.apache.maven.plugins.issues.Issue;
@@ -35,9 +34,10 @@
3534
import org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest;
3635
import org.apache.maven.settings.crypto.SettingsDecrypter;
3736
import org.apache.maven.settings.crypto.SettingsDecryptionResult;
38-
import org.eclipse.egit.github.core.Label;
39-
import org.eclipse.egit.github.core.client.GitHubClient;
40-
import org.eclipse.egit.github.core.service.IssueService;
37+
import org.kohsuke.github.GHIssue;
38+
import org.kohsuke.github.GHIssueState;
39+
import org.kohsuke.github.GHLabel;
40+
import org.kohsuke.github.GitHubBuilder;
4141

4242
/**
4343
* @since 2.8
@@ -47,7 +47,7 @@ public class GitHubDownloader {
4747
/**
4848
* The github client.
4949
*/
50-
private GitHubClient client;
50+
private GitHubBuilder client;
5151

5252
/**
5353
* A boolean to indicate if we should include open issues as well
@@ -80,7 +80,7 @@ public GitHubDownloader(
8080
int githubPort,
8181
boolean includeOpenIssues,
8282
boolean onlyMilestoneIssues)
83-
throws MalformedURLException {
83+
throws IOException {
8484
this.includeOpenIssues = includeOpenIssues;
8585
this.onlyMilestoneIssues = onlyMilestoneIssues;
8686

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

9797
this.githubIssueURL = project.getIssueManagement().getUrl();
@@ -119,7 +119,7 @@ public GitHubDownloader(
119119
this.githubRepo = urlPathParts[1];
120120
}
121121

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

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

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

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

169-
IssueService service = new IssueService(client);
170-
Map<String, String> issueFilter = new HashMap<>();
171-
172169
if (includeOpenIssues) {
173-
// Adding open issues
174-
175-
for (org.eclipse.egit.github.core.Issue issue : service.getIssues(githubOwner, githubRepo, issueFilter)) {
170+
final List<GHIssue> openIssues =
171+
client.build().getRepository(githubOwner + "/" + githubRepo).getIssues(GHIssueState.OPEN);
172+
for (final GHIssue issue : openIssues) {
176173
if (!onlyMilestoneIssues || issue.getMilestone() != null) {
177174
issueList.add(createIssue(issue));
178175
}
179176
}
180177
}
181178

182-
// Adding closed issues
183-
184-
issueFilter.put("state", "closed");
179+
final List<GHIssue> closedIssues =
180+
client.build().getRepository(githubOwner + "/" + githubRepo).getIssues(GHIssueState.CLOSED);
185181

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

212208
configured = true;
213209
break;

src/test/java/org/apache/maven/plugins/github/GitHubDownloaderTestCase.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
package org.apache.maven.plugins.github;
2020

2121
import java.io.IOException;
22-
import java.net.MalformedURLException;
2322
import java.util.Collections;
2423
import java.util.List;
2524

@@ -37,7 +36,8 @@
3736
import org.apache.maven.settings.crypto.SettingsDecrypter;
3837
import org.apache.maven.settings.crypto.SettingsDecryptionRequest;
3938
import org.apache.maven.settings.crypto.SettingsDecryptionResult;
40-
import org.eclipse.egit.github.core.User;
39+
import org.kohsuke.github.GHIssue;
40+
import org.kohsuke.github.GHUser;
4141
import org.mockito.ArgumentCaptor;
4242

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

54-
org.eclipse.egit.github.core.Issue githubIssue = new org.eclipse.egit.github.core.Issue();
55-
githubIssue.setNumber(1);
56-
githubIssue.setBody("Body");
57-
githubIssue.setTitle("Title");
58-
User user = new User();
59-
githubIssue.setUser(user);
54+
GHIssue githubIssue = mock(GHIssue.class);
55+
when(githubIssue.getNumber()).thenReturn(1);
56+
when(githubIssue.getTitle()).thenReturn("Title");
57+
when(githubIssue.getBody()).thenReturn("Body");
58+
when(githubIssue.getUser()).thenReturn(new GHUser());
6059

6160
Issue issue = gitHubDownloader.createIssue(githubIssue);
6261

@@ -118,7 +117,7 @@ private Server newServer(String id) {
118117
return server;
119118
}
120119

121-
private GitHubDownloader newGitHubDownloader(IssueManagement issueManagement) throws MalformedURLException {
120+
private GitHubDownloader newGitHubDownloader(IssueManagement issueManagement) throws IOException {
122121
MavenProject mavenProject = new MavenProject();
123122
mavenProject.setIssueManagement(issueManagement);
124123
return new GitHubDownloader(mavenProject, "https", 80, true, false);

0 commit comments

Comments
 (0)