Skip to content

Add 'View on [env]' link to blobs and individual files in diffs

Douwe Maan requested to merge route-map into master

What

This MR adds 'View on [env URL]' buttons to blobs and individual files in MR/commit/compare diffs, that will open the page represented by the file in question in the environment the commit/branch was last deployed to.

For files on master, this will usually open the file on staging or production; for files in an MR, this will open the file in the review app, if configured.

Changed file in diff of MR with review app

Will open https://around-the-world-in-6-releases.about.gitlab.com/images/blogimages/around-the-world-in-6-releases-cover.png

Screen_Shot_2017-01-29_at_13.34.56

Blob on MR branch with review app

Will open https://around-the-world-in-6-releases.about.gitlab.com/2017/01/30/around-the-world-in-6-releases/

Screen_Shot_2017-01-29_at_13.35.29

Blob on master

Will open https://about.gitlab.com/index.html

Screen_Shot_2017-01-29_at_13.38.43

How

In order to map these source file paths to public paths on the deployed website, this MR introduces the concept of a Route Map, located in a repo at .gitlab/route-map.yml.

The route map for a Middleman static website like https://gitlab.com/gitlab-com/www-gitlab-com looks like this:

# Blogposts
- source: /source/posts/([0-9]{4})-([0-9]{2})-([0-9]{2})-(.+?)\..*/ # source/posts/2017-01-30-around-the-world-in-6-releases.html.md.erb
  public: '\1/\2/\3/\4/' # 2017/01/30/around-the-world-in-6-releases/

# HTML files
- source: /source/(.+?\.html).*/ # source/index.html.haml
  public: '\1' # index.html

# Other files
- source: /source/(.*)/ # source/images/blogimages/around-the-world-in-6-releases-cover.png
  public: '\1' # images/blogimages/around-the-world-in-6-releases-cover.png

Why

This feature is especially useful with static sites that have review apps configured, like https://gitlab.com/gitlab-com/www-gitlab-com, where source paths map consistently to public paths, and this feature saves an MR reviewer time in locating the changed page in the review app.

Once GitLab Pages is refactored to use our environment/deployment model, we can provide sample .gitlab/route-map.yml files in the Pages sample repos at https://gitlab.com/groups/pages, so that people using these get the View on [env] functionality out of the box for their static sides.

To do

  • Resolve TODO's
  • Write tests
    • Write unit tests
    • Write feature specs
  • Write documentation

/cc @ayufan @markpundsack @zj @dimitrieh

Merge request reports