txgh-server 2.2.0 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0ed650a35c78fd2a4a616a5e106aceea35eae654
4
- data.tar.gz: a8df5a3a0ab04c9e30c86444dd06c49bf5127768
3
+ metadata.gz: 359b3bb8990904063bb4b3f9bbdc8602311ff53f
4
+ data.tar.gz: d4b6f7e1429cadac6cdf8aada177b54de89fc69c
5
5
  SHA512:
6
- metadata.gz: ece1db6aa35c8d561d6e8c1f8335190e23e0dc97d32ed90d4f1a83e38fdeaceef90bf86ceb46aab83c6ab13d760b999e726362df45a6a4568f619b4f5a59b403
7
- data.tar.gz: f9bdf5680ac0306ffa52564e7b8d31733d7e60e7bac5ae250086520ab3266e4e22325bb230bf0c42b7bd063d451fd6c9806dd1f824b30b5e66175a1a691e2b61
6
+ metadata.gz: 8c793ad9b43034ce152d910bbb6dff0f160d6e30c8df666c4cd93d66461efb4490421832b2799d392288a16566e57af77f201634048a58047465946618dc8989
7
+ data.tar.gz: 25dc3a1ae9b51abb31d0603948c4b8d1ef2a676f545cee664faf84f97f8936877210319c58a6fcffdd677604c39c2979c46d5af81486050f9458652d8f37a411
@@ -1,4 +1,5 @@
1
1
  require 'openssl'
2
+ require 'base64'
2
3
 
3
4
  module TxghServer
4
5
  class TransifexRequestAuth
@@ -1,3 +1,3 @@
1
1
  module TxghServer
2
- VERSION = '2.2.0'
2
+ VERSION = '2.3.0'
3
3
  end
@@ -9,6 +9,7 @@ module TxghServer
9
9
  autoload :PushHandler, 'txgh-server/webhooks/github/push_handler'
10
10
  autoload :PushAttributes, 'txgh-server/webhooks/github/push_attributes'
11
11
  autoload :RequestHandler, 'txgh-server/webhooks/github/request_handler'
12
+ autoload :StatusUpdater, 'txgh-server/webhooks/github/status_updater'
12
13
  end
13
14
  end
14
15
  end
@@ -30,26 +30,25 @@ module TxghServer
30
30
  { 'author' => attributes.author }
31
31
  end
32
32
 
33
- update_github_status
33
+ status_updater.update_status
34
34
  end
35
35
 
36
36
  respond_with(200, true)
37
+ rescue => e
38
+ status_updater.report_error_and_update_status(e)
39
+ respond_with_error(500, "Internal server error: #{e.message}", e)
37
40
  end
38
41
 
39
42
  private
40
43
 
41
- def update_github_status
42
- Txgh::GithubStatus.update(project, repo, branch)
43
- rescue Octokit::UnprocessableEntity
44
- # raised because we've tried to create too many statuses for the commit
45
- rescue Txgh::TransifexNotFoundError
46
- # raised if transifex resource can't be found
47
- end
48
-
49
44
  def pusher
50
45
  @pusher ||= Txgh::Pusher.new(project, repo, branch)
51
46
  end
52
47
 
48
+ def status_updater
49
+ @status_updater = StatusUpdater.new(project, repo, branch)
50
+ end
51
+
53
52
  # finds the resources that were updated in each commit
54
53
  def added_and_modified_resources
55
54
  @amr ||= attributes.files.each_with_object(Set.new) do |file, ret|
@@ -0,0 +1,45 @@
1
+ require 'octokit'
2
+
3
+ module TxghServer
4
+ module Webhooks
5
+ module Github
6
+ class StatusUpdater
7
+ attr_reader :project, :repo, :branch
8
+
9
+ def initialize(project, repo, branch)
10
+ @project = project
11
+ @repo = repo
12
+ @branch = branch
13
+ end
14
+
15
+ def report_error_and_update_status(error)
16
+ error_params = Txgh.events.publish_error!(error)
17
+
18
+ Txgh.events.publish_each('github.status.error', error_params) do |status_params|
19
+ if status_params
20
+ update_status_safely do
21
+ Txgh::GithubStatus.error(project, repo, branch, status_params)
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+ def update_status
28
+ update_status_safely do
29
+ Txgh::GithubStatus.update(project, repo, branch)
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ def update_status_safely
36
+ yield
37
+ rescue Octokit::UnprocessableEntity
38
+ # raised because we've tried to create too many statuses for the commit
39
+ rescue Txgh::TransifexNotFoundError
40
+ # raised if transifex resource can't be found
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -57,6 +57,31 @@ describe PushHandler do
57
57
  expect(response.body).to eq(true)
