Skip to content

Commit d190fb6

Browse files
committed
add comments
1 parent 7d77978 commit d190fb6

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

routers/web/repo/release.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -397,13 +397,16 @@ func NewReleasePost(ctx *context.Context) {
397397

398398
form := web.GetForm(ctx).(*forms.NewReleaseForm)
399399

400+
// first, check whether the release exists,
401+
// it should be done before the form error check, because the tmpl needs "TagNameReleaseExists" to show/hide the "tag only" button
400402
rel, err := repo_model.GetRelease(ctx, ctx.Repo.Repository.ID, form.TagName)
401403
if err != nil && !repo_model.IsErrReleaseNotExist(err) {
402404
ctx.ServerError("GetRelease", err)
403405
return
404406
}
405407
ctx.Data["TagNameReleaseExists"] = rel != nil
406408

409+
// do some form checks
407410
if ctx.HasError() {
408411
ctx.HTML(http.StatusOK, tplReleaseNew)
409412
return
@@ -414,8 +417,8 @@ func NewReleasePost(ctx *context.Context) {
414417
return
415418
}
416419

417-
// Title of release cannot be empty
418420
if !form.TagOnly && form.Title == "" {
421+
// if not "tag only", then the title of the release cannot be empty
419422
ctx.RenderWithErr(ctx.Tr("repo.release.title_empty"), tplReleaseNew, &form)
420423
return
421424
}
@@ -436,6 +439,7 @@ func NewReleasePost(ctx *context.Context) {
436439
}
437440
}
438441

442+
// prepare the git message for creating a new tag
439443
newTagMsg := ""
440444
if form.Title != "" && form.AddTagMsg {
441445
newTagMsg = form.Title + "\n\n" + form.Content
@@ -452,12 +456,9 @@ func NewReleasePost(ctx *context.Context) {
452456
return
453457
}
454458

455-
var attachmentUUIDs []string
456-
if setting.Attachment.Enabled {
457-
attachmentUUIDs = form.Files
458-
}
459+
attachmentUUIDs := util.Iif(setting.Attachment.Enabled, form.Files, nil)
459460

460-
// no release, create a new release
461+
// no existing release, create a new release
461462
if rel == nil {
462463
rel = &repo_model.Release{
463464
RepoID: ctx.Repo.Repository.ID,

routers/web/repo/release_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func TestNewReleasePost(t *testing.T) {
7676
Title: testCase.Form.Title,
7777
Note: testCase.Form.Content,
7878
IsTag: testCase.IsTag,
79-
}, unittest.Cond("is_draft=?", len(testCase.Form.Draft) > 0))
79+
}, unittest.Cond("is_draft=?", testCase.Form.Draft))
8080
ctx.Repo.GitRepo.Close()
8181
}
8282
}

0 commit comments

Comments
 (0)