Skip to content

Commit e89b88b

Browse files
authored
Merge branch 'main' into add-n-commits-link
2 parents 335cd35 + 566f535 commit e89b88b

File tree

21 files changed

+353
-133
lines changed

21 files changed

+353
-133
lines changed

.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/db/context_committer_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
package db // it's not db_test, because this file is for testing the private type halfCommitter
55

66
import (
7-
"fmt"
7+
"errors"
88
"testing"
99

1010
"github.com/stretchr/testify/assert"
@@ -80,7 +80,7 @@ func Test_halfCommitter(t *testing.T) {
8080
testWithCommitter(mockCommitter, func(committer Committer) error {
8181
defer committer.Close()
8282
if true {
83-
return fmt.Errorf("error")
83+
return errors.New("error")
8484
}
8585
return committer.Commit()
8686
})
@@ -94,7 +94,7 @@ func Test_halfCommitter(t *testing.T) {
9494
testWithCommitter(mockCommitter, func(committer Committer) error {
9595
committer.Close()
9696
committer.Commit()
97-
return fmt.Errorf("error")
97+
return errors.New("error")
9898
})
9999

100100
mockCommitter.Assert(t)

modules/git/commit.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,3 +474,17 @@ func (c *Commit) GetRepositoryDefaultPublicGPGKey(forceUpdate bool) (*GPGSetting
474474
}
475475
return c.repo.GetDefaultPublicGPGKey(forceUpdate)
476476
}
477+
478+
func IsStringLikelyCommitID(objFmt ObjectFormat, s string, minLength ...int) bool {
479+
minLen := util.OptionalArg(minLength, objFmt.FullLength())
480+
if len(s) < minLen || len(s) > objFmt.FullLength() {
481+
return false
482+
}
483+
for _, c := range s {
484+
isHex := (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f')
485+
if !isHex {
486+
return false
487+
}
488+
}
489+
return true
490+
}

modules/git/ref.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ func (ref RefName) RemoteName() string {
142142

143143
// ShortName returns the short name of the reference name
144144
func (ref RefName) ShortName() string {
145-
refName := string(ref)
146145
if ref.IsBranch() {
147146
return ref.BranchName()
148147
}
@@ -158,8 +157,7 @@ func (ref RefName) ShortName() string {
158157
if ref.IsFor() {
159158
return ref.ForBranchName()
160159
}
161-
162-
return refName
160+
return string(ref) // usually it is a commit ID
163161
}
164162

165163
// RefGroup returns the group type of the reference

modules/git/repo_ref.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,31 @@ func parseTags(refs []string) []string {
6161
}
6262
return results
6363
}
64+
65+
// UnstableGuessRefByShortName does the best guess to see whether a "short name" provided by user is a branch, tag or commit.
66+
// It could guess wrongly if the input is already ambiguous. For example:
67+
// * "refs/heads/the-name" vs "refs/heads/refs/heads/the-name"
68+
// * "refs/tags/1234567890" vs commit "1234567890"
69+
// In most cases, it SHOULD AVOID using this function, unless there is an irresistible reason (eg: make API friendly to end users)
70+
// If the function is used, the caller SHOULD CHECK the ref type carefully.
71+
func (repo *Repository) UnstableGuessRefByShortName(shortName string) RefName {
72+
if repo.IsBranchExist(shortName) {
73+
return RefNameFromBranch(shortName)
74+
}
75+
if repo.IsTagExist(shortName) {
76+
return RefNameFromTag(shortName)
77+
}
78+
if strings.HasPrefix(shortName, "refs/") {
79+
if repo.IsReferenceExist(shortName) {
80+
return RefName(shortName)
81+
}
82+
}
83+
commit, err := repo.GetCommit(shortName)
84+
if err == nil {
85+
commitIDString := commit.ID.String()
86+
if strings.HasPrefix(commitIDString, shortName) {
87+
return RefName(commitIDString)
88+
}
89+
}
90+
return ""
91+
}

modules/globallock/globallock_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func TestLockAndDo(t *testing.T) {
6464
}
6565

6666
func testLockAndDo(t *testing.T) {
67-
const concurrency = 1000
67+
const concurrency = 50
6868

6969
ctx := context.Background()
7070
count := 0

modules/structs/repo.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,16 @@ type CreateBranchRepoOption struct {
278278
OldRefName string `json:"old_ref_name" binding:"GitRefName;MaxSize(100)"`
279279
}
280280

281+
// UpdateBranchRepoOption options when updating a branch in a repository
282+
// swagger:model
283+
type UpdateBranchRepoOption struct {
284+
// New branch name
285+
//
286+
// required: true
287+
// unique: true
288+
Name string `json:"name" binding:"Required;GitRefName;MaxSize(100)"`
289+
}
290+
281291
// TransferRepoOption options when transfer a repository's ownership
282292
// swagger:model
283293
type TransferRepoOption struct {

routers/api/v1/api.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,6 +1195,7 @@ func Routes() *web.Router {
11951195
m.Get("/*", repo.GetBranch)
11961196
m.Delete("/*", reqToken(), reqRepoWriter(unit.TypeCode), mustNotBeArchived, repo.DeleteBranch)
11971197
m.Post("", reqToken(), reqRepoWriter(unit.TypeCode), mustNotBeArchived, bind(api.CreateBranchRepoOption{}), repo.CreateBranch)
1198+
m.Patch("/*", reqToken(), reqRepoWriter(unit.TypeCode), mustNotBeArchived, bind(api.UpdateBranchRepoOption{}), repo.UpdateBranch)
11981199
}, context.ReferencesGitRepo(), reqRepoReader(unit.TypeCode))
11991200
m.Group("/branch_protections", func() {
12001201
m.Get("", repo.ListBranchProtections)

0 commit comments

Comments
 (0)