75
75
76
76
const issueTasksRegexpStr = `(^\s*[-*]\s\[[\sx]\]\s.)|(\n\s*[-*]\s\[[\sx]\]\s.)`
77
77
const issueTasksDoneRegexpStr = `(^\s*[-*]\s\[[x]\]\s.)|(\n\s*[-*]\s\[[x]\]\s.)`
78
- const issueMaxDupIndexAttempts = 3
79
78
80
79
func init () {
81
80
issueTasksPat = regexp .MustCompile (issueTasksRegexpStr )
@@ -447,7 +446,7 @@ func (issue *Issue) ReplyReference() string {
447
446
return fmt .Sprintf ("%s/%s/%d@%s" , issue .Repo .FullName (), path , issue .Index , setting .Domain )
448
447
}
449
448
450
- func (issue * Issue ) addLabel (e * xorm. Session , label * Label , doer * User ) error {
449
+ func (issue * Issue ) addLabel (e Engine , label * Label , doer * User ) error {
451
450
return newIssueLabel (e , issue , label , doer )
452
451
}
453
452
@@ -843,10 +842,9 @@ type NewIssueOptions struct {
843
842
Issue * Issue
844
843
LabelIDs []int64
845
844
Attachments []string // In UUID format.
846
- IsPull bool
847
845
}
848
846
849
- func newIssue (e * xorm. Session , doer * User , opts NewIssueOptions ) (err error ) {
847
+ func newIssue (e Engine , doer * User , opts NewIssueOptions ) (err error ) {
850
848
opts .Issue .Title = strings .TrimSpace (opts .Issue .Title )
851
849
852
850
if opts .Issue .MilestoneID > 0 {
@@ -864,8 +862,8 @@ func newIssue(e *xorm.Session, doer *User, opts NewIssueOptions) (err error) {
864
862
}
865
863
866
864
// Milestone validation should happen before insert actual object.
867
- if _ , err := e .SetExpr ( "`index` " , "coalesce(MAX(`index`),0)+1" ).
868
- Where ( "repo_id=? " , opts . Issue . RepoID ).
865
+ if _ , err := e .Where ( "repo_id=? " , opts . Issue . RepoID ).
866
+ SetExpr ( "`index` " , "coalesce(MAX(`index`),0)+1" ).
869
867
Insert (opts .Issue ); err != nil {
870
868
return ErrNewIssueInsert {err }
871
869
}
@@ -896,7 +894,7 @@ func newIssue(e *xorm.Session, doer *User, opts NewIssueOptions) (err error) {
896
894
}
897
895
}
898
896
899
- if opts .IsPull {
897
+ if opts .Issue . IsPull {
900
898
_ , err = e .Exec ("UPDATE `repository` SET num_pulls = num_pulls + 1 WHERE id = ?" , opts .Issue .RepoID )
901
899
} else {
902
900
_ , err = e .Exec ("UPDATE `repository` SET num_issues = num_issues + 1 WHERE id = ?" , opts .Issue .RepoID )
@@ -953,48 +951,13 @@ func newIssue(e *xorm.Session, doer *User, opts NewIssueOptions) (err error) {
953
951
}
954
952
955
953
// NewIssue creates new issue with labels for repository.
956
- func NewIssue (repo * Repository , issue * Issue , labelIDs []int64 , uuids []string ) (err error ) {
957
- // Retry several times in case INSERT fails due to duplicate key for (repo_id, index); see #7887
958
- i := 0
959
- for {
960
- if err = newIssueAttempt (repo , issue , labelIDs , uuids ); err == nil {
961
- return nil
962
- }
963
- if ! IsErrNewIssueInsert (err ) {
964
- return err
965
- }
966
- if i ++ ; i == issueMaxDupIndexAttempts {
967
- break
968
- }
969
- log .Error ("NewIssue: error attempting to insert the new issue; will retry. Original error: %v" , err )
970
- }
971
- return fmt .Errorf ("NewIssue: too many errors attempting to insert the new issue. Last error was: %v" , err )
972
- }
973
-
974
- func newIssueAttempt (repo * Repository , issue * Issue , labelIDs []int64 , uuids []string ) (err error ) {
975
- sess := x .NewSession ()
976
- defer sess .Close ()
977
- if err = sess .Begin (); err != nil {
978
- return err
979
- }
980
-
981
- if err = newIssue (sess , issue .Poster , NewIssueOptions {
954
+ func NewIssue (ctx DBContext , repo * Repository , issue * Issue , labelIDs []int64 , uuids []string ) (err error ) {
955
+ return newIssue (ctx .e , issue .Poster , NewIssueOptions {
982
956
Repo : repo ,
983
957
Issue : issue ,
984
958
LabelIDs : labelIDs ,
985
959
Attachments : uuids ,
986
- }); err != nil {
987
- if IsErrUserDoesNotHaveAccessToRepo (err ) || IsErrNewIssueInsert (err ) {
988
- return err
989
- }
990
- return fmt .Errorf ("newIssue: %v" , err )
991
- }
992
-
993
- if err = sess .Commit (); err != nil {
994
- return fmt .Errorf ("Commit: %v" , err )
995
- }
996
-
997
- return nil
960
+ })
998
961
}
999
962
1000
963
// GetIssueByIndex returns raw issue without loading attributes by index in a repository.
0 commit comments