From 7c546a921f73d060910c0c222ef515e73a5bd191 Mon Sep 17 00:00:00 2001 From: tjh Date: Wed, 21 May 2025 12:08:22 +0100 Subject: [PATCH] appview: skip fork info query if user is not logged in Prevents a nil dereference in the repo index route if the user is not logged in, and hides the fork-sync button. Fixes: --- appview/pages/pages.go | 2 +- appview/pages/templates/repo/index.html | 2 +- appview/state/repo.go | 6 +++++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/appview/pages/pages.go b/appview/pages/pages.go index 998fbc5e..1f4858a1 100644 --- a/appview/pages/pages.go +++ b/appview/pages/pages.go @@ -410,7 +410,7 @@ type RepoIndexParams struct { CommitsTrunc []*object.Commit TagsTrunc []*types.TagReference BranchesTrunc []types.Branch - ForkInfo types.ForkInfo + ForkInfo *types.ForkInfo types.RepoIndexResponse HTMLReadme template.HTML Raw bool diff --git a/appview/pages/templates/repo/index.html b/appview/pages/templates/repo/index.html index 0b7bc552..99866f96 100644 --- a/appview/pages/templates/repo/index.html +++ b/appview/pages/templates/repo/index.html @@ -66,7 +66,7 @@ {{ end }} - {{ if .ForkInfo.IsFork }} + {{ if and .ForkInfo .ForkInfo.IsFork }} {{ $disabled := "" }} {{ $title := "" }} {{ if eq .ForkInfo.Status 0 }} diff --git a/appview/state/repo.go b/appview/state/repo.go index a7bad731..080e6286 100644 --- a/appview/state/repo.go +++ b/appview/state/repo.go @@ -137,7 +137,7 @@ func (s *State) RepoIndex(w http.ResponseWriter, r *http.Request) { RepoIndexResponse: result, CommitsTrunc: commitsTrunc, TagsTrunc: tagsTrunc, - ForkInfo: *forkInfo, + ForkInfo: forkInfo, BranchesTrunc: branchesTrunc, EmailToDidOrHandle: EmailToDidOrHandle(s, emails), }) @@ -151,6 +151,10 @@ func getForkInfo( w http.ResponseWriter, user *oauth.User, ) (*types.ForkInfo, error) { + if user == nil { + return nil, nil + } + forkInfo := types.ForkInfo{ IsFork: repoInfo.Source != nil, Status: types.UpToDate, -- 2.51.2