Skip to content

Commit

Permalink
Merge pull request #1 from seletskiy/master
Browse files Browse the repository at this point in the history
do not break ancestry tree
  • Loading branch information
kovetskiy committed Sep 22, 2015
2 parents 766aba2 + fa09917 commit 69b3cd0
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 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 @@ -180,6 +185,18 @@ func updatePage(
) error {
nextPageVersion := pageInfo.Version.Number + 1

if len(pageInfo.Ancestors) == 0 {
return fmt.Errorf(
"Page '%s' info does not contain any information about parents",
pageID,
)
}

// picking only the last one, which is required by confluence
oldAncestors := []map[string]interface{}{
{"id": pageInfo.Ancestors[len(pageInfo.Ancestors)-1].Id},
}

payload := map[string]interface{}{
"id": pageID,
"type": "page",
Expand All @@ -188,6 +205,7 @@ func updatePage(
"number": nextPageVersion,
"minorEdit": false,
},
"ancestors": oldAncestors,
"body": map[string]interface{}{
"storage": map[string]interface{}{
"value": string(newContent),
Expand Down Expand Up @@ -220,7 +238,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 69b3cd0

Please sign in to comment.