mirror of
https://github.com/kovetskiy/mark.git
synced 2025-04-24 05:42:40 +08:00
commit
69b3cd0e88
25
main.go
25
main.go
@ -56,10 +56,15 @@ Options:
|
|||||||
)
|
)
|
||||||
|
|
||||||
type PageInfo struct {
|
type PageInfo struct {
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
|
|
||||||
Version struct {
|
Version struct {
|
||||||
Number int64 `json:"number"`
|
Number int64 `json:"number"`
|
||||||
} `json:"version"`
|
} `json:"version"`
|
||||||
|
|
||||||
|
Ancestors []struct {
|
||||||
|
Id string `json:"id"`
|
||||||
|
} `json:"ancestors"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -180,6 +185,18 @@ func updatePage(
|
|||||||
) error {
|
) error {
|
||||||
nextPageVersion := pageInfo.Version.Number + 1
|
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{}{
|
payload := map[string]interface{}{
|
||||||
"id": pageID,
|
"id": pageID,
|
||||||
"type": "page",
|
"type": "page",
|
||||||
@ -188,6 +205,7 @@ func updatePage(
|
|||||||
"number": nextPageVersion,
|
"number": nextPageVersion,
|
||||||
"minorEdit": false,
|
"minorEdit": false,
|
||||||
},
|
},
|
||||||
|
"ancestors": oldAncestors,
|
||||||
"body": map[string]interface{}{
|
"body": map[string]interface{}{
|
||||||
"storage": map[string]interface{}{
|
"storage": map[string]interface{}{
|
||||||
"value": string(newContent),
|
"value": string(newContent),
|
||||||
@ -220,7 +238,10 @@ func updatePage(
|
|||||||
func getPageInfo(
|
func getPageInfo(
|
||||||
api *gopencils.Resource, pageID string,
|
api *gopencils.Resource, pageID string,
|
||||||
) (PageInfo, error) {
|
) (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 {
|
if err != nil {
|
||||||
return PageInfo{}, err
|
return PageInfo{}, err
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user