@@ -18,8 +18,8 @@ github.com/go-xorm/core = commit:5bf745d | |||
github.com/go-xorm/xorm = commit:c6c7056 | |||
github.com/gogits/chardet = commit:2404f77 | |||
github.com/gogits/cron = commit:7f3990a | |||
github.com/gogits/git-module = commit:f78bf3b | |||
github.com/gogits/go-gogs-client = commit:5e50f02 | |||
github.com/gogits/git-module = commit:7b206b5 | |||
github.com/gogits/go-gogs-client = commit:2ffd470 | |||
github.com/issue9/identicon = commit:d36b545 | |||
github.com/jaytaylor/html2text = commit:52d9b78 | |||
github.com/kardianos/minwinsvc = commit:cad6b2b |
@@ -3,7 +3,7 @@ Gogs - Go Git Service [![Build Status](https://travis-ci.org/gogits/gogs.svg?bra | |||
![](https://github.com/gogits/gogs/blob/master/public/img/gogs-large-resize.png?raw=true) | |||
##### Current tip version: 0.9.83 (see [Releases](https://github.com/gogits/gogs/releases) for binary versions) | |||
##### Current tip version: 0.9.84 (see [Releases](https://github.com/gogits/gogs/releases) for binary versions) | |||
| Web | UI | Preview | | |||
|:-------------:|:-------:|:-------:| |
@@ -88,7 +88,7 @@ func checkVersion() { | |||
{"github.com/go-macaron/toolbox", toolbox.Version, "0.1.0"}, | |||
{"gopkg.in/ini.v1", ini.Version, "1.8.4"}, | |||
{"gopkg.in/macaron.v1", macaron.Version, "1.1.7"}, | |||
{"github.com/gogits/git-module", git.Version, "0.3.7"}, | |||
{"github.com/gogits/git-module", git.Version, "0.3.8"}, | |||
{"github.com/gogits/go-gogs-client", gogs.Version, "0.12.1"}, | |||
} | |||
for _, c := range checkers { |
@@ -41,9 +41,9 @@ imports: | |||
- name: github.com/gogits/cron | |||
version: 7f3990acf1833faa5ebd0e86f0a4c72a4b5eba3c | |||
- name: github.com/gogits/git-module | |||
version: f78bf3bf703cb3eb0e85a9475d26826939feda4f | |||
version: 7b206b529a09ae8cfa1df52a6c0cdd2612cfc6fc | |||
- name: github.com/gogits/go-gogs-client | |||
version: 5e50f0292565471b41b3c73fcadcb886140f0082 | |||
version: 2ffd4704c6f37d7fb10110450fe035fa6df08db8 | |||
- name: github.com/issue9/identicon | |||
version: d36b54562f4cf70c83653e13dc95c220c79ef521 | |||
- name: github.com/jaytaylor/html2text |
@@ -17,7 +17,7 @@ import ( | |||
"github.com/gogits/gogs/modules/setting" | |||
) | |||
const APP_VER = "0.9.83.0816" | |||
const APP_VER = "0.9.84.0824" | |||
func init() { | |||
runtime.GOMAXPROCS(runtime.NumCPU()) |
@@ -62,73 +62,73 @@ type Issue struct { | |||
Comments []*Comment `xorm:"-"` | |||
} | |||
func (i *Issue) BeforeInsert() { | |||
i.CreatedUnix = time.Now().Unix() | |||
i.UpdatedUnix = i.CreatedUnix | |||
func (issue *Issue) BeforeInsert() { | |||
issue.CreatedUnix = time.Now().Unix() | |||
issue.UpdatedUnix = issue.CreatedUnix | |||
} | |||
func (i *Issue) BeforeUpdate() { | |||
i.UpdatedUnix = time.Now().Unix() | |||
i.DeadlineUnix = i.Deadline.Unix() | |||
func (issue *Issue) BeforeUpdate() { | |||
issue.UpdatedUnix = time.Now().Unix() | |||
issue.DeadlineUnix = issue.Deadline.Unix() | |||
} | |||
func (i *Issue) AfterSet(colName string, _ xorm.Cell) { | |||
func (issue *Issue) AfterSet(colName string, _ xorm.Cell) { | |||
var err error | |||
switch colName { | |||
case "id": | |||
i.Attachments, err = GetAttachmentsByIssueID(i.ID) | |||
issue.Attachments, err = GetAttachmentsByIssueID(issue.ID) | |||
if err != nil { | |||
log.Error(3, "GetAttachmentsByIssueID[%d]: %v", i.ID, err) | |||
log.Error(3, "GetAttachmentsByIssueID[%d]: %v", issue.ID, err) | |||
} | |||
i.Comments, err = GetCommentsByIssueID(i.ID) | |||
issue.Comments, err = GetCommentsByIssueID(issue.ID) | |||
if err != nil { | |||
log.Error(3, "GetCommentsByIssueID[%d]: %v", i.ID, err) | |||
log.Error(3, "GetCommentsByIssueID[%d]: %v", issue.ID, err) | |||
} | |||
i.Labels, err = GetLabelsByIssueID(i.ID) | |||
issue.Labels, err = GetLabelsByIssueID(issue.ID) | |||
if err != nil { | |||
log.Error(3, "GetLabelsByIssueID[%d]: %v", i.ID, err) | |||
log.Error(3, "GetLabelsByIssueID[%d]: %v", issue.ID, err) | |||
} | |||
case "poster_id": | |||
i.Poster, err = GetUserByID(i.PosterID) | |||
issue.Poster, err = GetUserByID(issue.PosterID) | |||
if err != nil { | |||
if IsErrUserNotExist(err) { | |||
i.PosterID = -1 | |||
i.Poster = NewGhostUser() | |||
issue.PosterID = -1 | |||
issue.Poster = NewGhostUser() | |||
} else { | |||
log.Error(3, "GetUserByID[%d]: %v", i.ID, err) | |||
log.Error(3, "GetUserByID[%d]: %v", issue.ID, err) | |||
} | |||
return | |||
} | |||
case "milestone_id": | |||
if i.MilestoneID == 0 { | |||
if issue.MilestoneID == 0 { | |||
return | |||
} | |||
i.Milestone, err = GetMilestoneByID(i.MilestoneID) | |||
issue.Milestone, err = GetMilestoneByRepoID(issue.RepoID, issue.MilestoneID) | |||
if err != nil { | |||
log.Error(3, "GetMilestoneById[%d]: %v", i.ID, err) | |||
log.Error(3, "GetMilestoneById[%d]: %v", issue.ID, err) | |||
} | |||
case "assignee_id": | |||
if i.AssigneeID == 0 { | |||
if issue.AssigneeID == 0 { | |||
return | |||
} | |||
i.Assignee, err = GetUserByID(i.AssigneeID) | |||
issue.Assignee, err = GetUserByID(issue.AssigneeID) | |||
if err != nil { | |||
log.Error(3, "GetUserByID[%d]: %v", i.ID, err) | |||
log.Error(3, "GetUserByID[%d]: %v", issue.ID, err) | |||
} | |||
case "deadline_unix": | |||
i.Deadline = time.Unix(i.DeadlineUnix, 0).Local() | |||
issue.Deadline = time.Unix(issue.DeadlineUnix, 0).Local() | |||
case "created_unix": | |||
i.Created = time.Unix(i.CreatedUnix, 0).Local() | |||
issue.Created = time.Unix(issue.CreatedUnix, 0).Local() | |||
case "updated_unix": | |||
i.Updated = time.Unix(i.UpdatedUnix, 0).Local() | |||
issue.Updated = time.Unix(issue.UpdatedUnix, 0).Local() | |||
} | |||
} | |||
@@ -600,7 +600,7 @@ func newIssue(e *xorm.Session, opts NewIssueOptions) (err error) { | |||
opts.Issue.Index = opts.Repo.NextIssueIndex() | |||
if opts.Issue.MilestoneID > 0 { | |||
milestone, err := getMilestoneByID(e, opts.Issue.MilestoneID) | |||
milestone, err := getMilestoneByRepoID(e, opts.Issue.RepoID, opts.Issue.MilestoneID) | |||
if err != nil && !IsErrMilestoneNotExist(err) { | |||
return fmt.Errorf("getMilestoneByID: %v", err) | |||
} | |||
@@ -1392,50 +1392,41 @@ func NewMilestone(m *Milestone) (err error) { | |||
return err | |||
} | |||
if _, err = sess.Exec("UPDATE `repository` SET num_milestones=num_milestones+1 WHERE id=?", m.RepoID); err != nil { | |||
if _, err = sess.Exec("UPDATE `repository` SET num_milestones = num_milestones + 1 WHERE id = ?", m.RepoID); err != nil { | |||
return err | |||
} | |||
return sess.Commit() | |||
} | |||
func getMilestoneByID(e Engine, id int64) (*Milestone, error) { | |||
m := &Milestone{ID: id} | |||
func getMilestoneByRepoID(e Engine, repoID, id int64) (*Milestone, error) { | |||
m := &Milestone{ | |||
ID: id, | |||
RepoID: repoID, | |||
} | |||
has, err := e.Get(m) | |||
if err != nil { | |||
return nil, err | |||
} else if !has { | |||
return nil, ErrMilestoneNotExist{id, 0} | |||
return nil, ErrMilestoneNotExist{id, repoID} | |||
} | |||
return m, nil | |||
} | |||
// GetMilestoneByID returns the milestone of given ID. | |||
func GetMilestoneByID(id int64) (*Milestone, error) { | |||
return getMilestoneByID(x, id) | |||
} | |||
// GetRepoMilestoneByID returns the milestone of given ID and repository. | |||
func GetRepoMilestoneByID(repoID, milestoneID int64) (*Milestone, error) { | |||
m := &Milestone{ID: milestoneID, RepoID: repoID} | |||
has, err := x.Get(m) | |||
if err != nil { | |||
return nil, err | |||
} else if !has { | |||
return nil, ErrMilestoneNotExist{milestoneID, repoID} | |||
} | |||
return m, nil | |||
// GetWebhookByRepoID returns milestone of repository by given ID. | |||
func GetMilestoneByRepoID(repoID, id int64) (*Milestone, error) { | |||
return getMilestoneByRepoID(x, repoID, id) | |||
} | |||
// GetAllRepoMilestones returns all milestones of given repository. | |||
func GetAllRepoMilestones(repoID int64) ([]*Milestone, error) { | |||
// GetMilestonesByRepoID returns all milestones of a repository. | |||
func GetMilestonesByRepoID(repoID int64) ([]*Milestone, error) { | |||
miles := make([]*Milestone, 0, 10) | |||
return miles, x.Where("repo_id=?", repoID).Find(&miles) | |||
return miles, x.Where("repo_id = ?", repoID).Find(&miles) | |||
} | |||
// GetMilestones returns a list of milestones of given repository and status. | |||
func GetMilestones(repoID int64, page int, isClosed bool) ([]*Milestone, error) { | |||
miles := make([]*Milestone, 0, setting.UI.IssuePagingNum) | |||
sess := x.Where("repo_id=? AND is_closed=?", repoID, isClosed) | |||
sess := x.Where("repo_id = ? AND is_closed = ?", repoID, isClosed) | |||
if page > 0 { | |||
sess = sess.Limit(setting.UI.IssuePagingNum, (page-1)*setting.UI.IssuePagingNum) | |||
} | |||
@@ -1509,7 +1500,7 @@ func changeMilestoneIssueStats(e *xorm.Session, issue *Issue) error { | |||
return nil | |||
} | |||
m, err := getMilestoneByID(e, issue.MilestoneID) | |||
m, err := getMilestoneByRepoID(e, issue.RepoID, issue.MilestoneID) | |||
if err != nil { | |||
return err | |||
} | |||
@@ -1543,7 +1534,7 @@ func ChangeMilestoneIssueStats(issue *Issue) (err error) { | |||
func changeMilestoneAssign(e *xorm.Session, issue *Issue, oldMilestoneID int64) error { | |||
if oldMilestoneID > 0 { | |||
m, err := getMilestoneByID(e, oldMilestoneID) | |||
m, err := getMilestoneByRepoID(e, issue.RepoID, oldMilestoneID) | |||
if err != nil { | |||
return err | |||
} | |||
@@ -1561,7 +1552,7 @@ func changeMilestoneAssign(e *xorm.Session, issue *Issue, oldMilestoneID int64) | |||
} | |||
if issue.MilestoneID > 0 { | |||
m, err := getMilestoneByID(e, issue.MilestoneID) | |||
m, err := getMilestoneByRepoID(e, issue.RepoID, issue.MilestoneID) | |||
if err != nil { | |||
return err | |||
} | |||
@@ -1595,9 +1586,9 @@ func ChangeMilestoneAssign(issue *Issue, oldMilestoneID int64) (err error) { | |||
return sess.Commit() | |||
} | |||
// DeleteMilestoneByID deletes a milestone by given ID. | |||
func DeleteMilestoneByID(id int64) error { | |||
m, err := GetMilestoneByID(id) | |||
// DeleteMilestoneByRepoID deletes a milestone from a repository. | |||
func DeleteMilestoneByRepoID(repoID, id int64) error { | |||
m, err := GetMilestoneByRepoID(repoID, id) | |||
if err != nil { | |||
if IsErrMilestoneNotExist(err) { | |||
return nil | |||
@@ -1626,9 +1617,9 @@ func DeleteMilestoneByID(id int64) error { | |||
return err | |||
} | |||
if _, err = sess.Exec("UPDATE `issue` SET milestone_id=0 WHERE milestone_id=?", m.ID); err != nil { | |||
if _, err = sess.Exec("UPDATE `issue` SET milestone_id = 0 WHERE milestone_id = ?", m.ID); err != nil { | |||
return err | |||
} else if _, err = sess.Exec("UPDATE `issue_user` SET milestone_id=0 WHERE milestone_id=?", m.ID); err != nil { | |||
} else if _, err = sess.Exec("UPDATE `issue_user` SET milestone_id = 0 WHERE milestone_id = ?", m.ID); err != nil { | |||
return err | |||
} | |||
return sess.Commit() |
@@ -359,7 +359,7 @@ func (repo *Repository) GetAssigneeByID(userID int64) (*User, error) { | |||
// GetMilestoneByID returns the milestone belongs to repository by given ID. | |||
func (repo *Repository) GetMilestoneByID(milestoneID int64) (*Milestone, error) { | |||
return GetRepoMilestoneByID(repo.ID, milestoneID) | |||
return GetMilestoneByRepoID(repo.ID, milestoneID) | |||
} | |||
// IssueStats returns number of open and closed repository issues by given filter mode. |
@@ -210,15 +210,18 @@ func GetWebhookByOrgID(orgID, id int64) (*Webhook, error) { | |||
} | |||
// GetActiveWebhooksByRepoID returns all active webhooks of repository. | |||
func GetActiveWebhooksByRepoID(repoID int64) (ws []*Webhook, err error) { | |||
err = x.Where("repo_id=?", repoID).And("is_active=?", true).Find(&ws) | |||
return ws, err | |||
func GetActiveWebhooksByRepoID(repoID int64) ([]*Webhook, error) { | |||
webhooks := make([]*Webhook, 0, 5) | |||
return webhooks, x.Find(&webhooks, &Webhook{ | |||
RepoID: repoID, | |||
IsActive: true, | |||
}) | |||
} | |||
// GetWebhooksByRepoID returns all webhooks of repository. | |||
func GetWebhooksByRepoID(repoID int64) (ws []*Webhook, err error) { | |||
err = x.Find(&ws, &Webhook{RepoID: repoID}) | |||
return ws, err | |||
// GetWebhooksByRepoID returns all webhooks of a repository. | |||
func GetWebhooksByRepoID(repoID int64) ([]*Webhook, error) { | |||
webhooks := make([]*Webhook, 0, 5) | |||
return webhooks, x.Find(&webhooks, &Webhook{RepoID: repoID}) | |||
} | |||
// UpdateWebhook updates information of webhook. |
@@ -110,6 +110,15 @@ func reqAdmin() macaron.Handler { | |||
} | |||
} | |||
func reqRepoWriter() macaron.Handler { | |||
return func(ctx *context.Context) { | |||
if !ctx.Repo.IsWriter() { | |||
ctx.Error(403) | |||
return | |||
} | |||
} | |||
} | |||
func orgAssignment(args ...bool) macaron.Handler { | |||
var ( | |||
assignOrg bool | |||
@@ -259,11 +268,6 @@ func RegisterRoutes(m *macaron.Macaron) { | |||
Delete(repo.ClearIssueLabels) | |||
m.Delete("/:id", repo.DeleteIssueLabel) | |||
}) | |||
m.Group("/milestone", func() { | |||
m.Combo("").Get(repo.GetIssueMilestone). | |||
Post(bind(api.SetIssueMilestoneOption{}), repo.SetIssueMilestone). | |||
Delete(repo.DeleteIssueMilestone) | |||
}) | |||
}) | |||
}, mustEnableIssues) | |||
@@ -275,10 +279,10 @@ func RegisterRoutes(m *macaron.Macaron) { | |||
}) | |||
m.Group("/milestones", func() { | |||
m.Combo("").Get(repo.ListMilestones). | |||
Post(bind(api.CreateMilestoneOption{}), repo.CreateMilestone) | |||
m.Combo("/:id").Get(repo.GetMilestone).Patch(bind(api.EditMilestoneOption{}), repo.EditMilestone). | |||
Delete(repo.DeleteMilestone) | |||
m.Post("/:id/:action", repo.ChangeMilestoneStatus) | |||
Post(reqRepoWriter(), bind(api.CreateMilestoneOption{}), repo.CreateMilestone) | |||
m.Combo("/:id").Get(repo.GetMilestone). | |||
Patch(reqRepoWriter(), bind(api.EditMilestoneOption{}), repo.EditMilestone). | |||
Delete(reqRepoWriter(), repo.DeleteMilestone) | |||
}) | |||
}, repoAssignment()) | |||
}, reqToken()) |
@@ -49,7 +49,6 @@ func GetIssue(ctx *context.APIContext) { | |||
} | |||
return | |||
} | |||
ctx.JSON(200, issue.APIFormat()) | |||
} | |||
@@ -133,7 +132,7 @@ func EditIssue(ctx *context.APIContext, form api.EditIssueOption) { | |||
assignee, err := models.GetUserByName(*form.Assignee) | |||
if err != nil { | |||
if models.IsErrUserNotExist(err) { | |||
ctx.Error(422, "", fmt.Sprintf("Assignee does not exist: [name: %s]", *form.Assignee)) | |||
ctx.Error(422, "", fmt.Sprintf("assignee does not exist: [name: %s]", *form.Assignee)) | |||
} else { | |||
ctx.Error(500, "GetUserByName", err) | |||
} |
@@ -1,76 +0,0 @@ | |||
// Copyright 2016 The Gogs Authors. All rights reserved. | |||
// Use of this source code is governed by a MIT-style | |||
// license that can be found in the LICENSE file. | |||
package repo | |||
import ( | |||
api "github.com/gogits/go-gogs-client" | |||
"github.com/gogits/gogs/models" | |||
"github.com/gogits/gogs/modules/context" | |||
"github.com/gogits/gogs/routers/api/v1/convert" | |||
) | |||
func GetIssueMilestone(ctx *context.APIContext) { | |||
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) | |||
if err != nil { | |||
if models.IsErrIssueNotExist(err) { | |||
ctx.Status(404) | |||
} else { | |||
ctx.Error(500, "GetIssueByIndex", err) | |||
} | |||
return | |||
} | |||
apiMilestone := convert.ToMilestone(issue.Milestone) | |||
ctx.JSON(200, &apiMilestone) | |||
} | |||
func SetIssueMilestone(ctx *context.APIContext, form api.SetIssueMilestoneOption) { | |||
if !ctx.Repo.IsWriter() { | |||
ctx.Status(403) | |||
return | |||
} | |||
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) | |||
if err != nil { | |||
if models.IsErrIssueNotExist(err) { | |||
ctx.Status(404) | |||
} else { | |||
ctx.Error(500, "GetIssueByIndex", err) | |||
} | |||
return | |||
} | |||
oldMid := issue.MilestoneID | |||
if oldMid != form.ID { | |||
issue.MilestoneID = form.ID | |||
if err = models.ChangeMilestoneAssign(oldMid, issue); err != nil { | |||
ctx.Error(500, "ChangeMilestoneAssign", err) | |||
return | |||
} | |||
} | |||
// Refresh issue to return updated milestone | |||
issue, err = models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) | |||
if err != nil { | |||
if models.IsErrIssueNotExist(err) { | |||
ctx.Status(404) | |||
} else { | |||
ctx.Error(500, "GetIssueByIndex", err) | |||
} | |||
return | |||
} | |||
apiMilestone := convert.ToMilestone(issue.Milestone) | |||
ctx.JSON(200, &apiMilestone) | |||
} | |||
func DeleteIssueMilestone(ctx *context.APIContext) { | |||
form := api.SetIssueMilestoneOption{ | |||
ID: 0, | |||
} | |||
SetIssueMilestone(ctx, form) | |||
} |
@@ -5,47 +5,42 @@ | |||
package repo | |||
import ( | |||
"time" | |||
api "github.com/gogits/go-gogs-client" | |||
"github.com/gogits/gogs/models" | |||
"github.com/gogits/gogs/modules/context" | |||
"github.com/gogits/gogs/routers/api/v1/convert" | |||
"time" | |||
) | |||
func ListMilestones(ctx *context.APIContext) { | |||
milestones, err := models.GetAllRepoMilestones(ctx.Repo.Repository.ID) | |||
milestones, err := models.GetMilestonesByRepoID(ctx.Repo.Repository.ID) | |||
if err != nil { | |||
ctx.Error(500, "GetAllRepoMilestones", err) | |||
ctx.Error(500, "GetMilestonesByRepoID", err) | |||
return | |||
} | |||
apiMilestones := make([]*api.Milestone, len(milestones)) | |||
for i := range milestones { | |||
apiMilestones[i] = convert.ToMilestone(milestones[i]) | |||
apiMilestones[i] = milestones[i].APIFormat() | |||
} | |||
ctx.JSON(200, &apiMilestones) | |||
} | |||
func GetMilestone(ctx *context.APIContext) { | |||
milestone, err := models.GetRepoMilestoneByID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id")) | |||
milestone, err := models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id")) | |||
if err != nil { | |||
if models.IsErrMilestoneNotExist(err) { | |||
ctx.Status(404) | |||
} else { | |||
ctx.Error(500, "GetRepoMilestoneByID", err) | |||
ctx.Error(500, "GetMilestoneByRepoID", err) | |||
} | |||
return | |||
} | |||
ctx.JSON(200, convert.ToMilestone(milestone)) | |||
ctx.JSON(200, milestone.APIFormat()) | |||
} | |||
func CreateMilestone(ctx *context.APIContext, form api.CreateMilestoneOption) { | |||
if !ctx.Repo.IsWriter() { | |||
ctx.Status(403) | |||
return | |||
} | |||
if form.Deadline == nil { | |||
defaultDeadline, _ := time.ParseInLocation("2006-01-02", "9999-12-31", time.Local) | |||
form.Deadline = &defaultDeadline | |||
@@ -62,21 +57,16 @@ func CreateMilestone(ctx *context.APIContext, form api.CreateMilestoneOption) { | |||
ctx.Error(500, "NewMilestone", err) | |||
return | |||
} | |||
ctx.JSON(201, convert.ToMilestone(milestone)) | |||
ctx.JSON(201, milestone.APIFormat()) | |||
} | |||
func EditMilestone(ctx *context.APIContext, form api.EditMilestoneOption) { | |||
if !ctx.Repo.IsWriter() { | |||
ctx.Status(403) | |||
return | |||
} | |||
milestone, err := models.GetRepoMilestoneByID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id")) | |||
milestone, err := models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id")) | |||
if err != nil { | |||
if models.IsErrMilestoneNotExist(err) { | |||
ctx.Status(404) | |||
} else { | |||
ctx.Error(500, "GetRepoMilestoneByID", err) | |||
ctx.Error(500, "GetMilestoneByRepoID", err) | |||
} | |||
return | |||
} | |||
@@ -84,67 +74,24 @@ func EditMilestone(ctx *context.APIContext, form api.EditMilestoneOption) { | |||
if len(form.Title) > 0 { | |||
milestone.Name = form.Title | |||
} | |||
if len(form.Description) > 0 { | |||
milestone.Content = form.Description | |||
if form.Description != nil { | |||
milestone.Content = *form.Description | |||
} | |||
if !form.Deadline.IsZero() { | |||
if form.Deadline != nil && !form.Deadline.IsZero() { | |||
milestone.Deadline = *form.Deadline | |||
} | |||
if err := models.UpdateMilestone(milestone); err != nil { | |||
ctx.Handle(500, "UpdateMilestone", err) | |||
return | |||
} | |||
ctx.JSON(200, convert.ToMilestone(milestone)) | |||
ctx.JSON(200, milestone.APIFormat()) | |||
} | |||
func DeleteMilestone(ctx *context.APIContext) { | |||
if !ctx.Repo.IsWriter() { | |||
ctx.Status(403) | |||
return | |||
} | |||
if err := models.DeleteMilestoneByID(ctx.ParamsInt64(":id")); err != nil { | |||
ctx.Error(500, "DeleteMilestoneByID", err) | |||
if err := models.DeleteMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id")); err != nil { | |||
ctx.Error(500, "DeleteMilestoneByRepoID", err) | |||
return | |||
} | |||
ctx.Status(204) | |||
} | |||
func ChangeMilestoneStatus(ctx *context.APIContext) { | |||
if !ctx.Repo.IsWriter() { | |||
ctx.Status(403) | |||
return | |||
} | |||
m, err := models.GetMilestoneByID(ctx.ParamsInt64(":id")) | |||
if err != nil { | |||
if models.IsErrMilestoneNotExist(err) { | |||
ctx.Handle(404, "GetMilestoneByID", err) | |||
} else { | |||
ctx.Handle(500, "GetMilestoneByID", err) | |||
} | |||
return | |||
} | |||
switch ctx.Params(":action") { | |||
case "open": | |||
if m.IsClosed { | |||
if err = models.ChangeMilestoneStatus(m, false); err != nil { | |||
ctx.Handle(500, "ChangeMilestoneStatus", err) | |||
return | |||
} | |||
} | |||
ctx.JSON(200, convert.ToMilestone(m)) | |||
case "close": | |||
if !m.IsClosed { | |||
m.ClosedDate = time.Now() | |||
if err = models.ChangeMilestoneStatus(m, true); err != nil { | |||
ctx.Handle(500, "ChangeMilestoneStatus", err) | |||
return | |||
} | |||
} | |||
ctx.JSON(200, convert.ToMilestone(m)) | |||
default: | |||
ctx.Status(400) | |||
} | |||
} |
@@ -210,7 +210,7 @@ func Issues(ctx *context.Context) { | |||
ctx.Data["Issues"] = issues | |||
// Get milestones. | |||
ctx.Data["Milestones"], err = models.GetAllRepoMilestones(repo.ID) | |||
ctx.Data["Milestones"], err = models.GetMilestonesByRepoID(repo.ID) | |||
if err != nil { | |||
ctx.Handle(500, "GetAllRepoMilestones", err) | |||
return | |||
@@ -1099,12 +1099,12 @@ func EditMilestone(ctx *context.Context) { | |||
ctx.Data["RequireDatetimepicker"] = true | |||
ctx.Data["DateLang"] = setting.DateLang(ctx.Locale.Language()) | |||
m, err := models.GetMilestoneByID(ctx.ParamsInt64(":id")) | |||
m, err := models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id")) | |||
if err != nil { | |||
if models.IsErrMilestoneNotExist(err) { | |||
ctx.Handle(404, "GetMilestoneByID", nil) | |||
ctx.Handle(404, "", nil) | |||
} else { | |||
ctx.Handle(500, "GetMilestoneByID", err) | |||
ctx.Handle(500, "GetMilestoneByRepoID", err) | |||
} | |||
return | |||
} | |||
@@ -1138,12 +1138,12 @@ func EditMilestonePost(ctx *context.Context, form auth.CreateMilestoneForm) { | |||
return | |||
} | |||
m, err := models.GetMilestoneByID(ctx.ParamsInt64(":id")) | |||
m, err := models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id")) | |||
if err != nil { | |||
if models.IsErrMilestoneNotExist(err) { | |||
ctx.Handle(404, "GetMilestoneByID", nil) | |||
ctx.Handle(404, "", nil) | |||
} else { | |||
ctx.Handle(500, "GetMilestoneByID", err) | |||
ctx.Handle(500, "GetMilestoneByRepoID", err) | |||
} | |||
return | |||
} | |||
@@ -1160,12 +1160,12 @@ func EditMilestonePost(ctx *context.Context, form auth.CreateMilestoneForm) { | |||
} | |||
func ChangeMilestonStatus(ctx *context.Context) { | |||
m, err := models.GetMilestoneByID(ctx.ParamsInt64(":id")) | |||
m, err := models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id")) | |||
if err != nil { | |||
if models.IsErrMilestoneNotExist(err) { | |||
ctx.Handle(404, "GetMilestoneByID", err) | |||
ctx.Handle(404, "", err) | |||
} else { | |||
ctx.Handle(500, "GetMilestoneByID", err) | |||
ctx.Handle(500, "GetMilestoneByRepoID", err) | |||
} | |||
return | |||
} | |||
@@ -1194,8 +1194,8 @@ func ChangeMilestonStatus(ctx *context.Context) { | |||
} | |||
func DeleteMilestone(ctx *context.Context) { | |||
if err := models.DeleteMilestoneByID(ctx.QueryInt64("id")); err != nil { | |||
ctx.Flash.Error("DeleteMilestoneByID: " + err.Error()) | |||
if err := models.DeleteMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.QueryInt64("id")); err != nil { | |||
ctx.Flash.Error("DeleteMilestoneByRepoID: " + err.Error()) | |||
} else { | |||
ctx.Flash.Success(ctx.Tr("repo.milestones.deletion_success")) | |||
} |
@@ -1 +1 @@ | |||
0.9.83.0816 | |||
0.9.84.0824 |