You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

repo.go 17 kB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package models
  5. import (
  6. "errors"
  7. "fmt"
  8. "io/ioutil"
  9. "os"
  10. "os/exec"
  11. "path"
  12. "path/filepath"
  13. "strings"
  14. "time"
  15. "unicode/utf8"
  16. "github.com/Unknwon/cae/zip"
  17. "github.com/Unknwon/com"
  18. "github.com/gogits/git"
  19. "github.com/gogits/gogs/modules/base"
  20. "github.com/gogits/gogs/modules/log"
  21. )
  22. var (
  23. ErrRepoAlreadyExist = errors.New("Repository already exist")
  24. ErrRepoNotExist = errors.New("Repository does not exist")
  25. ErrRepoFileNotExist = errors.New("Target Repo file does not exist")
  26. ErrRepoNameIllegal = errors.New("Repository name contains illegal characters")
  27. ErrRepoFileNotLoaded = fmt.Errorf("repo file not loaded")
  28. )
  29. var (
  30. LanguageIgns, Licenses []string
  31. )
  32. func LoadRepoConfig() {
  33. LanguageIgns = strings.Split(base.Cfg.MustValue("repository", "LANG_IGNS"), "|")
  34. Licenses = strings.Split(base.Cfg.MustValue("repository", "LICENSES"), "|")
  35. }
  36. func NewRepoContext() {
  37. zip.Verbose = false
  38. // Check if server has basic git setting.
  39. stdout, _, err := com.ExecCmd("git", "config", "--get", "user.name")
  40. if err != nil {
  41. fmt.Printf("repo.init(fail to get git user.name): %v", err)
  42. os.Exit(2)
  43. } else if len(stdout) == 0 {
  44. if _, _, err = com.ExecCmd("git", "config", "--global", "user.email", "gogitservice@gmail.com"); err != nil {
  45. fmt.Printf("repo.init(fail to set git user.email): %v", err)
  46. os.Exit(2)
  47. } else if _, _, err = com.ExecCmd("git", "config", "--global", "user.name", "Gogs"); err != nil {
  48. fmt.Printf("repo.init(fail to set git user.name): %v", err)
  49. os.Exit(2)
  50. }
  51. }
  52. }
  53. // Repository represents a git repository.
  54. type Repository struct {
  55. Id int64
  56. OwnerId int64 `xorm:"unique(s)"`
  57. ForkId int64
  58. LowerName string `xorm:"unique(s) index not null"`
  59. Name string `xorm:"index not null"`
  60. Description string
  61. Website string
  62. NumWatches int
  63. NumStars int
  64. NumForks int
  65. NumIssues int
  66. NumReleases int `xorm:"NOT NULL"`
  67. NumClosedIssues int
  68. NumOpenIssues int `xorm:"-"`
  69. IsPrivate bool
  70. IsBare bool
  71. Created time.Time `xorm:"created"`
  72. Updated time.Time `xorm:"updated"`
  73. }
  74. // IsRepositoryExist returns true if the repository with given name under user has already existed.
  75. func IsRepositoryExist(user *User, repoName string) (bool, error) {
  76. repo := Repository{OwnerId: user.Id}
  77. has, err := orm.Where("lower_name = ?", strings.ToLower(repoName)).Get(&repo)
  78. if err != nil {
  79. return has, err
  80. } else if !has {
  81. return false, nil
  82. }
  83. return com.IsDir(RepoPath(user.Name, repoName)), nil
  84. }
  85. var (
  86. illegalEquals = []string{"raw", "install", "api", "avatar", "user", "help", "stars", "issues", "pulls", "commits", "repo", "template", "admin"}
  87. illegalSuffixs = []string{".git"}
  88. )
  89. // IsLegalName returns false if name contains illegal characters.
  90. func IsLegalName(repoName string) bool {
  91. repoName = strings.ToLower(repoName)
  92. for _, char := range illegalEquals {
  93. if repoName == char {
  94. return false
  95. }
  96. }
  97. for _, char := range illegalSuffixs {
  98. if strings.HasSuffix(repoName, char) {
  99. return false
  100. }
  101. }
  102. return true
  103. }
  104. // CreateRepository creates a repository for given user or orgnaziation.
  105. func CreateRepository(user *User, repoName, desc, repoLang, license string, private bool, initReadme bool) (*Repository, error) {
  106. if !IsLegalName(repoName) {
  107. return nil, ErrRepoNameIllegal
  108. }
  109. isExist, err := IsRepositoryExist(user, repoName)
  110. if err != nil {
  111. return nil, err
  112. } else if isExist {
  113. return nil, ErrRepoAlreadyExist
  114. }
  115. repo := &Repository{
  116. OwnerId: user.Id,
  117. Name: repoName,
  118. LowerName: strings.ToLower(repoName),
  119. Description: desc,
  120. IsPrivate: private,
  121. IsBare: repoLang == "" && license == "" && !initReadme,
  122. }
  123. repoPath := RepoPath(user.Name, repoName)
  124. sess := orm.NewSession()
  125. defer sess.Close()
  126. sess.Begin()
  127. if _, err = sess.Insert(repo); err != nil {
  128. if err2 := os.RemoveAll(repoPath); err2 != nil {
  129. log.Error("repo.CreateRepository(repo): %v", err)
  130. return nil, errors.New(fmt.Sprintf(
  131. "delete repo directory %s/%s failed(1): %v", user.Name, repoName, err2))
  132. }
  133. sess.Rollback()
  134. return nil, err
  135. }
  136. access := Access{
  137. UserName: user.LowerName,
  138. RepoName: strings.ToLower(path.Join(user.Name, repo.Name)),
  139. Mode: AU_WRITABLE,
  140. }
  141. if _, err = sess.Insert(&access); err != nil {
  142. sess.Rollback()
  143. if err2 := os.RemoveAll(repoPath); err2 != nil {
  144. log.Error("repo.CreateRepository(access): %v", err)
  145. return nil, errors.New(fmt.Sprintf(
  146. "delete repo directory %s/%s failed(2): %v", user.Name, repoName, err2))
  147. }
  148. return nil, err
  149. }
  150. rawSql := "UPDATE `user` SET num_repos = num_repos + 1 WHERE id = ?"
  151. if _, err = sess.Exec(rawSql, user.Id); err != nil {
  152. sess.Rollback()
  153. if err2 := os.RemoveAll(repoPath); err2 != nil {
  154. log.Error("repo.CreateRepository(repo count): %v", err)
  155. return nil, errors.New(fmt.Sprintf(
  156. "delete repo directory %s/%s failed(3): %v", user.Name, repoName, err2))
  157. }
  158. return nil, err
  159. }
  160. if err = sess.Commit(); err != nil {
  161. sess.Rollback()
  162. if err2 := os.RemoveAll(repoPath); err2 != nil {
  163. log.Error("repo.CreateRepository(commit): %v", err)
  164. return nil, errors.New(fmt.Sprintf(
  165. "delete repo directory %s/%s failed(3): %v", user.Name, repoName, err2))
  166. }
  167. return nil, err
  168. }
  169. c := exec.Command("git", "update-server-info")
  170. c.Dir = repoPath
  171. if err = c.Run(); err != nil {
  172. log.Error("repo.CreateRepository(exec update-server-info): %v", err)
  173. }
  174. if err = NewRepoAction(user, repo); err != nil {
  175. log.Error("repo.CreateRepository(NewRepoAction): %v", err)
  176. }
  177. if err = WatchRepo(user.Id, repo.Id, true); err != nil {
  178. log.Error("repo.CreateRepository(WatchRepo): %v", err)
  179. }
  180. if err = initRepository(repoPath, user, repo, initReadme, repoLang, license); err != nil {
  181. return nil, err
  182. }
  183. return repo, nil
  184. }
  185. // extractGitBareZip extracts git-bare.zip to repository path.
  186. func extractGitBareZip(repoPath string) error {
  187. z, err := zip.Open("conf/content/git-bare.zip")
  188. if err != nil {
  189. fmt.Println("shi?")
  190. return err
  191. }
  192. defer z.Close()
  193. return z.ExtractTo(repoPath)
  194. }
  195. // initRepoCommit temporarily changes with work directory.
  196. func initRepoCommit(tmpPath string, sig *git.Signature) (err error) {
  197. var stderr string
  198. if _, stderr, err = com.ExecCmdDir(tmpPath, "git", "add", "--all"); err != nil {
  199. return err
  200. }
  201. if len(stderr) > 0 {
  202. log.Trace("stderr(1): %s", stderr)
  203. }
  204. if _, stderr, err = com.ExecCmdDir(tmpPath, "git", "commit", fmt.Sprintf("--author='%s <%s>'", sig.Name, sig.Email),
  205. "-m", "Init commit"); err != nil {
  206. return err
  207. }
  208. if len(stderr) > 0 {
  209. log.Trace("stderr(2): %s", stderr)
  210. }
  211. if _, stderr, err = com.ExecCmdDir(tmpPath, "git", "push", "origin", "master"); err != nil {
  212. return err
  213. }
  214. if len(stderr) > 0 {
  215. log.Trace("stderr(3): %s", stderr)
  216. }
  217. return nil
  218. }
  219. func createHookUpdate(hookPath, content string) error {
  220. pu, err := os.OpenFile(hookPath, os.O_CREATE|os.O_WRONLY, 0777)
  221. if err != nil {
  222. return err
  223. }
  224. defer pu.Close()
  225. _, err = pu.WriteString(content)
  226. return err
  227. }
  228. // SetRepoEnvs sets environment variables for command update.
  229. func SetRepoEnvs(userId int64, userName, repoName string) {
  230. os.Setenv("userId", base.ToStr(userId))
  231. os.Setenv("userName", userName)
  232. os.Setenv("repoName", repoName)
  233. }
  234. // InitRepository initializes README and .gitignore if needed.
  235. func initRepository(f string, user *User, repo *Repository, initReadme bool, repoLang, license string) error {
  236. repoPath := RepoPath(user.Name, repo.Name)
  237. // Create bare new repository.
  238. if err := extractGitBareZip(repoPath); err != nil {
  239. return err
  240. }
  241. // hook/post-update
  242. if err := createHookUpdate(filepath.Join(repoPath, "hooks", "update"),
  243. fmt.Sprintf("#!/usr/bin/env bash\n%s update $1 $2 $3\n",
  244. strings.Replace(appPath, "\\", "/", -1))); err != nil {
  245. return err
  246. }
  247. // Initialize repository according to user's choice.
  248. fileName := map[string]string{}
  249. if initReadme {
  250. fileName["readme"] = "README.md"
  251. }
  252. if repoLang != "" {
  253. fileName["gitign"] = ".gitignore"
  254. }
  255. if license != "" {
  256. fileName["license"] = "LICENSE"
  257. }
  258. // Clone to temprory path and do the init commit.
  259. tmpDir := filepath.Join(os.TempDir(), fmt.Sprintf("%d", time.Now().Nanosecond()))
  260. os.MkdirAll(tmpDir, os.ModePerm)
  261. if _, _, err := com.ExecCmd("git", "clone", repoPath, tmpDir); err != nil {
  262. return err
  263. }
  264. // README
  265. if initReadme {
  266. defaultReadme := repo.Name + "\n" + strings.Repeat("=",
  267. utf8.RuneCountInString(repo.Name)) + "\n\n" + repo.Description
  268. if err := ioutil.WriteFile(filepath.Join(tmpDir, fileName["readme"]),
  269. []byte(defaultReadme), 0644); err != nil {
  270. return err
  271. }
  272. }
  273. // .gitignore
  274. if repoLang != "" {
  275. filePath := "conf/gitignore/" + repoLang
  276. if com.IsFile(filePath) {
  277. if _, err := com.Copy(filePath,
  278. filepath.Join(tmpDir, fileName["gitign"])); err != nil {
  279. return err
  280. }
  281. }
  282. }
  283. // LICENSE
  284. if license != "" {
  285. filePath := "conf/license/" + license
  286. if com.IsFile(filePath) {
  287. if _, err := com.Copy(filePath,
  288. filepath.Join(tmpDir, fileName["license"])); err != nil {
  289. return err
  290. }
  291. }
  292. }
  293. if len(fileName) == 0 {
  294. return nil
  295. }
  296. SetRepoEnvs(user.Id, user.Name, repo.Name)
  297. // Apply changes and commit.
  298. return initRepoCommit(tmpDir, user.NewGitSig())
  299. }
  300. // UserRepo reporesents a repository with user name.
  301. type UserRepo struct {
  302. *Repository
  303. UserName string
  304. }
  305. // GetRepos returns given number of repository objects with offset.
  306. func GetRepos(num, offset int) ([]UserRepo, error) {
  307. repos := make([]Repository, 0, num)
  308. if err := orm.Limit(num, offset).Asc("id").Find(&repos); err != nil {
  309. return nil, err
  310. }
  311. urepos := make([]UserRepo, len(repos))
  312. for i := range repos {
  313. urepos[i].Repository = &repos[i]
  314. u := new(User)
  315. has, err := orm.Id(urepos[i].Repository.OwnerId).Get(u)
  316. if err != nil {
  317. return nil, err
  318. } else if !has {
  319. return nil, ErrUserNotExist
  320. }
  321. urepos[i].UserName = u.Name
  322. }
  323. return urepos, nil
  324. }
  325. func RepoPath(userName, repoName string) string {
  326. return filepath.Join(UserPath(userName), strings.ToLower(repoName)+".git")
  327. }
  328. // TransferOwnership transfers all corresponding setting from old user to new one.
  329. func TransferOwnership(user *User, newOwner string, repo *Repository) (err error) {
  330. newUser, err := GetUserByName(newOwner)
  331. if err != nil {
  332. return err
  333. }
  334. // Update accesses.
  335. accesses := make([]Access, 0, 10)
  336. if err = orm.Find(&accesses, &Access{RepoName: user.LowerName + "/" + repo.LowerName}); err != nil {
  337. return err
  338. }
  339. sess := orm.NewSession()
  340. defer sess.Close()
  341. if err = sess.Begin(); err != nil {
  342. return err
  343. }
  344. for i := range accesses {
  345. accesses[i].RepoName = newUser.LowerName + "/" + repo.LowerName
  346. if accesses[i].UserName == user.LowerName {
  347. accesses[i].UserName = newUser.LowerName
  348. }
  349. if err = UpdateAccessWithSession(sess, &accesses[i]); err != nil {
  350. return err
  351. }
  352. }
  353. // Update repository.
  354. repo.OwnerId = newUser.Id
  355. if _, err := sess.Id(repo.Id).Update(repo); err != nil {
  356. sess.Rollback()
  357. return err
  358. }
  359. // Update user repository number.
  360. rawSql := "UPDATE `user` SET num_repos = num_repos + 1 WHERE id = ?"
  361. if _, err = sess.Exec(rawSql, newUser.Id); err != nil {
  362. sess.Rollback()
  363. return err
  364. }
  365. rawSql = "UPDATE `user` SET num_repos = num_repos - 1 WHERE id = ?"
  366. if _, err = sess.Exec(rawSql, user.Id); err != nil {
  367. sess.Rollback()
  368. return err
  369. }
  370. // Add watch of new owner to repository.
  371. if !IsWatching(newUser.Id, repo.Id) {
  372. if err = WatchRepo(newUser.Id, repo.Id, true); err != nil {
  373. sess.Rollback()
  374. return err
  375. }
  376. }
  377. if err = TransferRepoAction(user, newUser, repo); err != nil {
  378. sess.Rollback()
  379. return err
  380. }
  381. // Change repository directory name.
  382. if err = os.Rename(RepoPath(user.Name, repo.Name), RepoPath(newUser.Name, repo.Name)); err != nil {
  383. sess.Rollback()
  384. return err
  385. }
  386. return sess.Commit()
  387. }
  388. // ChangeRepositoryName changes all corresponding setting from old repository name to new one.
  389. func ChangeRepositoryName(userName, oldRepoName, newRepoName string) (err error) {
  390. // Update accesses.
  391. accesses := make([]Access, 0, 10)
  392. if err = orm.Find(&accesses, &Access{RepoName: strings.ToLower(userName + "/" + oldRepoName)}); err != nil {
  393. return err
  394. }
  395. sess := orm.NewSession()
  396. defer sess.Close()
  397. if err = sess.Begin(); err != nil {
  398. return err
  399. }
  400. for i := range accesses {
  401. accesses[i].RepoName = userName + "/" + newRepoName
  402. if err = UpdateAccessWithSession(sess, &accesses[i]); err != nil {
  403. return err
  404. }
  405. }
  406. // Change repository directory name.
  407. if err = os.Rename(RepoPath(userName, oldRepoName), RepoPath(userName, newRepoName)); err != nil {
  408. sess.Rollback()
  409. return err
  410. }
  411. return sess.Commit()
  412. }
  413. func UpdateRepository(repo *Repository) error {
  414. repo.LowerName = strings.ToLower(repo.Name)
  415. if len(repo.Description) > 255 {
  416. repo.Description = repo.Description[:255]
  417. }
  418. if len(repo.Website) > 255 {
  419. repo.Website = repo.Website[:255]
  420. }
  421. _, err := orm.Id(repo.Id).AllCols().Update(repo)
  422. return err
  423. }
  424. // DeleteRepository deletes a repository for a user or orgnaztion.
  425. func DeleteRepository(userId, repoId int64, userName string) (err error) {
  426. repo := &Repository{Id: repoId, OwnerId: userId}
  427. has, err := orm.Get(repo)
  428. if err != nil {
  429. return err
  430. } else if !has {
  431. return ErrRepoNotExist
  432. }
  433. sess := orm.NewSession()
  434. defer sess.Close()
  435. if err = sess.Begin(); err != nil {
  436. return err
  437. }
  438. if _, err = sess.Delete(&Repository{Id: repoId}); err != nil {
  439. sess.Rollback()
  440. return err
  441. }
  442. if _, err := sess.Delete(&Access{RepoName: strings.ToLower(path.Join(userName, repo.Name))}); err != nil {
  443. sess.Rollback()
  444. return err
  445. }
  446. rawSql := "UPDATE `user` SET num_repos = num_repos - 1 WHERE id = ?"
  447. if _, err = sess.Exec(rawSql, userId); err != nil {
  448. sess.Rollback()
  449. return err
  450. }
  451. if _, err = sess.Delete(&Watch{RepoId: repoId}); err != nil {
  452. sess.Rollback()
  453. return err
  454. }
  455. if err = sess.Commit(); err != nil {
  456. sess.Rollback()
  457. return err
  458. }
  459. if err = os.RemoveAll(RepoPath(userName, repo.Name)); err != nil {
  460. // TODO: log and delete manully
  461. log.Error("delete repo %s/%s failed: %v", userName, repo.Name, err)
  462. return err
  463. }
  464. return nil
  465. }
  466. // GetRepositoryByName returns the repository by given name under user if exists.
  467. func GetRepositoryByName(userId int64, repoName string) (*Repository, error) {
  468. repo := &Repository{
  469. OwnerId: userId,
  470. LowerName: strings.ToLower(repoName),
  471. }
  472. has, err := orm.Get(repo)
  473. if err != nil {
  474. return nil, err
  475. } else if !has {
  476. return nil, ErrRepoNotExist
  477. }
  478. return repo, err
  479. }
  480. // GetRepositoryById returns the repository by given id if exists.
  481. func GetRepositoryById(id int64) (*Repository, error) {
  482. repo := &Repository{}
  483. has, err := orm.Id(id).Get(repo)
  484. if err != nil {
  485. return nil, err
  486. } else if !has {
  487. return nil, ErrRepoNotExist
  488. }
  489. return repo, err
  490. }
  491. // GetRepositories returns the list of repositories of given user.
  492. func GetRepositories(user *User) ([]Repository, error) {
  493. repos := make([]Repository, 0, 10)
  494. err := orm.Desc("updated").Find(&repos, &Repository{OwnerId: user.Id})
  495. return repos, err
  496. }
  497. func GetRepositoryCount(user *User) (int64, error) {
  498. return orm.Count(&Repository{OwnerId: user.Id})
  499. }
  500. // Watch is connection request for receiving repository notifycation.
  501. type Watch struct {
  502. Id int64
  503. RepoId int64 `xorm:"UNIQUE(watch)"`
  504. UserId int64 `xorm:"UNIQUE(watch)"`
  505. }
  506. // Watch or unwatch repository.
  507. func WatchRepo(userId, repoId int64, watch bool) (err error) {
  508. if watch {
  509. if _, err = orm.Insert(&Watch{RepoId: repoId, UserId: userId}); err != nil {
  510. return err
  511. }
  512. rawSql := "UPDATE `repository` SET num_watches = num_watches + 1 WHERE id = ?"
  513. _, err = orm.Exec(rawSql, repoId)
  514. } else {
  515. if _, err = orm.Delete(&Watch{0, repoId, userId}); err != nil {
  516. return err
  517. }
  518. rawSql := "UPDATE `repository` SET num_watches = num_watches - 1 WHERE id = ?"
  519. _, err = orm.Exec(rawSql, repoId)
  520. }
  521. return err
  522. }
  523. // GetWatches returns all watches of given repository.
  524. func GetWatches(repoId int64) ([]Watch, error) {
  525. watches := make([]Watch, 0, 10)
  526. err := orm.Find(&watches, &Watch{RepoId: repoId})
  527. return watches, err
  528. }
  529. // NotifyWatchers creates batch of actions for every watcher.
  530. func NotifyWatchers(act *Action) error {
  531. // Add feeds for user self and all watchers.
  532. watches, err := GetWatches(act.RepoId)
  533. if err != nil {
  534. return errors.New("repo.NotifyWatchers(get watches): " + err.Error())
  535. }
  536. // Add feed for actioner.
  537. act.UserId = act.ActUserId
  538. if _, err = orm.InsertOne(act); err != nil {
  539. return errors.New("repo.NotifyWatchers(create action): " + err.Error())
  540. }
  541. for i := range watches {
  542. if act.ActUserId == watches[i].UserId {
  543. continue
  544. }
  545. act.Id = 0
  546. act.UserId = watches[i].UserId
  547. if _, err = orm.InsertOne(act); err != nil {
  548. return errors.New("repo.NotifyWatchers(create action): " + err.Error())
  549. }
  550. }
  551. return nil
  552. }
  553. // IsWatching checks if user has watched given repository.
  554. func IsWatching(userId, repoId int64) bool {
  555. has, _ := orm.Get(&Watch{0, repoId, userId})
  556. return has
  557. }
  558. func ForkRepository(reposName string, userId int64) {
  559. }