From 1f12dc8e8862da8546fd9d984abdc7f69dd95f11 Mon Sep 17 00:00:00 2001 From: 赵智超 <1012112796@qq.com> Date: Thu, 30 Jul 2020 03:20:54 +0800 Subject: Add action feed for new release (#12324) * Add action feed for new release Signed-off-by: a1012112796 <1012112796@qq.com> * fix lint * Apply suggestions from code review * Add ReleaseID to the action table * Remove error message * Fold the attachments download list * remove attchment download list * simplify code * fix create release from existing tag * simplify ui * translation change * fix test Co-authored-by: Lunny Xiao Co-authored-by: Lauris BH Co-authored-by: techknowlogick --- services/release/release.go | 13 ++++++++++--- services/release/release_test.go | 6 +++--- 2 files changed, 13 insertions(+), 6 deletions(-) (limited to 'services') diff --git a/services/release/release.go b/services/release/release.go index 64d132cd73..2fc3cb199b 100644 --- a/services/release/release.go +++ b/services/release/release.go @@ -95,8 +95,8 @@ func CreateRelease(gitRepo *git.Repository, rel *models.Release, attachmentUUIDs return nil } -// UpdateRelease updates information of a release. -func UpdateRelease(doer *models.User, gitRepo *git.Repository, rel *models.Release, attachmentUUIDs []string) (err error) { +// UpdateReleaseOrCreatReleaseFromTag updates information of a release or create release from tag. +func UpdateReleaseOrCreatReleaseFromTag(doer *models.User, gitRepo *git.Repository, rel *models.Release, attachmentUUIDs []string, isCreate bool) (err error) { if err = createTag(gitRepo, rel); err != nil { return err } @@ -110,7 +110,14 @@ func UpdateRelease(doer *models.User, gitRepo *git.Repository, rel *models.Relea log.Error("AddReleaseAttachments: %v", err) } - notification.NotifyUpdateRelease(doer, rel) + if !isCreate { + notification.NotifyUpdateRelease(doer, rel) + return + } + + if !rel.IsDraft { + notification.NotifyNewRelease(rel) + } return err } diff --git a/services/release/release_test.go b/services/release/release_test.go index d5673b73b8..f50fca71ec 100644 --- a/services/release/release_test.go +++ b/services/release/release_test.go @@ -131,7 +131,7 @@ func TestRelease_Update(t *testing.T) { releaseCreatedUnix := release.CreatedUnix time.Sleep(2 * time.Second) // sleep 2 seconds to ensure a different timestamp release.Note = "Changed note" - assert.NoError(t, UpdateRelease(user, gitRepo, release, nil)) + assert.NoError(t, UpdateReleaseOrCreatReleaseFromTag(user, gitRepo, release, nil, false)) release, err = models.GetReleaseByID(release.ID) assert.NoError(t, err) assert.Equal(t, int64(releaseCreatedUnix), int64(release.CreatedUnix)) @@ -153,7 +153,7 @@ func TestRelease_Update(t *testing.T) { releaseCreatedUnix = release.CreatedUnix time.Sleep(2 * time.Second) // sleep 2 seconds to ensure a different timestamp release.Title = "Changed title" - assert.NoError(t, UpdateRelease(user, gitRepo, release, nil)) + assert.NoError(t, UpdateReleaseOrCreatReleaseFromTag(user, gitRepo, release, nil, false)) release, err = models.GetReleaseByID(release.ID) assert.NoError(t, err) assert.Less(t, int64(releaseCreatedUnix), int64(release.CreatedUnix)) @@ -176,7 +176,7 @@ func TestRelease_Update(t *testing.T) { time.Sleep(2 * time.Second) // sleep 2 seconds to ensure a different timestamp release.Title = "Changed title" release.Note = "Changed note" - assert.NoError(t, UpdateRelease(user, gitRepo, release, nil)) + assert.NoError(t, UpdateReleaseOrCreatReleaseFromTag(user, gitRepo, release, nil, false)) release, err = models.GetReleaseByID(release.ID) assert.NoError(t, err) assert.Equal(t, int64(releaseCreatedUnix), int64(release.CreatedUnix)) -- cgit v1.2.3