lita-github_pr_list 0.0.9 → 0.0.10

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: 2795f5b5e0c0730fb55e25d57f003e381afba4a1
4
- data.tar.gz: 726020281fc71178010f3768ec7c2555f71e31ef
3
+ metadata.gz: 1ebd99c23c469d5ad307dbdd6ab563e5d390546b
4
+ data.tar.gz: 20de13d2393fdc2064d6549fb128aa94d76fe0c2
5
5
  SHA512:
6
- metadata.gz: 32ba8f27ddc7ea1fab1f467500a257b861fdbc745a7c5db6564b9e1623f5967b1193b047966e3783a50a07660f9ed4c21d3887566be629f4eb6869d14e385018
7
- data.tar.gz: 53ee5ffcb19137a9e78a1d488ce9d24384831dba84051bb32b44d898c83d2eceb2ef149c13d5c1d17bb446bb54bd2a86129c272e0c8df996b3786d23108eefe7
6
+ metadata.gz: 08699121879e4dae99fcf367aeffee9d684ca19235319d6e8d129f50968b818e63af4070fa03a57ea9e07210ca80f4786273cc3d2958f825d4b8497825a0ed89
7
+ data.tar.gz: 8780112cdf8452e4801a9fc11d4350d8967a4b04f59a3a226a7d96e8e409ad44b432520338203b8e80838932984bb066dbb34083cec0debaf4c022721b3e0ddd
@@ -5,4 +5,5 @@ require "lita/github_pr_list/pull_request"
5
5
  require "lita/github_pr_list/web_hook"
6
6
  require "lita/github_pr_list/alias_user"
7
7
  require "lita/github_pr_list/check_list"
8
+ require "lita/github_pr_list/merge_request"
8
9
  require "lita/handlers/github_pr_list"
@@ -0,0 +1,52 @@
1
+ module Lita
2
+ module GithubPrList
3
+ class MergeRequest
4
+ attr_accessor :id, :title, :state, :redis
5
+
6
+ def initialize(params = {})
7
+ self.id = params[:id]
8
+ self.title = params[:title]
9
+ self.state = params[:state]
10
+ self.redis = params[:redis]
11
+ end
12
+
13
+ def open?
14
+ state == 'opened'
15
+ end
16
+
17
+ def handle
18
+ if open?
19
+ add_merge_request
20
+ else
21
+ remove_merge_request
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def url
28
+ "https://gitlab.corp.ads/ama/#{project}/merge_requests/#{id}"
29
+ end
30
+
31
+ def project
32
+ 'rails_envs'
33
+ end
34
+
35
+ def emoji
36
+ "(new)"
37
+ end
38
+
39
+ def message
40
+ "#{project} #{emoji} #{title} #{url}"
41
+ end
42
+
43
+ def add_merge_request
44
+ redis.set("gitlab_mr_#{id}", message)
45
+ end
46
+
47
+ def remove_merge_request
48
+ redis.del("gitlab_mr_#{id}")
49
+ end
50
+ end
51
+ end
52
+ end
@@ -3,8 +3,7 @@ require "octokit"
3
3
  module Lita
4
4
  module GithubPrList
5
5
  class PullRequest
6
- attr_accessor :github_client, :github_organization, :github_pull_requests,
7
- :summary, :response
6
+ attr_accessor :github_client, :github_organization, :github_pull_requests, :response
8
7
 
9
8
  def initialize(params = {})
10
9
  self.response = params.fetch(:response, nil)
@@ -20,8 +19,6 @@ module Lita
20
19
  def list
21
20
  get_pull_requests
22
21
  build_summary
23
-
24
- response.reply summary
25
22
  end
26
23
 
27
24
  private
@@ -29,18 +26,16 @@ module Lita
29
26
  # Grab the issues and sort out the pull request issues by repos name
30
27
  issues = github_client.org_issues(github_organization, filter: 'all')
31
28
  issues.sort! { |a,b| a.repository.name.downcase <=> b.repository.name.downcase }
32
-
29
+
33
30
  issues.each do |i|
34
31
  github_pull_requests << i if i.pull_request
35
32
  end
36
33
  end
37
34
 
38
35
  def build_summary
39
- self.summary = "I found #{github_pull_requests.count} open pull requests for #{github_organization}"
40
-
41
- github_pull_requests.each do |pr_issue|
36
+ github_pull_requests.map do |pr_issue|
42
37
  status = repo_status("#{pr_issue.repository.full_name}", pr_issue.number)
