-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Show branches and tags that contain a commit #25180
Merged
delvh
merged 45 commits into
go-gitea:main
from
delvh:feature/load-referencing-branches-and-tags
Jul 27, 2023
Merged
Changes from 9 commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
60cc93e
Add barebones frontend structure
delvh 1975e64
Add complete backend for loading tags and branches of a commit
delvh ff62d3c
Merge branch 'main' into feature/load-referencing-branches-and-tags
delvh 8adb11b
Complete the frontend and backend functionality
delvh be8cd4e
Make all borders rounded, increase margin between tags and commits
delvh b311b53
Remove dead code
delvh 0b39f9e
Move translation key and print error on browser console
delvh a433b56
Apparently, I don't like our too strict linter
delvh 73f31f8
Hopefully, please linter this time
delvh 9599991
Linter: 3, delvh: 0
delvh 83b9251
Use a better icon for the button as per @silverwind
delvh ef53879
Linter: 4, delvh: 0
delvh c87b361
Align branches/tags on their respective icon as per @silverwind + @KN…
delvh 4e80dca
Merge branch 'main' into feature/load-referencing-branches-and-tags
silverwind 7962907
I guess that's why the linter fails?
delvh e1efe08
Do not show branch/tag icon when this commit is not contained anywhere
delvh 2b55713
Rename `response` -> `res`
delvh 6983dc4
Batch add classes
delvh f75db06
`text` -> `textContent`
delvh c8ea65b
Convert "load" button to an ellipsis-button
delvh 82d3222
Let's hope the linter likes the line-splitting
delvh d37c790
Split even more lines
delvh 8d011d2
Remove information that is now redundant
delvh e3002bc
Merge branch 'main' into feature/load-referencing-branches-and-tags
delvh 42712b5
Apparently the merge went wrong
delvh 48c225e
Fix typo in translated string
delvh c9eba48
Merge branch 'main' into feature/load-referencing-branches-and-tags
silverwind 0969a39
Implement suggestions by @wxiaoguang
delvh b009c77
Separate ellipsis-button into ellipsis-button and ellipsis-js-button
delvh 97956cf
Fix formatting
delvh 7206f0f
Improve formatting
delvh 6818614
Merge branch 'main' into feature/load-referencing-branches-and-tags
delvh f335dd1
Merge branch 'main' into feature/load-referencing-branches-and-tags
delvh 0012681
Merge branch 'main' into feature/load-referencing-branches-and-tags
delvh b0f5f48
Merge branch 'main' into feature/load-referencing-branches-and-tags
wxiaoguang e91843a
temp fix
wxiaoguang 666a019
fix
wxiaoguang 672f0bb
fix
wxiaoguang bf96470
fix
wxiaoguang e5effc8
rename
wxiaoguang c573def
revert the "icon" position
wxiaoguang 23319d6
Merge branch 'main' into feature/load-referencing-branches-and-tags
delvh f17c4d4
Merge branch 'main' into feature/load-referencing-branches-and-tags
GiteaBot 07a31b9
Merge branch 'main' into feature/load-referencing-branches-and-tags
GiteaBot d52dbd4
Merge branch 'main' into feature/load-referencing-branches-and-tags
GiteaBot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright 2023 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package repository | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
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"` | ||
ContainedInDefaultBranch bool `json:"contained_in_default_branch"` | ||
DefaultBranch string `json:"default_branch"` | ||
} | ||
|
||
type namedLink struct { // TODO: better name? | ||
Name string `json:"name"` | ||
WebLink string `json:"web_url"` | ||
delvh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
// 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{ | ||
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 | ||
} | ||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<div class="branch-and-tag-area"> | ||
<button class="btn interact-bg gt-df gt-ac gt-mt-3 load-tags-and-branches" data-fetch-url="{{.RepoLink}}/commit/{{.CommitID}}/load-branches-and-tags" data-tooltip-content="{{.locale.Tr "repo.commit.load_referencing_branches_and_tags"}}" data-contained-in-text="{{.locale.Tr "repo.commit.contained_in"}}"> | ||
{{svg "octicon-git-branch" 12}}{{svg "octicon-tag" 12}}{{svg "octicon-plus" 16}} | ||
</button> | ||
<div class="ui divider branch-tag-area-divider gt-hidden"></div> | ||
<div class="branch-tag-area-text gt-df"></div> | ||
<div class="branch-area gt-df gt-ac gt-flex-wrap gt-my-3 gt-hidden" data-defaultbranch-tooltip="{{.locale.Tr "repo.commit.contained_in_default_branch"}}">{{svg "octicon-git-branch"}}</div> | ||
<div class="tag-area gt-df gt-ac gt-flex-wrap gt-hidden">{{svg "octicon-tag"}}</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
const {csrfToken} = window.config; | ||
|
||
async function loadBranchesAndTags(loadingButton, addHere) { | ||
loadingButton.setAttribute('disabled', 'disabled'); | ||
delvh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const response = await fetch(loadingButton.getAttribute('data-fetch-url'), { | ||
method: 'GET', | ||
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'); | ||
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, 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); | ||
delvh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
function showAreas(selector) { | ||
for (const branchArea of document.querySelectorAll(selector)) branchArea.classList.remove('gt-hidden'); | ||
delvh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
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'); | ||
delvh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (tooltip) { | ||
link.classList.add('gt-border-secondary'); | ||
link.setAttribute('data-tooltip-content', tooltip); | ||
} | ||
link.href = href; | ||
link.text = text; | ||
delvh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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'))); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note regarding the changes (above this line) in this file:
They are unused already, hence I removed them.
Below this line was made redundant through this PR.