Skip to content

Commit 2c743bd

Browse files
authored
Merge branch 'main' into unprotected-files
2 parents 3cb9819 + 57b0887 commit 2c743bd

File tree

35 files changed

+395
-181
lines changed

35 files changed

+395
-181
lines changed

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,9 @@ test\#%:
385385

386386
.PHONY: coverage
387387
coverage:
388-
GO111MODULE=on $(GO) run -mod=vendor build/gocovmerge.go integration.coverage.out coverage.out > coverage.all
388+
grep '^\(mode: .*\)\|\(.*:[0-9]\+\.[0-9]\+,[0-9]\+\.[0-9]\+ [0-9]\+ [0-9]\+\)$$' coverage.out > coverage-bodged.out
389+
grep '^\(mode: .*\)\|\(.*:[0-9]\+\.[0-9]\+,[0-9]\+\.[0-9]\+ [0-9]\+ [0-9]\+\)$$' integration.coverage.out > integration.coverage-bodged.out
390+
GO111MODULE=on $(GO) run -mod=vendor build/gocovmerge.go integration.coverage-bodged.out coverage-bodged.out > coverage.all || (echo "gocovmerge failed"; echo "integration.coverage.out"; cat integration.coverage.out; echo "coverage.out"; cat coverage.out; exit 1)
389391

390392
.PHONY: unit-test-coverage
391393
unit-test-coverage:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<a href="https://codecov.io/gh/go-gitea/gitea" title="Codecov">
1616
<img src="https://codecov.io/gh/go-gitea/gitea/branch/main/graph/badge.svg">
1717
</a>
18-
<a href="https://godoc.org/code.gitea.io/gitea" title="Go Report Card">
18+
<a href="https://goreportcard.com/report/code.gitea.io/gitea" title="Go Report Card">
1919
<img src="https://goreportcard.com/badge/code.gitea.io/gitea">
2020
</a>
2121
<a href="https://godoc.org/code.gitea.io/gitea" title="GoDoc">

README_ZH.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<a href="https://codecov.io/gh/go-gitea/gitea" title="Codecov">
1616
<img src="https://codecov.io/gh/go-gitea/gitea/branch/main/graph/badge.svg">
1717
</a>
18-
<a href="https://godoc.org/code.gitea.io/gitea" title="Go Report Card">
18+
<a href="https://goreportcard.com/report/code.gitea.io/gitea" title="Go Report Card">
1919
<img src="https://goreportcard.com/badge/code.gitea.io/gitea">
2020
</a>
2121
<a href="https://godoc.org/code.gitea.io/gitea" title="GoDoc">

integrations/api_repo_lfs_test.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,10 @@ func TestAPILFSBatch(t *testing.T) {
253253
assert.NoError(t, err)
254254
assert.True(t, exist)
255255

256+
repo2 := createLFSTestRepository(t, "batch2")
257+
content := []byte("dummy0")
258+
storeObjectInRepo(t, repo2.ID, &content)
259+
256260
meta, err := repo.GetLFSMetaObjectByOid(p.Oid)
257261
assert.Nil(t, meta)
258262
assert.Equal(t, models.ErrLFSObjectNotExist, err)
@@ -358,13 +362,19 @@ func TestAPILFSUpload(t *testing.T) {
358362
assert.Nil(t, meta)
359363
assert.Equal(t, models.ErrLFSObjectNotExist, err)
360364

361-
req := newRequest(t, p, "")
365+
t.Run("InvalidAccess", func(t *testing.T) {
366+
req := newRequest(t, p, "invalid")
367+
session.MakeRequest(t, req, http.StatusUnprocessableEntity)
368+
})
362369

363-
session.MakeRequest(t, req, http.StatusOK)
370+
t.Run("ValidAccess", func(t *testing.T) {
371+
req := newRequest(t, p, "dummy5")
364372

365-
meta, err = repo.GetLFSMetaObjectByOid(p.Oid)
366-
assert.NoError(t, err)
367-
assert.NotNil(t, meta)
373+
session.MakeRequest(t, req, http.StatusOK)
374+
meta, err = repo.GetLFSMetaObjectByOid(p.Oid)
375+
assert.NoError(t, err)
376+
assert.NotNil(t, meta)
377+
})
368378
})
369379

370380
t.Run("MetaAlreadyExists", func(t *testing.T) {

integrations/pull_update_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,34 @@ func TestAPIPullUpdate(t *testing.T) {
4747
})
4848
}
4949

