Skip to content

Commit 0969a39

Browse files
committed
Implement suggestions by @wxiaoguang
1 parent c9eba48 commit 0969a39

File tree

5 files changed

+39
-18
lines changed

5 files changed

+39
-18
lines changed

modules/git/repo_ref.go

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ package git
66
import (
77
"context"
88
"strings"
9+
10+
"code.gitea.io/gitea/modules/util"
911
)
1012

1113
// GetRefs returns all references of the repository.
@@ -16,18 +18,41 @@ func (repo *Repository) GetRefs() ([]*Reference, error) {
1618
// ListOccurrences lists all refs of the given refType the given commit appears in sorted by creation date DESC
1719
// refType should only be a literal "branch" or "tag" and nothing else
1820
func (repo *Repository) ListOccurrences(ctx context.Context, refType, commitSHA string) ([]string, error) {
21+
if refType != "branch" && refType != "tag" {
22+
return nil, util.NewInvalidArgumentErrorf("Can only use branch or 'tag' as 'refType'. Got '%s'", refType)
23+
}
1924
stdout, _, err := NewCommand(ctx, ToTrustedCmdArgs([]string{refType, "--no-color", "--sort=-creatordate", "--contains"})...).AddDynamicArguments(commitSHA).RunStdString(&RunOpts{Dir: repo.Path})
25+
if err != nil {
26+
return nil, err
27+
}
2028

2129
refs := strings.Split(strings.TrimSpace(stdout), "\n")
30+
if refType == "branch" {
31+
return parseBranches(refs), nil
32+
}
33+
return parseTags(refs), nil
34+
}
35+
36+
func parseBranches(refs []string) []string {
2237
results := make([]string, 0, len(refs))
2338
for _, ref := range refs {
24-
if strings.HasPrefix(ref, "* ") { // main branch
39+
if strings.HasPrefix(ref, "* ") { // current branch (main branch)
2540
results = append(results, ref[len("* "):])
2641
} else if strings.HasPrefix(ref, " ") { // all other branches
2742
results = append(results, ref[len(" "):])
28-
} else if ref != "" { // tags
43+
} else if ref != "" {
44+
results = append(results, ref)
45+
}
46+
}
47+
return results
48+
}
49+
50+
func parseTags(refs []string) []string {
51+
results := make([]string, 0, len(refs))
52+
for _, ref := range refs {
53+
if ref != "" {
2954
results = append(results, ref)
3055
}
3156
}
32-
return results, err
57+
return results
3358
}

services/repository/commit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type ContainedLinks struct { // TODO: better name?
2020

2121
type namedLink struct { // TODO: better name?
2222
Name string `json:"name"`
23-
WebLink string `json:"web_url"`
23+
WebLink string `json:"web_link"`
2424
}
2525

2626
// CreateNewBranch creates a new repository branch

templates/repo/commit_load_branches_and_tags.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
<div class="branch-tag-area-text gt-df"></div>
55
<div class="branch-area-parent gt-df gt-ac gt-my-3 gt-gap-2 gt-hidden">
66
{{svg "octicon-git-branch" 16 "gt-min-w-16"}}
7-
<div class="branch-area gt-df gt-ac gt-flex-wrap gt-hidden" data-defaultbranch-tooltip="{{.locale.Tr "repo.commit.contained_in_default_branch"}}"></div>
7+
<div class="branch-area gt-df gt-ac gt-fw gt-hidden" data-defaultbranch-tooltip="{{.locale.Tr "repo.commit.contained_in_default_branch"}}"></div>
88
</div>
99
<div class="tag-area-parent gt-df gt-ac gt-my-3 gt-gap-2 gt-hidden">
1010
{{svg "octicon-tag" 16 "gt-min-w-16"}}
11-
<div class="tag-area gt-df gt-ac gt-flex-wrap gt-hidden"></div>
11+
<div class="tag-area gt-df gt-ac gt-fw gt-hidden"></div>
1212
</div>
1313
</div>

web_src/css/helpers.css

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,12 @@ Gitea's private styles use `g-` prefix.
7777
.gt-overflow-x-auto { overflow-x: auto !important; }
7878
.gt-overflow-x-scroll { overflow-x: scroll !important; }
7979
.gt-overflow-y-hidden { overflow-y: hidden !important; }
80-
.gt-flex-wrap { flex-wrap: wrap !important; }
8180

8281
.gt-w-screen { width: 100vw !important; }
8382
.gt-h-screen { height: 100vh !important; }
8483

8584
.gt-min-w-0 { min-width: 0 !important; }
86-
.gt-min-w-16 { min-width: 16px !important; } /*There are some weird bugs with flexboxes and SVGs*/
85+
.gt-min-w-16 { min-width: 16px !important; } /*There are some weird bugs with flexboxes and SVGs where the svgs shrink into oblivion*/
8786

8887
.gt-float-left { float: left !important; }
8988
.gt-float-right { float: right !important; }

web_src/js/features/load-branches-and-tags.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
const {csrfToken} = window.config;
1+
import {showElem} from '../utils/dom.js';
22

33
async function loadBranchesAndTags(loadingButton, addHere) {
4-
loadingButton.setAttribute('disabled', 'disabled');
4+
loadingButton.classList.add('disabled')
55
let res;
66
try {
7-
res = await fetch(loadingButton.getAttribute('data-fetch-url'), {
8-
method: 'GET',
9-
headers: {'X-Csrf-Token': csrfToken},
10-
});
7+
res = await fetch(loadingButton.getAttribute('data-fetch-url'), { method: 'GET', });
118
} finally {
12-
loadingButton.removeAttribute('disabled');
9+
loadingButton.classList.remove('disabled')
1310
}
1411

1512
if (!res.ok) {
@@ -28,19 +25,19 @@ async function loadBranchesAndTags(loadingButton, addHere) {
2825
function addTags(tags, addHere) {
2926
if (tags.length > 0) showAreas('.tag-area,.tag-area-parent');
3027
for (const tag of tags) {
31-
addLink(tag.web_url, tag.name, addHere);
28+
addLink(tag.web_link, tag.name, addHere);
3229
}
3330
}
3431

3532
function addBranches(branches, defaultBranch, defaultBranchTooltip, addHere) {
3633
if (branches.length > 0) showAreas('.branch-area,.branch-area-parent');
3734
for (const branch of branches) {
38-
addLink(branch.web_url, branch.name, addHere, defaultBranch === branch.name ? defaultBranchTooltip : undefined);
35+
addLink(branch.web_link, branch.name, addHere, defaultBranch === branch.name ? defaultBranchTooltip : undefined);
3936
}
4037
}
4138

4239
function showAreas(selector) {
43-
for (const branchArea of document.querySelectorAll(selector)) branchArea.classList.remove('gt-hidden');
40+
for (const branchArea of document.querySelectorAll(selector)) showElem(branchArea);
4441
}
4542

4643
function addLink(href, text, addHere, tooltip) {

0 commit comments

Comments
 (0)