ellen-github 0.0.1 → 0.0.2

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: f1587809e50c74786a3bef3204c9d2b8b76595b0
4
- data.tar.gz: 6602da3e0e1f1997d6c0a06e50555b3008430d58
3
+ metadata.gz: 4c849dc2b74f690e8f9bec2968d5dc257586c968
4
+ data.tar.gz: fb81891c2819a3a6cca9d89659130890e1494b08
5
5
  SHA512:
6
- metadata.gz: 21e119a14ed2410a2f411f65a3ca6216fdcf464375df94808c4bc5432558ea44cca38d9d00f8a7cf00dd24400471ea33a3292bb2a0ee24ffc14c5c8a19bd25bc
7
- data.tar.gz: 54d5f3f8832d61e7440cbb00bad04b64a3ad5dd59932b61eababe31d8dc5d1bad6a79b2d30de426843322b01921e9766782ab66f99a892f63e0d65e18c316063
6
+ metadata.gz: 564707102b614e9321ccab7e724673f83700efee00a475f435aa886259f6003c3e3dd0d2e9b7e9554784debf06dd01609fcc1b0c4afd245cadb753575fef3b8d
7
+ data.tar.gz: 40eeb7c04e55da2d1244edfbbcb8419ebf9bd608e1801703ed82a727788374b26e426af7bb828ce651fcc5a852e290b9f2c84008f201b958aa1cd4b6df32863b
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## 0.0.2
2
+ * Memorize access token and use it to create a new issue
3
+
4
+ ## 0.0.1
5
+ * 1st Release
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
  Manage GitHub via Ellen.
3
3
 
4
4
  ## Install
5
- ```
5
+ ```ruby
6
6
  # Gemfile
7
7
  gem "ellen-github"
8
8
  ```
@@ -10,9 +10,5 @@ gem "ellen-github"
10
10
  ## Usage
11
11
  ```
12
12
  @ellen create issue "<title>" on <username>/<repository> - Create a new Issue
