1
0
Fork 0
forked from forgejo/forgejo

Add support for invalidating comments

Signed-off-by: Jonas Franz <info@jonasfranz.software>
This commit is contained in:
Jonas Franz 2018-05-13 13:24:19 +02:00
parent 066086c390
commit 7986d6ed22
No known key found for this signature in database
GPG key ID: 506AEEBE80BEDECD
7 changed files with 154 additions and 28 deletions

View file

@ -1063,10 +1063,7 @@ func (prs PullRequestList) loadAttributes(e Engine) error {
}
// Load issues.
issueIDs := make([]int64, 0, len(prs))
for i := range prs {
issueIDs = append(issueIDs, prs[i].IssueID)
}
issueIDs := prs.getIssueIDs()
issues := make([]*Issue, 0, len(issueIDs))
if err := e.
Where("id > 0").
@ -1085,11 +1082,44 @@ func (prs PullRequestList) loadAttributes(e Engine) error {
return nil
}
func (prs PullRequestList) getIssueIDs() []int64 {
issueIDs := make([]int64, 0, len(prs))
for i := range prs {
issueIDs = append(issueIDs, prs[i].IssueID)
}
return issueIDs
}
// LoadAttributes load all the prs attributes
func (prs PullRequestList) LoadAttributes() error {
return prs.loadAttributes(x)
}
func (prs PullRequestList) invalidateCodeComments(e Engine, repo *git.Repository, branch string) error {
if len(prs) == 0 {
return nil
}
issueIDs := prs.getIssueIDs()
var codeComments []*Comment
if err := e.
Where("type = ? and invalidated = ?", CommentTypeCode, false).
In("issue_id", issueIDs).
Find(&codeComments); err != nil {
return fmt.Errorf("find code comments: %v", err)
}
for _, comment := range codeComments {
if err := comment.CheckInvalidation(repo, branch); err != nil {
return err
}
}
return nil
}
// InvalidateCodeComments will lookup the prs for code comments which got invalidated by change
func (prs PullRequestList) InvalidateCodeComments(repo *git.Repository, branch string) error {
return prs.invalidateCodeComments(x, repo, branch)
}
func addHeadRepoTasks(prs []*PullRequest) {
for _, pr := range prs {
log.Trace("addHeadRepoTasks[%d]: composing new test task", pr.ID)
@ -1116,10 +1146,29 @@ func AddTestPullRequestTask(doer *User, repoID int64, branch string, isSync bool
}
if isSync {
if err = PullRequestList(prs).LoadAttributes(); err != nil {
requests := PullRequestList(prs)
if err = requests.LoadAttributes(); err != nil {
log.Error(4, "PullRequestList.LoadAttributes: %v", err)
}
var gitRepo *git.Repository
repo, err := GetRepositoryByID(repoID)
if err != nil {
log.Error(4, "GetRepositoryByID: %v", err)
goto REQUIRED_PROCEDURE
}
gitRepo, err = git.OpenRepository(repo.RepoPath())
if err != nil {
log.Error(4, "git.OpenRepository: %v", err)
goto REQUIRED_PROCEDURE
}
go func() {
err := requests.InvalidateCodeComments(gitRepo, branch)
if err != nil {
log.Error(4, "PullRequestList.InvalidateCodeComments: %v", err)
}
}()
REQUIRED_PROCEDURE:
if err == nil {
for _, pr := range prs {
pr.Issue.PullRequest = pr