From c05a8abc762f868e67dd131d34f45218a0fb95ab Mon Sep 17 00:00:00 2001 From: zeripath Date: Sun, 8 Nov 2020 17:21:54 +0000 Subject: Multiple GitGraph improvements: Exclude PR heads, Add branch/PR links, Show only certain branches, (#12766) * Multiple GitGraph improvements. Add backend support for excluding PRs, selecting branches and files. Fix #10327 Signed-off-by: Andrew Thornton * as per @silverwind Signed-off-by: Andrew Thornton * as per @silverwind Signed-off-by: Andrew Thornton * Only show refs in dropdown we display on the graph Signed-off-by: Andrew Thornton * as per @silverwind Signed-off-by: Andrew Thornton * use flexbox for ui header Signed-off-by: Andrew Thornton * Move Hide Pull Request button to the dropdown Signed-off-by: Andrew Thornton * Add SHA and user pictures Signed-off-by: Andrew Thornton * fix test Signed-off-by: Andrew Thornton * fix test 2 Signed-off-by: Andrew Thornton * fixes * async * more tweaks * use tabs in tmpl Signed-off-by: Andrew Thornton * remove commented thing Signed-off-by: Andrew Thornton * fix linting Signed-off-by: Andrew Thornton * Update web_src/js/features/gitgraph.js Co-authored-by: silverwind * graph tweaks * more tweaks * add title Signed-off-by: Andrew Thornton * fix loading indicator z-index and position Co-authored-by: silverwind Co-authored-by: techknowlogick Co-authored-by: Lauris BH --- modules/git/ref.go | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'modules/git/ref.go') diff --git a/modules/git/ref.go b/modules/git/ref.go index 67b56ac999..2a2798b18f 100644 --- a/modules/git/ref.go +++ b/modules/git/ref.go @@ -4,6 +4,8 @@ package git +import "strings" + // Reference represents a Git ref. type Reference struct { Name string @@ -16,3 +18,44 @@ type Reference struct { func (ref *Reference) Commit() (*Commit, error) { return ref.repo.getCommit(ref.Object) } + +// ShortName returns the short name of the reference +func (ref *Reference) ShortName() string { + if ref == nil { + return "" + } + if strings.HasPrefix(ref.Name, "refs/heads/") { + return ref.Name[11:] + } + if strings.HasPrefix(ref.Name, "refs/tags/") { + return ref.Name[10:] + } + if strings.HasPrefix(ref.Name, "refs/remotes/") { + return ref.Name[13:] + } + if strings.HasPrefix(ref.Name, "refs/pull/") && strings.IndexByte(ref.Name[10:], '/') > -1 { + return ref.Name[10 : strings.IndexByte(ref.Name[10:], '/')+10] + } + + return ref.Name +} + +// RefGroup returns the group type of the reference +func (ref *Reference) RefGroup() string { + if ref == nil { + return "" + } + if strings.HasPrefix(ref.Name, "refs/heads/") { + return "heads" + } + if strings.HasPrefix(ref.Name, "refs/tags/") { + return "tags" + } + if strings.HasPrefix(ref.Name, "refs/remotes/") { + return "remotes" + } + if strings.HasPrefix(ref.Name, "refs/pull/") && strings.IndexByte(ref.Name[10:], '/') > -1 { + return "pull" + } + return "" +} -- cgit v1.2.3