@@ -33,7 +33,7 @@ func UpdateIssueCols(ctx context.Context, issue *Issue, cols ...string) error {
3333 return nil
3434}
3535
36- func changeIssueStatus (ctx context.Context , issue * Issue , doer * user_model.User , isClosed , isMergePull bool ) (* Comment , error ) {
36+ func ChangeIssuePullStatus (ctx context.Context , issue * Issue , doer * user_model.User , isClosed , isMergePull bool ) (* Comment , error ) {
3737 // Reload the issue
3838 currentIssue , err := GetIssueByID (ctx , issue .ID )
3939 if err != nil {
@@ -127,41 +127,7 @@ func ChangeIssueStatus(ctx context.Context, issue *Issue, doer *user_model.User,
127127 return nil , err
128128 }
129129
130- return changeIssueStatus (ctx , issue , doer , isClosed , false )
131- }
132-
133- // ChangeIssueTitle changes the title of this issue, as the given user.
134- func ChangeIssueTitle (ctx context.Context , issue * Issue , doer * user_model.User , oldTitle string ) (err error ) {
135- ctx , committer , err := db .TxContext (ctx )
136- if err != nil {
137- return err
138- }
139- defer committer .Close ()
140-
141- if err = UpdateIssueCols (ctx , issue , "name" ); err != nil {
142- return fmt .Errorf ("updateIssueCols: %w" , err )
143- }
144-
145- if err = issue .LoadRepo (ctx ); err != nil {
146- return fmt .Errorf ("loadRepo: %w" , err )
147- }
148-
149- opts := & CreateCommentOptions {
150- Type : CommentTypeChangeTitle ,
151- Doer : doer ,
152- Repo : issue .Repo ,
153- Issue : issue ,
154- OldTitle : oldTitle ,
155- NewTitle : issue .Title ,
156- }
157- if _ , err = CreateComment (ctx , opts ); err != nil {
158- return fmt .Errorf ("createComment: %w" , err )
159- }
160- if err = issue .AddCrossReferences (ctx , doer , true ); err != nil {
161- return err
162- }
163-
164- return committer .Commit ()
130+ return ChangeIssuePullStatus (ctx , issue , doer , isClosed , false )
165131}
166132
167133// ChangeIssueRef changes the branch of this issue, as the given user.
@@ -234,48 +200,6 @@ func UpdateIssueAttachments(ctx context.Context, issueID int64, uuids []string)
234200 return committer .Commit ()
235201}
236202
237- // ChangeIssueContent changes issue content, as the given user.
238- func ChangeIssueContent (ctx context.Context , issue * Issue , doer * user_model.User , content string , contentVersion int ) (err error ) {
239- ctx , committer , err := db .TxContext (ctx )
240- if err != nil {
241- return err
242- }
243- defer committer .Close ()
244-
245- hasContentHistory , err := HasIssueContentHistory (ctx , issue .ID , 0 )
246- if err != nil {
247- return fmt .Errorf ("HasIssueContentHistory: %w" , err )
248- }
249- if ! hasContentHistory {
250- if err = SaveIssueContentHistory (ctx , issue .PosterID , issue .ID , 0 ,
251- issue .CreatedUnix , issue .Content , true ); err != nil {
252- return fmt .Errorf ("SaveIssueContentHistory: %w" , err )
253- }
254- }
255-
256- issue .Content = content
257- issue .ContentVersion = contentVersion + 1
258-
259- affected , err := db .GetEngine (ctx ).ID (issue .ID ).Cols ("content" , "content_version" ).Where ("content_version = ?" , contentVersion ).Update (issue )
260- if err != nil {
261- return err
262- }
263- if affected == 0 {
264- return ErrIssueAlreadyChanged
265- }
266-
267- if err = SaveIssueContentHistory (ctx , doer .ID , issue .ID , 0 ,
268- timeutil .TimeStampNow (), issue .Content , false ); err != nil {
269- return fmt .Errorf ("SaveIssueContentHistory: %w" , err )
270- }
271-
272- if err = issue .AddCrossReferences (ctx , doer , true ); err != nil {
273- return fmt .Errorf ("addCrossReferences: %w" , err )
274- }
275-
276- return committer .Commit ()
277- }
278-
279203// NewIssueOptions represents the options of a new issue.
280204type NewIssueOptions struct {
281205 Repo * repo_model.Repository
@@ -365,6 +289,10 @@ func NewIssueWithIndex(ctx context.Context, doer *user_model.User, opts NewIssue
365289 return err
366290 }
367291
292+ if err := UpdateIssueAttachments (ctx , opts .Issue .ID , opts .Attachments ); err != nil {
293+ return err
294+ }
295+
368296 if len (opts .Attachments ) > 0 {
369297 attachments , err := repo_model .GetAttachmentsByUUIDs (ctx , opts .Attachments )
370298 if err != nil {
@@ -385,40 +313,6 @@ func NewIssueWithIndex(ctx context.Context, doer *user_model.User, opts NewIssue
385313 return opts .Issue .AddCrossReferences (ctx , doer , false )
386314}
387315
388- // NewIssue creates new issue with labels for repository.
389- func NewIssue (ctx context.Context , repo * repo_model.Repository , issue * Issue , labelIDs []int64 , uuids []string ) (err error ) {
390- ctx , committer , err := db .TxContext (ctx )
391- if err != nil {
392- return err
393- }
394- defer committer .Close ()
395-
396- idx , err := db .GetNextResourceIndex (ctx , "issue_index" , repo .ID )
397- if err != nil {
398- return fmt .Errorf ("generate issue index failed: %w" , err )
399- }
400-
401- issue .Index = idx
402-
403- if err = NewIssueWithIndex (ctx , issue .Poster , NewIssueOptions {
404- Repo : repo ,
405- Issue : issue ,
406- LabelIDs : labelIDs ,
407- Attachments : uuids ,
408- }); err != nil {
409- if repo_model .IsErrUserDoesNotHaveAccessToRepo (err ) || IsErrNewIssueInsert (err ) {
410- return err
411- }
412- return fmt .Errorf ("newIssue: %w" , err )
413- }
414-
415- if err = committer .Commit (); err != nil {
416- return fmt .Errorf ("Commit: %w" , err )
417- }
418-
419- return nil
420- }
421-
422316// UpdateIssueMentions updates issue-user relations for mentioned users.
423317func UpdateIssueMentions (ctx context.Context , issueID int64 , mentions []* user_model.User ) error {
424318 if len (mentions ) == 0 {
0 commit comments