Skip to content

Commit 58581b1

Browse files
authored
Merge branch 'main' into fix/lfs-migration
2 parents 4d6fb0b + ab6d819 commit 58581b1

File tree

14 files changed

+112
-28
lines changed

14 files changed

+112
-28
lines changed

.github/actionlint.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ self-hosted-runner:
33
- actuated-4cpu-8gb
44
- actuated-4cpu-16gb
55
- nscloud
6+
- namespace-profile-gitea-release-docker
7+
- namespace-profile-gitea-release-binary

models/actions/run.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ type ActionRun struct {
3737
TriggerUser *user_model.User `xorm:"-"`
3838
ScheduleID int64
3939
Ref string `xorm:"index"` // the commit/tag/… that caused the run
40+
IsRefDeleted bool `xorm:"-"`
4041
CommitSHA string
4142
IsForkPullRequest bool // If this is triggered by a PR from a forked repository or an untrusted user, we need to check if it is approved and limit permissions when running the workflow.
4243
NeedApproval bool // may need approval if it's a fork pull request

models/git/branch.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
repo_model "code.gitea.io/gitea/models/repo"
1313
"code.gitea.io/gitea/models/unit"
1414
user_model "code.gitea.io/gitea/models/user"
15+
"code.gitea.io/gitea/modules/container"
1516
"code.gitea.io/gitea/modules/git"
1617
"code.gitea.io/gitea/modules/log"
1718
"code.gitea.io/gitea/modules/optional"
@@ -169,9 +170,22 @@ func GetBranch(ctx context.Context, repoID int64, branchName string) (*Branch, e
169170
return &branch, nil
170171
}
171172

172-
func GetBranches(ctx context.Context, repoID int64, branchNames []string) ([]*Branch, error) {
173+
func GetBranches(ctx context.Context, repoID int64, branchNames []string, includeDeleted bool) ([]*Branch, error) {
173174
branches := make([]*Branch, 0, len(branchNames))
174-
return branches, db.GetEngine(ctx).Where("repo_id=?", repoID).In("name", branchNames).Find(&branches)
175+
176+
sess := db.GetEngine(ctx).Where("repo_id=?", repoID).In("name", branchNames)
177+
if !includeDeleted {
178+
sess.And("is_deleted=?", false)
179+
}
180+
return branches, sess.Find(&branches)
181+
}
182+
183+
func BranchesToNamesSet(branches []*Branch) container.Set[string] {
184+
names := make(container.Set[string], len(branches))
185+
for _, branch := range branches {
186+
names.Add(branch.Name)
187+
}
188+
return names
175189
}
176190

177191
func AddBranches(ctx context.Context, branches []*Branch) error {

routers/web/repo/actions/actions.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,10 @@ func List(ctx *context.Context) {
245245
return
246246
}
247247

248+
if err := loadIsRefDeleted(ctx, runs); err != nil {
249+
log.Error("LoadIsRefDeleted", err)
250+
}
251+
248252
ctx.Data["Runs"] = runs
249253

250254
actors, err := actions_model.GetActors(ctx, ctx.Repo.Repository.ID)
@@ -267,6 +271,34 @@ func List(ctx *context.Context) {
267271
ctx.HTML(http.StatusOK, tplListActions)
268272
}
269273

274+
// loadIsRefDeleted loads the IsRefDeleted field for each run in the list.
275+
// TODO: move this function to models/actions/run_list.go but now it will result in a circular import.
276+
func loadIsRefDeleted(ctx *context.Context, runs actions_model.RunList) error {
277+
branches := make(container.Set[string], len(runs))
278+
for _, run := range runs {
279+
refName := git.RefName(run.Ref)
280+
if refName.IsBranch() {
281+
branches.Add(refName.ShortName())
282+
}
283+
}
284+
if len(branches) == 0 {
285+
return nil
286+
}
287+
288+
branchInfos, err := git_model.GetBranches(ctx, ctx.Repo.Repository.ID, branches.Values(), false)
289+
if err != nil {
290+
return err
291+
}
292+
branchSet := git_model.BranchesToNamesSet(branchInfos)
293+
for _, run := range runs {
294+
refName := git.RefName(run.Ref)
295+
if refName.IsBranch() && !branchSet.Contains(run.Ref) {
296+
run.IsRefDeleted = true
297+
}
298+
}
299+
return nil
300+
}
301+
270302
type WorkflowDispatchInput struct {
271303
Name string `yaml:"name"`
272304
Description string `yaml:"description"`

routers/web/repo/actions/view.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919

2020
actions_model "code.gitea.io/gitea/models/actions"
2121
"code.gitea.io/gitea/models/db"
22+
git_model "code.gitea.io/gitea/models/git"
2223
"code.gitea.io/gitea/models/perm"
2324
access_model "code.gitea.io/gitea/models/perm/access"
2425
repo_model "code.gitea.io/gitea/models/repo"
@@ -136,8 +137,9 @@ type ViewUser struct {
136137
}
137138

138139
type ViewBranch struct {
139-
Name string `json:"name"`
140-
Link string `json:"link"`
140+
Name string `json:"name"`
141+
Link string `json:"link"`
142+
IsDeleted bool `json:"isDeleted"`
141143
}
142144

143145
type ViewJobStep struct {
@@ -236,6 +238,16 @@ func ViewPost(ctx *context_module.Context) {
236238
Name: run.PrettyRef(),
237239
Link: run.RefLink(),
238240
}
241+
refName := git.RefName(run.Ref)
242+
if refName.IsBranch() {
243+
b, err := git_model.GetBranch(ctx, ctx.Repo.Repository.ID, refName.ShortName())
244+
if err != nil && !git_model.IsErrBranchNotExist(err) {
245+
log.Error("GetBranch: %v", err)
246+
} else if git_model.IsErrBranchNotExist(err) || (b != nil && b.IsDeleted) {
247+
branch.IsDeleted = true
248+
}
249+
}
250+
239251
resp.State.Run.Commit = ViewCommit{
240252
ShortSha: base.ShortSha(run.CommitSHA),
241253
Link: fmt.Sprintf("%s/commit/%s", run.Repo.Link(), run.CommitSHA),

services/repository/branch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ func SyncBranchesToDB(ctx context.Context, repoID, pusherID int64, branchNames,
305305
}
306306

307307
return db.WithTx(ctx, func(ctx context.Context) error {
308-
branches, err := git_model.GetBranches(ctx, repoID, branchNames)
308+
branches, err := git_model.GetBranches(ctx, repoID, branchNames, true)
309309
if err != nil {
310310
return fmt.Errorf("git_model.GetBranches: %v", err)
311311
}

templates/repo/actions/runs_list.tmpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
</div>
2828
</div>
2929
<div class="flex-item-trailing">
30-
{{if .RefLink}}
31-
<a class="ui label run-list-ref gt-ellipsis" href="{{.RefLink}}">{{.PrettyRef}}</a>
30+
{{if .IsRefDeleted}}
31+
<span class="ui label run-list-ref gt-ellipsis tw-line-through" data-tooltip-content="{{.PrettyRef}}">{{.PrettyRef}}</span>
3232
{{else}}
33-
<span class="ui label run-list-ref gt-ellipsis">{{.PrettyRef}}</span>
33+
<a class="ui label run-list-ref gt-ellipsis" href="{{.RefLink}}" data-tooltip-content="{{.PrettyRef}}">{{.PrettyRef}}</a>
3434
{{end}}
3535
<div class="run-list-item-right">
3636
<div class="run-list-meta">{{svg "octicon-calendar" 16}}{{DateUtils.TimeSince .Updated}}</div>

templates/repo/contributors.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{{if .Permission.CanRead ctx.Consts.RepoUnitTypeCode}}
22
<div id="repo-contributors-chart"
33
data-repo-link="{{.RepoLink}}"
4+
data-repo-default-branch-name="{{.Repository.DefaultBranch}}"
45
data-locale-filter-label="{{ctx.Locale.Tr "repo.contributors.contribution_type.filter_label"}}"
56
data-locale-contribution-type-commits="{{ctx.Locale.Tr "repo.contributors.contribution_type.commits"}}"
67
data-locale-contribution-type-additions="{{ctx.Locale.Tr "repo.contributors.contribution_type.additions"}}"

templates/repo/diff/box.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@
167167
<button class="btn diff-header-popup-btn tw-p-1">{{svg "octicon-kebab-horizontal" 18}}</button>
168168
<div class="tippy-target">
169169
{{if not (or $file.IsIncomplete $file.IsBin $file.IsSubmodule)}}
170-
<button class="unescape-button item" data-file-content-elem-id="diff-{{$file.NameHash}}">{{ctx.Locale.Tr "repo.unescape_control_characters"}}</button>
171-
<button class="escape-button tw-hidden item" data-file-content-elem-id="diff-{{$file.NameHash}}">{{ctx.Locale.Tr "repo.escape_control_characters"}}</button>
170+
<button class="unescape-button item" data-unicode-content-selector="#diff-{{$file.NameHash}}">{{ctx.Locale.Tr "repo.unescape_control_characters"}}</button>
171+
<button class="escape-button tw-hidden item" data-unicode-content-selector="#diff-{{$file.NameHash}}">{{ctx.Locale.Tr "repo.escape_control_characters"}}</button>
172172
{{end}}
173173
{{if and (not $file.IsSubmodule) (not $.PageIsWiki)}}
174174
{{if $file.IsDeleted}}

templates/repo/wiki/view.tmpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@
4444
</div>
4545
<div class="repo-button-row">
4646
{{if .EscapeStatus.Escaped}}
47-
<a class="ui small button unescape-button tw-m-0 tw-hidden">{{ctx.Locale.Tr "repo.unescape_control_characters"}}</a>
48-
<a class="ui small button escape-button tw-m-0">{{ctx.Locale.Tr "repo.escape_control_characters"}}</a>
47+
<a class="ui small button unescape-button tw-hidden" data-unicode-content-selector=".wiki-content-parts">{{ctx.Locale.Tr "repo.unescape_control_characters"}}</a>
48+
<a class="ui small button escape-button" data-unicode-content-selector=".wiki-content-parts">{{ctx.Locale.Tr "repo.escape_control_characters"}}</a>
4949
{{end}}
5050
{{if and .CanWriteWiki (not .Repository.IsMirror)}}
5151
<a class="ui small button" href="{{.RepoLink}}/wiki/{{.PageURL}}?action=_edit">{{ctx.Locale.Tr "repo.wiki.edit_page_button"}}</a>
5252
<a class="ui small primary button" href="{{.RepoLink}}/wiki?action=_new">{{ctx.Locale.Tr "repo.wiki.new_page_button"}}</a>
53-
<a class="ui small red button tw-m-0 delete-button" href="" data-url="{{.RepoLink}}/wiki/{{.PageURL}}?action=_delete" data-id="{{.PageURL}}">{{ctx.Locale.Tr "repo.wiki.delete_page_button"}}</a>
53+
<a class="ui small red button delete-button" href="" data-url="{{.RepoLink}}/wiki/{{.PageURL}}?action=_delete" data-id="{{.PageURL}}">{{ctx.Locale.Tr "repo.wiki.delete_page_button"}}</a>
5454
{{end}}
5555
</div>
5656
</div>

0 commit comments

Comments
 (0)