[buildbucket-gerrit] support non-json bad responses

_fetch assumes that all not-ok responses are necessarily JSON.
That proved to be incorrect. Try to parse body of a not-OK response
as JSON, but if that fails, return a rejected promise with the textual
body.

Change-Id: I58c0e535b223779ee83593a64ecbd1b918e2fd5c
Reviewed-on: https://chromium-review.googlesource.com/1020406
Reviewed-by: Quinten Yearsley <qyearsley@chromium.org>
2 files changed
tree: 8cd7bfb36d3f14ad63e05bafe61319f6bf1ca382
  1. src/
  2. test/
  3. .eslintrc.json
  4. .gitignore
  5. BUILD
  6. codereview.settings
  7. LICENSE
  8. README.md
  9. run-with-prod-data.sh
  10. run-with-testsite.sh
  11. wct.conf.json
README.md

Buildbucket Plugin for Gerrit

Usage

This plugin is configured via the buildbucket.config file present in the repo‘s refs/meta/config ref, as well as the same file in all repositories in the repo’s inheritance chain (up to and including All-Projects).

An example buildbucket.config is below:

[host]
  git = "chromium.googlesource.com"
  gerrit = "chromium-review.googlesource.com"

[bucket "chromium.buildbucket.swarming"]
  builder = infra_presubmit
  builder = infra_linux64
  builder = infra_mac
  builder = infra_win
[bucket "tryserver.infra"]
  builder = Infra Presubmit
  builder = Infra Linux Trusty 64 Tester
  builder = Infra Linux Precise 32 Tester
  builder = Infra Mac Tester
  builder = Infra Win Tester

In the vast majority of cases, the host.git and host.gerrit values are global to the entire host, so that stanza is specified in the All-Projects repo. Buckets and builders, on the other hand, are almost always very repository-specific, and so are only specified in “leaf” repositories which are not in any other repo's inheritance chain.

All changes to buildbucket.config files are instantly reflected. There is no caching period or need to restart the server.

Development

To use with the local testsite

Use the script run-with-testsite.sh; this rebuilds the plugin with bazel, copies it over and restarts the local testsite. Example invocation:

GERRIT_DIR=~/gerrit GERRIT_TESTSITE_DIR=~/testsite ./run-with-testsite.sh

To use with the polygerrit-ui server against live data

Use the script run-with-prod-data.sh; this creates a temporary directory with the plugin source in the expected layout and then invokes polygerrit-ui/run-server.sh. Example invocation:

GERRIT_DIR=~/gerrit ./run-with-prod-data.sh

Testing

# Install dependencies.
npm install -g bower
npm install -g web-component-tester
cd test/
bower install

# Run the tests from the directory root.
cd ../
wct

Note: Testing is disabled for Safari due to this issue.