ellen-github 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4c849dc2b74f690e8f9bec2968d5dc257586c968
4
- data.tar.gz: fb81891c2819a3a6cca9d89659130890e1494b08
3
+ metadata.gz: 9daee4e66e51d6e4a8f8e7faba35609ca088e7ea
4
+ data.tar.gz: f6dc855d733ecaba80492406a3ef3c23ecd260ed
5
5
  SHA512:
6
- metadata.gz: 564707102b614e9321ccab7e724673f83700efee00a475f435aa886259f6003c3e3dd0d2e9b7e9554784debf06dd01609fcc1b0c4afd245cadb753575fef3b8d
7
- data.tar.gz: 40eeb7c04e55da2d1244edfbbcb8419ebf9bd608e1801703ed82a727788374b26e426af7bb828ce651fcc5a852e290b9f2c84008f201b958aa1cd4b6df32863b
6
+ metadata.gz: 1e23e91b34ae15f824f162ceadc9e8633adb3d621ca86c1c553c6476094bcb70e879f685e277a98eb5393582bd1bd0022956ccb588ecb1296d09b0fb58688cbc
7
+ data.tar.gz: 8f47fb7aee9b2990a732fa2f1088cb12a7c3105d6e75ed3355e7b212614837843e2c41856a7905517348d009ea4e9ce0107bbaa823d5c9957b7e8a3b3f0c5584
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 0.0.3
2
+ * Support Ellen v0.2.0
3
+
1
4
  ## 0.0.2
2
5
  * Memorize access token and use it to create a new issue
3
6
 
data/ellen-github.gemspec CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
16
16
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
17
  spec.require_paths = ["lib"]
18
18
 
19
- spec.add_dependency "ellen", ">= 0.1.3"
19
+ spec.add_dependency "ellen", ">= 0.2.0"
20
20
  spec.add_dependency "octokit"
21
21
  spec.add_development_dependency "bundler", "~> 1.6"
22
22
  spec.add_development_dependency "rake"
@@ -6,17 +6,16 @@ module Ellen
6
6
  class Base
7
7
  NAMESPACE = "github"
8
8
 
9
- attr_reader :message, :robot
9
+ attr_reader :message
10
10
 
11
- def initialize(options)
12
- @message = options[:message]
13
- @robot = options[:robot]
11
+ def initialize(message)
12
+ @message = message
14
13
  end
15
14
 
16
15
  private
17
16
 
18
17
  def access_tokens
19
- robot.brain.data[NAMESPACE] ||= {}
18
+ message.robot.brain.data[NAMESPACE] ||= {}
20
19
  end
21
20
 
22
21
  def sender_name
@@ -15,21 +15,21 @@ module Ellen
15
15
  private
16
16
 
17
17
  def require_access_token
18
- robot.say("I don't know your github access token")
18
+ message.reply("I don't know your github access token")
19
19
  end
20
20
 
21
21
  def created
22
- robot.say("Created a new Issue")
22
+ message.reply("Created a new Issue")
23
23
  end
24
24
 
25
25
  def create
26
- robot.say("Created #{issue.html_url}")
26
+ message.reply("Created #{issue.html_url}")
27
27
  rescue Octokit::Unauthorized
28
- robot.say("Failed in authentication (401)")
28
+ message.reply("Failed in authentication (401)")
29
29
  rescue Octokit::NotFound
30
- robot.say("Could not find that repository")
30
+ message.reply("Could not find that repository")
31
31
  rescue => exception
32
- robot.say("Failed (#{exception.class})")
32
+ message.reply("Failed by #{exception.class}")
33
33
  end
34
34
 
35
35
  def issue
@@ -2,13 +2,6 @@ module Ellen
2
2
  module Github
3
3
  module Actions
4
4
  class Remember < Base
5
- attr_reader :message, :robot
6
-
7
- def initialize(options)
8
- @message = options[:message]
9
- @robot = options[:robot]
10
- end
11
-
12
5
  def call
13
6
  remember
14
7
  report
@@ -17,7 +10,7 @@ module Ellen
17
10
  private
18
11
 
19
12
  def report
20
- robot.say("Remembered #{robot.name}'s github access token")
13
+ message.reply("Remembered #{sender_name}'s github access token")
21
14
  end
22
15
 
23
16
  def remember
@@ -1,5 +1,5 @@
1
1
  module Ellen