43
- self.summary += "\n#{pr_issue.repository.name} #{status} #{pr_issue.title} #{pr_issue.pull_request.html_url}"
38
+ "#{pr_issue.repository.name} #{status} #{pr_issue.title} #{pr_issue.pull_request.html_url}"
44
39
  end
45
40
  end
46
41
 
@@ -1,5 +1,5 @@
1
1
  module Lita
2
2
  module GithubPrList
3
- VERSION = "0.0.9"
3
+ VERSION = "0.0.10"
4
4
  end
5
5
  end
@@ -36,10 +36,17 @@ module Lita
36
36
 
37
37
  http.post "/comment_hook", :comment_hook
38
38
  http.post "/check_list", :check_list
39
+ http.post "/merge_request_action", :merge_request_action
39
40
 
40
41
  def list_org_pr(response)
41
- Lita::GithubPrList::PullRequest.new({ github_organization: github_organization, github_token: github_access_token,
42
- response: response, redis: redis }).list
42
+ pull_requests = Lita::GithubPrList::PullRequest.new({ github_organization: github_organization,
43
+ github_token: github_access_token,
44
+ response: response }).list
45
+ merge_requests = redis.keys("gitlab_mr*").map { |key| redis.get(key) }
46
+
47
+ requests = pull_requests + merge_requests
48
+ message = "I found #{requests.count} open pull requests for #{github_organization}\n"
49
+ response.reply(message + requests.join("\n"))
43
50
  end
44
51
 
45
52
  def alias_user(response)
@@ -81,6 +88,17 @@ module Lita
81
88
  end
82
89
  end
83
90
 
91
+ def merge_request_action(request, response)
92
+ payload = JSON.parse(request.body.read)
93
+ if payload["object_kind"] == "merge_request"
94
+ attributes = payload["object_attributes"]
95
+ Lita::GithubPrList::MergeRequest.new({ id: attributes["id"],
96
+ title: attributes["title"],
97
+ state: attributes["state"],
98
+ redis: redis }).handle
99
+ end
100
+ end
101
+
84
102
  private
85
103
 
86
104
  def github_organization
@@ -0,0 +1,22 @@
1
+ {
2
+ "object_kind": "merge_request",
3
+ "object_attributes": {
4
+ "assignee_id": 6,
5
+ "author_id": 51,
6
+ "created_at": "2013-12-03T17:23:34Z",
7
+ "description": "",
8
+ "id": 99,
9
+ "iid": 1,
10
+ "merge_status": "unchecked",
11
+ "milestone_id": null,
12
+ "source_branch": "ms-viewport",
13
+ "source_project_id": 14,
14
+ "st_commits": null,
15
+ "st_diffs": null,
16
+ "state": "opened",
17
+ "target_branch": "master",
18
+ "target_project_id": 14,
19
+ "title": "Fixed the things",
20
+ "updated_at": "2013-12-03T17:23:34Z"
21
+ }
22
+ }
@@ -0,0 +1,22 @@
1
+ {
2
+ "object_kind": "merge_request",
3
+ "object_attributes": {
4
+ "assignee_id": 6,
5
+ "author_id": 51,
6
+ "created_at": "2013-12-03T17:23:34Z",
7
+ "description": "",
8
+ "id": 99,
9
+ "iid": 1,
10
+ "merge_status": "unchecked",
11
+ "milestone_id": null,
12
+ "source_branch": "ms-viewport",
13
+ "source_project_id": 14,
14
+ "st_commits": null,
15
+ "st_diffs": null,
16
+ "state": "closed",
17
+ "target_branch": "master",
18
+ "target_project_id": 14,
19
+ "title": "Fixed the things",
20
+ "updated_at": "2013-12-03T17:23:34Z"
21
+ }
22
+ }
@@ -29,8 +29,11 @@ describe Lita::Handlers::GithubPrList, lita_handler: true do
29
29
  let(:issue_comments_in_review) { sawyer_resource_array("spec/fixtures/issue_comments_in_review.json") }
30
30
  let(:issue_comments_fixed) { sawyer_resource_array("spec/fixtures/issue_comments_fixed.json") }
31
31
  let(:issue_comments_new) { sawyer_resource_array("spec/fixtures/issue_comments_new.json") }
32
+ let(:gitlab_merge_request) { OpenStruct.new(body: OpenStruct.new(read: File.read("spec/fixtures/gitlab_merge_request.json"))) }
33
+ let(:gitlab_request_closed) { OpenStruct.new(body: OpenStruct.new(read: File.read("spec/fixtures/gitlab_request_closed.json"))) }
32
34
 
