Skip to content
This repository has been archived by the owner on Dec 11, 2024. It is now read-only.

Commit

Permalink
Fix bug: nested empty dirs are no longer published (#43)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
johnboyes authored Aug 26, 2021
1 parent 00cd056 commit 91ca3b8
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 12 deletions.
40 changes: 31 additions & 9 deletions functional-tests/specs/do_not_publish_concepts.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
20 changes: 18 additions & 2 deletions internal/confluence/space.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "confluence",
"version": "0.13.2",
"version": "0.13.3",
"name": "Confluence",
"description": "Publishes Gauge specifications to Confluence",
"install": {
Expand Down

0 comments on commit 91ca3b8

Please sign in to comment.