Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix API raw requests for commits and tags #2841

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions modules/context/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,9 @@ const (
// RepoRefLegacy unknown type, make educated guess and redirect.
// for backward compatibility with previous URL scheme
RepoRefLegacy RepoRefType = iota
// RepoRefAPI is for usage in API where educated guess is needed
// but redirect can not be made
RepoRefAPI
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: rename to make behavior more obvious, perhaps RepoRefAny?

// RepoRefBranch branch
RepoRefBranch
// RepoRefTag tag
Expand Down Expand Up @@ -497,6 +500,8 @@ func getRefNameFromPath(ctx *Context, path string, isExist func(string) bool) st
func getRefName(ctx *Context, pathType RepoRefType) string {
path := ctx.Params("*")
switch pathType {
case RepoRefAPI:
fallthrough
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is not this same as case RepoRefLegacy, RepoRefAPI:? That means you don't need RepoRefAPI.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you do; see line 623

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ethantkoenig Thx, got it. case RepoRefLegacy, RepoRefAPI: can be used anyway.

case RepoRefLegacy:
if refName := getRefName(ctx, RepoRefBranch); len(refName) > 0 {
return refName
Expand Down
2 changes: 1 addition & 1 deletion routers/api/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ func RegisterRoutes(m *macaron.Macaron) {
Put(bind(api.AddCollaboratorOption{}), repo.AddCollaborator).
Delete(repo.DeleteCollaborator)
}, reqToken())
m.Get("/raw/*", context.RepoRef(), repo.GetRawFile)
m.Get("/raw/*", context.RepoRefByType(context.RepoRefAPI), repo.GetRawFile)
m.Get("/archive/*", repo.GetArchive)
m.Combo("/forks").Get(repo.ListForks).
Post(reqToken(), bind(api.CreateForkOption{}), repo.CreateFork)
Expand Down