@ -11,6 +11,7 @@ import (
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/perm"
"code.gitea.io/gitea/models/unit"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/metrics"
"code.gitea.io/gitea/modules/public"
@ -817,7 +818,6 @@ func registerRoutes(m *web.Router) {
reqRepoAdmin := context . RequireRepoAdmin ( )
reqRepoCodeWriter := context . RequireUnitWriter ( unit . TypeCode )
canEnableEditor := context . CanEnableEditor ( )
reqRepoReleaseWriter := context . RequireUnitWriter ( unit . TypeReleases )
reqRepoReleaseReader := context . RequireUnitReader ( unit . TypeReleases )
reqRepoIssuesOrPullsWriter := context . RequireUnitWriter ( unit . TypeIssues , unit . TypePullRequests )
@ -1152,16 +1152,16 @@ func registerRoutes(m *web.Router) {
// end "/{username}/{reponame}/settings"
// user/org home, including rss feeds
m . Get ( "/{username}/{reponame}" , optSignIn , context . RepoAssignment , context . RepoRef ( ) , repo . SetEditorconfigIfExists , repo . Home )
m . Get ( "/{username}/{reponame}" , optSignIn , context . RepoAssignment , context . RepoRef ByType ( git . RefTypeBranch ) , repo . SetEditorconfigIfExists , repo . Home )
m . Post ( "/{username}/{reponame}/markup" , optSignIn , context . RepoAssignment , reqUnitsWithMarkdown , web . Bind ( structs . MarkupOption { } ) , misc . Markup )
m . Group ( "/{username}/{reponame}" , func ( ) {
m . Get ( "/find/*" , repo . FindFiles )
m . Group ( "/tree-list" , func ( ) {
m . Get ( "/branch/*" , context . RepoRefByType ( context. RepoRef Branch) , repo . TreeList )
m . Get ( "/tag/*" , context . RepoRefByType ( context. RepoRef Tag) , repo . TreeList )
m . Get ( "/commit/*" , context . RepoRefByType ( context. RepoRef Commit) , repo . TreeList )
m . Get ( "/branch/*" , context . RepoRefByType ( git. RefType Branch) , repo . TreeList )
m . Get ( "/tag/*" , context . RepoRefByType ( git. RefType Tag) , repo . TreeList )
m . Get ( "/commit/*" , context . RepoRefByType ( git. RefType Commit) , repo . TreeList )
} )
m . Get ( "/compare" , repo . MustBeNotEmpty , repo . SetEditorconfigIfExists , repo . SetDiffViewStyle , repo . SetWhitespaceBehavior , repo . CompareDiff )
m . Combo ( "/compare/*" , repo . MustBeNotEmpty , repo . SetEditorconfigIfExists ) .
@ -1306,18 +1306,18 @@ func registerRoutes(m *web.Router) {
Post ( web . Bind ( forms . EditRepoFileForm { } ) , repo . NewDiffPatchPost )
m . Combo ( "/_cherrypick/{sha:([a-f0-9]{7,64})}/*" ) . Get ( repo . CherryPick ) .
Post ( web . Bind ( forms . CherryPickForm { } ) , repo . CherryPickPost )
} , repo. MustBeEditable )
} , context. RepoRefByType ( git . RefTypeBranch ) , context . CanWriteToBranch ( ) )
m . Group ( "" , func ( ) {
m . Post ( "/upload-file" , repo . UploadFileToServer )
m . Post ( "/upload-remove" , web . Bind ( forms . RemoveUploadFileForm { } ) , repo . RemoveUploadFileFromServer )
} , repo . MustBe Editable, repo . MustBeAbleToUpload )
} , context. RepoRef ( ) , canEnableEditor , context . RepoMustNotBeArchived ( ) )
} , repo . MustBe AbleToUpload, reqRepoCodeWriter )
} , repo. MustBeEditable , context . RepoMustNotBeArchived ( ) )
m . Group ( "/branches" , func ( ) {
m . Group ( "/_new" , func ( ) {
m . Post ( "/branch/*" , context . RepoRefByType ( context. RepoRef Branch) , repo . CreateBranch )
m . Post ( "/tag/*" , context . RepoRefByType ( context. RepoRef Tag) , repo . CreateBranch )
m . Post ( "/commit/*" , context . RepoRefByType ( context. RepoRef Commit) , repo . CreateBranch )
m . Post ( "/branch/*" , context . RepoRefByType ( git. RefType Branch) , repo . CreateBranch )
m . Post ( "/tag/*" , context . RepoRefByType ( git. RefType Tag) , repo . CreateBranch )
m . Post ( "/commit/*" , context . RepoRefByType ( git. RefType Commit) , repo . CreateBranch )
} , web . Bind ( forms . NewBranchForm { } ) )
m . Post ( "/delete" , repo . DeleteBranchPost )
m . Post ( "/restore" , repo . RestoreBranchPost )
@ -1332,39 +1332,36 @@ func registerRoutes(m *web.Router) {
m . Group ( "/{username}/{reponame}" , func ( ) { // repo tags
m . Group ( "/tags" , func ( ) {
m . Get ( "" , repo . TagsList )
m . Get ( "/list" , repo . GetTagList )
m . Get ( ".rss" , feedEnabled , repo . TagsListFeedRSS )
m . Get ( ".atom" , feedEnabled , repo . TagsListFeedAtom )
} , ctxDataSet ( "EnableFeed" , setting . Other . EnableFeed ) ,
repo . MustBeNotEmpty , context . RepoRefByType ( context . RepoRefTag , context . RepoRefByTypeOptions { IgnoreNotExistErr : true } ) )
m . Post ( "/tags/delete" , repo . DeleteTag , reqSignIn ,
repo . MustBeNotEmpty , context . RepoMustNotBeArchived ( ) , reqRepoCodeWriter , context . RepoRef ( ) )
} , optSignIn , context . RepoAssignment , reqUnitCodeReader )
m . Get ( "/list" , repo . GetTagList )
} , ctxDataSet ( "EnableFeed" , setting . Other . EnableFeed ) )
m . Post ( "/tags/delete" , reqSignIn , reqRepoCodeWriter , context . RepoMustNotBeArchived ( ) , repo . DeleteTag )
} , optSignIn , context . RepoAssignment , repo . MustBeNotEmpty , reqUnitCodeReader )
// end "/{username}/{reponame}": repo tags
m . Group ( "/{username}/{reponame}" , func ( ) { // repo releases
m . Group ( "/releases" , func ( ) {
m . Get ( "" , repo . Releases )
m . Get ( "/tag/*" , repo . SingleRelease )
m . Get ( "/latest" , repo . LatestRelease )
m . Get ( ".rss" , feedEnabled , repo . ReleasesFeedRSS )
m . Get ( ".atom" , feedEnabled , repo . ReleasesFeedAtom )
} , ctxDataSet ( "EnableFeed" , setting . Other . EnableFeed ) ,
repo . MustBeNotEmpty , context . RepoRefByType ( context . RepoRefTag , context . RepoRefByTypeOptions { IgnoreNotExistErr : true } ) )
m . Get ( "/releases/attachments/{uuid}" , repo . MustBeNotEmpty , repo . GetAttachment )
m . Get ( "/releases/download/{vTag}/{fileName}" , repo . MustBeNotEmpty , repo . RedirectDownload )
m . Get ( "/tag/*" , repo . SingleRelease )
m . Get ( "/latest" , repo . LatestRelease )
} , ctxDataSet ( "EnableFeed" , setting . Other . EnableFeed ) )
m . Get ( "/releases/attachments/{uuid}" , repo . GetAttachment )
m . Get ( "/releases/download/{vTag}/{fileName}" , repo . RedirectDownload )
m . Group ( "/releases" , func ( ) {
m . Get ( "/new" , repo . NewRelease )
m . Post ( "/new" , web . Bind ( forms . NewReleaseForm { } ) , repo . NewReleasePost )
m . Post ( "/delete" , repo . DeleteRelease )
m . Post ( "/attachments" , repo . UploadReleaseAttachment )
m . Post ( "/attachments/remove" , repo . DeleteAttachment )
} , reqSignIn , repo. MustBeNotEmpty , context. RepoMustNotBeArchived ( ) , reqRepoReleaseWriter , context . RepoRef ( ) )
} , reqSignIn , context. RepoMustNotBeArchived ( ) , reqRepoReleaseWriter , context . RepoRef ( ) )
m . Group ( "/releases" , func ( ) {
m . Get ( "/edit/*" , repo . EditRelease )
m . Post ( "/edit/*" , web . Bind ( forms . EditReleaseForm { } ) , repo . EditReleasePost )
} , reqSignIn , repo. MustBeNotEmpty , context. RepoMustNotBeArchived ( ) , reqRepoReleaseWriter , repo . CommitInfoCache )
} , optSignIn , context . RepoAssignment , re qRepoReleaseReader)
} , reqSignIn , context. RepoMustNotBeArchived ( ) , reqRepoReleaseWriter , repo . CommitInfoCache )
} , optSignIn , context . RepoAssignment , re po. MustBeNotEmpty , re qRepoReleaseReader)
// end "/{username}/{reponame}": repo releases
m . Group ( "/{username}/{reponame}" , func ( ) { // to maintain compatibility with old attachments
@ -1528,42 +1525,39 @@ func registerRoutes(m *web.Router) {
} , repo . MustBeNotEmpty , context . RepoRef ( ) )
m . Group ( "/media" , func ( ) {
m . Get ( "/branch/*" , context . RepoRefByType ( context . RepoRefBranch ) , repo . SingleDownloadOrLFS )
m . Get ( "/tag/*" , context . RepoRefByType ( context . RepoRefTag ) , repo . SingleDownloadOrLFS )
m . Get ( "/commit/*" , context . RepoRefByType ( context . RepoRefCommit ) , repo . SingleDownloadOrLFS )
m . Get ( "/blob/{sha}" , repo . DownloadByIDOrLFS )
// "/*" route is deprecated, and kept for backward compatibility
m . Get ( "/*" , context . RepoRefByType ( context . RepoRefUnknown ) , repo . SingleDownloadOrLFS )
m . Get ( "/branch/*" , context . RepoRefByType ( git . RefTypeBranch ) , repo . SingleDownloadOrLFS )
m . Get ( "/tag/*" , context . RepoRefByType ( git . RefTypeTag ) , repo . SingleDownloadOrLFS )
m . Get ( "/commit/*" , context . RepoRefByType ( git . RefTypeCommit ) , repo . SingleDownloadOrLFS )
m . Get ( "/*" , context . RepoRefByType ( "" ) , repo . SingleDownloadOrLFS ) // "/*" route is deprecated, and kept for backward compatibility
} , repo . MustBeNotEmpty )
m . Group ( "/raw" , func ( ) {
m . Get ( "/branch/*" , context . RepoRefByType ( context . RepoRefBranch ) , repo . SingleDownload )
m . Get ( "/tag/*" , context . RepoRefByType ( context . RepoRefTag ) , repo . SingleDownload )
m . Get ( "/commit/*" , context . RepoRefByType ( context . RepoRefCommit ) , repo . SingleDownload )
m . Get ( "/blob/{sha}" , repo . DownloadByID )
// "/*" route is deprecated, and kept for backward compatibility
m . Get ( "/*" , context . RepoRefByType ( context . RepoRefUnknown ) , repo . SingleDownload )
m . Get ( "/branch/*" , context . RepoRefByType ( git . RefTypeBranch ) , repo . SingleDownload )
m . Get ( "/tag/*" , context . RepoRefByType ( git . RefTypeTag ) , repo . SingleDownload )
m . Get ( "/commit/*" , context . RepoRefByType ( git . RefTypeCommit ) , repo . SingleDownload )
m . Get ( "/*" , context . RepoRefByType ( "" ) , repo . SingleDownload ) // "/*" route is deprecated, and kept for backward compatibility
} , repo . MustBeNotEmpty )
m . Group ( "/render" , func ( ) {
m . Get ( "/branch/*" , context . RepoRefByType ( context. RepoRef Branch) , repo . RenderFile )
m . Get ( "/tag/*" , context . RepoRefByType ( context. RepoRef Tag) , repo . RenderFile )
m . Get ( "/commit/*" , context . RepoRefByType ( context. RepoRef Commit) , repo . RenderFile )
m . Get ( "/branch/*" , context . RepoRefByType ( git. RefType Branch) , repo . RenderFile )
m . Get ( "/tag/*" , context . RepoRefByType ( git. RefType Tag) , repo . RenderFile )
m . Get ( "/commit/*" , context . RepoRefByType ( git. RefType Commit) , repo . RenderFile )
m . Get ( "/blob/{sha}" , repo . RenderFile )
} , repo . MustBeNotEmpty )
m . Group ( "/commits" , func ( ) {
m . Get ( "/branch/*" , context . RepoRefByType ( context . RepoRefBranch ) , repo . RefCommits )
m . Get ( "/tag/*" , context . RepoRefByType ( context . RepoRefTag ) , repo . RefCommits )
m . Get ( "/commit/*" , context . RepoRefByType ( context . RepoRefCommit ) , repo . RefCommits )
// "/*" route is deprecated, and kept for backward compatibility
m . Get ( "/*" , context . RepoRefByType ( context . RepoRefUnknown ) , repo . RefCommits )
m . Get ( "/branch/*" , context . RepoRefByType ( git . RefTypeBranch ) , repo . RefCommits )
m . Get ( "/tag/*" , context . RepoRefByType ( git . RefTypeTag ) , repo . RefCommits )
m . Get ( "/commit/*" , context . RepoRefByType ( git . RefTypeCommit ) , repo . RefCommits )
m . Get ( "/*" , context . RepoRefByType ( "" ) , repo . RefCommits ) // "/*" route is deprecated, and kept for backward compatibility
} , repo . MustBeNotEmpty )
m . Group ( "/blame" , func ( ) {
m . Get ( "/branch/*" , context . RepoRefByType ( context. RepoRef Branch) , repo . RefBlame )
m . Get ( "/tag/*" , context . RepoRefByType ( context. RepoRef Tag) , repo . RefBlame )
m . Get ( "/commit/*" , context . RepoRefByType ( context. RepoRef Commit) , repo . RefBlame )
m . Get ( "/branch/*" , context . RepoRefByType ( git. RefType Branch) , repo . RefBlame )
m . Get ( "/tag/*" , context . RepoRefByType ( git. RefType Tag) , repo . RefBlame )
m . Get ( "/commit/*" , context . RepoRefByType ( git. RefType Commit) , repo . RefBlame )
} , repo . MustBeNotEmpty )
m . Get ( "/blob_excerpt/{sha}" , repo . SetEditorconfigIfExists , repo . SetDiffViewStyle , repo . ExcerptBlob )
@ -1575,20 +1569,20 @@ func registerRoutes(m *web.Router) {
m . Get ( "/cherry-pick/{sha:([a-f0-9]{7,64})$}" , repo . SetEditorconfigIfExists , repo . CherryPick )
} , repo . MustBeNotEmpty , context . RepoRef ( ) )
m . Get ( "/rss/branch/*" , context . RepoRefByType ( context. RepoRef Branch) , feedEnabled , feed . RenderBranchFeed )
m . Get ( "/atom/branch/*" , context . RepoRefByType ( context. RepoRef Branch) , feedEnabled , feed . RenderBranchFeed )
m . Get ( "/rss/branch/*" , context . RepoRefByType ( git. RefType Branch) , feedEnabled , feed . RenderBranchFeed )
m . Get ( "/atom/branch/*" , context . RepoRefByType ( git. RefType Branch) , feedEnabled , feed . RenderBranchFeed )
m . Group ( "/src" , func ( ) {
m . Get ( "" , func ( ctx * context . Context ) { ctx . Redirect ( ctx . Repo . RepoLink ) } ) // there is no "{owner}/{repo}/src" page, so redirect to "{owner}/{repo}" to avoid 404
m . Get ( "/branch/*" , context . RepoRefByType ( context. RepoRef Branch) , repo . Home )
m . Get ( "/tag/*" , context . RepoRefByType ( context. RepoRef Tag) , repo . Home )
m . Get ( "/commit/*" , context . RepoRefByType ( context. RepoRef Commit) , repo . Home )
m . Get ( "/*" , context . RepoRefByType ( context . RepoRefUnknown ) , repo . Home ) // "/*" route is deprecated, and kept for backward compatibility
m . Get ( "/branch/*" , context . RepoRefByType ( git. RefType Branch) , repo . Home )
m . Get ( "/tag/*" , context . RepoRefByType ( git. RefType Tag) , repo . Home )
m . Get ( "/commit/*" , context . RepoRefByType ( git. RefType Commit) , repo . Home )
m . Get ( "/*" , context . RepoRefByType ( "" ) , repo . Home ) // "/*" route is deprecated, and kept for backward compatibility
} , repo . SetEditorconfigIfExists )
m . Get ( "/forks" , context . RepoRef ( ) , repo . Forks )
m . Get ( "/commit/{sha:([a-f0-9]{7,64})}.{ext:patch|diff}" , repo . MustBeNotEmpty , repo . RawDiff )
m . Post ( "/lastcommit/*" , context . RepoRefByType ( context. RepoRef Commit) , repo . LastCommit )
m . Post ( "/lastcommit/*" , context . RepoRefByType ( git. RefType Commit) , repo . LastCommit )
} , optSignIn , context . RepoAssignment , reqUnitCodeReader )
// end "/{username}/{reponame}": repo code