Class: Apadmi::Grout::CreateOrUpdateConfluencePageAction

Inherits:
Object
  • Object
show all
Defined in:
lib/apadmi/grout/actions/create_or_update_confluence_page_action.rb

Overview

Action for creating or updating a Confluence page

Instance Method Summary collapse

Constructor Details

#initialize(confluence_service, logger) ⇒ CreateOrUpdateConfluencePageAction

Returns a new instance of CreateOrUpdateConfluencePageAction.

Parameters:



9
10
11
12
# File 'lib/apadmi/grout/actions/create_or_update_confluence_page_action.rb', line 9

def initialize(confluence_service, logger)
  @confluence_service = confluence_service
  @logger = logger
end

Instance Method Details

#run(title, parent_id) {|String, nil| ... } ⇒ Apadmi::Grout::ConfluencePage

Parameters:

  • title (String)
  • parent_id (String)

Yields:

  • (String, nil)

    The current content of the page, or nil if it doesn’t exist.

Yield Returns:

  • (String)

    The new content for the page.

Returns:



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/apadmi/grout/actions/create_or_update_confluence_page_action.rb', line 19

def run(title, parent_id, &block)
  page = @confluence_service.get_page_by_title(title, parent_id)

  if page
    @logger.message("Found existing page: #{title} (ID: #{page.id})")
    new_content = block.call(page.page_contents)
    updated_page = @confluence_service.update_page(page.id, title, new_content, page.version["number"])
    @logger.success("Updated Confluence page: #{title}")
    updated_page
  else
    @logger.message("Page not found, creating: #{title}")
    parent_page = @confluence_service.get_page_by_id(parent_id)
    new_content = block.call(nil)
    created_page = @confluence_service.create_page(parent_page.space_id, parent_id, title, new_content)
    @logger.success("Created Confluence page: #{title}")
    created_page
  end
end