Skip to content

Commit 29cbfb8

Browse files
committed
Merge branch 'master' of https://github.com/go-gitea/gitea into mobile-tabs
2 parents 3a998ac + 5f8478a commit 29cbfb8

File tree

119 files changed

+807
-480
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

119 files changed

+807
-480
lines changed

integrations/api_pull_test.go

+72-1
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,79 @@ func TestAPICreatePullSuccess(t *testing.T) {
7474
Base: "master",
7575
Title: "create a failure pr",
7676
})
77-
7877
session.MakeRequest(t, req, 201)
78+
session.MakeRequest(t, req, http.StatusUnprocessableEntity) // second request should fail
79+
}
80+
81+
func TestAPICreatePullWithFieldsSuccess(t *testing.T) {
82+
defer prepareTestEnv(t)()
83+
// repo10 have code, pulls units.
84+
repo10 := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 10}).(*models.Repository)
85+
owner10 := models.AssertExistsAndLoadBean(t, &models.User{ID: repo10.OwnerID}).(*models.User)
86+
// repo11 only have code unit but should still create pulls
87+
repo11 := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 11}).(*models.Repository)
88+
owner11 := models.AssertExistsAndLoadBean(t, &models.User{ID: repo11.OwnerID}).(*models.User)
89+
90+
session := loginUser(t, owner11.Name)
91+
token := getTokenForLoggedInUser(t, session)
92+
93+
opts := &api.CreatePullRequestOption{
94+
Head: fmt.Sprintf("%s:master", owner11.Name),
95+
Base: "master",
96+
Title: "create a failure pr",
97+
Body: "foobaaar",
98+
Milestone: 5,
99+
Assignees: []string{owner10.Name},
100+
Labels: []int64{5},
101+
}
102+
103+
req := NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls?token=%s", owner10.Name, repo10.Name, token), opts)
104+
105+
res := session.MakeRequest(t, req, 201)
106+
pull := new(api.PullRequest)
107+
DecodeJSON(t, res, pull)
108+
109+
assert.NotNil(t, pull.Milestone)
110+
assert.EqualValues(t, opts.Milestone, pull.Milestone.ID)
111+
if assert.Len(t, pull.Assignees, 1) {
112+
assert.EqualValues(t, opts.Assignees[0], owner10.Name)
113+
}
114+
assert.NotNil(t, pull.Labels)
115+
assert.EqualValues(t, opts.Labels[0], pull.Labels[0].ID)
116+
}
117+
118+
func TestAPICreatePullWithFieldsFailure(t *testing.T) {
119+
defer prepareTestEnv(t)()
120+
// repo10 have code, pulls units.
121+
repo10 := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 10}).(*models.Repository)
122+
owner10 := models.AssertExistsAndLoadBean(t, &models.User{ID: repo10.OwnerID}).(*models.User)
123+
// repo11 only have code unit but should still create pulls
124+
repo11 := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 11}).(*models.Repository)
125+
owner11 := models.AssertExistsAndLoadBean(t, &models.User{ID: repo11.OwnerID}).(*models.User)
126+
127+
session := loginUser(t, owner11.Name)
128+
token := getTokenForLoggedInUser(t, session)
129+
130+
opts := &api.CreatePullRequestOption{
131+
Head: fmt.Sprintf("%s:master", owner11.Name),
132+
Base: "master",
133+
}
134+
135+
req := NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls?token=%s", owner10.Name, repo10.Name, token), opts)
136+
session.MakeRequest(t, req, http.StatusUnprocessableEntity)
137+
opts.Title = "is required"
138+
139+
opts.Milestone = 666
140+
session.MakeRequest(t, req, http.StatusUnprocessableEntity)
141+
opts.Milestone = 5
142+
143+
opts.Assignees = []string{"qweruqweroiuyqweoiruywqer"}
144+
session.MakeRequest(t, req, http.StatusUnprocessableEntity)
145+
opts.Assignees = []string{owner10.LoginName}
146+
147+
opts.Labels = []int64{55555}
148+
session.MakeRequest(t, req, http.StatusUnprocessableEntity)
149+
opts.Labels = []int64{5}
79150
}
80151

81152
func TestAPIEditPull(t *testing.T) {

integrations/git_test.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,10 @@ func rawTest(t *testing.T, ctx *APITestContext, little, big, littleLFS, bigLFS s
216216
req = NewRequest(t, "GET", path.Join("/", username, reponame, "/raw/branch/master/", littleLFS))
217217
resp = session.MakeRequest(t, req, http.StatusOK)
218218
assert.NotEqual(t, littleSize, resp.Body.Len())
219-
assert.Contains(t, resp.Body.String(), models.LFSMetaFileIdentifier)
219+
assert.LessOrEqual(t, resp.Body.Len(), 1024)
220+
if resp.Body.Len() != littleSize && resp.Body.Len() <= 1024 {
221+
assert.Contains(t, resp.Body.String(), models.LFSMetaFileIdentifier)
222+
}
220223
}
221224

222225
if !testing.Short() {
@@ -228,7 +231,9 @@ func rawTest(t *testing.T, ctx *APITestContext, little, big, littleLFS, bigLFS s
228231
req = NewRequest(t, "GET", path.Join("/", username, reponame, "/raw/branch/master/", bigLFS))
229232
resp = session.MakeRequest(t, req, http.StatusOK)
230233
assert.NotEqual(t, bigSize, resp.Body.Len())
231-
assert.Contains(t, resp.Body.String(), models.LFSMetaFileIdentifier)
234+
if resp.Body.Len() != bigSize && resp.Body.Len() <= 1024 {
235+
assert.Contains(t, resp.Body.String(), models.LFSMetaFileIdentifier)
236+
}
232237
}
233238
}
234239
})

