Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-shell
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
nexedi
gitlab-shell
Commits
1da7d54e
Commit
1da7d54e
authored
Feb 07, 2015
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Print broadcast message if one is available.
parent
6d23be22
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
152 additions
and
0 deletions
+152
-0
CHANGELOG
CHANGELOG
+3
-0
lib/gitlab_net.rb
lib/gitlab_net.rb
+9
-0
lib/gitlab_post_receive.rb
lib/gitlab_post_receive.rb
+41
-0
spec/gitlab_net_spec.rb
spec/gitlab_net_spec.rb
+20
-0
spec/gitlab_post_receive_spec.rb
spec/gitlab_post_receive_spec.rb
+3
-0
spec/vcr_cassettes/broadcast_message-none.yml
spec/vcr_cassettes/broadcast_message-none.yml
+38
-0
spec/vcr_cassettes/broadcast_message-ok.yml
spec/vcr_cassettes/broadcast_message-ok.yml
+38
-0
No files found.
CHANGELOG
View file @
1da7d54e
v2.4.3
- Print broadcast message if one is available
v2.4.2
- Pass git changes list as string instead of array
...
...
lib/gitlab_net.rb
View file @
1da7d54e
...
...
@@ -41,6 +41,15 @@ class GitlabNet
JSON
.
parse
(
resp
.
body
)
rescue
nil
end
def
broadcast_message
resp
=
get
(
"
#{
host
}
/broadcast_message"
)
if
resp
.
code
==
'200'
JSON
.
parse
(
resp
.
body
)
rescue
nil
else
nil
end
end
def
check
get
(
"
#{
host
}
/check"
)
end
...
...
lib/gitlab_post_receive.rb
View file @
1da7d54e
require_relative
'gitlab_init'
require_relative
'gitlab_net'
require
'json'
class
GitlabPostReceive
...
...
@@ -16,10 +17,50 @@ class GitlabPostReceive
ENV
[
'GL_ID'
]
=
nil
update_redis
if
broadcast_message
=
GitlabNet
.
new
.
broadcast_message
puts
print_broadcast_message
(
broadcast_message
[
"message"
])
end
end
protected
def
print_broadcast_message
(
message
)
# A standard terminal window is (at least) 80 characters wide.
total_width
=
80
# Git prefixes remote messages with "remote: ", so this width is subtracted
# from the width available to us.
total_width
-=
"remote: "
.
length
# Our centered text shouldn't start or end right at the edge of the window,
# so we add some horizontal padding: 2 chars on either side.
text_width
=
total_width
-
2
*
2
# Automatically wrap message at text_width (= 68) characters:
# Splits the message up into the longest possible chunks matching
# "<between 0 and text_width characters><space or end-of-line>".
# The last result is always an empty string (0 chars and the end-of-line),
# so drop that.
# message.scan returns a nested array of capture groups, so flatten.
lines
=
message
.
scan
(
/(.{,
#{
text_width
}
})(?:\s|$)/
)[
0
...-
1
].
flatten
puts
"="
*
total_width
puts
lines
.
each
do
|
line
|
line
.
strip!
# Center the line by calculating the left padding measured in characters.
line_padding
=
[(
total_width
-
line
.
length
)
/
2
,
0
].
max
puts
(
" "
*
line_padding
)
+
line
end
puts
puts
"="
*
total_width
end
def
update_redis
queue
=
"
#{
config
.
redis_namespace
}
:queue:post_receive"
msg
=
JSON
.
dump
({
'class'
=>
'PostReceive'
,
'args'
=>
[
@repo_path
,
@actor
,
@changes
]})
...
...
spec/gitlab_net_spec.rb
View file @
1da7d54e
...
...
@@ -44,6 +44,26 @@ describe GitlabNet, vcr: true do
end
end
describe
:broadcast_message
do
context
"broadcast message exists"
do
it
'should return message'
do
VCR
.
use_cassette
(
"broadcast_message-ok"
)
do
result
=
gitlab_net
.
broadcast_message
result
[
"message"
].
should
==
"Message"
end
end
end
context
"broadcast message doesn't exist"
do
it
'should return nil'
do
VCR
.
use_cassette
(
"broadcast_message-none"
)
do
result
=
gitlab_net
.
broadcast_message
result
.
should
==
nil
end
end
end
end
describe
:check_access
do
context
'ssh key with access to project'
do
it
'should allow pull access for dev.gitlab.org'
do
...
...
spec/gitlab_post_receive_spec.rb
View file @
1da7d54e
...
...
@@ -9,10 +9,13 @@ describe GitlabPostReceive do
before
do
GitlabConfig
.
any_instance
.
stub
(
repos_path:
repository_path
)
Kernel
.
stub
(
system:
true
)
GitlabNet
.
any_instance
.
stub
(
broadcast_message:
{
"message"
=>
"test "
*
10
+
"message "
*
10
})
end
describe
:initialize
do
it
{
gitlab_post_receive
.
repo_path
.
should
==
repo_path
}
it
{
gitlab_post_receive
.
changes
.
should
==
'wow'
}
it
{
gitlab_post_receive
.
exec
}
end
end
spec/vcr_cassettes/broadcast_message-none.yml
0 → 100644
View file @
1da7d54e
---
http_interactions
:
-
request
:
method
:
get
uri
:
https://dev.gitlab.org/api/v3/internal/broadcast_message
body
:
encoding
:
US-ASCII
string
:
secret_token=a123
headers
:
Accept-Encoding
:
-
gzip;q=1.0,deflate;q=0.6,identity;q=0.3
Accept
:
-
"
*/*"
User-Agent
:
-
Ruby
response
:
status
:
code
:
404
message
:
Not Found
headers
:
Server
:
-
nginx/1.1.19
Date
:
-
Sat, 07 Feb 2015 16:45:35 GMT
Content-Type
:
-
application/json
Content-Length
:
-
'
27'
Connection
:
-
keep-alive
Status
:
-
200 OK
body
:
encoding
:
UTF-8
string
:
'
{"message":"404
Not
Found"}'
http_version
:
recorded_at
:
Sat, 07 Feb 2015 16:45:35 GMT
recorded_with
:
VCR 2.4.0
spec/vcr_cassettes/broadcast_message-ok.yml
0 → 100644
View file @
1da7d54e
---
http_interactions
:
-
request
:
method
:
get
uri
:
https://dev.gitlab.org/api/v3/internal/broadcast_message
body
:
encoding
:
US-ASCII
string
:
secret_token=a123
headers
:
Accept-Encoding
:
-
gzip;q=1.0,deflate;q=0.6,identity;q=0.3
Accept
:
-
"
*/*"
User-Agent
:
-
Ruby
response
:
status
:
code
:
200
message
:
OK
headers
:
Server
:
-
nginx/1.1.19
Date
:
-
Sat, 07 Feb 2015 16:44:35 GMT
Content-Type
:
-
application/json
Content-Length
:
-
'
118'
Connection
:
-
keep-alive
Status
:
-
200 OK
body
:
encoding
:
UTF-8
string
:
'
{"message":"Message","starts_at":"2015-02-07T15:35:00.000Z","ends_at":"2015-02-07T16:35:00.000Z","color":"","font":""}'
http_version
:
recorded_at
:
Sat, 07 Feb 2015 16:44:35 GMT
recorded_with
:
VCR 2.4.0
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