forked from tangled.org/core
this repo has no description

appview: repo: better support for empty repos

empty repo template now shows a list of other branches if available

Changed files
+52 -40
appview
pages
state
+1 -2
appview/pages/pages.go
···
RepoInfo repoinfo.RepoInfo
Collaborators []Collaborator
Active string
-
Branches []string
-
DefaultBranch string
+
Branches []types.Branch
// TODO: use repoinfo.roles
IsCollaboratorInviteAllowed bool
}
+21 -3
appview/pages/templates/repo/empty.html
···
{{ end }}
{{ define "repoContent" }}
-
<main>
+
<main>
+
{{ if gt (len .BranchesTrunc) 0 }}
+
<div class="flex flex-col items-center">
<p class="text-center pt-5 text-gray-400 dark:text-gray-500">
-
This is an empty repository. Push some commits here.
+
This branch is empty. Other branches in this repository are populated:
</p>
-
</main>
+
<div class="mt-4 grid grid-cols-1 divide-y divide-gray-200 dark:divide-gray-700 rounded border border-gray-200 dark:border-gray-700 w-full md:w-1/2">
+
{{ range $br := .BranchesTrunc }}
+
<a href="/{{ $.RepoInfo.FullName }}/tree/{{$br.Name}}" class="no-underline hover:no-underline">
+
<div class="flex items-center justify-between p-2">
+
{{ $br.Name }}
+
<time class="text-gray-500 dark:text-gray-400">{{ timeFmt $br.Commit.Author.When }}</time>
+
</div>
+
</a>
+
{{ end }}
+
</div>
+
</div>
+
{{ else }}
+
<p class="text-center pt-5 text-gray-400 dark:text-gray-500">
+
This is an empty repository. Push some commits here.
+
</p>
+
{{ end }}
+
</main>
{{ end }}
{{ define "repoAfter" }}
+11 -4
appview/pages/templates/repo/settings.html
···
<label for="branch">default branch</label>
<div class="flex gap-2 items-center">
<select id="branch" name="branch" required class="p-1 border border-gray-200 bg-white dark:bg-gray-800 dark:text-white dark:border-gray-700">
+
<option
+
value=""
+
disabled
+
selected
+
>
+
Choose a default branch
+
</option>
{{ range .Branches }}
<option
-
value="{{ . }}"
+
value="{{ .Name }}"
class="py-1"
-
{{ if eq . $.DefaultBranch }}
+
{{ if .IsDefault }}
selected
{{ end }}
>
-
{{ . }}
+
{{ .Name }}
</option>
{{ end }}
</select>
-
<button class="btn my-2 flex gap-2 items-center" type="text">
+
<button class="btn my-2 flex gap-2 items-center" type="submit">
<span>save</span>
{{ i "loader-circle" "w-4 h-4 animate-spin hidden group-[.htmx-request]:inline" }}
</button>
+19 -31
appview/state/repo.go
···
}
}
-
var branchNames []string
-
var defaultBranch string
us, err := knotclient.NewUnsignedClient(f.Knot, s.config.Core.Dev)
if err != nil {
log.Println("failed to create unsigned client", err)
-
} else {
-
resp, err := us.Branches(f.OwnerDid(), f.RepoName)
-
if err != nil {
-
log.Println("failed to reach knotserver", err)
-
} else {
-
defer resp.Body.Close()
+
return
+
}
-
body, err := io.ReadAll(resp.Body)
-
if err != nil {
-
log.Printf("Error reading response body: %v", err)
-
} else {
-
var result types.RepoBranchesResponse
-
err = json.Unmarshal(body, &result)
-
if err != nil {
-
log.Println("failed to parse response:", err)
-
} else {
-
for _, branch := range result.Branches {
-
branchNames = append(branchNames, branch.Name)
-
}
-
}
-
}
-
}
+
resp, err := us.Branches(f.OwnerDid(), f.RepoName)
+
if err != nil {
+
log.Println("failed to reach knotserver", err)
+
return
+
}
+
defer resp.Body.Close()
-
defaultBranchResp, err := us.DefaultBranch(f.OwnerDid(), f.RepoName)
-
if err != nil {
-
log.Println("failed to reach knotserver", err)
-
} else {
-
defaultBranch = defaultBranchResp.Branch
-
}
+
body, err := io.ReadAll(resp.Body)
+
if err != nil {
+
log.Printf("Error reading response body: %v", err)
+
}
+
+
var result types.RepoBranchesResponse
+
err = json.Unmarshal(body, &result)
+
if err != nil {
+
log.Println("failed to parse response:", err)
+
s.pages.RepoSettings(w, pages.RepoSettingsParams{
LoggedInUser: user,
RepoInfo: f.RepoInfo(s, user),
Collaborators: repoCollaborators,
IsCollaboratorInviteAllowed: isCollaboratorInviteAllowed,
-
Branches: branchNames,
-
DefaultBranch: defaultBranch,
+
Branches: result.Branches,
})