package uk.co.pols.bamboo.gitplugin;

import com.atlassian.bamboo.commit.Commit;
import com.atlassian.bamboo.commit.CommitFile;
import com.atlassian.bamboo.repository.Repository;
import com.atlassian.bamboo.resultsummary.ResultsSummary;
import com.atlassian.bamboo.utils.error.ErrorCollection;
import com.atlassian.bamboo.webrepository.AbstractWebRepositoryViewer;
import com.atlassian.bamboo.webrepository.CommitUrlProvider;
import com.atlassian.bamboo.ww2.actions.build.admin.create.BuildConfiguration;
import org.apache.commons.configuration.HierarchicalConfiguration;

import java.util.Arrays;
import java.util.Collection;

import static uk.co.pols.bamboo.gitplugin.GitRepositoryConfig.AvailableConfig.WEB_REPOSITORY;

public class GitHubWebRepositoryViewer extends AbstractWebRepositoryViewer implements CommitUrlProvider {
    private GitRepositoryConfig gitRepositoryConfig = gitRepositoryConfig();

    @Override
    public Collection<String> getSupportedRepositories() {
        return Arrays.asList("uk.co.pols.bamboo.gitplugin:github");
    }

    @Override
    public void populateFromConfig(HierarchicalConfiguration config) {
        super.populateFromConfig(config);
        gitRepositoryConfig.populateFromConfig(config, WEB_REPOSITORY);
    }

    @Override
    public HierarchicalConfiguration toConfiguration() {
        return gitRepositoryConfig.toConfiguration(super.toConfiguration(), WEB_REPOSITORY);
    }

    @Override
    public ErrorCollection validate(BuildConfiguration buildConfiguration) {
        return gitRepositoryConfig.validate(super.validate(buildConfiguration), buildConfiguration, WEB_REPOSITORY);
    }

    public String getHtmlForCommitsFull(ResultsSummary resultsSummary, Repository repository) {
        System.out.println("resultsSummary = " + resultsSummary);
        return "<p>getHtmlForCommitsFull</p>";
    }

    public String getHtmlForCommitsSummary(ResultsSummary resultsSummary, Repository repository) {
        System.out.println("resultsSummary = " + resultsSummary);
        return "<p>getHtmlForCommitsSummary</p>";
    }

    public void setWebRepositoryUrl(String url) {
        gitRepositoryConfig.setWebRepositoryUrl(url);
    }

    public String getWebRepositoryUrl() {
        return gitRepositoryConfig.getWebRepositoryUrl();
    }

    public String getWebRepositoryUrlForFile(CommitFile commitFile) {
        return gitRepositoryConfig.getWebRepositoryUrlForFile(commitFile);
    }

    /*
        Rendering links in emails too
    */
    public String getWebRepositoryUrlForCommit(Commit commit, Repository repository) {
        return gitRepositoryConfig.getWebRepositoryUrlForCommit(commit);
    }

    protected GitRepositoryConfig gitRepositoryConfig() {
        return new GitRepositoryConfig();
    }
}
@@ -333,33 +333,23 @@
 ory.
-AbstractWebRepositoryView
+CommitUrlProvid
 er;%0A
@@ -386,39 +386,48 @@
 brepository.
-CommitUrlProvid
+DefaultWebRepositoryView
 er;%0Aimport c
@@ -559,24 +559,56 @@
 nfiguration;
+%0Aimport org.apache.log4j.Logger;
 %0A%0Aimport jav
@@ -798,15 +798,14 @@
 nds 
-Abstrac
+Defaul
 tWeb
@@ -852,16 +852,99 @@
 vider %7B%0A
+    private static Logger log = Logger.getLogger(GitHubWebRepositoryViewer.class);%0A
     priv
@@ -1082,24 +1082,118 @@
 itories() %7B%0A
+        log.info(%22********************* GitHubWebRepositoryViewer.getSupportedRepositories%22);%0A
         retu
@@ -1336,24 +1336,112 @@
 n config) %7B%0A
+        log.info(%22********************* GitHubWebRepositoryViewer.populateFromConfig%22);%0A
         supe
@@ -1616,24 +1616,109 @@
 uration() %7B%0A
+        log.info(%22********************  GitHubWebRepositoryViewer.toConfiguration%22);%0A
         retu
@@ -1892,24 +1892,102 @@
 guration) %7B%0A
+        log.info(%22********************  GitHubWebRepositoryViewer.validate%22);%0A
         retu
@@ -2206,48 +2206,196 @@
     
-System.out.println(%22resultsSummary = %22 +
+log.info(%22****************  GitHubWebRepositoryViewer.getHtmlForCommitsFull%22);%0A        String html = super.getHtmlForCommitsFull(resultsSummary,repository);%0A        log.info(%22*************
  res
@@ -2397,35 +2397,47 @@
 * resultsSummary
+ = %22 + html
 );%0A
+%0A
         return %22
@@ -2439,38 +2439,12 @@
 urn 
-%22%3Cp%3EgetHtmlForCommitsFull%3C/p%3E%22
+html
 ;%0A  
@@ -2559,49 +2559,191 @@
     
-System.out.println(%22resultsSummary = %22 + 
+log.info(%22****************** GitHubWebRepositoryViewer.getHtmlForCommitsSummary%22);%0A        String html = super.getHtmlForCommitsSummary(resultsSummary, repository);%0A        log.info(%22
 resu
@@ -2752,16 +2752,27 @@
 sSummary
+ = %22 + html
 );%0A     
@@ -2785,41 +2785,12 @@
 urn 
-%22%3Cp%3EgetHtmlForCommitsSummary%3C/p%3E%22
+html
 ;%0A  
@@ -2840,24 +2840,110 @@
 ring url) %7B%0A
+        log.info(%22*****************  GitHubWebRepositoryViewer.setWebRepositoryUrl%22);%0A
         gitR
@@ -3029,24 +3029,109 @@
 toryUrl() %7B%0A
+        log.info(%22****************  GitHubWebRepositoryViewer.getWebRepositoryUrl%22);%0A
         retu
@@ -3249,24 +3249,116 @@
 mmitFile) %7B%0A
+        log.info(%22**************** GitHubWebRepositoryViewer.getWebRepositoryUrlForFile%22);%0A%0A
         retu
@@ -3558,32 +3558,123 @@
 y repository) %7B%0A
+        log.info(%22************** GitHubWebRepositoryViewer.getWebRepositoryUrlForCommit%22);%0A
         return g

Extend the Default WeRepository Viewer so we get all the jira links and good stuff