Repository: go-gitea/gitea
File: routers/web/repo/release.go (Go)

Code before:
			Publisher:    ctx.Doer,
			Title:        form.Title,
			TagName:      form.TagName,
			Target:       form.Target,
			Note:         form.Content,
			IsDraft:      len(form.Draft) > 0,
			IsPrerelease: form.Prerelease,
			IsTag:        false,
		}

		if err = release_service.CreateRelease(ctx.Repo.GitRepo, rel, attachmentUUIDs, msg); err != nil {
			ctx.Data["Err_TagName"] = true
			switch {
			case repo_model.IsErrReleaseAlreadyExist(err):
				ctx.RenderWithErr(ctx.Tr("repo.release.tag_name_already_exist"), tplReleaseNew, &form)
			case release_service.IsErrInvalidTagName(err):
				ctx.RenderWithErr(ctx.Tr("repo.release.tag_name_invalid"), tplReleaseNew, &form)
			case release_service.IsErrProtectedTagName(err):
				ctx.RenderWithErr(ctx.Tr("repo.release.tag_name_protected"), tplReleaseNew, &form)
			default:
				ctx.ServerError("CreateRelease", err)
			}
			return
		}
	} else {
		if len(form.TagOnly) > 0 && rel.IsTag {
			ctx.Data["Err_TagName"] = true
			ctx.RenderWithErr(ctx.Tr("repo.release.tag_name_already_exist"), tplReleaseNew, &form)
			return
		}

		rel.Title = form.Title
		rel.Note = form.Content
		rel.Target = form.Target
		rel.IsDraft = len(form.Draft) > 0
		rel.IsPrerelease = form.Prerelease
		rel.PublisherID = ctx.Doer.ID
		rel.IsTag = false

		if err = release_service.UpdateRelease(ctx, ctx.Doer, ctx.Repo.GitRepo, rel, attachmentUUIDs, nil, nil); err != nil {
			ctx.Data["Err_TagName"] = true
			ctx.ServerError("UpdateRelease", err)
			return
		}
	}
	log.Trace("Release created: %s/%s:%s", ctx.Doer.LowerName, ctx.Repo.Repository.Name, form.TagName)

	ctx.Redirect(ctx.Repo.RepoLink + "/releases")
}

// EditRelease render release edit page

Review comment (suggestion):
I am not sure why `form.TagOnly` is a string here? From observing the form value in my network requests, It looks like it should just be a boolean.

Code after:
		return
	}

	attachmentUUIDs := util.Iif(setting.Attachment.Enabled, form.Files, nil)

	// no existing release, create a new release
	if rel == nil {
		rel = &repo_model.Release{
			RepoID:       ctx.Repo.Repository.ID,
			Repo:         ctx.Repo.Repository,
			PublisherID:  ctx.Doer.ID,
			Publisher:    ctx.Doer,
			Title:        form.Title,
			TagName:      form.TagName,
			Target:       form.Target,
			Note:         form.Content,
			IsDraft:      form.Draft,
			IsPrerelease: form.Prerelease,
			IsTag:        false,
		}
		if err = release_service.CreateRelease(ctx.Repo.GitRepo, rel, attachmentUUIDs, newTagMsg); err != nil {
			handleTagReleaseError(err)
			return
		}
		ctx.Redirect(ctx.Repo.RepoLink + "/releases")
		return
	}

	// tag exists, try to convert it to a real release
	// old logic: if the release is not a tag (it is a real release), do not update it on the "new release" page
	// add new logic: if tag-only, do not convert the tag to a release
	if form.TagOnly || !rel.IsTag {
		ctx.Data["Err_TagName"] = true
		ctx.RenderWithErr(ctx.Tr("repo.release.tag_name_already_exist"), tplReleaseNew, &form)
		return
	}

	// convert a tag to a real release (set is_tag=false)
	rel.Title = form.Title
	rel.Note = form.Content
	rel.Target = form.Target
	rel.IsDraft = form.Draft
	rel.IsPrerelease = form.Prerelease
	rel.PublisherID = ctx.Doer.ID
	rel.IsTag = false
	if err = release_service.UpdateRelease(ctx, ctx.Doer, ctx.Repo.GitRepo, rel, attachmentUUIDs, nil, nil); err != nil {
		handleTagReleaseError(err)
		return
	}
	ctx.Redirect(ctx.Repo.RepoLink + "/releases")
}