mirror of
https://github.com/kovetskiy/mark.git
synced 2026-05-03 22:12:35 +00:00
allow space home update and its children pages (#101)
* allow space home update and its children pages * fix coding styling * fix coding styling * codestyle: fix checking isHomepage * codestyle: fix checking skipHomeAncestry Co-authored-by: Hugo Cisneiros (Eitch) <hugo.cisneiros@ifood.com.br> Co-authored-by: Egor Kovetskiy <e.kovetskiy@gmail.com>
This commit is contained in:
@@ -30,6 +30,18 @@ type API struct {
|
||||
BaseURL string
|
||||
}
|
||||
|
||||
type SpaceInfo struct {
|
||||
ID int `json:"id"`
|
||||
Key string `json:"key"`
|
||||
Name string `json:"name"`
|
||||
|
||||
Homepage PageInfo `json:"homepage"`
|
||||
|
||||
Links struct {
|
||||
Full string `json:"webui"`
|
||||
} `json:"_links"`
|
||||
}
|
||||
|
||||
type PageInfo struct {
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
@@ -122,6 +134,26 @@ func (api *API) FindRootPage(space string) (*PageInfo, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (api *API) FindHomePage(space string) (*PageInfo, error) {
|
||||
payload := map[string]string{
|
||||
"expand": "homepage",
|
||||
}
|
||||
|
||||
request, err := api.rest.Res(
|
||||
"space/"+space, &SpaceInfo{},
|
||||
).Get(payload)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if request.Raw.StatusCode == 404 || request.Raw.StatusCode != 200 {
|
||||
return nil, newErrorStatusNotOK(request)
|
||||
}
|
||||
|
||||
return &request.Response.(*SpaceInfo).Homepage, nil
|
||||
}
|
||||
|
||||
func (api *API) FindPage(space string, title string, pageType string) (*PageInfo, error) {
|
||||
result := struct {
|
||||
Results []PageInfo `json:"results"`
|
||||
@@ -442,14 +474,7 @@ func (api *API) UpdatePage(
|
||||
nextPageVersion := page.Version.Number + 1
|
||||
oldAncestors := []map[string]interface{}{}
|
||||
|
||||
if page.Type != "blogpost" {
|
||||
if len(page.Ancestors) == 0 {
|
||||
return fmt.Errorf(
|
||||
"page %q info does not contain any information about parents",
|
||||
page.ID,
|
||||
)
|
||||
}
|
||||
|
||||
if page.Type != "blogpost" && len(page.Ancestors) > 0 {
|
||||
// picking only the last one, which is required by confluence
|
||||
oldAncestors = []map[string]interface{}{
|
||||
{"id": page.Ancestors[len(page.Ancestors)-1].Id},
|
||||
|
||||
Reference in New Issue
Block a user