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

repo.go 35KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Copyright 2017 The Gitea Authors. All rights reserved.
  3. // SPDX-License-Identifier: MIT
  4. package context
  5. import (
  6. "context"
  7. "errors"
  8. "fmt"
  9. "html"
  10. "net/http"
  11. "net/url"
  12. "path"
  13. "strings"
  14. "code.gitea.io/gitea/models"
  15. "code.gitea.io/gitea/models/db"
  16. git_model "code.gitea.io/gitea/models/git"
  17. issues_model "code.gitea.io/gitea/models/issues"
  18. access_model "code.gitea.io/gitea/models/perm/access"
  19. repo_model "code.gitea.io/gitea/models/repo"
  20. unit_model "code.gitea.io/gitea/models/unit"
  21. user_model "code.gitea.io/gitea/models/user"
  22. "code.gitea.io/gitea/modules/cache"
  23. "code.gitea.io/gitea/modules/git"
  24. "code.gitea.io/gitea/modules/gitrepo"
  25. code_indexer "code.gitea.io/gitea/modules/indexer/code"
  26. "code.gitea.io/gitea/modules/log"
  27. "code.gitea.io/gitea/modules/optional"
  28. repo_module "code.gitea.io/gitea/modules/repository"
  29. "code.gitea.io/gitea/modules/setting"
  30. "code.gitea.io/gitea/modules/util"
  31. asymkey_service "code.gitea.io/gitea/services/asymkey"
  32. "github.com/editorconfig/editorconfig-core-go/v2"
  33. )
  34. // PullRequest contains information to make a pull request
  35. type PullRequest struct {
  36. BaseRepo *repo_model.Repository
  37. Allowed bool
  38. SameRepo bool
  39. HeadInfoSubURL string // [<user>:]<branch> url segment
  40. }
  41. // Repository contains information to operate a repository
  42. type Repository struct {
  43. access_model.Permission
  44. IsWatching bool
  45. IsViewBranch bool
  46. IsViewTag bool
  47. IsViewCommit bool
  48. Repository *repo_model.Repository
  49. Owner *user_model.User
  50. Commit *git.Commit
  51. Tag *git.Tag
  52. GitRepo *git.Repository
  53. RefName string
  54. BranchName string
  55. TagName string
  56. TreePath string
  57. CommitID string
  58. RepoLink string
  59. CloneLink repo_model.CloneLink
  60. CommitsCount int64
  61. PullRequest *PullRequest
  62. }
  63. // CanWriteToBranch checks if the branch is writable by the user
  64. func (r *Repository) CanWriteToBranch(ctx context.Context, user *user_model.User, branch string) bool {
  65. return issues_model.CanMaintainerWriteToBranch(ctx, r.Permission, branch, user)
  66. }
  67. // CanEnableEditor returns true if repository is editable and user has proper access level.
  68. func (r *Repository) CanEnableEditor(ctx context.Context, user *user_model.User) bool {
  69. return r.IsViewBranch && r.CanWriteToBranch(ctx, user, r.BranchName) && r.Repository.CanEnableEditor() && !r.Repository.IsArchived
  70. }
  71. // CanCreateBranch returns true if repository is editable and user has proper access level.
  72. func (r *Repository) CanCreateBranch() bool {
  73. return r.Permission.CanWrite(unit_model.TypeCode) && r.Repository.CanCreateBranch()
  74. }
  75. func (r *Repository) GetObjectFormat() git.ObjectFormat {
  76. return git.ObjectFormatFromName(r.Repository.ObjectFormatName)
  77. }
  78. // RepoMustNotBeArchived checks if a repo is archived
  79. func RepoMustNotBeArchived() func(ctx *Context) {
  80. return func(ctx *Context) {
  81. if ctx.Repo.Repository.IsArchived {
  82. ctx.NotFound("IsArchived", errors.New(ctx.Locale.TrString("repo.archive.title")))
  83. }
  84. }
  85. }
  86. // CanCommitToBranchResults represents the results of CanCommitToBranch
  87. type CanCommitToBranchResults struct {
  88. CanCommitToBranch bool
  89. EditorEnabled bool
  90. UserCanPush bool
  91. RequireSigned bool
  92. WillSign bool
  93. SigningKey string
  94. WontSignReason string
  95. }
  96. // CanCommitToBranch returns true if repository is editable and user has proper access level
  97. //
  98. // and branch is not protected for push
  99. func (r *Repository) CanCommitToBranch(ctx context.Context, doer *user_model.User) (CanCommitToBranchResults, error) {
  100. protectedBranch, err := git_model.GetFirstMatchProtectedBranchRule(ctx, r.Repository.ID, r.BranchName)
  101. if err != nil {
  102. return CanCommitToBranchResults{}, err
  103. }
  104. userCanPush := true
  105. requireSigned := false
  106. if protectedBranch != nil {
  107. protectedBranch.Repo = r.Repository
  108. userCanPush = protectedBranch.CanUserPush(ctx, doer)
  109. requireSigned = protectedBranch.RequireSignedCommits
  110. }
  111. sign, keyID, _, err := asymkey_service.SignCRUDAction(ctx, r.Repository.RepoPath(), doer, r.Repository.RepoPath(), git.BranchPrefix+r.BranchName)
  112. canCommit := r.CanEnableEditor(ctx, doer) && userCanPush
  113. if requireSigned {
  114. canCommit = canCommit && sign
  115. }
  116. wontSignReason := ""
  117. if err != nil {
  118. if asymkey_service.IsErrWontSign(err) {
  119. wontSignReason = string(err.(*asymkey_service.ErrWontSign).Reason)
  120. err = nil
  121. } else {
  122. wontSignReason = "error"
  123. }
  124. }
  125. return CanCommitToBranchResults{
  126. CanCommitToBranch: canCommit,
  127. EditorEnabled: r.CanEnableEditor(ctx, doer),
  128. UserCanPush: userCanPush,
  129. RequireSigned: requireSigned,
  130. WillSign: sign,
  131. SigningKey: keyID,
  132. WontSignReason: wontSignReason,
  133. }, err
  134. }
  135. // CanUseTimetracker returns whether or not a user can use the timetracker.
  136. func (r *Repository) CanUseTimetracker(ctx context.Context, issue *issues_model.Issue, user *user_model.User) bool {
  137. // Checking for following:
  138. // 1. Is timetracker enabled
  139. // 2. Is the user a contributor, admin, poster or assignee and do the repository policies require this?
  140. isAssigned, _ := issues_model.IsUserAssignedToIssue(ctx, issue, user)
  141. return r.Repository.IsTimetrackerEnabled(ctx) && (!r.Repository.AllowOnlyContributorsToTrackTime(ctx) ||
  142. r.Permission.CanWriteIssuesOrPulls(issue.IsPull) || issue.IsPoster(user.ID) || isAssigned)
  143. }
  144. // CanCreateIssueDependencies returns whether or not a user can create dependencies.
  145. func (r *Repository) CanCreateIssueDependencies(ctx context.Context, user *user_model.User, isPull bool) bool {
  146. return r.Repository.IsDependenciesEnabled(ctx) && r.Permission.CanWriteIssuesOrPulls(isPull)
  147. }
  148. // GetCommitsCount returns cached commit count for current view
  149. func (r *Repository) GetCommitsCount() (int64, error) {
  150. if r.Commit == nil {
  151. return 0, nil
  152. }
  153. var contextName string
  154. if r.IsViewBranch {
  155. contextName = r.BranchName
  156. } else if r.IsViewTag {
  157. contextName = r.TagName
  158. } else {
  159. contextName = r.CommitID
  160. }
  161. return cache.GetInt64(r.Repository.GetCommitsCountCacheKey(contextName, r.IsViewBranch || r.IsViewTag), func() (int64, error) {
  162. return r.Commit.CommitsCount()
  163. })
  164. }
  165. // GetCommitGraphsCount returns cached commit count for current view
  166. func (r *Repository) GetCommitGraphsCount(ctx context.Context, hidePRRefs bool, branches, files []string) (int64, error) {
  167. cacheKey := fmt.Sprintf("commits-count-%d-graph-%t-%s-%s", r.Repository.ID, hidePRRefs, branches, files)
  168. return cache.GetInt64(cacheKey, func() (int64, error) {
  169. if len(branches) == 0 {
  170. return git.AllCommitsCount(ctx, r.Repository.RepoPath(), hidePRRefs, files...)
  171. }
  172. return git.CommitsCount(ctx,
  173. git.CommitsCountOptions{
  174. RepoPath: r.Repository.RepoPath(),
  175. Revision: branches,
  176. RelPath: files,
  177. })
  178. })
  179. }
  180. // BranchNameSubURL sub-URL for the BranchName field
  181. func (r *Repository) BranchNameSubURL() string {
  182. switch {
  183. case r.IsViewBranch:
  184. return "branch/" + util.PathEscapeSegments(r.BranchName)
  185. case r.IsViewTag:
  186. return "tag/" + util.PathEscapeSegments(r.TagName)
  187. case r.IsViewCommit:
  188. return "commit/" + util.PathEscapeSegments(r.CommitID)
  189. }
  190. log.Error("Unknown view type for repo: %v", r)
  191. return ""
  192. }
  193. // FileExists returns true if a file exists in the given repo branch
  194. func (r *Repository) FileExists(path, branch string) (bool, error) {
  195. if branch == "" {
  196. branch = r.Repository.DefaultBranch
  197. }
  198. commit, err := r.GitRepo.GetBranchCommit(branch)
  199. if err != nil {
  200. return false, err
  201. }
  202. if _, err := commit.GetTreeEntryByPath(path); err != nil {
  203. return false, err
  204. }
  205. return true, nil
  206. }
  207. // GetEditorconfig returns the .editorconfig definition if found in the
  208. // HEAD of the default repo branch.
  209. func (r *Repository) GetEditorconfig(optCommit ...*git.Commit) (cfg *editorconfig.Editorconfig, warning, err error) {
  210. if r.GitRepo == nil {
  211. return nil, nil, nil
  212. }
  213. var commit *git.Commit
  214. if len(optCommit) != 0 {
  215. commit = optCommit[0]
  216. } else {
  217. commit, err = r.GitRepo.GetBranchCommit(r.Repository.DefaultBranch)
  218. if err != nil {
  219. return nil, nil, err
  220. }
  221. }
  222. treeEntry, err := commit.GetTreeEntryByPath(".editorconfig")
  223. if err != nil {
  224. return nil, nil, err
  225. }
  226. if treeEntry.Blob().Size() >= setting.UI.MaxDisplayFileSize {
  227. return nil, nil, git.ErrNotExist{ID: "", RelPath: ".editorconfig"}
  228. }
  229. reader, err := treeEntry.Blob().DataAsync()
  230. if err != nil {
  231. return nil, nil, err
  232. }
  233. defer reader.Close()
  234. return editorconfig.ParseGraceful(reader)
  235. }
  236. // RetrieveBaseRepo retrieves base repository
  237. func RetrieveBaseRepo(ctx *Context, repo *repo_model.Repository) {
  238. // Non-fork repository will not return error in this method.
  239. if err := repo.GetBaseRepo(ctx); err != nil {
  240. if repo_model.IsErrRepoNotExist(err) {
  241. repo.IsFork = false
  242. repo.ForkID = 0
  243. return
  244. }
  245. ctx.ServerError("GetBaseRepo", err)
  246. return
  247. } else if err = repo.BaseRepo.LoadOwner(ctx); err != nil {
  248. ctx.ServerError("BaseRepo.LoadOwner", err)
  249. return
  250. }
  251. }
  252. // RetrieveTemplateRepo retrieves template repository used to generate this repository
  253. func RetrieveTemplateRepo(ctx *Context, repo *repo_model.Repository) {
  254. // Non-generated repository will not return error in this method.
  255. templateRepo, err := repo_model.GetTemplateRepo(ctx, repo)
  256. if err != nil {
  257. if repo_model.IsErrRepoNotExist(err) {
  258. repo.TemplateID = 0
  259. return
  260. }
  261. ctx.ServerError("GetTemplateRepo", err)
  262. return
  263. } else if err = templateRepo.LoadOwner(ctx); err != nil {
  264. ctx.ServerError("TemplateRepo.LoadOwner", err)
  265. return
  266. }
  267. perm, err := access_model.GetUserRepoPermission(ctx, templateRepo, ctx.Doer)
  268. if err != nil {
  269. ctx.ServerError("GetUserRepoPermission", err)
  270. return
  271. }
  272. if !perm.CanRead(unit_model.TypeCode) {
  273. repo.TemplateID = 0
  274. }
  275. }
  276. // ComposeGoGetImport returns go-get-import meta content.
  277. func ComposeGoGetImport(owner, repo string) string {
  278. /// setting.AppUrl is guaranteed to be parse as url
  279. appURL, _ := url.Parse(setting.AppURL)
  280. return path.Join(appURL.Host, setting.AppSubURL, url.PathEscape(owner), url.PathEscape(repo))
  281. }
  282. // EarlyResponseForGoGetMeta responses appropriate go-get meta with status 200
  283. // if user does not have actual access to the requested repository,
  284. // or the owner or repository does not exist at all.
  285. // This is particular a workaround for "go get" command which does not respect
  286. // .netrc file.
  287. func EarlyResponseForGoGetMeta(ctx *Context) {
  288. username := ctx.Params(":username")
  289. reponame := strings.TrimSuffix(ctx.Params(":reponame"), ".git")
  290. if username == "" || reponame == "" {
  291. ctx.PlainText(http.StatusBadRequest, "invalid repository path")
  292. return
  293. }
  294. var cloneURL string
  295. if setting.Repository.GoGetCloneURLProtocol == "ssh" {
  296. cloneURL = repo_model.ComposeSSHCloneURL(username, reponame)
  297. } else {
  298. cloneURL = repo_model.ComposeHTTPSCloneURL(username, reponame)
  299. }
  300. goImportContent := fmt.Sprintf("%s git %s", ComposeGoGetImport(username, reponame), cloneURL)
  301. htmlMeta := fmt.Sprintf(`<meta name="go-import" content="%s">`, html.EscapeString(goImportContent))
  302. ctx.PlainText(http.StatusOK, htmlMeta)
  303. }
  304. // RedirectToRepo redirect to a differently-named repository
  305. func RedirectToRepo(ctx *Base, redirectRepoID int64) {
  306. ownerName := ctx.Params(":username")
  307. previousRepoName := ctx.Params(":reponame")
  308. repo, err := repo_model.GetRepositoryByID(ctx, redirectRepoID)
  309. if err != nil {
  310. log.Error("GetRepositoryByID: %v", err)
  311. ctx.Error(http.StatusInternalServerError, "GetRepositoryByID")
  312. return
  313. }
  314. redirectPath := strings.Replace(
  315. ctx.Req.URL.EscapedPath(),
  316. url.PathEscape(ownerName)+"/"+url.PathEscape(previousRepoName),
  317. url.PathEscape(repo.OwnerName)+"/"+url.PathEscape(repo.Name),
  318. 1,
  319. )
  320. if ctx.Req.URL.RawQuery != "" {
  321. redirectPath += "?" + ctx.Req.URL.RawQuery
  322. }
  323. ctx.Redirect(path.Join(setting.AppSubURL, redirectPath), http.StatusTemporaryRedirect)
  324. }
  325. func repoAssignment(ctx *Context, repo *repo_model.Repository) {
  326. var err error
  327. if err = repo.LoadOwner(ctx); err != nil {
  328. ctx.ServerError("LoadOwner", err)
  329. return
  330. }
  331. ctx.Repo.Permission, err = access_model.GetUserRepoPermission(ctx, repo, ctx.Doer)
  332. if err != nil {
  333. ctx.ServerError("GetUserRepoPermission", err)
  334. return
  335. }
  336. // Check access.
  337. if !ctx.Repo.Permission.HasAccess() {
  338. if ctx.FormString("go-get") == "1" {
  339. EarlyResponseForGoGetMeta(ctx)
  340. return
  341. }
  342. ctx.NotFound("no access right", nil)
  343. return
  344. }
  345. ctx.Data["HasAccess"] = true
  346. ctx.Data["Permission"] = &ctx.Repo.Permission
  347. if repo.IsMirror {
  348. pullMirror, err := repo_model.GetMirrorByRepoID(ctx, repo.ID)
  349. if err == nil {
  350. ctx.Data["PullMirror"] = pullMirror
  351. } else if err != repo_model.ErrMirrorNotExist {
  352. ctx.ServerError("GetMirrorByRepoID", err)
  353. return
  354. }
  355. }
  356. pushMirrors, _, err := repo_model.GetPushMirrorsByRepoID(ctx, repo.ID, db.ListOptions{})
  357. if err != nil {
  358. ctx.ServerError("GetPushMirrorsByRepoID", err)
  359. return
  360. }
  361. ctx.Repo.Repository = repo
  362. ctx.Data["PushMirrors"] = pushMirrors
  363. ctx.Data["RepoName"] = ctx.Repo.Repository.Name
  364. ctx.Data["IsEmptyRepo"] = ctx.Repo.Repository.IsEmpty
  365. }
  366. // RepoAssignment returns a middleware to handle repository assignment
  367. func RepoAssignment(ctx *Context) context.CancelFunc {
  368. if _, repoAssignmentOnce := ctx.Data["repoAssignmentExecuted"]; repoAssignmentOnce {
  369. log.Trace("RepoAssignment was exec already, skipping second call ...")
  370. return nil
  371. }
  372. ctx.Data["repoAssignmentExecuted"] = true
  373. var (
  374. owner *user_model.User
  375. err error
  376. )
  377. userName := ctx.Params(":username")
  378. repoName := ctx.Params(":reponame")
  379. repoName = strings.TrimSuffix(repoName, ".git")
  380. if setting.Other.EnableFeed {
  381. repoName = strings.TrimSuffix(repoName, ".rss")
  382. repoName = strings.TrimSuffix(repoName, ".atom")
  383. }
  384. // Check if the user is the same as the repository owner
  385. if ctx.IsSigned && ctx.Doer.LowerName == strings.ToLower(userName) {
  386. owner = ctx.Doer
  387. } else {
  388. owner, err = user_model.GetUserByName(ctx, userName)
  389. if err != nil {
  390. if user_model.IsErrUserNotExist(err) {
  391. // go-get does not support redirects
  392. // https://github.com/golang/go/issues/19760
  393. if ctx.FormString("go-get") == "1" {
  394. EarlyResponseForGoGetMeta(ctx)
  395. return nil
  396. }
  397. if redirectUserID, err := user_model.LookupUserRedirect(ctx, userName); err == nil {
  398. RedirectToUser(ctx.Base, userName, redirectUserID)
  399. } else if user_model.IsErrUserRedirectNotExist(err) {
  400. ctx.NotFound("GetUserByName", nil)
  401. } else {
  402. ctx.ServerError("LookupUserRedirect", err)
  403. }
  404. } else {
  405. ctx.ServerError("GetUserByName", err)
  406. }
  407. return nil
  408. }
  409. }
  410. ctx.Repo.Owner = owner
  411. ctx.ContextUser = owner
  412. ctx.Data["ContextUser"] = ctx.ContextUser
  413. ctx.Data["Username"] = ctx.Repo.Owner.Name
  414. // redirect link to wiki
  415. if strings.HasSuffix(repoName, ".wiki") {
  416. // ctx.Req.URL.Path does not have the preceding appSubURL - any redirect must have this added
  417. // Now we happen to know that all of our paths are: /:username/:reponame/whatever_else
  418. originalRepoName := ctx.Params(":reponame")
  419. redirectRepoName := strings.TrimSuffix(repoName, ".wiki")
  420. redirectRepoName += originalRepoName[len(redirectRepoName)+5:]
  421. redirectPath := strings.Replace(
  422. ctx.Req.URL.EscapedPath(),
  423. url.PathEscape(userName)+"/"+url.PathEscape(originalRepoName),
  424. url.PathEscape(userName)+"/"+url.PathEscape(redirectRepoName)+"/wiki",
  425. 1,
  426. )
  427. if ctx.Req.URL.RawQuery != "" {
  428. redirectPath += "?" + ctx.Req.URL.RawQuery
  429. }
  430. ctx.Redirect(path.Join(setting.AppSubURL, redirectPath))
  431. return nil
  432. }
  433. // Get repository.
  434. repo, err := repo_model.GetRepositoryByName(ctx, owner.ID, repoName)
  435. if err != nil {
  436. if repo_model.IsErrRepoNotExist(err) {
  437. redirectRepoID, err := repo_model.LookupRedirect(ctx, owner.ID, repoName)
  438. if err == nil {
  439. RedirectToRepo(ctx.Base, redirectRepoID)
  440. } else if repo_model.IsErrRedirectNotExist(err) {
  441. if ctx.FormString("go-get") == "1" {
  442. EarlyResponseForGoGetMeta(ctx)
  443. return nil
  444. }
  445. ctx.NotFound("GetRepositoryByName", nil)
  446. } else {
  447. ctx.ServerError("LookupRepoRedirect", err)
  448. }
  449. } else {
  450. ctx.ServerError("GetRepositoryByName", err)
  451. }
  452. return nil
  453. }
  454. repo.Owner = owner
  455. repoAssignment(ctx, repo)
  456. if ctx.Written() {
  457. return nil
  458. }
  459. ctx.Repo.RepoLink = repo.Link()
  460. ctx.Data["RepoLink"] = ctx.Repo.RepoLink
  461. ctx.Data["RepoRelPath"] = ctx.Repo.Owner.Name + "/" + ctx.Repo.Repository.Name
  462. if setting.Other.EnableFeed {
  463. ctx.Data["EnableFeed"] = true
  464. ctx.Data["FeedURL"] = ctx.Repo.RepoLink
  465. }
  466. unit, err := ctx.Repo.Repository.GetUnit(ctx, unit_model.TypeExternalTracker)
  467. if err == nil {
  468. ctx.Data["RepoExternalIssuesLink"] = unit.ExternalTrackerConfig().ExternalTrackerURL
  469. }
  470. ctx.Data["NumTags"], err = db.Count[repo_model.Release](ctx, repo_model.FindReleasesOptions{
  471. IncludeDrafts: true,
  472. IncludeTags: true,
  473. HasSha1: optional.Some(true), // only draft releases which are created with existing tags
  474. RepoID: ctx.Repo.Repository.ID,
  475. })
  476. if err != nil {
  477. ctx.ServerError("GetReleaseCountByRepoID", err)
  478. return nil
  479. }
  480. ctx.Data["NumReleases"], err = db.Count[repo_model.Release](ctx, repo_model.FindReleasesOptions{
  481. // only show draft releases for users who can write, read-only users shouldn't see draft releases.
  482. IncludeDrafts: ctx.Repo.CanWrite(unit_model.TypeReleases),
  483. RepoID: ctx.Repo.Repository.ID,
  484. })
  485. if err != nil {
  486. ctx.ServerError("GetReleaseCountByRepoID", err)
  487. return nil
  488. }
  489. ctx.Data["Title"] = owner.Name + "/" + repo.Name
  490. ctx.Data["Repository"] = repo
  491. ctx.Data["Owner"] = ctx.Repo.Repository.Owner
  492. ctx.Data["IsRepositoryOwner"] = ctx.Repo.IsOwner()
  493. ctx.Data["IsRepositoryAdmin"] = ctx.Repo.IsAdmin()
  494. ctx.Data["RepoOwnerIsOrganization"] = repo.Owner.IsOrganization()
  495. ctx.Data["CanWriteCode"] = ctx.Repo.CanWrite(unit_model.TypeCode)
  496. ctx.Data["CanWriteIssues"] = ctx.Repo.CanWrite(unit_model.TypeIssues)
  497. ctx.Data["CanWritePulls"] = ctx.Repo.CanWrite(unit_model.TypePullRequests)
  498. ctx.Data["CanWriteActions"] = ctx.Repo.CanWrite(unit_model.TypeActions)
  499. canSignedUserFork, err := repo_module.CanUserForkRepo(ctx, ctx.Doer, ctx.Repo.Repository)
  500. if err != nil {
  501. ctx.ServerError("CanUserForkRepo", err)
  502. return nil
  503. }
  504. ctx.Data["CanSignedUserFork"] = canSignedUserFork
  505. userAndOrgForks, err := repo_model.GetForksByUserAndOrgs(ctx, ctx.Doer, ctx.Repo.Repository)
  506. if err != nil {
  507. ctx.ServerError("GetForksByUserAndOrgs", err)
  508. return nil
  509. }
  510. ctx.Data["UserAndOrgForks"] = userAndOrgForks
  511. // canSignedUserFork is true if the current user doesn't have a fork of this repo yet or
  512. // if he owns an org that doesn't have a fork of this repo yet
  513. // If multiple forks are available or if the user can fork to another account, but there is already a fork: open selection dialog
  514. ctx.Data["ShowForkModal"] = len(userAndOrgForks) > 1 || (canSignedUserFork && len(userAndOrgForks) > 0)
  515. ctx.Data["RepoCloneLink"] = repo.CloneLink()
  516. cloneButtonShowHTTPS := !setting.Repository.DisableHTTPGit
  517. cloneButtonShowSSH := !setting.SSH.Disabled && (ctx.IsSigned || setting.SSH.ExposeAnonymous)
  518. if !cloneButtonShowHTTPS && !cloneButtonShowSSH {
  519. // We have to show at least one link, so we just show the HTTPS
  520. cloneButtonShowHTTPS = true
  521. }
  522. ctx.Data["CloneButtonShowHTTPS"] = cloneButtonShowHTTPS
  523. ctx.Data["CloneButtonShowSSH"] = cloneButtonShowSSH
  524. ctx.Data["CloneButtonOriginLink"] = ctx.Data["RepoCloneLink"] // it may be rewritten to the WikiCloneLink by the router middleware
  525. ctx.Data["RepoSearchEnabled"] = setting.Indexer.RepoIndexerEnabled
  526. if setting.Indexer.RepoIndexerEnabled {
  527. ctx.Data["CodeIndexerUnavailable"] = !code_indexer.IsAvailable(ctx)
  528. }
  529. if ctx.IsSigned {
  530. ctx.Data["IsWatchingRepo"] = repo_model.IsWatching(ctx, ctx.Doer.ID, repo.ID)
  531. ctx.Data["IsStaringRepo"] = repo_model.IsStaring(ctx, ctx.Doer.ID, repo.ID)
  532. }
  533. if repo.IsFork {
  534. RetrieveBaseRepo(ctx, repo)
  535. if ctx.Written() {
  536. return nil
  537. }
  538. }
  539. if repo.IsGenerated() {
  540. RetrieveTemplateRepo(ctx, repo)
  541. if ctx.Written() {
  542. return nil
  543. }
  544. }
  545. isHomeOrSettings := ctx.Link == ctx.Repo.RepoLink || ctx.Link == ctx.Repo.RepoLink+"/settings" || strings.HasPrefix(ctx.Link, ctx.Repo.RepoLink+"/settings/")
  546. // Disable everything when the repo is being created
  547. if ctx.Repo.Repository.IsBeingCreated() || ctx.Repo.Repository.IsBroken() {
  548. ctx.Data["BranchName"] = ctx.Repo.Repository.DefaultBranch
  549. if !isHomeOrSettings {
  550. ctx.Redirect(ctx.Repo.RepoLink)
  551. }
  552. return nil
  553. }
  554. gitRepo, err := gitrepo.OpenRepository(ctx, repo)
  555. if err != nil {
  556. if strings.Contains(err.Error(), "repository does not exist") || strings.Contains(err.Error(), "no such file or directory") {
  557. log.Error("Repository %-v has a broken repository on the file system: %s Error: %v", ctx.Repo.Repository, ctx.Repo.Repository.RepoPath(), err)
  558. ctx.Repo.Repository.MarkAsBrokenEmpty()
  559. ctx.Data["BranchName"] = ctx.Repo.Repository.DefaultBranch
  560. // Only allow access to base of repo or settings
  561. if !isHomeOrSettings {
  562. ctx.Redirect(ctx.Repo.RepoLink)
  563. }
  564. return nil
  565. }
  566. ctx.ServerError("RepoAssignment Invalid repo "+repo.FullName(), err)
  567. return nil
  568. }
  569. if ctx.Repo.GitRepo != nil {
  570. ctx.Repo.GitRepo.Close()
  571. }
  572. ctx.Repo.GitRepo = gitRepo
  573. // We opened it, we should close it
  574. cancel := func() {
  575. // If it's been set to nil then assume someone else has closed it.
  576. if ctx.Repo.GitRepo != nil {
  577. ctx.Repo.GitRepo.Close()
  578. }
  579. }
  580. // Stop at this point when the repo is empty.
  581. if ctx.Repo.Repository.IsEmpty {
  582. ctx.Data["BranchName"] = ctx.Repo.Repository.DefaultBranch
  583. return cancel
  584. }
  585. branchOpts := git_model.FindBranchOptions{
  586. RepoID: ctx.Repo.Repository.ID,
  587. IsDeletedBranch: optional.Some(false),
  588. ListOptions: db.ListOptionsAll,
  589. }
  590. branchesTotal, err := db.Count[git_model.Branch](ctx, branchOpts)
  591. if err != nil {
  592. ctx.ServerError("CountBranches", err)
  593. return cancel
  594. }
  595. // non-empty repo should have at least 1 branch, so this repository's branches haven't been synced yet
  596. if branchesTotal == 0 { // fallback to do a sync immediately
  597. branchesTotal, err = repo_module.SyncRepoBranches(ctx, ctx.Repo.Repository.ID, 0)
  598. if err != nil {
  599. ctx.ServerError("SyncRepoBranches", err)
  600. return cancel
  601. }
  602. }
  603. ctx.Data["BranchesCount"] = branchesTotal
  604. // If no branch is set in the request URL, try to guess a default one.
  605. if len(ctx.Repo.BranchName) == 0 {
  606. if len(ctx.Repo.Repository.DefaultBranch) > 0 && gitRepo.IsBranchExist(ctx.Repo.Repository.DefaultBranch) {
  607. ctx.Repo.BranchName = ctx.Repo.Repository.DefaultBranch
  608. } else {
  609. ctx.Repo.BranchName, _ = gitrepo.GetDefaultBranch(ctx, ctx.Repo.Repository)
  610. if ctx.Repo.BranchName == "" {
  611. // If it still can't get a default branch, fall back to default branch from setting.
  612. // Something might be wrong. Either site admin should fix the repo sync or Gitea should fix a potential bug.
  613. ctx.Repo.BranchName = setting.Repository.DefaultBranch
  614. }
  615. }
  616. ctx.Repo.RefName = ctx.Repo.BranchName
  617. }
  618. ctx.Data["BranchName"] = ctx.Repo.BranchName
  619. // People who have push access or have forked repository can propose a new pull request.
  620. canPush := ctx.Repo.CanWrite(unit_model.TypeCode) ||
  621. (ctx.IsSigned && repo_model.HasForkedRepo(ctx, ctx.Doer.ID, ctx.Repo.Repository.ID))
  622. canCompare := false
  623. // Pull request is allowed if this is a fork repository
  624. // and base repository accepts pull requests.
  625. if repo.BaseRepo != nil && repo.BaseRepo.AllowsPulls(ctx) {
  626. canCompare = true
  627. ctx.Data["BaseRepo"] = repo.BaseRepo
  628. ctx.Repo.PullRequest.BaseRepo = repo.BaseRepo
  629. ctx.Repo.PullRequest.Allowed = canPush
  630. ctx.Repo.PullRequest.HeadInfoSubURL = url.PathEscape(ctx.Repo.Owner.Name) + ":" + util.PathEscapeSegments(ctx.Repo.BranchName)
  631. } else if repo.AllowsPulls(ctx) {
  632. // Or, this is repository accepts pull requests between branches.
  633. canCompare = true
  634. ctx.Data["BaseRepo"] = repo
  635. ctx.Repo.PullRequest.BaseRepo = repo
  636. ctx.Repo.PullRequest.Allowed = canPush
  637. ctx.Repo.PullRequest.SameRepo = true
  638. ctx.Repo.PullRequest.HeadInfoSubURL = util.PathEscapeSegments(ctx.Repo.BranchName)
  639. }
  640. ctx.Data["CanCompareOrPull"] = canCompare
  641. ctx.Data["PullRequestCtx"] = ctx.Repo.PullRequest
  642. if ctx.Repo.Repository.Status == repo_model.RepositoryPendingTransfer {
  643. repoTransfer, err := models.GetPendingRepositoryTransfer(ctx, ctx.Repo.Repository)
  644. if err != nil {
  645. ctx.ServerError("GetPendingRepositoryTransfer", err)
  646. return cancel
  647. }
  648. if err := repoTransfer.LoadAttributes(ctx); err != nil {
  649. ctx.ServerError("LoadRecipient", err)
  650. return cancel
  651. }
  652. ctx.Data["RepoTransfer"] = repoTransfer
  653. if ctx.Doer != nil {
  654. ctx.Data["CanUserAcceptTransfer"] = repoTransfer.CanUserAcceptTransfer(ctx, ctx.Doer)
  655. }
  656. }
  657. if ctx.FormString("go-get") == "1" {
  658. ctx.Data["GoGetImport"] = ComposeGoGetImport(owner.Name, repo.Name)
  659. fullURLPrefix := repo.HTMLURL() + "/src/branch/" + util.PathEscapeSegments(ctx.Repo.BranchName)
  660. ctx.Data["GoDocDirectory"] = fullURLPrefix + "{/dir}"
  661. ctx.Data["GoDocFile"] = fullURLPrefix + "{/dir}/{file}#L{line}"
  662. }
  663. return cancel
  664. }
  665. // RepoRefType type of repo reference
  666. type RepoRefType int
  667. const (
  668. // RepoRefLegacy unknown type, make educated guess and redirect.
  669. // for backward compatibility with previous URL scheme
  670. RepoRefLegacy RepoRefType = iota
  671. // RepoRefAny is for usage where educated guess is needed
  672. // but redirect can not be made
  673. RepoRefAny
  674. // RepoRefBranch branch
  675. RepoRefBranch
  676. // RepoRefTag tag
  677. RepoRefTag
  678. // RepoRefCommit commit
  679. RepoRefCommit
  680. // RepoRefBlob blob
  681. RepoRefBlob
  682. )
  683. const headRefName = "HEAD"
  684. // RepoRef handles repository reference names when the ref name is not
  685. // explicitly given
  686. func RepoRef() func(*Context) context.CancelFunc {
  687. // since no ref name is explicitly specified, ok to just use branch
  688. return RepoRefByType(RepoRefBranch)
  689. }
  690. // RefTypeIncludesBranches returns true if ref type can be a branch
  691. func (rt RepoRefType) RefTypeIncludesBranches() bool {
  692. if rt == RepoRefLegacy || rt == RepoRefAny || rt == RepoRefBranch {
  693. return true
  694. }
  695. return false
  696. }
  697. // RefTypeIncludesTags returns true if ref type can be a tag
  698. func (rt RepoRefType) RefTypeIncludesTags() bool {
  699. if rt == RepoRefLegacy || rt == RepoRefAny || rt == RepoRefTag {
  700. return true
  701. }
  702. return false
  703. }
  704. func getRefNameFromPath(ctx *Base, repo *Repository, path string, isExist func(string) bool) string {
  705. refName := ""
  706. parts := strings.Split(path, "/")
  707. for i, part := range parts {
  708. refName = strings.TrimPrefix(refName+"/"+part, "/")
  709. if isExist(refName) {
  710. repo.TreePath = strings.Join(parts[i+1:], "/")
  711. return refName
  712. }
  713. }
  714. return ""
  715. }
  716. func getRefName(ctx *Base, repo *Repository, pathType RepoRefType) string {
  717. path := ctx.Params("*")
  718. switch pathType {
  719. case RepoRefLegacy, RepoRefAny:
  720. if refName := getRefName(ctx, repo, RepoRefBranch); len(refName) > 0 {
  721. return refName
  722. }
  723. if refName := getRefName(ctx, repo, RepoRefTag); len(refName) > 0 {
  724. return refName
  725. }
  726. // For legacy and API support only full commit sha
  727. parts := strings.Split(path, "/")
  728. if len(parts) > 0 && len(parts[0]) == git.ObjectFormatFromName(repo.Repository.ObjectFormatName).FullLength() {
  729. repo.TreePath = strings.Join(parts[1:], "/")
  730. return parts[0]
  731. }
  732. if refName := getRefName(ctx, repo, RepoRefBlob); len(refName) > 0 {
  733. return refName
  734. }
  735. repo.TreePath = path
  736. return repo.Repository.DefaultBranch
  737. case RepoRefBranch:
  738. ref := getRefNameFromPath(ctx, repo, path, repo.GitRepo.IsBranchExist)
  739. if len(ref) == 0 {
  740. // check if ref is HEAD
  741. parts := strings.Split(path, "/")
  742. if parts[0] == headRefName {
  743. repo.TreePath = strings.Join(parts[1:], "/")
  744. return repo.Repository.DefaultBranch
  745. }
  746. // maybe it's a renamed branch
  747. return getRefNameFromPath(ctx, repo, path, func(s string) bool {
  748. b, exist, err := git_model.FindRenamedBranch(ctx, repo.Repository.ID, s)
  749. if err != nil {
  750. log.Error("FindRenamedBranch: %v", err)
  751. return false
  752. }
  753. if !exist {
  754. return false
  755. }
  756. ctx.Data["IsRenamedBranch"] = true
  757. ctx.Data["RenamedBranchName"] = b.To
  758. return true
  759. })
  760. }
  761. return ref
  762. case RepoRefTag:
  763. return getRefNameFromPath(ctx, repo, path, repo.GitRepo.IsTagExist)
  764. case RepoRefCommit:
  765. parts := strings.Split(path, "/")
  766. if len(parts) > 0 && len(parts[0]) >= 7 && len(parts[0]) <= repo.GetObjectFormat().FullLength() {
  767. repo.TreePath = strings.Join(parts[1:], "/")
  768. return parts[0]
  769. }
  770. if len(parts) > 0 && parts[0] == headRefName {
  771. // HEAD ref points to last default branch commit
  772. commit, err := repo.GitRepo.GetBranchCommit(repo.Repository.DefaultBranch)
  773. if err != nil {
  774. return ""
  775. }
  776. repo.TreePath = strings.Join(parts[1:], "/")
  777. return commit.ID.String()
  778. }
  779. case RepoRefBlob:
  780. _, err := repo.GitRepo.GetBlob(path)
  781. if err != nil {
  782. return ""
  783. }
  784. return path
  785. default:
  786. log.Error("Unrecognized path type: %v", path)
  787. }
  788. return ""
  789. }
  790. // RepoRefByType handles repository reference name for a specific type
  791. // of repository reference
  792. func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context) context.CancelFunc {
  793. return func(ctx *Context) (cancel context.CancelFunc) {
  794. // Empty repository does not have reference information.
  795. if ctx.Repo.Repository.IsEmpty {
  796. // assume the user is viewing the (non-existent) default branch
  797. ctx.Repo.IsViewBranch = true
  798. ctx.Repo.BranchName = ctx.Repo.Repository.DefaultBranch
  799. ctx.Data["TreePath"] = ""
  800. return nil
  801. }
  802. var (
  803. refName string
  804. err error
  805. )
  806. if ctx.Repo.GitRepo == nil {
  807. ctx.Repo.GitRepo, err = gitrepo.OpenRepository(ctx, ctx.Repo.Repository)
  808. if err != nil {
  809. ctx.ServerError(fmt.Sprintf("Open Repository %v failed", ctx.Repo.Repository.FullName()), err)
  810. return nil
  811. }
  812. // We opened it, we should close it
  813. cancel = func() {
  814. // If it's been set to nil then assume someone else has closed it.
  815. if ctx.Repo.GitRepo != nil {
  816. ctx.Repo.GitRepo.Close()
  817. }
  818. }
  819. }
  820. // Get default branch.
  821. if len(ctx.Params("*")) == 0 {
  822. refName = ctx.Repo.Repository.DefaultBranch
  823. if !ctx.Repo.GitRepo.IsBranchExist(refName) {
  824. brs, _, err := ctx.Repo.GitRepo.GetBranches(0, 1)
  825. if err == nil && len(brs) != 0 {
  826. refName = brs[0].Name
  827. } else if len(brs) == 0 {
  828. log.Error("No branches in non-empty repository %s", ctx.Repo.GitRepo.Path)
  829. ctx.Repo.Repository.MarkAsBrokenEmpty()
  830. } else {
  831. log.Error("GetBranches error: %v", err)
  832. ctx.Repo.Repository.MarkAsBrokenEmpty()
  833. }
  834. }
  835. ctx.Repo.RefName = refName
  836. ctx.Repo.BranchName = refName
  837. ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetBranchCommit(refName)
  838. if err == nil {
  839. ctx.Repo.CommitID = ctx.Repo.Commit.ID.String()
  840. } else if strings.Contains(err.Error(), "fatal: not a git repository") || strings.Contains(err.Error(), "object does not exist") {
  841. // if the repository is broken, we can continue to the handler code, to show "Settings -> Delete Repository" for end users
  842. log.Error("GetBranchCommit: %v", err)
  843. ctx.Repo.Repository.MarkAsBrokenEmpty()
  844. } else {
  845. ctx.ServerError("GetBranchCommit", err)
  846. return cancel
  847. }
  848. ctx.Repo.IsViewBranch = true
  849. } else {
  850. refName = getRefName(ctx.Base, ctx.Repo, refType)
  851. ctx.Repo.RefName = refName
  852. isRenamedBranch, has := ctx.Data["IsRenamedBranch"].(bool)
  853. if isRenamedBranch && has {
  854. renamedBranchName := ctx.Data["RenamedBranchName"].(string)
  855. ctx.Flash.Info(ctx.Tr("repo.branch.renamed", refName, renamedBranchName))
  856. link := setting.AppSubURL + strings.Replace(ctx.Req.URL.EscapedPath(), util.PathEscapeSegments(refName), util.PathEscapeSegments(renamedBranchName), 1)
  857. ctx.Redirect(link)
  858. return cancel
  859. }
  860. if refType.RefTypeIncludesBranches() && ctx.Repo.GitRepo.IsBranchExist(refName) {
  861. ctx.Repo.IsViewBranch = true
  862. ctx.Repo.BranchName = refName
  863. ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetBranchCommit(refName)
  864. if err != nil {
  865. ctx.ServerError("GetBranchCommit", err)
  866. return cancel
  867. }
  868. ctx.Repo.CommitID = ctx.Repo.Commit.ID.String()
  869. } else if refType.RefTypeIncludesTags() && ctx.Repo.GitRepo.IsTagExist(refName) {
  870. ctx.Repo.IsViewTag = true
  871. ctx.Repo.TagName = refName
  872. ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetTagCommit(refName)
  873. if err != nil {
  874. if git.IsErrNotExist(err) {
  875. ctx.NotFound("GetTagCommit", err)
  876. return cancel
  877. }
  878. ctx.ServerError("GetTagCommit", err)
  879. return cancel
  880. }
  881. ctx.Repo.CommitID = ctx.Repo.Commit.ID.String()
  882. } else if len(refName) >= 7 && len(refName) <= ctx.Repo.GetObjectFormat().FullLength() {
  883. ctx.Repo.IsViewCommit = true
  884. ctx.Repo.CommitID = refName
  885. ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetCommit(refName)
  886. if err != nil {
  887. ctx.NotFound("GetCommit", err)
  888. return cancel
  889. }
  890. // If short commit ID add canonical link header
  891. if len(refName) < ctx.Repo.GetObjectFormat().FullLength() {
  892. ctx.RespHeader().Set("Link", fmt.Sprintf("<%s>; rel=\"canonical\"",
  893. util.URLJoin(setting.AppURL, strings.Replace(ctx.Req.URL.RequestURI(), util.PathEscapeSegments(refName), url.PathEscape(ctx.Repo.Commit.ID.String()), 1))))
  894. }
  895. } else {
  896. if len(ignoreNotExistErr) > 0 && ignoreNotExistErr[0] {
  897. return cancel
  898. }
  899. ctx.NotFound("RepoRef invalid repo", fmt.Errorf("branch or tag not exist: %s", refName))
  900. return cancel
  901. }
  902. if refType == RepoRefLegacy {
  903. // redirect from old URL scheme to new URL scheme
  904. prefix := strings.TrimPrefix(setting.AppSubURL+strings.ToLower(strings.TrimSuffix(ctx.Req.URL.Path, ctx.Params("*"))), strings.ToLower(ctx.Repo.RepoLink))
  905. ctx.Redirect(path.Join(
  906. ctx.Repo.RepoLink,
  907. util.PathEscapeSegments(prefix),
  908. ctx.Repo.BranchNameSubURL(),
  909. util.PathEscapeSegments(ctx.Repo.TreePath)))
  910. return cancel
  911. }
  912. }
  913. ctx.Data["BranchName"] = ctx.Repo.BranchName
  914. ctx.Data["RefName"] = ctx.Repo.RefName
  915. ctx.Data["BranchNameSubURL"] = ctx.Repo.BranchNameSubURL()
  916. ctx.Data["TagName"] = ctx.Repo.TagName
  917. ctx.Data["CommitID"] = ctx.Repo.CommitID
  918. ctx.Data["TreePath"] = ctx.Repo.TreePath
  919. ctx.Data["IsViewBranch"] = ctx.Repo.IsViewBranch
  920. ctx.Data["IsViewTag"] = ctx.Repo.IsViewTag
  921. ctx.Data["IsViewCommit"] = ctx.Repo.IsViewCommit
  922. ctx.Data["CanCreateBranch"] = ctx.Repo.CanCreateBranch()
  923. ctx.Repo.CommitsCount, err = ctx.Repo.GetCommitsCount()
  924. if err != nil {
  925. ctx.ServerError("GetCommitsCount", err)
  926. return cancel
  927. }
  928. ctx.Data["CommitsCount"] = ctx.Repo.CommitsCount
  929. ctx.Repo.GitRepo.LastCommitCache = git.NewLastCommitCache(ctx.Repo.CommitsCount, ctx.Repo.Repository.FullName(), ctx.Repo.GitRepo, cache.GetCache())
  930. return cancel
  931. }
  932. }
  933. // GitHookService checks if repository Git hooks service has been enabled.
  934. func GitHookService() func(ctx *Context) {
  935. return func(ctx *Context) {
  936. if !ctx.Doer.CanEditGitHook() {
  937. ctx.NotFound("GitHookService", nil)
  938. return
  939. }
  940. }
  941. }
  942. // UnitTypes returns a middleware to set unit types to context variables.
  943. func UnitTypes() func(ctx *Context) {
  944. return func(ctx *Context) {
  945. ctx.Data["UnitTypeCode"] = unit_model.TypeCode
  946. ctx.Data["UnitTypeIssues"] = unit_model.TypeIssues
  947. ctx.Data["UnitTypePullRequests"] = unit_model.TypePullRequests
  948. ctx.Data["UnitTypeReleases"] = unit_model.TypeReleases
  949. ctx.Data["UnitTypeWiki"] = unit_model.TypeWiki
  950. ctx.Data["UnitTypeExternalWiki"] = unit_model.TypeExternalWiki
  951. ctx.Data["UnitTypeExternalTracker"] = unit_model.TypeExternalTracker
  952. ctx.Data["UnitTypeProjects"] = unit_model.TypeProjects
  953. ctx.Data["UnitTypePackages"] = unit_model.TypePackages
  954. ctx.Data["UnitTypeActions"] = unit_model.TypeActions
  955. }
  956. }