50+
func TestAPIPullUpdateByRebase(t *testing.T) {
51+
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
52+
//Create PR to test
53+
user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
54+
org26 := models.AssertExistsAndLoadBean(t, &models.User{ID: 26}).(*models.User)
55+
pr := createOutdatedPR(t, user, org26)
56+
57+
//Test GetDiverging
58+
diffCount, err := pull_service.GetDiverging(pr)
59+
assert.NoError(t, err)
60+
assert.EqualValues(t, 1, diffCount.Behind)
61+
assert.EqualValues(t, 1, diffCount.Ahead)
62+
assert.NoError(t, pr.LoadBaseRepo())
63+
assert.NoError(t, pr.LoadIssue())
64+
65+
session := loginUser(t, "user2")
66+
token := getTokenForLoggedInUser(t, session)
67+
req := NewRequestf(t, "POST", "/api/v1/repos/%s/%s/pulls/%d/update?style=rebase&token="+token, pr.BaseRepo.OwnerName, pr.BaseRepo.Name, pr.Issue.Index)
68+
session.MakeRequest(t, req, http.StatusOK)
69+
70+
//Test GetDiverging after update
71+
diffCount, err = pull_service.GetDiverging(pr)
72+
assert.NoError(t, err)
73+
assert.EqualValues(t, 0, diffCount.Behind)
74+
assert.EqualValues(t, 1, diffCount.Ahead)
75+
})
76+
}
77+
5078
func createOutdatedPR(t *testing.T, actor, forkOrg *models.User) *models.PullRequest {
5179
baseRepo, err := repo_service.CreateRepository(actor, actor, models.CreateRepoOptions{
5280
Name: "repo-pr-update",

models/org.go

Lines changed: 56 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -421,23 +421,67 @@ func GetOrgsByUserID(userID int64, showAll bool) ([]*User, error) {
421421
return getOrgsByUserID(sess, userID, showAll)
422422
}
423423

424-
// queryUserOrgIDs returns a condition to return user's organization id
425-
func queryUserOrgIDs(uid int64) *builder.Builder {
426-
return builder.Select("team.org_id").
427-
From("team_user").InnerJoin("team", "team.id = team_user.team_id").
428-
Where(builder.Eq{"team_user.uid": uid})
429-
}
430-
431424
// MinimalOrg represents a simple orgnization with only needed columns
432425
type MinimalOrg = User
433426

434427
// GetUserOrgsList returns one user's all orgs list
435-
func GetUserOrgsList(uid int64) ([]*MinimalOrg, error) {
436-
var orgs = make([]*MinimalOrg, 0, 20)
437-
return orgs, x.Select("id, name, full_name, visibility, avatar, avatar_email, use_custom_avatar").
428+
func GetUserOrgsList(user *User) ([]*MinimalOrg, error) {
429+
sess := x.NewSession()
430+
defer sess.Close()
431+
432+
schema, err := x.TableInfo(new(User))
433+
if err != nil {
434+
return nil, err
435+
}
436+
437+
outputCols := []string{
438+
"id",
439+
"name",
440+
"full_name",
441+
"visibility",
442+
"avatar",
443+
"avatar_email",
444+
"use_custom_avatar",
445+
}
446+
447+
groupByCols := &strings.Builder{}
448+
for _, col := range outputCols {
449+
fmt.Fprintf(groupByCols, "`%s`.%s,", schema.Name, col)
450+
}
451+
groupByStr := groupByCols.String()
452+
groupByStr = groupByStr[0 : len(groupByStr)-1]
453+
454+
sess.Select(groupByStr+", count(repo_id) as org_count").
438455
Table("user").
439-
In("id", queryUserOrgIDs(uid)).
440-
Find(&orgs)
456+
Join("INNER", "team", "`team`.org_id = `user`.id").
457+
Join("INNER", "team_user", "`team`.id = `team_user`.team_id").
458+
Join("LEFT", builder.
459+
Select("id as repo_id, owner_id as repo_owner_id").
460+
From("repository").
461+
Where(accessibleRepositoryCondition(user)), "`repository`.repo_owner_id = `team`.org_id").
462+
Where("`team_user`.uid = ?", user.ID).
463+
GroupBy(groupByStr)
464+
465+
type OrgCount struct {
466+
User `xorm:"extends"`
467+
OrgCount int
468+
}
469+
470+
orgCounts := make([]*OrgCount, 0, 10)
471+
472+
if err := sess.
473+
Asc("`user`.name").
474+
Find(&orgCounts); err != nil {
475+
return nil, err
476+
}
477+
478+
orgs := make([]*MinimalOrg, len(orgCounts))
479+
for i, orgCount := range orgCounts {
480+
orgCount.User.NumRepos = orgCount.OrgCount
481+
orgs[i] = &orgCount.User
482+
}
483+
484+
return orgs, nil
441485
}
442486

443487
func getOwnedOrgsByUserID(sess *xorm.Session, userID int64) ([]*User, error) {

models/pull.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,8 @@ const (
373373
MergeStyleSquash MergeStyle = "squash"
374374
// MergeStyleManuallyMerged pr has been merged manually, just mark it as merged directly
375375
MergeStyleManuallyMerged MergeStyle = "manually-merged"
376+
// MergeStyleRebaseUpdate not a merge style, used to update pull head by rebase
377+
MergeStyleRebaseUpdate MergeStyle = "rebase-update-only"
376378
)
377379

378380
// SetMerged sets a pull request to merged and closes the corresponding issue

models/repo.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,6 +1497,11 @@ func DeleteRepository(doer *User, uid, repoID int64) error {
14971497
releaseAttachments = append(releaseAttachments, attachments[i].RelativePath())
14981498
}
14991499

1500+
if _, err = sess.In("release_id", builder.Select("id").From("`release`").Where(builder.Eq{"`release`.repo_id": repoID})).
1501+
Delete(&Attachment{}); err != nil {
1502+
return err
1503+
}
1504+
15001505
if _, err := sess.Exec("UPDATE `user` SET num_stars=num_stars-1 WHERE id IN (SELECT `uid` FROM `star` WHERE repo_id = ?)", repo.ID); err != nil {
15011506
return err
15021507
}

modules/git/blob_nogogit.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ func (b *Blob) DataAsync() (io.ReadCloser, error) {
4747

4848
if size < 4096 {
4949
bs, err := ioutil.ReadAll(io.LimitReader(rd, size))
50+
defer cancel()
5051
if err != nil {
51-
cancel()
5252
return nil, err
5353
}
5454
_, err = rd.Discard(1)
@@ -106,27 +106,25 @@ func (b *blobReader) Read(p []byte) (n int, err error) {
106106

107107
// Close implements io.Closer
108108
func (b *blobReader) Close() error {
109+
defer b.cancel()
109110
if b.n > 0 {
110111
for b.n > math.MaxInt32 {
111112
n, err := b.rd.Discard(math.MaxInt32)
112113
b.n -= int64(n)
113114
if err != nil {
114-
b.cancel()
115115
return err
116116
}
117117
b.n -= math.MaxInt32
118118
}
119119
n, err := b.rd.Discard(int(b.n))
120120
b.n -= int64(n)
121121
if err != nil {
122-
b.cancel()
123122
return err
124123
}
125124
}
126125
if b.n == 0 {
127126
_, err := b.rd.Discard(1)
128127
b.n--
129-
b.cancel()
130128
return err
131129
}
132130
return nil

modules/migrations/dump.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"net/http"
1212
"net/url"
1313
"os"
14+
"path"
1415
"path/filepath"
1516
"strconv"
1617
"strings"
@@ -481,7 +482,9 @@ func (g *RepositoryDumper) CreatePullRequests(prs ...*base.PullRequest) error {
481482
if err != nil {
482483
log.Error("Fetch branch from %s failed: %v", pr.Head.CloneURL, err)
483484
} else {
484-
headBranch := filepath.Join(g.gitPath(), "refs", "heads", pr.Head.OwnerName, pr.Head.Ref)
485+
// a new branch name with <original_owner_name/original_branchname> will be created to as new head branch
486+
ref := path.Join(pr.Head.OwnerName, pr.Head.Ref)
487+
headBranch := filepath.Join(g.gitPath(), "refs", "heads", ref)
485488
if err := os.MkdirAll(filepath.Dir(headBranch), os.ModePerm); err != nil {
486489
return err
487490
}
@@ -494,10 +497,14 @@ func (g *RepositoryDumper) CreatePullRequests(prs ...*base.PullRequest) error {
494497
if err != nil {
495498
return err
496499
}
500+
pr.Head.Ref = ref
497501
}
498502
}
499503
}
500504
}
505+
// whatever it's a forked repo PR, we have to change head info as the same as the base info
506+
pr.Head.OwnerName = pr.Base.OwnerName
507+
pr.Head.RepoName = pr.Base.RepoName
501508
}
502509

503510
var err error

modules/migrations/gitea_uploader.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ func (g *GiteaLocalUploader) CreateReleases(releases ...*base.Release) error {
278278
if !release.Draft {
279279
commit, err := g.gitRepo.GetTagCommit(rel.TagName)
280280
if err != nil {
281-
return fmt.Errorf("GetCommit: %v", err)
281+
return fmt.Errorf("GetTagCommit[%v]: %v", rel.TagName, err)
282282
}
283283
rel.NumCommits, err = commit.CommitsCount()
284284
if err != nil {

modules/private/restore_repo.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ func RestoreRepo(ctx context.Context, repoDir, ownerName, repoName string, units
5454
if err := json.Unmarshal(body, &ret); err != nil {
5555
return http.StatusInternalServerError, fmt.Sprintf("Response body Unmarshal error: %v", err.Error())
5656
}
57+
return http.StatusInternalServerError, ret.Err
5758
}
5859

5960
return http.StatusOK, fmt.Sprintf("Restore repo %s/%s successfully", ownerName, repoName)

modules/setting/queue.go

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ package setting
77
import (
88
"fmt"
99
"path/filepath"
10-
"strconv"
11-
"strings"
1210
"time"
1311

1412
"code.gitea.io/gitea/modules/log"
@@ -22,12 +20,8 @@ type QueueSettings struct {
2220
BatchLength int
2321
ConnectionString string
2422
Type string
25-
Network string
26-
Addresses string
27-
Password string
2823
QueueName string
2924
SetName string
30-
DBIndex int
3125
WrapIfNecessary bool
3226
MaxAttempts int
3327
Timeout time.Duration
@@ -83,7 +77,6 @@ func GetQueueSettings(name string) QueueSettings {
8377
q.BoostTimeout = sec.Key("BOOST_TIMEOUT").MustDuration(Queue.BoostTimeout)
8478
q.BoostWorkers = sec.Key("BOOST_WORKERS").MustInt(Queue.BoostWorkers)
8579

86-
q.Network, q.Addresses, q.Password, q.DBIndex, _ = ParseQueueConnStr(q.ConnectionString)
8780
return q
8881
}
8982

@@ -100,7 +93,6 @@ func NewQueueService() {
10093
Queue.ConnectionString = sec.Key("CONN_STR").MustString("")
10194
defaultType := sec.Key("TYPE").String()
10295
Queue.Type = sec.Key("TYPE").MustString("persistable-channel")
103-
Queue.Network, Queue.Addresses, Queue.Password, Queue.DBIndex, _ = ParseQueueConnStr(Queue.ConnectionString)
10496
Queue.WrapIfNecessary = sec.Key("WRAP_IF_NECESSARY").MustBool(true)
10597
Queue.MaxAttempts = sec.Key("MAX_ATTEMPTS").MustInt(10)
10698
Queue.Timeout = sec.Key("TIMEOUT").MustDuration(GracefulHammerTime + 30*time.Second)
@@ -167,28 +159,3 @@ func NewQueueService() {
167159
_, _ = section.NewKey("LENGTH", fmt.Sprintf("%d", Repository.PullRequestQueueLength))
168160
}
169161
}
170-
171-
// ParseQueueConnStr parses a queue connection string
172-
func ParseQueueConnStr(connStr string) (network, addrs, password string, dbIdx int, err error) {
173-
fields := strings.Fields(connStr)
174-
for _, f := range fields {
175-
items := strings.SplitN(f, "=", 2)
176-
if len(items) < 2 {
177-
continue
178-
}
179-
switch strings.ToLower(items[0]) {
180-
case "network":
181-
network = items[1]
182-
case "addrs":
183-
addrs = items[1]
184-
case "password":
185-
password = items[1]
186-
case "db":
187-
dbIdx, err = strconv.Atoi(items[1])
188-
if err != nil {
189-
return
190-
}
191-
}
192-
}
193-
return
194-
}

options/locale/locale_en-US.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1468,7 +1468,8 @@ pulls.status_checks_failure = Some checks failed
14681468
pulls.status_checks_error = Some checks reported errors
14691469
pulls.status_checks_requested = Required
14701470
pulls.status_checks_details = Details
1471-
pulls.update_branch = Update branch
1471+
pulls.update_branch = Update branch by merge
1472+
pulls.update_branch_rebase = Update branch by rebase
14721473
pulls.update_branch_success = Branch update was successful
14731474
pulls.update_not_allowed = You are not allowed to update branch
14741475
pulls.outdated_with_base_branch = This branch is out-of-date with the base branch

routers/api/v1/admin/org.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ func GetAllOrgs(ctx *context.APIContext) {
105105
listOptions := utils.GetListOptions(ctx)
106106

107107
users, maxResults, err := models.SearchUsers(&models.SearchUserOptions{
108+
Actor: ctx.User,
108109
Type: models.UserTypeOrganization,
109110
OrderBy: models.SearchOrderByAlphabetically,
110111
ListOptions: listOptions,

routers/api/v1/org/org.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ func GetAll(ctx *context.APIContext) {
128128
listOptions := utils.GetListOptions(ctx)
129129

130130
publicOrgs, maxResults, err := models.SearchUsers(&models.SearchUserOptions{
131+
Actor: ctx.User,
131132
ListOptions: listOptions,
132133
Type: models.UserTypeOrganization,
133134
OrderBy: models.SearchOrderByAlphabetically,

0 commit comments

Comments
 (0)