@@ -87,8 +87,8 @@ func LoadIssuesFromBoardList(ctx context.Context, bs project_model.BoardList) (m
8787// If newProjectID is 0, the issue is removed from the project
8888func IssueAssignOrRemoveProject (ctx context.Context , issue * Issue , doer * user_model.User , newProjectID , newColumnID int64 , action string ) error {
8989 return db .WithTx (ctx , func (ctx context.Context ) error {
90- oldProjectID := issue .projectID (ctx )
91-
90+ oldProjectIDs := issue .projectIDs (ctx )
91+ var err error
9292 if err := issue .LoadRepo (ctx ); err != nil {
9393 return err
9494 }
@@ -111,50 +111,51 @@ func IssueAssignOrRemoveProject(ctx context.Context, issue *Issue, doer *user_mo
111111 }
112112 }
113113
114- if action == "null" {
115- if newProjectID == 0 {
116- action = "clear"
117- } else {
118- action = "attach"
119- count , err := db .GetEngine (ctx ).Table ("project_issue" ).Where ("issue_id=? AND project_id=?" , issue .ID , newProjectID ).Count ()
120- if err != nil {
121- return err
122- }
123- if count > 0 {
124- action = "detach"
114+ if action == "null" {
115+ if newProjectID == 0 {
116+ action = "clear"
117+ } else {
118+ action = "attach"
119+ count , err := db .GetEngine (ctx ).Table ("project_issue" ).Where ("issue_id=? AND project_id=?" , issue .ID , newProjectID ).Count ()
120+ if err != nil {
121+ return err
122+ }
123+ if count > 0 {
124+ action = "detach"
125+ }
125126 }
126127 }
127- }
128128
129- if action == "attach" {
130- err = db .Insert (ctx , & project_model.ProjectIssue {
131- IssueID : issue .ID ,
132- ProjectID : newProjectID ,
133- })
134- oldProjectIDs = append (oldProjectIDs , 0 )
135- } else if action == "detach" {
136- _ , err = db .GetEngine (ctx ).Where ("issue_id=? AND project_id=?" , issue .ID , newProjectID ).Delete (& project_model.ProjectIssue {})
137- oldProjectIDs = append (oldProjectIDs , newProjectID )
138- newProjectID = 0
139- } else if action == "clear" {
140- if err = db .GetEngine (ctx ).Table ("project_issue" ).Select ("project_id" ).Where ("issue_id=?" , issue .ID ).Find (& oldProjectIDs ); err != nil {
141- return err
129+ if action == "attach" {
130+ err = db .Insert (ctx , & project_model.ProjectIssue {
131+ IssueID : issue .ID ,
132+ ProjectID : newProjectID ,
133+ })
134+ oldProjectIDs = append (oldProjectIDs , 0 )
135+ } else if action == "detach" {
136+ _ , err = db .GetEngine (ctx ).Where ("issue_id=? AND project_id=?" , issue .ID , newProjectID ).Delete (& project_model.ProjectIssue {})
137+ oldProjectIDs = append (oldProjectIDs , newProjectID )
138+ newProjectID = 0
139+ } else if action == "clear" {
140+ if err = db .GetEngine (ctx ).Table ("project_issue" ).Select ("project_id" ).Where ("issue_id=?" , issue .ID ).Find (& oldProjectIDs ); err != nil {
141+ return err
142+ }
143+ _ , err = db .GetEngine (ctx ).Where ("issue_id=?" , issue .ID ).Delete (& project_model.ProjectIssue {})
144+ newProjectID = 0
142145 }
143- _ , err = db .GetEngine (ctx ).Where ("issue_id=?" , issue .ID ).Delete (& project_model.ProjectIssue {})
144- newProjectID = 0
145- }
146146
147- for i := range oldProjectIDs {
148- if _ , err := CreateComment (ctx , & CreateCommentOptions {
149- Type : CommentTypeProject ,
150- Doer : doer ,
151- Repo : issue .Repo ,
152- Issue : issue ,
153- OldProjectID : oldProjectIDs [i ],
154- ProjectID : newProjectID ,
155- }); err != nil {
156- return err
147+ for i := range oldProjectIDs {
148+ if _ , err := CreateComment (ctx , & CreateCommentOptions {
149+ Type : CommentTypeProject ,
150+ Doer : doer ,
151+ Repo : issue .Repo ,
152+ Issue : issue ,
153+ OldProjectID : oldProjectIDs [i ],
154+ ProjectID : newProjectID ,
155+ }); err != nil {
156+ return err
157+ }
157158 }
158-
159- return err
159+ return err
160+ })
160161}
0 commit comments