[MCHANGES-290] Provide GitHub support for generate announcement report
Submitted by Markku Saarela.

git-svn-id: https://svn.apache.org/repos/asf/maven/plugins/trunk@1392125 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 02ae473..40ba295 100644
--- a/src/main/java/org/apache/maven/plugin/announcement/AnnouncementMojo.java
+++ b/src/main/java/org/apache/maven/plugin/announcement/AnnouncementMojo.java
@@ -33,6 +33,8 @@
 import org.apache.maven.plugin.changes.IssueAdapter;
 import org.apache.maven.plugin.changes.ProjectUtils;
 import org.apache.maven.plugin.changes.ReleaseUtils;
+import org.apache.maven.plugin.github.GitHubDownloader;
+import org.apache.maven.plugin.github.GitHubIssueManagementSystem;
 import org.apache.maven.plugin.issues.Issue;
 import org.apache.maven.plugin.issues.IssueManagementSystem;
 import org.apache.maven.plugin.issues.IssueUtils;
@@ -74,6 +76,8 @@
 
     private static final String TRAC = "Trac";
 
+    private static final String GIT_HUB = "GitHub";
+
     /**
      * The name of the file which will contain the generated announcement. If
      * no value is specified the plugin will use the name of the template.
@@ -384,6 +388,26 @@
     @Parameter( property = "changes.tracUser", defaultValue = "" )
     private String tracUser;
 
+    //=======================================//
+    //  Github Parameters                    //
+    //=======================================//
+
+    /**
+     * The scheme of your github api domain. Only use if using github enterprise.
+     * 
+     * @since 2.9
+     */
+    @Parameter( defaultValue = "http", property = "changes.githubAPIScheme")
+    private String githubAPIScheme;
+
+    /**
+     * The port of your github api domain. Only use if using github enterprise.
+     * 
+     * @since 2.9
+     */
+    @Parameter( defaultValue = "80", property = "changes.githubAPIPort")
+    private int githubAPIPort;
+
     private ReleaseUtils releaseUtils = new ReleaseUtils( getLog() );
 
     private ChangesXML xml;
@@ -477,6 +501,21 @@
                 }
             }
 
+            if ( issueManagementSystems.contains( GIT_HUB ) )
+            {
+                if ( ProjectUtils.validateIfIssueManagementComplete( project, GIT_HUB, "GitHub announcement", getLog() ) )
+                {
+                    List<Release> gitHubReleases = getGitHubReleases();
+                    releases = releaseUtils.mergeReleases( releases, gitHubReleases );
+                    getLog().info( "Including issues from GitHub in announcement..." );
+                }
+                else
+                {
+                    throw new MojoExecutionException(
+                                                      "Something is wrong with the Issue Management section. See previous error messages." );
+                }
+            }
+
             // @todo Add more issue management systems here.
 
             // Follow these steps:
@@ -740,6 +779,21 @@
         }
     }
 
+    protected List<Release> getGitHubReleases()
+        throws MojoExecutionException
+    {
+        try
+        {
+            GitHubDownloader issueDownloader =
+                new GitHubDownloader( project, githubAPIScheme, githubAPIPort, false, true );
+            return getReleases( issueDownloader.getIssueList(), new GitHubIssueManagementSystem() );
+        }
+        catch ( Exception e )
+        {
+            throw new MojoExecutionException( "Failed to extract issues from GitHub.", e );
+        }
+    }
+
     /*
      * accessors
      */