@@ -114,6 +114,10 @@ const (
114114
115115 CommentTypePin // 36 pin Issue
116116 CommentTypeUnpin // 37 unpin Issue
117+
118+ CommentTypeAddedWeight // 38 Added a weight
119+ CommentTypeModifiedWeight // 39 Modified the weight
120+ CommentTypeRemovedWeight // 40 Removed a weight
117121)
118122
119123var commentStrings = []string {
@@ -960,6 +964,40 @@ func createDeadlineComment(ctx context.Context, doer *user_model.User, issue *Is
960964 return comment , nil
961965}
962966
967+ func CreateWeightComment (ctx context.Context , doer * user_model.User , issue * Issue , newWeight int ) (* Comment , error ) {
968+ var content string
969+ var commentType CommentType
970+
971+ // weight = 0 means deleting
972+ if newWeight == 0 {
973+ commentType = CommentTypeRemovedWeight
974+ content = fmt .Sprintf ("%d" , issue .Weight )
975+ } else if issue .Weight == 0 || issue .Weight == newWeight {
976+ commentType = CommentTypeAddedWeight
977+ content = fmt .Sprintf ("%d" , newWeight )
978+ } else { // Otherwise modified
979+ commentType = CommentTypeModifiedWeight
980+ content = fmt .Sprintf ("%d|%d" , newWeight , issue .Weight )
981+ }
982+
983+ if err := issue .LoadRepo (ctx ); err != nil {
984+ return nil , err
985+ }
986+
987+ opts := & CreateCommentOptions {
988+ Type : commentType ,
989+ Doer : doer ,
990+ Repo : issue .Repo ,
991+ Issue : issue ,
992+ Content : content ,
993+ }
994+ comment , err := CreateComment (ctx , opts )
995+ if err != nil {
996+ return nil , err
997+ }
998+ return comment , nil
999+ }
1000+
9631001// Creates issue dependency comment
9641002func createIssueDependencyComment (ctx context.Context , doer * user_model.User , issue , dependentIssue * Issue , add bool ) (err error ) {
9651003 cType := CommentTypeAddDependency
0 commit comments