Deploy cursor fix?
This commit is contained in:
@@ -528,11 +528,11 @@ 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) {
|
if entry.TID != 0 && entry.CID != 0 && shouldCheckRemoteTopicTitle(manifest.Pages[pageID], page.Title, entry.TopicTitle, opts.TitlePrefixMinLength) {
|
||||||
remotePage, ok, err := findMappedRemotePage(entry, remotePagesByCID, client, progress)
|
remoteTopic, ok, err := findMappedRemoteTopic(entry, client)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, result, next, err
|
return nil, result, next, err
|
||||||
}
|
}
|
||||||
if ok && titleNeedsRename(remotePageTitle(remotePage), entry.TopicTitle) {
|
if ok && titleNeedsRename(remoteTopic.Title, entry.TopicTitle) {
|
||||||
result.Renamed++
|
result.Renamed++
|
||||||
plans = append(plans, wikiDeployPlan{Page: page, Entry: entry, Action: "rename", Title: entry.TopicTitle})
|
plans = append(plans, wikiDeployPlan{Page: page, Entry: entry, Action: "rename", Title: entry.TopicTitle})
|
||||||
}
|
}
|
||||||
@@ -690,30 +690,15 @@ func planManagedNamespaceReset(opts DeployWikiOptions, client *nodeBBClient, pro
|
|||||||
return plans, len(plans), nil
|
return plans, len(plans), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func findMappedRemotePage(entry wikiDeployManifestPage, remotePagesByCID map[int][]nodeBBWikiPage, client *nodeBBClient, progress func(string)) (nodeBBWikiPage, bool, error) {
|
func findMappedRemoteTopic(entry wikiDeployManifestPage, client *nodeBBClient) (nodeBBPost, bool, error) {
|
||||||
remotePages, ok := remotePagesByCID[entry.CID]
|
topic, err := client.getTopic(entry.TID)
|
||||||
if !ok {
|
if err != nil {
|
||||||
var err error
|
if isNodeBBMissingResource(err) {
|
||||||
progress(fmt.Sprintf("Listing NodeBB wiki namespace category %d", entry.CID))
|
return nodeBBPost{}, false, nil
|
||||||
remotePages, err = client.listNamespacePages(entry.CID)
|
|
||||||
if err != nil {
|
|
||||||
return nodeBBWikiPage{}, false, err
|
|
||||||
}
|
}
|
||||||
remotePagesByCID[entry.CID] = remotePages
|
return nodeBBPost{}, false, err
|
||||||
}
|
}
|
||||||
for _, remotePage := range remotePages {
|
return topic, true, nil
|
||||||
if remotePage.TID == entry.TID {
|
|
||||||
return remotePage, true, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nodeBBWikiPage{}, false, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func remotePageTitle(page nodeBBWikiPage) string {
|
|
||||||
if title := strings.TrimSpace(page.Title); title != "" {
|
|
||||||
return title
|
|
||||||
}
|
|
||||||
return strings.TrimSpace(page.TitleLeaf)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func titleNeedsRename(current, desired string) bool {
|
func titleNeedsRename(current, desired string) bool {
|
||||||
@@ -1364,6 +1349,7 @@ func isNodeBBMissingResource(err error) bool {
|
|||||||
type nodeBBPost struct {
|
type nodeBBPost struct {
|
||||||
PID int
|
PID int
|
||||||
TID int
|
TID int
|
||||||
|
Title string
|
||||||
Content string
|
Content string
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1581,11 +1567,18 @@ func parseNodeBBPost(doc any) nodeBBPost {
|
|||||||
if post.TID == 0 {
|
if post.TID == 0 {
|
||||||
post.TID = intFromAny(m["tid"])
|
post.TID = intFromAny(m["tid"])
|
||||||
}
|
}
|
||||||
|
if post.PID == 0 {
|
||||||
|
post.PID = firstInt(m, "mainPid")
|
||||||
|
}
|
||||||
|
if post.Title == "" {
|
||||||
|
post.Title = firstString(m, "title", "titleRaw", "title_raw")
|
||||||
|
}
|
||||||
return post
|
return post
|
||||||
}
|
}
|
||||||
return nodeBBPost{
|
return nodeBBPost{
|
||||||
PID: firstInt(m, "pid", "mainPid"),
|
PID: firstInt(m, "pid", "mainPid"),
|
||||||
TID: firstInt(m, "tid"),
|
TID: firstInt(m, "tid"),
|
||||||
|
Title: firstString(m, "title", "titleRaw", "title_raw"),
|
||||||
Content: firstString(m, "content"),
|
Content: firstString(m, "content"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -770,14 +770,13 @@ func TestDeployWikiRenamesExistingPrefixedTopicWhenTitleIsLongEnough(t *testing.
|
|||||||
renameCalls := 0
|
renameCalls := 0
|
||||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
switch {
|
switch {
|
||||||
case r.Method == http.MethodGet && r.URL.Path == "/api/v3/plugins/westgate-wiki/namespace/5/pages":
|
case r.Method == http.MethodGet && r.URL.Path == "/api/v3/topics/7":
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
_ = json.NewEncoder(w).Encode(map[string]any{
|
_ = json.NewEncoder(w).Encode(map[string]any{
|
||||||
"response": map[string]any{
|
"response": map[string]any{
|
||||||
"pages": []map[string]any{
|
"tid": 7,
|
||||||
{"tid": 7, "title": "Itemtypes: Belt", "titleLeaf": "Itemtypes: Belt", "slug": "7/itemtypes-belt", "wikiPath": "/wiki/itemtypes/itemtypes-belt"},
|
"title": "Itemtypes: Belt",
|
||||||
},
|
"mainPid": 42,
|
||||||
"hasMore": false,
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
case r.Method == http.MethodPut && r.URL.Path == "/api/v3/plugins/westgate-wiki/page/move":
|
case r.Method == http.MethodPut && r.URL.Path == "/api/v3/plugins/westgate-wiki/page/move":
|
||||||
@@ -856,13 +855,13 @@ func TestDeployWikiRenamesManagedTopicWhenGeneratedTitleChanges(t *testing.T) {
|
|||||||
renameCalls := 0
|
renameCalls := 0
|
||||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
switch {
|
switch {
|
||||||
case r.Method == http.MethodGet && r.URL.Path == "/api/v3/plugins/westgate-wiki/namespace/5/pages":
|
case r.Method == http.MethodGet && r.URL.Path == "/api/v3/topics/7":
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
_ = json.NewEncoder(w).Encode(map[string]any{
|
_ = json.NewEncoder(w).Encode(map[string]any{
|
||||||
"response": map[string]any{
|
"response": map[string]any{
|
||||||
"pages": []map[string]any{
|
"tid": 7,
|
||||||
{"tid": 7, "title": "Weapon Focus (Dwaxe)", "titleLeaf": "Weapon Focus (Dwaxe)"},
|
"title": "Weapon Focus (Dwaxe)",
|
||||||
},
|
"mainPid": 42,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
case r.Method == http.MethodPut && r.URL.Path == "/api/v3/plugins/westgate-wiki/page/move":
|
case r.Method == http.MethodPut && r.URL.Path == "/api/v3/plugins/westgate-wiki/page/move":
|
||||||
|
|||||||
Reference in New Issue
Block a user