33
35
  it { routes_command("pr list").to(:list_org_pr) }
36
+ it { routes_http(:post, "/merge_request_action").to(:merge_request_action) }
34
37
 
35
38
  it "displays a list of pull requests" do
36
39
  expect_any_instance_of(Octokit::Client).to receive(:org_issues).and_return(two_issues)
@@ -69,4 +72,27 @@ describe Lita::Handlers::GithubPrList, lita_handler: true do
69
72
 
70
73
  expect(replies.last).to include("waffles (new) Found a bug https://github.com/octocat/Hello-World/pull/1347")
71
74
  end
75
+
76
+ it "lists gitlab merge requests" do
77
+ expect_any_instance_of(Octokit::Client).to receive(:org_issues).and_return(one_issue)
78
+ expect_any_instance_of(Octokit::Client).to receive(:issue_comments).and_return(issue_comments_new)
79
+
80
+ subject.merge_request_action(gitlab_merge_request, nil)
81
+
82
+ send_command("pr list")
83
+
84
+ expect(replies.last).to include("rails_envs (new) Fixed the things https://gitlab.corp.ads/ama/rails_envs/merge_requests/99")
85
+ end
86
+
87
+ it "removes gitlab merge requests" do
88
+ expect_any_instance_of(Octokit::Client).to receive(:org_issues).and_return(one_issue)
89
+ expect_any_instance_of(Octokit::Client).to receive(:issue_comments).and_return(issue_comments_new)
90
+
91
+ subject.merge_request_action(gitlab_request_closed, nil)
92
+
93
+ send_command("pr list")
94
+
95
+ expect(replies.last).to_not include("rails_envs (new) Fixed the things https://gitlab.corp.ads/ama/rails_envs/merge_requests/99")
96
+ end
97
+
72
98
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-github_pr_list
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael van den Beuken
@@ -13,118 +13,118 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2014-09-11 00:00:00.000000000 Z
16
+ date: 2014-09-15 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: lita
20
20
  requirement: !ruby/object:Gem::Requirement
21
21
  requirements:
22
- - - '>='
22
+ - - ">="
23
23
  - !ruby/object:Gem::Version
24
24
  version: '0'
25
25
  type: :runtime
26
26
  prerelease: false
27
27
  version_requirements: !ruby/object:Gem::Requirement
28
28
  requirements:
29
- - - '>='
29
+ - - ">="
30
30
  - !ruby/object:Gem::Version
31
31
  version: '0'
32
32
  - !ruby/object:Gem::Dependency
33
33
  name: octokit
34
34
  requirement: !ruby/object:Gem::Requirement
35
35
  requirements:
36
- - - ~>
36
+ - - "~>"
37
37
  - !ruby/object:Gem::Version
38
38
  version: '3.0'
39
39
  type: :runtime
40
40
  prerelease: false
41
41
  version_requirements: !ruby/object:Gem::Requirement
42
42
  requirements:
43
- - - ~>
43
+ - - "~>"
44
44
  - !ruby/object:Gem::Version
45
45
  version: '3.0'
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: bundler
48
48
  requirement: !ruby/object:Gem::Requirement
49
49
  requirements:
50
- - - ~>
50
+ - - "~>"
51
51
  - !ruby/object:Gem::Version
52
52
  version: '1.6'
53
53
  type: :development
54
54
  prerelease: false
55
55
  version_requirements: !ruby/object:Gem::Requirement
56
56
  requirements:
57
- - - ~>
57
+ - - "~>"
58
58
  - !ruby/object:Gem::Version
59
59
  version: '1.6'
60
60
  - !ruby/object:Gem::Dependency
61
61
  name: rake
62
62
  requirement: !ruby/object:Gem::Requirement
63
63
  requirements:
64
- - - '>='
64
+ - - ">="
65
65
  - !ruby/object:Gem::Version
66
66
  version: '0'
67
67
  type: :development
68
68
  prerelease: false
69
69
  version_requirements: !ruby/object:Gem::Requirement
70
70
  requirements:
71
- - - '>='
71
+ - - ">="
72
72
  - !ruby/object:Gem::Version
73
73
  version: '0'
74
74
  - !ruby/object:Gem::Dependency
75
75
  name: pry
76
76
  requirement: !ruby/object:Gem::Requirement
77
77
  requirements:
78
- - - '>='
78
+ - - ">="
79
79
  - !ruby/object:Gem::Version
80
80
  version: '0'
81
81
  type: :development
82
82
  prerelease: false
83
83
  version_requirements: !ruby/object:Gem::Requirement
