diff --git a/models/issue.go b/models/issue.go index 19f00d5f3..3ed49ce42 100755 --- a/models/issue.go +++ b/models/issue.go @@ -775,6 +775,41 @@ func (issue *Issue) ChangeContent(doer *User, content string) (err error) { return sess.Commit() } +// ChangeRef changes issue ref, as the given user. +func (issue *Issue) ChangeRef(doer *User, newRef string) (err error) { + oldRef := issue.Ref + issue.Ref = newRef + if oldRef == newRef { + return nil + } + + sess := x.NewSession() + defer sess.Close() + if err = sess.Begin(); err != nil { + return err + } + + if err = updateIssueCols(sess, issue, "ref"); err != nil { + sess.Rollback() + return fmt.Errorf("UpdateIssueCols: %v", err) + } + + var opts = &CreateCommentOptions{ + Type: CommentTypeRef, + Doer: doer, + Repo: issue.Repo, + Issue: issue, + OldRef: oldRef, + NewRef: newRef, + } + if _, err = createComment(sess, opts); err != nil { + sess.Rollback() + return err + } + + return sess.Commit() +} + // GetTasks returns the amount of tasks in the issues content func (issue *Issue) GetTasks() int { return len(issueTasksPat.FindAllStringIndex(issue.Content, -1)) diff --git a/models/issue_comment.go b/models/issue_comment.go index 60d38452c..8197eba85 100755 --- a/models/issue_comment.go +++ b/models/issue_comment.go @@ -90,6 +90,8 @@ const ( CommentTypeReviewRequest // merge pull request CommentTypeMergePull + // Ref changed + CommentTypeRef ) // CommentTag defines comment tag type diff --git a/modules/templates/helper.go b/modules/templates/helper.go index 006a1e046..dbb9354aa 100755 --- a/modules/templates/helper.go +++ b/modules/templates/helper.go @@ -40,6 +40,14 @@ import ( "github.com/editorconfig/editorconfig-core-go/v2" ) +const ( + REF_HEADS_PREFIX = "refs/heads/" + REF_TAGS_PREFIX = "refs/tags/" + REF_TYPE_BRANCH = "branch" + REF_TYPE_TAG = "tag" + REF_TYPE_PATTERN = "(refs/heads/|refs/tags/)" +) + // Used from static.go && dynamic.go var mailSubjectSplit = regexp.MustCompile(`(?m)^-{3,}[\s]*$`) @@ -317,6 +325,8 @@ func NewFuncMap() []template.FuncMap { "DatasetPathJoin": func(arr []string, index int, seq string) string { return strings.Join(arr[1:index+1], seq) }, + "GetRefType": GetRefType, + "GetRefName": GetRefName, }} } @@ -444,10 +454,12 @@ func SafeJS(raw string) template.JS { func Str2html(raw string) template.HTML { return template.HTML(markup.Sanitize(raw)) } + // -func subOne(length int)int{ - return length-1 +func subOne(length int) int { + return length - 1 } + // Escape escapes a HTML string func Escape(raw string) string { return html.EscapeString(raw) @@ -758,3 +770,18 @@ func licenses() []string { func tasks() []string { return []string{"machine_translation", "question_answering_system", "information_retrieval", "knowledge_graph", "text_annotation", "text_categorization", "emotion_analysis", "language_modeling", "speech_recognition", "automatic_digest", "information_extraction", "description_generation", "image_classification", "face_recognition", "image_search", "target_detection", "image_description_generation", "vehicle_license_plate_recognition", "medical_image_analysis", "unmanned", "unmanned_security", "drone", "vr_ar", "2_d_vision", "2.5_d_vision", "3_d_reconstruction", "image_processing", "video_processing", "visual_input_system", "speech_coding", "speech_enhancement", "speech_synthesis"} } + +func GetRefType(ref string) string { + if strings.HasPrefix(ref, REF_HEADS_PREFIX) { + return REF_TYPE_BRANCH + } + if strings.HasPrefix(ref, REF_TAGS_PREFIX) { + return REF_TYPE_TAG + } + return "" +} + +func GetRefName(ref string) string { + reg := regexp.MustCompile(REF_TYPE_PATTERN) + return reg.ReplaceAllString(ref, "") +} diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 3b352652c..1ae488026 100755 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1332,6 +1332,7 @@ issues.new.labels = Labels issues.new.add_labels_title = Apply labels issues.new.no_label = No Label issues.new.clear_labels = Clear labels +issues.new.clear_branch_tag = Clear branch or tag issues.new.no_items = No items issues.new.milestone = Milestone issues.new.add_milestone_title = Set milestone @@ -1361,6 +1362,13 @@ issues.remove_label_at = removed the
- + {{svg "octicon-git-branch" 16}} {{.i18n.Tr "repo.branches"}} - + {{.i18n.Tr "repo.tags"}} diff --git a/templates/repo/issue/view_content/comments.tmpl b/templates/repo/issue/view_content/comments.tmpl index e3c7df674..796054005 100644 --- a/templates/repo/issue/view_content/comments.tmpl +++ b/templates/repo/issue/view_content/comments.tmpl @@ -594,5 +594,40 @@ {{end}}
+ {{else if eq .Type 29}} +
+ {{svg "octicon-git-branch" 16}} + + + + + {{.Poster.GetDisplayName}} + + {{ $refOldName:= GetRefName .OldRef }} + {{ $refNewName:= GetRefName .NewRef }} + + {{if .OldRef }} + {{if .NewRef }} + {{$.i18n.Tr "repo.issues.change_branch_tag_at" ($refOldName|Escape) ($refNewName|Escape) $createdStr | Safe}} + {{else}} + {{ $getRefOldType:= GetRefType .OldRef }} + {{ if eq $getRefOldType "branch"}} + {{$.i18n.Tr "repo.issues.remove_branch_at" ($refOldName|Escape) $createdStr | Safe}} + {{else}} + {{$.i18n.Tr "repo.issues.remove_tag_at" ($refOldName|Escape) $createdStr | Safe}} + {{end}} + {{end}} + {{else}} + {{if .NewRef}} + {{ $getRefNewType:= GetRefType .NewRef }} + {{ if eq $getRefNewType "branch"}} + {{$.i18n.Tr "repo.issues.add_branch_at" ($refNewName|Escape) $createdStr | Safe}} + {{else}} + {{$.i18n.Tr "repo.issues.add_tag_at" ($refNewName|Escape) $createdStr | Safe}} + {{end}} + {{end}} + {{end}} + +
{{end}} {{end}} diff --git a/templates/repo/issue/view_content/sidebar.tmpl b/templates/repo/issue/view_content/sidebar.tmpl index bcc69a48b..e6a61a567 100644 --- a/templates/repo/issue/view_content/sidebar.tmpl +++ b/templates/repo/issue/view_content/sidebar.tmpl @@ -1,6 +1,52 @@
- {{template "repo/issue/branch_selector_field" .}} + + {{if and (not .Issue.IsPull) (not .PageIsComparePull)}} + + + +
+ {{end}} {{if .Issue.IsPull }} @@ -600,3 +646,4 @@
{{end}} {{end}} + diff --git a/web_src/js/index.js b/web_src/js/index.js index cfc27109e..4092072f6 100755 --- a/web_src/js/index.js +++ b/web_src/js/index.js @@ -183,11 +183,11 @@ function initBranchSelector() { }); $selectBranch.find('.reference.column').on('click', function () { $selectBranch.find('.scrolling.reference-list-menu').css('display', 'none'); - $selectBranch.find('.reference .text').removeClass('black'); + $selectBranch.find('.reference .text').addClass('black'); $($(this).data('target')).css('display', 'block'); $(this) - .find('.text') - .addClass('black'); + .find('.text.black') + .removeClass('black'); return false; }); } @@ -230,7 +230,7 @@ function initLabelEdit() { }); } -function updateIssuesMeta(url, action, issueIds, elementId, isAdd) { +function updateIssuesMeta(url, action, issueIds, elementId,isAdd) { return new Promise((resolve) => { $.ajax({ type: 'POST', @@ -240,13 +240,14 @@ function updateIssuesMeta(url, action, issueIds, elementId, isAdd) { action, issue_ids: issueIds, id: elementId, - is_add: isAdd + is_add: isAdd, }, success: resolve }); }); } + function initRepoStatusChecker() { const migrating = $('#repo_migrating'); $('#repo_migrating_failed').hide(); @@ -486,12 +487,13 @@ function initCommentForm() { const promises = []; Object.keys(labels).forEach((elementId) => { const label = labels[elementId]; + console.log("label:",label) const promise = updateIssuesMeta( label['update-url'], label.action, label['issue-id'], elementId, - label['is-checked'] + label['is-checked'], ); promises.push(promise); }); @@ -531,7 +533,7 @@ function initCommentForm() { '', $listMenu.data('issue-id'), $(this).data('id'), - $(this).data('is-checked') + $(this).data('is-checked'), ); $listMenu.data('action', 'update'); // Update to reload the page when we updated items return false; @@ -603,6 +605,7 @@ function initCommentForm() { $listMenu.data('issue-id'), '', '' + ).then(reload); } @@ -636,10 +639,16 @@ function initCommentForm() { initListSubmits('select-reviewers-modify', 'assignees'); function selectItem(select_id, input_id) { - const $menu = $(`${select_id} .menu`); + let $menu; + if (select_id=='.select-branch'){ + $menu = $(`${select_id} .menu`).eq(1); + }else{ + $menu = $(`${select_id} .menu`); + } + const $list = $(`.ui${select_id}.list`); const hasUpdateAction = $menu.data('action') === 'update'; - + $menu.find('.item:not(.no-select)').on('click', function () { $(this) .parent() @@ -650,12 +659,17 @@ function initCommentForm() { $(this).addClass('selected active'); if (hasUpdateAction) { + //let ref = '' + //if (select_id=='.select-branch'){ + // ref = $(this).data('name'); + // } + updateIssuesMeta( $menu.data('update-url'), '', $menu.data('issue-id'), $(this).data('id'), - $(this).data('is-checked') + $(this).data('is-checked'), ).then(reload); } switch (input_id) { @@ -708,6 +722,7 @@ function initCommentForm() { // Milestone and assignee selectItem('.select-milestone', '#milestone_id'); selectItem('.select-assignee', '#assignee_id'); + selectItem('.select-branch', ''); } function initInstall() { @@ -810,7 +825,7 @@ function initIssueComments() { const issueId = $(this).data('issue-id'); const id = $(this).data('id'); const isChecked = $(this).data('is-checked'); - + //const ref = $(this).data('name'); event.preventDefault(); updateIssuesMeta(url, '', issueId, id, isChecked).then(reload); }); @@ -2899,6 +2914,7 @@ $(document).ready(async () => { }) .get() .join(); + console.log("this:",this) const {url} = this.dataset; if (elementId === '0' && url.substr(-9) === '/assignee') { elementId = '';