58
58
  end
59
59
 
60
+ context 'with an error' do
61
+ let(:description) { 'An error done occurred, fool' }
62
+ let(:target_url) { 'http://you-goofed.com' }
63
+
64
+ let(:status_params) do
65
+ { description: description, target_url: target_url }
66
+ end
67
+
68
+ let(:error_params) { { foo: 'bar' } }
69
+
70
+ before(:each) do
71
+ Txgh.events.subscribe(Txgh::Events::ERROR_CHANNEL) { error_params }
72
+ Txgh.events.subscribe('github.status.error') { status_params }
73
+ end
74
+
75
+ it 'reports errors and updates the github status' do
76
+ expect(Txgh::GithubStatus).to(
77
+ receive(:error).with(transifex_project, github_repo, ref, status_params)
78
+ )
79
+
80
+ expect(handler).to receive(:should_process?).and_raise(StandardError)
81
+ handler.execute
82
+ end
83
+ end
84
+
60
85
  context 'with a deleted branch' do
61
86
  let(:before) { nil }
62
87
  let(:after) { '0' * 40 }
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+ require 'helpers/standard_txgh_setup'
3
+
4
+ include TxghServer::Webhooks::Github
5
+
6
+ describe StatusUpdater do
7
+ include StandardTxghSetup
8
+
9
+ let(:updater) { StatusUpdater.new(transifex_project, github_repo, ref) }
10
+
11
+ describe '#report_error_and_update_status' do
12
+ let(:description) { 'An error done occurred, fool' }
13
+ let(:target_url) { 'http://you-goofed.com' }
14
+
15
+ let(:status_params) do
16
+ { description: description, target_url: target_url }
17
+ end
18
+
19
+ let(:error_params) { { foo: 'bar' } }
20
+
21
+ before(:each) do
22
+ Txgh.events.subscribe(Txgh::Events::ERROR_CHANNEL) { error_params }
23
+ Txgh.events.subscribe('github.status.error') { status_params }
24
+ end
25
+
26
+ it 'reports the error and updates the status' do
27
+ expect(Txgh::GithubStatus).to(
28
+ receive(:error).with(transifex_project, github_repo, ref, status_params)
29
+ )
30
+
31
+ expect(Txgh.events).to receive(:publish_error!)
32
+ updater.report_error_and_update_status(StandardError.new)
33
+ end
34
+
35
+ it 'avoids blowing up on octokit error' do
36
+ expect(Txgh::GithubStatus).to(
37
+ receive(:error).and_raise(Octokit::UnprocessableEntity)
38
+ )
39
+
40
+ expect { updater.report_error_and_update_status(StandardError.new) }.to_not raise_error
41
+ end
42
+ end
43
+
44
+ describe '#update_status' do
45
+ it 'updates the github status' do
46
+ expect(Txgh::GithubStatus).to receive(:update)
47
+ updater.update_status
48
+ end
49
+
50
+ it 'avoids blowing up on octokit error' do
51
+ expect(Txgh::GithubStatus).to(
52
+ receive(:update).and_raise(Octokit::UnprocessableEntity)
53
+ )
54
+
55
+ expect { updater.update_status }.to_not raise_error
56
+ end
57
+ end
58
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: txgh-server
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Jackowski
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-10-14 00:00:00.000000000 Z
12
+ date: 2016-11-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mime-types
@@ -119,6 +119,7 @@ files:
119
119
  - lib/txgh-server/webhooks/github/push_attributes.rb
120
120
  - lib/txgh-server/webhooks/github/push_handler.rb
121
121
  - lib/txgh-server/webhooks/github/request_handler.rb
122
+ - lib/txgh-server/webhooks/github/status_updater.rb
122
123
  - lib/txgh-server/webhooks/transifex.rb
123
124
  - lib/txgh-server/webhooks/transifex/hook_handler.rb
124
125
  - lib/txgh-server/webhooks/transifex/request_handler.rb
@@ -147,6 +148,7 @@ files:
147
148
  - spec/webhooks/github/push_attributes_spec.rb
148
149
  - spec/webhooks/github/push_handler_spec.rb
149
150
  - spec/webhooks/github/request_handler_spec.rb
151
+ - spec/webhooks/github/status_updater_spec.rb
150
152
  - spec/webhooks/transifex/hook_handler_spec.rb
151
153
  - spec/webhooks/transifex/request_handler_spec.rb
152
154
  - spec/zip_stream_response_spec.rb