confluencer 0.1.2 → 0.1.3

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.
data/.gitignore CHANGED
@@ -19,3 +19,4 @@ rdoc
19
19
  pkg
20
20
 
21
21
  ## PROJECT::SPECIFIC
22
+ config/*.yaml
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.1.3
@@ -0,0 +1,7 @@
1
+ # confluencer external configuration example
2
+
3
+ # Confluence configuration
4
+ :confluence:
5
+ :url: http://confluence.acmecorp.com
6
+ :username: roger
7
+ :password: jessica
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{confluencer}
8
- s.version = "0.1.2"
8
+ s.version = "0.1.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Gabor Ratky"]
12
- s.date = %q{2010-05-03}
12
+ s.date = %q{2010-05-04}
13
13
  s.description = %q{ActiveRecord-like classes that map to Confluence entities and useful scripts that automate tasks}
14
14
  s.email = %q{rgabo@rgabostyle.com}
15
15
  s.executables = ["confluencer", "confluencer-bookmarks"]
@@ -27,8 +27,10 @@ Gem::Specification.new do |s|
27
27
  "VERSION",
28
28
  "bin/confluencer",
29
29
  "bin/confluencer-bookmarks",
30
+ "config/confluencer.yaml.example",
30
31
  "confluencer.gems",
31
32
  "confluencer.gemspec",
33
+ "lib/confluence/blog_entry.rb",
32
34
  "lib/confluence/bookmark.rb",
33
35
  "lib/confluence/client.rb",
34
36
  "lib/confluence/page.rb",
@@ -0,0 +1,17 @@
1
+ module Confluence
2
+ class BlogEntry < Record
3
+ record_attr_accessor :id => :entry_id
4
+ record_attr_accessor :space
5
+ record_attr_accessor :title, :content
6
+ record_attr_accessor :publishDate
7
+ record_attr_accessor :url
8
+
9
+ def self.find_by_id(entryid)
10
+ self.new(client.getBlogEntries(entryid))
11
+ end
12
+
13
+ def self.find_by_space(spacekey)
14
+ client.getBlogEntries(spacekey).collect {|summary| BlogEntry.new(client.getBlogEntry(summary["id"]))}
15
+ end
16
+ end
17
+ end
@@ -2,18 +2,35 @@ module Confluence
2
2
  class Bookmark < Page
3
3
  BOOKMARKS_PAGE_TITLE = ".bookmarks"
4
4
 
5
+ attr_reader :bookmark_url, :description
6
+
5
7
  def initialize(hash)
6
8
  super(hash)
9
+
10
+ # parse bookmark_url and description out of content
11
+ @bookmark_url = content[/\{bookmark:url=([^\}]+)\}/, 1] if content
12
+ @description = content[/\{bookmark.*\}([^\{]*)\{bookmark\}/, 1] if content
13
+ end
14
+
15
+ def bookmark_url=(value)
16
+ @bookmark_url = value
17
+
18
+ # update content with new bookmark_url
19
+ update_content
7
20
  end
8
21
 
9
- def bookmark_url
10
- # return url portion of {bookmark} macro in content
11
- content[/\{bookmark:url=([^\}]+)\}/, 1]
22
+ def description=(value)
23
+ @description = value
24
+
25
+ # update content with new description
26
+ update_content
12
27
  end
13
28
 
14
- def description
15
- # return description portion of {bookmark} macro in content
16
- content[/\{bookmark.*\}([^\{]*)\{bookmark\}/, 1]
29
+ def store
30
+ # always set .bookmarks as the parent page
31
+ parent_id = Page.find_by_title(space, BOOKMARKS_PAGE_TITLE).page_id
32
+
33
+ super
17
34
  end
18
35
 
19
36
  def self.find_by_space(spacekey)
@@ -23,5 +40,11 @@ module Confluence
23
40
  # map each page to a Bookmark
24
41
  bookmarks_page.children.collect {|page| Bookmark.new(page.attributes)}
25
42
  end
43
+
44
+ private
45
+
46
+ def update_content
47
+ self.content = "{bookmark:url=#{@bookmark_url}}#{@description}{bookmark}"
48
+ end
26
49
  end
27
50
  end
@@ -8,6 +8,7 @@ require 'confluence/client'
8
8
  require 'confluence/record'
9
9
  require 'confluence/page'
10
10
  require 'confluence/bookmark'
11
+ require 'confluence/blog_entry'
11
12
 
12
13
  module Confluencer
13
14
  autoload :App, 'confluencer/app'
@@ -1,36 +1,40 @@
1
1
  require 'rubygems'
2
2
  require 'thor'
3
+ require 'yaml'
3
4
 
4
5
  module Confluencer
5
6
  class App < Thor
6
7
  attr_reader :token
7
-
8
+
8
9
  # -v, --verbose
9
10
  class_option :verbose, :desc => "Verbose output", :type => :boolean, :default => false, :aliases => "-v"
10
11
 
11
- # XMLRPC url and authentication
12
- class_option :url, :type => :string, :required => false, :group => "Confluence", :desc => "URL where Confluence is available"
13
- class_option :username, :type => :string, :required => false, :aliases => "-u", :group => "Confluence", :desc => "Confluence username"
14
- class_option :password, :type => :string, :required => false, :aliases => "-p", :group => "Confluence", :desc => "Confluence password"
15
-
12
+ # external configuration
13
+ class_option :config, :type => :string, :aliases => "-c", :desc => "Confluence configuration", :default => "config/confluencer.yaml"
14
+ class_option :instance, :type => :string, :aliases => "-i", :desc => "Name of the Confluence instance", :default => "confluence"
16
15
  # explicitly specify default_task => :help
17
16
  default_task :help
18
17
 
19
18
  desc "login", "Logs in and verifies the Confluence account"
20
- def login
19
+ def login
20
+ raise Thor::Error, "Required configuration 'username' missing." unless configuration.key? :username
21
+ raise Thor::Error, "Required configuration 'password' missing." unless configuration.key? :password
22
+
21
23
  with_confluence do |confluence|
22
- @token = confluence.login(options[:username], options[:password])
24
+ @token = confluence.login(configuration[:username], configuration[:password])
23
25
  end
24
26
  end
25
27
 
26
28
  private
27
29
 
30
+ def configuration
31
+ @configuration ||= YAML::load(File.open(options[:config]))[options[:instance].to_sym]
32
+ end
33
+
28
34
  def with_confluence(&block)
29
- raise Thor::Error, "Required option '--url' missing." unless options.url?
30
- raise Thor::Error, "Required option '--username' missing." unless options.username?
31
- raise Thor::Error, "Required option '--password' missing." unless options.password?
35
+ raise Thor::Error, "Required configuration 'url' missing." unless configuration.key? :url
32
36
 
33
- client = Confluence::Client.new(:url => options[:url], :token => @token)
37
+ client = Confluence::Client.new(:url => configuration[:url], :token => @token)
34
38
 
35
39
  begin
36
40
  # Record objects should use this clent
@@ -18,48 +18,55 @@ module Confluencer
18
18
  end
19
19
  end
20
20
 
21
- method_option :parent, :type => :string, :default => "Bookmarks", :desc => "Parent page for the pages created", :required => true
22
- method_option :template, :type => :string, :desc => "ERB template to use", :required => true
21
+ method_option :parent, :type => :string, :default => "Bookmarks", :desc => "Parent page for the pages created"
22
+ method_option :template, :type => :string, :desc => "ERB template to use", :required => :true
23
23
  desc "create-pages SPACEKEY", "Creates pages for every bookmark"
24
24
  def create_pages(spacekey)
25
25
  invoke :login
26
-
26
+
27
27
  with_confluence do
28
- begin
29
- # get parent page
30
- parent_page = Confluence::Page.find_by_title(spacekey, options[:parent])
31
- rescue RuntimeError
32
- # page does not exist yet, create it
33
- parent_page = Confluence::Page.new :space => spacekey, :title => options[:parent], :content => ""
34
- parent_page.store
35
- end
36
-
37
- # grab the title of all existing pages
38
- existing_titles = parent_page.children.collect {|page| page.title }
39
-
40
- # grab all bookmarks from space
41
- bookmarks = Confluence::Bookmark.find_by_space(spacekey)
42
-
43
- # initialize ERB template
44
- template = ERB.new(IO.read(options[:template])) unless bookmarks.empty?
45
-
46
28
  # add a page for each bookmark, remove bookmark in the process
47
- bookmarks.each do |bookmark|
29
+ bookmarks(spacekey).each do |bookmark|
48
30
  puts bookmark.title
49
31
 
50
32
  labels = bookmark.labels << "bookmark"
51
33
 
52
- page = Confluence::Page.new :space => spacekey, :parentId => parent_page.page_id, :title => bookmark.title
34
+ page = Confluence::Page.new :space => spacekey, :parentId => parent_page(spacekey).page_id, :title => bookmark.title
53
35
  page.content = template.result(binding)
54
36
 
55
37
  # remove bookmark before storing page with same title
56
38
  bookmark.remove
57
39
  page.store
58
40
 
59
- # update labels
60
- page.labels = labels
41
+ # update labels, add bookmark
42
+ page.labels = labels << "bookmark"
43
+ end
44
+ end
45
+ end
46
+
47
+ private
48
+
49
+ def bookmarks(spacekey)
50
+ Confluence::Bookmark.find_by_space(spacekey)
51
+ end
52
+
53
+ def parent_page(spacekey)
54
+ @parent_pages[spacekey] ||= begin
55
+ unless @parent_pages[spacekey]
56
+ begin
57
+ # get parent page
58
+ @parent_pages[spacekey] = Confluence::Page.find_by_title(spacekey, options[:parent])
59
+ rescue RuntimeError
60
+ # page does not exist yet, create it
61
+ @parent_pages[spacekey] = Confluence::Page.new :space => spacekey, :title => options[:parent], :content => ""
62
+ @parent_pages[spacekey].store
63
+ end
61
64
  end
62
65
  end
63
66
  end
67
+
68
+ def template
69
+ @template ||= ERB.new(IO.read(options[:template]))
70
+ end
64
71
  end
65
72
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 2
9
- version: 0.1.2
8
+ - 3
9
+ version: 0.1.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Gabor Ratky
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-05-03 00:00:00 +02:00
17
+ date: 2010-05-04 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -65,8 +65,10 @@ files:
65
65
  - VERSION
66
66
  - bin/confluencer
67
67
  - bin/confluencer-bookmarks
68
+ - config/confluencer.yaml.example
68
69
  - confluencer.gems
69
70
  - confluencer.gemspec
71
+ - lib/confluence/blog_entry.rb
70
72
  - lib/confluence/bookmark.rb
71
73
  - lib/confluence/client.rb
72
74
  - lib/confluence/page.rb