@@ -32,7 +32,50 @@ func UpdateIssueCols(ctx context.Context, issue *Issue, cols ...string) error {
3232 return err
3333}
3434
35+ // ErrIssueWasClosed is used when close a closed issue
36+ type ErrIssueWasClosed struct {
37+ ID int64
38+ Index int64
39+ }
40+
41+ // IsErrIssueWasClosed checks if an error is a ErrIssueWasClosed.
42+ func IsErrIssueWasClosed (err error ) bool {
43+ _ , ok := err .(ErrIssueWasClosed )
44+ return ok
45+ }
46+
47+ func (err ErrIssueWasClosed ) Error () string {
48+ return fmt .Sprintf ("Issue [%d] %d was already closed" , err .ID , err .Index )
49+ }
50+
51+ // ErrPullWasClosed is used close a closed pull request
52+ type ErrPullWasClosed struct {
53+ ID int64
54+ Index int64
55+ }
56+
57+ // IsErrPullWasClosed checks if an error is a ErrErrPullWasClosed.
58+ func IsErrPullWasClosed (err error ) bool {
59+ _ , ok := err .(ErrPullWasClosed )
60+ return ok
61+ }
62+
63+ func (err ErrPullWasClosed ) Error () string {
64+ return fmt .Sprintf ("Pull request [%d] %d was already closed" , err .ID , err .Index )
65+ }
66+
3567func closeIssue (ctx context.Context , issue * Issue , doer * user_model.User , isMergePull bool ) (* Comment , error ) {
68+ if issue .IsClosed {
69+ if ! issue .IsPull {
70+ return nil , ErrIssueWasClosed {
71+ ID : issue .ID ,
72+ }
73+ }
74+ return nil , ErrPullWasClosed {
75+ ID : issue .ID ,
76+ }
77+ }
78+
3679 // Check for open dependencies
3780 if issue .Repo .IsDependenciesEnabled (ctx ) {
3881 // only check if dependencies are enabled and we're about to close an issue, otherwise reopening an issue would fail when there are unsatisfied dependencies
@@ -60,7 +103,50 @@ func closeIssue(ctx context.Context, issue *Issue, doer *user_model.User, isMerg
60103 return updateIssueNumbers (ctx , issue , doer , util .Iif (isMergePull , CommentTypeMergePull , CommentTypeClose ))
61104}
62105
106+ // ErrIssueWasOpened is used when reopen an opened issue
107+ type ErrIssueWasOpened struct {
108+ ID int64
109+ Index int64
110+ }
111+
112+ // IsErrIssueWasOpened checks if an error is a ErrIssueWasOpened.
113+ func IsErrIssueWasOpened (err error ) bool {
114+ _ , ok := err .(ErrIssueWasOpened )
115+ return ok
116+ }
117+
118+ func (err ErrIssueWasOpened ) Error () string {
119+ return fmt .Sprintf ("Issue [%d] %d was already opened" , err .ID , err .Index )
120+ }
121+
122+ // ErrPullWasOpened is used reopen an opened pull request
123+ type ErrPullWasOpened struct {
124+ ID int64
125+ Index int64
126+ }
127+
128+ // ErrPullWasOpened checks if an error is a ErrPullWasOpened.
129+ func IsErrPullWasOpened (err error ) bool {
130+ _ , ok := err .(ErrPullWasOpened )
131+ return ok
132+ }
133+
134+ func (err ErrPullWasOpened ) Error () string {
135+ return fmt .Sprintf ("Pull request [%d] %d was already opened" , err .ID , err .Index )
136+ }
137+
63138func SetIssueAsReopen (ctx context.Context , issue * Issue , doer * user_model.User , isMergePull bool ) (* Comment , error ) {
139+ if ! issue .IsClosed {
140+ if ! issue .IsPull {
141+ return nil , ErrIssueWasOpened {
142+ ID : issue .ID ,
143+ }
144+ }
145+ return nil , ErrPullWasOpened {
146+ ID : issue .ID ,
147+ }
148+ }
149+
64150 issue .IsClosed = false
65151 issue .ClosedUnix = 0
66152
0 commit comments