Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions models/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -1872,6 +1872,27 @@ func repoStatsCheck(ctx context.Context, checker *repoChecker) {
}
}

// FetchClosedIssueNum fetches the currently stored repositories NumClosedIssues from the database.
// To further clarify, this method does NOT:
// - Recalculate the number of closed issues in the database
// - Return the repositories value of the locally stored NumClosedIssues
// The method will only return an error if an actual SQL error occurred.
// If no value was found, a -1 and a nil error will be returned.
func (repo *Repository) FetchClosedIssueNum() (int, error) {
var value int
found, err := x.Table("repository").
Select("num_closed_issues").
Where("id = ?", repo.ID).
Get(&value)
if err != nil {
return 0, err
}
if !found {
return -1, nil
}
return value, nil
}

// CheckRepoStats checks the repository stats
func CheckRepoStats(ctx context.Context) {
log.Trace("Doing: CheckRepoStats")
Expand Down
16 changes: 16 additions & 0 deletions modules/repofiles/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ func changeIssueStatus(repo *models.Repository, issue *models.Issue, doer *model

// UpdateIssuesCommit checks if issues are manipulated by commit message.
func UpdateIssuesCommit(doer *models.User, repo *models.Repository, commits []*repository.PushCommit, branchName string) error {
// Track if a single commit changed an issue, as we need to update the repo instance in that case.
commitChangedIssue := false

// Commits are appended in the reverse order.
for i := len(commits) - 1; i >= 0; i-- {
c := commits[i]
Expand Down Expand Up @@ -142,9 +145,22 @@ func UpdateIssuesCommit(doer *models.User, repo *models.Repository, commits []*r
if err := changeIssueStatus(refRepo, refIssue, doer, close); err != nil {
return err
}
// Set the issue changed flag to true, to later on update the local repo instance
commitChangedIssue = true
}
}
}

if commitChangedIssue {
if fetchedValue, err := repo.FetchClosedIssueNum(); err == nil {
if fetchedValue > -1 {
repo.NumClosedIssues = fetchedValue
}
} else {
return err
}
}

return nil
}

Expand Down