Fixing release queue
This commit is contained in:
@@ -170,14 +170,18 @@ func DeployWikiWithOptions(p *project.Project, opts DeployWikiOptions, progress
|
||||
manifestPath = filepath.Join(filepath.Dir(opts.SourceDir), p.EffectiveConfig().TopData.Wiki.DeployManifest)
|
||||
}
|
||||
|
||||
progress(fmt.Sprintf("Collecting local wiki pages from %s", opts.SourceDir))
|
||||
pages, err := collectLocalPages(opts.SourceDir, namespaces)
|
||||
if err != nil {
|
||||
return deployResult{}, err
|
||||
}
|
||||
progress(fmt.Sprintf("Loaded %d local wiki page(s)", len(pages)))
|
||||
manifest := loadDeployManifest(manifestPath)
|
||||
progress(fmt.Sprintf("Loaded wiki deploy manifest %s with %d page mapping(s)", manifestPath, len(manifest.Pages)))
|
||||
client := newNodeBBClient(opts.Endpoint, opts.Token)
|
||||
|
||||
plans, result, nextManifest, err := planNodeBBDeploy(pages, manifest, opts, client)
|
||||
progress(fmt.Sprintf("Planning NodeBB wiki deploy for %d local page(s)", len(pages)))
|
||||
plans, result, nextManifest, err := planNodeBBDeploy(pages, manifest, opts, client, progress)
|
||||
if err != nil {
|
||||
return deployResult{}, err
|
||||
}
|
||||
@@ -451,7 +455,10 @@ func isDir(path string) bool {
|
||||
return err == nil && info.IsDir()
|
||||
}
|
||||
|
||||
func planNodeBBDeploy(pages map[string]wikiDeployPage, manifest wikiDeployManifest, opts DeployWikiOptions, client *nodeBBClient) ([]wikiDeployPlan, deployResult, wikiDeployManifest, error) {
|
||||
func planNodeBBDeploy(pages map[string]wikiDeployPage, manifest wikiDeployManifest, opts DeployWikiOptions, client *nodeBBClient, progress func(string)) ([]wikiDeployPlan, deployResult, wikiDeployManifest, error) {
|
||||
if progress == nil {
|
||||
progress = func(string) {}
|
||||
}
|
||||
pageIDs := sortedKeysFromMap(pages)
|
||||
next := wikiDeployManifest{Version: "nodebb-v1", Pages: map[string]wikiDeployManifestPage{}}
|
||||
remotePagesByCID := map[int][]nodeBBWikiPage{}
|
||||
@@ -461,7 +468,7 @@ func planNodeBBDeploy(pages map[string]wikiDeployPage, manifest wikiDeployManife
|
||||
if !opts.AllowCreates && len(pageIDs) > 0 {
|
||||
return nil, result, next, errors.New("wiki managed namespace reset requires --create so current generated pages can be recreated")
|
||||
}
|
||||
resetPlans, purged, err := planManagedNamespaceReset(opts, client)
|
||||
resetPlans, purged, err := planManagedNamespaceReset(opts, client, progress)
|
||||
if err != nil {
|
||||
return nil, result, next, err
|
||||
}
|
||||
@@ -475,7 +482,10 @@ func planNodeBBDeploy(pages map[string]wikiDeployPage, manifest wikiDeployManife
|
||||
}
|
||||
}
|
||||
|
||||
for _, pageID := range pageIDs {
|
||||
for i, pageID := range pageIDs {
|
||||
if i == 0 || (i+1)%100 == 0 || i+1 == len(pageIDs) {
|
||||
progress(fmt.Sprintf("Planning NodeBB wiki page %d/%d: %s", i+1, len(pageIDs), pageID))
|
||||
}
|
||||
page := pages[pageID]
|
||||
entry := manifest.Pages[pageID]
|
||||
entry.Hash = page.Hash
|
||||
@@ -491,7 +501,7 @@ func planNodeBBDeploy(pages map[string]wikiDeployPage, manifest wikiDeployManife
|
||||
|
||||
if entry.PID == 0 {
|
||||
if entry.CID != 0 {
|
||||
adopted, ok, err := adoptExistingNodeBBPage(page, entry.CID, remotePagesByCID, client)
|
||||
adopted, ok, err := adoptExistingNodeBBPage(page, entry.CID, remotePagesByCID, client, progress)
|
||||
if err != nil {
|
||||
return nil, result, next, err
|
||||
}
|
||||
@@ -518,7 +528,7 @@ func planNodeBBDeploy(pages map[string]wikiDeployPage, manifest wikiDeployManife
|
||||
}
|
||||
|
||||
if entry.TID != 0 && entry.CID != 0 && shouldCheckRemoteTopicTitle(manifest.Pages[pageID], page.Title, entry.TopicTitle, opts.TitlePrefixMinLength) {
|
||||
remotePage, ok, err := findMappedRemotePage(entry, remotePagesByCID, client)
|
||||
remotePage, ok, err := findMappedRemotePage(entry, remotePagesByCID, client, progress)
|
||||
if err != nil {
|
||||
return nil, result, next, err
|
||||
}
|
||||
@@ -540,7 +550,7 @@ func planNodeBBDeploy(pages map[string]wikiDeployPage, manifest wikiDeployManife
|
||||
entry.TID = 0
|
||||
entry.PID = 0
|
||||
if entry.CID != 0 {
|
||||
adopted, ok, adoptErr := adoptExistingNodeBBPage(page, entry.CID, remotePagesByCID, client)
|
||||
adopted, ok, adoptErr := adoptExistingNodeBBPage(page, entry.CID, remotePagesByCID, client, progress)
|
||||
if adoptErr != nil {
|
||||
return nil, result, next, adoptErr
|
||||
}
|
||||
@@ -633,7 +643,7 @@ func planNodeBBDeploy(pages map[string]wikiDeployPage, manifest wikiDeployManife
|
||||
return plans, result, next, nil
|
||||
}
|
||||
|
||||
func planManagedNamespaceReset(opts DeployWikiOptions, client *nodeBBClient) ([]wikiDeployPlan, int, error) {
|
||||
func planManagedNamespaceReset(opts DeployWikiOptions, client *nodeBBClient, progress func(string)) ([]wikiDeployPlan, int, error) {
|
||||
namespaces := slices.Clone(opts.Namespaces)
|
||||
if len(namespaces) == 0 {
|
||||
for namespace := range opts.CategoryIDs {
|
||||
@@ -649,6 +659,7 @@ func planManagedNamespaceReset(opts DeployWikiOptions, client *nodeBBClient) ([]
|
||||
if cid == 0 {
|
||||
continue
|
||||
}
|
||||
progress(fmt.Sprintf("Listing NodeBB wiki namespace category %d for managed reset", cid))
|
||||
remotePages, err := client.listNamespacePages(cid)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
@@ -679,10 +690,11 @@ func planManagedNamespaceReset(opts DeployWikiOptions, client *nodeBBClient) ([]
|
||||
return plans, len(plans), nil
|
||||
}
|
||||
|
||||
func findMappedRemotePage(entry wikiDeployManifestPage, remotePagesByCID map[int][]nodeBBWikiPage, client *nodeBBClient) (nodeBBWikiPage, bool, error) {
|
||||
func findMappedRemotePage(entry wikiDeployManifestPage, remotePagesByCID map[int][]nodeBBWikiPage, client *nodeBBClient, progress func(string)) (nodeBBWikiPage, bool, error) {
|
||||
remotePages, ok := remotePagesByCID[entry.CID]
|
||||
if !ok {
|
||||
var err error
|
||||
progress(fmt.Sprintf("Listing NodeBB wiki namespace category %d", entry.CID))
|
||||
remotePages, err = client.listNamespacePages(entry.CID)
|
||||
if err != nil {
|
||||
return nodeBBWikiPage{}, false, err
|
||||
@@ -748,10 +760,11 @@ func recoverCreateCollision(plan wikiDeployPlan, manifest wikiDeployManifest, cl
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func adoptExistingNodeBBPage(page wikiDeployPage, cid int, remotePagesByCID map[int][]nodeBBWikiPage, client *nodeBBClient) (wikiDeployManifestPage, bool, error) {
|
||||
func adoptExistingNodeBBPage(page wikiDeployPage, cid int, remotePagesByCID map[int][]nodeBBWikiPage, client *nodeBBClient, progress func(string)) (wikiDeployManifestPage, bool, error) {
|
||||
remotePages, ok := remotePagesByCID[cid]
|
||||
if !ok {
|
||||
var err error
|
||||
progress(fmt.Sprintf("Listing NodeBB wiki namespace category %d", cid))
|
||||
remotePages, err = client.listNamespacePages(cid)
|
||||
if err != nil {
|
||||
return wikiDeployManifestPage{}, false, err
|
||||
@@ -1406,6 +1419,7 @@ func (c *nodeBBClient) searchNamespacePages(cid int, query string) ([]nodeBBWiki
|
||||
func (c *nodeBBClient) listNamespacePagesWithQuery(cid int, query string) ([]nodeBBWikiPage, error) {
|
||||
var out []nodeBBWikiPage
|
||||
after := ""
|
||||
seenCursors := map[string]struct{}{}
|
||||
for {
|
||||
path := fmt.Sprintf("/api/v3/plugins/westgate-wiki/namespace/%d/pages?limit=80", cid)
|
||||
if query != "" {
|
||||
@@ -1423,6 +1437,13 @@ func (c *nodeBBClient) listNamespacePagesWithQuery(cid int, query string) ([]nod
|
||||
if !hasMore || next == "" {
|
||||
return out, nil
|
||||
}
|
||||
if after != "" && next == after {
|
||||
return nil, fmt.Errorf("NodeBB wiki namespace %d returned repeated pagination cursor %q", cid, next)
|
||||
}
|
||||
if _, ok := seenCursors[next]; ok {
|
||||
return nil, fmt.Errorf("NodeBB wiki namespace %d returned repeated pagination cursor %q", cid, next)
|
||||
}
|
||||
seenCursors[next] = struct{}{}
|
||||
after = next
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user