[MCHANGES-305] Provide support for private Github repos

git-svn-id: https://svn.apache.org/repos/asf/maven/plugins/trunk@1654113 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/maven/plugin/announcement/AnnouncementMojo.java b/src/main/java/org/apache/maven/plugin/announcement/AnnouncementMojo.java
index aa1ab17..b3fcdae 100644
--- a/src/main/java/org/apache/maven/plugin/announcement/AnnouncementMojo.java
+++ b/src/main/java/org/apache/maven/plugin/announcement/AnnouncementMojo.java
@@ -454,6 +454,14 @@
     @Parameter( defaultValue = "80", property = "changes.githubAPIPort" )
     private int githubAPIPort;
 
+    /**
+     * The settings.xml server id to be used to authenticate into github api domain. Only use if using github enterprise.
+     * 
+     * @since 2.12
+     */
+    @Parameter ( defaultValue = "github" )
+    private String githubAPIServerId;
+    
     private ReleaseUtils releaseUtils = new ReleaseUtils( getLog() );
 
     private ChangesXML xml;
@@ -849,6 +857,9 @@
         {
             GitHubDownloader issueDownloader =
                 new GitHubDownloader( project, githubAPIScheme, githubAPIPort, false, true );
+            
+            issueDownloader.configureAuthentication( githubAPIServerId, settings, getLog() );
+            
             return getReleases( issueDownloader.getIssueList(), new GitHubIssueManagementSystem() );
         }
         catch ( Exception e )
diff --git a/src/main/java/org/apache/maven/plugin/github/GitHubDownloader.java b/src/main/java/org/apache/maven/plugin/github/GitHubDownloader.java
index 0b0e9ab..5326dbd 100644
--- a/src/main/java/org/apache/maven/plugin/github/GitHubDownloader.java
+++ b/src/main/java/org/apache/maven/plugin/github/GitHubDownloader.java
@@ -20,7 +20,11 @@
  */
 
 import org.apache.maven.plugin.issues.Issue;
+import org.apache.maven.plugin.logging.Log;
 import org.apache.maven.project.MavenProject;
+import org.apache.maven.settings.Server;
+import org.apache.maven.settings.Settings;
+
 import org.eclipse.egit.github.core.Label;
 import org.eclipse.egit.github.core.client.GitHubClient;
 import org.eclipse.egit.github.core.service.IssueService;
@@ -207,4 +211,29 @@
         return issueList;
     }
 
+    public void configureAuthentication( String githubAPIServerId, Settings settings, Log log )
+    {
+        boolean configured = false;
+
+        List<Server> servers = settings.getServers();
+
+        for ( Server server : servers )
+        {
+            if ( server.getId().equals( githubAPIServerId ) )
+            {
+                String user = server.getUsername();
+                String password = server.getPassword();
+                this.client.setCredentials( user, password );
+
+                configured = true;
+                break;
+}
+        }
+        
+        if ( !configured )
+        {
+            log.warn( "Can't find server id [" + githubAPIServerId + "] configured in githubAPIServerId." );
+        }
+    }
+
 }
diff --git a/src/main/java/org/apache/maven/plugin/github/GitHubMojo.java b/src/main/java/org/apache/maven/plugin/github/GitHubMojo.java
index 43fca7b..daf2832 100644
--- a/src/main/java/org/apache/maven/plugin/github/GitHubMojo.java
+++ b/src/main/java/org/apache/maven/plugin/github/GitHubMojo.java
@@ -28,6 +28,7 @@
 import org.apache.maven.plugins.annotations.Mojo;
 import org.apache.maven.plugins.annotations.Parameter;
 import org.apache.maven.reporting.MavenReportException;
+import org.apache.maven.settings.Settings;
 
 import java.net.MalformedURLException;
 import java.util.HashMap;
@@ -94,6 +95,18 @@
     private int githubAPIPort;
 
     /**
+     * The settings.xml server id to be used to authenticate into github api domain. Only use if using github enterprise.
+     */
+    @Parameter ( defaultValue = "github" )
+    private String githubAPIServerId;
+
+    /**
+     * Settings XML configuration.
+     */
+    @Parameter( defaultValue = "${settings}", readonly = true, required = true )
+    private Settings settings;
+
+    /**
      * Boolean which says if we should include open issues in the report.
      */
     @Parameter ( defaultValue = "true" )
@@ -166,6 +179,8 @@
             GitHubDownloader issueDownloader =
                 new GitHubDownloader( project, githubAPIScheme, githubAPIPort, includeOpenIssues, onlyMilestoneIssues );
 
+            issueDownloader.configureAuthentication( githubAPIServerId, settings, getLog() );
+
             List<Issue> issueList = issueDownloader.getIssueList();
 
             if ( onlyCurrentVersion )