From c8aa46d27bbd2c85c75f11b22aba2b0197b82bde Mon Sep 17 00:00:00 2001
From: Gary Kim <gary@garykim.dev>
Date: Wed, 17 Jul 2019 20:02:41 +0000
Subject: [PATCH] Add Extra Info to Branches Page (#7461)

* Add branch protection information to branches page

This change will add a tag on the ui that indicates
whether a branch is protected on the repository
branches page.

Signed-off-by: Gary Kim <gary@garykim.dev>

* Add last commit information to repo branches page

This change adds the ID and commit message of the last
commit on a branch to the branches page for repositories.

Signed-off-by: Gary Kim <gary@garykim.dev>

* Make branch page commit message truncate in css rather then template

The truncating of commit messages shown under branches
in the repository branches page has been moved to using
css rather then the Go template as the template was causing
some issues when the commit messaged had a link when rendered.

This commit also makes the commit message paragraph itself
use flex in order to make managing its elements easier.

Signed-off-by: Gary Kim <gary@garykim.dev>
---
 public/css/index.css            |  3 ++-
 public/less/_explore.less       |  9 ++++++++-
 templates/repo/branch/list.tmpl | 19 ++++++++++++++++---
 3 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/public/css/index.css b/public/css/index.css
index 0630cb6ed5..4a7dfb2824 100644
--- a/public/css/index.css
+++ b/public/css/index.css
@@ -982,7 +982,8 @@ tbody.commit-list{vertical-align:baseline}
 .ui.repository.list .item .time{font-size:12px;color:grey}
 .ui.repository.list .item .ui.tags{margin-bottom:1em}
 .ui.repository.list .item .ui.avatar.image{width:24px;height:24px}
-.ui.repository.branches .time{font-size:12px;color:grey}
+.ui.repository.branches .info{font-size:12px;color:grey;display:flex;white-space:pre}
+.ui.repository.branches .info .commit-message{max-width:72em;overflow:hidden;text-overflow:ellipsis}
 .ui.user.list .item{padding-bottom:25px}
 .ui.user.list .item:not(:first-child){border-top:1px solid #eee;padding-top:25px}
 .ui.user.list .item .ui.avatar.image{width:40px;height:40px}
diff --git a/public/less/_explore.less b/public/less/_explore.less
index c5065a35bc..11dacb7285 100644
--- a/public/less/_explore.less
+++ b/public/less/_explore.less
@@ -62,9 +62,16 @@
 }
 
 .ui.repository.branches {
-    .time {
+    .info {
         font-size: 12px;
         color: #808080;
+        display: flex;
+        white-space: pre;
+        .commit-message {
+            max-width: 72em;
+            overflow: hidden;
+            text-overflow: ellipsis;
+        }
     }
 }
 
diff --git a/templates/repo/branch/list.tmpl b/templates/repo/branch/list.tmpl
index 2028797bdb..a284de2c90 100644
--- a/templates/repo/branch/list.tmpl
+++ b/templates/repo/branch/list.tmpl
@@ -12,7 +12,17 @@
 			<table class="ui very basic striped fixed table single line">
 				<tbody>
 					<tr>
-						<td>{{.DefaultBranch}}</td>
+						<td>
+						{{range $branch := .Branches}}
+							{{if eq .Name $.DefaultBranch}}
+								{{if .IsProtected}}
+									<i class="octicon octicon-shield"></i>
+								{{end}}
+								{{$.DefaultBranch}}
+								<p class="info"><i class="octicon octicon-git-commit"></i><a href="{{$.RepoLink}}/commit/{{.Commit.ID.String}}">{{ShortSha .Commit.ID.String}}</a> · <span class="commit-message">{{RenderCommitMessage .Commit.CommitMessage $.RepoLink $.Repository.ComposeMetas}}</span> · {{$.i18n.Tr "org.repo_updated"}} {{TimeSince .Commit.Committer.When $.i18n.Lang}}</p>
+							{{end}}
+						{{end}}
+						</td>
 					</tr>
 				</tbody>
 			</table>
@@ -41,10 +51,13 @@
 									<td>
 									{{if .IsDeleted}}
 										<s><a href="{{$.RepoLink}}/src/branch/{{.Name | EscapePound}}">{{.Name}}</a></s>
-										<p class="time">{{$.i18n.Tr "repo.branch.deleted_by" .DeletedBranch.DeletedBy.Name}} {{TimeSinceUnix .DeletedBranch.DeletedUnix $.i18n.Lang}}</p>
+										<p class="info">{{$.i18n.Tr "repo.branch.deleted_by" .DeletedBranch.DeletedBy.Name}} {{TimeSinceUnix .DeletedBranch.DeletedUnix $.i18n.Lang}}</p>
 									{{else}}
+										{{if .IsProtected}}
+											<i class="octicon octicon-shield"></i>
+										{{end}}
 										<a href="{{$.RepoLink}}/src/branch/{{.Name | EscapePound}}">{{.Name}}</a>
-										<p class="time">{{$.i18n.Tr "org.repo_updated"}} {{TimeSince .Commit.Committer.When $.i18n.Lang}}</p>
+										<p class="info"><i class="octicon octicon-git-commit"></i><a href="{{$.RepoLink}}/commit/{{.Commit.ID.String}}">{{ShortSha .Commit.ID.String}}</a> · <span class="commit-message">{{RenderCommitMessage .Commit.CommitMessage $.RepoLink $.Repository.ComposeMetas}}</span> · {{$.i18n.Tr "org.repo_updated"}} {{TimeSince .Commit.Committer.When $.i18n.Lang}}</p>
 									{{end}}
 									</td>
 									<td class="ui">