Skip to content

Commit

Permalink
do not break ancestry tree
Browse files Browse the repository at this point in the history
Running `mark` for updating page, deeply nested in some tree, ended up page
being shifted to the Ctulhu's void, e.g. not belonging to any parent.
  • Loading branch information
seletskiy committed Sep 22, 2015
1 parent 766aba2 commit 064b388
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,15 @@ Options:
)

type PageInfo struct {
Title string `json:"title"`
Title string `json:"title"`

Version struct {
Number int64 `json:"number"`
} `json:"version"`

Ancestors []struct {
Id string `json:"id"`
} `json:"ancestors"`
}

func main() {
Expand Down Expand Up @@ -188,6 +193,9 @@ func updatePage(
"number": nextPageVersion,
"minorEdit": false,
},
"ancestors": []map[string]interface{}{
{"id": pageInfo.Ancestors[len(pageInfo.Ancestors)-1].Id},
},
"body": map[string]interface{}{
"storage": map[string]interface{}{
"value": string(newContent),
Expand Down Expand Up @@ -220,7 +228,10 @@ func updatePage(
func getPageInfo(
api *gopencils.Resource, pageID string,
) (PageInfo, error) {
request, err := api.Res("content/"+pageID, &PageInfo{}).Get()
request, err := api.Res(
"content/"+pageID, &PageInfo{},
).Get(map[string]string{"expand": "ancestors,version"})

if err != nil {
return PageInfo{}, err
}
Expand Down

0 comments on commit 064b388

Please sign in to comment.