13
- ```
14
-
15
- ## ENV
16
- ```
17
- GITHUB_ACCESS_TOKEN - Github Access Token with `repo` or `public_repo` scope"
13
+ @ellen remember my github token <token> - Remember sender's GitHub access token
18
14
  ```
data/ellen-github.gemspec CHANGED
@@ -16,10 +16,11 @@ 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.2"
19
+ spec.add_dependency "ellen", ">= 0.1.3"
20
20
  spec.add_dependency "octokit"
21
21
  spec.add_development_dependency "bundler", "~> 1.6"
22
22
  spec.add_development_dependency "rake"
23
23
  spec.add_development_dependency "rspec", "2.14.1"
24
+ spec.add_development_dependency "simplecov"
24
25
  spec.add_development_dependency "webmock"
25
26
  end
data/lib/ellen/github.rb CHANGED
@@ -1,3 +1,6 @@
1
1
  require "ellen"
2
+ require "ellen/github/actions/base"
3
+ require "ellen/github/actions/create_issue"
4
+ require "ellen/github/actions/remember"
2
5
  require "ellen/github/version"
3
6
  require "ellen/handlers/github"
@@ -0,0 +1,28 @@
1
+ require "octokit"
2
+
3
+ module Ellen
4
+ module Github
5
+ module Actions
6
+ class Base
7
+ NAMESPACE = "github"
8
+
9
+ attr_reader :message, :robot
10
+
11
+ def initialize(options)
12
+ @message = options[:message]
13
+ @robot = options[:robot]
14
+ end
15
+
16
+ private
17
+
18
+ def access_tokens
19
+ robot.brain.data[NAMESPACE] ||= {}
20
+ end
21
+
22
+ def sender_name
23
+ message.from
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,65 @@
1
+ require "octokit"
2
+
3
+ module Ellen
4
+ module Github
5
+ module Actions
6
+ class CreateIssue < Base
7
+ def call
8
+ if has_access_token?
9
+ create
10
+ else
11
+ require_access_token
12
+ end
13
+ end
14
+
15
+ private
16
+
17
+ def require_access_token
18
+ robot.say("I don't know your github access token")
19
+ end
20
+
21
+ def created
22
+ robot.say("Created a new Issue")
23
+ end
24
+
25
+ def create
26
+ robot.say("Created #{issue.html_url}")
27
+ rescue Octokit::Unauthorized
28
+ robot.say("Failed in authentication (401)")
29
+ rescue Octokit::NotFound
30
+ robot.say("Could not find that repository")
31
+ rescue => exception
32
+ robot.say("Failed (#{exception.class})")
33
+ end
34
+
35
+ def issue
36
+ client.create_issue(repository, title, body)
37
+ end
38
+
39
+ def has_access_token?
40
+ !!access_token
41
+ end
42
+
43
+ def access_token
44
+ @access_token ||= access_tokens[sender_name]
45
+ end
46
+
47
+ def client
48
+ Octokit::Client.new(access_token: access_token)
49
+ end
50
+
51
+ def repository
52
+ message[:repo]
53
+ end
54
+
55
+ def title
56
+ message[:title]
57
+ end
58
+
59
+ def body
60
+ nil
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,33 @@
1
+ module Ellen
2
+ module Github
3
+ module Actions
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
+ def call
13
+ remember
14
+ report
15
+ end
16
+
17
+ private
18
+
19
+ def report
20
+ robot.say("Remembered #{robot.name}'s github access token")
21
+ end
22
+
23
+ def remember
24
+ access_tokens[sender_name] = given_access_token
25
+ end
26
+
27
+ def given_access_token
28
+ message[:token]
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -1,5 +1,5 @@
1
1
  module Ellen
2
2
  module Github
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -1,24 +1,16 @@
1
- require "octokit"
2
-
3
1
  module Ellen
4
2
  module Handlers
5
3
  class Github < Base
6
4
  on(/create issue "(?<title>.+)" on (?<repo>.+)\z/, name: "create_issue", description: "Create a new issue")
7
5
 
8
- env :GITHUB_ACCESS_TOKEN, "Github Access Token with `repo` or `public_repo` scope"
6
+ on(/remember my github token (?<token>.+)\z/, name: "remember", description: "Remember sender's GitHub access token")
9
7
 
10
8
  def create_issue(message)
11
- client.create_issue(message[:repo], message[:title], nil)
12
- end
13
-
14
- private
15
-
16
- def client
17
- @client ||= Octokit::Client.new(access_token: access_token)
9
+ Ellen::Github::Actions::CreateIssue.new(message: message, robot: robot).call
18
10
  end
19
11
 
20
- def access_token
21
- ENV["GITHUB_ACCESS_TOKEN"]
12
+ def remember(message)
13
+ Ellen::Github::Actions::Remember.new(message: message, robot: robot).call
22
14
  end
23
15
  end
24
16
  end
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,6 @@
1
+ require "simplecov"
2
+ SimpleCov.start
3
+
1
4
  require "ellen/github"
2
5
  require "webmock/rspec"
3
6
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ellen-github
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.1.2
19
+ version: 0.1.3
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.2
26
+ version: 0.1.3
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: octokit
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - '='
81
81
  - !ruby/object:Gem::Version
82
82
  version: 2.14.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: webmock
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -102,12 +116,16 @@ extensions: []
102
116
  extra_rdoc_files: []
103
117
  files:
104
118
  - ".gitignore"
119
+ - CHANGELOG.md
105
120
  - Gemfile
106
121
  - LICENSE.txt
107
122
  - README.md
108
123
  - Rakefile
109
124
  - ellen-github.gemspec
110
125
  - lib/ellen/github.rb
126
+ - lib/ellen/github/actions/base.rb
127
+ - lib/ellen/github/actions/create_issue.rb
128
+ - lib/ellen/github/actions/remember.rb
111
129
  - lib/ellen/github/version.rb
112
130
  - lib/ellen/handlers/github.rb
113
131
  - spec/ellen/github_spec.rb