phabricator 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,39 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ phabricator (0.0.1)
5
+ rest-client
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ansi (1.4.3)
11
+ builder (3.2.2)
12
+ hashie (2.0.5)
13
+ metaclass (0.0.4)
14
+ mime-types (2.2)
15
+ minitest (4.7.5)
16
+ minitest-reporters (0.14.24)
17
+ ansi
18
+ builder
19
+ minitest (>= 2.12, < 5.0)
20
+ powerbar
21
+ mocha (1.0.0)
22
+ metaclass (~> 0.0.1)
23
+ powerbar (1.0.11)
24
+ ansi (~> 1.4.0)
25
+ hashie (>= 1.1.0)
26
+ rake (10.2.2)
27
+ rest-client (1.6.7)
28
+ mime-types (>= 1.16)
29
+
30
+ PLATFORMS
31
+ ruby
32
+
33
+ DEPENDENCIES
34
+ bundler (~> 1.3)
35
+ minitest (< 5.0)
36
+ minitest-reporters
37
+ mocha
38
+ phabricator!
39
+ rake
@@ -1,4 +1,5 @@
1
- require "phabricator/version"
1
+ module Phabricator; end
2
2
 
3
- module Phabricator
4
- end
3
+ require_relative 'phabricator/version'
4
+ require_relative 'phabricator/conduit_client'
5
+ require_relative 'phabricator/maniphest'
@@ -0,0 +1,66 @@
1
+ require 'json'
2
+ require 'singleton'
3
+ require 'rest-client'
4
+
5
+ module Phabricator
6
+ class ConduitClient
7
+ include Singleton
8
+
9
+ def initialize
10
+ # Find the .arcrc file for Phabricator credentials.
11
+ filename = File.expand_path('~/.arcrc')
12
+
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.'
17
+ end
18
+
19
+ connect
20
+ end
21
+
22
+ def connect
23
+ token = Time.now.to_i
24
+
25
+ data = {
26
+ client: 'phabricator-ruby',
27
+ clientVersion: Phabricator::VERSION,
28
+ user: credentials['user'],
29
+ host: host,
30
+ authToken: token,
31
+ authSignature: Digest::SHA1.hexdigest("#{token}#{credentials['cert']}")
32
+ }
33
+
34
+ response = JSON.parse(post('conduit.connect', data, __conduit__: true))
35
+
36
+ # TODO: Something something error handling
37
+
38
+ @conduit = {
39
+ connectionID: response['result']['connectionID'],
40
+ sessionKey: response['result']['sessionKey']
41
+ }
42
+ end
43
+
44
+ def request(http_method, method, data={})
45
+ # TODO: validation on http_method
46
+ self.send(http_method, method, data.merge(__conduit__: @conduit))
47
+ end
48
+
49
+ private
50
+
51
+ def post(method, data, opts={})
52
+ RestClient.post("#{host}#{method}", {
53
+ params: data.to_json,
54
+ output: 'json'
55
+ }.merge(opts))
56
+ end
57
+
58
+ def host
59
+ @settings[0]
60
+ end
61
+
62
+ def credentials
63
+ @settings[1]
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,3 @@
1
+ module Phabricator::Maniphest; end;
2
+
3
+ require_relative 'maniphest/task'
@@ -0,0 +1,55 @@
1
+ require_relative '../conduit_client'
2
+
3
+ module Phabricator::Maniphest
4
+ class Task
5
+ module Priority
6
+ # TODO: Make these priority values actually correct, or figure out
7
+ # how to pull these programmatically.
8
+ PRIORITIES = {
9
+ unbreak_now: 100,
10
+ needs_triage: 90,
11
+ high: 80,
12
+ normal: 50,
13
+ low: 25,
14
+ wishlist: 0
15
+ }
16
+
17
+ PRIORITIES.each do |priority, value|
18
+ define_method(priority) do
19
+ value
20
+ end
21
+ end
22
+ end
23
+
24
+ attr_reader :id
25
+ attr_accessor :title, :description, :priority
26
+
27
+ def self.create(title, description=nil, projects=[], priority='normal', other={})
28
+ response = JSON.parse(client.request(:post, 'maniphest.createtask', {
29
+ title: title,
30
+ description: description,
31
+ priority: Priority.send(priority),
32
+ projectPHIDs: projects.map {|p| Phabricator::Project.find_by_name(p).phid }
33
+ }.merge(other)))
34
+
35
+ data = response['result']
36
+
37
+ # TODO: Error handling
38
+
39
+ self.new(data)
40
+ end
41
+
42
+ def initialize(attributes)
43
+ @id = attributes['id']
44
+ @title = attributes['title']
45
+ @description = attributes['description']
46
+ @priority = attributes['priority']
47
+ end
48
+
49
+ private
50
+
51
+ def self.client
52
+ @client ||= Phabricator::ConduitClient.instance
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,37 @@
1
+ require_relative './conduit_client'
2
+
3
+ module Phabricator
4
+ class Project
5
+ @@cached_projects = {}
6
+
7
+ attr_reader :id, :phid
8
+ attr_accessor :name
9
+
10
+ def self.populate_all
11
+ response = JSON.parse(client.request(:post, 'project.query'))
12
+
13
+ response['result'].each do |phid, data|
14
+ project = Project.new(data)
15
+ @@cached_projects[project.name] = project
16
+ end
17
+ end
18
+
19
+ def self.find_by_name(name)
20
+ populate_all if @@cached_projects.empty?
21
+
22
+ @@cached_projects[name]
23
+ end
24
+
25
+ def initialize(attributes)
26
+ @id = attributes['id']
27
+ @phid = attributes['phid']
28
+ @name = attributes['name']
29
+ end
30
+
31
+ private
32
+
33
+ def self.client
34
+ @client ||= Phabricator::ConduitClient.instance
35
+ end
36
+ end
37
+ end
@@ -1,3 +1,3 @@
1
1
  module Phabricator
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -17,6 +17,9 @@ Gem::Specification.new do |spec|
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'rest-client'
22
+
20
23
  spec.add_development_dependency 'minitest', '< 5.0'
21
24
  spec.add_development_dependency 'minitest-reporters'
22
25
  spec.add_development_dependency 'mocha'
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.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,6 +11,22 @@ bindir: bin
11
11
  cert_chain: []
12
12
  date: 2014-03-28 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rest-client
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
14
30
  - !ruby/object:Gem::Dependency
15
31
  name: minitest
16
32
  requirement: !ruby/object:Gem::Requirement
@@ -99,9 +115,14 @@ extensions: []
99
115
  extra_rdoc_files: []
100
116
  files:
101
117
  - Gemfile
118
+ - Gemfile.lock
102
119
  - LICENSE.txt
103
120
  - README.md
104
121
  - lib/phabricator.rb
122
+ - lib/phabricator/conduit_client.rb
123
+ - lib/phabricator/maniphest.rb
124
+ - lib/phabricator/maniphest/task.rb
125
+ - lib/phabricator/project.rb
105
126
  - lib/phabricator/version.rb
106
127
  - phabricator.gemspec
107
128
  - test/_lib.rb