Phase 5 part 1: read a site's section types and pages
Sites → Sections and pages reads the website's Hugo repository: each section type with the README's description, the fields in use and the layout's, the pages using it and a real example; the pages and their sections; the latest commits. Working copies are now held by one job at a time. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -475,10 +475,11 @@ func (ap *Applier) ApplyBrief(ctx context.Context, d *db.DB, id int64, confirmed
|
||||
}
|
||||
|
||||
func (ap *Applier) applyBrief(ctx context.Context, d *db.DB, b *Brief) error {
|
||||
wc, full, branch, err := ap.workingCopy(ctx)
|
||||
wc, full, branch, err := ap.WorkingCopy(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer wc.Release()
|
||||
canBuild, note := buildCheck(ctx, wc)
|
||||
work := fmt.Sprintf("supermarket/page-%d", b.ID)
|
||||
if err := wc.NewBranch(ctx, work); err != nil {
|
||||
|
||||
@@ -524,9 +524,10 @@ func (ap *Applier) Apply(ctx context.Context, d *db.DB, id int64) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// workingCopy is a fresh copy of the site's published branch, with the
|
||||
// repository's full name and that branch.
|
||||
func (ap *Applier) workingCopy(ctx context.Context) (*hugorepo.Repo, string, string, error) {
|
||||
// WorkingCopy is a fresh copy of the site's published branch, with the
|
||||
// repository's full name and that branch. The copy is held for the caller,
|
||||
// who must Release it.
|
||||
func (ap *Applier) WorkingCopy(ctx context.Context) (*hugorepo.Repo, string, string, error) {
|
||||
if ap.Gitea == nil {
|
||||
return nil, "", "", errors.New("save a Gitea token under Settings → Search engines first")
|
||||
}
|
||||
@@ -547,7 +548,9 @@ func (ap *Applier) workingCopy(ctx context.Context) (*hugorepo.Repo, string, str
|
||||
}
|
||||
wc := &hugorepo.Repo{Dir: filepath.Join(ap.ReposDir, strings.ReplaceAll(full, "/", "__")), CloneURL: repo.CloneURL,
|
||||
Token: ap.Gitea.Token(), Branch: branch, Author: ap.Author}
|
||||
wc.Acquire()
|
||||
if err := wc.Sync(ctx); err != nil {
|
||||
wc.Release()
|
||||
return nil, "", "", err
|
||||
}
|
||||
return wc, full, branch, nil
|
||||
@@ -568,10 +571,11 @@ func buildCheck(ctx context.Context, wc *hugorepo.Repo) (bool, string) {
|
||||
}
|
||||
|
||||
func (ap *Applier) apply(ctx context.Context, d *db.DB, c *Change) error {
|
||||
wc, full, branch, err := ap.workingCopy(ctx)
|
||||
wc, full, branch, err := ap.WorkingCopy(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer wc.Release()
|
||||
u, err := url.Parse(c.Page)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -200,10 +200,11 @@ func (ap *Applier) SetupSite(ctx context.Context, d *db.DB, site, key string, no
|
||||
}
|
||||
|
||||
func (ap *Applier) setupSite(ctx context.Context, site, key string, st *Setup) error {
|
||||
wc, full, branch, err := ap.workingCopy(ctx)
|
||||
wc, full, branch, err := ap.WorkingCopy(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer wc.Release()
|
||||
canBuild, note := buildCheck(ctx, wc)
|
||||
work := "supermarket/search-engines"
|
||||
if err := wc.NewBranch(ctx, work); err != nil {
|
||||
@@ -271,10 +272,11 @@ func (ap *Applier) setupSite(ctx context.Context, site, key string, st *Setup) e
|
||||
// updates it if it's there: used for the open metrics page. The build
|
||||
// checks the page comes out.
|
||||
func (ap *Applier) PublishPage(ctx context.Context, pagePath, title, description, body, why string) (*gitea.Pull, string, error) {
|
||||
wc, full, branch, err := ap.workingCopy(ctx)
|
||||
wc, full, branch, err := ap.WorkingCopy(ctx)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
defer wc.Release()
|
||||
canBuild, note := buildCheck(ctx, wc)
|
||||
pagePath = "/" + strings.Trim(pagePath, "/") + "/"
|
||||
work := "supermarket/page" + strings.TrimSuffix(strings.ReplaceAll(pagePath, "/", "-"), "-")
|
||||
|
||||
Reference in New Issue
Block a user