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 20 kB

Feature: Timetracking (#2211) * Added comment's hashtag to url for mail notifications. * Added explanation to return statement + documentation. * Replacing in-line link generation with HTMLURL. (+gofmt) * Replaced action-based model with nil-based model. (+gofmt) * Replaced mailIssueActionToParticipants with mailIssueCommentToParticipants. * Updating comment for mailIssueCommentToParticipants * Added link to comment in "Dashboard" * Deleting feed entry if a comment is going to be deleted * Added migration * Added improved migration to add a CommentID column to action. * Added improved links to comments in feed entries. * Fixes #1956 by filtering for deleted comments that are referenced in actions. * Introducing "IsDeleted" column to action. * Adding design draft (not functional) * Adding database models for stopwatches and trackedtimes * See go-gitea/gitea#967 * Adding design draft (not functional) * Adding translations and improving design * Implementing stopwatch (for timetracking) * Make UI functional * Add hints in timeline for time tracking events * Implementing timetracking feature * Adding "Add time manual" option * Improved stopwatch * Created report of total spent time by user * Only showing total time spent if theire is something to show. * Adding license headers. * Improved error handling for "Add Time Manual" * Adding @sapks 's changes, refactoring * Adding API for feature tracking * Adding unit test * Adding DISABLE/ENABLE option to Repository settings page * Improving translations * Applying @sapk 's changes * Removing repo_unit and using IssuesSetting for disabling/enabling timetracker * Adding DEFAULT_ENABLE_TIMETRACKER to config, installation and admin menu * Improving documentation * Fixing vendor/ folder * Changing timtracking routes by adding subgroups /times and /times/stopwatch (Proposed by @lafriks ) * Restricting write access to timetracking based on the repo settings (Proposed by @lafriks ) * Fixed minor permissions bug. * Adding CanUseTimetracker and IsTimetrackerEnabled in ctx.Repo * Allow assignees and authors to track there time too. * Fixed some build-time-errors + logical errors. * Removing unused Get...ByID functions * Moving IsTimetrackerEnabled from context.Repository to models.Repository * Adding a seperate file for issue related repo functions * Adding license headers * Fixed GetUserByParams return 404 * Moving /users/:username/times to /repos/:username/:reponame/times/:username for security reasons * Adding /repos/:username/times to get all tracked times of the repo * Updating sdk-dependency * Updating swagger.v1.json * Adding warning if user has already a running stopwatch (auto-timetracker) * Replacing GetTrackedTimesBy... with GetTrackedTimes(options FindTrackedTimesOptions) * Changing code.gitea.io/sdk back to code.gitea.io/sdk * Correcting spelling mistake * Updating vendor.json * Changing GET stopwatch/toggle to POST stopwatch/toggle * Changing GET stopwatch/cancel to POST stopwatch/cancel * Added migration for stopwatches/timetracking * Fixed some access bugs for read-only users * Added default allow only contributors to track time value to config * Fixed migration by chaging x.Iterate to x.Find * Resorted imports * Moved Add Time Manually form to repo_form.go * Removed "Seconds" field from Add Time Manually * Resorted imports * Improved permission checking * Fixed some bugs * Added integration test * gofmt * Adding integration test by @lafriks * Added created_unix to comment fixtures * Using last event instead of a fixed event * Adding another integration test by @lafriks * Fixing bug Timetracker enabled causing error 500 at sidebar.tpl * Fixed a refactoring bug that resulted in hiding "HasUserStopwatch" warning. * Returning TrackedTime instead of AddTimeOption at AddTime. * Updating SDK from go-gitea/go-sdk#69 * Resetting Go-SDK back to default repository * Fixing test-vendor by changing ini back to original repository * Adding "tags" to swagger spec * govendor sync * Removed duplicate * Formatting templates * Adding IsTimetrackingEnabled checks to API * Improving translations / english texts * Improving documentation * Updating swagger spec * Fixing integration test caused be translation-changes * Removed encoding issues in local_en-US.ini. * "Added" copyright line * Moved unit.IssuesConfig().EnableTimetracker into a != nil check * Removed some other encoding issues in local_en-US.ini * Improved javascript by checking if data-context exists * Replaced manual comment creation with CreateComment * Removed unnecessary code * Improved error checking * Small cosmetic changes * Replaced int>string>duration parsing with int>duration parsing * Fixed encoding issues * Removed unused imports Signed-off-by: Jonas Franz <info@jonasfranz.software>
8 years ago
11 years ago
11 years ago
11 years ago
Feature: Timetracking (#2211) * Added comment's hashtag to url for mail notifications. * Added explanation to return statement + documentation. * Replacing in-line link generation with HTMLURL. (+gofmt) * Replaced action-based model with nil-based model. (+gofmt) * Replaced mailIssueActionToParticipants with mailIssueCommentToParticipants. * Updating comment for mailIssueCommentToParticipants * Added link to comment in "Dashboard" * Deleting feed entry if a comment is going to be deleted * Added migration * Added improved migration to add a CommentID column to action. * Added improved links to comments in feed entries. * Fixes #1956 by filtering for deleted comments that are referenced in actions. * Introducing "IsDeleted" column to action. * Adding design draft (not functional) * Adding database models for stopwatches and trackedtimes * See go-gitea/gitea#967 * Adding design draft (not functional) * Adding translations and improving design * Implementing stopwatch (for timetracking) * Make UI functional * Add hints in timeline for time tracking events * Implementing timetracking feature * Adding "Add time manual" option * Improved stopwatch * Created report of total spent time by user * Only showing total time spent if theire is something to show. * Adding license headers. * Improved error handling for "Add Time Manual" * Adding @sapks 's changes, refactoring * Adding API for feature tracking * Adding unit test * Adding DISABLE/ENABLE option to Repository settings page * Improving translations * Applying @sapk 's changes * Removing repo_unit and using IssuesSetting for disabling/enabling timetracker * Adding DEFAULT_ENABLE_TIMETRACKER to config, installation and admin menu * Improving documentation * Fixing vendor/ folder * Changing timtracking routes by adding subgroups /times and /times/stopwatch (Proposed by @lafriks ) * Restricting write access to timetracking based on the repo settings (Proposed by @lafriks ) * Fixed minor permissions bug. * Adding CanUseTimetracker and IsTimetrackerEnabled in ctx.Repo * Allow assignees and authors to track there time too. * Fixed some build-time-errors + logical errors. * Removing unused Get...ByID functions * Moving IsTimetrackerEnabled from context.Repository to models.Repository * Adding a seperate file for issue related repo functions * Adding license headers * Fixed GetUserByParams return 404 * Moving /users/:username/times to /repos/:username/:reponame/times/:username for security reasons * Adding /repos/:username/times to get all tracked times of the repo * Updating sdk-dependency * Updating swagger.v1.json * Adding warning if user has already a running stopwatch (auto-timetracker) * Replacing GetTrackedTimesBy... with GetTrackedTimes(options FindTrackedTimesOptions) * Changing code.gitea.io/sdk back to code.gitea.io/sdk * Correcting spelling mistake * Updating vendor.json * Changing GET stopwatch/toggle to POST stopwatch/toggle * Changing GET stopwatch/cancel to POST stopwatch/cancel * Added migration for stopwatches/timetracking * Fixed some access bugs for read-only users * Added default allow only contributors to track time value to config * Fixed migration by chaging x.Iterate to x.Find * Resorted imports * Moved Add Time Manually form to repo_form.go * Removed "Seconds" field from Add Time Manually * Resorted imports * Improved permission checking * Fixed some bugs * Added integration test * gofmt * Adding integration test by @lafriks * Added created_unix to comment fixtures * Using last event instead of a fixed event * Adding another integration test by @lafriks * Fixing bug Timetracker enabled causing error 500 at sidebar.tpl * Fixed a refactoring bug that resulted in hiding "HasUserStopwatch" warning. * Returning TrackedTime instead of AddTimeOption at AddTime. * Updating SDK from go-gitea/go-sdk#69 * Resetting Go-SDK back to default repository * Fixing test-vendor by changing ini back to original repository * Adding "tags" to swagger spec * govendor sync * Removed duplicate * Formatting templates * Adding IsTimetrackingEnabled checks to API * Improving translations / english texts * Improving documentation * Updating swagger spec * Fixing integration test caused be translation-changes * Removed encoding issues in local_en-US.ini. * "Added" copyright line * Moved unit.IssuesConfig().EnableTimetracker into a != nil check * Removed some other encoding issues in local_en-US.ini * Improved javascript by checking if data-context exists * Replaced manual comment creation with CreateComment * Removed unnecessary code * Improved error checking * Small cosmetic changes * Replaced int>string>duration parsing with int>duration parsing * Fixed encoding issues * Removed unused imports Signed-off-by: Jonas Franz <info@jonasfranz.software>
8 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
Feature: Timetracking (#2211) * Added comment's hashtag to url for mail notifications. * Added explanation to return statement + documentation. * Replacing in-line link generation with HTMLURL. (+gofmt) * Replaced action-based model with nil-based model. (+gofmt) * Replaced mailIssueActionToParticipants with mailIssueCommentToParticipants. * Updating comment for mailIssueCommentToParticipants * Added link to comment in "Dashboard" * Deleting feed entry if a comment is going to be deleted * Added migration * Added improved migration to add a CommentID column to action. * Added improved links to comments in feed entries. * Fixes #1956 by filtering for deleted comments that are referenced in actions. * Introducing "IsDeleted" column to action. * Adding design draft (not functional) * Adding database models for stopwatches and trackedtimes * See go-gitea/gitea#967 * Adding design draft (not functional) * Adding translations and improving design * Implementing stopwatch (for timetracking) * Make UI functional * Add hints in timeline for time tracking events * Implementing timetracking feature * Adding "Add time manual" option * Improved stopwatch * Created report of total spent time by user * Only showing total time spent if theire is something to show. * Adding license headers. * Improved error handling for "Add Time Manual" * Adding @sapks 's changes, refactoring * Adding API for feature tracking * Adding unit test * Adding DISABLE/ENABLE option to Repository settings page * Improving translations * Applying @sapk 's changes * Removing repo_unit and using IssuesSetting for disabling/enabling timetracker * Adding DEFAULT_ENABLE_TIMETRACKER to config, installation and admin menu * Improving documentation * Fixing vendor/ folder * Changing timtracking routes by adding subgroups /times and /times/stopwatch (Proposed by @lafriks ) * Restricting write access to timetracking based on the repo settings (Proposed by @lafriks ) * Fixed minor permissions bug. * Adding CanUseTimetracker and IsTimetrackerEnabled in ctx.Repo * Allow assignees and authors to track there time too. * Fixed some build-time-errors + logical errors. * Removing unused Get...ByID functions * Moving IsTimetrackerEnabled from context.Repository to models.Repository * Adding a seperate file for issue related repo functions * Adding license headers * Fixed GetUserByParams return 404 * Moving /users/:username/times to /repos/:username/:reponame/times/:username for security reasons * Adding /repos/:username/times to get all tracked times of the repo * Updating sdk-dependency * Updating swagger.v1.json * Adding warning if user has already a running stopwatch (auto-timetracker) * Replacing GetTrackedTimesBy... with GetTrackedTimes(options FindTrackedTimesOptions) * Changing code.gitea.io/sdk back to code.gitea.io/sdk * Correcting spelling mistake * Updating vendor.json * Changing GET stopwatch/toggle to POST stopwatch/toggle * Changing GET stopwatch/cancel to POST stopwatch/cancel * Added migration for stopwatches/timetracking * Fixed some access bugs for read-only users * Added default allow only contributors to track time value to config * Fixed migration by chaging x.Iterate to x.Find * Resorted imports * Moved Add Time Manually form to repo_form.go * Removed "Seconds" field from Add Time Manually * Resorted imports * Improved permission checking * Fixed some bugs * Added integration test * gofmt * Adding integration test by @lafriks * Added created_unix to comment fixtures * Using last event instead of a fixed event * Adding another integration test by @lafriks * Fixing bug Timetracker enabled causing error 500 at sidebar.tpl * Fixed a refactoring bug that resulted in hiding "HasUserStopwatch" warning. * Returning TrackedTime instead of AddTimeOption at AddTime. * Updating SDK from go-gitea/go-sdk#69 * Resetting Go-SDK back to default repository * Fixing test-vendor by changing ini back to original repository * Adding "tags" to swagger spec * govendor sync * Removed duplicate * Formatting templates * Adding IsTimetrackingEnabled checks to API * Improving translations / english texts * Improving documentation * Updating swagger spec * Fixing integration test caused be translation-changes * Removed encoding issues in local_en-US.ini. * "Added" copyright line * Moved unit.IssuesConfig().EnableTimetracker into a != nil check * Removed some other encoding issues in local_en-US.ini * Improved javascript by checking if data-context exists * Replaced manual comment creation with CreateComment * Removed unnecessary code * Improved error checking * Small cosmetic changes * Replaced int>string>duration parsing with int>duration parsing * Fixed encoding issues * Removed unused imports Signed-off-by: Jonas Franz <info@jonasfranz.software>
8 years ago
Feature: Timetracking (#2211) * Added comment's hashtag to url for mail notifications. * Added explanation to return statement + documentation. * Replacing in-line link generation with HTMLURL. (+gofmt) * Replaced action-based model with nil-based model. (+gofmt) * Replaced mailIssueActionToParticipants with mailIssueCommentToParticipants. * Updating comment for mailIssueCommentToParticipants * Added link to comment in "Dashboard" * Deleting feed entry if a comment is going to be deleted * Added migration * Added improved migration to add a CommentID column to action. * Added improved links to comments in feed entries. * Fixes #1956 by filtering for deleted comments that are referenced in actions. * Introducing "IsDeleted" column to action. * Adding design draft (not functional) * Adding database models for stopwatches and trackedtimes * See go-gitea/gitea#967 * Adding design draft (not functional) * Adding translations and improving design * Implementing stopwatch (for timetracking) * Make UI functional * Add hints in timeline for time tracking events * Implementing timetracking feature * Adding "Add time manual" option * Improved stopwatch * Created report of total spent time by user * Only showing total time spent if theire is something to show. * Adding license headers. * Improved error handling for "Add Time Manual" * Adding @sapks 's changes, refactoring * Adding API for feature tracking * Adding unit test * Adding DISABLE/ENABLE option to Repository settings page * Improving translations * Applying @sapk 's changes * Removing repo_unit and using IssuesSetting for disabling/enabling timetracker * Adding DEFAULT_ENABLE_TIMETRACKER to config, installation and admin menu * Improving documentation * Fixing vendor/ folder * Changing timtracking routes by adding subgroups /times and /times/stopwatch (Proposed by @lafriks ) * Restricting write access to timetracking based on the repo settings (Proposed by @lafriks ) * Fixed minor permissions bug. * Adding CanUseTimetracker and IsTimetrackerEnabled in ctx.Repo * Allow assignees and authors to track there time too. * Fixed some build-time-errors + logical errors. * Removing unused Get...ByID functions * Moving IsTimetrackerEnabled from context.Repository to models.Repository * Adding a seperate file for issue related repo functions * Adding license headers * Fixed GetUserByParams return 404 * Moving /users/:username/times to /repos/:username/:reponame/times/:username for security reasons * Adding /repos/:username/times to get all tracked times of the repo * Updating sdk-dependency * Updating swagger.v1.json * Adding warning if user has already a running stopwatch (auto-timetracker) * Replacing GetTrackedTimesBy... with GetTrackedTimes(options FindTrackedTimesOptions) * Changing code.gitea.io/sdk back to code.gitea.io/sdk * Correcting spelling mistake * Updating vendor.json * Changing GET stopwatch/toggle to POST stopwatch/toggle * Changing GET stopwatch/cancel to POST stopwatch/cancel * Added migration for stopwatches/timetracking * Fixed some access bugs for read-only users * Added default allow only contributors to track time value to config * Fixed migration by chaging x.Iterate to x.Find * Resorted imports * Moved Add Time Manually form to repo_form.go * Removed "Seconds" field from Add Time Manually * Resorted imports * Improved permission checking * Fixed some bugs * Added integration test * gofmt * Adding integration test by @lafriks * Added created_unix to comment fixtures * Using last event instead of a fixed event * Adding another integration test by @lafriks * Fixing bug Timetracker enabled causing error 500 at sidebar.tpl * Fixed a refactoring bug that resulted in hiding "HasUserStopwatch" warning. * Returning TrackedTime instead of AddTimeOption at AddTime. * Updating SDK from go-gitea/go-sdk#69 * Resetting Go-SDK back to default repository * Fixing test-vendor by changing ini back to original repository * Adding "tags" to swagger spec * govendor sync * Removed duplicate * Formatting templates * Adding IsTimetrackingEnabled checks to API * Improving translations / english texts * Improving documentation * Updating swagger spec * Fixing integration test caused be translation-changes * Removed encoding issues in local_en-US.ini. * "Added" copyright line * Moved unit.IssuesConfig().EnableTimetracker into a != nil check * Removed some other encoding issues in local_en-US.ini * Improved javascript by checking if data-context exists * Replaced manual comment creation with CreateComment * Removed unnecessary code * Improved error checking * Small cosmetic changes * Replaced int>string>duration parsing with int>duration parsing * Fixed encoding issues * Removed unused imports Signed-off-by: Jonas Franz <info@jonasfranz.software>
8 years ago
Feature: Timetracking (#2211) * Added comment's hashtag to url for mail notifications. * Added explanation to return statement + documentation. * Replacing in-line link generation with HTMLURL. (+gofmt) * Replaced action-based model with nil-based model. (+gofmt) * Replaced mailIssueActionToParticipants with mailIssueCommentToParticipants. * Updating comment for mailIssueCommentToParticipants * Added link to comment in "Dashboard" * Deleting feed entry if a comment is going to be deleted * Added migration * Added improved migration to add a CommentID column to action. * Added improved links to comments in feed entries. * Fixes #1956 by filtering for deleted comments that are referenced in actions. * Introducing "IsDeleted" column to action. * Adding design draft (not functional) * Adding database models for stopwatches and trackedtimes * See go-gitea/gitea#967 * Adding design draft (not functional) * Adding translations and improving design * Implementing stopwatch (for timetracking) * Make UI functional * Add hints in timeline for time tracking events * Implementing timetracking feature * Adding "Add time manual" option * Improved stopwatch * Created report of total spent time by user * Only showing total time spent if theire is something to show. * Adding license headers. * Improved error handling for "Add Time Manual" * Adding @sapks 's changes, refactoring * Adding API for feature tracking * Adding unit test * Adding DISABLE/ENABLE option to Repository settings page * Improving translations * Applying @sapk 's changes * Removing repo_unit and using IssuesSetting for disabling/enabling timetracker * Adding DEFAULT_ENABLE_TIMETRACKER to config, installation and admin menu * Improving documentation * Fixing vendor/ folder * Changing timtracking routes by adding subgroups /times and /times/stopwatch (Proposed by @lafriks ) * Restricting write access to timetracking based on the repo settings (Proposed by @lafriks ) * Fixed minor permissions bug. * Adding CanUseTimetracker and IsTimetrackerEnabled in ctx.Repo * Allow assignees and authors to track there time too. * Fixed some build-time-errors + logical errors. * Removing unused Get...ByID functions * Moving IsTimetrackerEnabled from context.Repository to models.Repository * Adding a seperate file for issue related repo functions * Adding license headers * Fixed GetUserByParams return 404 * Moving /users/:username/times to /repos/:username/:reponame/times/:username for security reasons * Adding /repos/:username/times to get all tracked times of the repo * Updating sdk-dependency * Updating swagger.v1.json * Adding warning if user has already a running stopwatch (auto-timetracker) * Replacing GetTrackedTimesBy... with GetTrackedTimes(options FindTrackedTimesOptions) * Changing code.gitea.io/sdk back to code.gitea.io/sdk * Correcting spelling mistake * Updating vendor.json * Changing GET stopwatch/toggle to POST stopwatch/toggle * Changing GET stopwatch/cancel to POST stopwatch/cancel * Added migration for stopwatches/timetracking * Fixed some access bugs for read-only users * Added default allow only contributors to track time value to config * Fixed migration by chaging x.Iterate to x.Find * Resorted imports * Moved Add Time Manually form to repo_form.go * Removed "Seconds" field from Add Time Manually * Resorted imports * Improved permission checking * Fixed some bugs * Added integration test * gofmt * Adding integration test by @lafriks * Added created_unix to comment fixtures * Using last event instead of a fixed event * Adding another integration test by @lafriks * Fixing bug Timetracker enabled causing error 500 at sidebar.tpl * Fixed a refactoring bug that resulted in hiding "HasUserStopwatch" warning. * Returning TrackedTime instead of AddTimeOption at AddTime. * Updating SDK from go-gitea/go-sdk#69 * Resetting Go-SDK back to default repository * Fixing test-vendor by changing ini back to original repository * Adding "tags" to swagger spec * govendor sync * Removed duplicate * Formatting templates * Adding IsTimetrackingEnabled checks to API * Improving translations / english texts * Improving documentation * Updating swagger spec * Fixing integration test caused be translation-changes * Removed encoding issues in local_en-US.ini. * "Added" copyright line * Moved unit.IssuesConfig().EnableTimetracker into a != nil check * Removed some other encoding issues in local_en-US.ini * Improved javascript by checking if data-context exists * Replaced manual comment creation with CreateComment * Removed unnecessary code * Improved error checking * Small cosmetic changes * Replaced int>string>duration parsing with int>duration parsing * Fixed encoding issues * Removed unused imports Signed-off-by: Jonas Franz <info@jonasfranz.software>
8 years ago
11 years ago
11 years ago
11 years ago
10 years ago
11 years ago
11 years ago
10 years ago
11 years ago
11 years ago
11 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Copyright 2017 The Gitea Authors. All rights reserved.
  3. // Use of this source code is governed by a MIT-style
  4. // license that can be found in the LICENSE file.
  5. package context
  6. import (
  7. "fmt"
  8. "io/ioutil"
  9. "path"
  10. "strings"
  11. "code.gitea.io/git"
  12. "code.gitea.io/gitea/models"
  13. "code.gitea.io/gitea/modules/cache"
  14. "code.gitea.io/gitea/modules/log"
  15. "code.gitea.io/gitea/modules/setting"
  16. "github.com/Unknwon/com"
  17. "gopkg.in/editorconfig/editorconfig-core-go.v1"
  18. "gopkg.in/macaron.v1"
  19. )
  20. // PullRequest contains informations to make a pull request
  21. type PullRequest struct {
  22. BaseRepo *models.Repository
  23. Allowed bool
  24. SameRepo bool
  25. HeadInfo string // [<user>:]<branch>
  26. }
  27. // Repository contains information to operate a repository
  28. type Repository struct {
  29. models.Permission
  30. IsWatching bool
  31. IsViewBranch bool
  32. IsViewTag bool
  33. IsViewCommit bool
  34. Repository *models.Repository
  35. Owner *models.User
  36. Commit *git.Commit
  37. Tag *git.Tag
  38. GitRepo *git.Repository
  39. BranchName string
  40. TagName string
  41. TreePath string
  42. CommitID string
  43. RepoLink string
  44. CloneLink models.CloneLink
  45. CommitsCount int64
  46. Mirror *models.Mirror
  47. PullRequest *PullRequest
  48. }
  49. // CanEnableEditor returns true if repository is editable and user has proper access level.
  50. func (r *Repository) CanEnableEditor() bool {
  51. return r.Permission.CanWrite(models.UnitTypeCode) && r.Repository.CanEnableEditor() && r.IsViewBranch && !r.Repository.IsArchived
  52. }
  53. // CanCreateBranch returns true if repository is editable and user has proper access level.
  54. func (r *Repository) CanCreateBranch() bool {
  55. return r.Permission.CanWrite(models.UnitTypeCode) && r.Repository.CanCreateBranch()
  56. }
  57. // RepoMustNotBeArchived checks if a repo is archived
  58. func RepoMustNotBeArchived() macaron.Handler {
  59. return func(ctx *Context) {
  60. if ctx.Repo.Repository.IsArchived {
  61. ctx.NotFound("IsArchived", fmt.Errorf(ctx.Tr("repo.archive.title")))
  62. }
  63. }
  64. }
  65. // CanCommitToBranch returns true if repository is editable and user has proper access level
  66. // and branch is not protected for push
  67. func (r *Repository) CanCommitToBranch(doer *models.User) (bool, error) {
  68. protectedBranch, err := r.Repository.IsProtectedBranchForPush(r.BranchName, doer)
  69. if err != nil {
  70. return false, err
  71. }
  72. return r.CanEnableEditor() && !protectedBranch, nil
  73. }
  74. // CanUseTimetracker returns whether or not a user can use the timetracker.
  75. func (r *Repository) CanUseTimetracker(issue *models.Issue, user *models.User) bool {
  76. // Checking for following:
  77. // 1. Is timetracker enabled
  78. // 2. Is the user a contributor, admin, poster or assignee and do the repository policies require this?
  79. isAssigned, _ := models.IsUserAssignedToIssue(issue, user)
  80. return r.Repository.IsTimetrackerEnabled() && (!r.Repository.AllowOnlyContributorsToTrackTime() ||
  81. r.Permission.CanWrite(models.UnitTypeIssues) || issue.IsPoster(user.ID) || isAssigned)
  82. }
  83. // CanCreateIssueDependencies returns whether or not a user can create dependencies.
  84. func (r *Repository) CanCreateIssueDependencies(user *models.User) bool {
  85. return r.Permission.CanWrite(models.UnitTypeIssues) && r.Repository.IsDependenciesEnabled()
  86. }
  87. // GetCommitsCount returns cached commit count for current view
  88. func (r *Repository) GetCommitsCount() (int64, error) {
  89. var contextName string
  90. if r.IsViewBranch {
  91. contextName = r.BranchName
  92. } else if r.IsViewTag {
  93. contextName = r.TagName
  94. } else {
  95. contextName = r.CommitID
  96. }
  97. return cache.GetInt64(r.Repository.GetCommitsCountCacheKey(contextName, r.IsViewBranch || r.IsViewTag), func() (int64, error) {
  98. return r.Commit.CommitsCount()
  99. })
  100. }
  101. // BranchNameSubURL sub-URL for the BranchName field
  102. func (r *Repository) BranchNameSubURL() string {
  103. switch {
  104. case r.IsViewBranch:
  105. return "branch/" + r.BranchName
  106. case r.IsViewTag:
  107. return "tag/" + r.BranchName
  108. case r.IsViewCommit:
  109. return "commit/" + r.BranchName
  110. }
  111. log.Error(4, "Unknown view type for repo: %v", r)
  112. return ""
  113. }
  114. // GetEditorconfig returns the .editorconfig definition if found in the
  115. // HEAD of the default repo branch.
  116. func (r *Repository) GetEditorconfig() (*editorconfig.Editorconfig, error) {
  117. commit, err := r.GitRepo.GetBranchCommit(r.Repository.DefaultBranch)
  118. if err != nil {
  119. return nil, err
  120. }
  121. treeEntry, err := commit.GetTreeEntryByPath(".editorconfig")
  122. if err != nil {
  123. return nil, err
  124. }
  125. if treeEntry.Blob().Size() >= setting.UI.MaxDisplayFileSize {
  126. return nil, git.ErrNotExist{ID: "", RelPath: ".editorconfig"}
  127. }
  128. reader, err := treeEntry.Blob().Data()
  129. if err != nil {
  130. return nil, err
  131. }
  132. data, err := ioutil.ReadAll(reader)
  133. if err != nil {
  134. return nil, err
  135. }
  136. return editorconfig.ParseBytes(data)
  137. }
  138. // RetrieveBaseRepo retrieves base repository
  139. func RetrieveBaseRepo(ctx *Context, repo *models.Repository) {
  140. // Non-fork repository will not return error in this method.
  141. if err := repo.GetBaseRepo(); err != nil {
  142. if models.IsErrRepoNotExist(err) {
  143. repo.IsFork = false
  144. repo.ForkID = 0
  145. return
  146. }
  147. ctx.ServerError("GetBaseRepo", err)
  148. return
  149. } else if err = repo.BaseRepo.GetOwner(); err != nil {
  150. ctx.ServerError("BaseRepo.GetOwner", err)
  151. return
  152. }
  153. }
  154. // ComposeGoGetImport returns go-get-import meta content.
  155. func ComposeGoGetImport(owner, repo string) string {
  156. return path.Join(setting.Domain, setting.AppSubURL, owner, repo)
  157. }
  158. // EarlyResponseForGoGetMeta responses appropriate go-get meta with status 200
  159. // if user does not have actual access to the requested repository,
  160. // or the owner or repository does not exist at all.
  161. // This is particular a workaround for "go get" command which does not respect
  162. // .netrc file.
  163. func EarlyResponseForGoGetMeta(ctx *Context) {
  164. username := ctx.Params(":username")
  165. reponame := ctx.Params(":reponame")
  166. ctx.PlainText(200, []byte(com.Expand(`<meta name="go-import" content="{GoGetImport} git {CloneLink}">`,
  167. map[string]string{
  168. "GoGetImport": ComposeGoGetImport(username, strings.TrimSuffix(reponame, ".git")),
  169. "CloneLink": models.ComposeHTTPSCloneURL(username, reponame),
  170. })))
  171. }
  172. // RedirectToRepo redirect to a differently-named repository
  173. func RedirectToRepo(ctx *Context, redirectRepoID int64) {
  174. ownerName := ctx.Params(":username")
  175. previousRepoName := ctx.Params(":reponame")
  176. repo, err := models.GetRepositoryByID(redirectRepoID)
  177. if err != nil {
  178. ctx.ServerError("GetRepositoryByID", err)
  179. return
  180. }
  181. redirectPath := strings.Replace(
  182. ctx.Req.URL.Path,
  183. fmt.Sprintf("%s/%s", ownerName, previousRepoName),
  184. fmt.Sprintf("%s/%s", ownerName, repo.Name),
  185. 1,
  186. )
  187. ctx.Redirect(redirectPath)
  188. }
  189. func repoAssignment(ctx *Context, repo *models.Repository) {
  190. var err error
  191. ctx.Repo.Permission, err = models.GetUserRepoPermission(repo, ctx.User)
  192. if err != nil {
  193. ctx.ServerError("GetUserRepoPermission", err)
  194. return
  195. }
  196. // Check access.
  197. if ctx.Repo.Permission.AccessMode == models.AccessModeNone {
  198. if ctx.Query("go-get") == "1" {
  199. EarlyResponseForGoGetMeta(ctx)
  200. return
  201. }
  202. ctx.NotFound("no access right", nil)
  203. return
  204. }
  205. ctx.Data["HasAccess"] = true
  206. ctx.Data["Permission"] = &ctx.Repo.Permission
  207. if repo.IsMirror {
  208. var err error
  209. ctx.Repo.Mirror, err = models.GetMirrorByRepoID(repo.ID)
  210. if err != nil {
  211. ctx.ServerError("GetMirror", err)
  212. return
  213. }
  214. ctx.Data["MirrorEnablePrune"] = ctx.Repo.Mirror.EnablePrune
  215. ctx.Data["MirrorInterval"] = ctx.Repo.Mirror.Interval
  216. ctx.Data["Mirror"] = ctx.Repo.Mirror
  217. }
  218. ctx.Repo.Repository = repo
  219. ctx.Data["RepoName"] = ctx.Repo.Repository.Name
  220. ctx.Data["IsEmptyRepo"] = ctx.Repo.Repository.IsEmpty
  221. }
  222. // RepoIDAssignment returns a macaron handler which assigns the repo to the context.
  223. func RepoIDAssignment() macaron.Handler {
  224. return func(ctx *Context) {
  225. repoID := ctx.ParamsInt64(":repoid")
  226. // Get repository.
  227. repo, err := models.GetRepositoryByID(repoID)
  228. if err != nil {
  229. if models.IsErrRepoNotExist(err) {
  230. ctx.NotFound("GetRepositoryByID", nil)
  231. } else {
  232. ctx.ServerError("GetRepositoryByID", err)
  233. }
  234. return
  235. }
  236. repoAssignment(ctx, repo)
  237. }
  238. }
  239. // RepoAssignment returns a macaron to handle repository assignment
  240. func RepoAssignment() macaron.Handler {
  241. return func(ctx *Context) {
  242. var (
  243. owner *models.User
  244. err error
  245. )
  246. userName := ctx.Params(":username")
  247. repoName := ctx.Params(":reponame")
  248. // Check if the user is the same as the repository owner
  249. if ctx.IsSigned && ctx.User.LowerName == strings.ToLower(userName) {
  250. owner = ctx.User
  251. } else {
  252. owner, err = models.GetUserByName(userName)
  253. if err != nil {
  254. if models.IsErrUserNotExist(err) {
  255. if ctx.Query("go-get") == "1" {
  256. EarlyResponseForGoGetMeta(ctx)
  257. return
  258. }
  259. ctx.NotFound("GetUserByName", nil)
  260. } else {
  261. ctx.ServerError("GetUserByName", err)
  262. }
  263. return
  264. }
  265. }
  266. ctx.Repo.Owner = owner
  267. ctx.Data["Username"] = ctx.Repo.Owner.Name
  268. // Get repository.
  269. repo, err := models.GetRepositoryByName(owner.ID, repoName)
  270. if err != nil {
  271. if models.IsErrRepoNotExist(err) {
  272. redirectRepoID, err := models.LookupRepoRedirect(owner.ID, repoName)
  273. if err == nil {
  274. RedirectToRepo(ctx, redirectRepoID)
  275. } else if models.IsErrRepoRedirectNotExist(err) {
  276. if ctx.Query("go-get") == "1" {
  277. EarlyResponseForGoGetMeta(ctx)
  278. return
  279. }
  280. ctx.NotFound("GetRepositoryByName", nil)
  281. } else {
  282. ctx.ServerError("LookupRepoRedirect", err)
  283. }
  284. } else {
  285. ctx.ServerError("GetRepositoryByName", err)
  286. }
  287. return
  288. }
  289. repo.Owner = owner
  290. repoAssignment(ctx, repo)
  291. if ctx.Written() {
  292. return
  293. }
  294. gitRepo, err := git.OpenRepository(models.RepoPath(userName, repoName))
  295. if err != nil {
  296. ctx.ServerError("RepoAssignment Invalid repo "+models.RepoPath(userName, repoName), err)
  297. return
  298. }
  299. ctx.Repo.GitRepo = gitRepo
  300. ctx.Repo.RepoLink = repo.Link()
  301. ctx.Data["RepoLink"] = ctx.Repo.RepoLink
  302. ctx.Data["RepoRelPath"] = ctx.Repo.Owner.Name + "/" + ctx.Repo.Repository.Name
  303. tags, err := ctx.Repo.GitRepo.GetTags()
  304. if err != nil {
  305. ctx.ServerError("GetTags", err)
  306. return
  307. }
  308. ctx.Data["Tags"] = tags
  309. count, err := models.GetReleaseCountByRepoID(ctx.Repo.Repository.ID, models.FindReleasesOptions{
  310. IncludeDrafts: false,
  311. IncludeTags: true,
  312. })
  313. if err != nil {
  314. ctx.ServerError("GetReleaseCountByRepoID", err)
  315. return
  316. }
  317. ctx.Repo.Repository.NumReleases = int(count)
  318. ctx.Data["Title"] = owner.Name + "/" + repo.Name
  319. ctx.Data["Repository"] = repo
  320. ctx.Data["Owner"] = ctx.Repo.Repository.Owner
  321. ctx.Data["IsRepositoryOwner"] = ctx.Repo.IsOwner()
  322. ctx.Data["IsRepositoryAdmin"] = ctx.Repo.IsAdmin()
  323. ctx.Data["CanWriteCode"] = ctx.Repo.CanWrite(models.UnitTypeCode)
  324. ctx.Data["CanWriteIssues"] = ctx.Repo.CanWrite(models.UnitTypeIssues)
  325. ctx.Data["CanWritePulls"] = ctx.Repo.CanWrite(models.UnitTypePullRequests)
  326. if ctx.Data["CanSignedUserFork"], err = ctx.Repo.Repository.CanUserFork(ctx.User); err != nil {
  327. ctx.ServerError("CanUserFork", err)
  328. return
  329. }
  330. ctx.Data["DisableSSH"] = setting.SSH.Disabled
  331. ctx.Data["ExposeAnonSSH"] = setting.SSH.ExposeAnonymous
  332. ctx.Data["DisableHTTP"] = setting.Repository.DisableHTTPGit
  333. ctx.Data["RepoSearchEnabled"] = setting.Indexer.RepoIndexerEnabled
  334. ctx.Data["CloneLink"] = repo.CloneLink()
  335. ctx.Data["WikiCloneLink"] = repo.WikiCloneLink()
  336. if ctx.IsSigned {
  337. ctx.Data["IsWatchingRepo"] = models.IsWatching(ctx.User.ID, repo.ID)
  338. ctx.Data["IsStaringRepo"] = models.IsStaring(ctx.User.ID, repo.ID)
  339. }
  340. // repo is empty and display enable
  341. if ctx.Repo.Repository.IsEmpty {
  342. ctx.Data["BranchName"] = ctx.Repo.Repository.DefaultBranch
  343. return
  344. }
  345. ctx.Data["TagName"] = ctx.Repo.TagName
  346. brs, err := ctx.Repo.GitRepo.GetBranches()
  347. if err != nil {
  348. ctx.ServerError("GetBranches", err)
  349. return
  350. }
  351. ctx.Data["Branches"] = brs
  352. ctx.Data["BranchesCount"] = len(brs)
  353. // If not branch selected, try default one.
  354. // If default branch doesn't exists, fall back to some other branch.
  355. if len(ctx.Repo.BranchName) == 0 {
  356. if len(ctx.Repo.Repository.DefaultBranch) > 0 && gitRepo.IsBranchExist(ctx.Repo.Repository.DefaultBranch) {
  357. ctx.Repo.BranchName = ctx.Repo.Repository.DefaultBranch
  358. } else if len(brs) > 0 {
  359. ctx.Repo.BranchName = brs[0]
  360. }
  361. }
  362. ctx.Data["BranchName"] = ctx.Repo.BranchName
  363. ctx.Data["CommitID"] = ctx.Repo.CommitID
  364. if repo.IsFork {
  365. RetrieveBaseRepo(ctx, repo)
  366. if ctx.Written() {
  367. return
  368. }
  369. }
  370. // People who have push access or have forked repository can propose a new pull request.
  371. if ctx.Repo.CanWrite(models.UnitTypeCode) || (ctx.IsSigned && ctx.User.HasForkedRepo(ctx.Repo.Repository.ID)) {
  372. // Pull request is allowed if this is a fork repository
  373. // and base repository accepts pull requests.
  374. if repo.BaseRepo != nil && repo.BaseRepo.AllowsPulls() {
  375. ctx.Data["BaseRepo"] = repo.BaseRepo
  376. ctx.Repo.PullRequest.BaseRepo = repo.BaseRepo
  377. ctx.Repo.PullRequest.Allowed = true
  378. ctx.Repo.PullRequest.HeadInfo = ctx.Repo.Owner.Name + ":" + ctx.Repo.BranchName
  379. } else {
  380. // Or, this is repository accepts pull requests between branches.
  381. if repo.AllowsPulls() {
  382. ctx.Data["BaseRepo"] = repo
  383. ctx.Repo.PullRequest.BaseRepo = repo
  384. ctx.Repo.PullRequest.Allowed = true
  385. ctx.Repo.PullRequest.SameRepo = true
  386. ctx.Repo.PullRequest.HeadInfo = ctx.Repo.BranchName
  387. }
  388. }
  389. }
  390. ctx.Data["PullRequestCtx"] = ctx.Repo.PullRequest
  391. if ctx.Query("go-get") == "1" {
  392. ctx.Data["GoGetImport"] = ComposeGoGetImport(owner.Name, repo.Name)
  393. prefix := setting.AppURL + path.Join(owner.Name, repo.Name, "src", "branch", ctx.Repo.BranchName)
  394. ctx.Data["GoDocDirectory"] = prefix + "{/dir}"
  395. ctx.Data["GoDocFile"] = prefix + "{/dir}/{file}#L{line}"
  396. }
  397. }
  398. }
  399. // RepoRefType type of repo reference
  400. type RepoRefType int
  401. const (
  402. // RepoRefLegacy unknown type, make educated guess and redirect.
  403. // for backward compatibility with previous URL scheme
  404. RepoRefLegacy RepoRefType = iota
  405. // RepoRefAny is for usage where educated guess is needed
  406. // but redirect can not be made
  407. RepoRefAny
  408. // RepoRefBranch branch
  409. RepoRefBranch
  410. // RepoRefTag tag
  411. RepoRefTag
  412. // RepoRefCommit commit
  413. RepoRefCommit
  414. // RepoRefBlob blob
  415. RepoRefBlob
  416. )
  417. // RepoRef handles repository reference names when the ref name is not
  418. // explicitly given
  419. func RepoRef() macaron.Handler {
  420. // since no ref name is explicitly specified, ok to just use branch
  421. return RepoRefByType(RepoRefBranch)
  422. }
  423. func getRefNameFromPath(ctx *Context, path string, isExist func(string) bool) string {
  424. refName := ""
  425. parts := strings.Split(path, "/")
  426. for i, part := range parts {
  427. refName = strings.TrimPrefix(refName+"/"+part, "/")
  428. if isExist(refName) {
  429. ctx.Repo.TreePath = strings.Join(parts[i+1:], "/")
  430. return refName
  431. }
  432. }
  433. return ""
  434. }
  435. func getRefName(ctx *Context, pathType RepoRefType) string {
  436. path := ctx.Params("*")
  437. switch pathType {
  438. case RepoRefLegacy, RepoRefAny:
  439. if refName := getRefName(ctx, RepoRefBranch); len(refName) > 0 {
  440. return refName
  441. }
  442. if refName := getRefName(ctx, RepoRefTag); len(refName) > 0 {
  443. return refName
  444. }
  445. if refName := getRefName(ctx, RepoRefCommit); len(refName) > 0 {
  446. return refName
  447. }
  448. if refName := getRefName(ctx, RepoRefBlob); len(refName) > 0 {
  449. return refName
  450. }
  451. ctx.Repo.TreePath = path
  452. return ctx.Repo.Repository.DefaultBranch
  453. case RepoRefBranch:
  454. return getRefNameFromPath(ctx, path, ctx.Repo.GitRepo.IsBranchExist)
  455. case RepoRefTag:
  456. return getRefNameFromPath(ctx, path, ctx.Repo.GitRepo.IsTagExist)
  457. case RepoRefCommit:
  458. parts := strings.Split(path, "/")
  459. if len(parts) > 0 && len(parts[0]) == 40 {
  460. ctx.Repo.TreePath = strings.Join(parts[1:], "/")
  461. return parts[0]
  462. }
  463. case RepoRefBlob:
  464. _, err := ctx.Repo.GitRepo.GetBlob(path)
  465. if err != nil {
  466. return ""
  467. }
  468. return path
  469. default:
  470. log.Error(4, "Unrecognized path type: %v", path)
  471. }
  472. return ""
  473. }
  474. // RepoRefByType handles repository reference name for a specific type
  475. // of repository reference
  476. func RepoRefByType(refType RepoRefType) macaron.Handler {
  477. return func(ctx *Context) {
  478. // Empty repository does not have reference information.
  479. if ctx.Repo.Repository.IsEmpty {
  480. return
  481. }
  482. var (
  483. refName string
  484. err error
  485. )
  486. // For API calls.
  487. if ctx.Repo.GitRepo == nil {
  488. repoPath := models.RepoPath(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name)
  489. ctx.Repo.GitRepo, err = git.OpenRepository(repoPath)
  490. if err != nil {
  491. ctx.ServerError("RepoRef Invalid repo "+repoPath, err)
  492. return
  493. }
  494. }
  495. // Get default branch.
  496. if len(ctx.Params("*")) == 0 {
  497. refName = ctx.Repo.Repository.DefaultBranch
  498. ctx.Repo.BranchName = refName
  499. if !ctx.Repo.GitRepo.IsBranchExist(refName) {
  500. brs, err := ctx.Repo.GitRepo.GetBranches()
  501. if err != nil {
  502. ctx.ServerError("GetBranches", err)
  503. return
  504. } else if len(brs) == 0 {
  505. err = fmt.Errorf("No branches in non-empty repository %s",
  506. ctx.Repo.GitRepo.Path)
  507. ctx.ServerError("GetBranches", err)
  508. return
  509. }
  510. refName = brs[0]
  511. }
  512. ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetBranchCommit(refName)
  513. if err != nil {
  514. ctx.ServerError("GetBranchCommit", err)
  515. return
  516. }
  517. ctx.Repo.CommitID = ctx.Repo.Commit.ID.String()
  518. ctx.Repo.IsViewBranch = true
  519. } else {
  520. refName = getRefName(ctx, refType)
  521. ctx.Repo.BranchName = refName
  522. if ctx.Repo.GitRepo.IsBranchExist(refName) {
  523. ctx.Repo.IsViewBranch = true
  524. ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetBranchCommit(refName)
  525. if err != nil {
  526. ctx.ServerError("GetBranchCommit", err)
  527. return
  528. }
  529. ctx.Repo.CommitID = ctx.Repo.Commit.ID.String()
  530. } else if ctx.Repo.GitRepo.IsTagExist(refName) {
  531. ctx.Repo.IsViewTag = true
  532. ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetTagCommit(refName)
  533. if err != nil {
  534. ctx.ServerError("GetTagCommit", err)
  535. return
  536. }
  537. ctx.Repo.CommitID = ctx.Repo.Commit.ID.String()
  538. } else if len(refName) == 40 {
  539. ctx.Repo.IsViewCommit = true
  540. ctx.Repo.CommitID = refName
  541. ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetCommit(refName)
  542. if err != nil {
  543. ctx.NotFound("GetCommit", nil)
  544. return
  545. }
  546. } else {
  547. ctx.NotFound("RepoRef invalid repo", fmt.Errorf("branch or tag not exist: %s", refName))
  548. return
  549. }
  550. if refType == RepoRefLegacy {
  551. // redirect from old URL scheme to new URL scheme
  552. ctx.Redirect(path.Join(
  553. setting.AppSubURL,
  554. strings.TrimSuffix(ctx.Req.URL.Path, ctx.Params("*")),
  555. ctx.Repo.BranchNameSubURL(),
  556. ctx.Repo.TreePath))
  557. return
  558. }
  559. }
  560. ctx.Data["BranchName"] = ctx.Repo.BranchName
  561. ctx.Data["BranchNameSubURL"] = ctx.Repo.BranchNameSubURL()
  562. ctx.Data["CommitID"] = ctx.Repo.CommitID
  563. ctx.Data["TreePath"] = ctx.Repo.TreePath
  564. ctx.Data["IsViewBranch"] = ctx.Repo.IsViewBranch
  565. ctx.Data["IsViewTag"] = ctx.Repo.IsViewTag
  566. ctx.Data["IsViewCommit"] = ctx.Repo.IsViewCommit
  567. ctx.Data["CanCreateBranch"] = ctx.Repo.CanCreateBranch()
  568. ctx.Repo.CommitsCount, err = ctx.Repo.GetCommitsCount()
  569. if err != nil {
  570. ctx.ServerError("GetCommitsCount", err)
  571. return
  572. }
  573. ctx.Data["CommitsCount"] = ctx.Repo.CommitsCount
  574. }
  575. }
  576. // GitHookService checks if repository Git hooks service has been enabled.
  577. func GitHookService() macaron.Handler {
  578. return func(ctx *Context) {
  579. if !ctx.User.CanEditGitHook() {
  580. ctx.NotFound("GitHookService", nil)
  581. return
  582. }
  583. }
  584. }
  585. // UnitTypes returns a macaron middleware to set unit types to context variables.
  586. func UnitTypes() macaron.Handler {
  587. return func(ctx *Context) {
  588. ctx.Data["UnitTypeCode"] = models.UnitTypeCode
  589. ctx.Data["UnitTypeIssues"] = models.UnitTypeIssues
  590. ctx.Data["UnitTypePullRequests"] = models.UnitTypePullRequests
  591. ctx.Data["UnitTypeReleases"] = models.UnitTypeReleases
  592. ctx.Data["UnitTypeWiki"] = models.UnitTypeWiki
  593. ctx.Data["UnitTypeExternalWiki"] = models.UnitTypeExternalWiki
  594. ctx.Data["UnitTypeExternalTracker"] = models.UnitTypeExternalTracker
  595. }
  596. }