txgh 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +202 -0
  3. data/README.md +64 -0
  4. data/lib/ext/zipline/output_stream.rb +62 -0
  5. data/lib/txgh.rb +53 -0
  6. data/lib/txgh/app.rb +135 -0
  7. data/lib/txgh/category_support.rb +31 -0
  8. data/lib/txgh/config.rb +11 -0
  9. data/lib/txgh/config/config_pair.rb +36 -0
  10. data/lib/txgh/config/key_manager.rb +54 -0
  11. data/lib/txgh/config/provider_instance.rb +20 -0
  12. data/lib/txgh/config/provider_support.rb +26 -0
  13. data/lib/txgh/config/providers.rb +9 -0
  14. data/lib/txgh/config/providers/file_provider.rb +19 -0
  15. data/lib/txgh/config/providers/git_provider.rb +58 -0
  16. data/lib/txgh/config/providers/raw_provider.rb +19 -0
  17. data/lib/txgh/config/tx_config.rb +77 -0
  18. data/lib/txgh/config/tx_manager.rb +15 -0
  19. data/lib/txgh/diff_calculator.rb +90 -0
  20. data/lib/txgh/empty_resource_contents.rb +43 -0
  21. data/lib/txgh/errors.rb +9 -0
  22. data/lib/txgh/github_api.rb +83 -0
  23. data/lib/txgh/github_repo.rb +88 -0
  24. data/lib/txgh/github_request_auth.rb +28 -0
  25. data/lib/txgh/handlers.rb +12 -0
  26. data/lib/txgh/handlers/download_handler.rb +84 -0
  27. data/lib/txgh/handlers/github.rb +10 -0
  28. data/lib/txgh/handlers/github/delete_handler.rb +65 -0
  29. data/lib/txgh/handlers/github/handler.rb +20 -0
  30. data/lib/txgh/handlers/github/push_handler.rb +108 -0
  31. data/lib/txgh/handlers/github/request_handler.rb +106 -0
  32. data/lib/txgh/handlers/response.rb +17 -0
  33. data/lib/txgh/handlers/stream_response.rb +39 -0
  34. data/lib/txgh/handlers/tgz_stream_response.rb +41 -0
  35. data/lib/txgh/handlers/transifex.rb +8 -0
  36. data/lib/txgh/handlers/transifex/hook_handler.rb +77 -0
  37. data/lib/txgh/handlers/transifex/request_handler.rb +78 -0
  38. data/lib/txgh/handlers/triggers.rb +9 -0
  39. data/lib/txgh/handlers/triggers/handler.rb +66 -0
  40. data/lib/txgh/handlers/triggers/pull_handler.rb +29 -0
  41. data/lib/txgh/handlers/triggers/push_handler.rb +21 -0
  42. data/lib/txgh/handlers/zip_stream_response.rb +21 -0
  43. data/lib/txgh/merge_calculator.rb +74 -0
  44. data/lib/txgh/parse_config.rb +24 -0
  45. data/lib/txgh/resource_committer.rb +39 -0
  46. data/lib/txgh/resource_contents.rb +118 -0
  47. data/lib/txgh/resource_downloader.rb +141 -0
  48. data/lib/txgh/resource_updater.rb +104 -0
  49. data/lib/txgh/response_helpers.rb +30 -0
  50. data/lib/txgh/transifex_api.rb +165 -0
  51. data/lib/txgh/transifex_project.rb +37 -0
  52. data/lib/txgh/transifex_request_auth.rb +53 -0
  53. data/lib/txgh/tx_branch_resource.rb +59 -0
  54. data/lib/txgh/tx_logger.rb +12 -0
  55. data/lib/txgh/tx_resource.rb +66 -0
  56. data/lib/txgh/utils.rb +44 -0
  57. data/lib/txgh/version.rb +3 -0
  58. data/spec/app_spec.rb +346 -0
  59. data/spec/category_support_spec.rb +43 -0
  60. data/spec/config/config_pair_spec.rb +47 -0
  61. data/spec/config/key_manager_spec.rb +48 -0
  62. data/spec/config/provider_instance_spec.rb +30 -0
  63. data/spec/config/provider_support_spec.rb +55 -0
  64. data/spec/config/tx_config_spec.rb +49 -0
  65. data/spec/config/tx_manager_spec.rb +57 -0
  66. data/spec/diff_calculator_spec.rb +90 -0
  67. data/spec/github_api_spec.rb +148 -0
  68. data/spec/github_repo_spec.rb +178 -0
  69. data/spec/github_request_auth_spec.rb +39 -0
  70. data/spec/handlers/download_handler_spec.rb +81 -0
  71. data/spec/handlers/github/delete_handler_spec.rb +71 -0
  72. data/spec/handlers/github/push_handler_spec.rb +76 -0
  73. data/spec/handlers/tgz_stream_response_spec.rb +59 -0
  74. data/spec/handlers/transifex/hook_handler_spec.rb +115 -0
  75. data/spec/handlers/zip_stream_response_spec.rb +58 -0
  76. data/spec/helpers/github_payload_builder.rb +141 -0
  77. data/spec/helpers/integration_setup.rb +47 -0
  78. data/spec/helpers/nil_logger.rb +10 -0
  79. data/spec/helpers/standard_txgh_setup.rb +92 -0
  80. data/spec/helpers/test_provider.rb +12 -0
  81. data/spec/integration/cassettes/github_l10n_hook_endpoint.yml +536 -0
  82. data/spec/integration/cassettes/pull.yml +47 -0
  83. data/spec/integration/cassettes/push.yml +544 -0
  84. data/spec/integration/cassettes/transifex_hook_endpoint.yml +560 -0
  85. data/spec/integration/config/tx.config +10 -0
  86. data/spec/integration/hooks_spec.rb +158 -0
  87. data/spec/integration/payloads/github_postbody.json +161 -0
  88. data/spec/integration/payloads/github_postbody_l10n.json +136 -0
  89. data/spec/integration/payloads/github_postbody_release.json +136 -0
  90. data/spec/integration/triggers_spec.rb +45 -0
  91. data/spec/merge_calculator_spec.rb +112 -0
  92. data/spec/parse_config_spec.rb +52 -0
  93. data/spec/resource_committer_spec.rb +42 -0
  94. data/spec/resource_contents_spec.rb +212 -0
  95. data/spec/resource_downloader_spec.rb +205 -0
  96. data/spec/resource_updater_spec.rb +147 -0
  97. data/spec/spec_helper.rb +32 -0
  98. data/spec/transifex_api_spec.rb +345 -0
  99. data/spec/transifex_project_spec.rb +45 -0
  100. data/spec/transifex_request_auth_spec.rb +39 -0
  101. data/spec/tx_branch_resource_spec.rb +99 -0
  102. data/spec/tx_resource_spec.rb +47 -0
  103. data/spec/utils_spec.rb +58 -0
  104. data/txgh.gemspec +29 -0
  105. metadata +296 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9ec3f22b53b126054d2701a552de557e53058336
4
+ data.tar.gz: 38a63ad5e99c5e0b18f66e44b9ea5c21fe8fad03
5
+ SHA512:
6
+ metadata.gz: 69d0266b6817987b5e35b1e6e553ecea97b3d4508fd79f26abe29b9d65f0b42ad7a097a2cd1bb3010d6c2c37e1ba449dd3efcfc9984c2ee570e8f8643e3ec15e
7
+ data.tar.gz: f741b3996704abe11f4d05320be5bdcb9d269f825a4e0b68680ded32d1942fe5c784cf631731e15837e215533efdc3c4859dc8dd9db0a1b9328d5c96f7fb66e3
data/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright {yyyy} {name of copyright owner}
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
202
+
data/README.md ADDED
@@ -0,0 +1,64 @@
1
+ Transifex Txgh (Lumos Labs fork)
2
+ ====
3
+
4
+ [![Build Status](https://travis-ci.org/lumoslabs/txgh.svg?branch=master)](https://travis-ci.org/lumoslabs/txgh)
5
+
6
+ Txgh, a mashup of "_T_ransife_x_" and "_G_it_h_ub", is a lightweight server that connects Transifex to Github via webhooks. It enables automatic translation of new content in your Github repository, and supports single-resource as well as branch-based git workflows.
7
+
8
+
9
+ How Does it Work?
10
+ ---
11
+
12
+ Configure Transifex and Github:
13
+
14
+ 1. Add a service hook to your Github repo and point it to your running Txgh instance.
15
+ 2. Configure a service hook for your project in Transifex (via the settings page).
16
+
17
+ This enables the following automated processes:
18
+
19
+ 1. When a source file is pushed to Github, the Txgh service will update the corresponding Transifex resource with the contents of the new file. Configuration options exist to process only certain branches and tags.
20
+
21
+ 2. When a resource in Transifex reaches 100% translated, the Txgh service will download the translations and commit them to the target repository. Configuration options exist to protect certain branches or tags from automatic commits.
22
+
23
+ <br>
24
+ For the more visually inclined:
25
+ ![Txgh Use Cases](https://www.gliffy.com/go/publish/image/9483799/L.png)
26
+ <br>
27
+ <br>
28
+
29
+ Supported Workflows
30
+ ---
31
+
32
+ Use the following table to determine if Txgh will work for your git and translation workflow:
33
+
34
+ |Workflow|Comments|
35
+ |:--------|:----------|
36
+ |**Basic**<br>* You maintain one master version of your translations<br>* Translations may not be under source control<br>* New content is translated before each release and does not change|This is the default. Txgh <br> can also be configured to only<br> listen for changes that happen<br> on a certain branch or tag.|
37
+ |**Multi-branch**<br>* Your team is small or everyone works from the same branch<br>* Translations should change when code changes|You might want to consider <br>multi-branch with diffs (below)<br> since your translators may see<br> a number of duplicate strings<br> in Transifex using this workflow.|
38
+ |**Multi-branch with Diffs**<br>* Your team uses git branches for feature development<br>* Translations should change when code changes|This is the recommended workflow<br> if you'd like to manage translations<br> in an agile way, i.e. "continuous<br> translation." Only new and changed<br> phrases are uploaded to Transifex.|
39
+
40
+ Running Txgh
41
+ ---
42
+
43
+ Txgh is distributed as a [Docker image](https://quay.io/repository/lumoslabs/txgh) and as a [Rubygem](). You can choose to run it via Docker, install and run it as a Rubygem, or run it straight from a local clone of this repository.
44
+
45
+ In order to run the server, you need to have Ruby 2.1.5 and bundler installed.
46
+
47
+ There are 2 important configuration files.
48
+
49
+ txgh.yml - This is the base configuration for the service. For 12 factor app support, this file should pull it's settings from the Ruby ENV. Additionally, this file can be located in the users $HOME directory to support running the server with hard coded values.
50
+
51
+
52
+ tx.config - This is a configuration which maps the source file, languages, and target translation files. It is based on this specification: http://docs.transifex.com/client/config/#txconfig
53
+
54
+
55
+ AWS
56
+ ---
57
+
58
+ https://github.com/transifex/txgh/issues/14
59
+
60
+
61
+ Heroku
62
+ ---
63
+
64
+ https://www.transifex.com/blog/2015/bridging-github-and-transifex-with-txgh/
@@ -0,0 +1,62 @@
1
+ # Taken from https://github.com/fringd/zipline
2
+ # Didn't include zipline gem b/c it depends directly on rails and brings in a
3
+ # ton of useless dependencies
4
+
5
+ require 'stringio'
6
+ require 'zip'
7
+
8
+ # a ZipOutputStream that never rewinds output
9
+ # in order for that to be possible we store only uncompressed files
10
+ module Zipline
11
+ class OutputStream < Zip::OutputStream
12
+
13
+ #we need to be able to hand out own custom output in order to stream to browser
14
+ def initialize(io)
15
+ # Create an io stream thing
16
+ super StringIO.new, true
17
+ # Overwrite it with my own
18
+ @output_stream = io
19
+ end
20
+
21
+ def stream
22
+ @output_stream
23
+ end
24
+
25
+ def put_next_entry(entry_name, size)
26
+ new_entry = Zip::Entry.new(@file_name, entry_name)
27
+
28
+ #THIS IS THE MAGIC, tells zip to look after data for size, crc
29
+ new_entry.gp_flags = new_entry.gp_flags | 0x0008
30
+
31
+ super(new_entry)
32
+
33
+ # Uncompressed size in the local file header must be zero when bit 3
34
+ # of the general purpose flags is set, so set the size after the header
35
+ # has been written.
36
+ new_entry.size = size
37
+ end
38
+
39
+ # just reset state, no rewinding required
40
+ def finalize_current_entry
41
+ if current_entry
42
+ entry = current_entry
43
+ super
44
+ write_local_footer(entry)
45
+ end
46
+ end
47
+
48
+ def write_local_footer(entry)
49
+ @output_stream << [ 0x08074b50, entry.crc, entry.compressed_size, entry.size].pack('VVVV')
50
+ end
51
+
52
+ #never need to do this because we set correct sizes up front
53
+ def update_local_headers
54
+ nil
55
+ end
56
+
57
+ # helper to deal with difference between rubyzip 1.0 and 1.1
58
+ def current_entry
59
+ @currentEntry || @current_entry
60
+ end
61
+ end
62
+ end
data/lib/txgh.rb ADDED
@@ -0,0 +1,53 @@
1
+ require 'txgh/errors'
2
+ require 'yaml'
3
+
4
+ module Txgh
5
+ autoload :Application, 'txgh/app'
6
+ autoload :CategorySupport, 'txgh/category_support'
7
+ autoload :Config, 'txgh/config'
8
+ autoload :DiffCalculator, 'txgh/diff_calculator'
9
+ autoload :EmptyResourceContents, 'txgh/empty_resource_contents'
10
+ autoload :GithubApi, 'txgh/github_api'
11
+ autoload :GithubRepo, 'txgh/github_repo'
12
+ autoload :GithubRequestAuth, 'txgh/github_request_auth'
13
+ autoload :Handlers, 'txgh/handlers'
14
+ autoload :Hooks, 'txgh/app'
15
+ autoload :MergeCalculator, 'txgh/merge_calculator'
16
+ autoload :ParseConfig, 'txgh/parse_config'
17
+ autoload :ResourceCommitter, 'txgh/resource_committer'
18
+ autoload :ResourceContents, 'txgh/resource_contents'
19
+ autoload :ResourceDownloader, 'txgh/resource_downloader'
20
+ autoload :ResourceUpdater, 'txgh/resource_updater'
21
+ autoload :ResponseHelpers, 'txgh/response_helpers'
22
+ autoload :TransifexApi, 'txgh/transifex_api'
23
+ autoload :TransifexProject, 'txgh/transifex_project'
24
+ autoload :TransifexRequestAuth, 'txgh/transifex_request_auth'
25
+ autoload :Triggers, 'txgh/app'
26
+ autoload :TxBranchResource, 'txgh/tx_branch_resource'
27
+ autoload :TxLogger, 'txgh/tx_logger'
28
+ autoload :TxResource, 'txgh/tx_resource'
29
+ autoload :Utils, 'txgh/utils'
30
+
31
+ class << self
32
+ def tx_manager
33
+ Txgh::Config::TxManager
34
+ end
35
+
36
+ def key_manager
37
+ Txgh::Config::KeyManager
38
+ end
39
+
40
+ def providers
41
+ Txgh::Config::Providers
42
+ end
43
+ end
44
+
45
+ # default set of tx config providers
46
+ tx_manager.register_provider(providers::FileProvider, Txgh::Config::TxConfig)
47
+ tx_manager.register_provider(providers::GitProvider, Txgh::Config::TxConfig)
48
+ tx_manager.register_provider(providers::RawProvider, Txgh::Config::TxConfig)
49
+
50
+ # default set of base config providers
51
+ key_manager.register_provider(providers::FileProvider, YAML)
52
+ key_manager.register_provider(providers::RawProvider, YAML)
53
+ end
data/lib/txgh/app.rb ADDED
@@ -0,0 +1,135 @@
1
+ require 'sinatra'
2
+ require 'sinatra/json'
3
+ require 'sinatra/reloader'
4
+ require 'sinatra/streaming'
5
+
6
+ module Txgh
7
+ module RespondWith
8
+ def respond_with(resp)
9
+ env['txgh.response'] = resp
10
+
11
+ if resp.streaming?
12
+ response.headers.merge!(resp.headers)
13
+
14
+ stream do |out|
15
+ resp.write_to(out)
16
+ end
17
+ else
18
+ status resp.status
19
+ json resp.body
20
+ end
21
+ end
22
+ end
23
+
24
+ class Application < Sinatra::Base
25
+ include Txgh::Handlers
26
+
27
+ helpers Sinatra::Streaming
28
+ helpers RespondWith
29
+
30
+ configure do
31
+ set :logging, nil
32
+ logger = Txgh::TxLogger.logger
33
+ set :logger, logger
34
+ end
35
+
36
+ def initialize(app = nil)
37
+ super(app)
38
+ end
39
+
40
+ get '/health_check' do
41
+ respond_with(
42
+ Response.new(200, {})
43
+ )
44
+ end
45
+
46
+ get '/config' do
47
+ config = Txgh::Config::KeyManager.config_from_project(params[:project_slug])
48
+ branch = Utils.absolute_branch(params[:branch])
49
+
50
+ begin
51
+ tx_config = Txgh::Config::TxManager.tx_config(
52
+ config.transifex_project, config.github_repo, branch
53
+ )
54
+
55
+ data = tx_config.to_h
56
+ data.merge!(branch_slug: Utils.slugify(branch)) if branch
57
+
58
+ status 200
59
+ json data: data
60
+ rescue ConfigNotFoundError => e
61
+ status 404
62
+ json [{ error: e.message }]
63
+ rescue => e
64
+ status 500
65
+ json [{ error: e.message }]
66
+ end
67
+ end
68
+
69
+ get '/download.:format' do
70
+ respond_with(
71
+ DownloadHandler.handle_request(request, settings.logger)
72
+ )
73
+ end
74
+ end
75
+
76
+ # Hooks are protected endpoints used for data integration between Github and
77
+ # Transifex. They live under the /hooks namespace (see config.ru)
78
+ class Hooks < Sinatra::Base
79
+ include Txgh::Handlers
80
+
81
+ helpers RespondWith
82
+
83
+ configure do
84
+ set :logging, nil
85
+ logger = Txgh::TxLogger.logger
86
+ set :logger, logger
87
+ end
88
+
89
+ configure :development do
90
+ register Sinatra::Reloader
91
+ end
92
+
93
+ def initialize(app = nil)
94
+ super(app)
95
+ end
96
+
97
+ post '/transifex' do
98
+ respond_with(
99
+ Transifex::RequestHandler.handle_request(request, settings.logger)
100
+ )
101
+ end
102
+
103
+ post '/github' do
104
+ respond_with(
105
+ Github::RequestHandler.handle_request(request, settings.logger)
106
+ )
107
+ end
108
+ end
109
+
110
+ class Triggers < Sinatra::Base
111
+ helpers RespondWith
112
+
113
+ configure do
114
+ set :logging, nil
115
+ logger = Txgh::TxLogger.logger
116
+ set :logger, logger
117
+ end
118
+
119
+ configure :development do
120
+ register Sinatra::Reloader
121
+ end
122
+
123
+ patch '/push' do
124
+ respond_with(
125
+ Txgh::Handlers::Triggers::PushHandler.handle_request(request, settings.logger)
126
+ )
127
+ end
128
+
129
+ patch '/pull' do
130
+ respond_with(
131
+ Txgh::Handlers::Triggers::PullHandler.handle_request(request, settings.logger)
132
+ )
133
+ end
134
+ end
135
+ end