|
|
@ -141,43 +141,52 @@ func CreateRepository(user *User, repoName, desc, repoLang, license string, priv
|
|
|
|
|
|
|
|
|
|
|
|
// InitRepository initializes README and .gitignore if needed.
|
|
|
|
// InitRepository initializes README and .gitignore if needed.
|
|
|
|
func initRepository(f string, user *User, repo *Repository, initReadme bool, repoLang, license string) error {
|
|
|
|
func initRepository(f string, user *User, repo *Repository, initReadme bool, repoLang, license string) error {
|
|
|
|
fileName := map[string]string{
|
|
|
|
fileName := map[string]string{}
|
|
|
|
"readme": "README.md",
|
|
|
|
|
|
|
|
"gitign": ".gitignore",
|
|
|
|
if initReadme {
|
|
|
|
"license": "LICENSE",
|
|
|
|
fileName["readme"] = "README.md"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if repoLang != "" {
|
|
|
|
|
|
|
|
fileName["gitign"] = ".gitignore"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if license != "" {
|
|
|
|
|
|
|
|
fileName["license"] = "LICENSE"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
workdir := os.TempDir() + fmt.Sprintf("%d", time.Now().Nanosecond())
|
|
|
|
workdir := os.TempDir() + fmt.Sprintf("%d", time.Now().Nanosecond())
|
|
|
|
os.MkdirAll(workdir, os.ModePerm)
|
|
|
|
os.MkdirAll(workdir, os.ModePerm)
|
|
|
|
|
|
|
|
|
|
|
|
sig := &git.Signature{
|
|
|
|
sig := user.NewGitSig()
|
|
|
|
Name: user.Name,
|
|
|
|
|
|
|
|
Email: user.Email,
|
|
|
|
|
|
|
|
When: time.Now(),
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// README
|
|
|
|
// README
|
|
|
|
defaultReadme := repo.Name + "\n" + strings.Repeat("=",
|
|
|
|
if initReadme {
|
|
|
|
utf8.RuneCountInString(repo.Name)) + "\n\n" + repo.Description
|
|
|
|
defaultReadme := repo.Name + "\n" + strings.Repeat("=",
|
|
|
|
if err := ioutil.WriteFile(filepath.Join(workdir, fileName["readme"]),
|
|
|
|
utf8.RuneCountInString(repo.Name)) + "\n\n" + repo.Description
|
|
|
|
[]byte(defaultReadme), 0644); err != nil {
|
|
|
|
if err := ioutil.WriteFile(filepath.Join(workdir, fileName["readme"]),
|
|
|
|
return err
|
|
|
|
[]byte(defaultReadme), 0644); err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// .gitignore
|
|
|
|
if repoLang != "" {
|
|
|
|
filePath := "conf/gitignore/" + repoLang
|
|
|
|
// .gitignore
|
|
|
|
if com.IsFile(filePath) {
|
|
|
|
filePath := "conf/gitignore/" + repoLang
|
|
|
|
if _, err := com.Copy(filePath,
|
|
|
|
if com.IsFile(filePath) {
|
|
|
|
filepath.Join(workdir, fileName["gitign"])); err != nil {
|
|
|
|
if _, err := com.Copy(filePath,
|
|
|
|
return err
|
|
|
|
filepath.Join(workdir, fileName["gitign"])); err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// LICENSE
|
|
|
|
if license != "" {
|
|
|
|
filePath = "conf/license/" + license
|
|
|
|
// LICENSE
|
|
|
|
if com.IsFile(filePath) {
|
|
|
|
filePath := "conf/license/" + license
|
|
|
|
if _, err := com.Copy(filePath,
|
|
|
|
if com.IsFile(filePath) {
|
|
|
|
filepath.Join(workdir, fileName["license"])); err != nil {
|
|
|
|
if _, err := com.Copy(filePath,
|
|
|
|
return err
|
|
|
|
filepath.Join(workdir, fileName["license"])); err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -227,6 +236,48 @@ func GetRepositoryCount(user *User) (int64, error) {
|
|
|
|
return orm.Count(&Repository{OwnerId: user.Id})
|
|
|
|
return orm.Count(&Repository{OwnerId: user.Id})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
|
|
|
RFile = iota + 1
|
|
|
|
|
|
|
|
RDir
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type RepoFile struct {
|
|
|
|
|
|
|
|
Type int
|
|
|
|
|
|
|
|
Name string
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Created time.Time
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func GetReposFiles(userName, reposName, treeName, rpath string) ([]RepoFile, error) {
|
|
|
|
|
|
|
|
f := RepoPath(userName, reposName)
|
|
|
|
|
|
|
|
repo, err := git.OpenRepository(f)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
obj, err := repo.RevparseSingle("HEAD")
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
lastCommit := obj.(*git.Commit)
|
|
|
|
|
|
|
|
var repofiles []RepoFile
|
|
|
|
|
|
|
|
tree, err := lastCommit.Tree()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var i uint64 = 0
|
|
|
|
|
|
|
|
for ; i < tree.EntryCount(); i++ {
|
|
|
|
|
|
|
|
entry := tree.EntryByIndex(i)
|
|
|
|
|
|
|
|
repofiles = append(repofiles, RepoFile{
|
|
|
|
|
|
|
|
entry.Filemode,
|
|
|
|
|
|
|
|
entry.Name,
|
|
|
|
|
|
|
|
time.Now(),
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return repofiles, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func StarReposiory(user *User, repoName string) error {
|
|
|
|
func StarReposiory(user *User, repoName string) error {
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|