From f86dd2723ad888d43342fb0fbb2e92431363de14 Mon Sep 17 00:00:00 2001 From: Rolf Ahrenberg Date: Mon, 4 Jan 2021 13:08:58 +0200 Subject: [PATCH 1/2] Add label support --- README.md | 2 ++ main.go | 2 +- pkg/confluence/api.go | 16 +++++++++++++++- pkg/mark/meta.go | 5 +++++ 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 74c9d76..84830f0 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,8 @@ File in the extended format should follow the specification: + + ``` diff --git a/main.go b/main.go index 9ac0fdd..3c44285 100644 --- a/main.go +++ b/main.go @@ -240,7 +240,7 @@ func main() { html = buffer.String() } - err = api.UpdatePage(target, html) + err = api.UpdatePage(target, html, meta.Labels) if err != nil { log.Fatal(err) } diff --git a/pkg/confluence/api.go b/pkg/confluence/api.go index 181e656..4d24a17 100644 --- a/pkg/confluence/api.go +++ b/pkg/confluence/api.go @@ -434,7 +434,7 @@ func (api *API) CreatePage( } func (api *API) UpdatePage( - page *PageInfo, newContent string, + page *PageInfo, newContent string, newLabels []string, ) error { nextPageVersion := page.Version.Number + 1 @@ -450,6 +450,17 @@ func (api *API) UpdatePage( {"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{}{ "id": page.ID, "type": "page", @@ -465,6 +476,9 @@ func (api *API) UpdatePage( "representation": "storage", }, }, + "metadata": map[string]interface{}{ + "labels": labels, + }, } request, err := api.rest.Res( diff --git a/pkg/mark/meta.go b/pkg/mark/meta.go index 404a03f..49eadac 100644 --- a/pkg/mark/meta.go +++ b/pkg/mark/meta.go @@ -16,6 +16,7 @@ const ( HeaderTitle = `Title` HeaderLayout = `Layout` HeaderAttachment = `Attachment` + HeaderLabel = `Label` ) type Meta struct { @@ -24,6 +25,7 @@ type Meta struct { Title string Layout string Attachments map[string]string + Labels []string } var ( @@ -90,6 +92,9 @@ func ExtractMeta(data []byte) (*Meta, []byte, error) { case HeaderAttachment: meta.Attachments[value] = value + case HeaderLabel: + meta.Labels = append(meta.Labels, value) + default: log.Errorf( nil, From 1d8e43add244a43f8df5243213b6872491550c63 Mon Sep 17 00:00:00 2001 From: Rolf Ahrenberg Date: Mon, 4 Jan 2021 15:42:34 +0200 Subject: [PATCH 2/2] Add --minor-edit command-line flag --- README.md | 3 +++ main.go | 4 +++- pkg/confluence/api.go | 4 ++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 84830f0..5d6c3ab 100644 --- a/README.md +++ b/README.md @@ -270,6 +270,7 @@ mark -h | --help manual edits over Confluence Web UI. - `--drop-h1` – Don't include H1 headings in Confluence output. - `--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. - `-v | --version` — Show version. - `-h | --help` — Show help screen and call 911. @@ -284,6 +285,8 @@ password = "matrixishere" base_url = "http://confluence.local" ``` +**NOTE**: Labels aren't supported when using `minor-edit`! + # Tricks ## Continuous Integration diff --git a/main.go b/main.go index 3c44285..b295c6b 100644 --- a/main.go +++ b/main.go @@ -43,6 +43,7 @@ Options: --drop-h1 Don't include H1 headings in Confluence output. --dry-run Resolve page and ancestry, show resulting HTML and exit. --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. --trace Enable trace logs. -h --help Show this screen and call 911. @@ -62,6 +63,7 @@ func main() { dryRun = args["--dry-run"].(bool) editLock = args["-k"].(bool) dropH1 = args["--drop-h1"].(bool) + minorEdit = args["--minor-edit"].(bool) ) if args["--debug"].(bool) { @@ -240,7 +242,7 @@ func main() { html = buffer.String() } - err = api.UpdatePage(target, html, meta.Labels) + err = api.UpdatePage(target, html, minorEdit, meta.Labels) if err != nil { log.Fatal(err) } diff --git a/pkg/confluence/api.go b/pkg/confluence/api.go index 4d24a17..188bfbd 100644 --- a/pkg/confluence/api.go +++ b/pkg/confluence/api.go @@ -434,7 +434,7 @@ func (api *API) CreatePage( } func (api *API) UpdatePage( - page *PageInfo, newContent string, newLabels []string, + page *PageInfo, newContent string, minorEdit bool, newLabels []string, ) error { nextPageVersion := page.Version.Number + 1 @@ -467,7 +467,7 @@ func (api *API) UpdatePage( "title": page.Title, "version": map[string]interface{}{ "number": nextPageVersion, - "minorEdit": false, + "minorEdit": minorEdit, }, "ancestors": oldAncestors, "body": map[string]interface{}{