2
2
  module Github
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
@@ -6,11 +6,11 @@ module Ellen
6
6
  on(/remember my github token (?<token>.+)\z/, name: "remember", description: "Remember sender's GitHub access token")
7
7
 
8
8
  def create_issue(message)
9
- Ellen::Github::Actions::CreateIssue.new(message: message, robot: robot).call
9
+ Ellen::Github::Actions::CreateIssue.new(message).call
10
10
  end
11
11
 
12
12
  def remember(message)
13
- Ellen::Github::Actions::Remember.new(message: message, robot: robot).call
13
+ Ellen::Github::Actions::Remember.new(message).call
14
14
  end
15
15
  end
16
16
  end
@@ -2,14 +2,6 @@ require "spec_helper"
2
2
  require "json"
3
3
 
4
4
  describe Ellen::Handlers::Github do
5
- before do
6
- ENV["GITHUB_ACCESS_TOKEN"] = github_access_token
7
- end
8
-
9
- after do
10
- ENV["GITHUB_ACCESS_TOKEN"] = nil
11
- end
12
-
13
5
  let(:robot) do
14
6
  Ellen::Robot.new
15
7
  end
@@ -18,28 +10,21 @@ describe Ellen::Handlers::Github do
18
10
  "dummy"
19
11
  end
20
12
 
21
- describe "#initialize" do
22
- context "without GITHUB_ACCESS_TOKEN" do
23
- let(:github_access_token) do
24
- nil
25
- end
13
+ let(:sender) do
14
+ "bob"
15
+ end
26
16
 
27
- it "dies" do
28
- Ellen.should_receive(:die)
29
- described_class.new(robot)
30
- end
31
- end
17
+ let(:channel) do
18
+ "#general"
19
+ end
32
20
 
33
- context "with GITHUB_ACCESS_TOKEN" do
34
- it "does not die" do
35
- Ellen.should_not_receive(:die)
36
- described_class.new(robot)
37
- end
38
- end
21
+ let(:access_tokens) do
22
+ robot.brain.data[Ellen::Github::Actions::Base::NAMESPACE] ||= {}
39
23
  end
40
24
 
41
25
  describe "#create_issue" do
42
26
  before do
27
+ Ellen.logger.stub(:info)
43
28
  stub_request(:post, "https://api.github.com/repos/#{user}/#{repository}/issues").
44
29
  with(
45
30
  body: {
@@ -65,8 +50,50 @@ describe Ellen::Handlers::Github do
65
50
  "This is a test issue"
66
51
  end
67
52
 
68
- it "creates a new issue with given title on given repository" do
69
- robot.receive(body: %<ellen create issue "#{title}" on #{user}/#{repository}>)
53
+ let(:body) do
54
+ %<ellen create issue "#{title}" on #{user}/#{repository}>
55
+ end
56
+
57
+ context "when access token for the sender is remembered" do
58
+ before do
59
+ access_tokens.merge!(sender => github_access_token)
60
+ end
61
+
62
+ it "creates a new issue with given title on given repository" do
63
+ robot.receive(
64
+ body: body,
65
+ from: sender,
66
+ to: channel,
67
+ )
68
+ a_request(:any, //).should have_been_made
69
+ end
70
+ end
71
+
72
+ context "when access token for the sender is not remembered" do
73
+ it "does not create a new issue" do
74
+ robot.receive(
75
+ body: body,
76
+ from: sender,
77
+ to: channel,
78
+ )
79
+ a_request(:any, //).should_not have_been_made
80
+ end
81
+ end
82
+ end
83
+
84
+ describe "#remember" do
85
+ let(:body) do
86
+ "@ellen remember my github token #{github_access_token}"
87
+ end
88
+
89
+ it "remembers sender's access token in its brain" do
90
+ Ellen.logger.should_receive(:info).with("Remembered #{sender}'s github access token")
91
+ robot.receive(
92
+ body: body,
93
+ from: sender,
94
+ to: channel,
95
+ )
96
+ access_tokens[sender].should == github_access_token
70
97
  end
71
98
  end
72
99
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ellen-github
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-25 00:00:00.000000000 Z
11
+ date: 2014-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ellen
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.1.3
19
+ version: 0.2.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.1.3
26
+ version: 0.2.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: octokit
29
29
  requirement: !ruby/object:Gem::Requirement