supportal 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/supportal.rb +14 -0
- data/lib/supportal/confluence.rb +54 -0
- data/lib/supportal/jira.rb +36 -0
- data/lib/supportal/logger.rb +14 -0
- data/lib/supportal/request.rb +33 -0
- metadata +52 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 35fe1d810b986f714fbbe8df443eed1819974c22
|
4
|
+
data.tar.gz: ed8be9f450918e54455dc9a5038bf380b87cb499
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f94ccf38046e1604f96a2f01e88d5e160ef91dcf7c75794b1a7cf91e1c85c40ec7dd596ec4f0aaddca80b472f0d294d2258ca8589b01a7da5c038cf6e7284dd6
|
7
|
+
data.tar.gz: f43bd064f1c6018eeaa8a718022c89976220d1662f6178999ae36878b0c4c780d6b0081e4acd16eb8bfd06b5128ee99fccf4656c685047dfdf4f442cdf3ced57
|
data/lib/supportal.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
class Supportal
|
2
|
+
# jiras is an array of ojects with the properties: username, password, instance, query
|
3
|
+
def self.fetch_from_multiple_jiras(jiras)
|
4
|
+
jiras.map do |jira_config|
|
5
|
+
issues = JIRA.new(jira_config[:username], jira_config[:password], jira_config[:instance]).fetch_issues(jira_config[:query])
|
6
|
+
end.flatten!
|
7
|
+
end
|
8
|
+
|
9
|
+
end
|
10
|
+
|
11
|
+
require 'supportal/confluence'
|
12
|
+
require 'supportal/jira'
|
13
|
+
require 'supportal/logger'
|
14
|
+
require 'supportal/request'
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
|
3
|
+
class Supportal::Confluence
|
4
|
+
|
5
|
+
def initialize(user, pass, instance)
|
6
|
+
@host = instance
|
7
|
+
@user = user
|
8
|
+
@pass = pass
|
9
|
+
end
|
10
|
+
|
11
|
+
def strip_tags(str)
|
12
|
+
# TODO: Do this properly.
|
13
|
+
str.gsub(/<\/?[^>]*>/, ' ')
|
14
|
+
end
|
15
|
+
|
16
|
+
def content_type_filter(type)
|
17
|
+
type.sub(/com\.atlassian\.confluence\.plugins\.confluence\-questions:.*/, 'question')
|
18
|
+
end
|
19
|
+
|
20
|
+
def highlight_filter(str)
|
21
|
+
strip_tags(str).gsub(/@@@hl@@@/, '<strong>').gsub(/@@@endhl@@@/, '</strong>')
|
22
|
+
end
|
23
|
+
|
24
|
+
def fetch_latest_blog_posts(limit, space)
|
25
|
+
trim_to = 300 # Trim body of blog post to first X characters.
|
26
|
+
path = '/rest/api/content/search?cql='
|
27
|
+
cql = 'space=' + space + '+AND+type=blogpost+order+by+created+desc&limit=' + limit.to_i.to_s + '&expand=body.export_view,version'
|
28
|
+
posts = Supportal::Request.get_json(@host + path + cql, @user, @pass)
|
29
|
+
posts['results'].map do |post|
|
30
|
+
{
|
31
|
+
heading: highlight_filter(post['title']),
|
32
|
+
body: strip_tags(post['body']['export_view']['value'])[0, trim_to] + '...',
|
33
|
+
link: @host + post['_links']['webui'],
|
34
|
+
date: post['version']['when']
|
35
|
+
}
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def search(str, root_doc_page_ids, space, label)
|
40
|
+
root_page_cql = root_doc_page_ids.map { |root_page| "(container=#{root_page} OR ancestor=#{root_page})" }.join(" OR ")
|
41
|
+
path = '/rest/api/search?limit=10&expand=version&cql='
|
42
|
+
cql = CGI.escape("text~\"#{str}\" AND (space=#{space} OR label=\"#{label}\") AND (((#{root_page_cql}) AND (type=blogpost OR type=page OR type=comment)) OR (type=\"com.atlassian.confluence.plugins.confluence-questions:question\" OR type=\"com.atlassian.confluence.plugins.confluence-questions:answer\"))")
|
43
|
+
body = Supportal::Request.get_json(@host + path + cql, @user, @pass)
|
44
|
+
body['results'].map do |result|
|
45
|
+
{
|
46
|
+
title: highlight_filter(result['title']),
|
47
|
+
link: @host + result['url'],
|
48
|
+
date: result['lastModified'],
|
49
|
+
type: content_type_filter(result['content']['type'])
|
50
|
+
}
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
|
3
|
+
class Supportal::JIRA
|
4
|
+
|
5
|
+
def initialize(user, pass, instance)
|
6
|
+
@host = instance
|
7
|
+
@user = user
|
8
|
+
@pass = pass
|
9
|
+
@search = '/rest/api/2/search'
|
10
|
+
end
|
11
|
+
|
12
|
+
def fetch_issues(query)
|
13
|
+
path = @search + '?fields=key,summary&jql='
|
14
|
+
jql = CGI.escape(query)
|
15
|
+
issues = Supportal::Request.get_json(@host + path + jql, @user, @pass)
|
16
|
+
issues['issues'].map do |issue|
|
17
|
+
{
|
18
|
+
key: issue['key'],
|
19
|
+
summary: issue['fields']['summary']
|
20
|
+
}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def fetch_changelogs(query, changelog_field_id)
|
25
|
+
path = @search + "?fields=key,customfield_#{changelog_field_id}&jql="
|
26
|
+
jql = CGI.escape(query)
|
27
|
+
issues = Supportal::Request.get_json(@host + path + jql, @user, @pass)
|
28
|
+
issues['issues'].map do |issue|
|
29
|
+
{
|
30
|
+
key: issue['key'],
|
31
|
+
changelog: issue['fields']["customfield_#{changelog_field_id}"]
|
32
|
+
}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'logger'
|
3
|
+
|
4
|
+
class Supportal::MicrosLogger
|
5
|
+
|
6
|
+
def self.create(stream)
|
7
|
+
logger = Logger.new(stream)
|
8
|
+
logger.formatter = proc do |severity, datetime, progname, msg|
|
9
|
+
{ time: datetime, type: severity, message: msg }.to_json + "\n"
|
10
|
+
end
|
11
|
+
return logger
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'net/http'
|
3
|
+
require 'net/https'
|
4
|
+
require 'uri'
|
5
|
+
|
6
|
+
class Supportal::Request
|
7
|
+
|
8
|
+
def self.get(url, user, pass)
|
9
|
+
logger = Supportal::MicrosLogger.create(STDOUT)
|
10
|
+
logger.level = Logger::DEBUG # FIXME
|
11
|
+
uri = URI(url)
|
12
|
+
logger.debug("Opening connection to: #{uri.host}")
|
13
|
+
http = Net::HTTP.new(uri.host, 443)
|
14
|
+
http.use_ssl = true
|
15
|
+
logger.debug("Requesting: #{url}")
|
16
|
+
request = Net::HTTP::Get.new(url)
|
17
|
+
request.basic_auth(user, pass)
|
18
|
+
body = false
|
19
|
+
begin
|
20
|
+
http.request(request) do |response|
|
21
|
+
body = response.body
|
22
|
+
end
|
23
|
+
rescue Exception => e
|
24
|
+
logger.error("Error '#{e}' when downloading: #{url}")
|
25
|
+
end
|
26
|
+
return body
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.get_json(url, user, pass)
|
30
|
+
JSON.parse(self.get(url, user, pass))
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: supportal
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michael Knight
|
8
|
+
- Lachlan Dally
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2017-07-18 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: A library for pulling information from JIRA and Confluence for service
|
15
|
+
entrypoints
|
16
|
+
email:
|
17
|
+
- mknight@atlassian.com
|
18
|
+
- ldally@atlassian.com
|
19
|
+
executables: []
|
20
|
+
extensions: []
|
21
|
+
extra_rdoc_files: []
|
22
|
+
files:
|
23
|
+
- lib/supportal.rb
|
24
|
+
- lib/supportal/confluence.rb
|
25
|
+
- lib/supportal/jira.rb
|
26
|
+
- lib/supportal/logger.rb
|
27
|
+
- lib/supportal/request.rb
|
28
|
+
homepage:
|
29
|
+
licenses:
|
30
|
+
- MIT
|
31
|
+
metadata: {}
|
32
|
+
post_install_message:
|
33
|
+
rdoc_options: []
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
requirements: []
|
47
|
+
rubyforge_project:
|
48
|
+
rubygems_version: 2.5.2
|
49
|
+
signing_key:
|
50
|
+
specification_version: 4
|
51
|
+
summary: Supportal
|
52
|
+
test_files: []
|