Commits

Sebastian Sdorra committed 930e483

added links commit and source view links to git repository quick view

Comments (0)

Files changed (3)

scm-plugins/scm-git-plugin/src/main/java/sonia/scm/web/GitRepositoryViewer.java

 import com.google.common.collect.Iterables;
 import com.google.common.io.Closeables;
 import com.google.inject.Inject;
+import com.google.inject.name.Named;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import sonia.scm.template.Template;
 import sonia.scm.template.TemplateEngine;
 import sonia.scm.template.TemplateEngineFactory;
+import sonia.scm.url.RepositoryUrlProvider;
+import sonia.scm.url.UrlProvider;
+import sonia.scm.url.UrlProviderFactory;
+import sonia.scm.util.HttpUtil;
 import sonia.scm.util.Util;
 
 //~--- JDK imports ------------------------------------------------------------
 import java.util.Date;
 import java.util.Iterator;
 
+import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
 /**
   public static final String MIMETYPE_HTML = "text/html";
 
   /** Field description */
-  public static final String RESOURCE_GITINDEX =
-    "sonia/scm/git.index.mustache";
+  public static final String RESOURCE_GITINDEX = "sonia/scm/git.index.mustache";
 
   /** Field description */
   private static final int CHANGESET_PER_BRANCH = 10;
    * Method description
    *
    *
+   *
+   * @param request
    * @param response
    * @param repository
    *
    * @throws IOException
    * @throws RepositoryException
    */
-  public void handleRequest(HttpServletResponse response, Repository repository)
+  public void handleRequest(HttpServletRequest request,
+    HttpServletResponse response, Repository repository)
     throws RepositoryException, IOException
   {
+
+    String baseUrl = HttpUtil.getCompleteUrl(request);
+
+    UrlProvider urlProvider = UrlProviderFactory.createUrlProvider(baseUrl,
+                                UrlProviderFactory.TYPE_WUI);
+
     response.setContentType(MIMETYPE_HTML);
 
+    RepositoryUrlProvider rup = urlProvider.getRepositoryUrlProvider();
+
     TemplateEngine engine = templateEngineFactory.getDefaultEngine();
     Template template = engine.getTemplate(RESOURCE_GITINDEX);
     //J-
     ImmutableMap<String,Object> env = ImmutableMap.of(
       "repository", repository, 
-      "branches", createBranchesModel(repository)
+      "branches", createBranchesModel(repository),
+      "commitViewLink", rup.getChangesetUrl(repository.getId(), 0, 20),
+      "sourceViewLink", rup.getBrowseUrl(repository.getId(), null, null)
     );
     //J+
 
     }
     finally
     {
-      Closeables.closeQuietly(writer);
+      Closeables.close(writer, true);
     }
   }
 

scm-plugins/scm-git-plugin/src/main/java/sonia/scm/web/ScmGitServlet.java

     }
     else
     {
-      printGitInformation(response);
+      printGitInformation(request, response);
     }
   }
 
    * @throws IOException
    * @throws ServletException
    */
-  private void printGitInformation(HttpServletResponse response)
+  private void printGitInformation(HttpServletRequest request,
+    HttpServletResponse response)
     throws ServletException, IOException
   {
     sonia.scm.repository.Repository scmRepository = repositoryProvider.get();
     {
       try
       {
-        repositoryViewer.handleRequest(response, scmRepository);
+        repositoryViewer.handleRequest(request, response, scmRepository);
       }
       catch (Exception ex)
       {

scm-plugins/scm-git-plugin/src/main/resources/sonia/scm/git.index.mustache

         </tbody>
       </table>
     {{/branches}}
+    
+    <h2>Notes</h2>
+    
+    <div>
+      <p>
+        This page is only a quick view for git commits. 
+        The full commit view is <a href="{{commitViewLink}}">here</a>.
+      </p>
+      <ul>
+        <li>
+          <a href="{{commitViewLink}}">Commits</a>
+        </li>
+        <li>
+          <a href="{{sourceViewLink}}">Source</a>
+        </li>
+      </ul>
+    </div>
 
     <h2>Git Informations</h2>
     <ul>