Class: Lazylead::Confluence

Inherits:
Object
  • Object
show all
Defined in:
lib/lazylead/confluence.rb

Overview

Represents single Confluence instance.

Author

Yurii Dubinka ([email protected])

Copyright

Copyright © 2019-2020 Yurii Dubinka

License

MIT

Instance Method Summary collapse

Constructor Details

#initialize(conf) ⇒ Confluence

Returns a new instance of Confluence.



35
36
37
38
39
40
# File 'lib/lazylead/confluence.rb', line 35

def initialize(conf)
  @conf = conf
  @http = Faraday.new(url: @conf.url) do |conn|
    conn.request :authorization, :basic, @conf.user, @conf.pass
  end
end

Instance Method Details

#fetch_page_id(space, title) ⇒ Object

TODO:

#/DEV Unable to find confluence pages where title has “:” symbol. The symbol “:” might be replaced by “%3A”. The search needs to consider this case as well.

Fetch the page url with pageId (Atlassian global id)

using confluence space name and page title.

Returns:



73
74
75
76
77
78
79
80
81
# File 'lib/lazylead/confluence.rb', line 73

def fetch_page_id(space, title)
  resp = @http.get(
    "/rest/api/content", limit: 1, spaceKey: space, title: title
  ).body
  return "" if resp.blank?
  pages = JSON.parse(resp)
  return "" if pages["results"].empty?
  "#{@conf.url}/pages/viewpage.action?pageId=#{pages['results'].first['id']}"
end

Construct the remote link from Jira ticket to Confluence page. Read more:

- https://bit.ly/2zkfTwB
- https://bit.ly/2zk8iOB
- https://bit.ly/3bkGkiU


54
55
56
57
58
59
60
61
# File 'lib/lazylead/confluence.rb', line 54

def make_link(url, type = "Wiki Page")
  {
    globalId: "appId=#{@conf.app}&pageId=#{url[/pageId=(?<id>\d+)/, 1]}",
    application: { type: @conf.type, name: @conf.name },
    relationship: type,
    object: { url: url, title: type }
  }
end

#urlObject

Confluence instance url like

http://confluence.com
https://confluence.com


45
46
47
# File 'lib/lazylead/confluence.rb', line 45

def url
  @conf.url
end