mirror of
https://github.com/kovetskiy/mark.git
synced 2025-04-24 05:42:40 +08:00
Merge pull request #51 from rofafor/feature/labels
Add label support fix #34 fix #50
This commit is contained in:
commit
8b28912866
@ -25,6 +25,8 @@ File in the extended format should follow the specification:
|
|||||||
<!-- Parent: <parent 2> -->
|
<!-- Parent: <parent 2> -->
|
||||||
<!-- Title: <title> -->
|
<!-- Title: <title> -->
|
||||||
<!-- Attachment: <local path> -->
|
<!-- Attachment: <local path> -->
|
||||||
|
<!-- Label: <label 1> -->
|
||||||
|
<!-- Label: <label 2> -->
|
||||||
|
|
||||||
<page contents>
|
<page contents>
|
||||||
```
|
```
|
||||||
@ -268,6 +270,7 @@ mark -h | --help
|
|||||||
manual edits over Confluence Web UI.
|
manual edits over Confluence Web UI.
|
||||||
- `--drop-h1` – Don't include H1 headings in Confluence output.
|
- `--drop-h1` – Don't include H1 headings in Confluence output.
|
||||||
- `--dry-run` — Show resulting HTML and don't update Confluence page content.
|
- `--dry-run` — Show resulting HTML and don't update Confluence page content.
|
||||||
|
- `--minor-edit` — Don't send notifications while updating Confluence page.
|
||||||
- `--trace` — Enable trace logs.
|
- `--trace` — Enable trace logs.
|
||||||
- `-v | --version` — Show version.
|
- `-v | --version` — Show version.
|
||||||
- `-h | --help` — Show help screen and call 911.
|
- `-h | --help` — Show help screen and call 911.
|
||||||
@ -282,6 +285,8 @@ password = "matrixishere"
|
|||||||
base_url = "http://confluence.local"
|
base_url = "http://confluence.local"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**NOTE**: Labels aren't supported when using `minor-edit`!
|
||||||
|
|
||||||
# Tricks
|
# Tricks
|
||||||
|
|
||||||
## Continuous Integration
|
## Continuous Integration
|
||||||
|
4
main.go
4
main.go
@ -43,6 +43,7 @@ Options:
|
|||||||
--drop-h1 Don't include H1 headings in Confluence output.
|
--drop-h1 Don't include H1 headings in Confluence output.
|
||||||
--dry-run Resolve page and ancestry, show resulting HTML and exit.
|
--dry-run Resolve page and ancestry, show resulting HTML and exit.
|
||||||
--compile-only Show resulting HTML and don't update Confluence page content.
|
--compile-only Show resulting HTML and don't update Confluence page content.
|
||||||
|
--minor-edit Don't send notifications while updating Confluence page.
|
||||||
--debug Enable debug logs.
|
--debug Enable debug logs.
|
||||||
--trace Enable trace logs.
|
--trace Enable trace logs.
|
||||||
-h --help Show this screen and call 911.
|
-h --help Show this screen and call 911.
|
||||||
@ -62,6 +63,7 @@ func main() {
|
|||||||
dryRun = args["--dry-run"].(bool)
|
dryRun = args["--dry-run"].(bool)
|
||||||
editLock = args["-k"].(bool)
|
editLock = args["-k"].(bool)
|
||||||
dropH1 = args["--drop-h1"].(bool)
|
dropH1 = args["--drop-h1"].(bool)
|
||||||
|
minorEdit = args["--minor-edit"].(bool)
|
||||||
)
|
)
|
||||||
|
|
||||||
if args["--debug"].(bool) {
|
if args["--debug"].(bool) {
|
||||||
@ -240,7 +242,7 @@ func main() {
|
|||||||
html = buffer.String()
|
html = buffer.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
err = api.UpdatePage(target, html)
|
err = api.UpdatePage(target, html, minorEdit, meta.Labels)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -434,7 +434,7 @@ func (api *API) CreatePage(
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (api *API) UpdatePage(
|
func (api *API) UpdatePage(
|
||||||
page *PageInfo, newContent string,
|
page *PageInfo, newContent string, minorEdit bool, newLabels []string,
|
||||||
) error {
|
) error {
|
||||||
nextPageVersion := page.Version.Number + 1
|
nextPageVersion := page.Version.Number + 1
|
||||||
|
|
||||||
@ -450,13 +450,24 @@ func (api *API) UpdatePage(
|
|||||||
{"id": page.Ancestors[len(page.Ancestors)-1].Id},
|
{"id": page.Ancestors[len(page.Ancestors)-1].Id},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
labels := []map[string]interface{}{}
|
||||||
|
for _, label := range newLabels {
|
||||||
|
if label != "" {
|
||||||
|
item := map[string]interface{}{
|
||||||
|
"prexix": "global",
|
||||||
|
"name": label,
|
||||||
|
}
|
||||||
|
labels = append(labels, item)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
payload := map[string]interface{}{
|
payload := map[string]interface{}{
|
||||||
"id": page.ID,
|
"id": page.ID,
|
||||||
"type": "page",
|
"type": "page",
|
||||||
"title": page.Title,
|
"title": page.Title,
|
||||||
"version": map[string]interface{}{
|
"version": map[string]interface{}{
|
||||||
"number": nextPageVersion,
|
"number": nextPageVersion,
|
||||||
"minorEdit": false,
|
"minorEdit": minorEdit,
|
||||||
},
|
},
|
||||||
"ancestors": oldAncestors,
|
"ancestors": oldAncestors,
|
||||||
"body": map[string]interface{}{
|
"body": map[string]interface{}{
|
||||||
@ -465,6 +476,9 @@ func (api *API) UpdatePage(
|
|||||||
"representation": "storage",
|
"representation": "storage",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"metadata": map[string]interface{}{
|
||||||
|
"labels": labels,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
request, err := api.rest.Res(
|
request, err := api.rest.Res(
|
||||||
|
@ -16,6 +16,7 @@ const (
|
|||||||
HeaderTitle = `Title`
|
HeaderTitle = `Title`
|
||||||
HeaderLayout = `Layout`
|
HeaderLayout = `Layout`
|
||||||
HeaderAttachment = `Attachment`
|
HeaderAttachment = `Attachment`
|
||||||
|
HeaderLabel = `Label`
|
||||||
)
|
)
|
||||||
|
|
||||||
type Meta struct {
|
type Meta struct {
|
||||||
@ -24,6 +25,7 @@ type Meta struct {
|
|||||||
Title string
|
Title string
|
||||||
Layout string
|
Layout string
|
||||||
Attachments map[string]string
|
Attachments map[string]string
|
||||||
|
Labels []string
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -90,6 +92,9 @@ func ExtractMeta(data []byte) (*Meta, []byte, error) {
|
|||||||
case HeaderAttachment:
|
case HeaderAttachment:
|
||||||
meta.Attachments[value] = value
|
meta.Attachments[value] = value
|
||||||
|
|
||||||
|
case HeaderLabel:
|
||||||
|
meta.Labels = append(meta.Labels, value)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
log.Errorf(
|
log.Errorf(
|
||||||
nil,
|
nil,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user