lita-github_pr_list 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: beeb7009c49b1c0b9d0e0b4a545e026d44977136
4
- data.tar.gz: f80eb0cd2ed89ead579fad36e4f8ed711d4f5651
3
+ metadata.gz: 92954eb65ab5ee5e43a5efc4ceff2739ed631dc4
4
+ data.tar.gz: b7c95004063f30bcca990cf590a8b4063fe0a9db
5
5
  SHA512:
6
- metadata.gz: e6c011f75f9aedc132bf069e3a9ef837c9191951274209033cce5db6e105e5af3d9e099906c22dc8053cccbf175a18f2c92d6387002125460f008d968ccf6748
7
- data.tar.gz: c6164d0556c112064ed90ca655c164df6526b7769c3fd3bb2cd3dffe2c99ed517c3d9d1ce3aba789e5f14a4e800e15ae6bf1fdd44c0992b3bfeecdcf797cedec
6
+ metadata.gz: d4ebb88010886876c09ce16f37b95019079ebc7aadd2430cadfb8a61ed3fb9955d49d7e4c1af07baede2dad81f4afc146122e73078fd6140523e6d625b0bef0d
7
+ data.tar.gz: 7d9466eae44d281956e3cac6fb5ac4edb09f0dcb7bf2af4f35083f7093409bdd7ce89cb1ce58adf64cb46a09a2135eab44c170921dc9af7678e4c51d6d47c878
@@ -1,5 +1,5 @@
1
1
  module Lita
2
2
  module GithubPrList
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -3,28 +3,40 @@ require "octokit"
3
3
  module Lita
4
4
  module GithubPrList
5
5
  class WebHook
6
- attr_accessor :web_hook, :github_client, :github_organization, :github_pull_requests
6
+ attr_accessor :web_hook, :github_client, :github_organization, :github_pull_requests, :response
7
7
 
8
8
  def initialize(params = {})
9
9
  github_token = params.fetch(:github_token, nil)
10
10
  self.github_organization = params.fetch(:github_organization, nil)
11
11
  self.web_hook = params.fetch(:web_hook, nil)
12
+ self.response = params.fetch(:response, nil)
12
13
 
13
- raise "invalid params in #{self.class.name}" if github_token.nil? || github_organization.nil? || web_hook.nil?
14
+ if github_token.nil? || github_organization.nil? || web_hook.nil? || response.nil?
15
+ raise "invalid params in #{self.class.name}"
16
+ end
14
17
 
15
18
  self.github_client = Octokit::Client.new(access_token: github_token, auto_paginate: true)
16
19
  end
17
20
 
18
21
  def add_hooks
19
- github_client.repositories(github_organization).each do |repo|
20
- config = { url: "#{web_hook}", content_type: "json" }
21
- events = { events: ["issue_comment"] }
22
+ response.reply "Adding webhooks to #{github_organization}, this may take awhile..."
22
23
 
23
- github_client.create_hook(repo.full_name, "web", config, events)
24
+ github_client.repositories(github_organization).each do |repo|
25
+ begin
26
+ create_hook(repo.full_name)
27
+ rescue => ex
28
+ if ex.errors.first[:message] == "Hook already exists on this repository"
29
+ next
30
+ end
31
+ end
24
32
  end
33
+
34
+ response.reply "Finished adding webhooks to #{github_organization}"
25
35
  end
26
36
 
27
37
  def remove_hooks
38
+ response.reply "Removing #{web_hook} webhooks from #{github_organization}, this may take awhile..."
39
+
28
40
  github_client.repositories(github_organization).each do |repo|
29
41
  github_client.hooks(repo.full_name).each do |hook|
30
42
  if hook.config.url == web_hook
@@ -32,6 +44,17 @@ module Lita
32
44
  end
33
45
  end
34
46
  end
47
+
48
+ response.reply "Finished removing webhooks from #{github_organization}"
49
+ end
50
+
51
+ private
52
+
53
+ def create_hook(repo_full_name)
54
+ config = { url: "#{web_hook}", content_type: "json" }
55
+ events = { events: ["issue_comment"] }
56
+
57
+ github_client.create_hook(repo_full_name, "web", config, events)
35
58
  end
36
59
 
37
60
  end
@@ -57,24 +57,21 @@ module Lita
57
57
  end
58
58
 
59
59
  def add_pr_hooks(response)
60
- response.reply "Adding webhooks to #{github_organization}, this may take "\
61
- "awhile..."
62
-
63
60
  Lita::GithubPrList::WebHook.new(github_organization: github_organization,
64
61
  github_token: github_access_token,
65
- web_hook: web_hook).add_hooks
62
+ web_hook: web_hook,
63
+ response: response).add_hooks
66
64
  end
67
65
 
68
66
  def remove_pr_hooks(response)
69
- response.reply "Removing github_pr_list webhooks from #{github_organization},"\
70
- " this may take awhile..."
71
-
72
67
  Lita::GithubPrList::WebHook.new(github_organization: github_organization,
73
68
  github_token: github_access_token,
74
- web_hook: web_hook).remove_hooks
69
+ web_hook: web_hook,
70
+ response: response).remove_hooks
75
71
  end
76
72
 
77
73
  private
74
+
78
75
  def github_organization
79
76
  Lita.config.handlers.github_pr_list.github_organization
80
77
  end
@@ -35,7 +35,8 @@ describe Lita::Handlers::GithubPrList, lita_handler: true do
35
35
 
36
36
  send_command("pr add hooks")
37
37
 
38
- expect(replies.last).to include("Adding webhooks to aaaaaabbbbbbcccccc, this may take awhile...")
38
+ expect(replies).to include("Adding webhooks to aaaaaabbbbbbcccccc, this may take awhile...")
39
+ expect(replies).to include("Finished adding webhooks to aaaaaabbbbbbcccccc")
39
40
  end
40
41
 
41
42
  it "removes web hooks from an org's repos" do
@@ -45,6 +46,20 @@ describe Lita::Handlers::GithubPrList, lita_handler: true do
45
46
 
46
47
  send_command("pr remove hooks")
47
48
 
48
- expect(replies.last).to include("Removing github_pr_list webhooks from aaaaaabbbbbbcccccc, this may take awhile...")
49
+ expect(replies).to include("Removing https://example.com/hook webhooks from aaaaaabbbbbbcccccc, this may take awhile...")
50
+ expect(replies).to include("Finished removing webhooks from aaaaaabbbbbbcccccc")
51
+ end
52
+
53
+ it "catches exceptions when the hook already exists and continues" do
54
+ expect_any_instance_of(Octokit::Client).to receive(:repositories).and_return(repos)
55
+ expect_any_instance_of(Octokit::Client).to receive(:create_hook).twice.and_return(nil)
56
+ exception = Octokit::UnprocessableEntity.new
57
+ allow(exception).to receive(:errors).and_return([OpenStruct.new(message: "Hook already exists on this repository")])
58
+ allow(Lita::GithubPrList::WebHook).to receive(:create_hook).and_raise(exception)
59
+
60
+ send_command("pr add hooks")
61
+
62
+ expect(replies).to include("Adding webhooks to aaaaaabbbbbbcccccc, this may take awhile...")
63
+ expect(replies).to include("Finished adding webhooks to aaaaaabbbbbbcccccc")
49
64
  end
50
65
  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.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael van den Beuken