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
8d322292
Commit
8d322292
authored
Oct 15, 2018
by
Nick Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rubocop improvements
parent
04aaf719
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
29 deletions
+30
-29
lib/flowdock/git.rb
lib/flowdock/git.rb
+16
-14
lib/flowdock/git/builder.rb
lib/flowdock/git/builder.rb
+14
-15
No files found.
lib/flowdock/git.rb
View file @
8d322292
# frozen_string_literal: true
require
"multi_json"
require
"multi_json"
require
"cgi"
require
"cgi"
require
"flowdock"
require
"flowdock"
...
@@ -6,7 +6,7 @@ require "flowdock/git/builder"
...
@@ -6,7 +6,7 @@ require "flowdock/git/builder"
module
Flowdock
module
Flowdock
class
Git
class
Git
class
TokenError
<
StandardError
;
end
TokenError
=
Class
.
new
(
StandardError
)
class
<<
self
class
<<
self
def
post
(
ref
,
from
,
to
,
options
=
{})
def
post
(
ref
,
from
,
to
,
options
=
{})
...
@@ -28,11 +28,12 @@ module Flowdock
...
@@ -28,11 +28,12 @@ module Flowdock
@diff_url
=
options
[
:diff_url
]
||
config
[
"flowdock.diff-url-pattern"
]
||
nil
@diff_url
=
options
[
:diff_url
]
||
config
[
"flowdock.diff-url-pattern"
]
||
nil
@repo_url
=
options
[
:repo_url
]
||
config
[
"flowdock.repository-url"
]
||
nil
@repo_url
=
options
[
:repo_url
]
||
config
[
"flowdock.repository-url"
]
||
nil
@repo_name
=
options
[
:repo_name
]
||
config
[
"flowdock.repository-name"
]
||
nil
@repo_name
=
options
[
:repo_name
]
||
config
[
"flowdock.repository-name"
]
||
nil
@permanent_refs
=
options
[
:permanent_refs
]
||
(
config
[
"flowdock.permanent-references"
]
||
"refs/heads/master"
)
refs
=
options
[
:permanent_refs
]
||
config
[
"flowdock.permanent-references"
]
||
"refs/heads/master"
.
split
(
","
)
@permanent_refs
=
refs
.
map
(
&
:strip
)
.
split
(
","
)
.
map
{
|
exp
|
Regexp
.
new
(
exp
)
}
.
map
(
&
:strip
)
.
map
{
|
exp
|
Regexp
.
new
(
exp
)
}
end
end
# Send git push notification to Flowdock
# Send git push notification to Flowdock
...
@@ -80,13 +81,14 @@ module Flowdock
...
@@ -80,13 +81,14 @@ module Flowdock
# Flowdock tags attached to the push notification
# Flowdock tags attached to the push notification
def
tags
def
tags
if
@options
[
:tags
]
tags
=
@options
[
:tags
]
if
@options
[
:tags
]
else
@options
[
:tags
]
config
[
"flowdock.tags"
].
to_s
.
split
(
","
).
map
(
&
:strip
)
else
end
.
map
do
|
t
|
config
[
"flowdock.tags"
].
to_s
.
split
(
","
).
map
(
&
:strip
)
CGI
.
escape
(
t
)
end
end
tags
.
map
{
|
t
|
CGI
.
escape
(
t
)
}
end
end
def
config
def
config
...
...
lib/flowdock/git/builder.rb
View file @
8d322292
# frozen_string_literal: true
require
"grit"
require
"grit"
require
'cgi'
require
'cgi'
require
"securerandom"
require
"securerandom"
...
@@ -31,7 +32,8 @@ module Flowdock
...
@@ -31,7 +32,8 @@ module Flowdock
private
private
def
encode
(
hash
)
def
encode
(
hash
)
return
hash
unless
""
.
respond_to?
:encode
return
hash
unless
""
.
respond_to?
(
:encode
)
encode_as_utf8
(
hash
)
encode_as_utf8
(
hash
)
end
end
...
@@ -46,8 +48,8 @@ module Flowdock
...
@@ -46,8 +48,8 @@ module Flowdock
encode_as_utf8
(
val
)
encode_as_utf8
(
val
)
end
end
elsif
obj
.
is_a?
(
String
)
&&
obj
.
encoding
!=
Encoding
::
UTF_8
elsif
obj
.
is_a?
(
String
)
&&
obj
.
encoding
!=
Encoding
::
UTF_8
if
!
obj
.
force_encoding
(
"UTF-8"
).
valid_encoding?
unless
obj
.
force_encoding
(
"UTF-8"
).
valid_encoding?
obj
.
force_encoding
(
"ISO-8859-1"
).
encode!
(
Encoding
::
UTF_8
,
:invalid
=>
:replace
,
:undef
=>
:replace
)
obj
.
force_encoding
(
"ISO-8859-1"
).
encode!
(
Encoding
::
UTF_8
,
invalid: :replace
,
undef:
:replace
)
end
end
end
end
end
end
...
@@ -78,6 +80,8 @@ module Flowdock
...
@@ -78,6 +80,8 @@ module Flowdock
# Class used to build Git payload
# Class used to build Git payload
class
Builder
class
Builder
include
::
Gitlab
::
Utils
::
StrongMemoize
def
initialize
(
opts
)
def
initialize
(
opts
)
@repo
=
opts
[
:repo
]
@repo
=
opts
[
:repo
]
@ref
=
opts
[
:ref
]
@ref
=
opts
[
:ref
]
...
@@ -101,7 +105,7 @@ module Flowdock
...
@@ -101,7 +105,7 @@ module Flowdock
end
end
def
ref_name
def
ref_name
@ref
.
to_s
.
sub
(
/\Arefs\/(heads|tags)\//
,
''
)
@ref
.
to_s
.
sub
(
%r{
\A
refs/(heads|tags)/}
,
''
)
end
end
def
to_hashes
def
to_hashes
...
@@ -120,20 +124,15 @@ module Flowdock
...
@@ -120,20 +124,15 @@ module Flowdock
end
end
def
permanent?
def
permanent?
@permanent
||=
@opts
[
:permanent_refs
].
select
do
|
regex
|
strong_memoize
(
:permanent
)
do
regex
.
match
(
@ref
)
@opts
[
:permanent_refs
].
any?
{
|
regex
|
regex
.
match
(
@ref
)
}
end
.
size
>
0
end
end
end
def
thread_title
def
thread_title
action
=
if
permanent?
action
=
"updated"
if
permanent?
"updated"
type
=
@ref
=~
%r(^refs/heads/)
?
"branch"
:
"tag"
end
type
=
if
@ref
.
match
(
%r(^refs/heads/)
)
"branch"
else
"tag"
end
[
@opts
[
:repo_name
],
type
,
ref_name
,
action
].
compact
.
join
(
" "
)
[
@opts
[
:repo_name
],
type
,
ref_name
,
action
].
compact
.
join
(
" "
)
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