models/access.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ func (user *User) GetRepositoryAccesses() (map[*Repository]AccessMode, error) {
121121
}
122122
defer rows.Close()
123123

124-
var repos = make(map[*Repository]AccessMode, 10)
125-
var ownerCache = make(map[int64]*User, 10)
124+
repos := make(map[*Repository]AccessMode, 10)
125+
ownerCache := make(map[int64]*User, 10)
126126
for rows.Next() {
127127
var repo repoAccess
128128
err = rows.Scan(&repo)

models/action.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ func (a *Action) GetRepoLink() string {
186186
}
187187

188188
// GetRepositoryFromMatch returns a *Repository from a username and repo strings
189-
func GetRepositoryFromMatch(ownerName string, repoName string) (*Repository, error) {
189+
func GetRepositoryFromMatch(ownerName, repoName string) (*Repository, error) {
190190
var err error
191191
refRepo, err := GetRepositoryByOwnerAndName(ownerName, repoName)
192192
if err != nil {
@@ -218,7 +218,7 @@ func (a *Action) getCommentLink(e Engine) string {
218218
if len(a.GetIssueInfos()) == 0 {
219219
return "#"
220220
}
221-
//Return link to issue
221+
// Return link to issue
222222
issueIDString := a.GetIssueInfos()[0]
223223
issueID, err := strconv.ParseInt(issueIDString, 10, 64)
224224
if err != nil {
@@ -322,7 +322,7 @@ func GetFeeds(opts GetFeedsOptions) ([]*Action, error) {
322322
return actions, nil
323323
}
324324

325-
func activityReadable(user *User, doer *User) bool {
325+
func activityReadable(user, doer *User) bool {
326326
var doerID int64
327327
if doer != nil {
328328
doerID = doer.ID

models/admin.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ import (
1414
"code.gitea.io/gitea/modules/util"
1515
)
1616

17-
//NoticeType describes the notice type
17+
// NoticeType describes the notice type
1818
type NoticeType int
1919

2020
const (
21-
//NoticeRepository type
21+
// NoticeRepository type
2222
NoticeRepository NoticeType = iota + 1
2323
// NoticeTask type
2424
NoticeTask

models/attachment.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ func DeleteAttachments(attachments []*Attachment, remove bool) (int, error) {
193193
return 0, nil
194194
}
195195

196-
var ids = make([]int64, 0, len(attachments))
196+
ids := make([]int64, 0, len(attachments))
197197
for _, a := range attachments {
198198
ids = append(ids, a.ID)
199199
}
@@ -216,7 +216,6 @@ func DeleteAttachments(attachments []*Attachment, remove bool) (int, error) {
216216
// DeleteAttachmentsByIssue deletes all attachments associated with the given issue.
217217
func DeleteAttachmentsByIssue(issueID int64, remove bool) (int, error) {
218218
attachments, err := GetAttachmentsByIssueID(issueID)
219-
220219
if err != nil {
221220
return 0, err
222221
}
@@ -227,7 +226,6 @@ func DeleteAttachmentsByIssue(issueID int64, remove bool) (int, error) {
227226
// DeleteAttachmentsByComment deletes all attachments associated with the given comment.
228227
func DeleteAttachmentsByComment(commentID int64, remove bool) (int, error) {
229228
attachments, err := GetAttachmentsByCommentID(commentID)
230-
231229
if err != nil {
232230
return 0, err
233231
}
@@ -263,7 +261,7 @@ func IterateAttachment(f func(attach *Attachment) error) error {
263261
var start int
264262
const batchSize = 100
265263
for {
266-
var attachments = make([]*Attachment, 0, batchSize)
264+
attachments := make([]*Attachment, 0, batchSize)
267265
if err := x.Limit(batchSize, start).Find(&attachments); err != nil {
268266
return err
269267
}

models/attachment_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ func TestUploadAttachment(t *testing.T) {
1717

1818
user := AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
1919

20-
var fPath = "./attachment_test.go"
20+
fPath := "./attachment_test.go"
2121
f, err := os.Open(fPath)
2222
assert.NoError(t, err)
2323
defer f.Close()
2424

25-
var buf = make([]byte, 1024)
25+
buf := make([]byte, 1024)
2626
n, err := f.Read(buf)
2727
assert.NoError(t, err)
2828
buf = buf[:n]
@@ -152,7 +152,6 @@ func TestLinkedRepository(t *testing.T) {
152152
assert.Equal(t, tc.expectedRepo.ID, repo.ID)
153153
}
154154
assert.Equal(t, tc.expectedUnitType, unitType)
155-
156155
})
157156
}
158157
}

models/commit_status.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,11 @@ func FindRepoRecentCommitStatusContexts(repoID int64, before time.Duration) ([]s
176176
return nil, err
177177
}
178178

179-
var contexts = make([]string, 0, len(ids))
179+
contexts := make([]string, 0, len(ids))
180180
if len(ids) == 0 {
181181
return contexts, nil
182182
}
183183
return contexts, x.Select("context").Table("commit_status").In("id", ids).Find(&contexts)
184-
185184
}
186185

187186
// NewCommitStatusOptions holds options for creating a CommitStatus

models/error.go

+3-6
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ func (err ErrNameCharsNotAllowed) Error() string {
7272
}
7373

7474
// ErrSSHDisabled represents an "SSH disabled" error.
75-
type ErrSSHDisabled struct {
76-
}
75+
type ErrSSHDisabled struct{}
7776

7877
// IsErrSSHDisabled checks if an error is a ErrSSHDisabled.
7978
func IsErrSSHDisabled(err error) bool {
@@ -269,8 +268,7 @@ func (err ErrUserHasOrgs) Error() string {
269268
}
270269

271270
// ErrUserNotAllowedCreateOrg represents a "UserNotAllowedCreateOrg" kind of error.
272-
type ErrUserNotAllowedCreateOrg struct {
273-
}
271+
type ErrUserNotAllowedCreateOrg struct{}
274272

275273
// IsErrUserNotAllowedCreateOrg checks if an error is an ErrUserNotAllowedCreateOrg.
276274
func IsErrUserNotAllowedCreateOrg(err error) bool {
@@ -603,8 +601,7 @@ func (err ErrAccessTokenNotExist) Error() string {
603601
}
604602

605603
// ErrAccessTokenEmpty represents a "AccessTokenEmpty" kind of error.
606-
type ErrAccessTokenEmpty struct {
607-
}
604+
type ErrAccessTokenEmpty struct{}
608605

609606
// IsErrAccessTokenEmpty checks if an error is a ErrAccessTokenEmpty.
610607
func IsErrAccessTokenEmpty(err error) bool {

models/external_login_user.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ func ListAccountLinks(user *User) ([]*ExternalLoginUser, error) {
4545
err := x.Where("user_id=?", user.ID).
4646
Desc("login_source_id").
4747
Find(&externalAccounts)
48-
4948
if err != nil {
5049
return nil, err
5150
}
@@ -87,7 +86,7 @@ func removeAllAccountLinks(e Engine, user *User) error {
8786
}
8887

8988
// GetUserIDByExternalUserID get user id according to provider and userID
90-
func GetUserIDByExternalUserID(provider string, userID string) (int64, error) {
89+
func GetUserIDByExternalUserID(provider, userID string) (int64, error) {
9190
var id int64
9291
_, err := x.Table("external_login_user").
9392
Select("user_id").
@@ -147,7 +146,7 @@ type FindExternalUserOptions struct {
147146
}
148147

149148
func (opts FindExternalUserOptions) toConds() builder.Cond {
150-
var cond = builder.NewCond()
149+
cond := builder.NewCond()
151150
if len(opts.Provider) > 0 {
152151
cond = cond.And(builder.Eq{"provider": opts.Provider})
153152
}

models/fixture_generation.go

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
// GetYamlFixturesAccess returns a string containing the contents
1313
// for the access table, as recalculated using repo.RecalculateAccesses()
1414
func GetYamlFixturesAccess() (string, error) {
15-
1615
repos := make([]*Repository, 0, 50)
1716
if err := x.Find(&repos); err != nil {
1817
return "", err

models/fixtures/label.yml

+8
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,11 @@
3333
num_issues: 1
3434
num_closed_issues: 0
3535

36+
-
37+
id: 5
38+
repo_id: 10
39+
org_id: 0
40+
name: pull-test-label
41+
color: '#000000'
42+
num_issues: 0
43+
num_closed_issues: 0

models/fixtures/milestone.yml

+8
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,11 @@
2929
content: content random
3030
is_closed: false
3131
num_issues: 0
32+
33+
-
34+
id: 5
35+
repo_id: 10
36+
name: milestone of repo 10
37+
content: for testing with PRs
38+
is_closed: false
39+
num_issues: 0

models/fixtures/repository.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@
148148
num_closed_issues: 0
149149
num_pulls: 1
150150
num_closed_pulls: 0
151+
num_milestones: 1
151152
is_mirror: false
152153
num_forks: 1
153154
status: 0
@@ -734,4 +735,4 @@
734735
num_watches: 0
735736
num_projects: 0
736737
num_closed_projects: 0
737-
status: 0
738+
status: 0

0 commit comments

Comments
 (0)