mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-18 20:09:26 +00:00
Create tag on ui (#13467)
Support create single tag directly support create tag with message from create release ui Signed-off-by: a1012112796 <1012112796@qq.com> Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: zeripath <art27@cantab.net>
This commit is contained in:
parent
3e652860bb
commit
83cf1a894e
|
@ -16,6 +16,7 @@ import (
|
|||
// NewBranchForm form for creating a new branch
|
||||
type NewBranchForm struct {
|
||||
NewBranchName string `binding:"Required;MaxSize(100);GitRefName"`
|
||||
CreateTag bool
|
||||
}
|
||||
|
||||
// Validate validates the fields
|
||||
|
|
|
@ -642,7 +642,9 @@ type NewReleaseForm struct {
|
|||
Title string `binding:"Required;MaxSize(255)"`
|
||||
Content string
|
||||
Draft string
|
||||
TagOnly string
|
||||
Prerelease bool
|
||||
AddTagMsg bool
|
||||
Files []string
|
||||
}
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ func TestRepository_GetTag(t *testing.T) {
|
|||
|
||||
aTagCommitID := "8006ff9adbf0cb94da7dad9e537e53817f9fa5c0"
|
||||
aTagName := "annotatedTag"
|
||||
aTagMessage := "my annotated message"
|
||||
aTagMessage := "my annotated message \n - test two line"
|
||||
bareRepo1.CreateAnnotatedTag(aTagName, aTagMessage, aTagCommitID)
|
||||
aTagID, _ := bareRepo1.GetTagID(aTagName)
|
||||
|
||||
|
|
|
@ -1895,6 +1895,8 @@ release.tag_name_invalid = The tag name is not valid.
|
|||
release.tag_already_exist = This tag name already exists.
|
||||
release.downloads = Downloads
|
||||
release.download_count = Downloads: %s
|
||||
release.add_tag_msg = Use the title and content of release as tag message.
|
||||
release.add_tag = Create Tag Only
|
||||
|
||||
branch.name = Branch Name
|
||||
branch.search = Search branches
|
||||
|
@ -1922,6 +1924,9 @@ branch.download = Download Branch '%s'
|
|||
branch.included_desc = This branch is part of the default branch
|
||||
branch.included = Included
|
||||
|
||||
tag.create_tag = Create tag <strong>%s</strong>
|
||||
tag.create_success = Tag '%s' has been created.
|
||||
|
||||
topic.manage_topics = Manage Topics
|
||||
topic.done = Done
|
||||
topic.count_prompt = You can not select more than 25 topics
|
||||
|
|
|
@ -179,7 +179,7 @@ func CreateRelease(ctx *context.APIContext) {
|
|||
IsTag: false,
|
||||
Repo: ctx.Repo.Repository,
|
||||
}
|
||||
if err := releaseservice.CreateRelease(ctx.Repo.GitRepo, rel, nil); err != nil {
|
||||
if err := releaseservice.CreateRelease(ctx.Repo.GitRepo, rel, nil, ""); err != nil {
|
||||
if models.IsErrReleaseAlreadyExist(err) {
|
||||
ctx.Error(http.StatusConflict, "ReleaseAlreadyExist", err)
|
||||
} else {
|
||||
|
|
|
@ -20,6 +20,7 @@ import (
|
|||
"code.gitea.io/gitea/modules/util"
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
"code.gitea.io/gitea/routers/utils"
|
||||
release_service "code.gitea.io/gitea/services/release"
|
||||
repo_service "code.gitea.io/gitea/services/repository"
|
||||
)
|
||||
|
||||
|
@ -383,7 +384,14 @@ func CreateBranch(ctx *context.Context) {
|
|||
}
|
||||
|
||||
var err error
|
||||
if ctx.Repo.IsViewBranch {
|
||||
|
||||
if form.CreateTag {
|
||||
if ctx.Repo.IsViewTag {
|
||||
err = release_service.CreateNewTag(ctx.User, ctx.Repo.Repository, ctx.Repo.CommitID, form.NewBranchName, "")
|
||||
} else {
|
||||
err = release_service.CreateNewTag(ctx.User, ctx.Repo.Repository, ctx.Repo.BranchName, form.NewBranchName, "")
|
||||
}
|
||||
} else if ctx.Repo.IsViewBranch {
|
||||
err = repo_module.CreateNewBranch(ctx.User, ctx.Repo.Repository, ctx.Repo.BranchName, form.NewBranchName)
|
||||
} else if ctx.Repo.IsViewTag {
|
||||
err = repo_module.CreateNewBranchFromCommit(ctx.User, ctx.Repo.Repository, ctx.Repo.CommitID, form.NewBranchName)
|
||||
|
@ -432,6 +440,12 @@ func CreateBranch(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
if form.CreateTag {
|
||||
ctx.Flash.Success(ctx.Tr("repo.tag.create_success", form.NewBranchName))
|
||||
ctx.Redirect(ctx.Repo.RepoLink + "/src/tag/" + util.PathEscapeSegments(form.NewBranchName))
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Flash.Success(ctx.Tr("repo.branch.create_success", form.NewBranchName))
|
||||
ctx.Redirect(ctx.Repo.RepoLink + "/src/branch/" + util.PathEscapeSegments(form.NewBranchName))
|
||||
}
|
||||
|
|
|
@ -262,6 +262,29 @@ func NewReleasePost(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
msg := ""
|
||||
if len(form.Title) > 0 && form.AddTagMsg {
|
||||
msg = form.Title + "\n\n" + form.Content
|
||||
}
|
||||
|
||||
if len(form.TagOnly) > 0 {
|
||||
if err = releaseservice.CreateNewTag(ctx.User, ctx.Repo.Repository, form.Target, form.TagName, msg); err != nil {
|
||||
if models.IsErrTagAlreadyExists(err) {
|
||||
e := err.(models.ErrTagAlreadyExists)
|
||||
ctx.Flash.Error(ctx.Tr("repo.branch.tag_collision", e.TagName))
|
||||
ctx.Redirect(ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL())
|
||||
return
|
||||
}
|
||||
|
||||
ctx.ServerError("releaseservice.CreateNewTag", err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Flash.Success(ctx.Tr("repo.tag.create_success", form.TagName))
|
||||
ctx.Redirect(ctx.Repo.RepoLink + "/src/tag/" + form.TagName)
|
||||
return
|
||||
}
|
||||
|
||||
rel = &models.Release{
|
||||
RepoID: ctx.Repo.Repository.ID,
|
||||
PublisherID: ctx.User.ID,
|
||||
|
@ -274,7 +297,7 @@ func NewReleasePost(ctx *context.Context) {
|
|||
IsTag: false,
|
||||
}
|
||||
|
||||
if err = releaseservice.CreateRelease(ctx.Repo.GitRepo, rel, attachmentUUIDs); err != nil {
|
||||
if err = releaseservice.CreateRelease(ctx.Repo.GitRepo, rel, attachmentUUIDs, msg); err != nil {
|
||||
ctx.Data["Err_TagName"] = true
|
||||
switch {
|
||||
case models.IsErrReleaseAlreadyExist(err):
|
||||
|
|
|
@ -69,7 +69,7 @@ func TestRelease_MirrorDelete(t *testing.T) {
|
|||
IsDraft: false,
|
||||
IsPrerelease: false,
|
||||
IsTag: true,
|
||||
}, nil))
|
||||
}, nil, ""))
|
||||
|
||||
err = mirror.GetMirror()
|
||||
assert.NoError(t, err)
|
||||
|
|
|
@ -17,7 +17,7 @@ import (
|
|||
"code.gitea.io/gitea/modules/timeutil"
|
||||
)
|
||||
|
||||
func createTag(gitRepo *git.Repository, rel *models.Release) error {
|
||||
func createTag(gitRepo *git.Repository, rel *models.Release, msg string) error {
|
||||
// Only actual create when publish.
|
||||
if !rel.IsDraft {
|
||||
if !gitRepo.IsTagExist(rel.TagName) {
|
||||
|
@ -28,7 +28,16 @@ func createTag(gitRepo *git.Repository, rel *models.Release) error {
|
|||
|
||||
// Trim '--' prefix to prevent command line argument vulnerability.
|
||||
rel.TagName = strings.TrimPrefix(rel.TagName, "--")
|
||||
if err = gitRepo.CreateTag(rel.TagName, commit.ID.String()); err != nil {
|
||||
if len(msg) > 0 {
|
||||
if err = gitRepo.CreateAnnotatedTag(rel.TagName, msg, commit.ID.String()); err != nil {
|
||||
if strings.Contains(err.Error(), "is not a valid tag name") {
|
||||
return models.ErrInvalidTagName{
|
||||
TagName: rel.TagName,
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
} else if err = gitRepo.CreateTag(rel.TagName, commit.ID.String()); err != nil {
|
||||
if strings.Contains(err.Error(), "is not a valid tag name") {
|
||||
return models.ErrInvalidTagName{
|
||||
TagName: rel.TagName,
|
||||
|
@ -77,7 +86,7 @@ func createTag(gitRepo *git.Repository, rel *models.Release) error {
|
|||
}
|
||||
|
||||
// CreateRelease creates a new release of repository.
|
||||
func CreateRelease(gitRepo *git.Repository, rel *models.Release, attachmentUUIDs []string) error {
|
||||
func CreateRelease(gitRepo *git.Repository, rel *models.Release, attachmentUUIDs []string, msg string) error {
|
||||
isExist, err := models.IsReleaseExist(rel.RepoID, rel.TagName)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -87,7 +96,7 @@ func CreateRelease(gitRepo *git.Repository, rel *models.Release, attachmentUUIDs
|
|||
}
|
||||
}
|
||||
|
||||
if err = createTag(gitRepo, rel); err != nil {
|
||||
if err = createTag(gitRepo, rel, msg); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -107,9 +116,47 @@ func CreateRelease(gitRepo *git.Repository, rel *models.Release, attachmentUUIDs
|
|||
return nil
|
||||
}
|
||||
|
||||
// CreateNewTag creates a new repository tag
|
||||
func CreateNewTag(doer *models.User, repo *models.Repository, commit, tagName, msg string) error {
|
||||
isExist, err := models.IsReleaseExist(repo.ID, tagName)
|
||||
if err != nil {
|
||||
return err
|
||||
} else if isExist {
|
||||
return models.ErrTagAlreadyExists{
|
||||
TagName: tagName,
|
||||
}
|
||||
}
|
||||
|
||||
gitRepo, err := git.OpenRepository(repo.RepoPath())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer gitRepo.Close()
|
||||
|
||||
rel := &models.Release{
|
||||
RepoID: repo.ID,
|
||||
PublisherID: doer.ID,
|
||||
TagName: tagName,
|
||||
Target: commit,
|
||||
IsDraft: false,
|
||||
IsPrerelease: false,
|
||||
IsTag: true,
|
||||
}
|
||||
|
||||
if err = createTag(gitRepo, rel, msg); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = models.InsertRelease(rel); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// 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 {
|
||||
if err = createTag(gitRepo, rel, ""); err != nil {
|
||||
return err
|
||||
}
|
||||
rel.LowerTagName = strings.ToLower(rel.TagName)
|
||||
|
|
|
@ -40,7 +40,7 @@ func TestRelease_Create(t *testing.T) {
|
|||
IsDraft: false,
|
||||
IsPrerelease: false,
|
||||
IsTag: false,
|
||||
}, nil))
|
||||
}, nil, ""))
|
||||
|
||||
assert.NoError(t, CreateRelease(gitRepo, &models.Release{
|
||||
RepoID: repo.ID,
|
||||
|
@ -52,7 +52,7 @@ func TestRelease_Create(t *testing.T) {
|
|||
IsDraft: false,
|
||||
IsPrerelease: false,
|
||||
IsTag: false,
|
||||
}, nil))
|
||||
}, nil, ""))
|
||||
|
||||
assert.NoError(t, CreateRelease(gitRepo, &models.Release{
|
||||
RepoID: repo.ID,
|
||||
|
@ -64,7 +64,7 @@ func TestRelease_Create(t *testing.T) {
|
|||
IsDraft: false,
|
||||
IsPrerelease: false,
|
||||
IsTag: false,
|
||||
}, nil))
|
||||
}, nil, ""))
|
||||
|
||||
assert.NoError(t, CreateRelease(gitRepo, &models.Release{
|
||||
RepoID: repo.ID,
|
||||
|
@ -76,7 +76,7 @@ func TestRelease_Create(t *testing.T) {
|
|||
IsDraft: true,
|
||||
IsPrerelease: false,
|
||||
IsTag: false,
|
||||
}, nil))
|
||||
}, nil, ""))
|
||||
|
||||
assert.NoError(t, CreateRelease(gitRepo, &models.Release{
|
||||
RepoID: repo.ID,
|
||||
|
@ -88,7 +88,7 @@ func TestRelease_Create(t *testing.T) {
|
|||
IsDraft: false,
|
||||
IsPrerelease: true,
|
||||
IsTag: false,
|
||||
}, nil))
|
||||
}, nil, ""))
|
||||
|
||||
assert.NoError(t, CreateRelease(gitRepo, &models.Release{
|
||||
RepoID: repo.ID,
|
||||
|
@ -100,7 +100,7 @@ func TestRelease_Create(t *testing.T) {
|
|||
IsDraft: false,
|
||||
IsPrerelease: false,
|
||||
IsTag: true,
|
||||
}, nil))
|
||||
}, nil, "test"))
|
||||
}
|
||||
|
||||
func TestRelease_Update(t *testing.T) {
|
||||
|
@ -125,7 +125,7 @@ func TestRelease_Update(t *testing.T) {
|
|||
IsDraft: false,
|
||||
IsPrerelease: false,
|
||||
IsTag: false,
|
||||
}, nil))
|
||||
}, nil, ""))
|
||||
release, err := models.GetRelease(repo.ID, "v1.1.1")
|
||||
assert.NoError(t, err)
|
||||
releaseCreatedUnix := release.CreatedUnix
|
||||
|
@ -147,7 +147,7 @@ func TestRelease_Update(t *testing.T) {
|
|||
IsDraft: true,
|
||||
IsPrerelease: false,
|
||||
IsTag: false,
|
||||
}, nil))
|
||||
}, nil, ""))
|
||||
release, err = models.GetRelease(repo.ID, "v1.2.1")
|
||||
assert.NoError(t, err)
|
||||
releaseCreatedUnix = release.CreatedUnix
|
||||
|
@ -169,7 +169,7 @@ func TestRelease_Update(t *testing.T) {
|
|||
IsDraft: false,
|
||||
IsPrerelease: true,
|
||||
IsTag: false,
|
||||
}, nil))
|
||||
}, nil, ""))
|
||||
release, err = models.GetRelease(repo.ID, "v1.3.1")
|
||||
assert.NoError(t, err)
|
||||
releaseCreatedUnix = release.CreatedUnix
|
||||
|
@ -205,12 +205,12 @@ func TestRelease_createTag(t *testing.T) {
|
|||
IsPrerelease: false,
|
||||
IsTag: false,
|
||||
}
|
||||
assert.NoError(t, createTag(gitRepo, release))
|
||||
assert.NoError(t, createTag(gitRepo, release, ""))
|
||||
assert.NotEmpty(t, release.CreatedUnix)
|
||||
releaseCreatedUnix := release.CreatedUnix
|
||||
time.Sleep(2 * time.Second) // sleep 2 seconds to ensure a different timestamp
|
||||
release.Note = "Changed note"
|
||||
assert.NoError(t, createTag(gitRepo, release))
|
||||
assert.NoError(t, createTag(gitRepo, release, ""))
|
||||
assert.Equal(t, int64(releaseCreatedUnix), int64(release.CreatedUnix))
|
||||
|
||||
// Test a changed draft
|
||||
|
@ -225,11 +225,11 @@ func TestRelease_createTag(t *testing.T) {
|
|||
IsPrerelease: false,
|
||||
IsTag: false,
|
||||
}
|
||||
assert.NoError(t, createTag(gitRepo, release))
|
||||
assert.NoError(t, createTag(gitRepo, release, ""))
|
||||
releaseCreatedUnix = release.CreatedUnix
|
||||
time.Sleep(2 * time.Second) // sleep 2 seconds to ensure a different timestamp
|
||||
release.Title = "Changed title"
|
||||
assert.NoError(t, createTag(gitRepo, release))
|
||||
assert.NoError(t, createTag(gitRepo, release, ""))
|
||||
assert.Less(t, int64(releaseCreatedUnix), int64(release.CreatedUnix))
|
||||
|
||||
// Test a changed pre-release
|
||||
|
@ -244,11 +244,20 @@ func TestRelease_createTag(t *testing.T) {
|
|||
IsPrerelease: true,
|
||||
IsTag: false,
|
||||
}
|
||||
assert.NoError(t, createTag(gitRepo, release))
|
||||
assert.NoError(t, createTag(gitRepo, release, ""))
|
||||
releaseCreatedUnix = release.CreatedUnix
|
||||
time.Sleep(2 * time.Second) // sleep 2 seconds to ensure a different timestamp
|
||||
release.Title = "Changed title"
|
||||
release.Note = "Changed note"
|
||||
assert.NoError(t, createTag(gitRepo, release))
|
||||
assert.NoError(t, createTag(gitRepo, release, ""))
|
||||
assert.Equal(t, int64(releaseCreatedUnix), int64(release.CreatedUnix))
|
||||
}
|
||||
|
||||
func TestCreateNewTag(t *testing.T) {
|
||||
assert.NoError(t, models.PrepareTestDatabase())
|
||||
user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
|
||||
repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
|
||||
|
||||
assert.NoError(t, CreateNewTag(user, repo, "master", "v2.0",
|
||||
"v2.0 is released \n\n BUGFIX: .... \n\n 123"))
|
||||
}
|
||||
|
|
|
@ -24,12 +24,12 @@
|
|||
<div class="header branch-tag-choice">
|
||||
<div class="ui grid">
|
||||
<div class="two column row">
|
||||
<a class="reference column" href="#" @click="mode = 'branches'; focusSearchField()">
|
||||
<a class="reference column" href="#" @click="createTag = false; mode = 'branches'; focusSearchField()">
|
||||
<span class="text" :class="{black: mode == 'branches'}">
|
||||
{{svg "octicon-git-branch" 16 "mr-2"}}{{.i18n.Tr "repo.branches"}}
|
||||
</span>
|
||||
</a>
|
||||
<a class="reference column" href="#" @click="mode = 'tags'; focusSearchField()">
|
||||
<a class="reference column" href="#" @click="createTag = true; mode = 'tags'; focusSearchField()">
|
||||
<span class="text" :class="{black: mode == 'tags'}">
|
||||
{{svg "octicon-tag" 16 "mr-2"}}{{.i18n.Tr "repo.tags"}}
|
||||
</span>
|
||||
|
@ -41,7 +41,11 @@
|
|||
<div v-for="(item, index) in filteredItems" :key="item.name" class="item" :class="{selected: item.selected, active: active == index}" @click="selectItem(item)" :ref="'listItem' + index">${ item.name }</div>
|
||||
<div class="item" v-if="showCreateNewBranch" :class="{active: active == filteredItems.length}" :ref="'listItem' + filteredItems.length">
|
||||
<a href="#" @click="createNewBranch()">
|
||||
<div>
|
||||
<div v-show="createTag">
|
||||
<i class="reference tags icon"></i>
|
||||
{{.i18n.Tr "repo.tag.create_tag" `${ searchTerm }` | Safe}}
|
||||
</div>
|
||||
<div v-show="!createTag">
|
||||
{{svg "octicon-git-branch"}}
|
||||
{{.i18n.Tr "repo.branch.create_branch" `${ searchTerm }` | Safe}}
|
||||
</div>
|
||||
|
@ -56,6 +60,7 @@
|
|||
<form ref="newBranchForm" action="{{.RepoLink}}/branches/_new/{{EscapePound .BranchNameSubURL}}" method="post">
|
||||
{{.CsrfTokenHtml}}
|
||||
<input type="hidden" name="new_branch_name" v-model="searchTerm">
|
||||
<input type="hidden" name="create_tag" v-model="createTag">
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -67,6 +67,16 @@
|
|||
<div class="ui container">
|
||||
<div class="ui divider"></div>
|
||||
<div class="ui text right">
|
||||
{{if not .PageIsEditRelease}}
|
||||
<div class="tag-message field">
|
||||
<div class="ui checkbox">
|
||||
<input type="checkbox" name="add_tag_msg">
|
||||
<label><strong>{{.i18n.Tr "repo.release.add_tag_msg"}}</strong></label>
|
||||
</div>
|
||||
</div>
|
||||
{{else}}
|
||||
<input type="hidden" name="add_tag_msg" value="false">
|
||||
{{end}}
|
||||
<div class="prerelease field">
|
||||
<div class="ui checkbox">
|
||||
<input type="checkbox" name="prerelease" {{if .prerelease}}checked{{end}}>
|
||||
|
@ -93,6 +103,9 @@
|
|||
</button>
|
||||
{{end}}
|
||||
{{else}}
|
||||
{{if not .tag_name}}
|
||||
<input class="ui grey button" type="submit" name="tag_only" value="{{.i18n.Tr "repo.release.add_tag"}}"/>
|
||||
{{end}}
|
||||
<input class="ui button" type="submit" name="draft" value="{{.i18n.Tr "repo.release.save_draft"}}"/>
|
||||
<button class="ui primary button">
|
||||
{{.i18n.Tr "repo.release.publish"}}
|
||||
|
|
|
@ -3310,6 +3310,7 @@ function initFilterBranchTagDropdown(selector) {
|
|||
noResults: '',
|
||||
canCreateBranch: false,
|
||||
menuVisible: false,
|
||||
createTag: false,
|
||||
active: 0
|
||||
};
|
||||
$data.find('.item').each(function () {
|
||||
|
@ -3341,7 +3342,7 @@ function initFilterBranchTagDropdown(selector) {
|
|||
return this.filteredItems.length === 0 && !this.showCreateNewBranch;
|
||||
},
|
||||
showCreateNewBranch() {
|
||||
if (!this.canCreateBranch || !this.searchTerm || this.mode === 'tags') {
|
||||
if (!this.canCreateBranch || !this.searchTerm) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue