Skip to content

Commit 596308f

Browse files
ethantkoeniglunny
authored andcommitted
Fix missing branch in release bug (#3108)
1 parent 68179dc commit 596308f

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

modules/test/context_tests.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"net/url"
1010
"testing"
1111

12+
"code.gitea.io/git"
1213
"code.gitea.io/gitea/models"
1314
"code.gitea.io/gitea/modules/context"
1415

@@ -51,6 +52,15 @@ func LoadUser(t *testing.T, ctx *context.Context, userID int64) {
5152
ctx.User = models.AssertExistsAndLoadBean(t, &models.User{ID: userID}).(*models.User)
5253
}
5354

55+
// LoadGitRepo load a git repo into a test context. Requires that ctx.Repo has
56+
// already been populated.
57+
func LoadGitRepo(t *testing.T, ctx *context.Context) {
58+
assert.NoError(t, ctx.Repo.Repository.GetOwner())
59+
var err error
60+
ctx.Repo.GitRepo, err = git.OpenRepository(ctx.Repo.Repository.RepoPath())
61+
assert.NoError(t, err)
62+
}
63+
5464
type mockLocale struct{}
5565

5666
func (l mockLocale) Language() string {

routers/repo/release.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ func NewReleasePost(ctx *context.Context, form auth.NewReleaseForm) {
191191

192192
rel.Title = form.Title
193193
rel.Note = form.Content
194+
rel.Target = form.Target
194195
rel.IsDraft = len(form.Draft) > 0
195196
rel.IsPrerelease = form.Prerelease
196197
rel.PublisherID = ctx.User.ID

routers/repo/release_test.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright 2017 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package repo
6+
7+
import (
8+
"testing"
9+
10+
"code.gitea.io/gitea/models"
11+
"code.gitea.io/gitea/modules/auth"
12+
"code.gitea.io/gitea/modules/test"
13+
)
14+
15+
func TestNewReleasePost(t *testing.T) {
16+
for _, testCase := range []struct {
17+
RepoID int64
18+
UserID int64
19+
TagName string
20+
Form auth.NewReleaseForm
21+
}{
22+
{
23+
RepoID: 1,
24+
UserID: 2,
25+
TagName: "v1.1", // pre-existing tag
26+
Form: auth.NewReleaseForm{
27+
TagName: "newtag",
28+
Target: "master",
29+
Title: "title",
30+
Content: "content",
31+
},
32+
},
33+
{
34+
RepoID: 1,
35+
UserID: 2,
36+
TagName: "newtag",
37+
Form: auth.NewReleaseForm{
38+
TagName: "newtag",
39+
Target: "master",
40+
Title: "title",
41+
Content: "content",
42+
},
43+
},
44+
} {
45+
models.PrepareTestEnv(t)
46+
47+
ctx := test.MockContext(t, "user2/repo1/releases/new")
48+
test.LoadUser(t, ctx, 2)
49+
test.LoadRepo(t, ctx, 1)
50+
test.LoadGitRepo(t, ctx)
51+
NewReleasePost(ctx, testCase.Form)
52+
models.AssertExistsAndLoadBean(t, &models.Release{
53+
RepoID: 1,
54+
PublisherID: 2,
55+
TagName: testCase.Form.TagName,
56+
Target: testCase.Form.Target,
57+
Title: testCase.Form.Title,
58+
Note: testCase.Form.Content,
59+
}, models.Cond("is_draft=?", len(testCase.Form.Draft) > 0))
60+
}
61+
}

0 commit comments

Comments
 (0)