Skip to content

Commit 6693437

Browse files
committed
Add weight to api
Only show comments when weight is enabled
1 parent ef064c5 commit 6693437

File tree

6 files changed

+30
-6
lines changed

6 files changed

+30
-6
lines changed

modules/structs/issue.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ type Issue struct {
8080
Repo *RepositoryMeta `json:"repository"`
8181

8282
PinOrder int `json:"pin_order"`
83+
Weight int `json:"weight"`
8384
}
8485

8586
// CreateIssueOption options to create one issue
@@ -98,6 +99,7 @@ type CreateIssueOption struct {
9899
// list of label ids
99100
Labels []int64 `json:"labels"`
100101
Closed bool `json:"closed"`
102+
Weight int `json:"weight`
101103
}
102104

103105
// EditIssueOption options for editing an issue
@@ -113,6 +115,7 @@ type EditIssueOption struct {
113115
// swagger:strfmt date-time
114116
Deadline *time.Time `json:"due_date"`
115117
RemoveDeadline *bool `json:"unset_due_date"`
118+
Weight *int `json:"weight"`
116119
}
117120

118121
// EditDeadlineOption options for creating a deadline

routers/api/v1/repo/issue.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ func CreateIssue(ctx *context.APIContext) {
707707
form.Labels = make([]int64, 0)
708708
}
709709

710-
if err := issue_service.NewIssue(ctx, ctx.Repo.Repository, issue, form.Labels, nil, assigneeIDs, 0, 0); err != nil {
710+
if err := issue_service.NewIssue(ctx, ctx.Repo.Repository, issue, form.Labels, nil, assigneeIDs, 0, form.Weight); err != nil {
711711
if repo_model.IsErrUserDoesNotHaveAccessToRepo(err) {
712712
ctx.Error(http.StatusBadRequest, "UserDoesNotHaveAccessToRepo", err)
713713
} else if errors.Is(err, user_model.ErrBlockedUser) {
@@ -829,6 +829,13 @@ func EditIssue(ctx *context.APIContext) {
829829
}
830830
}
831831

832+
if form.Weight != nil {
833+
if err := issue_service.ChangeIssueWeight(ctx, issue, ctx.Doer, *form.Weight); err != nil {
834+
ctx.Error(http.StatusInternalServerError, "ChangeWeight", err)
835+
return
836+
}
837+
}
838+
832839
// Update or remove the deadline, only if set and allowed
833840
if (form.Deadline != nil || form.RemoveDeadline != nil) && canWrite {
834841
var deadlineUnix timeutil.TimeStamp

routers/web/repo/issue.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption opt
266266
}
267267

268268
if repo.IsWeightEnabled(ctx) {
269-
totalWeight, totalWeightClosed, err := issues_model.GetIssueTotalWeight(ctx, statsOpts, isShowClosed)
269+
totalWeight, totalWeightClosed, err := issues_model.GetIssueTotalWeight(ctx, statsOpts)
270270
if err != nil {
271271
ctx.ServerError("GetIssueTotalWeight", err)
272272
return
@@ -2398,7 +2398,6 @@ func UpdateIssueWeight(ctx *context.Context) {
23982398
}
23992399

24002400
ctx.Redirect(issue.Link())
2401-
// ctx.JSON(http.StatusCreated, api.IssueWeight{Weight: form.Weight})
24022401
}
24032402

24042403
// UpdateIssueMilestone change issue's milestone

services/convert/issue.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ func toIssue(ctx context.Context, doer *user_model.User, issue *issues_model.Iss
5555
Created: issue.CreatedUnix.AsTime(),
5656
Updated: issue.UpdatedUnix.AsTime(),
5757
PinOrder: issue.PinOrder,
58+
Weight: issue.Weight,
5859
}
5960

6061
if issue.Repo != nil {

services/issue/issue.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,19 @@ func ChangeIssueRef(ctx context.Context, issue *issues_model.Issue, doer *user_m
126126
return nil
127127
}
128128

129+
// ChangeIssueWeight changes the weight of this issue, as the given user.
130+
func ChangeIssueWeight(ctx context.Context, issue *issues_model.Issue, doer *user_model.User, weight int) error {
131+
if issue.Weight == weight {
132+
return nil
133+
}
134+
135+
if err := issues_model.UpdateIssueWeight(ctx, issue, weight, doer); err != nil {
136+
return err
137+
}
138+
139+
return nil
140+
}
141+
129142
// UpdateAssignees is a helper function to add or delete one or multiple issue assignee(s)
130143
// Deleting is done the GitHub way (quote from their api documentation):
131144
// https://developer.github.com/v3/issues/#edit-an-issue

templates/repo/issue/view_content/comments.tmpl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{{range .Issue.Comments}}
33
{{if call $.ShouldShowCommentType .Type}}
44
{{$createdStr:= TimeSinceUnix .CreatedUnix ctx.Locale}}
5+
{{$isWeightEnabled:= $.Repository.IsWeightEnabled ctx}}
56

67
<!-- 0 = COMMENT, 1 = REOPEN, 2 = CLOSE, 3 = ISSUE_REF, 4 = COMMIT_REF,
78
5 = COMMENT_REF, 6 = PULL_REF, 7 = COMMENT_LABEL, 8 = MILESTONE_CHANGE,
@@ -700,7 +701,7 @@
700701
{{else}}{{ctx.Locale.Tr "repo.issues.unpin_comment" $createdStr}}{{end}}
701702
</span>
702703
</div>
703-
{{else if eq .Type 38}}
704+
{{else if and (eq .Type 38) ($isWeightEnabled)}}
704705
<div class="timeline-item event" id="{{.HashTag}}">
705706
<span class="badge">{{svg "octicon-clock"}}</span>
706707
{{template "shared/user/avatarlink" dict "user" .Poster}}
@@ -709,7 +710,7 @@
709710
{{ctx.Locale.Tr "repo.issues.weight_added" .Content $createdStr}}
710711
</span>
711712
</div>
712-
{{else if eq .Type 39}}
713+
{{else if and (eq .Type 39) ($isWeightEnabled)}}
713714
<div class="timeline-item event" id="{{.HashTag}}">
714715
<span class="badge">{{svg "octicon-clock"}}</span>
715716
{{template "shared/user/avatarlink" dict "user" .Poster}}
@@ -724,7 +725,7 @@
724725
{{end}}
725726
</span>
726727
</div>
727-
{{else if eq .Type 40}}
728+
{{else if and (eq .Type 40) ($isWeightEnabled)}}
728729
<div class="timeline-item event" id="{{.HashTag}}">
729730
<span class="badge">{{svg "octicon-clock"}}</span>
730731
{{template "shared/user/avatarlink" dict "user" .Poster}}

0 commit comments

Comments
 (0)