Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
0aa1f53d
Commit
0aa1f53d
authored
May 07, 2018
by
Marc
Committed by
Douwe Maan
May 07, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add signature verification badge to compare view
parent
d840535c
Changes
9
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
296 additions
and
101 deletions
+296
-101
app/assets/javascripts/gpg_badges.js
app/assets/javascripts/gpg_badges.js
+3
-3
app/assets/javascripts/pages/projects/compare/show/index.js
app/assets/javascripts/pages/projects/compare/show/index.js
+2
-0
app/controllers/projects/compare_controller.rb
app/controllers/projects/compare_controller.rb
+49
-16
app/views/projects/commits/show.html.haml
app/views/projects/commits/show.html.haml
+1
-1
app/views/projects/compare/_form.html.haml
app/views/projects/compare/_form.html.haml
+1
-1
changelogs/unreleased/44879.yml
changelogs/unreleased/44879.yml
+5
-0
config/routes/repository.rb
config/routes/repository.rb
+1
-0
spec/controllers/projects/compare_controller_spec.rb
spec/controllers/projects/compare_controller_spec.rb
+232
-78
spec/javascripts/gpg_badges_spec.js
spec/javascripts/gpg_badges_spec.js
+2
-2
No files found.
app/assets/javascripts/gpg_badges.js
View file @
0aa1f53d
...
...
@@ -7,12 +7,12 @@ import { __ } from '~/locale';
export
default
class
GpgBadges
{
static
fetch
()
{
const
badges
=
$
(
'
.js-loading-gpg-badge
'
);
const
form
=
$
(
'
.commits-search-form
'
);
const
tag
=
$
(
'
.js-signature-container
'
);
badges
.
html
(
'
<i class="fa fa-spinner fa-spin"></i>
'
);
const
params
=
parseQueryStringIntoObject
(
form
.
serialize
());
return
axios
.
get
(
form
.
data
(
'
signaturesPath
'
),
{
params
})
const
params
=
parseQueryStringIntoObject
(
tag
.
serialize
());
return
axios
.
get
(
tag
.
data
(
'
signaturesPath
'
),
{
params
})
.
then
(({
data
})
=>
{
data
.
signatures
.
forEach
((
signature
)
=>
{
badges
.
filter
(
`[data-commit-sha="
${
signature
.
commit_sha
}
"]`
).
replaceWith
(
signature
.
html
);
...
...
app/assets/javascripts/pages/projects/compare/show/index.js
View file @
0aa1f53d
import
Diff
from
'
~/diff
'
;
import
initChangesDropdown
from
'
~/init_changes_dropdown
'
;
import
GpgBadges
from
'
~/gpg_badges
'
;
document
.
addEventListener
(
'
DOMContentLoaded
'
,
()
=>
{
new
Diff
();
// eslint-disable-line no-new
const
paddingTop
=
16
;
initChangesDropdown
(
document
.
querySelector
(
'
.navbar-gitlab
'
).
offsetHeight
-
paddingTop
);
GpgBadges
.
fetch
();
});
app/controllers/projects/compare_controller.rb
View file @
0aa1f53d
...
...
@@ -8,8 +8,11 @@ class Projects::CompareController < Projects::ApplicationController
# Authorize
before_action
:require_non_empty_project
before_action
:authorize_download_code!
before_action
:define_ref_vars
,
only:
[
:index
,
:show
,
:diff_for_path
]
before_action
:define_diff_vars
,
only:
[
:show
,
:diff_for_path
]
# Defining ivars
before_action
:define_diffs
,
only:
[
:show
,
:diff_for_path
]
before_action
:define_environment
,
only:
[
:show
]
before_action
:define_diff_notes_disabled
,
only:
[
:show
,
:diff_for_path
]
before_action
:define_commits
,
only:
[
:show
,
:diff_for_path
,
:signatures
]
before_action
:merge_request
,
only:
[
:index
,
:show
]
def
index
...
...
@@ -22,9 +25,9 @@ class Projects::CompareController < Projects::ApplicationController
end
def
diff_for_path
return
render_404
unless
@
compare
return
render_404
unless
compare
render_diff_for_path
(
@
compare
.
diffs
(
diff_options
))
render_diff_for_path
(
compare
.
diffs
(
diff_options
))
end
def
create
...
...
@@ -41,30 +44,60 @@ class Projects::CompareController < Projects::ApplicationController
end
end
def
signatures
respond_to
do
|
format
|
format
.
json
do
render
json:
{
signatures:
@commits
.
select
(
&
:has_signature?
).
map
do
|
commit
|
{
commit_sha:
commit
.
sha
,
html:
view_to_html_string
(
'projects/commit/_signature'
,
signature:
commit
.
signature
)
}
end
}
end
end
end
private
def
define_ref_vars
@start_ref
=
Addressable
::
URI
.
unescape
(
params
[
:from
])
def
compare
return
@compare
if
defined?
(
@compare
)
@compare
=
CompareService
.
new
(
@project
,
head_ref
).
execute
(
@project
,
start_ref
)
end
def
start_ref
@start_ref
||=
Addressable
::
URI
.
unescape
(
params
[
:from
])
end
def
head_ref
return
@ref
if
defined?
(
@ref
)
@ref
=
@head_ref
=
Addressable
::
URI
.
unescape
(
params
[
:to
])
end
def
define_
diff_var
s
@com
pare
=
CompareService
.
new
(
@project
,
@head_ref
)
.
execute
(
@project
,
@start_ref
)
def
define_
commit
s
@com
mits
=
compare
.
present?
?
prepare_commits_for_rendering
(
compare
.
commits
)
:
[]
end
if
@compare
@commits
=
prepare_commits_for_rendering
(
@compare
.
commits
)
@diffs
=
@compare
.
diffs
(
diff_options
)
def
define_diffs
@diffs
=
compare
.
present?
?
compare
.
diffs
(
diff_options
)
:
[]
end
environment_params
=
@repository
.
branch_exists?
(
@head_ref
)
?
{
ref:
@head_ref
}
:
{
commit:
@compare
.
commit
}
def
define_environment
if
compare
environment_params
=
@repository
.
branch_exists?
(
head_ref
)
?
{
ref:
head_ref
}
:
{
commit:
compare
.
commit
}
@environment
=
EnvironmentsFinder
.
new
(
@project
,
current_user
,
environment_params
).
execute
.
last
@diff_notes_disabled
=
true
end
end
def
define_diff_notes_disabled
@diff_notes_disabled
=
compare
.
present?
end
def
merge_request
@merge_request
||=
MergeRequestsFinder
.
new
(
current_user
,
project_id:
@project
.
id
).
execute
.
opened
.
find_by
(
source_project:
@project
,
source_branch:
@head_ref
,
target_branch:
@
start_ref
)
.
find_by
(
source_project:
@project
,
source_branch:
head_ref
,
target_branch:
start_ref
)
end
end
app/views/projects/commits/show.html.haml
View file @
0aa1f53d
...
...
@@ -24,7 +24,7 @@
=
link_to
_
(
"Create merge request"
),
create_mr_path
(
@repository
.
root_ref
,
@ref
),
class:
'btn btn-success'
.control
=
form_tag
(
project_commits_path
(
@project
,
@id
),
method: :get
,
class:
'commits-search-form'
,
data:
{
'signatures-path'
=>
namespace_project_signatures_path
})
do
=
form_tag
(
project_commits_path
(
@project
,
@id
),
method: :get
,
class:
'commits-search-form
js-signature-container
'
,
data:
{
'signatures-path'
=>
namespace_project_signatures_path
})
do
=
search_field_tag
:search
,
params
[
:search
],
{
placeholder:
_
(
'Filter by commit message'
),
id:
'commits-search'
,
class:
'form-control search-text-input input-short'
,
spellcheck:
false
}
.control
=
link_to
project_commits_path
(
@project
,
@ref
,
rss_url_options
),
title:
_
(
"Commits feed"
),
class:
'btn'
do
...
...
app/views/projects/compare/_form.html.haml
View file @
0aa1f53d
=
form_tag
project_compare_index_path
(
@project
),
method: :post
,
class:
'form-inline js-requires-input
'
do
=
form_tag
project_compare_index_path
(
@project
),
method: :post
,
class:
'form-inline js-requires-input
js-signature-container'
,
data:
{
'signatures-path'
=>
signatures_namespace_project_compare_index_path
}
do
.clearfix
-
if
params
[
:to
]
&&
params
[
:from
]
.compare-switch-container
...
...
changelogs/unreleased/44879.yml
0 → 100644
View file @
0aa1f53d
---
title
:
Add the signature verfication badge to the compare view
merge_request
:
18245
author
:
Marc Shaw
type
:
added
config/routes/repository.rb
View file @
0aa1f53d
...
...
@@ -18,6 +18,7 @@ scope format: false do
resources
:compare
,
only:
[
:index
,
:create
]
do
collection
do
get
:diff_for_path
get
:signatures
end
end
...
...
spec/controllers/projects/compare_controller_spec.rb
View file @
0aa1f53d
This diff is collapsed.
Click to expand it.
spec/javascripts/gpg_badges_spec.js
View file @
0aa1f53d
...
...
@@ -17,7 +17,7 @@ describe('GpgBadges', () => {
mock
=
new
MockAdapter
(
axios
);
setFixtures
(
`
<form
class="commits-search-form" data-signatures-path="/hello" action="/hello"
class="commits-search-form
js-signature-container
" data-signatures-path="/hello" action="/hello"
method="get">
<input name="utf8" type="hidden" value="✓">
<input type="search" name="search" id="commits-search"class="form-control search-text-input input-short">
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment