Skip to content

Commit 27b6753

Browse files
committed
Merge branch 'main' into lunny/refactor_getpatch
2 parents 91147db + 0b8a894 commit 27b6753

File tree

20 files changed

+129
-38
lines changed

20 files changed

+129
-38
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

.github/workflows/release-nightly.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ concurrency:
1010

1111
jobs:
1212
nightly-binary:
13-
runs-on: nscloud
13+
runs-on: namespace-profile-gitea-release-binary
1414
steps:
1515
- uses: actions/checkout@v4
1616
# fetch all commits instead of only the last as some branches are long lived and could have many between versions
@@ -58,7 +58,7 @@ jobs:
5858
run: |
5959
aws s3 sync dist/release s3://${{ secrets.AWS_S3_BUCKET }}/gitea/${{ steps.clean_name.outputs.branch }} --no-progress
6060
nightly-docker-rootful:
61-
runs-on: ubuntu-latest
61+
runs-on: namespace-profile-gitea-release-docker
6262
steps:
6363
- uses: actions/checkout@v4
6464
# fetch all commits instead of only the last as some branches are long lived and could have many between versions
@@ -95,7 +95,7 @@ jobs:
9595
push: true
9696
tags: gitea/gitea:${{ steps.clean_name.outputs.branch }}
9797
nightly-docker-rootless:
98-
runs-on: ubuntu-latest
98+
runs-on: namespace-profile-gitea-release-docker
9999
steps:
100100
- uses: actions/checkout@v4
101101
# fetch all commits instead of only the last as some branches are long lived and could have many between versions

.github/workflows/release-tag-rc.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ concurrency:
1111

1212
jobs:
1313
binary:
14-
runs-on: nscloud
14+
runs-on: namespace-profile-gitea-release-binary
1515
steps:
1616
- uses: actions/checkout@v4
1717
# fetch all commits instead of only the last as some branches are long lived and could have many between versions
@@ -68,7 +68,7 @@ jobs:
6868
env:
6969
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
7070
docker-rootful:
71-
runs-on: ubuntu-latest
71+
runs-on: namespace-profile-gitea-release-docker
7272
steps:
7373
- uses: actions/checkout@v4
7474
# fetch all commits instead of only the last as some branches are long lived and could have many between versions
@@ -99,7 +99,7 @@ jobs:
9999
tags: ${{ steps.meta.outputs.tags }}
100100
labels: ${{ steps.meta.outputs.labels }}
101101
docker-rootless:
102-
runs-on: ubuntu-latest
102+
runs-on: namespace-profile-gitea-release-docker
103103
steps:
104104
- uses: actions/checkout@v4
105105
# fetch all commits instead of only the last as some branches are long lived and could have many between versions

.github/workflows/release-tag-version.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ concurrency:
1313

1414
jobs:
1515
binary:
16-
runs-on: nscloud
16+
runs-on: namespace-profile-gitea-release-binary
1717
steps:
1818
- uses: actions/checkout@v4
1919
# fetch all commits instead of only the last as some branches are long lived and could have many between versions
@@ -70,7 +70,7 @@ jobs:
7070
env:
7171
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
7272
docker-rootful:
73-
runs-on: ubuntu-latest
73+
runs-on: namespace-profile-gitea-release-docker
7474
steps:
7575
- uses: actions/checkout@v4
7676
# fetch all commits instead of only the last as some branches are long lived and could have many between versions
@@ -105,7 +105,7 @@ jobs:
105105
tags: ${{ steps.meta.outputs.tags }}
106106
labels: ${{ steps.meta.outputs.labels }}
107107
docker-rootless:
108-
runs-on: ubuntu-latest
108+
runs-on: namespace-profile-gitea-release-docker
109109
steps:
110110
- uses: actions/checkout@v4
111111
# fetch all commits instead of only the last as some branches are long lived and could have many between versions

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 {

modules/lfs/http_client.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ func createRequest(ctx context.Context, method, url string, headers map[string]s
236236
req.Header.Set(key, value)
237237
}
238238
req.Header.Set("Accept", AcceptHeader)
239+
req.Header.Set("User-Agent", UserAgentHeader)
239240

240241
return req, nil
241242
}

modules/lfs/shared.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ const (
1515
// MediaType contains the media type for LFS server requests
1616
MediaType = "application/vnd.git-lfs+json"
1717
// Some LFS servers offer content with other types, so fallback to '*/*' if application/vnd.git-lfs+json cannot be served
18-
AcceptHeader = "application/vnd.git-lfs+json;q=0.9, */*;q=0.8"
18+
AcceptHeader = "application/vnd.git-lfs+json;q=0.9, */*;q=0.8"
19+
UserAgentHeader = "git-lfs"
1920
)
2021

2122
// BatchRequest contains multiple requests processed in one batch operation.

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),

0 commit comments

Comments
 (0)