From 91ca3b8516c7e972a9d795e91f7cf5f86d2fb3a0 Mon Sep 17 00:00:00 2001 From: John Boyes <154404+johnboyes@users.noreply.github.com> Date: Thu, 26 Aug 2021 19:24:57 +0100 Subject: [PATCH] Fix bug: nested empty dirs are no longer published (#43) * Add test for nested empty directories * Fix bug: nested empty dirs are no longer published Prior to this commit if there were nested directories with no specs (e.g. nested directories just containing concepts), then some of the empty directories were being published as pages in Confluence when they shouldn't have been. * Bump plugin patch version --- .../specs/do_not_publish_concepts.spec | 40 ++++++++++++++----- internal/confluence/space.go | 20 +++++++++- plugin.json | 2 +- 3 files changed, 50 insertions(+), 12 deletions(-) diff --git a/functional-tests/specs/do_not_publish_concepts.spec b/functional-tests/specs/do_not_publish_concepts.spec index 6d9ad1d..72f458c 100644 --- a/functional-tests/specs/do_not_publish_concepts.spec +++ b/functional-tests/specs/do_not_publish_concepts.spec @@ -18,19 +18,41 @@ |specs |Space Home| |A spec |specs | + ## A directory that just contains concepts is not published * Publish specs to Confluence: - |heading |path |concept| - |-----------------------------|--------------|-------| - |A spec in the specs dir |specs | | - |A concept in the concepts dir|specs/concepts|yes | + |heading |path |concept| + |---------------------------|--------------|-------| + |A spec in a specs dir |specs | | + |A concept in a concepts dir|specs/concepts|yes | + +* Published pages are: + + |title |parent | + |---------------------|----------| + |Space Home | | + |specs |Space Home| + |A spec in a specs dir|specs | + + +## Nested directories that just contain concepts are not published + +* Publish specs to Confluence: + + |heading |path |concept| + |-----------------------------------------|-----------------------|-------| + |A spec in a specs dir |specs | | + |A concept in a concepts dir |specs/concepts |yes | + |A concept in a sub concepts dir |specs/concepts/sub |yes | + |Another concept in a sub concepts dir |specs/concepts/sub |yes | + |Another concept in a sub sub concepts dir|specs/concepts/sub/sub2|yes | * Published pages are: - |title |parent | - |-----------------------|----------| - |Space Home | | - |specs |Space Home| - |A spec in the specs dir|specs | + |title |parent | + |---------------------|----------| + |Space Home | | + |specs |Space Home| + |A spec in a specs dir|specs | diff --git a/internal/confluence/space.go b/internal/confluence/space.go index 2a63cf8..c865a0a 100644 --- a/internal/confluence/space.go +++ b/internal/confluence/space.go @@ -130,8 +130,8 @@ func (s *space) deleteAllPagesExceptHomepage() (err error) { // deleteEmptyDirPages deletes any pages that the plugin has published to in this run // that are empty directories func (s *space) deleteEmptyDirPages() (err error) { - for key, page := range s.publishedPages { - if s.isEmptyDir(page) { + for s.hasEmptyDirPages() { + for key, page := range s.emptyDirPages() { err = s.apiClient.DeletePage(page.id) if err != nil { return err @@ -144,6 +144,22 @@ func (s *space) deleteEmptyDirPages() (err error) { return nil } +func (s *space) hasEmptyDirPages() bool { + return len(s.emptyDirPages()) > 0 +} + +func (s *space) emptyDirPages() map[string]page { + emptyDirPages := make(map[string]page) + + for key, page := range s.publishedPages { + if s.isEmptyDir(page) { + emptyDirPages[key] = page + } + } + + return emptyDirPages +} + func (s *space) isEmptyDir(p page) bool { return p.isDir && s.isChildless(p) } diff --git a/plugin.json b/plugin.json index 59ed765..dc82074 100644 --- a/plugin.json +++ b/plugin.json @@ -1,6 +1,6 @@ { "id": "confluence", - "version": "0.13.2", + "version": "0.13.3", "name": "Confluence", "description": "Publishes Gauge specifications to Confluence", "install": {