Files
gerrit/polygerrit-ui
David Pursehouse 923318b446 Merge branch 'stable-3.0'
* stable-3.0:
  Update git submodules
  Update git submodules
  Update git submodules
  Fix documentation of UI selection
  Set version to 2.16.12-SNAPSHOT
  Set version to 2.16.11
  Update git submodules
  Revert "GerritServer: Silence non-critical logs from JGit's FileSnapshot"
  Revert "GerritServer: Silence non-critical logs from JGit's FS"
  Revert "Upgrade JGit to 5.1.10.201908230655-r"
  Revert "Stop using deprecated DirCacheEntry#setLastModified(long)"
  Update git submodules
  Update git submodules
  Update git submodules
  Update git submodules
  Update git submodules
  Update git submodules
  Set version to 2.15.17-SNAPSHOT
  Update git submodules
  Update git submodules
  Revert "Upgrade JGit to 5.3.4.201908231101-r"
  Set version to 2.15.16
  Revert "CreateAccount: Fail early when invalid SSH key is given"
  Update git submodules
  tools/eclipse/project.py: Fix typo of bazelisk
  Set XSRF on '/' under PolyGerrit
  Migrate from old-style legacy .java provider to the new JavaInfo.
  Remove deleted rules for the new added section
  Support bazelisk or bazel in tools/eclipse/project.py
  Rework imports in project.py
  Update project.py to use argparse
  AccountIT: Test that account is not created with invalid email
  CreateAccount: Fail early when invalid SSH key is given
  Update git submodules
  GerritServer: Silence non-critical logs from JGit's FS
  GerritServer: Silence non-critical logs from JGit's FileSnapshot
  Stop using deprecated DirCacheEntry#setLastModified(long)
  ProjectState: Fix 'invalid type qualification' javadoc warning
  Upgrade JGit to 5.3.4.201908231101-r
  Documentation: refresh IntelliJ IDEA developer documentation
  Documentation: update external links to Bazel
  Use base url for commentlink
  Update git submodules
  Update git submodules
  Don't store LabelTypes in ProjectState
  Upgrade highlight.js to latest master revision
  Update git submodules
  Update git submodules
  Update git submodules
  StarredChangesUtil: Stop using deprecated RefDatabase.getRef
  Suppress warnings about deprecated BaseReceivePack
  DeleteRef: Stop using deprecated RefDatabase.getRef
  Upgrade elasticsearch-rest-client to 7.3.1
  Add .gitreview file
  Remove vestigal GWT plugin loading hooks
  Upgrade JGit to 5.1.10.201908230655-r
  DeleteDraftComments: Don't update change modified timestamp
  ChangeIT: set submittableAfterLosingPermissions private
  Rebase: Don't swallow caught exception
  Output NoteDb migration progress to Flogger
  Update git submodules
  Remove AccountPatchReview data when change gets auto-abandoned
  DefaultChangeReportFormatter: Make constructor and urlFormatter visible
  StarredChangesUtil: Fix NPE when ref to be deleted doesn't exist
  StarredChangesUtil: Throw LockFailureException on LOCK_FAILURE
  Add test for creating a change on a non-existing base change
  Rebase: Do not fail with 500 ISE if non-existing change is given as base
  Fix detecting changes of parent trees when computing change kind for merge commit
  Remove duplicate descriptions of fields in Requirement JSON entity
  Allow to set content type in the plugin REST API interface
  InternalAccountQuery: Add back the oneByExternalId method
  Set version to 2.16.11-SNAPSHOT
  Revert "Migrate from old-style legacy .java provider to the new JavaInfo."
  Catch all exceptions for reporting on Schema_130 migration
  Update git submodules
  Migrate from old-style legacy .java provider to the new JavaInfo.
  Update git submodules
  Update git submodules
  AuthRequest: Fix Javadoc for return values
  ChangeApi: Add methods to get change comments/drafts as list
  Update git submodules
  ListChangeComments: Extend ListChangeDrafts
  Upgrade Go Bazel rules to the latest version
  detach -> detached
  Fix anchor tag for settings page
  Add support for Elasticsearch version 7.3.*
  PrologEnvironment: Reduce "setting reductionLimit" log spam
  ElasticContainer: Upgrade to 6.8.2 image for V6_8 tests
  Fix typo: program
  Fix email token routing
  Clarify usage of 'parent' option in list files API
  Remove unused Skylark patch file
  Files: Use Gerrit API to get revision parents
  Fix broken link for rest-api-projects.html#commentlink-info
  Add support for Elasticsearch version 6.8.x
  Upgrade elasticsearch-rest-client to 7.2.1
  Add support for "Link Another Identity" in gr-identities
  Update git submodules
  CommitApi: Add method to get commit info
  Consolidate all CommitApi tests into a single class
  Files: Validate parent option to prevent internal server error
  RevisionIT: Assert that files(base) only works for patch set revisions
  Fix and expand documentation of REST API to get revision files
  RevisionIT#files: Simplify assertion
  Update git submodules
  Update git submodules
  Update git submodules
  Update git submodules
  Remove default bug tracker from _feedbackUrl
  PG: Add shortcuts for dashboard and watched changes
  PG: Allow empty label values
  Remove token param from getCapabilities
  Add an extension point to show a small banner next to the search bar
  Fix gr-group-audit-log to use tbody

Change-Id: Iaf877b737f115d4fe95af74f8284eec19112a21d
2019-08-30 20:55:37 +09:00
..
2019-08-30 20:55:37 +09:00
2019-03-21 16:13:02 +01:00

