-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move some milestone functions to a standalone package (#8213)
- Loading branch information
Showing
5 changed files
with
65 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright 2019 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package models | ||
|
||
import ( | ||
"code.gitea.io/gitea/models" | ||
"code.gitea.io/gitea/modules/log" | ||
api "code.gitea.io/gitea/modules/structs" | ||
) | ||
|
||
// ChangeMilestoneAssign changes assignment of milestone for issue. | ||
func ChangeMilestoneAssign(issue *models.Issue, doer *models.User, oldMilestoneID int64) (err error) { | ||
if err = models.ChangeMilestoneAssign(issue, doer, oldMilestoneID); err != nil { | ||
return | ||
} | ||
|
||
var hookAction api.HookIssueAction | ||
if issue.MilestoneID > 0 { | ||
hookAction = api.HookIssueMilestoned | ||
} else { | ||
hookAction = api.HookIssueDemilestoned | ||
} | ||
|
||
if err = issue.LoadAttributes(); err != nil { | ||
return err | ||
} | ||
|
||
mode, _ := models.AccessLevel(doer, issue.Repo) | ||
if issue.IsPull { | ||
err = issue.PullRequest.LoadIssue() | ||
if err != nil { | ||
log.Error("LoadIssue: %v", err) | ||
return | ||
} | ||
err = models.PrepareWebhooks(issue.Repo, models.HookEventPullRequest, &api.PullRequestPayload{ | ||
Action: hookAction, | ||
Index: issue.Index, | ||
PullRequest: issue.PullRequest.APIFormat(), | ||
Repository: issue.Repo.APIFormat(mode), | ||
Sender: doer.APIFormat(), | ||
}) | ||
} else { | ||
err = models.PrepareWebhooks(issue.Repo, models.HookEventIssues, &api.IssuePayload{ | ||
Action: hookAction, | ||
Index: issue.Index, | ||
Issue: issue.APIFormat(), | ||
Repository: issue.Repo.APIFormat(mode), | ||
Sender: doer.APIFormat(), | ||
}) | ||
} | ||
if err != nil { | ||
log.Error("PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err) | ||
} else { | ||
go models.HookQueue.Add(issue.RepoID) | ||
} | ||
return nil | ||
} |