From 721dd1b6424b832a8a71f9bcfa32fa4b2489a894 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20R=C3=BCger?= Date: Thu, 5 Jan 2023 11:25:14 +0100 Subject: [PATCH 1/3] Makefile: Add test target --- .gitignore | 1 + Makefile | 3 +++ 2 files changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index bc9f460..edd1254 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ /testdata .idea/ /mark.test +/profile.cov diff --git a/Makefile b/Makefile index 9ede00b..9f1df9b 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,9 @@ build: -ldflags "-X main.version=$(VERSION)" \ -gcflags "-trimpath $(GOPATH)/src" +test: + go test -race -coverprofile=profile.cov ./... + image: @echo :: building image $(NAME):$(VERSION) @docker build -t $(NAME):$(VERSION) -f Dockerfile . From bde4b702427f488e61d21e6cd7d856dd75fdfefd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20R=C3=BCger?= Date: Thu, 5 Jan 2023 11:26:32 +0100 Subject: [PATCH 2/3] .github: Add CI pipeline --- .github/ci.yml | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 .github/ci.yml diff --git a/.github/ci.yml b/.github/ci.yml new file mode 100644 index 0000000..d1e941b --- /dev/null +++ b/.github/ci.yml @@ -0,0 +1,66 @@ +name: continuous-integration + +on: + push: + branches: + - master + pull_request: + branches: + - master + +env: + GO_VERSION: "~1.19.4" + +jobs: + # Runs Golangci-lint on the source code + ci-go-lint: + name: ci-go-lint + runs-on: ubuntu-latest + steps: + - name: Set up Go 1.x + uses: actions/setup-go@v3 + with: + go-version: ${{ env.GO_VERSION }} + id: go + + - name: Check out code into the Go module directory + uses: actions/checkout@v3 + + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + + # Executes Unit Tests + ci-unit-tests: + name: ci-unit-tests + runs-on: ubuntu-latest + steps: + - name: Set up Go 1.x + uses: actions/setup-go@v3 + with: + go-version: ${{ env.GO_VERSION }} + id: go + + - name: Check out code into the Go module directory + uses: actions/checkout@v3 + + - name: Run unit tests + run: | + make test + + # Builds mark binary + ci-build: + name: ci-build + runs-on: ubuntu-latest + steps: + - name: Set up Go 1.x + uses: actions/setup-go@v3 + with: + go-version: ${{ env.GO_VERSION }} + id: go + + - name: Check out code into the Go module directory + uses: actions/checkout@v3 + + - name: Build mark + run: | + make build From 8deecfd67a82f586e946c347edcc5987c248e2f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20R=C3=BCger?= Date: Thu, 5 Jan 2023 11:30:22 +0100 Subject: [PATCH 3/3] Lint --- pkg/confluence/api.go | 5 ++++- pkg/mark/link.go | 2 +- pkg/mark/markdown.go | 44 +++++++++++++++++++++++++++++++-------- pkg/mark/markdown_test.go | 4 ---- 4 files changed, 40 insertions(+), 15 deletions(-) diff --git a/pkg/confluence/api.go b/pkg/confluence/api.go index a97fc09..a48f204 100644 --- a/pkg/confluence/api.go +++ b/pkg/confluence/api.go @@ -89,7 +89,10 @@ func (tracer *tracer) Printf(format string, args ...interface{}) { func NewAPI(baseURL string, username string, password string) *API { var auth *gopencils.BasicAuth if username != "" { - auth = &gopencils.BasicAuth{username, password} + auth = &gopencils.BasicAuth{ + Username: username, + Password: password, + } } rest := gopencils.Api(baseURL+"/rest/api", auth) if username == "" { diff --git a/pkg/mark/link.go b/pkg/mark/link.go index 805d305..b38baed 100644 --- a/pkg/mark/link.go +++ b/pkg/mark/link.go @@ -149,7 +149,7 @@ func SubstituteLinks(markdown []byte, links []LinkSubstitution) []byte { } func parseLinks(markdown string) []markdownLink { - re := regexp.MustCompile("\\[[^\\]]+\\]\\((([^\\)#]+)?#?([^\\)]+)?)\\)") + re := regexp.MustCompile(`\[[^\]]+\]\((([^\)#]+)?#?([^\)]+)?)\)`) matches := re.FindAllStringSubmatch(markdown, -1) links := make([]markdownLink, len(matches)) diff --git a/pkg/mark/markdown.go b/pkg/mark/markdown.go index 679a1fb..98576c0 100644 --- a/pkg/mark/markdown.go +++ b/pkg/mark/markdown.go @@ -176,7 +176,7 @@ func (renderer ConfluenceRenderer) RenderNode( theme = option } } - renderer.Stdlib.Templates.ExecuteTemplate( + err := renderer.Stdlib.Templates.ExecuteTemplate( writer, "ac:code", struct { @@ -197,20 +197,46 @@ func (renderer ConfluenceRenderer) RenderNode( strings.TrimSuffix(string(node.Literal), "\n"), }, ) + if err != nil { + panic(err) + } return bf.GoToNext } if node.Type == bf.Link && string(node.Destination[0:3]) == "ac:" { if entering { - writer.Write([]byte("")) + + if len(node.Destination) < 4 { + _, err := writer.Write(node.FirstChild.Literal) + if err != nil { + panic(err) + } + } else { + _, err := writer.Write(node.Destination[3:]) + if err != nil { + panic(err) + } + + } + _, err = writer.Write([]byte("\"/>")) + if err != nil { + panic(err) + } + return bf.SkipChildren } return bf.GoToNext diff --git a/pkg/mark/markdown_test.go b/pkg/mark/markdown_test.go index 7bc8c04..9819386 100644 --- a/pkg/mark/markdown_test.go +++ b/pkg/mark/markdown_test.go @@ -14,10 +14,6 @@ const ( NL = "\n" ) -func text(lines ...string) string { - return strings.Join(lines, "\n") -} - func TestCompileMarkdown(t *testing.T) { test := assert.New(t)