// NewBranchForm form for creating a new branch
type NewBranchForm struct {
NewBranchName string `binding:"Required;MaxSize(100);GitRefName"`
+ CreateTag bool
}
// Validate validates the fields
Title string `binding:"Required;MaxSize(255)"`
Content string
Draft string
+ TagOnly string
Prerelease bool
+ AddTagMsg bool
Files []string
}
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)
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
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
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 {
"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"
)
}
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)
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))
}
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,
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):
IsDraft: false,
IsPrerelease: false,
IsTag: true,
- }, nil))
+ }, nil, ""))
err = mirror.GetMirror()
assert.NoError(t, err)
"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) {
// 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,
}
// 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
}
}
- if err = createTag(gitRepo, rel); err != nil {
+ if err = createTag(gitRepo, rel, msg); err != nil {
return err
}
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)
IsDraft: false,
IsPrerelease: false,
IsTag: false,
- }, nil))
+ }, nil, ""))
assert.NoError(t, CreateRelease(gitRepo, &models.Release{
RepoID: repo.ID,
IsDraft: false,
IsPrerelease: false,
IsTag: false,
- }, nil))
+ }, nil, ""))
assert.NoError(t, CreateRelease(gitRepo, &models.Release{
RepoID: repo.ID,
IsDraft: false,
IsPrerelease: false,
IsTag: false,
- }, nil))
+ }, nil, ""))
assert.NoError(t, CreateRelease(gitRepo, &models.Release{
RepoID: repo.ID,
IsDraft: true,
IsPrerelease: false,
IsTag: false,
- }, nil))
+ }, nil, ""))
assert.NoError(t, CreateRelease(gitRepo, &models.Release{
RepoID: repo.ID,
IsDraft: false,
IsPrerelease: true,
IsTag: false,
- }, nil))
+ }, nil, ""))
assert.NoError(t, CreateRelease(gitRepo, &models.Release{
RepoID: repo.ID,
IsDraft: false,
IsPrerelease: false,
IsTag: true,
- }, nil))
+ }, nil, "test"))
}
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
IsDraft: true,
IsPrerelease: false,
IsTag: false,
- }, nil))
+ }, nil, ""))
release, err = models.GetRelease(repo.ID, "v1.2.1")
assert.NoError(t, err)
releaseCreatedUnix = release.CreatedUnix
IsDraft: false,
IsPrerelease: true,
IsTag: false,
- }, nil))
+ }, nil, ""))
release, err = models.GetRelease(repo.ID, "v1.3.1")
assert.NoError(t, err)
releaseCreatedUnix = release.CreatedUnix
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
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
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"))
+}
<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>
<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>
<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>
<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}}>
</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"}}
noResults: '',
canCreateBranch: false,
menuVisible: false,
+ createTag: false,
active: 0
};
$data.find('.item').each(function () {
return this.filteredItems.length === 0 && !this.showCreateNewBranch;
},
showCreateNewBranch() {
- if (!this.canCreateBranch || !this.searchTerm || this.mode === 'tags') {
+ if (!this.canCreateBranch || !this.searchTerm) {
return false;
}