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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
eda00156
Commit
eda00156
authored
Jul 25, 2017
by
Alexis Reigel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fetch gpg signature badges by ajax
parent
c4c44c6a
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
75 additions
and
16 deletions
+75
-16
app/assets/javascripts/dispatcher.js
app/assets/javascripts/dispatcher.js
+4
-0
app/assets/javascripts/gpg_badges.js
app/assets/javascripts/gpg_badges.js
+15
-0
app/controllers/projects/commits_controller.rb
app/controllers/projects/commits_controller.rb
+30
-10
app/helpers/commits_helper.rb
app/helpers/commits_helper.rb
+4
-0
app/models/commit.rb
app/models/commit.rb
+7
-1
app/views/projects/commit/_ajax_signature.html.haml
app/views/projects/commit/_ajax_signature.html.haml
+3
-0
app/views/projects/commit/_signature_badge.html.haml
app/views/projects/commit/_signature_badge.html.haml
+1
-1
app/views/projects/commits/_commit.html.haml
app/views/projects/commits/_commit.html.haml
+6
-1
app/views/projects/commits/show.html.haml
app/views/projects/commits/show.html.haml
+1
-1
config/routes/repository.rb
config/routes/repository.rb
+2
-0
spec/features/commits_spec.rb
spec/features/commits_spec.rb
+2
-2
No files found.
app/assets/javascripts/dispatcher.js
View file @
eda00156
...
...
@@ -64,6 +64,7 @@ import initSettingsPanels from './settings_panels';
import
initExperimentalFlags
from
'
./experimental_flags
'
;
import
OAuthRememberMe
from
'
./oauth_remember_me
'
;
import
PerformanceBar
from
'
./performance_bar
'
;
import
GpgBadges
from
'
./gpg_badges
'
;
(
function
()
{
var
Dispatcher
;
...
...
@@ -300,6 +301,9 @@ import PerformanceBar from './performance_bar';
}).
bindEvents
();
break
;
case
'
projects:commits:show
'
:
shortcut_handler
=
new
ShortcutsNavigation
();
GpgBadges
.
fetch
();
break
;
case
'
projects:activity
'
:
shortcut_handler
=
new
ShortcutsNavigation
();
break
;
...
...
app/assets/javascripts/gpg_badges.js
0 → 100644
View file @
eda00156
export
default
class
GpgBadges
{
static
fetch
()
{
const
form
=
$
(
'
.commits-search-form
'
);
$
.
get
({
url
:
form
.
data
(
'
signatures-path
'
),
data
:
form
.
serialize
(),
}).
done
((
response
)
=>
{
const
badges
=
$
(
'
.js-loading-gpg-badge
'
);
response
.
signatures
.
forEach
((
signature
)
=>
{
badges
.
filter
(
`[data-commit-sha="
${
signature
.
commit_sha
}
"]`
).
replaceWith
(
signature
.
html
);
});
});
}
}
app/controllers/projects/commits_controller.rb
View file @
eda00156
...
...
@@ -6,18 +6,9 @@ class Projects::CommitsController < Projects::ApplicationController
before_action
:require_non_empty_project
before_action
:assign_ref_vars
before_action
:authorize_download_code!
before_action
:set_commits
def
show
@limit
,
@offset
=
(
params
[
:limit
]
||
40
).
to_i
,
(
params
[
:offset
]
||
0
).
to_i
search
=
params
[
:search
]
@commits
=
if
search
.
present?
@repository
.
find_commits_by_message
(
search
,
@ref
,
@path
,
@limit
,
@offset
)
else
@repository
.
commits
(
@ref
,
path:
@path
,
limit:
@limit
,
offset:
@offset
)
end
@note_counts
=
project
.
notes
.
where
(
commit_id:
@commits
.
map
(
&
:id
))
.
group
(
:commit_id
).
count
...
...
@@ -37,4 +28,33 @@ class Projects::CommitsController < Projects::ApplicationController
end
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
set_commits
@limit
,
@offset
=
(
params
[
:limit
]
||
40
).
to_i
,
(
params
[
:offset
]
||
0
).
to_i
search
=
params
[
:search
]
@commits
=
if
search
.
present?
@repository
.
find_commits_by_message
(
search
,
@ref
,
@path
,
@limit
,
@offset
)
else
@repository
.
commits
(
@ref
,
path:
@path
,
limit:
@limit
,
offset:
@offset
)
end
end
end
app/helpers/commits_helper.rb
View file @
eda00156
...
...
@@ -113,6 +113,10 @@ module CommitsHelper
commit_action_link
(
'cherry-pick'
,
commit
,
continue_to_path
,
btn_class:
btn_class
,
has_tooltip:
has_tooltip
)
end
def
commit_signature_badge_classes
(
additional_classes
)
%w(btn status-box gpg-status-box)
+
Array
(
additional_classes
)
end
protected
# Private: Returns a link to a person. If the person has a matching user and
...
...
app/models/commit.rb
View file @
eda00156
...
...
@@ -237,9 +237,11 @@ class Commit
def
signature
return
@signature
if
defined?
(
@signature
)
@signature
=
Gitlab
::
Gpg
::
Commit
.
new
(
self
)
.
signature
@signature
=
gpg_commit
.
signature
end
delegate
:has_signature?
,
to: :gpg_commit
def
revert_branch_name
"revert-
#{
short_id
}
"
end
...
...
@@ -388,4 +390,8 @@ class Commit
def
merged_merge_request_no_cache
(
user
)
MergeRequestsFinder
.
new
(
user
,
project_id:
project
.
id
).
find_by
(
merge_commit_sha:
id
)
if
merge_commit?
end
def
gpg_commit
@gpg_commit
||=
Gitlab
::
Gpg
::
Commit
.
new
(
self
)
end
end
app/views/projects/commit/_ajax_signature.html.haml
0 → 100644
View file @
eda00156
-
if
commit
.
has_signature?
%button
{
class:
commit_signature_badge_classes
(
'js-loading-gpg-badge'
),
data:
{
toggle:
'tooltip'
,
placement:
'auto top'
,
title:
'GPG signature (loading...)'
,
'commit-sha'
=>
commit
.
sha
}
}
%i
.fa.fa-spinner.fa-spin
app/views/projects/commit/_signature_badge.html.haml
View file @
eda00156
-
css_classes
=
%w(btn status-box gpg-status-box)
+
css_classes
-
css_classes
=
commit_signature_badge_classes
(
css_classes
)
-
title
=
capture
do
.gpg-popover-status
...
...
app/views/projects/commits/_commit.html.haml
View file @
eda00156
...
...
@@ -39,7 +39,12 @@
.commit-actions.hidden-xs
-
if
commit
.
status
(
ref
)
=
render_commit_status
(
commit
,
ref:
ref
)
=
render
partial:
'projects/commit/signature'
,
object:
commit
.
signature
-
if
request
.
xhr?
=
render
partial:
'projects/commit/signature'
,
object:
commit
.
signature
-
else
=
render
partial:
'projects/commit/ajax_signature'
,
locals:
{
commit:
commit
}
=
link_to
commit
.
short_id
,
project_commit_path
(
project
,
commit
),
class:
"commit-sha btn btn-transparent"
=
clipboard_button
(
text:
commit
.
id
,
title:
_
(
"Copy commit SHA to clipboard"
))
=
link_to_browse_code
(
project
,
commit
)
app/views/projects/commits/show.html.haml
View file @
eda00156
...
...
@@ -29,7 +29,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'
)
do
=
form_tag
(
project_commits_path
(
@project
,
@id
),
method: :get
,
class:
'commits-search-form'
,
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
...
...
config/routes/repository.rb
View file @
eda00156
...
...
@@ -76,6 +76,8 @@ scope format: false do
get
'/tree/*id'
,
to:
'tree#show'
,
as: :tree
get
'/raw/*id'
,
to:
'raw#show'
,
as: :raw
get
'/blame/*id'
,
to:
'blame#show'
,
as: :blame
get
'/commits/*id/signatures'
,
to:
'commits#signatures'
,
as: :signatures
get
'/commits/*id'
,
to:
'commits#show'
,
as: :commits
post
'/create_dir/*id'
,
to:
'tree#create_dir'
,
as: :create_dir
...
...
spec/features/commits_spec.rb
View file @
eda00156
...
...
@@ -204,7 +204,7 @@ describe 'Commits' do
end
end
describe
'GPG signed commits'
do
describe
'GPG signed commits'
,
:js
do
it
'changes from unverified to verified when the user changes his email to match the gpg key'
do
user
=
create
:user
,
email:
'unrelated.user@example.org'
project
.
team
<<
[
user
,
:master
]
...
...
@@ -262,7 +262,7 @@ describe 'Commits' do
end
end
it
'shows popover badges'
,
:js
do
it
'shows popover badges'
do
gpg_user
=
create
:user
,
email:
GpgHelpers
::
User1
.
emails
.
first
,
username:
'nannie.bernhard'
,
name:
'Nannie Bernhard'
Sidekiq
::
Testing
.
inline!
do
create
:gpg_key
,
key:
GpgHelpers
::
User1
.
public_key
,
user:
gpg_user
...
...
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