code.gitea.io/gitea@v1.22.3/services/issue/status.go (about)

     1  // Copyright 2019 The Gitea Authors. All rights reserved.
     2  // SPDX-License-Identifier: MIT
     3  
     4  package issue
     5  
     6  import (
     7  	"context"
     8  
     9  	issues_model "code.gitea.io/gitea/models/issues"
    10  	user_model "code.gitea.io/gitea/models/user"
    11  	"code.gitea.io/gitea/modules/log"
    12  	notify_service "code.gitea.io/gitea/services/notify"
    13  )
    14  
    15  // ChangeStatus changes issue status to open or closed.
    16  // closed means the target status
    17  // Fix me: you should check whether the current issue status is same to the target status before call this function
    18  // as in function changeIssueStatus we will return WasClosedError, even the issue status and target status are both open
    19  func ChangeStatus(ctx context.Context, issue *issues_model.Issue, doer *user_model.User, commitID string, closed bool) error {
    20  	comment, err := issues_model.ChangeIssueStatus(ctx, issue, doer, closed)
    21  	if err != nil {
    22  		if issues_model.IsErrDependenciesLeft(err) && closed {
    23  			if err := issues_model.FinishIssueStopwatchIfPossible(ctx, doer, issue); err != nil {
    24  				log.Error("Unable to stop stopwatch for issue[%d]#%d: %v", issue.ID, issue.Index, err)
    25  			}
    26  		}
    27  		return err
    28  	}
    29  
    30  	if closed {
    31  		if err := issues_model.FinishIssueStopwatchIfPossible(ctx, doer, issue); err != nil {
    32  			return err
    33  		}
    34  	}
    35  
    36  	notify_service.IssueChangeStatus(ctx, doer, commitID, issue, comment, closed)
    37  
    38  	return nil
    39  }