| 
 | 1 | +// Copyright 2019 The Gitea Authors. All rights reserved.  | 
 | 2 | +// Use of this source code is governed by a MIT-style  | 
 | 3 | +// license that can be found in the LICENSE file.  | 
 | 4 | + | 
 | 5 | +package models  | 
 | 6 | + | 
 | 7 | +import (  | 
 | 8 | +	"code.gitea.io/gitea/models"  | 
 | 9 | +	"code.gitea.io/gitea/modules/log"  | 
 | 10 | +	api "code.gitea.io/gitea/modules/structs"  | 
 | 11 | +)  | 
 | 12 | + | 
 | 13 | +// ChangeMilestoneAssign changes assignment of milestone for issue.  | 
 | 14 | +func ChangeMilestoneAssign(issue *models.Issue, doer *models.User, oldMilestoneID int64) (err error) {  | 
 | 15 | +	if err = models.ChangeMilestoneAssign(issue, doer, oldMilestoneID); err != nil {  | 
 | 16 | +		return  | 
 | 17 | +	}  | 
 | 18 | + | 
 | 19 | +	var hookAction api.HookIssueAction  | 
 | 20 | +	if issue.MilestoneID > 0 {  | 
 | 21 | +		hookAction = api.HookIssueMilestoned  | 
 | 22 | +	} else {  | 
 | 23 | +		hookAction = api.HookIssueDemilestoned  | 
 | 24 | +	}  | 
 | 25 | + | 
 | 26 | +	if err = issue.LoadAttributes(); err != nil {  | 
 | 27 | +		return err  | 
 | 28 | +	}  | 
 | 29 | + | 
 | 30 | +	mode, _ := models.AccessLevel(doer, issue.Repo)  | 
 | 31 | +	if issue.IsPull {  | 
 | 32 | +		err = issue.PullRequest.LoadIssue()  | 
 | 33 | +		if err != nil {  | 
 | 34 | +			log.Error("LoadIssue: %v", err)  | 
 | 35 | +			return  | 
 | 36 | +		}  | 
 | 37 | +		err = models.PrepareWebhooks(issue.Repo, models.HookEventPullRequest, &api.PullRequestPayload{  | 
 | 38 | +			Action:      hookAction,  | 
 | 39 | +			Index:       issue.Index,  | 
 | 40 | +			PullRequest: issue.PullRequest.APIFormat(),  | 
 | 41 | +			Repository:  issue.Repo.APIFormat(mode),  | 
 | 42 | +			Sender:      doer.APIFormat(),  | 
 | 43 | +		})  | 
 | 44 | +	} else {  | 
 | 45 | +		err = models.PrepareWebhooks(issue.Repo, models.HookEventIssues, &api.IssuePayload{  | 
 | 46 | +			Action:     hookAction,  | 
 | 47 | +			Index:      issue.Index,  | 
 | 48 | +			Issue:      issue.APIFormat(),  | 
 | 49 | +			Repository: issue.Repo.APIFormat(mode),  | 
 | 50 | +			Sender:     doer.APIFormat(),  | 
 | 51 | +		})  | 
 | 52 | +	}  | 
 | 53 | +	if err != nil {  | 
 | 54 | +		log.Error("PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err)  | 
 | 55 | +	} else {  | 
 | 56 | +		go models.HookQueue.Add(issue.RepoID)  | 
 | 57 | +	}  | 
 | 58 | +	return nil  | 
 | 59 | +}  | 
0 commit comments