From 60cc93ef85ec2abdc7aa1fbd3013716ae7281c1a Mon Sep 17 00:00:00 2001 From: delvh Date: Tue, 6 Jun 2023 10:26:57 +0200 Subject: [PATCH 01/33] Add barebones frontend structure --- options/locale/locale_en-US.ini | 1 + templates/repo/view_file.tmpl | 4 +++ web_src/js/features/load-branches-and-tags.js | 36 +++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 web_src/js/features/load-branches-and-tags.js diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 195252c47d176..76945a5bc37d4 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1147,6 +1147,7 @@ ambiguous_character = `%[1]c [U+%04[1]X] can be confused with %[2]c [U+%04[2]X]` escape_control_characters = Escape unescape_control_characters = Unescape file_copy_permalink = Copy Permalink +file.load_referencing_branches_and_tags = Load branches and tags referencing this file view_git_blame = View Git Blame video_not_supported_in_browser = Your browser does not support the HTML5 'video' tag. audio_not_supported_in_browser = Your browser does not support the HTML5 'audio' tag. diff --git a/templates/repo/view_file.tmpl b/templates/repo/view_file.tmpl index 389aa2f4f2013..08db63b93cea7 100644 --- a/templates/repo/view_file.tmpl +++ b/templates/repo/view_file.tmpl @@ -61,6 +61,10 @@ {{end}} + +
diff --git a/web_src/js/features/load-branches-and-tags.js b/web_src/js/features/load-branches-and-tags.js new file mode 100644 index 0000000000000..fd872c99f9dc6 --- /dev/null +++ b/web_src/js/features/load-branches-and-tags.js @@ -0,0 +1,36 @@ +const {csrfToken} = window.config; + +function loadBranchesAndTags(loadingButton, addHere) { + loadingButton.setAttribute('disabled', 'disabled'); + const response = await fetch(loadingButton.getAttribute('data-fetch-url'), { + method: 'GET', + headers: {'X-Csrf-Token': csrfToken}, + body: JSON.stringify(data), + }).finally(() => loadingButton.removeAttribute('disabled')); + + const data = await response.json(); + addTags(data.tags, addHere); + addBranches(data.branches, addHere); +} + +function addTags(tags, addHere) { + for(const tag of tags) + addLink(tag.link, addHere); +} + +function addTags(tags, addHere) { + for(const branch of branches) + addLink(branch.link, branch.name, addHere); +} + +function addLink(href, text, parent) { + const link = document.createElement('a'); + link.href=href; + link.text=text; + parent.appendChild(link); +} + +export function initLoadBranchesAndTagsButton() { + for(const loadButton of document.querySelector('.load-tags-and-branches-button')) + loadButton.addEventListener('click', (e) => loadBranchesAndTags(e.target, )); +} From 1975e643f0c8be9a19f1525fe9ee8ef38e0e5e61 Mon Sep 17 00:00:00 2001 From: delvh Date: Fri, 9 Jun 2023 15:28:42 +0200 Subject: [PATCH 02/33] Add complete backend for loading tags and branches of a commit --- modules/git/repo_ref.go | 12 +++++ routers/web/repo/commit.go | 12 +++++ routers/web/web.go | 1 + services/repository/commit.go | 44 +++++++++++++++++++ templates/repo/commit_page.tmpl | 4 ++ templates/repo/view_file.tmpl | 4 -- web_src/js/features/load-branches-and-tags.js | 13 +++--- web_src/js/index.js | 3 ++ 8 files changed, 82 insertions(+), 11 deletions(-) create mode 100644 services/repository/commit.go diff --git a/modules/git/repo_ref.go b/modules/git/repo_ref.go index 54e424bb832ab..c036deb6b4f45 100644 --- a/modules/git/repo_ref.go +++ b/modules/git/repo_ref.go @@ -3,7 +3,19 @@ package git +import ( + "context" + "strings" +) + // GetRefs returns all references of the repository. func (repo *Repository) GetRefs() ([]*Reference, error) { return repo.GetRefsFiltered("") } + +// ListOccurrences lists all refs of the given refType the given commit appears in +// refType should only be a literal "branch" or "tag" and nothing else +func (repo *Repository) ListOccurrences(ctx context.Context, refType string, commitSHA string) ([]string, error) { + stdout, _, err := NewCommand(ctx, ToTrustedCmdArgs([]string{refType, "--contains"})...).AddDynamicArguments(commitSHA).RunStdString(&RunOpts{Dir: repo.Path}) + return strings.Split(stdout, "\n"), err +} diff --git a/routers/web/repo/commit.go b/routers/web/repo/commit.go index e88f1139f8b7e..a76db52cf52a9 100644 --- a/routers/web/repo/commit.go +++ b/routers/web/repo/commit.go @@ -22,7 +22,9 @@ import ( "code.gitea.io/gitea/modules/gitgraph" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" + "code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/services/gitdiff" + git_service "code.gitea.io/gitea/services/repository" ) const ( @@ -255,6 +257,16 @@ func FileHistory(ctx *context.Context) { ctx.HTML(http.StatusOK, tplCommits) } +func LoadBranchesAndTags(ctx *context.Context) { + fmt.Println("Hello from mfuntrion") + response, err := git_service.LoadBranchesAndTags(ctx, ctx.Repo, ctx.Params("sha")) + if err == nil { + ctx.JSON(http.StatusOK, response) + return + } + ctx.NotFoundOrServerError(fmt.Sprintf("could not load branches and tags the commit %s belongs to", ctx.Params("sha")), func(err error) bool { return errors.Is(err, util.ErrNotExist) }, err) +} + // Diff show different from current commit to previous commit func Diff(ctx *context.Context) { ctx.Data["PageIsDiff"] = true diff --git a/routers/web/web.go b/routers/web/web.go index f5037a848ea59..ab7710e9897f4 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -1323,6 +1323,7 @@ func registerRoutes(m *web.Route) { m.Group("", func() { m.Get("/graph", repo.Graph) m.Get("/commit/{sha:([a-f0-9]{7,40})$}", repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.Diff) + m.Get("/commit/{sha:([a-f0-9]{7,40})$}/load-branches-and-tags", repo.LoadBranchesAndTags) m.Get("/cherry-pick/{sha:([a-f0-9]{7,40})$}", repo.SetEditorconfigIfExists, repo.CherryPick) }, repo.MustBeNotEmpty, context.RepoRef(), reqRepoCodeReader) diff --git a/services/repository/commit.go b/services/repository/commit.go new file mode 100644 index 0000000000000..bbb78e0fc119a --- /dev/null +++ b/services/repository/commit.go @@ -0,0 +1,44 @@ +// Copyright 2023 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package repository + +import ( + "context" + "fmt" + + "code.gitea.io/gitea/modules/util" + gitea_ctx "code.gitea.io/gitea/modules/context" +) + +type containedLinks struct { // TODO: better name? + Branches []*namedLink `json:"branches"` + Tags []*namedLink `json:"tags"` +} + +type namedLink struct { // TODO: better name? + Name string `json:"name"` + WebLink string `json:"web_url"` +} + +// CreateNewBranch creates a new repository branch +func LoadBranchesAndTags(ctx context.Context, baseRepo *gitea_ctx.Repository, commitSHA string) (*containedLinks, error) { + containedTags, err := baseRepo.GitRepo.ListOccurrences(ctx, "tag", commitSHA) + if err != nil { + return nil, fmt.Errorf("encountered a problem while querying %s: %w", "tags", err) + } + containedBranches, err := baseRepo.GitRepo.ListOccurrences(ctx, "branch", commitSHA) + if err != nil { + return nil, fmt.Errorf("encountered a problem while querying %s: %w", "branches", err) + } + + result := &containedLinks{Branches: make([]*namedLink, 0, len(containedBranches)), Tags: make([]*namedLink, 0, len(containedTags))} + for _, tag := range containedTags { + result.Tags = append(result.Tags, &namedLink{Name: tag, WebLink: fmt.Sprintf("%s/src/tag/%s", baseRepo.RepoLink, util.PathEscapeSegments(tag))}) // TODO: Use a common method to get the link to a branch/tag instead of hardcoding it here + } + for _, branch := range containedBranches { + result.Branches = append(result.Branches, &namedLink{Name: branch, WebLink: fmt.Sprintf("%s/src/branch/%s", baseRepo.RepoLink, util.PathEscapeSegments(branch))}) + } + + return result, nil +} diff --git a/templates/repo/commit_page.tmpl b/templates/repo/commit_page.tmpl index 5e26c04fd879c..ec6979008ad14 100644 --- a/templates/repo/commit_page.tmpl +++ b/templates/repo/commit_page.tmpl @@ -142,6 +142,10 @@ {{if .TagName}} {{svg "octicon-tag" 16 "gt-mr-2"}}{{.TagName}} {{end}} + +
diff --git a/templates/repo/view_file.tmpl b/templates/repo/view_file.tmpl index 08db63b93cea7..389aa2f4f2013 100644 --- a/templates/repo/view_file.tmpl +++ b/templates/repo/view_file.tmpl @@ -61,10 +61,6 @@ {{end}} - -
diff --git a/web_src/js/features/load-branches-and-tags.js b/web_src/js/features/load-branches-and-tags.js index fd872c99f9dc6..6ae8ce9e5b7e8 100644 --- a/web_src/js/features/load-branches-and-tags.js +++ b/web_src/js/features/load-branches-and-tags.js @@ -1,11 +1,10 @@ const {csrfToken} = window.config; -function loadBranchesAndTags(loadingButton, addHere) { +async function loadBranchesAndTags(loadingButton, addHere) { loadingButton.setAttribute('disabled', 'disabled'); const response = await fetch(loadingButton.getAttribute('data-fetch-url'), { method: 'GET', headers: {'X-Csrf-Token': csrfToken}, - body: JSON.stringify(data), }).finally(() => loadingButton.removeAttribute('disabled')); const data = await response.json(); @@ -15,12 +14,12 @@ function loadBranchesAndTags(loadingButton, addHere) { function addTags(tags, addHere) { for(const tag of tags) - addLink(tag.link, addHere); + addLink(tag.web_url, addHere); } -function addTags(tags, addHere) { +function addBranches(tags, addHere) { for(const branch of branches) - addLink(branch.link, branch.name, addHere); + addLink(branch.web_url, branch.name, addHere); } function addLink(href, text, parent) { @@ -31,6 +30,6 @@ function addLink(href, text, parent) { } export function initLoadBranchesAndTagsButton() { - for(const loadButton of document.querySelector('.load-tags-and-branches-button')) - loadButton.addEventListener('click', (e) => loadBranchesAndTags(e.target, )); + for(const loadButton of document.querySelectorAll('.load-tags-and-branches')) + loadButton.addEventListener('click', async (e) => loadBranchesAndTags(loadButton, document.querySelector('.branch-and-tag-area'))); } diff --git a/web_src/js/index.js b/web_src/js/index.js index 0c786f96fbef2..e4dcfa9f47398 100644 --- a/web_src/js/index.js +++ b/web_src/js/index.js @@ -83,6 +83,7 @@ import {initGiteaFomantic} from './modules/fomantic.js'; import {onDomReady} from './utils/dom.js'; import {initRepoIssueList} from './features/repo-issue-list.js'; import {initCommonIssueListQuickGoto} from './features/common-issue-list.js'; +import {initLoadBranchesAndTagsButton} from './features/load-branches-and-tags.js' // Init Gitea's Fomantic settings initGiteaFomantic(); @@ -179,4 +180,6 @@ onDomReady(() => { initRepoDiffView(); initPdfViewer(); initScopedAccessTokenCategories(); + + initLoadBranchesAndTagsButton(); }); From 8adb11bcbd3e1ea2f6c2d275d84527bb01e268c5 Mon Sep 17 00:00:00 2001 From: delvh Date: Fri, 9 Jun 2023 19:22:20 +0200 Subject: [PATCH 03/33] Complete the frontend and backend functionality --- modules/git/repo_ref.go | 20 +++++++++--- options/locale/locale_en-US.ini | 2 ++ routers/web/repo/commit.go | 1 - services/repository/commit.go | 15 ++++++--- .../repo/commit_load_branches_and_tags.tmpl | 9 ++++++ templates/repo/commit_page.tmpl | 5 +-- web_src/css/helpers.css | 1 + web_src/js/features/load-branches-and-tags.js | 32 +++++++++++++++---- 8 files changed, 64 insertions(+), 21 deletions(-) create mode 100644 templates/repo/commit_load_branches_and_tags.tmpl diff --git a/modules/git/repo_ref.go b/modules/git/repo_ref.go index c036deb6b4f45..b5a1dfc7f8fe6 100644 --- a/modules/git/repo_ref.go +++ b/modules/git/repo_ref.go @@ -13,9 +13,21 @@ func (repo *Repository) GetRefs() ([]*Reference, error) { return repo.GetRefsFiltered("") } -// ListOccurrences lists all refs of the given refType the given commit appears in +// ListOccurrences lists all refs of the given refType the given commit appears in sorted by creation date DESC // refType should only be a literal "branch" or "tag" and nothing else -func (repo *Repository) ListOccurrences(ctx context.Context, refType string, commitSHA string) ([]string, error) { - stdout, _, err := NewCommand(ctx, ToTrustedCmdArgs([]string{refType, "--contains"})...).AddDynamicArguments(commitSHA).RunStdString(&RunOpts{Dir: repo.Path}) - return strings.Split(stdout, "\n"), err +func (repo *Repository) ListOccurrences(ctx context.Context, refType, commitSHA string) ([]string, error) { + stdout, _, err := NewCommand(ctx, ToTrustedCmdArgs([]string{refType, "--no-color", "--sort=-creatordate", "--contains"})...).AddDynamicArguments(commitSHA).RunStdString(&RunOpts{Dir: repo.Path}) + + refs := strings.Split(strings.TrimSpace(stdout), "\n") + results := make([]string, 0, len(refs)) + for _, ref := range refs { + if strings.HasPrefix(ref, "* ") { // main branch + results = append(results, ref[len("* "):]) + } else if strings.HasPrefix(ref, " ") { // all other branches + results = append(results, ref[len(" "):]) + } else if ref != "" { // tags + results = append(results, ref) + } + } + return results, err } diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 726f793454b5d..c24ca32d3f8bb 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1159,6 +1159,8 @@ commit_graph.select = Select branches commit_graph.hide_pr_refs = Hide Pull Requests commit_graph.monochrome = Mono commit_graph.color = Color +commit.contained_in = This commit is contained in: +commit.contained_in_default_branch = This commit is part of the default branch blame = Blame download_file = Download file normal_view = Normal View diff --git a/routers/web/repo/commit.go b/routers/web/repo/commit.go index a76db52cf52a9..2bcfbac2b490f 100644 --- a/routers/web/repo/commit.go +++ b/routers/web/repo/commit.go @@ -258,7 +258,6 @@ func FileHistory(ctx *context.Context) { } func LoadBranchesAndTags(ctx *context.Context) { - fmt.Println("Hello from mfuntrion") response, err := git_service.LoadBranchesAndTags(ctx, ctx.Repo, ctx.Params("sha")) if err == nil { ctx.JSON(http.StatusOK, response) diff --git a/services/repository/commit.go b/services/repository/commit.go index bbb78e0fc119a..621aeb247c5a8 100644 --- a/services/repository/commit.go +++ b/services/repository/commit.go @@ -7,17 +7,19 @@ import ( "context" "fmt" - "code.gitea.io/gitea/modules/util" gitea_ctx "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/modules/util" ) type containedLinks struct { // TODO: better name? - Branches []*namedLink `json:"branches"` - Tags []*namedLink `json:"tags"` + Branches []*namedLink `json:"branches"` + Tags []*namedLink `json:"tags"` + ContainedInDefaultBranch bool `json:"contained_in_default_branch"` + DefaultBranch string `json:"default_branch"` } type namedLink struct { // TODO: better name? - Name string `json:"name"` + Name string `json:"name"` WebLink string `json:"web_url"` } @@ -32,7 +34,10 @@ func LoadBranchesAndTags(ctx context.Context, baseRepo *gitea_ctx.Repository, co return nil, fmt.Errorf("encountered a problem while querying %s: %w", "branches", err) } - result := &containedLinks{Branches: make([]*namedLink, 0, len(containedBranches)), Tags: make([]*namedLink, 0, len(containedTags))} + result := &containedLinks{ + ContainedInDefaultBranch: util.SliceContains(containedBranches, baseRepo.Repository.DefaultBranch), DefaultBranch: baseRepo.Repository.DefaultBranch, + Branches: make([]*namedLink, 0, len(containedBranches)), Tags: make([]*namedLink, 0, len(containedTags)), + } for _, tag := range containedTags { result.Tags = append(result.Tags, &namedLink{Name: tag, WebLink: fmt.Sprintf("%s/src/tag/%s", baseRepo.RepoLink, util.PathEscapeSegments(tag))}) // TODO: Use a common method to get the link to a branch/tag instead of hardcoding it here } diff --git a/templates/repo/commit_load_branches_and_tags.tmpl b/templates/repo/commit_load_branches_and_tags.tmpl new file mode 100644 index 0000000000000..887d29c56f9f7 --- /dev/null +++ b/templates/repo/commit_load_branches_and_tags.tmpl @@ -0,0 +1,9 @@ +
+ +
+
+
{{svg "octicon-git-branch"}}
+
{{svg "octicon-tag"}}
+
diff --git a/templates/repo/commit_page.tmpl b/templates/repo/commit_page.tmpl index ec6979008ad14..7006451fcbb43 100644 --- a/templates/repo/commit_page.tmpl +++ b/templates/repo/commit_page.tmpl @@ -142,10 +142,7 @@ {{if .TagName}} {{svg "octicon-tag" 16 "gt-mr-2"}}{{.TagName}} {{end}} - -
+ {{template "repo/commit_load_branches_and_tags" .}}
diff --git a/web_src/css/helpers.css b/web_src/css/helpers.css index eb0cf020689ac..2c17f11aaa7b7 100644 --- a/web_src/css/helpers.css +++ b/web_src/css/helpers.css @@ -80,6 +80,7 @@ Gitea's private styles use `g-` prefix. .gt-overflow-x-auto { overflow-x: auto !important; } .gt-overflow-x-scroll { overflow-x: scroll !important; } .gt-overflow-y-hidden { overflow-y: hidden !important; } +.gt-flex-wrap { flex-wrap: wrap !important; } .gt-w-screen { width: 100vw !important; } .gt-h-screen { height: 100vh !important; } diff --git a/web_src/js/features/load-branches-and-tags.js b/web_src/js/features/load-branches-and-tags.js index 6ae8ce9e5b7e8..0f1f0f399f433 100644 --- a/web_src/js/features/load-branches-and-tags.js +++ b/web_src/js/features/load-branches-and-tags.js @@ -8,25 +8,43 @@ async function loadBranchesAndTags(loadingButton, addHere) { }).finally(() => loadingButton.removeAttribute('disabled')); const data = await response.json(); - addTags(data.tags, addHere); - addBranches(data.branches, addHere); + showAreas('.branch-tag-area-divider'); + loadingButton.classList.add('gt-hidden'); + addHere.querySelector('.branch-tag-area-text').textContent = loadingButton.getAttribute('data-contained-in-text'); + addTags(data.tags, addHere.querySelector('.tag-area')); + const branchArea = addHere.querySelector('.branch-area'); + addBranches(data.branches, data.default_branch, branchArea.getAttribute('data-defaultbranch-tooltip'), branchArea); } function addTags(tags, addHere) { + showAreas('.tag-area'); for(const tag of tags) - addLink(tag.web_url, addHere); + addLink(tag.web_url, tag.name, addHere); } -function addBranches(tags, addHere) { +function addBranches(branches, defaultBranch, defaultBranchTooltip, addHere) { + showAreas('.branch-area'); for(const branch of branches) - addLink(branch.web_url, branch.name, addHere); + addLink(branch.web_url, branch.name, addHere, defaultBranch === branch.name ? defaultBranchTooltip : undefined); } -function addLink(href, text, parent) { +function showAreas(selector) { + for(const branchArea of document.querySelectorAll(selector)) + branchArea.classList.remove('gt-hidden'); +} + +function addLink(href, text, addHere, tooltip) { const link = document.createElement('a'); + link.classList.add('muted'); + link.classList.add('gt-px-3'); + if(tooltip) { + link.classList.add('gt-border-secondary'); + link.classList.add('gt-rounded'); + link.setAttribute('data-tooltip-content', tooltip); + } link.href=href; link.text=text; - parent.appendChild(link); + addHere.appendChild(link); } export function initLoadBranchesAndTagsButton() { From be8cd4eea4414448d60c5210f8ea2cec26d8a128 Mon Sep 17 00:00:00 2001 From: delvh Date: Fri, 9 Jun 2023 19:34:26 +0200 Subject: [PATCH 04/33] Make all borders rounded, increase margin between tags and commits --- templates/repo/commit_load_branches_and_tags.tmpl | 2 +- web_src/js/features/load-branches-and-tags.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/repo/commit_load_branches_and_tags.tmpl b/templates/repo/commit_load_branches_and_tags.tmpl index 887d29c56f9f7..9923c86b47763 100644 --- a/templates/repo/commit_load_branches_and_tags.tmpl +++ b/templates/repo/commit_load_branches_and_tags.tmpl @@ -4,6 +4,6 @@
-
{{svg "octicon-git-branch"}}
+
{{svg "octicon-git-branch"}}
{{svg "octicon-tag"}}
diff --git a/web_src/js/features/load-branches-and-tags.js b/web_src/js/features/load-branches-and-tags.js index 0f1f0f399f433..d1aae96080757 100644 --- a/web_src/js/features/load-branches-and-tags.js +++ b/web_src/js/features/load-branches-and-tags.js @@ -37,9 +37,9 @@ function addLink(href, text, addHere, tooltip) { const link = document.createElement('a'); link.classList.add('muted'); link.classList.add('gt-px-3'); + link.classList.add('gt-rounded'); if(tooltip) { link.classList.add('gt-border-secondary'); - link.classList.add('gt-rounded'); link.setAttribute('data-tooltip-content', tooltip); } link.href=href; From b311b53ab3f7a78d3c7605d5f2d9781f6eb87fdb Mon Sep 17 00:00:00 2001 From: delvh Date: Fri, 9 Jun 2023 19:39:30 +0200 Subject: [PATCH 05/33] Remove dead code --- modules/git/commit.go | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/modules/git/commit.go b/modules/git/commit.go index ff654f394d221..047bf446136f3 100644 --- a/modules/git/commit.go +++ b/modules/git/commit.go @@ -20,7 +20,6 @@ import ( // Commit represents a git commit. type Commit struct { - Branch string // Branch this commit belongs to Tree ID SHA1 // The ID of this commit object Author *Signature @@ -432,16 +431,6 @@ func (c *Commit) GetBranchName() (string, error) { return strings.SplitN(strings.TrimSpace(data), "~", 2)[0], nil } -// LoadBranchName load branch name for commit -func (c *Commit) LoadBranchName() (err error) { - if len(c.Branch) != 0 { - return - } - - c.Branch, err = c.GetBranchName() - return err -} - // GetTagName gets the current tag name for given commit func (c *Commit) GetTagName() (string, error) { data, _, err := NewCommand(c.repo.Ctx, "describe", "--exact-match", "--tags", "--always").AddDynamicArguments(c.ID.String()).RunStdString(&RunOpts{Dir: c.repo.Path}) From 0b39f9e6b9c4506f6ba998f185eb3441c9bd1f6a Mon Sep 17 00:00:00 2001 From: delvh Date: Fri, 9 Jun 2023 20:04:10 +0200 Subject: [PATCH 06/33] Move translation key and print error on browser console --- options/locale/locale_en-US.ini | 2 +- templates/repo/commit_load_branches_and_tags.tmpl | 2 +- web_src/js/features/load-branches-and-tags.js | 5 +++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index c24ca32d3f8bb..b238f1d2783c4 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1148,7 +1148,6 @@ ambiguous_character = `%[1]c [U+%04[1]X] can be confused with %[2]c [U+%04[2]X]` escape_control_characters = Escape unescape_control_characters = Unescape file_copy_permalink = Copy Permalink -file.load_referencing_branches_and_tags = Load branches and tags referencing this file view_git_blame = View Git Blame video_not_supported_in_browser = Your browser does not support the HTML5 'video' tag. audio_not_supported_in_browser = Your browser does not support the HTML5 'audio' tag. @@ -1161,6 +1160,7 @@ commit_graph.monochrome = Mono commit_graph.color = Color commit.contained_in = This commit is contained in: commit.contained_in_default_branch = This commit is part of the default branch +commit.load_referencing_branches_and_tags = Load branches and tags referencing this file blame = Blame download_file = Download file normal_view = Normal View diff --git a/templates/repo/commit_load_branches_and_tags.tmpl b/templates/repo/commit_load_branches_and_tags.tmpl index 9923c86b47763..53e3af3588940 100644 --- a/templates/repo/commit_load_branches_and_tags.tmpl +++ b/templates/repo/commit_load_branches_and_tags.tmpl @@ -1,5 +1,5 @@
-
diff --git a/web_src/js/features/load-branches-and-tags.js b/web_src/js/features/load-branches-and-tags.js index d1aae96080757..9a2be0969804c 100644 --- a/web_src/js/features/load-branches-and-tags.js +++ b/web_src/js/features/load-branches-and-tags.js @@ -7,6 +7,11 @@ async function loadBranchesAndTags(loadingButton, addHere) { headers: {'X-Csrf-Token': csrfToken}, }).finally(() => loadingButton.removeAttribute('disabled')); + if(!response.ok) { + console.log('Could not retrieve branches and tags for ' + response); + return; + } + const data = await response.json(); showAreas('.branch-tag-area-divider'); loadingButton.classList.add('gt-hidden'); From a433b565216e0493baac177c3c0ca3b038f5e89f Mon Sep 17 00:00:00 2001 From: delvh Date: Fri, 9 Jun 2023 20:29:26 +0200 Subject: [PATCH 07/33] Apparently, I don't like our too strict linter --- services/repository/commit.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/services/repository/commit.go b/services/repository/commit.go index 621aeb247c5a8..89cf012c9e42b 100644 --- a/services/repository/commit.go +++ b/services/repository/commit.go @@ -11,7 +11,7 @@ import ( "code.gitea.io/gitea/modules/util" ) -type containedLinks struct { // TODO: better name? +type ContainedLinks struct { // TODO: better name? Branches []*namedLink `json:"branches"` Tags []*namedLink `json:"tags"` ContainedInDefaultBranch bool `json:"contained_in_default_branch"` @@ -24,7 +24,7 @@ type namedLink struct { // TODO: better name? } // CreateNewBranch creates a new repository branch -func LoadBranchesAndTags(ctx context.Context, baseRepo *gitea_ctx.Repository, commitSHA string) (*containedLinks, error) { +func LoadBranchesAndTags(ctx context.Context, baseRepo *gitea_ctx.Repository, commitSHA string) (*ContainedLinks, error) { containedTags, err := baseRepo.GitRepo.ListOccurrences(ctx, "tag", commitSHA) if err != nil { return nil, fmt.Errorf("encountered a problem while querying %s: %w", "tags", err) @@ -34,7 +34,7 @@ func LoadBranchesAndTags(ctx context.Context, baseRepo *gitea_ctx.Repository, co return nil, fmt.Errorf("encountered a problem while querying %s: %w", "branches", err) } - result := &containedLinks{ + result := &ContainedLinks{ ContainedInDefaultBranch: util.SliceContains(containedBranches, baseRepo.Repository.DefaultBranch), DefaultBranch: baseRepo.Repository.DefaultBranch, Branches: make([]*namedLink, 0, len(containedBranches)), Tags: make([]*namedLink, 0, len(containedTags)), } From 73f31f84a2e827ae053eed1d41030b42fdbe301b Mon Sep 17 00:00:00 2001 From: delvh Date: Fri, 9 Jun 2023 20:34:32 +0200 Subject: [PATCH 08/33] Hopefully, please linter this time --- web_src/js/features/load-branches-and-tags.js | 26 ++++++++----------- web_src/js/index.js | 2 +- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/web_src/js/features/load-branches-and-tags.js b/web_src/js/features/load-branches-and-tags.js index 9a2be0969804c..f21bb759065d6 100644 --- a/web_src/js/features/load-branches-and-tags.js +++ b/web_src/js/features/load-branches-and-tags.js @@ -7,12 +7,12 @@ async function loadBranchesAndTags(loadingButton, addHere) { headers: {'X-Csrf-Token': csrfToken}, }).finally(() => loadingButton.removeAttribute('disabled')); - if(!response.ok) { - console.log('Could not retrieve branches and tags for ' + response); + if (!response.ok) { + console.log(`Could not retrieve branches and tags for ${response}`); return; } - const data = await response.json(); + const data = await response.json(); showAreas('.branch-tag-area-divider'); loadingButton.classList.add('gt-hidden'); addHere.querySelector('.branch-tag-area-text').textContent = loadingButton.getAttribute('data-contained-in-text'); @@ -23,19 +23,16 @@ async function loadBranchesAndTags(loadingButton, addHere) { function addTags(tags, addHere) { showAreas('.tag-area'); - for(const tag of tags) - addLink(tag.web_url, tag.name, addHere); + for (const tag of tags) addLink(tag.web_url, tag.name, addHere); } function addBranches(branches, defaultBranch, defaultBranchTooltip, addHere) { showAreas('.branch-area'); - for(const branch of branches) - addLink(branch.web_url, branch.name, addHere, defaultBranch === branch.name ? defaultBranchTooltip : undefined); + for (const branch of branches) addLink(branch.web_url, branch.name, addHere, defaultBranch === branch.name ? defaultBranchTooltip : undefined); } function showAreas(selector) { - for(const branchArea of document.querySelectorAll(selector)) - branchArea.classList.remove('gt-hidden'); + for (const branchArea of document.querySelectorAll(selector)) branchArea.classList.remove('gt-hidden'); } function addLink(href, text, addHere, tooltip) { @@ -43,16 +40,15 @@ function addLink(href, text, addHere, tooltip) { link.classList.add('muted'); link.classList.add('gt-px-3'); link.classList.add('gt-rounded'); - if(tooltip) { + if (tooltip) { link.classList.add('gt-border-secondary'); link.setAttribute('data-tooltip-content', tooltip); } - link.href=href; - link.text=text; - addHere.appendChild(link); + link.href = href; + link.text = text; + addHere.append(link); } export function initLoadBranchesAndTagsButton() { - for(const loadButton of document.querySelectorAll('.load-tags-and-branches')) - loadButton.addEventListener('click', async (e) => loadBranchesAndTags(loadButton, document.querySelector('.branch-and-tag-area'))); + for (const loadButton of document.querySelectorAll('.load-tags-and-branches')) loadButton.addEventListener('click', async (e) => loadBranchesAndTags(loadButton, document.querySelector('.branch-and-tag-area'))); } diff --git a/web_src/js/index.js b/web_src/js/index.js index e4dcfa9f47398..98b2de68a853d 100644 --- a/web_src/js/index.js +++ b/web_src/js/index.js @@ -83,7 +83,7 @@ import {initGiteaFomantic} from './modules/fomantic.js'; import {onDomReady} from './utils/dom.js'; import {initRepoIssueList} from './features/repo-issue-list.js'; import {initCommonIssueListQuickGoto} from './features/common-issue-list.js'; -import {initLoadBranchesAndTagsButton} from './features/load-branches-and-tags.js' +import {initLoadBranchesAndTagsButton} from './features/load-branches-and-tags.js'; // Init Gitea's Fomantic settings initGiteaFomantic(); From 9599991561fe006fdb0f5d4c29173c3c4e7e732e Mon Sep 17 00:00:00 2001 From: delvh Date: Fri, 9 Jun 2023 20:44:17 +0200 Subject: [PATCH 09/33] Linter: 3, delvh: 0 --- web_src/js/features/load-branches-and-tags.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web_src/js/features/load-branches-and-tags.js b/web_src/js/features/load-branches-and-tags.js index f21bb759065d6..ca60e657f52de 100644 --- a/web_src/js/features/load-branches-and-tags.js +++ b/web_src/js/features/load-branches-and-tags.js @@ -50,5 +50,5 @@ function addLink(href, text, addHere, tooltip) { } export function initLoadBranchesAndTagsButton() { - for (const loadButton of document.querySelectorAll('.load-tags-and-branches')) loadButton.addEventListener('click', async (e) => loadBranchesAndTags(loadButton, document.querySelector('.branch-and-tag-area'))); + for (const loadButton of document.querySelectorAll('.load-tags-and-branches')) loadButton.addEventListener('click', async () => loadBranchesAndTags(loadButton, document.querySelector('.branch-and-tag-area'))); } From 83b9251db0c9bfc6acfda371b049f387d471f5c3 Mon Sep 17 00:00:00 2001 From: delvh Date: Fri, 9 Jun 2023 21:36:46 +0200 Subject: [PATCH 10/33] Use a better icon for the button as per @silverwind --- templates/repo/commit_load_branches_and_tags.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/repo/commit_load_branches_and_tags.tmpl b/templates/repo/commit_load_branches_and_tags.tmpl index 53e3af3588940..d6d86185f5d10 100644 --- a/templates/repo/commit_load_branches_and_tags.tmpl +++ b/templates/repo/commit_load_branches_and_tags.tmpl @@ -1,6 +1,6 @@
From ef53879f7b58e18456a7209255ee394f5636f5b1 Mon Sep 17 00:00:00 2001 From: delvh Date: Fri, 9 Jun 2023 21:55:22 +0200 Subject: [PATCH 11/33] Linter: 4, delvh: 0 --- web_src/js/features/load-branches-and-tags.js | 1 - 1 file changed, 1 deletion(-) diff --git a/web_src/js/features/load-branches-and-tags.js b/web_src/js/features/load-branches-and-tags.js index ca60e657f52de..7141a632505f6 100644 --- a/web_src/js/features/load-branches-and-tags.js +++ b/web_src/js/features/load-branches-and-tags.js @@ -8,7 +8,6 @@ async function loadBranchesAndTags(loadingButton, addHere) { }).finally(() => loadingButton.removeAttribute('disabled')); if (!response.ok) { - console.log(`Could not retrieve branches and tags for ${response}`); return; } From c87b3610ae3ef574d82ce11d6d3a18dedc98cec2 Mon Sep 17 00:00:00 2001 From: delvh Date: Tue, 13 Jun 2023 22:34:49 +0200 Subject: [PATCH 12/33] Align branches/tags on their respective icon as per @silverwind + @KN4CK3R --- templates/repo/commit_load_branches_and_tags.tmpl | 10 ++++++++-- web_src/css/helpers.css | 3 +++ web_src/js/features/load-branches-and-tags.js | 4 ++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/templates/repo/commit_load_branches_and_tags.tmpl b/templates/repo/commit_load_branches_and_tags.tmpl index d6d86185f5d10..32a2244a3f417 100644 --- a/templates/repo/commit_load_branches_and_tags.tmpl +++ b/templates/repo/commit_load_branches_and_tags.tmpl @@ -4,6 +4,12 @@
-
{{svg "octicon-git-branch"}}
-
{{svg "octicon-tag"}}
+
+ {{svg "octicon-git-branch" 16 "gt-min-w-16"}} +
+
+
+ {{svg "octicon-tag" 16 "gt-min-w-16"}} +
+
diff --git a/web_src/css/helpers.css b/web_src/css/helpers.css index 2c17f11aaa7b7..23e1b70c9c02f 100644 --- a/web_src/css/helpers.css +++ b/web_src/css/helpers.css @@ -85,6 +85,9 @@ Gitea's private styles use `g-` prefix. .gt-w-screen { width: 100vw !important; } .gt-h-screen { height: 100vh !important; } +.gt-min-w-0 { min-width: 0px !important; } +.gt-min-w-16 { min-width: 16px !important; } /*There are some weird bugs with flexboxes and SVGs*/ + .gt-float-left { float: left !important; } .gt-float-right { float: right !important; } diff --git a/web_src/js/features/load-branches-and-tags.js b/web_src/js/features/load-branches-and-tags.js index 7141a632505f6..b48e747143826 100644 --- a/web_src/js/features/load-branches-and-tags.js +++ b/web_src/js/features/load-branches-and-tags.js @@ -21,12 +21,12 @@ async function loadBranchesAndTags(loadingButton, addHere) { } function addTags(tags, addHere) { - showAreas('.tag-area'); + showAreas('.tag-area,.tag-area-parent'); for (const tag of tags) addLink(tag.web_url, tag.name, addHere); } function addBranches(branches, defaultBranch, defaultBranchTooltip, addHere) { - showAreas('.branch-area'); + showAreas('.branch-area,.branch-area-parent'); for (const branch of branches) addLink(branch.web_url, branch.name, addHere, defaultBranch === branch.name ? defaultBranchTooltip : undefined); } From 796290784124058b66243600c5acc33f1497e614 Mon Sep 17 00:00:00 2001 From: delvh Date: Tue, 13 Jun 2023 22:45:37 +0200 Subject: [PATCH 13/33] I guess that's why the linter fails? --- web_src/css/helpers.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web_src/css/helpers.css b/web_src/css/helpers.css index 23e1b70c9c02f..4b35f760212a0 100644 --- a/web_src/css/helpers.css +++ b/web_src/css/helpers.css @@ -85,7 +85,7 @@ Gitea's private styles use `g-` prefix. .gt-w-screen { width: 100vw !important; } .gt-h-screen { height: 100vh !important; } -.gt-min-w-0 { min-width: 0px !important; } +.gt-min-w-0 { min-width: 0 !important; } .gt-min-w-16 { min-width: 16px !important; } /*There are some weird bugs with flexboxes and SVGs*/ .gt-float-left { float: left !important; } From e1efe083407b9cdfca6e642e0107d9599307758f Mon Sep 17 00:00:00 2001 From: delvh Date: Tue, 13 Jun 2023 22:50:24 +0200 Subject: [PATCH 14/33] Do not show branch/tag icon when this commit is not contained anywhere --- web_src/js/features/load-branches-and-tags.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web_src/js/features/load-branches-and-tags.js b/web_src/js/features/load-branches-and-tags.js index b48e747143826..2ab82cbc43a8e 100644 --- a/web_src/js/features/load-branches-and-tags.js +++ b/web_src/js/features/load-branches-and-tags.js @@ -21,12 +21,12 @@ async function loadBranchesAndTags(loadingButton, addHere) { } function addTags(tags, addHere) { - showAreas('.tag-area,.tag-area-parent'); + if (tags.length > 0) showAreas('.tag-area,.tag-area-parent'); for (const tag of tags) addLink(tag.web_url, tag.name, addHere); } function addBranches(branches, defaultBranch, defaultBranchTooltip, addHere) { - showAreas('.branch-area,.branch-area-parent'); + if (branches.length > 0) showAreas('.branch-area,.branch-area-parent'); for (const branch of branches) addLink(branch.web_url, branch.name, addHere, defaultBranch === branch.name ? defaultBranchTooltip : undefined); } From 2b55713f1b09f261369052e81c081cd5de51c712 Mon Sep 17 00:00:00 2001 From: delvh Date: Tue, 13 Jun 2023 22:58:51 +0200 Subject: [PATCH 15/33] Rename `response` -> `res` Co-authored-by: silverwind --- web_src/js/features/load-branches-and-tags.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/web_src/js/features/load-branches-and-tags.js b/web_src/js/features/load-branches-and-tags.js index 2ab82cbc43a8e..75035966cf916 100644 --- a/web_src/js/features/load-branches-and-tags.js +++ b/web_src/js/features/load-branches-and-tags.js @@ -2,16 +2,21 @@ const {csrfToken} = window.config; async function loadBranchesAndTags(loadingButton, addHere) { loadingButton.setAttribute('disabled', 'disabled'); - const response = await fetch(loadingButton.getAttribute('data-fetch-url'), { - method: 'GET', - headers: {'X-Csrf-Token': csrfToken}, - }).finally(() => loadingButton.removeAttribute('disabled')); + let res; + try { + res = await fetch(loadingButton.getAttribute('data-fetch-url'), { + method: 'GET', + headers: {'X-Csrf-Token': csrfToken}, + }); + } finally { + loadingButton.removeAttribute('disabled'); + } - if (!response.ok) { + if (!res.ok) { return; } - const data = await response.json(); + const data = await res.json(); showAreas('.branch-tag-area-divider'); loadingButton.classList.add('gt-hidden'); addHere.querySelector('.branch-tag-area-text').textContent = loadingButton.getAttribute('data-contained-in-text'); From 6983dc441bbf5acbec328961fd17d0b4906709ea Mon Sep 17 00:00:00 2001 From: delvh Date: Tue, 13 Jun 2023 23:00:03 +0200 Subject: [PATCH 16/33] Batch add classes Co-authored-by: silverwind --- web_src/js/features/load-branches-and-tags.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/web_src/js/features/load-branches-and-tags.js b/web_src/js/features/load-branches-and-tags.js index 75035966cf916..0363b27070496 100644 --- a/web_src/js/features/load-branches-and-tags.js +++ b/web_src/js/features/load-branches-and-tags.js @@ -41,9 +41,7 @@ function showAreas(selector) { function addLink(href, text, addHere, tooltip) { const link = document.createElement('a'); - link.classList.add('muted'); - link.classList.add('gt-px-3'); - link.classList.add('gt-rounded'); + link.classList.add('muted', 'gt-px-3', 'gt-rounded'); if (tooltip) { link.classList.add('gt-border-secondary'); link.setAttribute('data-tooltip-content', tooltip); From f75db06c8a130cd7590f9b0c25f3ffac2574964e Mon Sep 17 00:00:00 2001 From: delvh Date: Tue, 13 Jun 2023 23:02:54 +0200 Subject: [PATCH 17/33] `text` -> `textContent` Co-authored-by: silverwind --- web_src/js/features/load-branches-and-tags.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web_src/js/features/load-branches-and-tags.js b/web_src/js/features/load-branches-and-tags.js index 0363b27070496..de14065d7271c 100644 --- a/web_src/js/features/load-branches-and-tags.js +++ b/web_src/js/features/load-branches-and-tags.js @@ -47,7 +47,7 @@ function addLink(href, text, addHere, tooltip) { link.setAttribute('data-tooltip-content', tooltip); } link.href = href; - link.text = text; + link.textContent = text; addHere.append(link); } From c8ea65bb9fecf3f9fe1f2c13d02191cac4b8f9cc Mon Sep 17 00:00:00 2001 From: delvh Date: Tue, 13 Jun 2023 23:08:17 +0200 Subject: [PATCH 18/33] Convert "load" button to an ellipsis-button --- templates/repo/commit_load_branches_and_tags.tmpl | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/templates/repo/commit_load_branches_and_tags.tmpl b/templates/repo/commit_load_branches_and_tags.tmpl index 32a2244a3f417..e1a12f2e67e99 100644 --- a/templates/repo/commit_load_branches_and_tags.tmpl +++ b/templates/repo/commit_load_branches_and_tags.tmpl @@ -1,7 +1,5 @@
- +
From 82d3222c632e9d04fa72ce8d3fec43be9b97bf70 Mon Sep 17 00:00:00 2001 From: delvh Date: Tue, 13 Jun 2023 23:10:32 +0200 Subject: [PATCH 19/33] Let's hope the linter likes the line-splitting --- web_src/js/features/load-branches-and-tags.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/web_src/js/features/load-branches-and-tags.js b/web_src/js/features/load-branches-and-tags.js index de14065d7271c..3673cf174da61 100644 --- a/web_src/js/features/load-branches-and-tags.js +++ b/web_src/js/features/load-branches-and-tags.js @@ -27,12 +27,16 @@ async function loadBranchesAndTags(loadingButton, addHere) { function addTags(tags, addHere) { if (tags.length > 0) showAreas('.tag-area,.tag-area-parent'); - for (const tag of tags) addLink(tag.web_url, tag.name, addHere); + for (const tag of tags) { + addLink(tag.web_url, tag.name, addHere); + } } function addBranches(branches, defaultBranch, defaultBranchTooltip, addHere) { if (branches.length > 0) showAreas('.branch-area,.branch-area-parent'); - for (const branch of branches) addLink(branch.web_url, branch.name, addHere, defaultBranch === branch.name ? defaultBranchTooltip : undefined); + for (const branch of branches) { + addLink(branch.web_url, branch.name, addHere, defaultBranch === branch.name ? defaultBranchTooltip : undefined); + } } function showAreas(selector) { From d37c79059a48a60556484d5db3ee83b17c361809 Mon Sep 17 00:00:00 2001 From: delvh Date: Tue, 13 Jun 2023 23:11:57 +0200 Subject: [PATCH 20/33] Split even more lines --- web_src/js/features/load-branches-and-tags.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/web_src/js/features/load-branches-and-tags.js b/web_src/js/features/load-branches-and-tags.js index 3673cf174da61..ada4af337d989 100644 --- a/web_src/js/features/load-branches-and-tags.js +++ b/web_src/js/features/load-branches-and-tags.js @@ -56,5 +56,9 @@ function addLink(href, text, addHere, tooltip) { } export function initLoadBranchesAndTagsButton() { - for (const loadButton of document.querySelectorAll('.load-tags-and-branches')) loadButton.addEventListener('click', async () => loadBranchesAndTags(loadButton, document.querySelector('.branch-and-tag-area'))); + for (const loadButton of document.querySelectorAll('.load-tags-and-branches')) { + loadButton.addEventListener('click', () => { + loadBranchesAndTags(loadButton, document.querySelector('.branch-and-tag-area')); + }); + } } From 8d011d26effb955ae5cde1332718af49ea879d6d Mon Sep 17 00:00:00 2001 From: delvh Date: Fri, 30 Jun 2023 16:13:21 +0200 Subject: [PATCH 21/33] Remove information that is now redundant MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Note: Only the tag function has been removed, the BranchName is still needed further down below in the template Note 2: For some reason, this whole functionality really breaks modules/git/commit#GetBranchName, even though I've never touched it and the git docs don't say anything about side effects? How is that possible? This results in the cherry-picking popup displaying a non-existent branch at the moment by default… --- modules/git/commit.go | 15 --------------- routers/web/repo/commit.go | 5 ----- templates/repo/commit_page.tmpl | 6 ------ 3 files changed, 26 deletions(-) diff --git a/modules/git/commit.go b/modules/git/commit.go index 047bf446136f3..c44882d886171 100644 --- a/modules/git/commit.go +++ b/modules/git/commit.go @@ -431,21 +431,6 @@ func (c *Commit) GetBranchName() (string, error) { return strings.SplitN(strings.TrimSpace(data), "~", 2)[0], nil } -// GetTagName gets the current tag name for given commit -func (c *Commit) GetTagName() (string, error) { - data, _, err := NewCommand(c.repo.Ctx, "describe", "--exact-match", "--tags", "--always").AddDynamicArguments(c.ID.String()).RunStdString(&RunOpts{Dir: c.repo.Path}) - if err != nil { - // handle special case where there is no tag for this commit - if strings.Contains(err.Error(), "no tag exactly matches") { - return "", nil - } - - return "", err - } - - return strings.TrimSpace(data), nil -} - // CommitFileStatus represents status of files in a commit. type CommitFileStatus struct { Added []string diff --git a/routers/web/repo/commit.go b/routers/web/repo/commit.go index 2bcfbac2b490f..a717f414a1cce 100644 --- a/routers/web/repo/commit.go +++ b/routers/web/repo/commit.go @@ -385,11 +385,6 @@ func Diff(ctx *context.Context) { return } - ctx.Data["TagName"], err = commit.GetTagName() - if err != nil { - ctx.ServerError("commit.GetTagName", err) - return - } ctx.HTML(http.StatusOK, tplCommitPage) } diff --git a/templates/repo/commit_page.tmpl b/templates/repo/commit_page.tmpl index 7006451fcbb43..b232ee1c08704 100644 --- a/templates/repo/commit_page.tmpl +++ b/templates/repo/commit_page.tmpl @@ -136,12 +136,6 @@ {{if IsMultilineCommitMessage .Commit.Message}}
{{RenderCommitBody $.Context .Commit.Message $.RepoLink $.Repository.ComposeMetas}}
{{end}} - {{if .BranchName}} - {{svg "octicon-git-branch" 16 "gt-mr-2"}}{{.BranchName}} - {{end}} - {{if .TagName}} - {{svg "octicon-tag" 16 "gt-mr-2"}}{{.TagName}} - {{end}} {{template "repo/commit_load_branches_and_tags" .}}
From 42712b5f13b2aec657b9f3c146f56204acdbd6f8 Mon Sep 17 00:00:00 2001 From: delvh Date: Fri, 14 Jul 2023 14:51:57 +0200 Subject: [PATCH 22/33] Apparently the merge went wrong --- modules/git/commit.go | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/modules/git/commit.go b/modules/git/commit.go index f646093a01382..c44882d886171 100644 --- a/modules/git/commit.go +++ b/modules/git/commit.go @@ -431,31 +431,6 @@ func (c *Commit) GetBranchName() (string, error) { return strings.SplitN(strings.TrimSpace(data), "~", 2)[0], nil } -// LoadBranchName load branch name for commit -func (c *Commit) LoadBranchName() (err error) { - if len(c.Branch) != 0 { - return nil - } - - c.Branch, err = c.GetBranchName() - return err -} - -// GetTagName gets the current tag name for given commit -func (c *Commit) GetTagName() (string, error) { - data, _, err := NewCommand(c.repo.Ctx, "describe", "--exact-match", "--tags", "--always").AddDynamicArguments(c.ID.String()).RunStdString(&RunOpts{Dir: c.repo.Path}) - if err != nil { - // handle special case where there is no tag for this commit - if strings.Contains(err.Error(), "no tag exactly matches") { - return "", nil - } - - return "", err - } - - return strings.TrimSpace(data), nil -} - // CommitFileStatus represents status of files in a commit. type CommitFileStatus struct { Added []string From 48c225ea9f17f1c8a61d07636c8e3347bfa10aca Mon Sep 17 00:00:00 2001 From: delvh Date: Fri, 14 Jul 2023 16:15:49 +0200 Subject: [PATCH 23/33] Fix typo in translated string Took me surprisingly long to notice --- options/locale/locale_en-US.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 848e92844b963..70cd2d6346f94 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1172,7 +1172,7 @@ commit_graph.monochrome = Mono commit_graph.color = Color commit.contained_in = This commit is contained in: commit.contained_in_default_branch = This commit is part of the default branch -commit.load_referencing_branches_and_tags = Load branches and tags referencing this file +commit.load_referencing_branches_and_tags = Load branches and tags referencing this commit blame = Blame download_file = Download file normal_view = Normal View From 0969a39d2b0e3a9b298a40395239aba22a0ebc9c Mon Sep 17 00:00:00 2001 From: delvh Date: Fri, 21 Jul 2023 15:40:37 +0200 Subject: [PATCH 24/33] Implement suggestions by @wxiaoguang --- modules/git/repo_ref.go | 31 +++++++++++++++++-- services/repository/commit.go | 2 +- .../repo/commit_load_branches_and_tags.tmpl | 4 +-- web_src/css/helpers.css | 3 +- web_src/js/features/load-branches-and-tags.js | 17 +++++----- 5 files changed, 39 insertions(+), 18 deletions(-) diff --git a/modules/git/repo_ref.go b/modules/git/repo_ref.go index b5a1dfc7f8fe6..28dde6e90f502 100644 --- a/modules/git/repo_ref.go +++ b/modules/git/repo_ref.go @@ -6,6 +6,8 @@ package git import ( "context" "strings" + + "code.gitea.io/gitea/modules/util" ) // GetRefs returns all references of the repository. @@ -16,18 +18,41 @@ func (repo *Repository) GetRefs() ([]*Reference, error) { // ListOccurrences lists all refs of the given refType the given commit appears in sorted by creation date DESC // refType should only be a literal "branch" or "tag" and nothing else func (repo *Repository) ListOccurrences(ctx context.Context, refType, commitSHA string) ([]string, error) { + if refType != "branch" && refType != "tag" { + return nil, util.NewInvalidArgumentErrorf("Can only use branch or 'tag' as 'refType'. Got '%s'", refType) + } stdout, _, err := NewCommand(ctx, ToTrustedCmdArgs([]string{refType, "--no-color", "--sort=-creatordate", "--contains"})...).AddDynamicArguments(commitSHA).RunStdString(&RunOpts{Dir: repo.Path}) + if err != nil { + return nil, err + } refs := strings.Split(strings.TrimSpace(stdout), "\n") + if refType == "branch" { + return parseBranches(refs), nil + } + return parseTags(refs), nil +} + +func parseBranches(refs []string) []string { results := make([]string, 0, len(refs)) for _, ref := range refs { - if strings.HasPrefix(ref, "* ") { // main branch + if strings.HasPrefix(ref, "* ") { // current branch (main branch) results = append(results, ref[len("* "):]) } else if strings.HasPrefix(ref, " ") { // all other branches results = append(results, ref[len(" "):]) - } else if ref != "" { // tags + } else if ref != "" { + results = append(results, ref) + } + } + return results +} + +func parseTags(refs []string) []string { + results := make([]string, 0, len(refs)) + for _, ref := range refs { + if ref != "" { results = append(results, ref) } } - return results, err + return results } diff --git a/services/repository/commit.go b/services/repository/commit.go index 89cf012c9e42b..4a7703d18c917 100644 --- a/services/repository/commit.go +++ b/services/repository/commit.go @@ -20,7 +20,7 @@ type ContainedLinks struct { // TODO: better name? type namedLink struct { // TODO: better name? Name string `json:"name"` - WebLink string `json:"web_url"` + WebLink string `json:"web_link"` } // CreateNewBranch creates a new repository branch diff --git a/templates/repo/commit_load_branches_and_tags.tmpl b/templates/repo/commit_load_branches_and_tags.tmpl index e1a12f2e67e99..a96ddb271726f 100644 --- a/templates/repo/commit_load_branches_and_tags.tmpl +++ b/templates/repo/commit_load_branches_and_tags.tmpl @@ -4,10 +4,10 @@
{{svg "octicon-git-branch" 16 "gt-min-w-16"}} -
+
{{svg "octicon-tag" 16 "gt-min-w-16"}} -
+
diff --git a/web_src/css/helpers.css b/web_src/css/helpers.css index d2137acb4cdf8..34e522650282c 100644 --- a/web_src/css/helpers.css +++ b/web_src/css/helpers.css @@ -77,13 +77,12 @@ Gitea's private styles use `g-` prefix. .gt-overflow-x-auto { overflow-x: auto !important; } .gt-overflow-x-scroll { overflow-x: scroll !important; } .gt-overflow-y-hidden { overflow-y: hidden !important; } -.gt-flex-wrap { flex-wrap: wrap !important; } .gt-w-screen { width: 100vw !important; } .gt-h-screen { height: 100vh !important; } .gt-min-w-0 { min-width: 0 !important; } -.gt-min-w-16 { min-width: 16px !important; } /*There are some weird bugs with flexboxes and SVGs*/ +.gt-min-w-16 { min-width: 16px !important; } /*There are some weird bugs with flexboxes and SVGs where the svgs shrink into oblivion*/ .gt-float-left { float: left !important; } .gt-float-right { float: right !important; } diff --git a/web_src/js/features/load-branches-and-tags.js b/web_src/js/features/load-branches-and-tags.js index ada4af337d989..b51f95c39dcda 100644 --- a/web_src/js/features/load-branches-and-tags.js +++ b/web_src/js/features/load-branches-and-tags.js @@ -1,15 +1,12 @@ -const {csrfToken} = window.config; +import {showElem} from '../utils/dom.js'; async function loadBranchesAndTags(loadingButton, addHere) { - loadingButton.setAttribute('disabled', 'disabled'); + loadingButton.classList.add('disabled') let res; try { - res = await fetch(loadingButton.getAttribute('data-fetch-url'), { - method: 'GET', - headers: {'X-Csrf-Token': csrfToken}, - }); + res = await fetch(loadingButton.getAttribute('data-fetch-url'), { method: 'GET', }); } finally { - loadingButton.removeAttribute('disabled'); + loadingButton.classList.remove('disabled') } if (!res.ok) { @@ -28,19 +25,19 @@ async function loadBranchesAndTags(loadingButton, addHere) { function addTags(tags, addHere) { if (tags.length > 0) showAreas('.tag-area,.tag-area-parent'); for (const tag of tags) { - addLink(tag.web_url, tag.name, addHere); + addLink(tag.web_link, tag.name, addHere); } } function addBranches(branches, defaultBranch, defaultBranchTooltip, addHere) { if (branches.length > 0) showAreas('.branch-area,.branch-area-parent'); for (const branch of branches) { - addLink(branch.web_url, branch.name, addHere, defaultBranch === branch.name ? defaultBranchTooltip : undefined); + addLink(branch.web_link, branch.name, addHere, defaultBranch === branch.name ? defaultBranchTooltip : undefined); } } function showAreas(selector) { - for (const branchArea of document.querySelectorAll(selector)) branchArea.classList.remove('gt-hidden'); + for (const branchArea of document.querySelectorAll(selector)) showElem(branchArea); } function addLink(href, text, addHere, tooltip) { From b009c77a75836d2e4d150af662922886b0136533 Mon Sep 17 00:00:00 2001 From: delvh Date: Fri, 21 Jul 2023 15:49:32 +0200 Subject: [PATCH 25/33] Separate ellipsis-button into ellipsis-button and ellipsis-js-button So, differentiate between CSS content and JS content. As per @wxiaoguang --- templates/repo/commits_list.tmpl | 2 +- templates/repo/commits_list_small.tmpl | 2 +- templates/repo/view_list.tmpl | 2 +- web_src/js/features/repo-commit.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/templates/repo/commits_list.tmpl b/templates/repo/commits_list.tmpl index 6768bcb5137f0..a15deb847adaa 100644 --- a/templates/repo/commits_list.tmpl +++ b/templates/repo/commits_list.tmpl @@ -70,7 +70,7 @@ {{end}} {{if IsMultilineCommitMessage .Message}} - + {{end}} {{template "repo/commit_statuses" dict "Status" .Status "Statuses" .Statuses "root" $}} {{if IsMultilineCommitMessage .Message}} diff --git a/templates/repo/commits_list_small.tmpl b/templates/repo/commits_list_small.tmpl index 6bbc19529f942..558c3d2a2d30f 100644 --- a/templates/repo/commits_list_small.tmpl +++ b/templates/repo/commits_list_small.tmpl @@ -40,7 +40,7 @@ {{RenderCommitMessageLinkSubject $.root.Context .Message ($.comment.Issue.PullRequest.BaseRepo.Link|Escape) $commitLink $.comment.Issue.PullRequest.BaseRepo.ComposeMetas}} {{if IsMultilineCommitMessage .Message}} - + {{end}} {{if IsMultilineCommitMessage .Message}}
{{RenderCommitBody $.root.Context .Message ($.comment.Issue.PullRequest.BaseRepo.Link|Escape) $.comment.Issue.PullRequest.BaseRepo.ComposeMetas}}
diff --git a/templates/repo/view_list.tmpl b/templates/repo/view_list.tmpl index 13b4d3d3d322f..9c5b82b1b6507 100644 --- a/templates/repo/view_list.tmpl +++ b/templates/repo/view_list.tmpl @@ -28,7 +28,7 @@ {{$commitLink:= printf "%s/commit/%s" .RepoLink (PathEscape .LatestCommit.ID.String)}} {{RenderCommitMessageLinkSubject $.Context .LatestCommit.Message $.RepoLink $commitLink $.Repository.ComposeMetas}} {{if IsMultilineCommitMessage .LatestCommit.Message}} - +
{{RenderCommitBody $.Context .LatestCommit.Message $.RepoLink $.Repository.ComposeMetas}}
{{end}}
diff --git a/web_src/js/features/repo-commit.js b/web_src/js/features/repo-commit.js index 7e4e40806b6c1..d8e9306d6cba9 100644 --- a/web_src/js/features/repo-commit.js +++ b/web_src/js/features/repo-commit.js @@ -5,7 +5,7 @@ import {toggleElem} from '../utils/dom.js'; const {csrfToken} = window.config; export function initRepoEllipsisButton() { - $('.ellipsis-button').on('click', function (e) { + $('.ellipsis-js-button').on('click', function (e) { e.preventDefault(); const expanded = $(this).attr('aria-expanded') === 'true'; toggleElem($(this).parent().find('.commit-body')); From 97956cfd531c5344e04b18730b83558bd50b2df6 Mon Sep 17 00:00:00 2001 From: delvh Date: Fri, 21 Jul 2023 15:53:50 +0200 Subject: [PATCH 26/33] Fix formatting --- web_src/js/features/load-branches-and-tags.js | 34 ++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/web_src/js/features/load-branches-and-tags.js b/web_src/js/features/load-branches-and-tags.js index b51f95c39dcda..9d8eac79a36f9 100644 --- a/web_src/js/features/load-branches-and-tags.js +++ b/web_src/js/features/load-branches-and-tags.js @@ -1,12 +1,14 @@ import {showElem} from '../utils/dom.js'; async function loadBranchesAndTags(loadingButton, addHere) { - loadingButton.classList.add('disabled') + loadingButton.classList.add('disabled'); let res; try { - res = await fetch(loadingButton.getAttribute('data-fetch-url'), { method: 'GET', }); + res = await fetch(loadingButton.getAttribute('data-fetch-url'), { + method: 'GET', + }); } finally { - loadingButton.classList.remove('disabled') + loadingButton.classList.remove('disabled'); } if (!res.ok) { @@ -16,10 +18,16 @@ async function loadBranchesAndTags(loadingButton, addHere) { const data = await res.json(); showAreas('.branch-tag-area-divider'); loadingButton.classList.add('gt-hidden'); - addHere.querySelector('.branch-tag-area-text').textContent = loadingButton.getAttribute('data-contained-in-text'); + addHere.querySelector('.branch-tag-area-text').textContent = + loadingButton.getAttribute('data-contained-in-text'); addTags(data.tags, addHere.querySelector('.tag-area')); const branchArea = addHere.querySelector('.branch-area'); - addBranches(data.branches, data.default_branch, branchArea.getAttribute('data-defaultbranch-tooltip'), branchArea); + addBranches( + data.branches, + data.default_branch, + branchArea.getAttribute('data-defaultbranch-tooltip'), + branchArea, + ); } function addTags(tags, addHere) { @@ -32,7 +40,12 @@ function addTags(tags, addHere) { function addBranches(branches, defaultBranch, defaultBranchTooltip, addHere) { if (branches.length > 0) showAreas('.branch-area,.branch-area-parent'); for (const branch of branches) { - addLink(branch.web_link, branch.name, addHere, defaultBranch === branch.name ? defaultBranchTooltip : undefined); + addLink( + branch.web_link, + branch.name, + addHere, + defaultBranch === branch.name ? defaultBranchTooltip : undefined, + ); } } @@ -53,9 +66,14 @@ function addLink(href, text, addHere, tooltip) { } export function initLoadBranchesAndTagsButton() { - for (const loadButton of document.querySelectorAll('.load-tags-and-branches')) { + for (const loadButton of document.querySelectorAll( + '.load-tags-and-branches', + )) { loadButton.addEventListener('click', () => { - loadBranchesAndTags(loadButton, document.querySelector('.branch-and-tag-area')); + loadBranchesAndTags( + loadButton, + document.querySelector('.branch-and-tag-area'), + ); }); } } From 7206f0f37123e378d2c6716820adfac286e59f69 Mon Sep 17 00:00:00 2001 From: delvh Date: Fri, 21 Jul 2023 16:22:04 +0200 Subject: [PATCH 27/33] Improve formatting --- web_src/js/features/load-branches-and-tags.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/web_src/js/features/load-branches-and-tags.js b/web_src/js/features/load-branches-and-tags.js index 9d8eac79a36f9..e72968534e4ba 100644 --- a/web_src/js/features/load-branches-and-tags.js +++ b/web_src/js/features/load-branches-and-tags.js @@ -66,9 +66,7 @@ function addLink(href, text, addHere, tooltip) { } export function initLoadBranchesAndTagsButton() { - for (const loadButton of document.querySelectorAll( - '.load-tags-and-branches', - )) { + for (const loadButton of document.querySelectorAll('.load-tags-and-branches')) { loadButton.addEventListener('click', () => { loadBranchesAndTags( loadButton, From e91843ae6baef90943abbdb3a53018f416503284 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Wed, 26 Jul 2023 21:53:20 +0800 Subject: [PATCH 28/33] temp fix --- modules/context/context_response.go | 1 + modules/git/repo_ref.go | 11 +++++++--- routers/web/repo/commit.go | 3 +-- services/repository/commit.go | 21 +++++++++++++------ templates/repo/commits_list.tmpl | 2 +- templates/repo/commits_list_small.tmpl | 2 +- templates/repo/view_list.tmpl | 2 +- web_src/js/features/load-branches-and-tags.js | 3 +-- web_src/js/features/repo-commit.js | 2 +- 9 files changed, 30 insertions(+), 17 deletions(-) diff --git a/modules/context/context_response.go b/modules/context/context_response.go index bb3ccf69ce421..9dc6d1fc0ec5f 100644 --- a/modules/context/context_response.go +++ b/modules/context/context_response.go @@ -166,6 +166,7 @@ func (ctx *Context) serverErrorInternal(logMsg string, logErr error) { // NotFoundOrServerError use error check function to determine if the error // is about not found. It responds with 404 status code for not found error, // or error context description for logging purpose of 500 server error. +// TODO: remove the "errCheck" and use util.ErrNotFound to check func (ctx *Context) NotFoundOrServerError(logMsg string, errCheck func(error) bool, logErr error) { if errCheck(logErr) { ctx.notFoundInternal(logMsg, logErr) diff --git a/modules/git/repo_ref.go b/modules/git/repo_ref.go index 28dde6e90f502..8eaa17cb04182 100644 --- a/modules/git/repo_ref.go +++ b/modules/git/repo_ref.go @@ -18,10 +18,15 @@ func (repo *Repository) GetRefs() ([]*Reference, error) { // ListOccurrences lists all refs of the given refType the given commit appears in sorted by creation date DESC // refType should only be a literal "branch" or "tag" and nothing else func (repo *Repository) ListOccurrences(ctx context.Context, refType, commitSHA string) ([]string, error) { - if refType != "branch" && refType != "tag" { - return nil, util.NewInvalidArgumentErrorf("Can only use branch or 'tag' as 'refType'. Got '%s'", refType) + cmd := NewCommand(ctx) + if refType == "branch" { + cmd.AddArguments("branch") + } else if refType == "tag" { + cmd.AddArguments("tag") + } else { + return nil, util.NewInvalidArgumentErrorf(`can only use "branch" or "tag" for refType, but got %q`, refType) } - stdout, _, err := NewCommand(ctx, ToTrustedCmdArgs([]string{refType, "--no-color", "--sort=-creatordate", "--contains"})...).AddDynamicArguments(commitSHA).RunStdString(&RunOpts{Dir: repo.Path}) + stdout, _, err := cmd.AddArguments("--no-color", "--sort=-creatordate", "--contains").AddDynamicArguments(commitSHA).RunStdString(&RunOpts{Dir: repo.Path}) if err != nil { return nil, err } diff --git a/routers/web/repo/commit.go b/routers/web/repo/commit.go index a717f414a1cce..5b32591b89140 100644 --- a/routers/web/repo/commit.go +++ b/routers/web/repo/commit.go @@ -22,7 +22,6 @@ import ( "code.gitea.io/gitea/modules/gitgraph" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" - "code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/services/gitdiff" git_service "code.gitea.io/gitea/services/repository" ) @@ -263,7 +262,7 @@ func LoadBranchesAndTags(ctx *context.Context) { ctx.JSON(http.StatusOK, response) return } - ctx.NotFoundOrServerError(fmt.Sprintf("could not load branches and tags the commit %s belongs to", ctx.Params("sha")), func(err error) bool { return errors.Is(err, util.ErrNotExist) }, err) + ctx.NotFoundOrServerError(fmt.Sprintf("could not load branches and tags the commit %s belongs to", ctx.Params("sha")), git.IsErrNotExist, err) } // Diff show different from current commit to previous commit diff --git a/services/repository/commit.go b/services/repository/commit.go index 4a7703d18c917..5934887fb06a0 100644 --- a/services/repository/commit.go +++ b/services/repository/commit.go @@ -23,7 +23,7 @@ type namedLink struct { // TODO: better name? WebLink string `json:"web_link"` } -// CreateNewBranch creates a new repository branch +// LoadBranchesAndTags creates a new repository branch func LoadBranchesAndTags(ctx context.Context, baseRepo *gitea_ctx.Repository, commitSHA string) (*ContainedLinks, error) { containedTags, err := baseRepo.GitRepo.ListOccurrences(ctx, "tag", commitSHA) if err != nil { @@ -35,15 +35,24 @@ func LoadBranchesAndTags(ctx context.Context, baseRepo *gitea_ctx.Repository, co } result := &ContainedLinks{ - ContainedInDefaultBranch: util.SliceContains(containedBranches, baseRepo.Repository.DefaultBranch), DefaultBranch: baseRepo.Repository.DefaultBranch, - Branches: make([]*namedLink, 0, len(containedBranches)), Tags: make([]*namedLink, 0, len(containedTags)), + ContainedInDefaultBranch: util.SliceContains(containedBranches, baseRepo.Repository.DefaultBranch), + + DefaultBranch: baseRepo.Repository.DefaultBranch, + Branches: make([]*namedLink, 0, len(containedBranches)), + Tags: make([]*namedLink, 0, len(containedTags)), } for _, tag := range containedTags { - result.Tags = append(result.Tags, &namedLink{Name: tag, WebLink: fmt.Sprintf("%s/src/tag/%s", baseRepo.RepoLink, util.PathEscapeSegments(tag))}) // TODO: Use a common method to get the link to a branch/tag instead of hardcoding it here + // TODO: Use a common method to get the link to a branch/tag instead of hard-coding it here + result.Tags = append(result.Tags, &namedLink{ + Name: tag, + WebLink: fmt.Sprintf("%s/src/tag/%s", baseRepo.RepoLink, util.PathEscapeSegments(tag)), + }) } for _, branch := range containedBranches { - result.Branches = append(result.Branches, &namedLink{Name: branch, WebLink: fmt.Sprintf("%s/src/branch/%s", baseRepo.RepoLink, util.PathEscapeSegments(branch))}) + result.Branches = append(result.Branches, &namedLink{ + Name: branch, + WebLink: fmt.Sprintf("%s/src/branch/%s", baseRepo.RepoLink, util.PathEscapeSegments(branch)), + }) } - return result, nil } diff --git a/templates/repo/commits_list.tmpl b/templates/repo/commits_list.tmpl index a15deb847adaa..ef9d0654566f5 100644 --- a/templates/repo/commits_list.tmpl +++ b/templates/repo/commits_list.tmpl @@ -70,7 +70,7 @@ {{end}} {{if IsMultilineCommitMessage .Message}} - + {{end}} {{template "repo/commit_statuses" dict "Status" .Status "Statuses" .Statuses "root" $}} {{if IsMultilineCommitMessage .Message}} diff --git a/templates/repo/commits_list_small.tmpl b/templates/repo/commits_list_small.tmpl index 558c3d2a2d30f..57c9fd17ef775 100644 --- a/templates/repo/commits_list_small.tmpl +++ b/templates/repo/commits_list_small.tmpl @@ -40,7 +40,7 @@ {{RenderCommitMessageLinkSubject $.root.Context .Message ($.comment.Issue.PullRequest.BaseRepo.Link|Escape) $commitLink $.comment.Issue.PullRequest.BaseRepo.ComposeMetas}} {{if IsMultilineCommitMessage .Message}} - + {{end}} {{if IsMultilineCommitMessage .Message}}
{{RenderCommitBody $.root.Context .Message ($.comment.Issue.PullRequest.BaseRepo.Link|Escape) $.comment.Issue.PullRequest.BaseRepo.ComposeMetas}}
diff --git a/templates/repo/view_list.tmpl b/templates/repo/view_list.tmpl index 9c5b82b1b6507..3eabf9f181e57 100644 --- a/templates/repo/view_list.tmpl +++ b/templates/repo/view_list.tmpl @@ -28,7 +28,7 @@ {{$commitLink:= printf "%s/commit/%s" .RepoLink (PathEscape .LatestCommit.ID.String)}} {{RenderCommitMessageLinkSubject $.Context .LatestCommit.Message $.RepoLink $commitLink $.Repository.ComposeMetas}} {{if IsMultilineCommitMessage .LatestCommit.Message}} - +
{{RenderCommitBody $.Context .LatestCommit.Message $.RepoLink $.Repository.ComposeMetas}}
{{end}}
diff --git a/web_src/js/features/load-branches-and-tags.js b/web_src/js/features/load-branches-and-tags.js index e72968534e4ba..f3082f68e9e10 100644 --- a/web_src/js/features/load-branches-and-tags.js +++ b/web_src/js/features/load-branches-and-tags.js @@ -18,8 +18,7 @@ async function loadBranchesAndTags(loadingButton, addHere) { const data = await res.json(); showAreas('.branch-tag-area-divider'); loadingButton.classList.add('gt-hidden'); - addHere.querySelector('.branch-tag-area-text').textContent = - loadingButton.getAttribute('data-contained-in-text'); + addHere.querySelector('.branch-tag-area-text').textContent = loadingButton.getAttribute('data-contained-in-text'); addTags(data.tags, addHere.querySelector('.tag-area')); const branchArea = addHere.querySelector('.branch-area'); addBranches( diff --git a/web_src/js/features/repo-commit.js b/web_src/js/features/repo-commit.js index d8e9306d6cba9..7240bf398aec6 100644 --- a/web_src/js/features/repo-commit.js +++ b/web_src/js/features/repo-commit.js @@ -5,7 +5,7 @@ import {toggleElem} from '../utils/dom.js'; const {csrfToken} = window.config; export function initRepoEllipsisButton() { - $('.ellipsis-js-button').on('click', function (e) { + $('.js-toggle-commit-body').on('click', function (e) { e.preventDefault(); const expanded = $(this).attr('aria-expanded') === 'true'; toggleElem($(this).parent().find('.commit-body')); From 666a01992226d82c4e0fb29e5998d06d3393db6e Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Wed, 26 Jul 2023 22:26:34 +0800 Subject: [PATCH 29/33] fix --- .../repo/commit_load_branches_and_tags.tmpl | 21 +++-- web_src/css/helpers.css | 3 - web_src/js/features/load-branches-and-tags.js | 76 +++++++------------ web_src/js/features/repo-legacy.js | 2 +- 4 files changed, 37 insertions(+), 65 deletions(-) diff --git a/templates/repo/commit_load_branches_and_tags.tmpl b/templates/repo/commit_load_branches_and_tags.tmpl index a96ddb271726f..cfc6ec3404ce5 100644 --- a/templates/repo/commit_load_branches_and_tags.tmpl +++ b/templates/repo/commit_load_branches_and_tags.tmpl @@ -1,13 +1,12 @@ -
- -
-
-
- {{svg "octicon-git-branch" 16 "gt-min-w-16"}} -
-
-
- {{svg "octicon-tag" 16 "gt-min-w-16"}} -
+
+ +
+
+
{{.locale.Tr "repo.commit.contained_in"}}
+
{{svg "octicon-git-branch"}}
+
{{svg "octicon-tag"}}
diff --git a/web_src/css/helpers.css b/web_src/css/helpers.css index bd4540450ec02..8a6c2c6539074 100644 --- a/web_src/css/helpers.css +++ b/web_src/css/helpers.css @@ -82,9 +82,6 @@ Gitea's private styles use `g-` prefix. .gt-w-screen { width: 100vw !important; } .gt-h-screen { height: 100vh !important; } -.gt-min-w-0 { min-width: 0 !important; } -.gt-min-w-16 { min-width: 16px !important; } /*There are some weird bugs with flexboxes and SVGs where the svgs shrink into oblivion*/ - .gt-float-left { float: left !important; } .gt-float-right { float: right !important; } .gt-clear-both { clear: both !important; } diff --git a/web_src/js/features/load-branches-and-tags.js b/web_src/js/features/load-branches-and-tags.js index f3082f68e9e10..5e484b629edd6 100644 --- a/web_src/js/features/load-branches-and-tags.js +++ b/web_src/js/features/load-branches-and-tags.js @@ -1,76 +1,52 @@ -import {showElem} from '../utils/dom.js'; +import {showElem, toggleElem} from '../utils/dom.js'; -async function loadBranchesAndTags(loadingButton, addHere) { +async function loadBranchesAndTags(area, loadingButton) { loadingButton.classList.add('disabled'); - let res; try { - res = await fetch(loadingButton.getAttribute('data-fetch-url'), { - method: 'GET', - }); + const res = await fetch(loadingButton.getAttribute('data-fetch-url')); + const data = await res.json(); + loadingButton.classList.add('gt-hidden'); + addTags(area, data.tags); + addBranches(area, data.branches, data.default_branch); + showElem(area.querySelectorAll('.branch-and-tag-detail')); } finally { loadingButton.classList.remove('disabled'); } - - if (!res.ok) { - return; - } - - const data = await res.json(); - showAreas('.branch-tag-area-divider'); - loadingButton.classList.add('gt-hidden'); - addHere.querySelector('.branch-tag-area-text').textContent = loadingButton.getAttribute('data-contained-in-text'); - addTags(data.tags, addHere.querySelector('.tag-area')); - const branchArea = addHere.querySelector('.branch-area'); - addBranches( - data.branches, - data.default_branch, - branchArea.getAttribute('data-defaultbranch-tooltip'), - branchArea, - ); } -function addTags(tags, addHere) { - if (tags.length > 0) showAreas('.tag-area,.tag-area-parent'); +function addTags(area, tags) { + toggleElem(area.querySelectorAll('.tag-area-parent'), tags.length > 0); + const tagArea = area.querySelector('.tag-area'); for (const tag of tags) { - addLink(tag.web_link, tag.name, addHere); + addLink(tagArea, tag.web_link, tag.name); } } -function addBranches(branches, defaultBranch, defaultBranchTooltip, addHere) { - if (branches.length > 0) showAreas('.branch-area,.branch-area-parent'); +function addBranches(area, branches, defaultBranch) { + const defaultBranchTooltip = area.getAttribute('data-text-default-branch-tooltip'); + toggleElem(area.querySelectorAll('.branch-area-parent'), branches.length > 0); + const branchArea = area.querySelector('.branch-area'); for (const branch of branches) { - addLink( - branch.web_link, - branch.name, - addHere, - defaultBranch === branch.name ? defaultBranchTooltip : undefined, - ); + const tooltip = defaultBranch === branch.name ? defaultBranchTooltip : null; + addLink(branchArea, branch.web_link, branch.name, tooltip); } } -function showAreas(selector) { - for (const branchArea of document.querySelectorAll(selector)) showElem(branchArea); -} - -function addLink(href, text, addHere, tooltip) { +function addLink(parent, href, text, tooltip) { const link = document.createElement('a'); - link.classList.add('muted', 'gt-px-3', 'gt-rounded'); + link.classList.add('muted', 'gt-px-2', 'gt-rounded'); + link.href = href; + link.textContent = text; if (tooltip) { link.classList.add('gt-border-secondary'); link.setAttribute('data-tooltip-content', tooltip); } - link.href = href; - link.textContent = text; - addHere.append(link); + parent.append(link); } export function initLoadBranchesAndTagsButton() { - for (const loadButton of document.querySelectorAll('.load-tags-and-branches')) { - loadButton.addEventListener('click', () => { - loadBranchesAndTags( - loadButton, - document.querySelector('.branch-and-tag-area'), - ); - }); + for (const area of document.querySelectorAll('.branch-and-tag-area')) { + const loadButton = area.querySelector('.load-branches-and-tags'); + loadButton.addEventListener('click', () => loadBranchesAndTags(area, loadButton)); } } diff --git a/web_src/js/features/repo-legacy.js b/web_src/js/features/repo-legacy.js index f23ff45470c10..5991df6322c57 100644 --- a/web_src/js/features/repo-legacy.js +++ b/web_src/js/features/repo-legacy.js @@ -459,7 +459,7 @@ async function onEditContent(event) { } export function initRepository() { - if ($('.repository').length === 0) { + if ($('.page-content.repository').length === 0) { return; } From 672f0bb4ce2c04c47aae197ecc71e960ced3aa27 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Wed, 26 Jul 2023 22:30:40 +0800 Subject: [PATCH 30/33] fix --- services/repository/commit.go | 9 +++------ web_src/js/features/load-branches-and-tags.js | 4 ++-- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/services/repository/commit.go b/services/repository/commit.go index 5934887fb06a0..2497910a838d7 100644 --- a/services/repository/commit.go +++ b/services/repository/commit.go @@ -12,10 +12,9 @@ import ( ) type ContainedLinks struct { // TODO: better name? - Branches []*namedLink `json:"branches"` - Tags []*namedLink `json:"tags"` - ContainedInDefaultBranch bool `json:"contained_in_default_branch"` - DefaultBranch string `json:"default_branch"` + Branches []*namedLink `json:"branches"` + Tags []*namedLink `json:"tags"` + DefaultBranch string `json:"default_branch"` } type namedLink struct { // TODO: better name? @@ -35,8 +34,6 @@ func LoadBranchesAndTags(ctx context.Context, baseRepo *gitea_ctx.Repository, co } result := &ContainedLinks{ - ContainedInDefaultBranch: util.SliceContains(containedBranches, baseRepo.Repository.DefaultBranch), - DefaultBranch: baseRepo.Repository.DefaultBranch, Branches: make([]*namedLink, 0, len(containedBranches)), Tags: make([]*namedLink, 0, len(containedTags)), diff --git a/web_src/js/features/load-branches-and-tags.js b/web_src/js/features/load-branches-and-tags.js index 5e484b629edd6..ba7be4b599c53 100644 --- a/web_src/js/features/load-branches-and-tags.js +++ b/web_src/js/features/load-branches-and-tags.js @@ -1,11 +1,11 @@ -import {showElem, toggleElem} from '../utils/dom.js'; +import {hideElem, showElem, toggleElem} from '../utils/dom.js'; async function loadBranchesAndTags(area, loadingButton) { loadingButton.classList.add('disabled'); try { const res = await fetch(loadingButton.getAttribute('data-fetch-url')); const data = await res.json(); - loadingButton.classList.add('gt-hidden'); + hideElem(loadingButton); addTags(area, data.tags); addBranches(area, data.branches, data.default_branch); showElem(area.querySelectorAll('.branch-and-tag-detail')); From bf96470e12b48780657e9980365e4577d4691c61 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Wed, 26 Jul 2023 22:40:19 +0800 Subject: [PATCH 31/33] fix --- web_src/js/features/load-branches-and-tags.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/web_src/js/features/load-branches-and-tags.js b/web_src/js/features/load-branches-and-tags.js index ba7be4b599c53..2dcadf4e43a39 100644 --- a/web_src/js/features/load-branches-and-tags.js +++ b/web_src/js/features/load-branches-and-tags.js @@ -15,8 +15,8 @@ async function loadBranchesAndTags(area, loadingButton) { } function addTags(area, tags) { - toggleElem(area.querySelectorAll('.tag-area-parent'), tags.length > 0); const tagArea = area.querySelector('.tag-area'); + toggleElem(tagArea, tags.length > 0); for (const tag of tags) { addLink(tagArea, tag.web_link, tag.name); } @@ -24,8 +24,8 @@ function addTags(area, tags) { function addBranches(area, branches, defaultBranch) { const defaultBranchTooltip = area.getAttribute('data-text-default-branch-tooltip'); - toggleElem(area.querySelectorAll('.branch-area-parent'), branches.length > 0); const branchArea = area.querySelector('.branch-area'); + toggleElem(branchArea, branches.length > 0); for (const branch of branches) { const tooltip = defaultBranch === branch.name ? defaultBranchTooltip : null; addLink(branchArea, branch.web_link, branch.name, tooltip); @@ -34,11 +34,11 @@ function addBranches(area, branches, defaultBranch) { function addLink(parent, href, text, tooltip) { const link = document.createElement('a'); - link.classList.add('muted', 'gt-px-2', 'gt-rounded'); + link.classList.add('muted', 'gt-px-2'); link.href = href; link.textContent = text; if (tooltip) { - link.classList.add('gt-border-secondary'); + link.classList.add('gt-border-secondary', 'gt-rounded'); link.setAttribute('data-tooltip-content', tooltip); } parent.append(link); @@ -46,7 +46,7 @@ function addLink(parent, href, text, tooltip) { export function initLoadBranchesAndTagsButton() { for (const area of document.querySelectorAll('.branch-and-tag-area')) { - const loadButton = area.querySelector('.load-branches-and-tags'); - loadButton.addEventListener('click', () => loadBranchesAndTags(area, loadButton)); + const btn = area.querySelector('.load-branches-and-tags'); + btn.addEventListener('click', () => loadBranchesAndTags(area, btn)); } } From e5effc84e28613c601743e3063ec5d5d087fba92 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Wed, 26 Jul 2023 22:44:16 +0800 Subject: [PATCH 32/33] rename --- .../{load-branches-and-tags.js => repo-diff-commit.js} | 2 +- web_src/js/index.js | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) rename web_src/js/features/{load-branches-and-tags.js => repo-diff-commit.js} (96%) diff --git a/web_src/js/features/load-branches-and-tags.js b/web_src/js/features/repo-diff-commit.js similarity index 96% rename from web_src/js/features/load-branches-and-tags.js rename to web_src/js/features/repo-diff-commit.js index 2dcadf4e43a39..968f318e63d5d 100644 --- a/web_src/js/features/load-branches-and-tags.js +++ b/web_src/js/features/repo-diff-commit.js @@ -44,7 +44,7 @@ function addLink(parent, href, text, tooltip) { parent.append(link); } -export function initLoadBranchesAndTagsButton() { +export function initRepoDiffCommitBranchesAndTags() { for (const area of document.querySelectorAll('.branch-and-tag-area')) { const btn = area.querySelector('.load-branches-and-tags'); btn.addEventListener('click', () => loadBranchesAndTags(area, btn)); diff --git a/web_src/js/index.js b/web_src/js/index.js index 98b2de68a853d..8bd219bbe1576 100644 --- a/web_src/js/index.js +++ b/web_src/js/index.js @@ -83,7 +83,7 @@ import {initGiteaFomantic} from './modules/fomantic.js'; import {onDomReady} from './utils/dom.js'; import {initRepoIssueList} from './features/repo-issue-list.js'; import {initCommonIssueListQuickGoto} from './features/common-issue-list.js'; -import {initLoadBranchesAndTagsButton} from './features/load-branches-and-tags.js'; +import {initRepoDiffCommitBranchesAndTags} from './features/repo-diff-commit.js'; // Init Gitea's Fomantic settings initGiteaFomantic(); @@ -142,6 +142,7 @@ onDomReady(() => { initRepoCodeView(); initRepoCommentForm(); initRepoEllipsisButton(); + initRepoDiffCommitBranchesAndTags(); initRepoCommitLastCommitLoader(); initRepoEditor(); initRepoGraphGit(); @@ -180,6 +181,4 @@ onDomReady(() => { initRepoDiffView(); initPdfViewer(); initScopedAccessTokenCategories(); - - initLoadBranchesAndTagsButton(); }); From c573defad7f4e26c397c541279d25374ea8966ed Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Wed, 26 Jul 2023 23:12:56 +0800 Subject: [PATCH 33/33] revert the "icon" position --- templates/repo/commit_load_branches_and_tags.tmpl | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/templates/repo/commit_load_branches_and_tags.tmpl b/templates/repo/commit_load_branches_and_tags.tmpl index cfc6ec3404ce5..c19aa55c56197 100644 --- a/templates/repo/commit_load_branches_and_tags.tmpl +++ b/templates/repo/commit_load_branches_and_tags.tmpl @@ -6,7 +6,13 @@
{{.locale.Tr "repo.commit.contained_in"}}
-
{{svg "octicon-git-branch"}}
-
{{svg "octicon-tag"}}
+
+
{{svg "octicon-git-branch"}}
+
+
+
+
{{svg "octicon-tag"}}
+
+