Class: Aircana::Contexts::Confluence

Inherits:
Object
  • Object
show all
Includes:
ConfluenceContent, ConfluenceHttp, ConfluenceLogging, ConfluenceSetup, HTTParty
Defined in:
lib/aircana/contexts/confluence.rb

Constant Summary collapse

LABEL_PREFIX =
"global"

Instance Method Summary collapse

Methods included from ConfluenceSetup

#setup_httparty

Methods included from ConfluenceContent

#convert_to_markdown, #fetch_page_content, #log_pages_found, #preprocess_confluence_macros, #store_page_as_markdown

Methods included from ConfluenceHttp

#get_next_page_url, #get_page_content, #get_pages_for_label, #validate_response

Constructor Details

#initializeConfluence

Returns a new instance of Confluence.



23
24
25
# File 'lib/aircana/contexts/confluence.rb', line 23

def initialize
  @local_storage = Local.new
end

Instance Method Details

#fetch_pages_for(kb_name:, kb_type: "local", label: nil) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/aircana/contexts/confluence.rb', line 27

def fetch_pages_for(kb_name:, kb_type: "local", label: nil)
  validate_configuration!
  setup_httparty

  label_to_search = label || kb_name
  pages = search_and_log_pages(label_to_search)
  return { pages_count: 0, sources: [] } if pages.empty?

  sources = process_pages_with_manifest(pages, kb_name, kb_type)
  create_or_update_manifest(kb_name, sources, kb_type)

  { pages_count: pages.size, sources: sources }
end

#process_pages(pages, kb_name, kb_type = "local") ⇒ Object



73
74
75
76
77
# File 'lib/aircana/contexts/confluence.rb', line 73

def process_pages(pages, kb_name, kb_type = "local")
  ProgressTracker.with_batch_progress(pages, "Processing pages") do |page, _index|
    store_page_as_markdown(page, kb_name, kb_type)
  end
end

#process_pages_with_manifest(pages, kb_name, kb_type = "local") ⇒ Object



79
80
81
82
83
84
85
86
87
88
# File 'lib/aircana/contexts/confluence.rb', line 79

def process_pages_with_manifest(pages, kb_name, kb_type = "local")
   = []

  ProgressTracker.with_batch_progress(pages, "Processing pages") do |page, _index|
    store_page_as_markdown(page, kb_name, kb_type)
     << (page)
  end

  (kb_name, )
end

#refresh_from_manifest(kb_name:) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/aircana/contexts/confluence.rb', line 41

def refresh_from_manifest(kb_name:)
  sources = Manifest.sources_from_manifest(kb_name)
  kb_type = Manifest.kb_type_from_manifest(kb_name)
  return { pages_count: 0, sources: [] } if sources.empty?

  validate_configuration!
  setup_httparty

  confluence_sources = sources.select { |s| s["type"] == "confluence" }
  return { pages_count: 0, sources: [] } if confluence_sources.empty?

  all_pages = []
  confluence_sources.each do |source|
    pages = fetch_pages_from_source(source)
    all_pages.concat(pages)
  end

  return { pages_count: 0, sources: [] } if all_pages.empty?

  updated_sources = process_pages_with_manifest(all_pages, kb_name, kb_type)

  { pages_count: all_pages.size, sources: updated_sources }
end

#search_and_log_pages(label) ⇒ Object



65
66
67
68
69
70
71
# File 'lib/aircana/contexts/confluence.rb', line 65

def search_and_log_pages(label)
  pages = ProgressTracker.with_spinner("Searching for pages labeled '#{label}'") do
    fetch_pages_by_label(label)
  end
  log_pages_found(pages.size, label)
  pages
end