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
Boxiang Sun
gitlab-ce
Commits
e63b693f
Commit
e63b693f
authored
Jul 10, 2017
by
Alexis Reigel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
generate gpg signature on push
parent
4c5d4a69
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
108 additions
and
0 deletions
+108
-0
app/services/git_push_service.rb
app/services/git_push_service.rb
+8
-0
app/workers/create_gpg_signature_worker.rb
app/workers/create_gpg_signature_worker.rb
+20
-0
config/sidekiq_queues.yml
config/sidekiq_queues.yml
+1
-0
spec/services/git_push_service_spec.rb
spec/services/git_push_service_spec.rb
+18
-0
spec/workers/create_gpg_signature_worker_spec.rb
spec/workers/create_gpg_signature_worker_spec.rb
+61
-0
No files found.
app/services/git_push_service.rb
View file @
e63b693f
...
...
@@ -56,6 +56,8 @@ class GitPushService < BaseService
perform_housekeeping
update_caches
update_signatures
end
def
update_gitattributes
...
...
@@ -80,6 +82,12 @@ class GitPushService < BaseService
ProjectCacheWorker
.
perform_async
(
@project
.
id
,
types
,
[
:commit_count
,
:repository_size
])
end
def
update_signatures
@push_commits
.
each
do
|
commit
|
CreateGpgSignatureWorker
.
perform_async
(
commit
.
sha
,
@project
.
id
)
end
end
# Schedules processing of commit messages.
def
process_commit_messages
default
=
is_default_branch?
...
...
app/workers/create_gpg_signature_worker.rb
0 → 100644
View file @
e63b693f
class
CreateGpgSignatureWorker
include
Sidekiq
::
Worker
include
DedicatedSidekiqQueue
def
perform
(
commit_sha
,
project_id
)
project
=
Project
.
find_by
(
id:
project_id
)
unless
project
return
Rails
.
logger
.
error
(
"CreateGpgSignatureWorker: couldn't find project with ID=
#{
project_id
}
, skipping job"
)
end
commit
=
project
.
commit
(
commit_sha
)
unless
commit
return
Rails
.
logger
.
error
(
"CreateGpgSignatureWorker: couldn't find commit with commit_sha=
#{
commit_sha
}
, skipping job"
)
end
commit
.
signature
end
end
config/sidekiq_queues.yml
View file @
e63b693f
...
...
@@ -30,6 +30,7 @@
- [emails_on_push, 2]
- [mailers, 2]
- [invalid_gpg_signature_update, 2]
- [create_gpg_signature, 2]
- [upload_checksum, 1]
- [use_key, 1]
- [repository_fork, 1]
...
...
spec/services/git_push_service_spec.rb
View file @
e63b693f
...
...
@@ -681,6 +681,24 @@ describe GitPushService, services: true do
end
end
describe
'#update_signatures'
do
let
(
:service
)
do
described_class
.
new
(
project
,
user
,
oldrev:
sample_commit
.
parent_id
,
newrev:
sample_commit
.
id
,
ref:
'refs/heads/master'
)
end
it
'calls CreateGpgSignatureWorker.perform_async for each commit'
do
expect
(
CreateGpgSignatureWorker
).
to
receive
(
:perform_async
).
with
(
sample_commit
.
id
,
project
.
id
)
execute_service
(
project
,
user
,
@oldrev
,
@newrev
,
@ref
)
end
end
def
execute_service
(
project
,
user
,
oldrev
,
newrev
,
ref
)
service
=
described_class
.
new
(
project
,
user
,
oldrev:
oldrev
,
newrev:
newrev
,
ref:
ref
)
service
.
execute
...
...
spec/workers/create_gpg_signature_worker_spec.rb
0 → 100644
View file @
e63b693f
require
'spec_helper'
describe
CreateGpgSignatureWorker
do
context
'when GpgKey is found'
do
it
'calls Commit#signature'
do
commit_sha
=
'0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33'
project
=
create
:project
commit
=
instance_double
(
Commit
)
allow
(
Project
).
to
receive
(
:find_by
).
with
(
id:
project
.
id
).
and_return
(
project
)
allow
(
project
).
to
receive
(
:commit
).
with
(
commit_sha
).
and_return
(
commit
)
expect
(
commit
).
to
receive
(
:signature
)
described_class
.
new
.
perform
(
commit_sha
,
project
.
id
)
end
end
context
'when Commit is not found'
do
let
(
:nonexisting_commit_sha
)
{
'bogus'
}
let
(
:project
)
{
create
:project
}
it
'logs CreateGpgSignatureWorker process skipping'
do
expect
(
Rails
.
logger
).
to
receive
(
:error
)
.
with
(
"CreateGpgSignatureWorker: couldn't find commit with commit_sha=bogus, skipping job"
)
described_class
.
new
.
perform
(
nonexisting_commit_sha
,
project
.
id
)
end
it
'does not raise errors'
do
expect
{
described_class
.
new
.
perform
(
nonexisting_commit_sha
,
project
.
id
)
}.
not_to
raise_error
end
it
'does not call Commit#signature'
do
expect_any_instance_of
(
Commit
).
not_to
receive
(
:signature
)
described_class
.
new
.
perform
(
nonexisting_commit_sha
,
project
.
id
)
end
end
context
'when Project is not found'
do
let
(
:nonexisting_project_id
)
{
-
1
}
it
'logs CreateGpgSignatureWorker process skipping'
do
expect
(
Rails
.
logger
).
to
receive
(
:error
)
.
with
(
"CreateGpgSignatureWorker: couldn't find project with ID=-1, skipping job"
)
described_class
.
new
.
perform
(
anything
,
nonexisting_project_id
)
end
it
'does not raise errors'
do
expect
{
described_class
.
new
.
perform
(
anything
,
nonexisting_project_id
)
}.
not_to
raise_error
end
it
'does not call Commit#signature'
do
expect_any_instance_of
(
Commit
).
not_to
receive
(
:signature
)
described_class
.
new
.
perform
(
anything
,
nonexisting_project_id
)
end
end
end
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