mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-24 08:57:03 -05:00
Fix release published actions not triggering for releases created from existing tags
This commit is contained in:
parent
20c0292b5c
commit
46977b0f01
4 changed files with 15 additions and 15 deletions
|
@ -267,7 +267,7 @@ func CreateRelease(ctx *context.APIContext) {
|
|||
rel.Publisher = ctx.Doer
|
||||
rel.Target = form.Target
|
||||
|
||||
if err = release_service.UpdateRelease(ctx, ctx.Doer, ctx.Repo.GitRepo, rel, nil, nil, nil); err != nil {
|
||||
if err = release_service.UpdateRelease(ctx, ctx.Doer, ctx.Repo.GitRepo, rel, nil, nil, nil, true); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "UpdateRelease", err)
|
||||
return
|
||||
}
|
||||
|
@ -341,7 +341,7 @@ func EditRelease(ctx *context.APIContext) {
|
|||
if form.IsPrerelease != nil {
|
||||
rel.IsPrerelease = *form.IsPrerelease
|
||||
}
|
||||
if err := release_service.UpdateRelease(ctx, ctx.Doer, ctx.Repo.GitRepo, rel, nil, nil, nil); err != nil {
|
||||
if err := release_service.UpdateRelease(ctx, ctx.Doer, ctx.Repo.GitRepo, rel, nil, nil, nil, false); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "UpdateRelease", err)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -567,7 +567,7 @@ func NewReleasePost(ctx *context.Context) {
|
|||
rel.PublisherID = ctx.Doer.ID
|
||||
rel.IsTag = false
|
||||
|
||||
if err = releaseservice.UpdateRelease(ctx, ctx.Doer, ctx.Repo.GitRepo, rel, attachmentUUIDs, nil, nil); err != nil {
|
||||
if err = releaseservice.UpdateRelease(ctx, ctx.Doer, ctx.Repo.GitRepo, rel, attachmentUUIDs, nil, nil, true); err != nil {
|
||||
ctx.Data["Err_TagName"] = true
|
||||
ctx.ServerError("UpdateRelease", err)
|
||||
return
|
||||
|
@ -674,7 +674,7 @@ func EditReleasePost(ctx *context.Context) {
|
|||
rel.IsDraft = len(form.Draft) > 0
|
||||
rel.IsPrerelease = form.Prerelease
|
||||
if err = releaseservice.UpdateRelease(ctx, ctx.Doer, ctx.Repo.GitRepo,
|
||||
rel, addAttachmentUUIDs, delAttachmentUUIDs, editAttachments); err != nil {
|
||||
rel, addAttachmentUUIDs, delAttachmentUUIDs, editAttachments, false); err != nil {
|
||||
ctx.ServerError("UpdateRelease", err)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -199,7 +199,7 @@ func CreateNewTag(ctx context.Context, doer *user_model.User, repo *repo_model.R
|
|||
// delAttachmentUUIDs accept a slice of attachments' uuids which will be deleted from the release
|
||||
// editAttachments accept a map of attachment uuid to new attachment name which will be updated with attachments.
|
||||
func UpdateRelease(ctx context.Context, doer *user_model.User, gitRepo *git.Repository, rel *repo_model.Release,
|
||||
addAttachmentUUIDs, delAttachmentUUIDs []string, editAttachments map[string]string,
|
||||
addAttachmentUUIDs, delAttachmentUUIDs []string, editAttachments map[string]string, createdFromTag bool,
|
||||
) error {
|
||||
if rel.ID == 0 {
|
||||
return errors.New("UpdateRelease only accepts an exist release")
|
||||
|
@ -292,11 +292,11 @@ func UpdateRelease(ctx context.Context, doer *user_model.User, gitRepo *git.Repo
|
|||
}
|
||||
|
||||
if !rel.IsDraft {
|
||||
if !isCreated {
|
||||
notify_service.UpdateRelease(gitRepo.Ctx, doer, rel)
|
||||
if createdFromTag || isCreated {
|
||||
notify_service.NewRelease(gitRepo.Ctx, rel)
|
||||
return nil
|
||||
}
|
||||
notify_service.NewRelease(gitRepo.Ctx, rel)
|
||||
notify_service.UpdateRelease(gitRepo.Ctx, doer, rel)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -159,7 +159,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(db.DefaultContext, user, gitRepo, release, nil, nil, nil))
|
||||
assert.NoError(t, UpdateRelease(db.DefaultContext, user, gitRepo, release, nil, nil, nil, false))
|
||||
release, err = repo_model.GetReleaseByID(db.DefaultContext, release.ID)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, int64(releaseCreatedUnix), int64(release.CreatedUnix))
|
||||
|
@ -183,7 +183,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(db.DefaultContext, user, gitRepo, release, nil, nil, nil))
|
||||
assert.NoError(t, UpdateRelease(db.DefaultContext, user, gitRepo, release, nil, nil, nil, false))
|
||||
release, err = repo_model.GetReleaseByID(db.DefaultContext, release.ID)
|
||||
assert.NoError(t, err)
|
||||
assert.Less(t, int64(releaseCreatedUnix), int64(release.CreatedUnix))
|
||||
|
@ -208,7 +208,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(db.DefaultContext, user, gitRepo, release, nil, nil, nil))
|
||||
assert.NoError(t, UpdateRelease(db.DefaultContext, user, gitRepo, release, nil, nil, nil, false))
|
||||
release, err = repo_model.GetReleaseByID(db.DefaultContext, release.ID)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, int64(releaseCreatedUnix), int64(release.CreatedUnix))
|
||||
|
@ -233,7 +233,7 @@ func TestRelease_Update(t *testing.T) {
|
|||
release.IsDraft = false
|
||||
tagName := release.TagName
|
||||
|
||||
assert.NoError(t, UpdateRelease(db.DefaultContext, user, gitRepo, release, nil, nil, nil))
|
||||
assert.NoError(t, UpdateRelease(db.DefaultContext, user, gitRepo, release, nil, nil, nil, false))
|
||||
release, err = repo_model.GetReleaseByID(db.DefaultContext, release.ID)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, tagName, release.TagName)
|
||||
|
@ -247,7 +247,7 @@ func TestRelease_Update(t *testing.T) {
|
|||
}, strings.NewReader(samplePayload), int64(len([]byte(samplePayload))))
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.NoError(t, UpdateRelease(db.DefaultContext, user, gitRepo, release, []string{attach.UUID}, nil, nil))
|
||||
assert.NoError(t, UpdateRelease(db.DefaultContext, user, gitRepo, release, []string{attach.UUID}, nil, nil, false))
|
||||
assert.NoError(t, repo_model.GetReleaseAttachments(db.DefaultContext, release))
|
||||
assert.Len(t, release.Attachments, 1)
|
||||
assert.EqualValues(t, attach.UUID, release.Attachments[0].UUID)
|
||||
|
@ -257,7 +257,7 @@ func TestRelease_Update(t *testing.T) {
|
|||
// update the attachment name
|
||||
assert.NoError(t, UpdateRelease(db.DefaultContext, user, gitRepo, release, nil, nil, map[string]string{
|
||||
attach.UUID: "test2.txt",
|
||||
}))
|
||||
}, false))
|
||||
release.Attachments = nil
|
||||
assert.NoError(t, repo_model.GetReleaseAttachments(db.DefaultContext, release))
|
||||
assert.Len(t, release.Attachments, 1)
|
||||
|
@ -266,7 +266,7 @@ func TestRelease_Update(t *testing.T) {
|
|||
assert.EqualValues(t, "test2.txt", release.Attachments[0].Name)
|
||||
|
||||
// delete the attachment
|
||||
assert.NoError(t, UpdateRelease(db.DefaultContext, user, gitRepo, release, nil, []string{attach.UUID}, nil))
|
||||
assert.NoError(t, UpdateRelease(db.DefaultContext, user, gitRepo, release, nil, []string{attach.UUID}, nil, false))
|
||||
release.Attachments = nil
|
||||
assert.NoError(t, repo_model.GetReleaseAttachments(db.DefaultContext, release))
|
||||
assert.Empty(t, release.Attachments)
|
||||
|
|
Loading…
Reference in a new issue