wip: attachments

This commit is contained in:
Egor Kovetskiy
2019-04-19 10:31:41 +03:00
parent 5f582e51e6
commit 76ddde31ab
7 changed files with 219 additions and 137 deletions

View File

@@ -5,6 +5,7 @@ import (
"strings"
"github.com/kovetskiy/mark/pkg/confluence"
"github.com/reconquest/faces/logger"
"github.com/reconquest/karma-go"
)
@@ -22,7 +23,7 @@ func EnsureAncestry(
if err != nil {
return nil, karma.Format(
err,
`error during finding parent page with title '%s': %s`,
`error during finding parent page with title %q`,
title,
)
}
@@ -31,7 +32,7 @@ func EnsureAncestry(
break
}
logger.Tracef("parent page '%s' exists: %s", title, page.Links.Full)
log.Tracef(nil, "parent page %q exists: %s", title, page.Links.Full)
rest = ancestry[i:]
parent = page
@@ -44,19 +45,19 @@ func EnsureAncestry(
if err != nil {
return nil, karma.Format(
err,
"can't find root page for space '%s': %s", space,
"can't find root page for space %q",
space,
)
}
parent = page
}
if len(rest) == 0 {
return parent, nil
}
logger.Debugf(
"empty pages under '%s' to be created: %s",
"empty pages under %q to be created: %s",
parent.Title,
strings.Join(rest, ` > `),
)
@@ -66,7 +67,7 @@ func EnsureAncestry(
if err != nil {
return nil, karma.Format(
err,
`error during creating parent page with title '%s': %s`,
`error during creating parent page with title %q`,
title,
)
}
@@ -92,12 +93,12 @@ func ValidateAncestry(
}
if len(page.Ancestors) < 1 {
return nil, fmt.Errorf(`page '%s' has no parents`, page.Title)
return nil, fmt.Errorf(`page %q has no parents`, page.Title)
}
if len(page.Ancestors) < len(ancestry) {
return nil, fmt.Errorf(
"page '%s' has fewer parents than specified: %s",
"page %q has fewer parents than specified: %s",
page.Title,
strings.Join(ancestry, ` > `),
)
@@ -108,7 +109,7 @@ func ValidateAncestry(
if ancestor.Title != ancestry[i] {
return nil, fmt.Errorf(
"broken ancestry tree; expected tree: %s; "+
"encountered '%s' at position of '%s'",
"encountered %q at position of %q",
strings.Join(ancestry, ` > `),
ancestor.Title,
ancestry[i],

19
pkg/mark/attachment.go Normal file
View File

@@ -0,0 +1,19 @@
package mark
import "github.com/kovetskiy/mark/pkg/confluence"
type Attachment struct {
Name string
}
func ResolveAttachments(
api *confluence.API,
page *confluence.PageInfo,
base string,
names []string,
) {
err := api.GetAttachments(page.ID)
if err != nil {
panic(err)
}
}

View File

@@ -3,19 +3,11 @@ package mark
import (
"strings"
"github.com/kovetskiy/lorg"
"github.com/kovetskiy/mark/pkg/confluence"
"github.com/reconquest/faces/logger"
"github.com/reconquest/karma-go"
)
var (
logger lorg.Logger = lorg.NewDiscarder()
)
func SetLogger(log lorg.Logger) {
logger = log
}
func ResolvePage(
api *confluence.API,
meta *Meta,
@@ -24,7 +16,7 @@ func ResolvePage(
if err != nil {
return nil, karma.Format(
err,
"error during finding page '%s': %s",
"error while finding page %q",
meta.Title,
)
}
@@ -45,8 +37,9 @@ func ResolvePage(
}
if page == nil {
logger.Warningf(
"page '%s' is not found ",
log.Warningf(
nil,
"page %q is not found ",
meta.Parents[len(ancestry)-1],
)
}
@@ -68,7 +61,7 @@ func ResolvePage(
if err != nil {
return nil, karma.Format(
err,
"can't create ancestry tree: %s; error: %s",
"can't create ancestry tree: %s",
strings.Join(meta.Parents, ` > `),
)
}
@@ -80,7 +73,8 @@ func ResolvePage(
titles = append(titles, parent.Title)
logger.Infof(
log.Infof(
nil,
"page will be stored under path: %s > %s",
strings.Join(titles, ` > `),
meta.Title,

View File

@@ -4,22 +4,42 @@ import (
"bufio"
"bytes"
"fmt"
"io/ioutil"
"regexp"
"strings"
"github.com/kovetskiy/lorg"
"github.com/reconquest/cog"
)
func discarder() *lorg.Log {
stderr := lorg.NewLog()
stderr.SetOutput(ioutil.Discard)
return stderr
}
var (
log = cog.NewLogger(discarder())
)
func SetLogger(logger *cog.Logger) {
log = logger
}
const (
HeaderParent string = `Parent`
HeaderSpace = `Space`
HeaderTitle = `Title`
HeaderLayout = `Layout`
HeaderParent = `Parent`
HeaderSpace = `Space`
HeaderTitle = `Title`
HeaderLayout = `Layout`
HeaderAttachment = `Attachment`
)
type Meta struct {
Parents []string
Space string
Title string
Layout string
Parents []string
Space string
Title string
Layout string
Attachments []string
}
func ExtractMeta(data []byte) (*Meta, error) {
@@ -46,22 +66,31 @@ func ExtractMeta(data []byte) (*Meta, error) {
header := strings.Title(matches[1])
var value string
if len(matches) > 1 {
value = strings.TrimSpace(matches[2])
}
switch header {
case HeaderParent:
meta.Parents = append(meta.Parents, matches[2])
meta.Parents = append(meta.Parents, value)
case HeaderSpace:
meta.Space = strings.ToUpper(matches[2])
meta.Space = strings.ToUpper(value)
case HeaderTitle:
meta.Title = strings.TrimSpace(matches[2])
meta.Title = strings.TrimSpace(value)
case HeaderLayout:
meta.Layout = strings.TrimSpace(matches[2])
meta.Layout = strings.TrimSpace(value)
case HeaderAttachment:
meta.Attachments = append(meta.Attachments, value)
default:
logger.Errorf(
`encountered unknown header '%s' line: %#v`,
log.Errorf(
nil,
`encountered unknown header %q line: %#v`,
header,
line,
)