Gerrit Polymer Frontend

Follow the setup instructions for Gerrit backend developers where applicable.

Installing Bazel

Follow the instructions here to get and install Bazel.

Installing Node.js and npm packages

The minimum nodejs version supported is 8.x+

# Debian experimental
sudo apt-get install nodejs-legacy
sudo apt-get install npm

# OS X with Homebrew
brew install node
brew install npm

All other platforms: download from nodejs.org.

Various steps below require installing additional npm packages. The full list of dependencies can be installed with:

npm install

It may complain about a missing typescript@2.3.4 peer dependency, which is harmless.

Running locally against production data

Go server

To test the local Polymer frontend against gerrit-review.googlesource.com simply execute:

./polygerrit-ui/run-server.sh

Then visit http://localhost:8081.

This method is based on a simple hand-written Go webserver. Mostly it just switches between serving files locally and proxying the real server based on the file name. It also does some basic response rewriting, e.g. it patches the config/server/info response with plugin information provided on the command line:

./polygerrit-ui/run-server.sh --plugins=plugins/my_plugin/static/my_plugin.js,plugins/my_plugin/static/my_plugin.html

The biggest draw back of this method is that you cannot log in, so cannot test scenarios that require it.

MITM Proxy

MITM Proxy is an open source product for proxying https servers. The contrib/mitm-ui/ directory contains scripts (and documentation) for using this technology (instead of the Go server). These scripts are somewhat experimental and unmaintained though.

Running locally against a Gerrit test site

Set up a local test site once:

  1. Build Gerrit
  2. Set up a local test site.
  3. Optionally populate your test site with some test data.

For running a locally built Gerrit war against your test instance use this command, and add the --polygerrit-dev option, if you want to serve the Polymer frontend directly from the sources in polygerrit_ui/app/ instead of from the war:

$(bazel info output_base)/external/local_jdk/bin/java \
    -DsourceRoot=$(bazel info workspace) \
    -jar bazel-bin/gerrit.war daemon \
    -d $GERRIT_SITE \
    --console-log \
    --polygerrit-dev

Running Tests

This step requires the web-component-tester npm module.

Note: it may be necessary to add the options --unsafe-perm=true --allow-root to the npm install command to avoid file permission errors.

For daily development you typically only want to run and debug individual tests. Run the local Go proxy server and navigate for example to http://localhost:8081/elements/change/gr-account-entry/gr-account-entry_test.html. Check "Disable cache" in the "Network" tab of Chrome's dev tools, so code changes are picked up on "reload".

Our CI integration ensures that all tests are run when you upload a change to Gerrit, but you can also run all tests locally in headless mode:

npm test

To allow the tests to run in Safari:

  • In the Advanced preferences tab, check "Show Develop menu in menu bar".
  • In the Develop menu, enable the "Allow Remote Automation" option.

To run Chrome tests in headless mode:

WCT_HEADLESS_MODE=1 WCT_ARGS='--verbose -l chrome' ./polygerrit-ui/app/run_test.sh

Style guide

We follow the Google JavaScript Style Guide with a few exceptions. When in doubt, remain consistent with the code around you.

In addition, we encourage the use of ESLint. It is available as a command line utility, as well as a plugin for most editors and IDEs.

eslint-config-google is a port of the Google JS Style Guide to an ESLint config module, and eslint-plugin-html allows ESLint to lint scripts inside HTML. We have an .eslintrc.json config file in the polygerrit-ui/ directory configured to enforce the preferred style of the PolyGerrit project. After installing, you can use eslint on any new file you create. In addition, you can supply the --fix flag to apply some suggested fixes for simple style issues. If you modify JS inside of <script> tags, like for test suites, you may have to supply the --ext .html flag.

Some useful commands:

  • To run ESLint on the whole app, less some dependency code:
npm run eslint
  • To run ESLint on just the subdirectory you modified:
node_modules/eslint/bin/eslint.js --ext .html,.js polygerrit-ui/app/$YOUR_DIR_HERE
  • To run the linter on all of your local changes:
git diff --name-only master | xargs node_modules/eslint/bin/eslint.js --ext .html,.js

We also use the polylint tool to lint use of Polymer. To install polylint, execute the following command.

To run polylint, execute the following command.

bazel test //polygerrit-ui/app:polylint_test

or

npm run polylint

Template Type Safety

Polymer elements are not type checked against the element definition, making it trivial to break the display when refactoring or moving code. We now run additional tests to help ensure that template types are checked.

A few notes to ensure that these tests pass

  • Any functions with optional parameters will need closure annotations.
  • Any Polymer parameters that are nullable or can be multiple types (other than the one explicitly delared) will need type annotations.

These tests require the typescript and fried-twinkie npm packages.

To run on all files, execute the following command:

./polygerrit-ui/app/run_template_test.sh

or

npm run test-template

To run on a specific top level directory (ex: change-list)

TEMPLATE_NO_DEFAULT=true ./polygerrit-ui/app/run_template_test.sh //polygerrit-ui/app:template_test_change-list

To run on a specific file (ex: gr-change-list-view), execute the following command:

TEMPLATE_NO_DEFAULT=true ./polygerrit-ui/app/run_template_test.sh //polygerrit-ui/app:template_test_<TOP_LEVEL_DIRECTORY> --test_arg=<VIEW_NAME>
TEMPLATE_NO_DEFAULT=true ./polygerrit-ui/app/run_template_test.sh //polygerrit-ui/app:template_test_change-list --test_arg=gr-change-list-view