phabricator 0.0.4 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- phabricator (0.0.1)
4
+ phabricator (0.0.5)
5
5
  rest-client
6
6
 
7
7
  GEM
@@ -23,7 +23,6 @@ GEM
23
23
  powerbar (1.0.11)
24
24
  ansi (~> 1.4.0)
25
25
  hashie (>= 1.1.0)
26
- rake (10.2.2)
27
26
  rest-client (1.6.7)
28
27
  mime-types (>= 1.16)
29
28
 
@@ -36,4 +35,3 @@ DEPENDENCIES
36
35
  minitest-reporters
37
36
  mocha
38
37
  phabricator!
39
- rake
data/README.md CHANGED
@@ -16,4 +16,38 @@ Or install it yourself as:
16
16
 
17
17
  ## Usage
18
18
 
19
- TODO (:
19
+ ### Configuration
20
+
21
+ You can configure Phabricator to use a specific host, user, and cert. Otherwise,
22
+ it will fall back to whatever is in your `~/.arcrc` file.
23
+
24
+ ```ruby
25
+ Phabricator.configure do |c|
26
+ c.host = 'secure.phabricator.com'
27
+ c.user = 'amber'
28
+ c.cert = '<CERT>'
29
+ end
30
+ ```
31
+
32
+ ### Projects
33
+
34
+ ```ruby
35
+ # Find the project given a project name.
36
+ Phabricator::Project.find_by_name('Project')
37
+ ```
38
+
39
+ ### Tasks
40
+
41
+ ```ruby
42
+ # Create a Maniphest task.
43
+ Phabricator::Maniphest::Task.create('title')
44
+
45
+ # Create a Maniphest task with more detail.
46
+ Phabricator::Maniphest::Task.create('title', 'description', ['Project'], 'normal')
47
+ ```
48
+
49
+ ### Contributing
50
+
51
+ Patches welcome! (:
52
+
53
+ For a list of Conduit methods available, see http://secure.phabricator.com/conduit.
@@ -1,5 +1,9 @@
1
- module Phabricator; end
1
+ require 'phabricator/config'
2
+ require 'phabricator/version'
2
3
 
3
- require_relative 'phabricator/version'
4
- require_relative 'phabricator/conduit_client'
5
- require_relative 'phabricator/maniphest'
4
+ module Phabricator
5
+ extend Phabricator::Config
6
+ end
7
+
8
+ require 'phabricator/conduit_client'
9
+ require 'phabricator/maniphest'
@@ -7,13 +7,16 @@ module Phabricator
7
7
  include Singleton
8
8
 
9
9
  def initialize
10
- # Find the .arcrc file for Phabricator credentials.
11
- filename = File.expand_path('~/.arcrc')
10
+ @host = Phabricator.host
11
+ @credentials = {
12
+ user: Phabricator.user,
13
+ cert: Phabricator.cert
14
+ }
12
15
 
13
- if File.readable?(filename)
14
- @settings = JSON.parse(File.read(filename))['hosts'].first
15
- else
16
- raise '~/.arcrc does not exist or is not readable.'
16
+ # The config is incomplete; try to get the credentials off the ~/.arcrc
17
+ # file instead.
18
+ if @host.nil? || @credentials.values.any? {|v| v.nil?}
19
+ get_credentials_from_file
17
20
  end
18
21
 
19
22
  connect
@@ -25,10 +28,10 @@ module Phabricator
25
28
  data = {
26
29
  client: 'phabricator-ruby',
27
30
  clientVersion: Phabricator::VERSION,
28
- user: credentials['user'],
29
- host: host,
31
+ user: @credentials[:user],
32
+ host: @host,
30
33
  authToken: token,
31
- authSignature: Digest::SHA1.hexdigest("#{token}#{credentials['cert']}")
34
+ authSignature: Digest::SHA1.hexdigest("#{token}#{@credentials[:cert]}")
32
35
  }
33
36
 
34
37
  response = JSON.parse(post('conduit.connect', data, __conduit__: true))
@@ -48,19 +51,29 @@ module Phabricator
48
51
 
49
52
  private
50
53
 
54
+ def get_credentials_from_file
55
+ filename = File.expand_path('~/.arcrc')
56
+
57
+ if File.readable?(filename)
58
+ settings = JSON.parse(File.read(filename))
59
+ user_settings = settings['hosts'].first
60
+
61
+ @host = settings['config']['phabricator.uri']
62
+ @credentials = {
63
+ user: user_settings[1]['user'],
64
+ cert: user_settings[1]['cert']
65
+ }
66
+ else
67
+ raise 'No credentials passed in, and ~/.arcrc does not exist or is \
68
+ not readable.'
69
+ end
70
+ end
71
+
51
72
  def post(method, data, opts={})
52
- RestClient.post("#{host}#{method}", {
73
+ RestClient.post("#{@host}/api/#{method}", {
53
74
  params: data.to_json,
54
75
  output: 'json'
55
76
  }.merge(opts))
56
77
  end
57
-
58
- def host
59
- @settings[0]
60
- end
61
-
62
- def credentials
63
- @settings[1]
64
- end
65
78
  end
66
79
  end
@@ -0,0 +1,9 @@
1
+ module Phabricator
2
+ module Config
3
+ attr_accessor :host, :user, :cert
4
+
5
+ def configure
6
+ yield self
7
+ end
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module Phabricator::Maniphest; end;
2
2
 
3
- require_relative 'maniphest/task'
3
+ require 'phabricator/maniphest/task'
@@ -1,5 +1,6 @@
1
- require_relative '../conduit_client'
2
- require_relative '../project'
1
+ require 'phabricator/conduit_client'
2
+ require 'phabricator/project'
3
+ require 'phabricator/user'
3
4
 
4
5
  module Phabricator::Maniphest
5
6
  class Task
@@ -27,12 +28,14 @@ module Phabricator::Maniphest
27
28
  attr_reader :id
28
29
  attr_accessor :title, :description, :priority
29
30
 
30
- def self.create(title, description=nil, projects=[], priority='normal', other={})
31
+ def self.create(title, description=nil, projects=[], priority='normal', owner=nil, ccs=[], other={})
31
32
  response = JSON.parse(client.request(:post, 'maniphest.createtask', {
32
33
  title: title,
33
34
  description: description,
34
35
  priority: Priority.send(priority),
35
- projectPHIDs: projects.map {|p| Phabricator::Project.find_by_name(p).phid }
36
+ projectPHIDs: projects.map {|p| Phabricator::Project.find_by_name(p).phid },
37
+ ownerPHID: owner ? Phabricator::User.find_by_name(owner).phid : nil,
38
+ ccPHIDs: ccs.map {|c| Phabricator::User.find_by_name(c).phid }
36
39
  }.merge(other)))
37
40
 
38
41
  data = response['result']
@@ -1,4 +1,4 @@
1
- require_relative './conduit_client'
1
+ require 'phabricator/conduit_client'
2
2
 
3
3
  module Phabricator
4
4
  class Project
@@ -17,7 +17,9 @@ module Phabricator
17
17
  end
18
18
 
19
19
  def self.find_by_name(name)
20
- populate_all if @@cached_projects.empty?
20
+ # Re-populate if we couldn't find it in the cache (this applies to
21
+ # if the cache is empty as well).
22
+ populate_all unless @@cached_projects[name]
21
23
 
22
24
  @@cached_projects[name]
23
25
  end
@@ -0,0 +1,39 @@
1
+ require 'phabricator/conduit_client'
2
+
3
+ module Phabricator
4
+ class User
5
+ @@cached_users = {}
6
+
7
+ attr_reader :phid
8
+ attr_accessor :name
9
+
10
+ def self.populate_all
11
+ response = JSON.parse(client.request(:post, 'user.query'))
12
+
13
+ response['result'].each do |data|
14
+ user = User.new(data)
15
+ @@cached_users[user.name] = user
16
+ end
17
+
18
+ end
19
+
20
+ def self.find_by_name(name)
21
+ # Re-populate if we couldn't find it in the cache (this applies to
22
+ # if the cache is empty as well).
23
+ populate_all unless @@cached_users[name]
24
+
25
+ @@cached_users[name]
26
+ end
27
+
28
+ def initialize(attributes)
29
+ @phid = attributes['phid']
30
+ @name = attributes['userName']
31
+ end
32
+
33
+ private
34
+
35
+ def self.client
36
+ @client ||= Phabricator::ConduitClient.instance
37
+ end
38
+ end
39
+ end
@@ -1,3 +1,3 @@
1
1
  module Phabricator
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.7"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phabricator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-03-28 00:00:00.000000000 Z
12
+ date: 2014-04-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
@@ -104,9 +104,11 @@ files:
104
104
  - README.md
105
105
  - lib/phabricator.rb
106
106
  - lib/phabricator/conduit_client.rb
107
+ - lib/phabricator/config.rb
107
108
  - lib/phabricator/maniphest.rb
108
109
  - lib/phabricator/maniphest/task.rb
109
110
  - lib/phabricator/project.rb
111
+ - lib/phabricator/user.rb
110
112
  - lib/phabricator/version.rb
111
113
  - phabricator.gemspec
112
114
  - test/_lib.rb