Browse Source

#3383 code cleanup

Unknwon 3 years ago
parent
commit
0b273ac4d5

+ 2 - 2
.gopmfile

@@ -18,8 +18,8 @@ github.com/go-xorm/core = commit:5bf745d
18 18
 github.com/go-xorm/xorm = commit:c6c7056
19 19
 github.com/gogits/chardet = commit:2404f77
20 20
 github.com/gogits/cron = commit:7f3990a
21
-github.com/gogits/git-module = commit:f78bf3b
22
-github.com/gogits/go-gogs-client = commit:5e50f02
21
+github.com/gogits/git-module = commit:7b206b5
22
+github.com/gogits/go-gogs-client = commit:2ffd470
23 23
 github.com/issue9/identicon = commit:d36b545
24 24
 github.com/jaytaylor/html2text = commit:52d9b78
25 25
 github.com/kardianos/minwinsvc = commit:cad6b2b

+ 1 - 1
README.md

@@ -3,7 +3,7 @@ Gogs - Go Git Service [![Build Status](https://travis-ci.org/gogits/gogs.svg?bra
3 3
 
4 4
 ![](https://github.com/gogits/gogs/blob/master/public/img/gogs-large-resize.png?raw=true)
5 5
 
6
-##### Current tip version: 0.9.83 (see [Releases](https://github.com/gogits/gogs/releases) for binary versions)
6
+##### Current tip version: 0.9.84 (see [Releases](https://github.com/gogits/gogs/releases) for binary versions)
7 7
 
8 8
 | Web | UI  | Preview  |
9 9
 |:-------------:|:-------:|:-------:|

+ 1 - 1
cmd/web.go

@@ -88,7 +88,7 @@ func checkVersion() {
88 88
 		{"github.com/go-macaron/toolbox", toolbox.Version, "0.1.0"},
89 89
 		{"gopkg.in/ini.v1", ini.Version, "1.8.4"},
90 90
 		{"gopkg.in/macaron.v1", macaron.Version, "1.1.7"},
91
-		{"github.com/gogits/git-module", git.Version, "0.3.7"},
91
+		{"github.com/gogits/git-module", git.Version, "0.3.8"},
92 92
 		{"github.com/gogits/go-gogs-client", gogs.Version, "0.12.1"},
93 93
 	}
94 94
 	for _, c := range checkers {

+ 2 - 2
glide.lock

@@ -41,9 +41,9 @@ imports:
41 41
 - name: github.com/gogits/cron
42 42
   version: 7f3990acf1833faa5ebd0e86f0a4c72a4b5eba3c
43 43
 - name: github.com/gogits/git-module
44
-  version: f78bf3bf703cb3eb0e85a9475d26826939feda4f
44
+  version: 7b206b529a09ae8cfa1df52a6c0cdd2612cfc6fc
45 45
 - name: github.com/gogits/go-gogs-client
46
-  version: 5e50f0292565471b41b3c73fcadcb886140f0082
46
+  version: 2ffd4704c6f37d7fb10110450fe035fa6df08db8
47 47
 - name: github.com/issue9/identicon
48 48
   version: d36b54562f4cf70c83653e13dc95c220c79ef521
49 49
 - name: github.com/jaytaylor/html2text

+ 1 - 1
gogs.go

@@ -17,7 +17,7 @@ import (
17 17
 	"github.com/gogits/gogs/modules/setting"
18 18
 )
19 19
 
20
-const APP_VER = "0.9.83.0816"
20
+const APP_VER = "0.9.84.0824"
21 21
 
22 22
 func init() {
23 23
 	runtime.GOMAXPROCS(runtime.NumCPU())

+ 49 - 58
models/issue.go

@@ -62,73 +62,73 @@ type Issue struct {
62 62
 	Comments    []*Comment    `xorm:"-"`
63 63
 }
64 64
 
65
-func (i *Issue) BeforeInsert() {
66
-	i.CreatedUnix = time.Now().Unix()
67
-	i.UpdatedUnix = i.CreatedUnix
65
+func (issue *Issue) BeforeInsert() {
66
+	issue.CreatedUnix = time.Now().Unix()
67
+	issue.UpdatedUnix = issue.CreatedUnix
68 68
 }
69 69
 
70
-func (i *Issue) BeforeUpdate() {
71
-	i.UpdatedUnix = time.Now().Unix()
72
-	i.DeadlineUnix = i.Deadline.Unix()
70
+func (issue *Issue) BeforeUpdate() {
71
+	issue.UpdatedUnix = time.Now().Unix()
72
+	issue.DeadlineUnix = issue.Deadline.Unix()
73 73
 }
74 74
 
75
-func (i *Issue) AfterSet(colName string, _ xorm.Cell) {
75
+func (issue *Issue) AfterSet(colName string, _ xorm.Cell) {
76 76
 	var err error
77 77
 	switch colName {
78 78
 	case "id":
79
-		i.Attachments, err = GetAttachmentsByIssueID(i.ID)
79
+		issue.Attachments, err = GetAttachmentsByIssueID(issue.ID)
80 80
 		if err != nil {
81
-			log.Error(3, "GetAttachmentsByIssueID[%d]: %v", i.ID, err)
81
+			log.Error(3, "GetAttachmentsByIssueID[%d]: %v", issue.ID, err)
82 82
 		}
83 83
 
84
-		i.Comments, err = GetCommentsByIssueID(i.ID)
84
+		issue.Comments, err = GetCommentsByIssueID(issue.ID)
85 85
 		if err != nil {
86
-			log.Error(3, "GetCommentsByIssueID[%d]: %v", i.ID, err)
86
+			log.Error(3, "GetCommentsByIssueID[%d]: %v", issue.ID, err)
87 87
 		}
88 88
 
89
-		i.Labels, err = GetLabelsByIssueID(i.ID)
89
+		issue.Labels, err = GetLabelsByIssueID(issue.ID)
90 90
 		if err != nil {
91
-			log.Error(3, "GetLabelsByIssueID[%d]: %v", i.ID, err)
91
+			log.Error(3, "GetLabelsByIssueID[%d]: %v", issue.ID, err)
92 92
 		}
93 93
 
94 94
 	case "poster_id":
95
-		i.Poster, err = GetUserByID(i.PosterID)
95
+		issue.Poster, err = GetUserByID(issue.PosterID)
96 96
 		if err != nil {
97 97
 			if IsErrUserNotExist(err) {
98
-				i.PosterID = -1
99
-				i.Poster = NewGhostUser()
98
+				issue.PosterID = -1
99
+				issue.Poster = NewGhostUser()
100 100
 			} else {
101
-				log.Error(3, "GetUserByID[%d]: %v", i.ID, err)
101
+				log.Error(3, "GetUserByID[%d]: %v", issue.ID, err)
102 102
 			}
103 103
 			return
104 104
 		}
105 105
 
106 106
 	case "milestone_id":
107
-		if i.MilestoneID == 0 {
107
+		if issue.MilestoneID == 0 {
108 108
 			return
109 109
 		}
110 110
 
111
-		i.Milestone, err = GetMilestoneByID(i.MilestoneID)
111
+		issue.Milestone, err = GetMilestoneByRepoID(issue.RepoID, issue.MilestoneID)
112 112
 		if err != nil {
113
-			log.Error(3, "GetMilestoneById[%d]: %v", i.ID, err)
113
+			log.Error(3, "GetMilestoneById[%d]: %v", issue.ID, err)
114 114
 		}
115 115
 
116 116
 	case "assignee_id":
117
-		if i.AssigneeID == 0 {
117
+		if issue.AssigneeID == 0 {
118 118
 			return
119 119
 		}
120 120
 
121
-		i.Assignee, err = GetUserByID(i.AssigneeID)
121
+		issue.Assignee, err = GetUserByID(issue.AssigneeID)
122 122
 		if err != nil {
123
-			log.Error(3, "GetUserByID[%d]: %v", i.ID, err)
123
+			log.Error(3, "GetUserByID[%d]: %v", issue.ID, err)
124 124
 		}
125 125
 
126 126
 	case "deadline_unix":
127
-		i.Deadline = time.Unix(i.DeadlineUnix, 0).Local()
127
+		issue.Deadline = time.Unix(issue.DeadlineUnix, 0).Local()
128 128
 	case "created_unix":
129
-		i.Created = time.Unix(i.CreatedUnix, 0).Local()
129
+		issue.Created = time.Unix(issue.CreatedUnix, 0).Local()
130 130
 	case "updated_unix":
131
-		i.Updated = time.Unix(i.UpdatedUnix, 0).Local()
131
+		issue.Updated = time.Unix(issue.UpdatedUnix, 0).Local()
132 132
 	}
133 133
 }
134 134
 
@@ -600,7 +600,7 @@ func newIssue(e *xorm.Session, opts NewIssueOptions) (err error) {
600 600
 	opts.Issue.Index = opts.Repo.NextIssueIndex()
601 601
 
602 602
 	if opts.Issue.MilestoneID > 0 {
603
-		milestone, err := getMilestoneByID(e, opts.Issue.MilestoneID)
603
+		milestone, err := getMilestoneByRepoID(e, opts.Issue.RepoID, opts.Issue.MilestoneID)
604 604
 		if err != nil && !IsErrMilestoneNotExist(err) {
605 605
 			return fmt.Errorf("getMilestoneByID: %v", err)
606 606
 		}
@@ -1392,50 +1392,41 @@ func NewMilestone(m *Milestone) (err error) {
1392 1392
 		return err
1393 1393
 	}
1394 1394
 
1395
-	if _, err = sess.Exec("UPDATE `repository` SET num_milestones=num_milestones+1 WHERE id=?", m.RepoID); err != nil {
1395
+	if _, err = sess.Exec("UPDATE `repository` SET num_milestones = num_milestones + 1 WHERE id = ?", m.RepoID); err != nil {
1396 1396
 		return err
1397 1397
 	}
1398 1398
 	return sess.Commit()
1399 1399
 }
1400 1400
 
1401
-func getMilestoneByID(e Engine, id int64) (*Milestone, error) {
1402
-	m := &Milestone{ID: id}
1401
+func getMilestoneByRepoID(e Engine, repoID, id int64) (*Milestone, error) {
1402
+	m := &Milestone{
1403
+		ID:     id,
1404
+		RepoID: repoID,
1405
+	}
1403 1406
 	has, err := e.Get(m)
1404 1407
 	if err != nil {
1405 1408
 		return nil, err
1406 1409
 	} else if !has {
1407
-		return nil, ErrMilestoneNotExist{id, 0}
1410
+		return nil, ErrMilestoneNotExist{id, repoID}
1408 1411
 	}
1409 1412
 	return m, nil
1410 1413
 }
1411 1414
 
1412
-// GetMilestoneByID returns the milestone of given ID.
1413
-func GetMilestoneByID(id int64) (*Milestone, error) {
1414
-	return getMilestoneByID(x, id)
1415
-}
1416
-
1417
-// GetRepoMilestoneByID returns the milestone of given ID and repository.
1418
-func GetRepoMilestoneByID(repoID, milestoneID int64) (*Milestone, error) {
1419
-	m := &Milestone{ID: milestoneID, RepoID: repoID}
1420
-	has, err := x.Get(m)
1421
-	if err != nil {
1422
-		return nil, err
1423
-	} else if !has {
1424
-		return nil, ErrMilestoneNotExist{milestoneID, repoID}
1425
-	}
1426
-	return m, nil
1415
+// GetWebhookByRepoID returns milestone of repository by given ID.
1416
+func GetMilestoneByRepoID(repoID, id int64) (*Milestone, error) {
1417
+	return getMilestoneByRepoID(x, repoID, id)
1427 1418
 }
1428 1419
 
1429
-// GetAllRepoMilestones returns all milestones of given repository.
1430
-func GetAllRepoMilestones(repoID int64) ([]*Milestone, error) {
1420
+// GetMilestonesByRepoID returns all milestones of a repository.
1421
+func GetMilestonesByRepoID(repoID int64) ([]*Milestone, error) {
1431 1422
 	miles := make([]*Milestone, 0, 10)
1432
-	return miles, x.Where("repo_id=?", repoID).Find(&miles)
1423
+	return miles, x.Where("repo_id = ?", repoID).Find(&miles)
1433 1424
 }
1434 1425
 
1435 1426
 // GetMilestones returns a list of milestones of given repository and status.
1436 1427
 func GetMilestones(repoID int64, page int, isClosed bool) ([]*Milestone, error) {
1437 1428
 	miles := make([]*Milestone, 0, setting.UI.IssuePagingNum)
1438
-	sess := x.Where("repo_id=? AND is_closed=?", repoID, isClosed)
1429
+	sess := x.Where("repo_id = ? AND is_closed = ?", repoID, isClosed)
1439 1430
 	if page > 0 {
1440 1431
 		sess = sess.Limit(setting.UI.IssuePagingNum, (page-1)*setting.UI.IssuePagingNum)
1441 1432
 	}
@@ -1509,7 +1500,7 @@ func changeMilestoneIssueStats(e *xorm.Session, issue *Issue) error {
1509 1500
 		return nil
1510 1501
 	}
1511 1502
 
1512
-	m, err := getMilestoneByID(e, issue.MilestoneID)
1503
+	m, err := getMilestoneByRepoID(e, issue.RepoID, issue.MilestoneID)
1513 1504
 	if err != nil {
1514 1505
 		return err
1515 1506
 	}
@@ -1543,7 +1534,7 @@ func ChangeMilestoneIssueStats(issue *Issue) (err error) {
1543 1534
 
1544 1535
 func changeMilestoneAssign(e *xorm.Session, issue *Issue, oldMilestoneID int64) error {
1545 1536
 	if oldMilestoneID > 0 {
1546
-		m, err := getMilestoneByID(e, oldMilestoneID)
1537
+		m, err := getMilestoneByRepoID(e, issue.RepoID, oldMilestoneID)
1547 1538
 		if err != nil {
1548 1539
 			return err
1549 1540
 		}
@@ -1561,7 +1552,7 @@ func changeMilestoneAssign(e *xorm.Session, issue *Issue, oldMilestoneID int64)
1561 1552
 	}
1562 1553
 
1563 1554
 	if issue.MilestoneID > 0 {
1564
-		m, err := getMilestoneByID(e, issue.MilestoneID)
1555
+		m, err := getMilestoneByRepoID(e, issue.RepoID, issue.MilestoneID)
1565 1556
 		if err != nil {
1566 1557
 			return err
1567 1558
 		}
@@ -1595,9 +1586,9 @@ func ChangeMilestoneAssign(issue *Issue, oldMilestoneID int64) (err error) {
1595 1586
 	return sess.Commit()
1596 1587
 }
1597 1588
 
1598
-// DeleteMilestoneByID deletes a milestone by given ID.
1599
-func DeleteMilestoneByID(id int64) error {
1600
-	m, err := GetMilestoneByID(id)
1589
+// DeleteMilestoneByRepoID deletes a milestone from a repository.
1590
+func DeleteMilestoneByRepoID(repoID, id int64) error {
1591
+	m, err := GetMilestoneByRepoID(repoID, id)
1601 1592
 	if err != nil {
1602 1593
 		if IsErrMilestoneNotExist(err) {
1603 1594
 			return nil
@@ -1626,9 +1617,9 @@ func DeleteMilestoneByID(id int64) error {
1626 1617
 		return err
1627 1618
 	}
1628 1619
 
1629
-	if _, err = sess.Exec("UPDATE `issue` SET milestone_id=0 WHERE milestone_id=?", m.ID); err != nil {
1620
+	if _, err = sess.Exec("UPDATE `issue` SET milestone_id = 0 WHERE milestone_id = ?", m.ID); err != nil {
1630 1621
 		return err
1631
-	} else if _, err = sess.Exec("UPDATE `issue_user` SET milestone_id=0 WHERE milestone_id=?", m.ID); err != nil {
1622
+	} else if _, err = sess.Exec("UPDATE `issue_user` SET milestone_id = 0 WHERE milestone_id = ?", m.ID); err != nil {
1632 1623
 		return err
1633 1624
 	}
1634 1625
 	return sess.Commit()

+ 1 - 1
models/repo.go

@@ -359,7 +359,7 @@ func (repo *Repository) GetAssigneeByID(userID int64) (*User, error) {
359 359
 
360 360
 // GetMilestoneByID returns the milestone belongs to repository by given ID.
361 361
 func (repo *Repository) GetMilestoneByID(milestoneID int64) (*Milestone, error) {
362
-	return GetRepoMilestoneByID(repo.ID, milestoneID)
362
+	return GetMilestoneByRepoID(repo.ID, milestoneID)
363 363
 }
364 364
 
365 365
 // IssueStats returns number of open and closed repository issues by given filter mode.

+ 10 - 7
models/webhook.go

@@ -210,15 +210,18 @@ func GetWebhookByOrgID(orgID, id int64) (*Webhook, error) {
210 210
 }
211 211
 
212 212
 // GetActiveWebhooksByRepoID returns all active webhooks of repository.
213
-func GetActiveWebhooksByRepoID(repoID int64) (ws []*Webhook, err error) {
214
-	err = x.Where("repo_id=?", repoID).And("is_active=?", true).Find(&ws)
215
-	return ws, err
213
+func GetActiveWebhooksByRepoID(repoID int64) ([]*Webhook, error) {
214
+	webhooks := make([]*Webhook, 0, 5)
215
+	return webhooks, x.Find(&webhooks, &Webhook{
216
+		RepoID:   repoID,
217
+		IsActive: true,
218
+	})
216 219
 }
217 220
 
218
-// GetWebhooksByRepoID returns all webhooks of repository.
219
-func GetWebhooksByRepoID(repoID int64) (ws []*Webhook, err error) {
220
-	err = x.Find(&ws, &Webhook{RepoID: repoID})
221
-	return ws, err
221
+// GetWebhooksByRepoID returns all webhooks of a repository.
222
+func GetWebhooksByRepoID(repoID int64) ([]*Webhook, error) {
223
+	webhooks := make([]*Webhook, 0, 5)
224
+	return webhooks, x.Find(&webhooks, &Webhook{RepoID: repoID})
222 225
 }
223 226
 
224 227
 // UpdateWebhook updates information of webhook.

File diff suppressed because it is too large
+ 2 - 2
modules/bindata/bindata.go


+ 13 - 9
routers/api/v1/api.go

@@ -110,6 +110,15 @@ func reqAdmin() macaron.Handler {
110 110
 	}
111 111
 }
112 112
 
113
+func reqRepoWriter() macaron.Handler {
114
+	return func(ctx *context.Context) {
115
+		if !ctx.Repo.IsWriter() {
116
+			ctx.Error(403)
117
+			return
118
+		}
119
+	}
120
+}
121
+
113 122
 func orgAssignment(args ...bool) macaron.Handler {
114 123
 	var (
115 124
 		assignOrg  bool
@@ -259,11 +268,6 @@ func RegisterRoutes(m *macaron.Macaron) {
259 268
 								Delete(repo.ClearIssueLabels)
260 269
 							m.Delete("/:id", repo.DeleteIssueLabel)
261 270
 						})
262
-						m.Group("/milestone", func() {
263
-							m.Combo("").Get(repo.GetIssueMilestone).
264
-								Post(bind(api.SetIssueMilestoneOption{}), repo.SetIssueMilestone).
265
-								Delete(repo.DeleteIssueMilestone)
266
-						})
267 271
 
268 272
 					})
269 273
 				}, mustEnableIssues)
@@ -275,10 +279,10 @@ func RegisterRoutes(m *macaron.Macaron) {
275 279
 				})
276 280
 				m.Group("/milestones", func() {
277 281
 					m.Combo("").Get(repo.ListMilestones).
278
-						Post(bind(api.CreateMilestoneOption{}), repo.CreateMilestone)
279
-					m.Combo("/:id").Get(repo.GetMilestone).Patch(bind(api.EditMilestoneOption{}), repo.EditMilestone).
280
-						Delete(repo.DeleteMilestone)
281
-					m.Post("/:id/:action", repo.ChangeMilestoneStatus)
282
+						Post(reqRepoWriter(), bind(api.CreateMilestoneOption{}), repo.CreateMilestone)
283
+					m.Combo("/:id").Get(repo.GetMilestone).
284
+						Patch(reqRepoWriter(), bind(api.EditMilestoneOption{}), repo.EditMilestone).
285
+						Delete(reqRepoWriter(), repo.DeleteMilestone)
282 286
 				})
283 287
 			}, repoAssignment())
284 288
 		}, reqToken())

+ 1 - 2
routers/api/v1/repo/issue.go

@@ -49,7 +49,6 @@ func GetIssue(ctx *context.APIContext) {
49 49
 		}
50 50
 		return
51 51
 	}
52
-
53 52
 	ctx.JSON(200, issue.APIFormat())
54 53
 }
55 54
 
@@ -133,7 +132,7 @@ func EditIssue(ctx *context.APIContext, form api.EditIssueOption) {
133 132
 			assignee, err := models.GetUserByName(*form.Assignee)
134 133
 			if err != nil {
135 134
 				if models.IsErrUserNotExist(err) {
136
-					ctx.Error(422, "", fmt.Sprintf("Assignee does not exist: [name: %s]", *form.Assignee))
135
+					ctx.Error(422, "", fmt.Sprintf("assignee does not exist: [name: %s]", *form.Assignee))
137 136
 				} else {
138 137
 					ctx.Error(500, "GetUserByName", err)
139 138
 				}

+ 0 - 76
routers/api/v1/repo/issue_milestone.go

@@ -1,76 +0,0 @@
1
-// Copyright 2016 The Gogs Authors. All rights reserved.
2
-// Use of this source code is governed by a MIT-style
3
-// license that can be found in the LICENSE file.
4
-
5
-package repo
6
-
7
-import (
8
-	api "github.com/gogits/go-gogs-client"
9
-
10
-	"github.com/gogits/gogs/models"
11
-	"github.com/gogits/gogs/modules/context"
12
-	"github.com/gogits/gogs/routers/api/v1/convert"
13
-)
14
-
15
-func GetIssueMilestone(ctx *context.APIContext) {
16
-	issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
17
-	if err != nil {
18
-		if models.IsErrIssueNotExist(err) {
19
-			ctx.Status(404)
20
-		} else {
21
-			ctx.Error(500, "GetIssueByIndex", err)
22
-		}
23
-		return
24
-	}
25
-
26
-	apiMilestone := convert.ToMilestone(issue.Milestone)
27
-	ctx.JSON(200, &apiMilestone)
28
-}
29
-
30
-func SetIssueMilestone(ctx *context.APIContext, form api.SetIssueMilestoneOption) {
31
-	if !ctx.Repo.IsWriter() {
32
-		ctx.Status(403)
33
-		return
34
-	}
35
-
36
-	issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
37
-	if err != nil {
38
-		if models.IsErrIssueNotExist(err) {
39
-			ctx.Status(404)
40
-		} else {
41
-			ctx.Error(500, "GetIssueByIndex", err)
42
-		}
43
-		return
44
-	}
45
-
46
-	oldMid := issue.MilestoneID
47
-	if oldMid != form.ID {
48
-		issue.MilestoneID = form.ID
49
-		if err = models.ChangeMilestoneAssign(oldMid, issue); err != nil {
50
-			ctx.Error(500, "ChangeMilestoneAssign", err)
51
-			return
52
-		}
53
-	}
54
-
55
-	// Refresh issue to return updated milestone
56
-	issue, err = models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
57
-	if err != nil {
58
-		if models.IsErrIssueNotExist(err) {
59
-			ctx.Status(404)
60
-		} else {
61
-			ctx.Error(500, "GetIssueByIndex", err)
62
-		}
63
-		return
64
-	}
65
-
66
-	apiMilestone := convert.ToMilestone(issue.Milestone)
67
-	ctx.JSON(200, &apiMilestone)
68
-}
69
-
70
-func DeleteIssueMilestone(ctx *context.APIContext) {
71
-	form := api.SetIssueMilestoneOption{
72
-		ID: 0,
73
-	}
74
-
75
-	SetIssueMilestone(ctx, form)
76
-}

+ 18 - 71
routers/api/v1/repo/milestone.go

@@ -5,47 +5,42 @@
5 5
 package repo
6 6
 
7 7
 import (
8
+	"time"
9
+
8 10
 	api "github.com/gogits/go-gogs-client"
9 11
 
10 12
 	"github.com/gogits/gogs/models"
11 13
 	"github.com/gogits/gogs/modules/context"
12
-	"github.com/gogits/gogs/routers/api/v1/convert"
13
-	"time"
14 14
 )
15 15
 
16 16
 func ListMilestones(ctx *context.APIContext) {
17
-	milestones, err := models.GetAllRepoMilestones(ctx.Repo.Repository.ID)
17
+	milestones, err := models.GetMilestonesByRepoID(ctx.Repo.Repository.ID)
18 18
 	if err != nil {
19
-		ctx.Error(500, "GetAllRepoMilestones", err)
19
+		ctx.Error(500, "GetMilestonesByRepoID", err)
20 20
 		return
21 21
 	}
22 22
 
23 23
 	apiMilestones := make([]*api.Milestone, len(milestones))
24 24
 	for i := range milestones {
25
-		apiMilestones[i] = convert.ToMilestone(milestones[i])
25
+		apiMilestones[i] = milestones[i].APIFormat()
26 26
 	}
27 27
 	ctx.JSON(200, &apiMilestones)
28 28
 }
29 29
 
30 30
 func GetMilestone(ctx *context.APIContext) {
31
-	milestone, err := models.GetRepoMilestoneByID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
31
+	milestone, err := models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
32 32
 	if err != nil {
33 33
 		if models.IsErrMilestoneNotExist(err) {
34 34
 			ctx.Status(404)
35 35
 		} else {
36
-			ctx.Error(500, "GetRepoMilestoneByID", err)
36
+			ctx.Error(500, "GetMilestoneByRepoID", err)
37 37
 		}
38 38
 		return
39 39
 	}
40
-	ctx.JSON(200, convert.ToMilestone(milestone))
40
+	ctx.JSON(200, milestone.APIFormat())
41 41
 }
42 42
 
43 43
 func CreateMilestone(ctx *context.APIContext, form api.CreateMilestoneOption) {
44
-	if !ctx.Repo.IsWriter() {
45
-		ctx.Status(403)
46
-		return
47
-	}
48
-
49 44
 	if form.Deadline == nil {
50 45
 		defaultDeadline, _ := time.ParseInLocation("2006-01-02", "9999-12-31", time.Local)
51 46
 		form.Deadline = &defaultDeadline
@@ -62,21 +57,16 @@ func CreateMilestone(ctx *context.APIContext, form api.CreateMilestoneOption) {
62 57
 		ctx.Error(500, "NewMilestone", err)
63 58
 		return
64 59
 	}
65
-	ctx.JSON(201, convert.ToMilestone(milestone))
60
+	ctx.JSON(201, milestone.APIFormat())
66 61
 }
67 62
 
68 63
 func EditMilestone(ctx *context.APIContext, form api.EditMilestoneOption) {
69
-	if !ctx.Repo.IsWriter() {
70
-		ctx.Status(403)
71
-		return
72
-	}
73
-
74
-	milestone, err := models.GetRepoMilestoneByID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
64
+	milestone, err := models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
75 65
 	if err != nil {
76 66
 		if models.IsErrMilestoneNotExist(err) {
77 67
 			ctx.Status(404)
78 68
 		} else {
79
-			ctx.Error(500, "GetRepoMilestoneByID", err)
69
+			ctx.Error(500, "GetMilestoneByRepoID", err)
80 70
 		}
81 71
 		return
82 72
 	}
@@ -84,67 +74,24 @@ func EditMilestone(ctx *context.APIContext, form api.EditMilestoneOption) {
84 74
 	if len(form.Title) > 0 {
85 75
 		milestone.Name = form.Title
86 76
 	}
87
-	if len(form.Description) > 0 {
88
-		milestone.Content = form.Description
77
+	if form.Description != nil {
78
+		milestone.Content = *form.Description
89 79
 	}
90
-	if !form.Deadline.IsZero() {
80
+	if form.Deadline != nil && !form.Deadline.IsZero() {
91 81
 		milestone.Deadline = *form.Deadline
92 82
 	}
83
+
93 84
 	if err := models.UpdateMilestone(milestone); err != nil {
94 85
 		ctx.Handle(500, "UpdateMilestone", err)
95 86
 		return
96 87
 	}
97
-	ctx.JSON(200, convert.ToMilestone(milestone))
88
+	ctx.JSON(200, milestone.APIFormat())
98 89
 }
99 90
 
100 91
 func DeleteMilestone(ctx *context.APIContext) {
101
-	if !ctx.Repo.IsWriter() {
102
-		ctx.Status(403)
103
-		return
104
-	}
105
-
106
-	if err := models.DeleteMilestoneByID(ctx.ParamsInt64(":id")); err != nil {
107
-		ctx.Error(500, "DeleteMilestoneByID", err)
92
+	if err := models.DeleteMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id")); err != nil {
93
+		ctx.Error(500, "DeleteMilestoneByRepoID", err)
108 94
 		return
109 95
 	}
110 96
 	ctx.Status(204)
111 97
 }
112
-
113
-func ChangeMilestoneStatus(ctx *context.APIContext) {
114
-	if !ctx.Repo.IsWriter() {
115
-		ctx.Status(403)
116
-		return
117
-	}
118
-
119
-	m, err := models.GetMilestoneByID(ctx.ParamsInt64(":id"))
120
-	if err != nil {
121
-		if models.IsErrMilestoneNotExist(err) {
122
-			ctx.Handle(404, "GetMilestoneByID", err)
123
-		} else {
124
-			ctx.Handle(500, "GetMilestoneByID", err)
125
-		}
126
-		return
127
-	}
128
-
129
-	switch ctx.Params(":action") {
130
-	case "open":
131
-		if m.IsClosed {
132
-			if err = models.ChangeMilestoneStatus(m, false); err != nil {
133
-				ctx.Handle(500, "ChangeMilestoneStatus", err)
134
-				return
135
-			}
136
-		}
137
-		ctx.JSON(200, convert.ToMilestone(m))
138
-	case "close":
139
-		if !m.IsClosed {
140
-			m.ClosedDate = time.Now()
141
-			if err = models.ChangeMilestoneStatus(m, true); err != nil {
142
-				ctx.Handle(500, "ChangeMilestoneStatus", err)
143
-				return
144
-			}
145
-		}
146
-		ctx.JSON(200, convert.ToMilestone(m))
147
-	default:
148
-		ctx.Status(400)
149
-	}
150
-}

+ 12 - 12
routers/repo/issue.go

@@ -210,7 +210,7 @@ func Issues(ctx *context.Context) {
210 210
 	ctx.Data["Issues"] = issues
211 211
 
212 212
 	// Get milestones.
213
-	ctx.Data["Milestones"], err = models.GetAllRepoMilestones(repo.ID)
213
+	ctx.Data["Milestones"], err = models.GetMilestonesByRepoID(repo.ID)
214 214
 	if err != nil {
215 215
 		ctx.Handle(500, "GetAllRepoMilestones", err)
216 216
 		return
@@ -1099,12 +1099,12 @@ func EditMilestone(ctx *context.Context) {
1099 1099
 	ctx.Data["RequireDatetimepicker"] = true
1100 1100
 	ctx.Data["DateLang"] = setting.DateLang(ctx.Locale.Language())
1101 1101
 
1102
-	m, err := models.GetMilestoneByID(ctx.ParamsInt64(":id"))
1102
+	m, err := models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
1103 1103
 	if err != nil {
1104 1104
 		if models.IsErrMilestoneNotExist(err) {
1105
-			ctx.Handle(404, "GetMilestoneByID", nil)
1105
+			ctx.Handle(404, "", nil)
1106 1106
 		} else {
1107
-			ctx.Handle(500, "GetMilestoneByID", err)
1107
+			ctx.Handle(500, "GetMilestoneByRepoID", err)
1108 1108
 		}
1109 1109
 		return
1110 1110
 	}
@@ -1138,12 +1138,12 @@ func EditMilestonePost(ctx *context.Context, form auth.CreateMilestoneForm) {
1138 1138
 		return
1139 1139
 	}
1140 1140
 
1141
-	m, err := models.GetMilestoneByID(ctx.ParamsInt64(":id"))
1141
+	m, err := models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
1142 1142
 	if err != nil {
1143 1143
 		if models.IsErrMilestoneNotExist(err) {
1144
-			ctx.Handle(404, "GetMilestoneByID", nil)
1144
+			ctx.Handle(404, "", nil)
1145 1145
 		} else {
1146
-			ctx.Handle(500, "GetMilestoneByID", err)
1146
+			ctx.Handle(500, "GetMilestoneByRepoID", err)
1147 1147
 		}
1148 1148
 		return
1149 1149
 	}
@@ -1160,12 +1160,12 @@ func EditMilestonePost(ctx *context.Context, form auth.CreateMilestoneForm) {
1160 1160
 }
1161 1161
 
1162 1162
 func ChangeMilestonStatus(ctx *context.Context) {
1163
-	m, err := models.GetMilestoneByID(ctx.ParamsInt64(":id"))
1163
+	m, err := models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
1164 1164
 	if err != nil {
1165 1165
 		if models.IsErrMilestoneNotExist(err) {
1166
-			ctx.Handle(404, "GetMilestoneByID", err)
1166
+			ctx.Handle(404, "", err)
1167 1167
 		} else {
1168
-			ctx.Handle(500, "GetMilestoneByID", err)
1168
+			ctx.Handle(500, "GetMilestoneByRepoID", err)
1169 1169
 		}
1170 1170
 		return
1171 1171
 	}
@@ -1194,8 +1194,8 @@ func ChangeMilestonStatus(ctx *context.Context) {
1194 1194
 }
1195 1195
 
1196 1196
 func DeleteMilestone(ctx *context.Context) {
1197
-	if err := models.DeleteMilestoneByID(ctx.QueryInt64("id")); err != nil {
1198
-		ctx.Flash.Error("DeleteMilestoneByID: " + err.Error())
1197
+	if err := models.DeleteMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.QueryInt64("id")); err != nil {
1198
+		ctx.Flash.Error("DeleteMilestoneByRepoID: " + err.Error())
1199 1199
 	} else {
1200 1200
 		ctx.Flash.Success(ctx.Tr("repo.milestones.deletion_success"))
1201 1201
 	}

+ 1 - 1
templates/.VERSION

@@ -1 +1 @@
1
-0.9.83.0816
1
+0.9.84.0824