This is an automated email from the ASF dual-hosted git repository.

sjaranowski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-changes-plugin.git


The following commit(s) were added to refs/heads/master by this push:
     new 71415d8  [MCHANGES-431] Replace GitHub client with recommended client 
from docs
71415d8 is described below

commit 71415d83e26a045a4677070524bccaccf7e8c32b
Author: Giovanni van der Schelde <gvdsche...@gmail.com>
AuthorDate: Fri Nov 22 15:14:04 2024 +0100

    [MCHANGES-431] Replace GitHub client with recommended client from docs
---
 pom.xml                                            |  6 ++--
 .../maven/plugins/github/GitHubDownloader.java     | 42 ++++++++++------------
 .../plugins/github/GitHubDownloaderTestCase.java   | 17 +++++----
 3 files changed, 30 insertions(+), 35 deletions(-)

diff --git a/pom.xml b/pom.xml
index 77bef92..336268c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -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>
diff --git 
a/src/main/java/org/apache/maven/plugins/github/GitHubDownloader.java 
b/src/main/java/org/apache/maven/plugins/github/GitHubDownloader.java
index 410deab..5c0fa03 100644
--- a/src/main/java/org/apache/maven/plugins/github/GitHubDownloader.java
+++ b/src/main/java/org/apache/maven/plugins/github/GitHubDownloader.java
@@ -22,9 +22,8 @@ import java.io.IOException;
 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;
@@ -35,9 +34,10 @@ import org.apache.maven.settings.building.SettingsProblem;
 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
@@ -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
@@ -80,7 +80,7 @@ public class GitHubDownloader {
             int githubPort,
             boolean includeOpenIssues,
             boolean onlyMilestoneIssues)
-            throws MalformedURLException {
+            throws IOException {
         this.includeOpenIssues = includeOpenIssues;
         this.onlyMilestoneIssues = onlyMilestoneIssues;
 
@@ -89,9 +89,9 @@ public class 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();
@@ -119,7 +119,7 @@ public class 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()));
@@ -155,9 +155,9 @@ public class GitHubDownloader {
             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;
@@ -166,24 +166,20 @@ public class GitHubDownloader {
     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));
             }
@@ -207,7 +203,7 @@ public class GitHubDownloader {
                 server = result.getServer();
                 String user = server.getUsername();
                 String password = server.getPassword();
-                this.client.setCredentials(user, password);
+                this.client.withPassword(user, password);
 
                 configured = true;
                 break;
diff --git 
a/src/test/java/org/apache/maven/plugins/github/GitHubDownloaderTestCase.java 
b/src/test/java/org/apache/maven/plugins/github/GitHubDownloaderTestCase.java
index 36f18a2..35f7401 100644
--- 
a/src/test/java/org/apache/maven/plugins/github/GitHubDownloaderTestCase.java
+++ 
b/src/test/java/org/apache/maven/plugins/github/GitHubDownloaderTestCase.java
@@ -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;
 
@@ -37,7 +36,8 @@ import 
org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest;
 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;
@@ -51,12 +51,11 @@ public class GitHubDownloaderTestCase extends TestCase {
         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);
 
@@ -118,7 +117,7 @@ public class GitHubDownloaderTestCase extends TestCase {
         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);

Reply via email to