* Add `gitea doctor --list` flag to list the checks that will be run, including those by default
* Add `gitea doctor --run` to run specific checks
* Add `gitea doctor --all` to run all checks
* Add db version checker
* Add non-default recalculate merge bases check/fixer to doctor
* Add hook checker (Fix#9878) and ensure hooks are executable (Fix#6319)
* Fix authorized_keys checker - slight change of functionality here because parsing the command is fragile and we should just check if the authorized_keys file is essentially the same as what gitea would produce. (This is still not perfect as order matters - we should probably just md5sum the two files.)
* Add SCRIPT_TYPE check (Fix#10977)
* Add `gitea doctor --fix` to attempt to fix what is possible to easily fix
* Add `gitea doctor --log-file` to set the log-file, be it a file, stdout or to switch off completely. (Fixes previously undetected bug with certain xorm logging configurations - see @6543 comment.)
Signed-off-by: Andrew Thornton <art27@cantab.net>
return[]string{fmt.Sprintf("WARN: Got Error %v during ensure up to date",err),"Attempting to migrate to the latest DB version to fix this."},models.NewEngine(context.Background(),migrations.Migrate)
results=append(results,fmt.Sprintf("WARN: Unable to get merge base for PR ID %d, #%d onto %s in %s/%s",pr.ID,pr.Index,pr.BaseBranch,pr.BaseRepo.OwnerName,pr.BaseRepo.Name))
log.Error("Unable to get merge base for PR ID %d, Index %d in %s/%s. Error: %v & %v",pr.ID,pr.Index,pr.BaseRepo.OwnerName,pr.BaseRepo.Name,err,err2)
results=append(results,fmt.Sprintf("WARN: Unable to get parents for merged PR ID %d, #%d onto %s in %s/%s",pr.ID,pr.Index,pr.BaseBranch,pr.BaseRepo.OwnerName,pr.BaseRepo.Name))
log.Error("Unable to get parents for merged PR ID %d, Index %d in %s/%s. Error: %v",pr.ID,pr.Index,pr.BaseRepo.OwnerName,pr.BaseRepo.Name,err)
results=append(results,fmt.Sprintf("WARN: Unable to get merge base for merged PR ID %d, #%d onto %s in %s/%s",pr.ID,pr.Index,pr.BaseBranch,pr.BaseRepo.OwnerName,pr.BaseRepo.Name))
log.Error("Unable to get merge base for merged PR ID %d, Index %d in %s/%s. Error: %v",pr.ID,pr.Index,pr.BaseRepo.OwnerName,pr.BaseRepo.Name,err)
returnresults,nil
}
}
pr.MergeBase=strings.TrimSpace(pr.MergeBase)
ifpr.MergeBase!=oldMergeBase{
ifctx.Bool("fix"){
iferr:=pr.UpdateCols("merge_base");err!=nil{
returnresults,err
}
iflen(iniPath)>0&&iniPath!=setting.CustomConf{
return[]string{fmt.Sprintf("Gitea config path wants %s but %s on %s",setting.CustomConf,iniPath,fPath)},nil
}else{
results=append(results,fmt.Sprintf("#%d onto %s in %s/%s: MergeBase should be %s but is %s",pr.Index,pr.BaseBranch,pr.BaseRepo.OwnerName,pr.BaseRepo.Name,oldMergeBase,pr.MergeBase))
}
numPRsUpdated++
}
returnresults,nil
})
})
returnnil,nil
ifctx.Bool("fix"){
results=append(results,fmt.Sprintf("%d PR mergebases updated of %d PRs total in %d repos",numPRsUpdated,numPRs,numRepos))
}else{
results=append(results,fmt.Sprintf("%d PRs with incorrect mergebases of %d PRs total in %d repos",numPRsUpdated,numPRs,numRepos))
// ExpectedVersion returns the expected db version
funcExpectedVersion()int64{
returnint64(minDBVersion+len(migrations))
}
// EnsureUpToDate will check if the db is at the correct version
funcEnsureUpToDate(x*xorm.Engine)error{
currentDB,err:=GetCurrentDBVersion(x)
iferr!=nil{
returnerr
}
ifcurrentDB<0{
returnfmt.Errorf("Database has not been initialised")
}
ifminDBVersion>currentDB{
returnfmt.Errorf("DB version %d (<= %d) is too old for auto-migration. Upgrade to Gitea 1.6.4 first then upgrade to this version",currentDB,minDBVersion)
}
expected:=ExpectedVersion()
ifcurrentDB!=expected{
returnfmt.Errorf(`Current database version %d is not equal to the expected version %d. Please run "gitea [--config /path/to/app.ini] migrate" to update the database version`,currentDB,expected)