ruboty-github_assignor 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +2 -0
- data/lib/ruboty/github_assignor/assignor.rb +27 -0
- data/lib/ruboty/github_assignor/repo_watcher.rb +66 -0
- data/lib/ruboty/github_assignor/version.rb +5 -0
- data/lib/ruboty/github_assignor.rb +11 -0
- data/lib/ruboty/handlers/github_assignor.rb +38 -0
- data/ruboty-github_assignor.gemspec +28 -0
- data/spec/fixtures/issues1.json +80 -0
- data/spec/fixtures/issues2.json +158 -0
- data/spec/ruboty/github_assignor/repo_watcher_spec.rb +51 -0
- data/spec/spec_helper.rb +101 -0
- metadata +162 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cfe75361cdc5fe144005e37719876b228545fca0
|
4
|
+
data.tar.gz: 847422d5ecb60f67e683ae3d200e0d32d9710e4c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7febfe9dda40c8612102e8f948e2daecf9af47bed94472ad8d9ed98e1e1dfac68f25fc351923e8364feb6c4f4e36cbf6953dc0abe84319c61975769f441ec3d3
|
7
|
+
data.tar.gz: 985c53f44b1034fb4f208d4887ad5aa7244ed515beb39a6b2032817a4570e67e99bd8a3bec28257a0343ab8d758359720c9310d8623757f89f39df18ea120030
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Ryota Arai
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Ruboty::GithubAssignor
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'ruboty-github_assignor'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install ruboty-github_assignor
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( https://github.com/[my-github-username]/ruboty-github_assignor/fork )
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
module Ruboty
|
2
|
+
module GithubAssignor
|
3
|
+
class Assignee < Struct.new(:chat_name, :github_name)
|
4
|
+
end
|
5
|
+
|
6
|
+
class Assignor
|
7
|
+
attr_accessor :current
|
8
|
+
|
9
|
+
def initialize(assignees)
|
10
|
+
@mutex = Mutex.new
|
11
|
+
@assignees = assignees.map do |assignee|
|
12
|
+
Assignee.new(*assignee.values_at(*Assignee.members))
|
13
|
+
end
|
14
|
+
@current = rand(@assignees.size)
|
15
|
+
end
|
16
|
+
|
17
|
+
def next
|
18
|
+
@mutex.synchronize do
|
19
|
+
assignee = @assignees[@current % @assignees.size]
|
20
|
+
@current += 1
|
21
|
+
|
22
|
+
assignee
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'octokit'
|
2
|
+
|
3
|
+
module Ruboty
|
4
|
+
module GithubAssignor
|
5
|
+
class RepoWatcher
|
6
|
+
def initialize(robot:, repo:, octokit:, assignor:, to:)
|
7
|
+
@robot = robot
|
8
|
+
@repo = repo
|
9
|
+
@octokit = octokit
|
10
|
+
@assignor = assignor
|
11
|
+
@to = to
|
12
|
+
|
13
|
+
@checked_issue_ids = []
|
14
|
+
|
15
|
+
check_issues(false)
|
16
|
+
end
|
17
|
+
|
18
|
+
def check_issues(assign = true)
|
19
|
+
@octokit.issues(@repo).each do |issue|
|
20
|
+
unless @checked_issue_ids.include?(issue[:id])
|
21
|
+
if assign && !issue[:assignee]
|
22
|
+
# assign this issue
|
23
|
+
assignee = @assignor.next
|
24
|
+
|
25
|
+
@octokit.update_issue(@repo, issue[:number], assignee: assignee.github_name)
|
26
|
+
say(<<-EOC)
|
27
|
+
@#{assignee.chat_name} さん、お願いします!
|
28
|
+
|
29
|
+
#{issue[:title]}
|
30
|
+
<#{issue[:html_url]}>
|
31
|
+
EOC
|
32
|
+
end
|
33
|
+
@checked_issue_ids << issue[:id]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def start(interval)
|
39
|
+
Thread.start do
|
40
|
+
loop do
|
41
|
+
sleep(interval)
|
42
|
+
check_issues
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def say(body)
|
50
|
+
from = if @robot.send(:adapter).respond_to?(:jid, true)
|
51
|
+
@robot.send(:adapter).send(:jid)
|
52
|
+
else
|
53
|
+
nil
|
54
|
+
end
|
55
|
+
|
56
|
+
@robot.say(
|
57
|
+
body: body,
|
58
|
+
from: from,
|
59
|
+
to: @to,
|
60
|
+
original: {type: "groupchat"},
|
61
|
+
)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'ruboty'
|
2
|
+
require "ruboty/github_assignor/version"
|
3
|
+
require "ruboty/github_assignor/repo_watcher"
|
4
|
+
require "ruboty/github_assignor/assignor"
|
5
|
+
require "ruboty/handlers/github_assignor"
|
6
|
+
|
7
|
+
module Ruboty
|
8
|
+
module GithubAssignor
|
9
|
+
# Your code goes here...
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module Ruboty
|
4
|
+
module Handlers
|
5
|
+
class GithubAssignor < Base
|
6
|
+
env :GITHUB_ASSIGNOR_REPOS, "e.g. '#{[{repo: 'your/repo', to: 'chatroom', assignees: [{chat_name: 'name', github_name: 'name'}]}].to_json}'"
|
7
|
+
env :GITHUB_TOKEN, "GitHub Access Token"
|
8
|
+
env :GITHUB_ASSIGNOR_INTERVAL, "Check interval", optional: true
|
9
|
+
|
10
|
+
def initialize(*args)
|
11
|
+
super
|
12
|
+
|
13
|
+
start_watching
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def start_watching
|
19
|
+
octokit = Octokit::Client.new(access_token: ENV['GITHUB_TOKEN'])
|
20
|
+
|
21
|
+
data = JSON.parse(ENV['GITHUB_ASSIGNOR_REPOS'])
|
22
|
+
data.each do |datum|
|
23
|
+
repo = datum['repo']
|
24
|
+
to = datum['to']
|
25
|
+
assignor = Ruboty::GithubAssignor::Assignor.new(datum['assignees'])
|
26
|
+
|
27
|
+
Ruboty::GithubAssignor::RepoWatcher.new(
|
28
|
+
robot: robot,
|
29
|
+
repo: repo,
|
30
|
+
octokit: octokit,
|
31
|
+
assignor: assignor,
|
32
|
+
to: to,
|
33
|
+
).start((ENV['GITHUB_ASSIGNOR_INTERVAL'] || 60).to_i)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ruboty/github_assignor/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ruboty-github_assignor"
|
8
|
+
spec.version = Ruboty::GithubAssignor::VERSION
|
9
|
+
spec.authors = ["Ryota Arai"]
|
10
|
+
spec.email = ["ryota.arai@gmail.com"]
|
11
|
+
spec.summary = %q{Assign GitHub issues automatically}
|
12
|
+
spec.homepage = "https://github.com/ryotarai/ruboty-github_assignor"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_dependency "ruboty"
|
21
|
+
spec.add_dependency "octokit"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "rspec"
|
26
|
+
spec.add_development_dependency "pry-byebug"
|
27
|
+
spec.add_development_dependency "webmock"
|
28
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"id": 1,
|
4
|
+
"url": "https://api.github.com/repos/octocat/Hello-World/issues/1347",
|
5
|
+
"html_url": "https://github.com/octocat/Hello-World/issues/1347",
|
6
|
+
"number": 1347,
|
7
|
+
"state": "open",
|
8
|
+
"title": "Found a bug",
|
9
|
+
"body": "I'm having a problem with this.",
|
10
|
+
"user": {
|
11
|
+
"login": "octocat",
|
12
|
+
"id": 1,
|
13
|
+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
|
14
|
+
"gravatar_id": "",
|
15
|
+
"url": "https://api.github.com/users/octocat",
|
16
|
+
"html_url": "https://github.com/octocat",
|
17
|
+
"followers_url": "https://api.github.com/users/octocat/followers",
|
18
|
+
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
|
19
|
+
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
|
20
|
+
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
|
21
|
+
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
|
22
|
+
"organizations_url": "https://api.github.com/users/octocat/orgs",
|
23
|
+
"repos_url": "https://api.github.com/users/octocat/repos",
|
24
|
+
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
|
25
|
+
"received_events_url": "https://api.github.com/users/octocat/received_events",
|
26
|
+
"type": "User",
|
27
|
+
"site_admin": false
|
28
|
+
},
|
29
|
+
"labels": [
|
30
|
+
{
|
31
|
+
"url": "https://api.github.com/repos/octocat/Hello-World/labels/bug",
|
32
|
+
"name": "bug",
|
33
|
+
"color": "f29513"
|
34
|
+
}
|
35
|
+
],
|
36
|
+
"assignee": null,
|
37
|
+
"milestone": {
|
38
|
+
"url": "https://api.github.com/repos/octocat/Hello-World/milestones/1",
|
39
|
+
"number": 1,
|
40
|
+
"state": "open",
|
41
|
+
"title": "v1.0",
|
42
|
+
"description": "",
|
43
|
+
"creator": {
|
44
|
+
"login": "octocat",
|
45
|
+
"id": 1,
|
46
|
+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
|
47
|
+
"gravatar_id": "",
|
48
|
+
"url": "https://api.github.com/users/octocat",
|
49
|
+
"html_url": "https://github.com/octocat",
|
50
|
+
"followers_url": "https://api.github.com/users/octocat/followers",
|
51
|
+
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
|
52
|
+
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
|
53
|
+
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
|
54
|
+
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
|
55
|
+
"organizations_url": "https://api.github.com/users/octocat/orgs",
|
56
|
+
"repos_url": "https://api.github.com/users/octocat/repos",
|
57
|
+
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
|
58
|
+
"received_events_url": "https://api.github.com/users/octocat/received_events",
|
59
|
+
"type": "User",
|
60
|
+
"site_admin": false
|
61
|
+
},
|
62
|
+
"open_issues": 4,
|
63
|
+
"closed_issues": 8,
|
64
|
+
"created_at": "2011-04-10T20:09:31Z",
|
65
|
+
"updated_at": "2014-03-03T18:58:10Z",
|
66
|
+
"closed_at": "2013-02-12T13:22:01Z",
|
67
|
+
"due_on": null
|
68
|
+
},
|
69
|
+
"comments": 0,
|
70
|
+
"pull_request": {
|
71
|
+
"url": "https://api.github.com/repos/octocat/Hello-World/pulls/1347",
|
72
|
+
"html_url": "https://github.com/octocat/Hello-World/pull/1347",
|
73
|
+
"diff_url": "https://github.com/octocat/Hello-World/pull/1347.diff",
|
74
|
+
"patch_url": "https://github.com/octocat/Hello-World/pull/1347.patch"
|
75
|
+
},
|
76
|
+
"closed_at": null,
|
77
|
+
"created_at": "2011-04-22T13:33:48Z",
|
78
|
+
"updated_at": "2011-04-22T13:33:48Z"
|
79
|
+
}
|
80
|
+
]
|
@@ -0,0 +1,158 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"id": 1,
|
4
|
+
"url": "https://api.github.com/repos/octocat/Hello-World/issues/1347",
|
5
|
+
"html_url": "https://github.com/octocat/Hello-World/issues/1347",
|
6
|
+
"number": 1347,
|
7
|
+
"state": "open",
|
8
|
+
"title": "Found a bug",
|
9
|
+
"body": "I'm having a problem with this.",
|
10
|
+
"user": {
|
11
|
+
"login": "octocat",
|
12
|
+
"id": 1,
|
13
|
+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
|
14
|
+
"gravatar_id": "",
|
15
|
+
"url": "https://api.github.com/users/octocat",
|
16
|
+
"html_url": "https://github.com/octocat",
|
17
|
+
"followers_url": "https://api.github.com/users/octocat/followers",
|
18
|
+
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
|
19
|
+
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
|
20
|
+
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
|
21
|
+
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
|
22
|
+
"organizations_url": "https://api.github.com/users/octocat/orgs",
|
23
|
+
"repos_url": "https://api.github.com/users/octocat/repos",
|
24
|
+
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
|
25
|
+
"received_events_url": "https://api.github.com/users/octocat/received_events",
|
26
|
+
"type": "User",
|
27
|
+
"site_admin": false
|
28
|
+
},
|
29
|
+
"labels": [
|
30
|
+
{
|
31
|
+
"url": "https://api.github.com/repos/octocat/Hello-World/labels/bug",
|
32
|
+
"name": "bug",
|
33
|
+
"color": "f29513"
|
34
|
+
}
|
35
|
+
],
|
36
|
+
"assignee": null,
|
37
|
+
"milestone": {
|
38
|
+
"url": "https://api.github.com/repos/octocat/Hello-World/milestones/1",
|
39
|
+
"number": 1,
|
40
|
+
"state": "open",
|
41
|
+
"title": "v1.0",
|
42
|
+
"description": "",
|
43
|
+
"creator": {
|
44
|
+
"login": "octocat",
|
45
|
+
"id": 1,
|
46
|
+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
|
47
|
+
"gravatar_id": "",
|
48
|
+
"url": "https://api.github.com/users/octocat",
|
49
|
+
"html_url": "https://github.com/octocat",
|
50
|
+
"followers_url": "https://api.github.com/users/octocat/followers",
|
51
|
+
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
|
52
|
+
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
|
53
|
+
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
|
54
|
+
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
|
55
|
+
"organizations_url": "https://api.github.com/users/octocat/orgs",
|
56
|
+
"repos_url": "https://api.github.com/users/octocat/repos",
|
57
|
+
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
|
58
|
+
"received_events_url": "https://api.github.com/users/octocat/received_events",
|
59
|
+
"type": "User",
|
60
|
+
"site_admin": false
|
61
|
+
},
|
62
|
+
"open_issues": 4,
|
63
|
+
"closed_issues": 8,
|
64
|
+
"created_at": "2011-04-10T20:09:31Z",
|
65
|
+
"updated_at": "2014-03-03T18:58:10Z",
|
66
|
+
"closed_at": "2013-02-12T13:22:01Z",
|
67
|
+
"due_on": null
|
68
|
+
},
|
69
|
+
"comments": 0,
|
70
|
+
"pull_request": {
|
71
|
+
"url": "https://api.github.com/repos/octocat/Hello-World/pulls/1347",
|
72
|
+
"html_url": "https://github.com/octocat/Hello-World/pull/1347",
|
73
|
+
"diff_url": "https://github.com/octocat/Hello-World/pull/1347.diff",
|
74
|
+
"patch_url": "https://github.com/octocat/Hello-World/pull/1347.patch"
|
75
|
+
},
|
76
|
+
"closed_at": null,
|
77
|
+
"created_at": "2011-04-22T13:33:48Z",
|
78
|
+
"updated_at": "2011-04-22T13:33:48Z"
|
79
|
+
},
|
80
|
+
{
|
81
|
+
"id": 2,
|
82
|
+
"url": "https://api.github.com/repos/octocat/Hello-World/issues/1347",
|
83
|
+
"html_url": "https://github.com/octocat/Hello-World/issues/1347",
|
84
|
+
"number": 1347,
|
85
|
+
"state": "open",
|
86
|
+
"title": "Found a bug",
|
87
|
+
"body": "I'm having a problem with this.",
|
88
|
+
"user": {
|
89
|
+
"login": "octocat",
|
90
|
+
"id": 1,
|
91
|
+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
|
92
|
+
"gravatar_id": "",
|
93
|
+
"url": "https://api.github.com/users/octocat",
|
94
|
+
"html_url": "https://github.com/octocat",
|
95
|
+
"followers_url": "https://api.github.com/users/octocat/followers",
|
96
|
+
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
|
97
|
+
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
|
98
|
+
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
|
99
|
+
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
|
100
|
+
"organizations_url": "https://api.github.com/users/octocat/orgs",
|
101
|
+
"repos_url": "https://api.github.com/users/octocat/repos",
|
102
|
+
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
|
103
|
+
"received_events_url": "https://api.github.com/users/octocat/received_events",
|
104
|
+
"type": "User",
|
105
|
+
"site_admin": false
|
106
|
+
},
|
107
|
+
"labels": [
|
108
|
+
{
|
109
|
+
"url": "https://api.github.com/repos/octocat/Hello-World/labels/bug",
|
110
|
+
"name": "bug",
|
111
|
+
"color": "f29513"
|
112
|
+
}
|
113
|
+
],
|
114
|
+
"assignee": null,
|
115
|
+
"milestone": {
|
116
|
+
"url": "https://api.github.com/repos/octocat/Hello-World/milestones/1",
|
117
|
+
"number": 1,
|
118
|
+
"state": "open",
|
119
|
+
"title": "v1.0",
|
120
|
+
"description": "",
|
121
|
+
"creator": {
|
122
|
+
"login": "octocat",
|
123
|
+
"id": 1,
|
124
|
+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
|
125
|
+
"gravatar_id": "",
|
126
|
+
"url": "https://api.github.com/users/octocat",
|
127
|
+
"html_url": "https://github.com/octocat",
|
128
|
+
"followers_url": "https://api.github.com/users/octocat/followers",
|
129
|
+
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
|
130
|
+
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
|
131
|
+
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
|
132
|
+
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
|
133
|
+
"organizations_url": "https://api.github.com/users/octocat/orgs",
|
134
|
+
"repos_url": "https://api.github.com/users/octocat/repos",
|
135
|
+
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
|
136
|
+
"received_events_url": "https://api.github.com/users/octocat/received_events",
|
137
|
+
"type": "User",
|
138
|
+
"site_admin": false
|
139
|
+
},
|
140
|
+
"open_issues": 4,
|
141
|
+
"closed_issues": 8,
|
142
|
+
"created_at": "2011-04-10T20:09:31Z",
|
143
|
+
"updated_at": "2014-03-03T18:58:10Z",
|
144
|
+
"closed_at": "2013-02-12T13:22:01Z",
|
145
|
+
"due_on": null
|
146
|
+
},
|
147
|
+
"comments": 0,
|
148
|
+
"pull_request": {
|
149
|
+
"url": "https://api.github.com/repos/octocat/Hello-World/pulls/1347",
|
150
|
+
"html_url": "https://github.com/octocat/Hello-World/pull/1347",
|
151
|
+
"diff_url": "https://github.com/octocat/Hello-World/pull/1347.diff",
|
152
|
+
"patch_url": "https://github.com/octocat/Hello-World/pull/1347.patch"
|
153
|
+
},
|
154
|
+
"closed_at": null,
|
155
|
+
"created_at": "2011-04-22T13:33:48Z",
|
156
|
+
"updated_at": "2011-04-22T13:33:48Z"
|
157
|
+
}
|
158
|
+
]
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Ruboty::GithubAssignor::RepoWatcher do
|
4
|
+
let(:robot) { Ruboty::Robot.new }
|
5
|
+
let(:octokit) { Octokit::Client.new(access_token: 'access_token') }
|
6
|
+
let(:assignor) do
|
7
|
+
Ruboty::GithubAssignor::Assignor.new([
|
8
|
+
{chat_name: 'alice', github_name: 'gh_alice'},
|
9
|
+
{chat_name: 'bob', github_name: 'gh_bob'},
|
10
|
+
]).tap {|assignor| assignor.current = 0 }
|
11
|
+
end
|
12
|
+
|
13
|
+
subject(:watcher) do
|
14
|
+
described_class.new(
|
15
|
+
robot: robot,
|
16
|
+
repo: 'octocat/Hello-World',
|
17
|
+
octokit: octokit,
|
18
|
+
assignor: assignor,
|
19
|
+
to: 'room',
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
let(:request_header) { {'Accept'=>'application/vnd.github.v3+json', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'token access_token', 'Content-Type'=>'application/json', 'User-Agent'=>'Octokit Ruby Gem 3.7.0'} }
|
24
|
+
|
25
|
+
describe '#check_issues' do
|
26
|
+
before do
|
27
|
+
stub_request(:get, "https://api.github.com/repos/octocat/Hello-World/issues").
|
28
|
+
with(:headers => request_header).
|
29
|
+
to_return(:status => 200, :body => fixture('issues1.json'), :headers => {'Content-Type' => 'application/json; charset=utf-8'}).then.
|
30
|
+
to_return(:status => 200, :body => fixture('issues2.json'), :headers => {'Content-Type' => 'application/json; charset=utf-8'})
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'sends a message to assignee' do
|
34
|
+
stub_request(:patch, "https://api.github.com/repos/octocat/Hello-World/issues/1347").
|
35
|
+
with(:body => "{\"assignee\":\"gh_alice\"}",
|
36
|
+
:headers => request_header).
|
37
|
+
to_return(:status => 200, :body => "", :headers => {})
|
38
|
+
|
39
|
+
expect(robot).to receive(:say).with(
|
40
|
+
hash_including(body: <<-EOC)
|
41
|
+
@alice さん、お願いします!
|
42
|
+
|
43
|
+
Found a bug
|
44
|
+
<https://github.com/octocat/Hello-World/issues/1347>
|
45
|
+
EOC
|
46
|
+
)
|
47
|
+
watcher.check_issues
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'ruboty/github_assignor'
|
2
|
+
require 'webmock/rspec'
|
3
|
+
|
4
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
5
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
6
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause this
|
7
|
+
# file to always be loaded, without a need to explicitly require it in any files.
|
8
|
+
#
|
9
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
10
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
11
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
12
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
13
|
+
# a separate helper file that requires the additional dependencies and performs
|
14
|
+
# the additional setup, and require it from the spec files that actually need it.
|
15
|
+
#
|
16
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
17
|
+
# users commonly want.
|
18
|
+
#
|
19
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
20
|
+
|
21
|
+
module SpecHelper
|
22
|
+
def fixture(name)
|
23
|
+
File.read(File.expand_path(File.join(__FILE__, '..', 'fixtures', name)))
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
RSpec.configure do |config|
|
28
|
+
config.include SpecHelper
|
29
|
+
|
30
|
+
# rspec-expectations config goes here. You can use an alternate
|
31
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
32
|
+
# assertions if you prefer.
|
33
|
+
config.expect_with :rspec do |expectations|
|
34
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
35
|
+
# and `failure_message` of custom matchers include text for helper methods
|
36
|
+
# defined using `chain`, e.g.:
|
37
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
38
|
+
# # => "be bigger than 2 and smaller than 4"
|
39
|
+
# ...rather than:
|
40
|
+
# # => "be bigger than 2"
|
41
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
42
|
+
end
|
43
|
+
|
44
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
45
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
46
|
+
config.mock_with :rspec do |mocks|
|
47
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
48
|
+
# a real object. This is generally recommended, and will default to
|
49
|
+
# `true` in RSpec 4.
|
50
|
+
mocks.verify_partial_doubles = true
|
51
|
+
end
|
52
|
+
|
53
|
+
# The settings below are suggested to provide a good initial experience
|
54
|
+
# with RSpec, but feel free to customize to your heart's content.
|
55
|
+
=begin
|
56
|
+
# These two settings work together to allow you to limit a spec run
|
57
|
+
# to individual examples or groups you care about by tagging them with
|
58
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
59
|
+
# get run.
|
60
|
+
config.filter_run :focus
|
61
|
+
config.run_all_when_everything_filtered = true
|
62
|
+
|
63
|
+
# Limits the available syntax to the non-monkey patched syntax that is recommended.
|
64
|
+
# For more details, see:
|
65
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
66
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
67
|
+
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
68
|
+
config.disable_monkey_patching!
|
69
|
+
|
70
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
71
|
+
# be too noisy due to issues in dependencies.
|
72
|
+
config.warnings = true
|
73
|
+
|
74
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
75
|
+
# file, and it's useful to allow more verbose output when running an
|
76
|
+
# individual spec file.
|
77
|
+
if config.files_to_run.one?
|
78
|
+
# Use the documentation formatter for detailed output,
|
79
|
+
# unless a formatter has already been configured
|
80
|
+
# (e.g. via a command-line flag).
|
81
|
+
config.default_formatter = 'doc'
|
82
|
+
end
|
83
|
+
|
84
|
+
# Print the 10 slowest examples and example groups at the
|
85
|
+
# end of the spec run, to help surface which specs are running
|
86
|
+
# particularly slow.
|
87
|
+
config.profile_examples = 10
|
88
|
+
|
89
|
+
# Run specs in random order to surface order dependencies. If you find an
|
90
|
+
# order dependency and want to debug it, you can fix the order by providing
|
91
|
+
# the seed, which is printed after each run.
|
92
|
+
# --seed 1234
|
93
|
+
config.order = :random
|
94
|
+
|
95
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
96
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
97
|
+
# test failures related to randomization by passing the same `--seed` value
|
98
|
+
# as the one that triggered the failure.
|
99
|
+
Kernel.srand config.seed
|
100
|
+
=end
|
101
|
+
end
|
metadata
ADDED
@@ -0,0 +1,162 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruboty-github_assignor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ryota Arai
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ruboty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: octokit
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.7'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.7'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry-byebug
|
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'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: webmock
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description:
|
112
|
+
email:
|
113
|
+
- ryota.arai@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- ".rspec"
|
120
|
+
- Gemfile
|
121
|
+
- LICENSE.txt
|
122
|
+
- README.md
|
123
|
+
- Rakefile
|
124
|
+
- lib/ruboty/github_assignor.rb
|
125
|
+
- lib/ruboty/github_assignor/assignor.rb
|
126
|
+
- lib/ruboty/github_assignor/repo_watcher.rb
|
127
|
+
- lib/ruboty/github_assignor/version.rb
|
128
|
+
- lib/ruboty/handlers/github_assignor.rb
|
129
|
+
- ruboty-github_assignor.gemspec
|
130
|
+
- spec/fixtures/issues1.json
|
131
|
+
- spec/fixtures/issues2.json
|
132
|
+
- spec/ruboty/github_assignor/repo_watcher_spec.rb
|
133
|
+
- spec/spec_helper.rb
|
134
|
+
homepage: https://github.com/ryotarai/ruboty-github_assignor
|
135
|
+
licenses:
|
136
|
+
- MIT
|
137
|
+
metadata: {}
|
138
|
+
post_install_message:
|
139
|
+
rdoc_options: []
|
140
|
+
require_paths:
|
141
|
+
- lib
|
142
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
requirements: []
|
153
|
+
rubyforge_project:
|
154
|
+
rubygems_version: 2.2.2
|
155
|
+
signing_key:
|
156
|
+
specification_version: 4
|
157
|
+
summary: Assign GitHub issues automatically
|
158
|
+
test_files:
|
159
|
+
- spec/fixtures/issues1.json
|
160
|
+
- spec/fixtures/issues2.json
|
161
|
+
- spec/ruboty/github_assignor/repo_watcher_spec.rb
|
162
|
+
- spec/spec_helper.rb
|