Commit bb00e42d authored by Nikola Milojevic's avatar Nikola Milojevic

Merge branch '341825-integrate-rb-ipynbdiff-into-gitlab' into 'master'

Resolve "Integrate rb-ipynbdiff into Gitlab"

See merge request gitlab-org/gitlab!71477
parents 8d8e1619 46a0f612
......@@ -537,3 +537,5 @@ gem 'webauthn', '~> 2.3'
gem 'ipaddress', '~> 0.8.3'
gem 'parslet', '~> 1.8'
gem 'ipynbdiff', '0.3.6'
......@@ -640,6 +640,9 @@ GEM
invisible_captcha (1.1.0)
rails (>= 4.2)
ipaddress (0.8.3)
ipynbdiff (0.3.6)
diffy (= 3.3.0)
json (= 2.5.1)
jaeger-client (1.1.0)
opentracing (~> 0.3)
thrift
......@@ -1501,6 +1504,7 @@ DEPENDENCIES
icalendar
invisible_captcha (~> 1.1.0)
ipaddress (~> 0.8.3)
ipynbdiff (= 0.3.6)
jira-ruby (~> 2.1.4)
js_regex (~> 3.7)
json (~> 2.5.1)
......
# frozen_string_literal: true
require 'ipynbdiff'
class BlobPresenter < Gitlab::View::Presenter::Delegated
include ApplicationHelper
......@@ -20,6 +21,17 @@ class BlobPresenter < Gitlab::View::Presenter::Delegated
)
end
def highlight_transformed(plain: nil)
load_all_blob_data
Gitlab::Highlight.highlight(
blob.path,
transformed_blob_data,
language: language,
plain: plain
)
end
def plain_data
return if blob.binary?
......@@ -107,4 +119,8 @@ class BlobPresenter < Gitlab::View::Presenter::Delegated
def language
blob.language_from_gitattributes
end
def transformed_blob_data
@transformed_blob ||= ( blob.path.ends_with?('.ipynb') && IpynbDiff.transform(blob.data, options: { include_metadata: false, cell_decorator: :percent }) ) || blob.data
end
end
---
name: jupyter_clean_diffs
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/71477
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/343433
milestone: '14.5'
type: development
group: group::incubation
default_enabled: false
......@@ -20,6 +20,15 @@ rendered to HTML when viewed:
Interactive features, including JavaScript plots, don't work when viewed in
GitLab.
## Cleaner diffs
> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/epics/6589) in GitLab 14.5
When commits include changes to Jupyter Notebook files, GitLab strips out the
noise and displays a cleaner version of the diff.
![Jupyter Notebook Clean Diff](img/jupyter_notebook_diff.png)
## Jupyter Git integration
Jupyter can be configured as an OAuth application with repository access, acting
......
......@@ -43,6 +43,8 @@ module Gitlab
# Ensure items are collected in the the batch
new_blob_lazy
old_blob_lazy
preprocess_before_diff(diff) if Feature.enabled?(:jupyter_clean_diffs, @project)
end
def position(position_marker, position_type: :text)
......@@ -448,6 +450,19 @@ module Gitlab
find_renderable_viewer_class(classes)
end
def preprocess_before_diff(diff)
return unless diff.new_path.ends_with? '.ipynb'
from = old_blob_lazy&.data
to = new_blob_lazy&.data
new_diff = IpynbDiff.diff(from, to,
diff_opts: { context: 5, include_diff_info: true },
transform_options: { cell_decorator: :percent } )
diff.diff = new_diff.scan(/.*\n/)[2..-1].join('') if new_diff
end
def alternate_viewer_class
return unless viewer.instance_of?(DiffViewer::Renamed)
......
......@@ -152,6 +152,9 @@ module Gitlab
return [] unless blob
blob.load_all_data!
return blob.present.highlight_transformed.lines if Feature.enabled?(:jupyter_clean_diffs, @project)
blob.present.highlight.lines
end
......
......@@ -53,7 +53,7 @@ module TestEnv
'wip' => 'b9238ee',
'csv' => '3dd0896',
'v1.1.0' => 'b83d6e3',
'add-ipython-files' => 'f6b7a70',
'add-ipython-files' => 'c10c411',
'add-pdf-file' => 'e774ebd',
'squash-large-files' => '54cec52',
'add-pdf-text-binary' => '79faa7b',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment