pronto 0.9.5 → 0.11.0

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
- SHA1:
3
- metadata.gz: 751d40e214f58802ae6f48a1c71a8bee1780dc81
4
- data.tar.gz: ab5ffa282a02e967c825120dda4b19cb0cd66439
2
+ SHA256:
3
+ metadata.gz: 46470dd7ac5341cc9bebbf13127f62c06d5d5a19cf55578a40439265761d59b3
4
+ data.tar.gz: a6a51d6593f9c4e521c8adf4a7fca559c3342931e7b207659e620d8d3585678a
5
5
  SHA512:
6
- metadata.gz: 6160600de386512e3924bcc578b83995cccbf5ca44b4a57ae2476828fde3c796783eadb3edeb88923efddd28bbc8d395d09797626c0b7fccd5a8388ae18cf507
7
- data.tar.gz: 180b4f95b5fa3407e3f04e6327327634b9bfe9b54a8feb52b95a2685918492512e0174770f5034c813bc225b43a3bc477e480a87161038604b94e02f7f038104
6
+ metadata.gz: e500bc433123227725e318c285995986ba6cf4a5281cbcb2be92aaac130515a788be5fabdd957d9d95e2f58fb95708bed6db193ab340c123760d8210471f4995
7
+ data.tar.gz: 1342570798515c8efdfcc17eaf383c308c8875031dd61cb4eef5821513c8e3a748b411b7112d5c210dabda11afc0831fc5767f08729dcad8d452e9c1215c60c1
@@ -0,0 +1,3 @@
1
+ # Order is important. The last matching pattern takes the most precedence.
2
+ # Default owners for everything in the repo.
3
+ * @prontolabs/core
data/CHANGELOG.md CHANGED
@@ -2,6 +2,55 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.11.0
6
+
7
+ ### New features
8
+
9
+ * [#304](https://github.com/prontolabs/pronto/pull/304) add option to limit comments per PR review
10
+ * [#333](https://github.com/prontolabs/pronto/pull/333) add github_combined_status formatter
11
+ * [#334](https://github.com/prontolabs/pronto/pull/334) add configurable review_type for GitHub (with REQUEST_CHANGES as default)
12
+ * [#351](https://github.com/prontolabs/pronto/pull/351) add gitLab_mr formatter
13
+ * [#369](https://github.com/prontolabs/pronto/pull/369) make Pronto::Git::Patch#new_file_path public
14
+ * update to the BitBucket 2.0 API (_as the 1.0 API was deprecated_) via [#347](https://github.com/prontolabs/pronto/pull/347), [#348](https://github.com/prontolabs/pronto/pull/348), [#352](https://github.com/prontolabs/pronto/pull/352) and [#354](https://github.com/prontolabs/pronto/pull/354)
15
+
16
+ ### Bugs fixed
17
+
18
+ * [#344](https://github.com/prontolabs/pronto/pull/344) treat Gemfile and .gemspecs as Ruby
19
+ * [#380](https://github.com/prontolabs/pronto/pull/380) fix compatibility with rugged >= 0.99
20
+ * [#387](https://github.com/prontolabs/pronto/pull/387) fix running pronto inside git submodules
21
+
22
+ ### Changes
23
+
24
+ * [#370](https://github.com/prontolabs/pronto/pull/370) allow thor 1.x gem versions
25
+ * [#379](https://github.com/prontolabs/pronto/pull/379) allow rugged 1.0.x gem versions
26
+ * [#386](https://github.com/prontolabs/pronto/pull/386) add ruby 2.7 to CI
27
+ * [#390](https://github.com/prontolabs/pronto/pull/390) fix issue with generating Sorbet RBI
28
+ * [#396](https://github.com/prontolabs/pronto/pull/396) add support for Ruby 3.0
29
+ * document/improve GitHub Actions integration in README.md via [#360](https://github.com/prontolabs/pronto/pull/360), [#378](https://github.com/prontolabs/pronto/pull/378) and [#389](https://github.com/prontolabs/pronto/pull/389)
30
+ * add links to additional pronto runners in README.md
31
+
32
+ ## 0.10.0
33
+
34
+ ### New features
35
+
36
+ * [#301](https://github.com/prontolabs/pronto/pull/301): add ability to auto approve Bitbucket pull requests.
37
+ * [#331](https://github.com/prontolabs/pronto/pull/331): allow to specify PATH in "run" command.
38
+
39
+ ### Bugs fixed
40
+
41
+ * [#258](https://github.com/prontolabs/pronto/pull/258): fix blame returning nil when file does not exist in the git tree.
42
+ * [#270](https://github.com/prontolabs/pronto/pull/270): fix ${line} in text format to mean line number.
43
+ * [#282](https://github.com/prontolabs/pronto/issues/282): relax rainbow dependency.
44
+ * [#329](https://github.com/prontolabs/pronto/pull/329): correctly handle renamed-only files.
45
+
46
+ ### Changes
47
+
48
+ * Depend on thor `0.20.*`.
49
+ * [#298](https://github.com/prontolabs/pronto/pull/298): change default GitLab API endpoint to v4.
50
+ * [#332](https://github.com/prontolabs/pronto/pull/332): remove support for Ruby older than 2.3.0.
51
+
52
+ ## 0.9.5
53
+
5
54
  ### Bugs fixed
6
55
 
7
56
  * [#253](https://github.com/prontolabs/pronto/pull/253): fix an infinite loop when Bitbucket Server sends a paginated response.
@@ -51,7 +100,7 @@
51
100
  ### Changes
52
101
 
53
102
  * [#193](https://github.com/prontolabs/pronto/issues/193): rename `pronto run --index` option to `--unstaged`.
54
- * [#49](https://github.com/prontolabs/pronto/issues/49): handle non-existance of GitHub pull requests gracefully.
103
+ * [#49](https://github.com/prontolabs/pronto/issues/49): handle nonexistence of GitHub pull requests gracefully.
55
104
  * [#217](https://github.com/prontolabs/pronto/issues/217): depend on `octokit >= 4.7.0`.
56
105
  * [#224](https://github.com/prontolabs/pronto/issues/224): depend on `gitlab >= 4.0.0`.
57
106
  * [#222](https://github.com/prontolabs/pronto/pull/184): prefix PULL_REQUEST_ID env variable with `PRONTO_`.
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License
2
2
 
3
- Copyright (c) 2017 Mindaugas Mozūras
3
+ Copyright (c) 2018 Mindaugas Mozūras
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,10 +1,9 @@
1
1
  # Pronto
2
2
 
3
3
  [![Build Status](https://secure.travis-ci.org/prontolabs/pronto.svg)](http://travis-ci.org/prontolabs/pronto)
4
- [![Coverage Status](https://img.shields.io/codeclimate/coverage/github/prontolabs/pronto.svg)](https://codeclimate.com/github/prontolabs/pronto)
4
+ [![Coverage Status](https://img.shields.io/codeclimate/coverage/prontolabs/pronto.svg)](https://codeclimate.com/github/prontolabs/pronto)
5
5
  [![Code Climate](https://codeclimate.com/github/prontolabs/pronto.svg)](https://codeclimate.com/github/prontolabs/pronto)
6
6
  [![Gem Version](https://badge.fury.io/rb/pronto.svg)](http://badge.fury.io/rb/pronto)
7
- [![Dependency Status](https://gemnasium.com/prontolabs/pronto.svg)](https://gemnasium.com/prontolabs/pronto)
8
7
  [![Inline docs](http://inch-ci.org/github/prontolabs/pronto.svg)](http://inch-ci.org/github/prontolabs/pronto)
9
8
 
10
9
  **Pronto** runs analysis quickly by checking only the relevant changes. Created to
@@ -111,18 +110,40 @@ If you want comments to appear on pull request diff, instead of commit:
111
110
  $ PRONTO_GITHUB_ACCESS_TOKEN=token pronto run -f github_pr -c origin/master
112
111
  ```
113
112
 
114
- If you want review to appear on pull request diff, instead of comments:
113
+ If you want review to appear on pull request diff, instead of separate comments:
115
114
 
116
115
  ```sh
117
116
  $ PRONTO_GITHUB_ACCESS_TOKEN=token pronto run -f github_pr_review -c origin/master
118
117
  ```
119
118
 
119
+ All the **N** pending comments will be now separated into **X** number of PR reviews.
120
+ The number of the PR reviews will be controlled by an additional environment variable or with the help of a config setting.
121
+ This way, by a single pronto run, all the comments will be published to the PR, but divided into small reviews
122
+ in order to avoid the rate limit of the providers.
123
+
124
+ ```
125
+ X = N / {PRONTO_WARNINGS_PER_REVIEW || warnings_per_review || 30})
126
+ ```
127
+
128
+ Note: In case no environment variable or config setting is specified in `.pronto.yml`,
129
+ a default value of `30` will be used.
130
+
131
+ ```sh
132
+ $ PRONTO_WARNINGS_PER_REVIEW=30 PRONTO_GITHUB_ACCESS_TOKEN=token pronto run -f github_pr_review -c origin/master
133
+ ```
134
+
120
135
  Use `GithubStatusFormatter` to submit [commit status](https://github.com/blog/1227-commit-status-api):
121
136
 
122
137
  ```sh
123
138
  $ PRONTO_GITHUB_ACCESS_TOKEN=token pronto run -f github_status -c origin/master
124
139
  ```
125
140
 
141
+ If you want to show a one single status for all runners, instead of status per runner:
142
+
143
+ ```sh
144
+ $ PRONTO_GITHUB_ACCESS_TOKEN=token pronto run -f github_combined_status -c origin/master
145
+ ```
146
+
126
147
  It's possible to combine multiple formatters.
127
148
  To get both pull request comments and commit status summary use:
128
149
 
@@ -141,6 +162,39 @@ formatters = [formatter, status_formatter]
141
162
  Pronto.run('origin/master', '.', formatters)
142
163
  ```
143
164
 
165
+ #### GitHub Actions Integration
166
+
167
+ You can also run Pronto as a GitHub action.
168
+
169
+ Here's an example `.github/workflows/pronto.yml` workflow file using the `github_status` and `github_pr` formatters and running on each GitHub PR, with `pronto-rubocop` as the runner:
170
+
171
+
172
+ ```yml
173
+ name: Pronto
174
+ on: [pull_request]
175
+
176
+ jobs:
177
+ pronto:
178
+
179
+ runs-on: ubuntu-latest
180
+
181
+ steps:
182
+ - name: Checkout code
183
+ uses: actions/checkout@v2
184
+ - run: |
185
+ git fetch --no-tags --prune --depth=10 origin +refs/heads/*:refs/remotes/origin/*
186
+ - name: Setup Ruby
187
+ uses: ruby/setup-ruby@v1
188
+ - name: Setup pronto
189
+ run: gem install pronto pronto-rubocop
190
+ - name: Run Pronto
191
+ run: pronto run -f github_status github_pr -c origin/${{ github.base_ref }}
192
+ env:
193
+ PRONTO_PULL_REQUEST_ID: ${{ github.event.pull_request.number }}
194
+ PRONTO_GITHUB_ACCESS_TOKEN: "${{ github.token }}"
195
+ ```
196
+ check Wiki on [GitHub Actions Integration](https://github.com/prontolabs/pronto/wiki/GitHub-Actions-Integration) for more info.
197
+
144
198
  ### GitLab Integration
145
199
 
146
200
  You can run Pronto as a step of your CI builds and get the results as comments
@@ -151,7 +205,7 @@ on GitLab commits using `GitlabFormatter`.
151
205
  Set the `PRONTO_GITLAB_API_ENDPOINT` environment variable or value in `.pronto.yml` to
152
206
  your API endpoint URL. If you are using Gitlab.com's hosted service your
153
207
  endpoint will be set by default.
154
- Set the `PRONTO_GITLAB_API_PRIVATE_TOKEN` environment variable or value in `.pronto.yml
208
+ Set the `PRONTO_GITLAB_API_PRIVATE_TOKEN` environment variable or value in `.pronto.yml`
155
209
  to your Gitlab private token which you can find in your account settings.
156
210
 
157
211
  Then just run it:
@@ -160,6 +214,29 @@ Then just run it:
160
214
  $ PRONTO_GITLAB_API_PRIVATE_TOKEN=token pronto run -f gitlab -c origin/master
161
215
  ```
162
216
 
217
+ **note: this requires at least Gitlab 11.6+**
218
+
219
+ Merge request integration:
220
+
221
+ ```sh
222
+ $ PRONTO_GITLAB_API_PRIVATE_TOKEN=token PRONTO_PULL_REQUEST_ID=id pronto run -f gitlab_mr -c origin/master
223
+ ```
224
+
225
+ On GitLabCI make make sure to run Pronto in a [merge request pipeline](https://docs.gitlab.com/ce/ci/merge_request_pipelines/):
226
+
227
+ ```yml
228
+ lint:
229
+ image: ruby
230
+ variables:
231
+ PRONTO_GITLAB_API_ENDPOINT: "https://gitlab.com/api/v4"
232
+ PRONTO_GITLAB_API_PRIVATE_TOKEN: token
233
+ only:
234
+ - merge_requests
235
+ script:
236
+ - bundle install
237
+ - bundle exec pronto run -f gitlab_mr -c origin/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME
238
+ ```
239
+
163
240
  ### Bitbucket Integration
164
241
 
165
242
  You can run Pronto as a step of your CI builds and get the results as comments
@@ -168,7 +245,6 @@ on Bitbucket commits using `BitbucketFormatter` or `BitbucketPullRequestFormatte
168
245
  Add Pronto runners you want to use to your Gemfile:
169
246
 
170
247
  Set the PRONTO_BITBUCKET_USERNAME and PRONTO_BITBUCKET_PASSWORD environment variables or values in `.pronto.yml`.
171
- .
172
248
 
173
249
  Then just run it:
174
250
 
@@ -212,6 +288,7 @@ bitbucket:
212
288
  password: pass
213
289
  web_endpoint: https://bitbucket.org/
214
290
  max_warnings: 150
291
+ warnings_per_review: 30
215
292
  verbose: false
216
293
  ```
217
294
 
@@ -262,20 +339,34 @@ The following values are available only to the text formatter:
262
339
  Pronto can run various tools and libraries, as long as there's a runner for it.
263
340
  Currently available:
264
341
 
342
+ * [pronto-bigfiles](https://github.com/apiology/pronto-bigfiles)
343
+ * [pronto-blacklist](https://github.com/pbstriker38/pronto-blacklist)
265
344
  * [pronto-brakeman](https://github.com/prontolabs/pronto-brakeman)
345
+ * [pronto-bundler_audit](https://github.com/pdobb/pronto-bundler_audit)
346
+ * [pronto-checkstyle](https://github.com/seikichi/pronto-checkstyle)
266
347
  * [pronto-coffeelint](https://github.com/siebertm/pronto-coffeelint)
348
+ * [pronto-clang_format](https://github.com/micjabbour/pronto-clang_format)
349
+ * [pronto-clang_tidy](https://github.com/micjabbour/pronto-clang_tidy)
267
350
  * [pronto-clippy](https://github.com/hauleth/pronto-clippy)
268
351
  * [pronto-credo](https://github.com/carakan/pronto-credo)
352
+ * [pronto-dialyxir](https://github.com/Apelsinka223/pronto-dialyxir)
269
353
  * [pronto-dialyzer](https://github.com/iurifq/pronto-dialyzer)
270
354
  * [pronto-dirty_words](https://github.com/kevinjalbert/pronto-dirty_words)
271
355
  * [pronto-dogma](https://github.com/iurifq/pronto-dogma)
356
+ * [pronto-erb_lint](https://github.com/tleish/pronto-erb_lint)
272
357
  * [pronto-eslint](https://github.com/prontolabs/pronto-eslint) (uses [eslintrb](https://github.com/zendesk/eslintrb))
273
358
  * [pronto-eslint_npm](https://github.com/doits/pronto-eslint_npm) (uses eslint installed from npm)
274
359
  * [pronto-fasterer](https://github.com/prontolabs/pronto-fasterer)
360
+ * [pronto-findbugs](https://github.com/seikichi/pronto-findbugs)
361
+ * [pronto-flake8](https://github.com/scoremedia/pronto-flake8)
275
362
  * [pronto-flay](https://github.com/prontolabs/pronto-flay)
276
363
  * [pronto-flow](https://github.com/kevinjalbert/pronto-flow)
277
364
  * [pronto-foodcritic](https://github.com/prontolabs/pronto-foodcritic)
365
+ * [pronto-goodcheck](https://github.com/aergonaut/pronto-goodcheck)
278
366
  * [pronto-haml](https://github.com/prontolabs/pronto-haml)
367
+ * [pronto-hlint](https://github.com/fretlink/pronto-hlint/) (uses Haskell code suggestions [hlint](https://github.com/ndmitchell/hlint))
368
+ * [pronto-infer](https://github.com/seikichi/pronto-infer)
369
+ * [pronto-inspec](https://github.com/stiller-leser/pronto-inspec)
279
370
  * [pronto-jscs](https://github.com/spajus/pronto-jscs)
280
371
  * [pronto-jshint](https://github.com/prontolabs/pronto-jshint)
281
372
  * [pronto-json](https://github.com/deees/pronto-json)
@@ -283,8 +374,11 @@ Currently available:
283
374
  * [pronto-perl_lint](https://github.com/bells17/pronto-perl_lint)
284
375
  * [pronto-phpcs](https://github.com/EllisV/pronto-phpcs)
285
376
  * [pronto-phpmd](https://github.com/EllisV/pronto-phpmd)
377
+ * [pronto-phpstan](https://github.com/Powerhamster/pronto-phpstan)
286
378
  * [pronto-poper](https://github.com/prontolabs/pronto-poper)
379
+ * [pronto-punchlist](https://github.com/apiology/pronto-punchlist)
287
380
  * [pronto-rails_best_practices](https://github.com/prontolabs/pronto-rails_best_practices)
381
+ * [pronto-rails_data_schema](https://github.com/mbajur/pronto-rails_data_schema)
288
382
  * [pronto-rails_schema](https://github.com/raimondasv/pronto-rails_schema)
289
383
  * [pronto-reek](https://github.com/prontolabs/pronto-reek)
290
384
  * [pronto-rubocop](https://github.com/prontolabs/pronto-rubocop)
@@ -292,28 +386,36 @@ Currently available:
292
386
  * [pronto-shellcheck](https://github.com/pclalv/pronto-shellcheck)
293
387
  * [pronto-slim](https://github.com/nysthee/pronto-slim)
294
388
  * [pronto-slim_lint](https://github.com/ibrahima/pronto-slim_lint)
389
+ * [pronto-sorbet](https://github.com/teamsimplepay/pronto-sorbet)
295
390
  * [pronto-spell](https://github.com/prontolabs/pronto-spell)
391
+ * [pronto-standardrb](https://github.com/julianrubisch/pronto-standardrb)
296
392
  * [pronto-stylelint](https://github.com/kevinjalbert/pronto-stylelint)
297
393
  * [pronto-swiftlint](https://github.com/ajanauskas/pronto-swiftlint)
298
394
  * [pronto-tailor](https://github.com/ajanauskas/pronto-tailor)
299
395
  * [pronto-textlint](https://github.com/seikichi/pronto-textlint)
300
396
  * [pronto-tslint_npm](https://github.com/eprislac/pronto-tslint_npm)
397
+ * [pronto-yamllint](https://github.com/pauliusm/pronto-yamllint)
398
+ * [pronto-undercover](https://github.com/grodowski/pronto-undercover)
399
+ * [pronto-xmllint](https://github.com/pauliusm/pronto-xmllint)
301
400
 
302
401
  ## Articles
303
402
 
304
403
  Articles to help you to get started:
305
404
 
405
+ * [Effortless Code Conventions Review for Pull Request Changes](https://jtway.co/effortless-code-review-for-pull-request-changes-241206b1cb04)
306
406
  * [Automating code review with Pronto (and friends)](http://everydayrails.com/2015/02/17/pronto-ruby-code-review.html)
307
407
  * [Setup Pronto with CircleCI](https://medium.com/@MaximAbramchuk/circleci-github-pr-commenting-ruby-scss-coffeescript-javascript-git-and-etc-fbcbe2a378a5#.gk5f14p3j)
308
408
  * [Continuous Static Analysis using Pronto](http://codingfearlessly.com/2014/11/06/continuous-static-analysis/)
309
409
  * [Pronto and git hooks](http://elliotthilaire.net/gem-pronto-and-git-hooks/)
310
410
  * [How to end fruitless dev discussions about your project’s code style?](https://medium.com/appaloosa-store-engineering/how-to-end-fruitless-dev-discussions-about-your-project-s-code-style-245070bff6d4)
311
- * [Free automated code reviews using Pronto](https://hovancik.net/blog/2016/04/11/free-automated-code-reviews-using-pronto.html)
411
+ * [Free automated code reviews using Pronto](https://hovancik.net/blog/2016/04/11/free-automated-code-reviews-using-pronto/)
312
412
  * [Automated Elixir code review with Github, Credo and Travis CI](https://medium.com/fazibear/automated-elixir-code-review-with-github-credo-and-travis-ci-986cd56b8f02)
313
413
  * [Running Rubocop before git commit](https://christoph.luppri.ch/articles/2016/11/21/running-rubocop-before-git-commit/)
314
414
  * [Pronto, Codeship and GitHub for automatic code review](http://abinoam.tl1n.com/pronto-codeship-and-github-for-automatic-code-review/)
315
415
  * [How to automatically review your PRs for style violations with Pronto and RuboCop](https://christoph.luppri.ch/articles/2017/03/05/how-to-automatically-review-your-prs-for-style-violations-with-pronto-and-rubocop/)
316
416
  * [Create your own Pronto Runner](https://kevinjalbert.com/create-your-own-pronto-runner/)
417
+ * [Make Code Reviews A Little Bit Better With Automation](https://medium.com/jimmy-farrell/make-codes-reviews-a-little-bit-better-with-automation-35640df08a62)
418
+ * [Stop shipping untested Ruby code with undercover](https://medium.com/futuredev/stop-shipping-untested-ruby-code-with-undercover-1edc963be4a6)
317
419
 
318
420
  Make a Pull Request to add something you wrote or found useful.
319
421
 
@@ -323,4 +425,4 @@ Make a Pull Request to add something you wrote or found useful.
323
425
 
324
426
  ## Copyright
325
427
 
326
- Copyright (c) 2013-2017 Mindaugas Mozūras. See [LICENSE](LICENSE) for further details.
428
+ Copyright (c) 2013-2018 Mindaugas Mozūras. See [LICENSE](LICENSE) for further details.
data/lib/pronto.rb CHANGED
@@ -42,9 +42,11 @@ require 'pronto/formatter/commit_formatter'
42
42
  require 'pronto/formatter/pull_request_formatter'
43
43
  require 'pronto/formatter/github_formatter'
44
44
  require 'pronto/formatter/github_status_formatter'
45
+ require 'pronto/formatter/github_combined_status_formatter'
45
46
  require 'pronto/formatter/github_pull_request_formatter'
46
47
  require 'pronto/formatter/github_pull_request_review_formatter'
47
48
  require 'pronto/formatter/gitlab_formatter'
49
+ require 'pronto/formatter/gitlab_merge_request_review_formatter'
48
50
  require 'pronto/formatter/bitbucket_formatter'
49
51
  require 'pronto/formatter/bitbucket_pull_request_formatter'
50
52
  require 'pronto/formatter/bitbucket_server_pull_request_formatter'
@@ -32,6 +32,13 @@ module Pronto
32
32
  end
33
33
  end
34
34
 
35
+ def approve_pull_request
36
+ client.approve_pull_request(slug, pull_id)
37
+ end
38
+
39
+ def unapprove_pull_request
40
+ client.unapprove_pull_request(slug, pull_id)
41
+ end
35
42
  private
36
43
 
37
44
  def slug
data/lib/pronto/cli.rb CHANGED
@@ -12,7 +12,7 @@ module Pronto
12
12
  end
13
13
  end
14
14
 
15
- desc 'run', 'Run Pronto'
15
+ desc 'run [PATH]', 'Run Pronto'
16
16
 
17
17
  method_option :'exit-code',
18
18
  type: :boolean,
@@ -45,7 +45,9 @@ module Pronto
45
45
  aliases: ['formatter', '-f'],
46
46
  desc: "Pick output formatters. Available: #{::Pronto::Formatter.names.join(', ')}"
47
47
 
48
- def run(path = nil)
48
+ def run(path = '.')
49
+ path = File.expand_path(path)
50
+
49
51
  gem_names = options[:runner].any? ? options[:runner] : ::Pronto::GemNames.new.to_a
50
52
  gem_names.each do |gem_name|
51
53
  require "pronto/#{gem_name}"
@@ -56,16 +58,19 @@ module Pronto
56
58
  commit_options = %i[staged unstaged index]
57
59
  commit = commit_options.find { |o| options[o] } || options[:commit]
58
60
 
59
- repo_workdir = ::Rugged::Repository.discover('.').workdir
61
+ repo_workdir = ::Rugged::Repository.discover(path).workdir
62
+ relative = path.sub(repo_workdir, '')
63
+
60
64
  messages = Dir.chdir(repo_workdir) do
61
- ::Pronto.run(commit, '.', formatters, path)
65
+ file = relative.length != path.length ? relative : nil
66
+ ::Pronto.run(commit, '.', formatters, file)
62
67
  end
63
68
  if options[:'exit-code']
64
69
  error_messages_count = messages.count { |m| m.level != :info }
65
70
  exit(error_messages_count)
66
71
  end
67
72
  rescue Rugged::RepositoryError
68
- puts '"pronto" should be run from a git repository'
73
+ puts '"pronto" must be run from within a git repository or must be supplied the path to a git repository'
69
74
  rescue Pronto::Error => e
70
75
  $stderr.puts "Pronto errored: #{e.message}"
71
76
  end
@@ -1,47 +1,86 @@
1
1
  class BitbucketClient
2
2
  include HTTParty
3
- base_uri 'https://api.bitbucket.org/1.0/repositories'
3
+ base_uri 'https://api.bitbucket.org/2.0/repositories'
4
4
 
5
5
  def initialize(username, password)
6
6
  self.class.basic_auth(username, password)
7
7
  end
8
8
 
9
9
  def commit_comments(slug, sha)
10
- response = get("/#{slug}/changesets/#{sha}/comments")
11
- openstruct(response)
10
+ response = get("/#{slug}/commit/#{sha}/comments?pagelen=100")
11
+ result = parse_comments(openstruct(response))
12
+ while (response['next'])
13
+ response = get response['next']
14
+ result.concat(parse_comments(openstruct(response)))
15
+ end
16
+ result
12
17
  end
13
18
 
14
19
  def create_commit_comment(slug, sha, body, path, position)
15
- post("/#{slug}/changesets/#{sha}/comments", body, path, position)
20
+ post("/#{slug}/commit/#{sha}/comments", body, path, position)
16
21
  end
17
22
 
18
23
  def pull_comments(slug, pull_id)
19
- response = get("/#{slug}/pullrequests/#{pull_id}/comments")
20
- openstruct(response)
24
+ response = get("/#{slug}/pullrequests/#{pull_id}/comments?pagelen=100")
25
+ parse_comments(openstruct(response))
26
+ result = parse_comments(openstruct(response))
27
+ while (response['next'])
28
+ response = get response['next']
29
+ result.concat(parse_comments(openstruct(response)))
30
+ end
31
+ result
21
32
  end
22
33
 
23
34
  def pull_requests(slug)
24
- base = 'https://api.bitbucket.org/2.0/repositories'
25
- response = get("#{base}/#{slug}/pullrequests?state=OPEN")
26
- openstruct(response['values'])
35
+ response = get("/#{slug}/pullrequests?state=OPEN")
36
+ openstruct(response)
27
37
  end
28
38
 
29
39
  def create_pull_comment(slug, pull_id, body, path, position)
30
40
  post("/#{slug}/pullrequests/#{pull_id}/comments", body, path, position)
31
41
  end
32
42
 
43
+ def approve_pull_request(slug, pull_id)
44
+ self.class.post("/#{slug}/pullrequests/#{pull_id}/approve")
45
+ end
46
+
47
+ def unapprove_pull_request(slug, pull_id)
48
+ self.class.delete("/#{slug}/pullrequests/#{pull_id}/approve")
49
+ end
50
+
33
51
  private
34
52
 
35
53
  def openstruct(response)
36
- response.map { |r| OpenStruct.new(r) }
54
+ if response['values']
55
+ response['values'].map { |r| OpenStruct.new(r) }
56
+ else
57
+ p response
58
+ raise 'BitBucket response invalid'
59
+ end
37
60
  end
38
61
 
62
+ def parse_comments(values)
63
+ values.each do |value|
64
+ value.content = value.content['raw']
65
+ value.line_to = value.inline ? value.inline['to'] : 0
66
+ value.filename = value.inline ? value.inline['path'] : ''
67
+ end
68
+ values
69
+ end
70
+
39
71
  def post(url, body, path, position)
40
72
  options = {
41
73
  body: {
42
- content: body,
43
- line_to: position,
44
- filename: path
74
+ content: {
75
+ raw: body
76
+ },
77
+ inline: {
78
+ to: position,
79
+ path: path
80
+ }
81
+ }.to_json,
82
+ headers: {
83
+ 'Content-Type': 'application/json'
45
84
  }
46
85
  }
47
86
  self.class.post(url, options)