Signed-off-by: Seongmin Lee git@boltless.me
+9
-4
appview/issues/issues.go
+9
-4
appview/issues/issues.go
···
312
312
// notify about the issue closure
313
313
rp.notifier.NewIssueState(r.Context(), syntax.DID(user.Did), issue)
314
314
315
-
rp.pages.HxLocation(w, fmt.Sprintf("/%s/issues/%d", f.OwnerSlashRepo(), issue.IssueId))
315
+
ownerSlashRepo := rp.repoResolver.GetBaseRepoPath(r, &f.Repo)
316
+
rp.pages.HxLocation(w, fmt.Sprintf("/%s/issues/%d", ownerSlashRepo, issue.IssueId))
316
317
return
317
318
} else {
318
319
l.Error("user is not permitted to close issue")
···
362
363
// notify about the issue reopen
363
364
rp.notifier.NewIssueState(r.Context(), syntax.DID(user.Did), issue)
364
365
365
-
rp.pages.HxLocation(w, fmt.Sprintf("/%s/issues/%d", f.OwnerSlashRepo(), issue.IssueId))
366
+
ownerSlashRepo := rp.repoResolver.GetBaseRepoPath(r, &f.Repo)
367
+
rp.pages.HxLocation(w, fmt.Sprintf("/%s/issues/%d", ownerSlashRepo, issue.IssueId))
366
368
return
367
369
} else {
368
370
l.Error("user is not the owner of the repo")
···
466
468
}
467
469
rp.notifier.NewIssueComment(r.Context(), &comment, mentions)
468
470
469
-
rp.pages.HxLocation(w, fmt.Sprintf("/%s/issues/%d#comment-%d", f.OwnerSlashRepo(), issue.IssueId, commentId))
471
+
ownerSlashRepo := rp.repoResolver.GetBaseRepoPath(r, &f.Repo)
472
+
rp.pages.HxLocation(w, fmt.Sprintf("/%s/issues/%d#comment-%d", ownerSlashRepo, issue.IssueId, commentId))
470
473
}
471
474
472
475
func (rp *Issues) IssueComment(w http.ResponseWriter, r *http.Request) {
···
970
973
}
971
974
}
972
975
rp.notifier.NewIssue(r.Context(), issue, mentions)
973
-
rp.pages.HxLocation(w, fmt.Sprintf("/%s/issues/%d", f.OwnerSlashRepo(), issue.IssueId))
976
+
977
+
ownerSlashRepo := rp.repoResolver.GetBaseRepoPath(r, &f.Repo)
978
+
rp.pages.HxLocation(w, fmt.Sprintf("/%s/issues/%d", ownerSlashRepo, issue.IssueId))
974
979
return
975
980
}
976
981
}
+2
-2
appview/middleware/middleware.go
+2
-2
appview/middleware/middleware.go
···
164
164
ok, err := mw.enforcer.E.Enforce(actor.Did, f.Knot, f.DidSlashRepo(), requiredPerm)
165
165
if err != nil || !ok {
166
166
// we need a logged in user
167
-
log.Printf("%s does not have perms of a %s in repo %s", actor.Did, requiredPerm, f.OwnerSlashRepo())
167
+
log.Printf("%s does not have perms of a %s in repo %s", actor.Did, requiredPerm, f.DidSlashRepo())
168
168
http.Error(w, "Forbiden", http.StatusUnauthorized)
169
169
return
170
170
}
···
327
327
return
328
328
}
329
329
330
-
fullName := f.OwnerHandle() + "/" + f.Name
330
+
fullName := mw.repoResolver.GetBaseRepoPath(r, &f.Repo)
331
331
332
332
if r.Header.Get("User-Agent") == "Go-http-client/1.1" {
333
333
if r.URL.Query().Get("go-get") == "1" {
+2
-2
appview/pages/repoinfo/repoinfo.go
+2
-2
appview/pages/repoinfo/repoinfo.go
···
21
21
return path.Join(r.owner(), r.Name)
22
22
}
23
23
24
-
func (r RepoInfo) OwnerWithoutAt() string {
24
+
func (r RepoInfo) ownerWithoutAt() string {
25
25
if r.OwnerHandle != "" {
26
26
return r.OwnerHandle
27
27
} else {
···
30
30
}
31
31
32
32
func (r RepoInfo) FullNameWithoutAt() string {
33
-
return path.Join(r.OwnerWithoutAt(), r.Name)
33
+
return path.Join(r.ownerWithoutAt(), r.Name)
34
34
}
35
35
36
36
func (r RepoInfo) GetTabs() [][]string {
+16
-8
appview/pulls/pulls.go
+16
-8
appview/pulls/pulls.go
···
800
800
}
801
801
s.notifier.NewPullComment(r.Context(), comment, mentions)
802
802
803
-
s.pages.HxLocation(w, fmt.Sprintf("/%s/pulls/%d#comment-%d", f.OwnerSlashRepo(), pull.PullId, commentId))
803
+
ownerSlashRepo := s.repoResolver.GetBaseRepoPath(r, &f.Repo)
804
+
s.pages.HxLocation(w, fmt.Sprintf("/%s/pulls/%d#comment-%d", ownerSlashRepo, pull.PullId, commentId))
804
805
return
805
806
}
806
807
}
···
1271
1272
1272
1273
s.notifier.NewPull(r.Context(), pull)
1273
1274
1274
-
s.pages.HxLocation(w, fmt.Sprintf("/%s/pulls/%d", f.OwnerSlashRepo(), pullId))
1275
+
ownerSlashRepo := s.repoResolver.GetBaseRepoPath(r, &f.Repo)
1276
+
s.pages.HxLocation(w, fmt.Sprintf("/%s/pulls/%d", ownerSlashRepo, pullId))
1275
1277
}
1276
1278
1277
1279
func (s *Pulls) createStackedPullRequest(
···
1372
1374
return
1373
1375
}
1374
1376
1375
-
s.pages.HxLocation(w, fmt.Sprintf("/%s/pulls", f.OwnerSlashRepo()))
1377
+
ownerSlashRepo := s.repoResolver.GetBaseRepoPath(r, &f.Repo)
1378
+
s.pages.HxLocation(w, fmt.Sprintf("/%s/pulls", ownerSlashRepo))
1376
1379
}
1377
1380
1378
1381
func (s *Pulls) ValidatePatch(w http.ResponseWriter, r *http.Request) {
···
1920
1923
return
1921
1924
}
1922
1925
1923
-
s.pages.HxLocation(w, fmt.Sprintf("/%s/pulls/%d", f.OwnerSlashRepo(), pull.PullId))
1926
+
ownerSlashRepo := s.repoResolver.GetBaseRepoPath(r, &f.Repo)
1927
+
s.pages.HxLocation(w, fmt.Sprintf("/%s/pulls/%d", ownerSlashRepo, pull.PullId))
1924
1928
}
1925
1929
1926
1930
func (s *Pulls) resubmitStackedPullHelper(
···
2113
2117
return
2114
2118
}
2115
2119
2116
-
s.pages.HxLocation(w, fmt.Sprintf("/%s/pulls/%d", f.OwnerSlashRepo(), pull.PullId))
2120
+
ownerSlashRepo := s.repoResolver.GetBaseRepoPath(r, &f.Repo)
2121
+
s.pages.HxLocation(w, fmt.Sprintf("/%s/pulls/%d", ownerSlashRepo, pull.PullId))
2117
2122
}
2118
2123
2119
2124
func (s *Pulls) MergePull(w http.ResponseWriter, r *http.Request) {
···
2231
2236
s.notifier.NewPullState(r.Context(), syntax.DID(user.Did), p)
2232
2237
}
2233
2238
2234
-
s.pages.HxLocation(w, fmt.Sprintf("/@%s/%s/pulls/%d", f.OwnerHandle(), f.Name, pull.PullId))
2239
+
ownerSlashRepo := s.repoResolver.GetBaseRepoPath(r, &f.Repo)
2240
+
s.pages.HxLocation(w, fmt.Sprintf("/%s/pulls/%d", ownerSlashRepo, pull.PullId))
2235
2241
}
2236
2242
2237
2243
func (s *Pulls) ClosePull(w http.ResponseWriter, r *http.Request) {
···
2303
2309
s.notifier.NewPullState(r.Context(), syntax.DID(user.Did), p)
2304
2310
}
2305
2311
2306
-
s.pages.HxLocation(w, fmt.Sprintf("/%s/pulls/%d", f.OwnerSlashRepo(), pull.PullId))
2312
+
ownerSlashRepo := s.repoResolver.GetBaseRepoPath(r, &f.Repo)
2313
+
s.pages.HxLocation(w, fmt.Sprintf("/%s/pulls/%d", ownerSlashRepo, pull.PullId))
2307
2314
}
2308
2315
2309
2316
func (s *Pulls) ReopenPull(w http.ResponseWriter, r *http.Request) {
···
2376
2383
s.notifier.NewPullState(r.Context(), syntax.DID(user.Did), p)
2377
2384
}
2378
2385
2379
-
s.pages.HxLocation(w, fmt.Sprintf("/%s/pulls/%d", f.OwnerSlashRepo(), pull.PullId))
2386
+
ownerSlashRepo := s.repoResolver.GetBaseRepoPath(r, &f.Repo)
2387
+
s.pages.HxLocation(w, fmt.Sprintf("/%s/pulls/%d", ownerSlashRepo, pull.PullId))
2380
2388
}
2381
2389
2382
2390
func newStack(f *reporesolver.ResolvedRepo, user *oauth.User, targetBranch, patch string, pullSource *models.PullSource, stackId string) (models.Stack, error) {
+3
-1
appview/repo/blob.go
+3
-1
appview/repo/blob.go
···
62
62
return
63
63
}
64
64
65
+
ownerSlashRepo := rp.repoResolver.GetBaseRepoPath(r, &f.Repo)
66
+
65
67
// Use XRPC response directly instead of converting to internal types
66
68
var breadcrumbs [][]string
67
-
breadcrumbs = append(breadcrumbs, []string{f.Name, fmt.Sprintf("/%s/tree/%s", f.OwnerSlashRepo(), url.PathEscape(ref))})
69
+
breadcrumbs = append(breadcrumbs, []string{f.Name, fmt.Sprintf("/%s/tree/%s", ownerSlashRepo, url.PathEscape(ref))})
68
70
if filePath != "" {
69
71
for idx, elem := range strings.Split(filePath, "/") {
70
72
breadcrumbs = append(breadcrumbs, []string{elem, fmt.Sprintf("%s/%s", breadcrumbs[idx][1], url.PathEscape(elem))})
+3
-2
appview/repo/tree.go
+3
-2
appview/repo/tree.go
···
79
79
result.ReadmeFileName = xrpcResp.Readme.Filename
80
80
result.Readme = xrpcResp.Readme.Contents
81
81
}
82
+
ownerSlashRepo := rp.repoResolver.GetBaseRepoPath(r, &f.Repo)
82
83
// redirects tree paths trying to access a blob; in this case the result.Files is unpopulated,
83
84
// so we can safely redirect to the "parent" (which is the same file).
84
85
if len(result.Files) == 0 && result.Parent == treePath {
85
-
redirectTo := fmt.Sprintf("/%s/blob/%s/%s", f.OwnerSlashRepo(), url.PathEscape(ref), result.Parent)
86
+
redirectTo := fmt.Sprintf("/%s/blob/%s/%s", ownerSlashRepo, url.PathEscape(ref), result.Parent)
86
87
http.Redirect(w, r, redirectTo, http.StatusFound)
87
88
return
88
89
}
89
90
user := rp.oauth.GetUser(r)
90
91
var breadcrumbs [][]string
91
-
breadcrumbs = append(breadcrumbs, []string{f.Name, fmt.Sprintf("/%s/tree/%s", f.OwnerSlashRepo(), url.PathEscape(ref))})
92
+
breadcrumbs = append(breadcrumbs, []string{f.Name, fmt.Sprintf("/%s/tree/%s", ownerSlashRepo, url.PathEscape(ref))})
92
93
if treePath != "" {
93
94
for idx, elem := range strings.Split(treePath, "/") {
94
95
breadcrumbs = append(breadcrumbs, []string{elem, fmt.Sprintf("%s/%s", breadcrumbs[idx][1], url.PathEscape(elem))})
+12
appview/reporesolver/resolver.go
+12
appview/reporesolver/resolver.go
···
44
44
return &RepoResolver{config: config, enforcer: enforcer, idResolver: resolver, execer: execer}
45
45
}
46
46
47
+
// NOTE: this... should not even be here. the entire package will be removed in future refactor
48
+
func (rr *RepoResolver) GetBaseRepoPath(r *http.Request, repo *models.Repo) string {
49
+
var (
50
+
user = chi.URLParam(r, "user")
51
+
name = chi.URLParam(r, "repo")
52
+
)
53
+
if user == "" || name == "" {
54
+
return repo.DidSlashRepo()
55
+
}
56
+
return path.Join(user, name)
57
+
}
58
+
47
59
func (rr *RepoResolver) Resolve(r *http.Request) (*ResolvedRepo, error) {
48
60
repo, ok := r.Context().Value("repo").(*models.Repo)
49
61
if !ok {