Skip to content

Commit 291adce

Browse files
author
Gusted
committed
Fix errors
1 parent dbb22f8 commit 291adce

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

models/issues/issue_project.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,15 @@ func ChangeProjectAssign(issue *Issue, doer *user_model.User, newProjectID int64
124124
func addUpdateIssueProject(ctx context.Context, issue *Issue, doer *user_model.User, newProjectID int64) error {
125125
oldProjectID := issue.projectID(ctx)
126126

127-
newProject, err := project_model.GetProjectByID(ctx, newProjectID)
128-
if err != nil {
129-
return err
130-
}
131-
if newProject.RepoID != issue.RepoID {
132-
return fmt.Errorf("issue's repository is not the same as project's repository")
127+
// Only check if we add a new project and not remove it.
128+
if newProjectID > 0 {
129+
newProject, err := project_model.GetProjectByID(ctx, newProjectID)
130+
if err != nil {
131+
return err
132+
}
133+
if newProject.RepoID != issue.RepoID {
134+
return fmt.Errorf("issue's repository is not the same as project's repository")
135+
}
133136
}
134137

135138
if _, err := db.GetEngine(ctx).Where("project_issue.issue_id=?", issue.ID).Delete(&project_model.ProjectIssue{}); err != nil {

services/issue/milestone.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@ import (
1515
)
1616

1717
func changeMilestoneAssign(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldMilestoneID int64) error {
18-
has, err := issues_model.HasMilestoneByRepoID(ctx, issue.RepoID, issue.MilestoneID)
19-
if err != nil {
20-
return fmt.Errorf("GetMilestoneByRepoID: %v", err)
21-
}
22-
if !has {
23-
return fmt.Errorf("GetMilestoneByRepoID: issue doesn't exist")
18+
// Only check if milestone exists if we don't remove it.
19+
if issue.MilestoneID > 0 {
20+
has, err := issues_model.HasMilestoneByRepoID(ctx, issue.RepoID, issue.MilestoneID)
21+
if err != nil {
22+
return fmt.Errorf("GetMilestoneByRepoID: %v", err)
23+
}
24+
if !has {
25+
return fmt.Errorf("GetMilestoneByRepoID: issue doesn't exist")
26+
}
2427
}
2528

2629
if err := issues_model.UpdateIssueCols(ctx, issue, "milestone_id"); err != nil {

0 commit comments

Comments
 (0)