Remove SavePatch and generate patches on the fly (#9302)
* Save patches to temporary files
* Remove SavePatch and generate patches on the fly
* Use ioutil.TempDir
* fixup! Use ioutil.TempDir
* fixup! fixup! Use ioutil.TempDir
* RemoveAll LocalCopyPath() in initIntergrationTest
* Default to status checking on PR creation
* Remove unnecessary set to StatusChecking
* Protect against unable to load repo
* Handle conflicts
* Restore original conflict setting
* In TestPullRequests update status to StatusChecking before running TestPatch
log.Error("Unable to fetch origin base branch [%s:%s -> base, original_base in %s]: %v:\n%s\n%s",pr.BaseRepo.FullName(),pr.BaseBranch,tmpBasePath,err,outbuf.String(),errbuf.String())
returnfmt.Errorf("Unable to fetch origin base branch [%s:%s -> base, original_base in tmpBasePath]: %v\n%s\n%s",pr.BaseRepo.FullName(),pr.BaseBranch,err,outbuf.String(),errbuf.String())
log.Error("Unable to add head repository as head_repo [%s -> %s]: %v\n%s\n%s",pr.HeadRepo.FullName(),tmpBasePath,err,outbuf.String(),errbuf.String())
returnfmt.Errorf("Unable to add head repository as head_repo [%s -> tmpBasePath]: %v\n%s\n%s",pr.HeadRepo.FullName(),err,outbuf.String(),errbuf.String())
log.Error("Unable to fetch head_repo head branch [%s:%s -> tracking in %s]: %v:\n%s\n%s",pr.HeadRepo.FullName(),pr.HeadBranch,tmpBasePath,err,outbuf.String(),errbuf.String())
returnfmt.Errorf("Unable to fetch head_repo head branch [%s:%s -> tracking in tmpBasePath]: %v\n%s\n%s",pr.HeadRepo.FullName(),pr.HeadBranch,err,outbuf.String(),errbuf.String())
log.Error("Unable to get patch file from %s to %s in %s/%s Error: %v",pr.MergeBase,pr.HeadBranch,pr.BaseRepo.MustOwner().Name,pr.BaseRepo.Name,err)
returnfmt.Errorf("Unable to get patch file from %s to %s in %s/%s Error: %v",pr.MergeBase,pr.HeadBranch,pr.BaseRepo.MustOwner().Name,pr.BaseRepo.Name,err)
}
returnnil
}
varpatchErrorSuffices=[]string{
": already exists in index",
": patch does not apply",
": already exists in working directory",
"unrecognized input",
}
// TestPatch will test whether a simple patch will apply
log.Error("Unable to get patch file from %s to %s in %s/%s Error: %v",pr.MergeBase,pr.HeadBranch,pr.BaseRepo.MustOwner().Name,pr.BaseRepo.Name,err)
returnfmt.Errorf("Unable to get patch file from %s to %s in %s/%s Error: %v",pr.MergeBase,pr.HeadBranch,pr.BaseRepo.MustOwner().Name,pr.BaseRepo.Name,err)
}
stat,err:=tmpPatchFile.Stat()
iferr!=nil{
tmpPatchFile.Close()
returnfmt.Errorf("Unable to stat patch file: %v",err)
}
patchPath:=tmpPatchFile.Name()
tmpPatchFile.Close()
ifstat.Size()==0{
log.Debug("PullRequest[%d]: Patch is empty - ignoring",pr.ID)
return"",fmt.Errorf("Unable to add base repository as origin [%s -> tmpBasePath]: %v\n%s\n%s",pr.BaseRepo.FullName(),err,outbuf.String(),errbuf.String())
log.Error("Unable to fetch origin base branch [%s:%s -> base, original_base in %s]: %v:\n%s\n%s",pr.BaseRepo.FullName(),pr.BaseBranch,tmpBasePath,err,outbuf.String(),errbuf.String())
return"",fmt.Errorf("Unable to fetch origin base branch [%s:%s -> base, original_base in tmpBasePath]: %v\n%s\n%s",pr.BaseRepo.FullName(),pr.BaseBranch,err,outbuf.String(),errbuf.String())
return"",fmt.Errorf("Unable to add head repository as head_repo [%s -> tmpBasePath]: %v\n%s\n%s",pr.HeadRepo.FullName(),err,outbuf.String(),errbuf.String())
log.Error("Unable to fetch head_repo head branch [%s:%s -> tracking in %s]: %v:\n%s\n%s",pr.HeadRepo.FullName(),pr.HeadBranch,tmpBasePath,err,outbuf.String(),errbuf.String())
return"",fmt.Errorf("Unable to fetch head_repo head branch [%s:%s -> tracking in tmpBasePath]: %v\n%s\n%s",pr.HeadRepo.FullName(),pr.HeadBranch,err,outbuf.String(),errbuf.String())