84
84
  requirements:
85
- - - '>='
85
+ - - ">="
86
86
  - !ruby/object:Gem::Version
87
87
  version: '0'
88
88
  - !ruby/object:Gem::Dependency
89
89
  name: rspec
90
90
  requirement: !ruby/object:Gem::Requirement
91
91
  requirements:
92
- - - '>='
92
+ - - ">="
93
93
  - !ruby/object:Gem::Version
94
94
  version: '0'
95
95
  type: :development
96
96
  prerelease: false
97
97
  version_requirements: !ruby/object:Gem::Requirement
98
98
  requirements:
99
- - - '>='
99
+ - - ">="
100
100
  - !ruby/object:Gem::Version
101
101
  version: '0'
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: rspec-instafail
104
104
  requirement: !ruby/object:Gem::Requirement
105
105
  requirements:
106
- - - '>='
106
+ - - ">="
107
107
  - !ruby/object:Gem::Version
108
108
  version: '0'
109
109
  type: :development
110
110
  prerelease: false
111
111
  version_requirements: !ruby/object:Gem::Requirement
112
112
  requirements:
113
- - - '>='
113
+ - - ">="
114
114
  - !ruby/object:Gem::Version
115
115
  version: '0'
116
116
  - !ruby/object:Gem::Dependency
117
117
  name: simplecov
118
118
  requirement: !ruby/object:Gem::Requirement
119
119
  requirements:
120
- - - '>='
120
+ - - ">="
121
121
  - !ruby/object:Gem::Version
122
122
  version: '0'
123
123
  type: :development
124
124
  prerelease: false
125
125
  version_requirements: !ruby/object:Gem::Requirement
126
126
  requirements:
127
- - - '>='
127
+ - - ">="
128
128
  - !ruby/object:Gem::Version
129
129
  version: '0'
130
130
  description: List open pull requests for an organization.
@@ -141,10 +141,10 @@ executables:
141
141
  extensions: []
142
142
  extra_rdoc_files: []
143
143
  files:
144
- - .gitignore
145
- - .hound.yml
146
- - .rspec
147
- - .travis.yml
144
+ - ".gitignore"
145
+ - ".hound.yml"
146
+ - ".rspec"
147
+ - ".travis.yml"
148
148
  - Gemfile
149
149
  - LICENSE
150
150
  - README.md
@@ -155,12 +155,15 @@ files:
155
155
  - lib/lita/github_pr_list/alias_user.rb
156
156
  - lib/lita/github_pr_list/check_list.rb
157
157
  - lib/lita/github_pr_list/comment_hook.rb
158
+ - lib/lita/github_pr_list/merge_request.rb
158
159
  - lib/lita/github_pr_list/pull_request.rb
159
160
  - lib/lita/github_pr_list/status.rb
160
161
  - lib/lita/github_pr_list/version.rb
161
162
  - lib/lita/github_pr_list/web_hook.rb
162
163
  - lib/lita/handlers/github_pr_list.rb
163
164
  - lita-github_pr_list.gemspec
165
+ - spec/fixtures/gitlab_merge_request.json
166
+ - spec/fixtures/gitlab_request_closed.json
164
167
  - spec/fixtures/issue_comment_event_failed.json
165
168
  - spec/fixtures/issue_comment_event_fixed.json
166
169
  - spec/fixtures/issue_comment_event_in_review.json
@@ -193,21 +196,23 @@ require_paths:
193
196
  - lib
194
197
  required_ruby_version: !ruby/object:Gem::Requirement
195
198
  requirements:
196
- - - '>='
199
+ - - ">="
197
200
  - !ruby/object:Gem::Version
198
201
  version: '0'
199
202
  required_rubygems_version: !ruby/object:Gem::Requirement
200
203
  requirements:
201
- - - '>='
204
+ - - ">="
202
205
  - !ruby/object:Gem::Version
203
206
  version: '0'
204
207
  requirements: []
205
208
  rubyforge_project:
206
- rubygems_version: 2.0.0
209
+ rubygems_version: 2.4.1
207
210
  signing_key:
208
211
  specification_version: 4
209
212
  summary: List open pull requests for an organization.
210
213
  test_files:
214
+ - spec/fixtures/gitlab_merge_request.json
215
+ - spec/fixtures/gitlab_request_closed.json
211
216
  - spec/fixtures/issue_comment_event_failed.json
212
217
  - spec/fixtures/issue_comment_event_fixed.json
213
218
  - spec/fixtures/issue_comment_event_in_review.json