|
|
@@ -23,6 +23,7 @@ import (
|
|
|
"time"
|
|
|
|
|
|
"github.com/Unknwon/com"
|
|
|
+ raven "github.com/getsentry/raven-go"
|
|
|
"github.com/go-xorm/xorm"
|
|
|
"github.com/mcuadros/go-version"
|
|
|
"github.com/nfnt/resize"
|
|
|
@@ -42,7 +43,7 @@ var (
|
|
|
Gitignores, Licenses, Readmes, LabelTemplates []string
|
|
|
|
|
|
// Maximum items per page in forks, watchers and stars of a repo
|
|
|
- ItemsPerPage = 40
|
|
|
+ ItemsPerPage = 39
|
|
|
)
|
|
|
|
|
|
func LoadRepoConfig() {
|
|
|
@@ -52,12 +53,14 @@ func LoadRepoConfig() {
|
|
|
for i, t := range types {
|
|
|
files, err := bindata.AssetDir("conf/" + t)
|
|
|
if err != nil {
|
|
|
+ raven.CaptureErrorAndWait(err, nil)
|
|
|
log.Fatal(4, "Fail to get %s files: %v", t, err)
|
|
|
}
|
|
|
customPath := path.Join(setting.CustomPath, "conf", t)
|
|
|
if com.IsDir(customPath) {
|
|
|
customFiles, err := com.StatDir(customPath)
|
|
|
if err != nil {
|
|
|
+ raven.CaptureErrorAndWait(err, nil)
|
|
|
log.Fatal(4, "Fail to get custom %s files: %v", t, err)
|
|
|
}
|
|
|
|
|
|
@@ -99,6 +102,7 @@ func NewRepoContext() {
|
|
|
|
|
|
// Check Git installation.
|
|
|
if _, err := exec.LookPath("git"); err != nil {
|
|
|
+ raven.CaptureErrorAndWait(err, nil)
|
|
|
log.Fatal(4, "Fail to test 'git' command: %v (forgotten install?)", err)
|
|
|
}
|
|
|
|
|
|
@@ -106,11 +110,13 @@ func NewRepoContext() {
|
|
|
var err error
|
|
|
setting.Git.Version, err = git.BinVersion()
|
|
|
if err != nil {
|
|
|
+ raven.CaptureErrorAndWait(err, nil)
|
|
|
log.Fatal(4, "Fail to get Git version: %v", err)
|
|
|
}
|
|
|
|
|
|
log.Info("Git Version: %s", setting.Git.Version)
|
|
|
if version.Compare("1.7.1", setting.Git.Version, ">") {
|
|
|
+ raven.CaptureErrorAndWait(err, nil)
|
|
|
log.Fatal(4, "Gitote requires Git version greater or equal to 1.7.1")
|
|
|
}
|
|
|
git.HookDir = "custom_hooks"
|
|
|
@@ -123,10 +129,12 @@ func NewRepoContext() {
|
|
|
// ExitError indicates this config is not set
|
|
|
if _, ok := err.(*exec.ExitError); ok || strings.TrimSpace(stdout) == "" {
|
|
|
if _, stderr, gerr := process.Exec("NewRepoContext(set "+configKey+")", "git", "config", "--global", configKey, defaultValue); gerr != nil {
|
|
|
+ raven.CaptureErrorAndWait(err, nil)
|
|
|
log.Fatal(4, "Fail to set git %s(%s): %s", configKey, gerr, stderr)
|
|
|
}
|
|
|
log.Info("Git config %s set to %s", configKey, defaultValue)
|
|
|
} else {
|
|
|
+ raven.CaptureErrorAndWait(err, nil)
|
|
|
log.Fatal(4, "Fail to get git %s(%s): %s", configKey, err, stderr)
|
|
|
}
|
|
|
}
|
|
|
@@ -135,6 +143,7 @@ func NewRepoContext() {
|
|
|
// Set git some configurations.
|
|
|
if _, stderr, err := process.Exec("NewRepoContext(git config --global core.quotepath false)",
|
|
|
"git", "config", "--global", "core.quotepath", "false"); err != nil {
|
|
|
+ raven.CaptureErrorAndWait(err, nil)
|
|
|
log.Fatal(4, "Fail to execute 'git config --global core.quotepath false': %s", stderr)
|
|
|
}
|
|
|
|
|
|
@@ -807,6 +816,7 @@ func MigrateRepository(doer, owner *User, opts MigrateRepoOptions) (*Repository,
|
|
|
}
|
|
|
|
|
|
if err = repo.UpdateSize(); err != nil {
|
|
|
+ raven.CaptureErrorAndWait(err, nil)
|
|
|
log.Error(2, "UpdateSize [repo_id: %d]: %v", repo.ID, err)
|
|
|
}
|
|
|
}
|
|
|
@@ -1157,6 +1167,7 @@ func countRepositories(userID int64, private bool) int64 {
|
|
|
|
|
|
count, err := sess.Count(new(Repository))
|
|
|
if err != nil {
|
|
|
+ raven.CaptureErrorAndWait(err, nil)
|
|
|
log.Error(4, "countRepositories: %v", err)
|
|
|
}
|
|
|
return count
|
|
|
@@ -1426,10 +1437,12 @@ func updateRepository(e Engine, repo *Repository, visibilityChanged bool) (err e
|
|
|
daemonExportFile := path.Join(repo.RepoPath(), "git-daemon-export-ok")
|
|
|
if repo.IsPrivate && com.IsExist(daemonExportFile) {
|
|
|
if err = os.Remove(daemonExportFile); err != nil {
|
|
|
+ raven.CaptureErrorAndWait(err, nil)
|
|
|
log.Error(4, "Failed to remove %s: %v", daemonExportFile, err)
|
|
|
}
|
|
|
} else if !repo.IsPrivate && !com.IsExist(daemonExportFile) {
|
|
|
if f, err := os.Create(daemonExportFile); err != nil {
|
|
|
+ raven.CaptureErrorAndWait(err, nil)
|
|
|
log.Error(4, "Failed to create %s: %v", daemonExportFile, err)
|
|
|
} else {
|
|
|
f.Close()
|
|
|
@@ -1582,6 +1595,7 @@ func DeleteRepository(uid, repoID int64) error {
|
|
|
|
|
|
if repo.NumForks > 0 {
|
|
|
if _, err = x.Exec("UPDATE `repository` SET fork_id=0,is_fork=? WHERE fork_id=?", false, repo.ID); err != nil {
|
|
|
+ raven.CaptureErrorAndWait(err, nil)
|
|
|
log.Error(4, "reset 'fork_id' and 'is_fork': %v", err)
|
|
|
}
|
|
|
}
|
|
|
@@ -1771,6 +1785,7 @@ func DeleteOldRepositoryArchives() {
|
|
|
|
|
|
dir, err := os.Open(dirPath)
|
|
|
if err != nil {
|
|
|
+ raven.CaptureErrorAndWait(err, nil)
|
|
|
log.Error(3, "Fail to open directory '%s': %v", dirPath, err)
|
|
|
continue
|
|
|
}
|
|
|
@@ -1778,6 +1793,7 @@ func DeleteOldRepositoryArchives() {
|
|
|
fis, err := dir.Readdir(0)
|
|
|
dir.Close()
|
|
|
if err != nil {
|
|
|
+ raven.CaptureErrorAndWait(err, nil)
|
|
|
log.Error(3, "Fail to read directory '%s': %v", dirPath, err)
|
|
|
continue
|
|
|
}
|
|
|
@@ -1792,6 +1808,7 @@ func DeleteOldRepositoryArchives() {
|
|
|
desc := fmt.Sprintf("Fail to health delete archive '%s': %v", archivePath, err)
|
|
|
log.Warn(desc)
|
|
|
if err = CreateRepositoryNotice(desc); err != nil {
|
|
|
+ raven.CaptureErrorAndWait(err, nil)
|
|
|
log.Error(3, "CreateRepositoryNotice: %v", err)
|
|
|
}
|
|
|
}
|
|
|
@@ -1800,6 +1817,7 @@ func DeleteOldRepositoryArchives() {
|
|
|
|
|
|
return nil
|
|
|
}); err != nil {
|
|
|
+ raven.CaptureErrorAndWait(err, nil)
|
|
|
log.Error(2, "DeleteOldRepositoryArchives: %v", err)
|
|
|
}
|
|
|
}
|
|
|
@@ -1925,11 +1943,13 @@ func GitFsck() {
|
|
|
desc := fmt.Sprintf("Fail to health check repository '%s': %v", repoPath, err)
|
|
|
log.Warn(desc)
|
|
|
if err = CreateRepositoryNotice(desc); err != nil {
|
|
|
+ raven.CaptureErrorAndWait(err, nil)
|
|
|
log.Error(3, "CreateRepositoryNotice: %v", err)
|
|
|
}
|
|
|
}
|
|
|
return nil
|
|
|
}); err != nil {
|
|
|
+ raven.CaptureErrorAndWait(err, nil)
|
|
|
log.Error(2, "GitFsck: %v", err)
|
|
|
}
|
|
|
}
|
|
|
@@ -1961,6 +1981,7 @@ type repoChecker struct {
|
|
|
func repoStatsCheck(checker *repoChecker) {
|
|
|
results, err := x.Query(checker.querySQL)
|
|
|
if err != nil {
|
|
|
+ raven.CaptureErrorAndWait(err, nil)
|
|
|
log.Error(2, "Select %s: %v", checker.desc, err)
|
|
|
return
|
|
|
}
|
|
|
@@ -1969,6 +1990,7 @@ func repoStatsCheck(checker *repoChecker) {
|
|
|
log.Trace("Updating %s: %d", checker.desc, id)
|
|
|
_, err = x.Exec(checker.correctSQL, id, id)
|
|
|
if err != nil {
|
|
|
+ raven.CaptureErrorAndWait(err, nil)
|
|
|
log.Error(2, "Update %s[%d]: %v", checker.desc, id, err)
|
|
|
}
|
|
|
}
|
|
|
@@ -2023,6 +2045,7 @@ func CheckRepoStats() {
|
|
|
desc := "repository count 'num_closed_issues'"
|
|
|
results, err := x.Query("SELECT repo.id FROM `repository` repo WHERE repo.num_closed_issues!=(SELECT COUNT(*) FROM `issue` WHERE repo_id=repo.id AND is_closed=? AND is_pull=?)", true, false)
|
|
|
if err != nil {
|
|
|
+ raven.CaptureErrorAndWait(err, nil)
|
|
|
log.Error(2, "Select %s: %v", desc, err)
|
|
|
} else {
|
|
|
for _, result := range results {
|
|
|
@@ -2030,6 +2053,7 @@ func CheckRepoStats() {
|
|
|
log.Trace("Updating %s: %d", desc, id)
|
|
|
_, err = x.Exec("UPDATE `repository` SET num_closed_issues=(SELECT COUNT(*) FROM `issue` WHERE repo_id=? AND is_closed=? AND is_pull=?) WHERE id=?", id, true, false, id)
|
|
|
if err != nil {
|
|
|
+ raven.CaptureErrorAndWait(err, nil)
|
|
|
log.Error(2, "Update %s[%d]: %v", desc, id, err)
|
|
|
}
|
|
|
}
|
|
|
@@ -2040,6 +2064,7 @@ func CheckRepoStats() {
|
|
|
// ***** START: Repository.NumForks *****
|
|
|
results, err = x.Query("SELECT repo.id FROM `repository` repo WHERE repo.num_forks!=(SELECT COUNT(*) FROM `repository` WHERE fork_id=repo.id)")
|
|
|
if err != nil {
|
|
|
+ raven.CaptureErrorAndWait(err, nil)
|
|
|
log.Error(2, "Select repository count 'num_forks': %v", err)
|
|
|
} else {
|
|
|
for _, result := range results {
|
|
|
@@ -2048,18 +2073,21 @@ func CheckRepoStats() {
|
|
|
|
|
|
repo, err := GetRepositoryByID(id)
|
|
|
if err != nil {
|
|
|
+ raven.CaptureErrorAndWait(err, nil)
|
|
|
log.Error(2, "GetRepositoryByID[%d]: %v", id, err)
|
|
|
continue
|
|
|
}
|
|
|
|
|
|
rawResult, err := x.Query("SELECT COUNT(*) FROM `repository` WHERE fork_id=?", repo.ID)
|
|
|
if err != nil {
|
|
|
+ raven.CaptureErrorAndWait(err, nil)
|
|
|
log.Error(2, "Select count of forks[%d]: %v", repo.ID, err)
|
|
|
continue
|
|
|
}
|
|
|
repo.NumForks = int(parseCountResult(rawResult))
|
|
|
|
|
|
if err = UpdateRepository(repo, false); err != nil {
|
|
|
+ raven.CaptureErrorAndWait(err, nil)
|
|
|
log.Error(2, "UpdateRepository[%d]: %v", id, err)
|
|
|
continue
|
|
|
}
|
|
|
@@ -2393,6 +2421,7 @@ func ForkRepository(doer, owner *User, baseRepo *Repository, name, desc string)
|
|
|
}
|
|
|
|
|
|
if err = repo.UpdateSize(); err != nil {
|
|
|
+ raven.CaptureErrorAndWait(err, nil)
|
|
|
log.Error(2, "UpdateSize [repo_id: %d]: %v", repo.ID, err)
|
|
|
}
|
|
|
if err = PrepareWebhooks(baseRepo, HOOK_EVENT_FORK, &api.ForkPayload{
|
|
|
@@ -2400,6 +2429,7 @@ func ForkRepository(doer, owner *User, baseRepo *Repository, name, desc string)
|
|
|
Repo: baseRepo.APIFormat(nil),
|
|
|
Sender: doer.APIFormat(),
|
|
|
}); err != nil {
|
|
|
+ raven.CaptureErrorAndWait(err, nil)
|
|
|
log.Error(2, "PrepareWebhooks [repo_id: %d]: %v", baseRepo.ID, err)
|
|
|
}
|
|
|
return repo, nil
|