Skip to content

Commit da230a2

Browse files
gzsomborlafriks
authored andcommitted
Add possibility to record branch or tag information in an issue (#780)
1 parent 174255e commit da230a2

File tree

9 files changed

+78
-0
lines changed

9 files changed

+78
-0
lines changed

models/issue.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ type Issue struct {
4949
IsPull bool `xorm:"INDEX"` // Indicates whether is a pull request or not.
5050
PullRequest *PullRequest `xorm:"-"`
5151
NumComments int
52+
Ref string
5253

5354
Deadline time.Time `xorm:"-"`
5455
DeadlineUnix int64 `xorm:"INDEX"`

modules/auth/repo_form.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ func (f *NewSlackHookForm) Validate(ctx *macaron.Context, errs binding.Errors) b
194194
type CreateIssueForm struct {
195195
Title string `binding:"Required;MaxSize(255)"`
196196
LabelIDs string `form:"label_ids"`
197+
Ref string `form:"ref"`
197198
MilestoneID int64
198199
AssigneeID int64
199200
Content string

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,7 @@ issues.new.closed_milestone = Closed Milestones
612612
issues.new.assignee = Assignee
613613
issues.new.clear_assignee = Clear assignee
614614
issues.new.no_assignee = No assignee
615+
issues.no_ref = No Branch/Tag Specified
615616
issues.create = Create Issue
616617
issues.new_label = New Label
617618
issues.new_label_placeholder = Label name...

public/js/index.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,22 @@ function initEditForm() {
8686
initEditDiffTab($('.edit.form'));
8787
}
8888

89+
function initBranchSelector() {
90+
var $selectBranch = $('.ui.select-branch')
91+
var $branchMenu = $selectBranch.find('.reference-list-menu');
92+
$branchMenu.find('.item:not(.no-select)').click(function () {
93+
var selectedValue = $(this).data('id');
94+
$($(this).data('id-selector')).val(selectedValue);
95+
$selectBranch.find('.ui .branch-name').text(selectedValue);
96+
});
97+
$selectBranch.find('.reference.column').click(function () {
98+
$selectBranch.find('.scrolling.reference-list-menu').css('display', 'none');
99+
$selectBranch.find('.reference .text').removeClass('black');
100+
$($(this).data('target')).css('display', 'block');
101+
$(this).find('.text').addClass('black');
102+
return false;
103+
});
104+
}
89105

90106
function updateIssuesMeta(url, action, issueIds, elementId, afterSuccess) {
91107
$.ajax({
@@ -106,6 +122,7 @@ function initCommentForm() {
106122
return
107123
}
108124

125+
initBranchSelector();
109126
initCommentPreviewTab($('.comment.form'));
110127

111128
// Labels

routers/repo/issue.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,13 @@ func RetrieveRepoMetas(ctx *context.Context, repo *models.Repository) []*models.
292292
return nil
293293
}
294294

295+
brs, err := ctx.Repo.GitRepo.GetBranches()
296+
if err != nil {
297+
ctx.Handle(500, "GetBranches", err)
298+
return nil
299+
}
300+
ctx.Data["Branches"] = brs
301+
295302
return labels
296303
}
297304

@@ -418,6 +425,7 @@ func NewIssuePost(ctx *context.Context, form auth.CreateIssueForm) {
418425
ctx.Data["PageIsIssueList"] = true
419426
ctx.Data["RequireHighlightJS"] = true
420427
ctx.Data["RequireSimpleMDE"] = true
428+
ctx.Data["ReadOnly"] = false
421429
renderAttachmentSettings(ctx)
422430

423431
var (
@@ -447,6 +455,7 @@ func NewIssuePost(ctx *context.Context, form auth.CreateIssueForm) {
447455
MilestoneID: milestoneID,
448456
AssigneeID: assigneeID,
449457
Content: form.Content,
458+
Ref: form.Ref,
450459
}
451460
if err := models.NewIssue(repo, issue, labelIDs, attachments); err != nil {
452461
ctx.Handle(500, "NewIssue", err)
@@ -668,6 +677,7 @@ func ViewIssue(ctx *context.Context) {
668677
ctx.Data["Participants"] = participants
669678
ctx.Data["NumParticipants"] = len(participants)
670679
ctx.Data["Issue"] = issue
680+
ctx.Data["ReadOnly"] = true
671681
ctx.Data["IsIssueOwner"] = ctx.Repo.IsWriter() || (ctx.IsSigned && issue.IsPoster(ctx.User.ID))
672682
ctx.Data["SignInLink"] = setting.AppSubURL + "/user/login?redirect_to=" + ctx.Data["Link"].(string)
673683
ctx.HTML(200, tplIssueView)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<input id="ref_selector" name="ref" type="hidden" value="{{.Issue.Ref}}">
2+
<div class="ui {{if .ReadOnly}}disabled{{end}} floating filter select-branch dropdown" data-no-results="{{.i18n.Tr "repo.pulls.no_results"}}">
3+
<div class="ui basic small button">
4+
<span class="text branch-name">{{if .Issue.Ref}}{{.Issue.Ref}}{{else}}{{.i18n.Tr "repo.issues.no_ref"}}{{end}}</span>
5+
<i class="dropdown icon"></i>
6+
</div>
7+
<div class="menu">
8+
<div class="ui icon search input">
9+
<i class="filter icon"></i>
10+
<input name="search" placeholder="{{.i18n.Tr "repo.filter_branch_and_tag"}}...">
11+
</div>
12+
<div class="header">
13+
<div class="ui grid">
14+
<div class="two column row">
15+
<a class="reference column" href="#" data-target="#branch-list">
16+
<span class="text black">
17+
<i class="octicon octicon-git-branch"></i> {{.i18n.Tr "repo.branches"}}
18+
</span>
19+
</a>
20+
<a class="reference column" href="#" data-target="#tag-list">
21+
<span class="text">
22+
<i class="reference tags icon"></i> {{.i18n.Tr "repo.tags"}}
23+
</span>
24+
</a>
25+
</div>
26+
</div>
27+
</div>
28+
<div id="branch-list" class="scrolling menu reference-list-menu">
29+
{{range .Branches}}
30+
<div class="item" data-id="{{.}}" data-id-selector="#ref_selector">{{.}}</div>
31+
{{end}}
32+
</div>
33+
<div id="tag-list" class="scrolling menu reference-list-menu" style="display: none">
34+
{{range .Tags}}
35+
<div class="item" data-id="{{.}}" data-id-selector="#ref_selector">{{.}}</div>
36+
{{end}}
37+
</div>
38+
</div>
39+
</div>
40+
41+
<div class="ui divider"></div>

templates/repo/issue/list.tmpl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@
171171
<div class="ui {{if .IsRead}}black{{else}}green{{end}} label">#{{.Index}}</div>
172172
<a class="title has-emoji" href="{{$.Link}}/{{.Index}}">{{.Title}}</a>
173173

174+
{{if .Ref}}
175+
<a class="ui label" href="{{$.RepoLink}}/src/{{.Ref}}">{{.Ref}}</a>
176+
{{end}}
174177
{{range .Labels}}
175178
<a class="ui label" href="{{$.Link}}?q={{$.Keyword}}&type={{$.ViewType}}&state={{$.State}}&labels={{.ID}}&milestone={{$.MilestoneID}}&assignee={{$.AssigneeID}}" style="color: {{.ForegroundColor}}; background-color: {{.Color}}">{{.Name | Sanitize}}</a>
176179
{{end}}

templates/repo/issue/new_form.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232

3333
<div class="four wide column">
3434
<div class="ui segment metas">
35+
{{template "repo/issue/branch_selector_field" .}}
36+
3537
<input id="label_ids" name="label_ids" type="hidden" value="{{.label_ids}}">
3638
<div class="ui {{if not .Labels}}disabled{{end}} floating jump select-label dropdown">
3739
<span class="text">

templates/repo/issue/view_content/sidebar.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<div class="four wide column">
22
<div class="ui segment metas">
3+
{{template "repo/issue/branch_selector_field" .}}
4+
35
<div class="ui {{if not .IsRepositoryWriter}}disabled{{end}} floating jump select-label dropdown">
46
<span class="text">
57
<strong>{{.i18n.Tr "repo.issues.new.labels"}}</strong>

0 commit comments

Comments
 (0)