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
27e9ed7a
Commit
27e9ed7a
authored
Oct 15, 2018
by
Nick Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge flowdock monkeypatch into the inlined gem
parent
8d322292
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
101 deletions
+23
-101
app/models/project_services/flowdock_service.rb
app/models/project_services/flowdock_service.rb
+0
-48
lib/flowdock/git.rb
lib/flowdock/git.rb
+19
-48
lib/flowdock/git/builder.rb
lib/flowdock/git/builder.rb
+4
-5
No files found.
app/models/project_services/flowdock_service.rb
View file @
27e9ed7a
# frozen_string_literal: true
# frozen_string_literal: true
require
'flowdock/git'
# Flow dock depends on Grit to compute the number of commits between two given
# commits. To make this depend on Gitaly, a monkey patch is applied
module
Flowdock
class
Git
# pass down a Repository all the way down
def
repo
@options
[
:repo
]
end
def
config
{}
end
def
messages
Git
::
Builder
.
new
(
repo:
repo
,
ref:
@ref
,
before:
@from
,
after:
@to
,
commit_url:
@commit_url
,
branch_url:
@branch_url
,
diff_url:
@diff_url
,
repo_url:
@repo_url
,
repo_name:
@repo_name
,
permanent_refs:
@permanent_refs
,
tags:
tags
).
to_hashes
end
class
Builder
def
commits
@repo
.
commits_between
(
@before
,
@after
).
map
do
|
commit
|
{
url:
@opts
[
:commit_url
]
?
@opts
[
:commit_url
]
%
[
commit
.
sha
]
:
nil
,
id:
commit
.
sha
,
message:
commit
.
message
,
author:
{
name:
commit
.
author_name
,
email:
commit
.
author_email
}
}
end
end
end
end
end
class
FlowdockService
<
Service
class
FlowdockService
<
Service
prop_accessor
:token
prop_accessor
:token
validates
:token
,
presence:
true
,
if: :activated?
validates
:token
,
presence:
true
,
if: :activated?
...
...
lib/flowdock/git.rb
View file @
27e9ed7a
# frozen_string_literal: true
# frozen_string_literal: true
require
"multi_json"
require
'multi_json'
require
"cgi"
require
'cgi'
require
"flowdock"
require
'flowdock'
require
"flowdock/git/builder"
require
'flowdock/git/builder'
module
Flowdock
module
Flowdock
class
Git
class
Git
TokenError
=
Class
.
new
(
StandardError
)
TokenError
=
Class
.
new
(
StandardError
)
DEFAULT_PERMANENT_REFS
=
[
Regexp
.
new
(
'refs/heads/master'
)
].
freeze
class
<<
self
class
<<
self
def
post
(
ref
,
from
,
to
,
options
=
{})
def
post
(
ref
,
from
,
to
,
options
=
{})
Git
.
new
(
ref
,
from
,
to
,
options
).
post
Git
.
new
(
ref
,
from
,
to
,
options
).
post
end
end
def
background_post
(
ref
,
from
,
to
,
options
=
{})
Git
.
new
(
ref
,
from
,
to
,
options
).
background_post
end
end
end
def
initialize
(
ref
,
from
,
to
,
options
=
{})
def
initialize
(
ref
,
from
,
to
,
options
=
{})
raise
TokenError
.
new
(
"Flowdock API token not found"
)
unless
options
[
:token
]
@ref
=
ref
@ref
=
ref
@from
=
from
@from
=
from
@to
=
to
@to
=
to
@options
=
options
@options
=
options
@token
=
options
[
:token
]
||
config
[
"flowdock.token"
]
||
raise
(
TokenError
.
new
(
"Flowdock API token not found"
))
@token
=
options
[
:token
]
@commit_url
=
options
[
:commit_url
]
||
config
[
"flowdock.commit-url-pattern"
]
||
nil
@commit_url
=
options
[
:commit_url
]
@diff_url
=
options
[
:diff_url
]
||
config
[
"flowdock.diff-url-pattern"
]
||
nil
@diff_url
=
options
[
:diff_url
]
@repo_url
=
options
[
:repo_url
]
||
config
[
"flowdock.repository-url"
]
||
nil
@repo_url
=
options
[
:repo_url
]
@repo_name
=
options
[
:repo_name
]
||
config
[
"flowdock.repository-name"
]
||
nil
@repo_name
=
options
[
:repo_name
]
@permanent_refs
=
options
.
fetch
(
:permanent_refs
,
DEFAULT_PERMANENT_REFS
)
refs
=
options
[
:permanent_refs
]
||
config
[
"flowdock.permanent-references"
]
||
"refs/heads/master"
@permanent_refs
=
refs
.
split
(
","
)
.
map
(
&
:strip
)
.
map
{
|
exp
|
Regexp
.
new
(
exp
)
}
end
end
# Send git push notification to Flowdock
# Send git push notification to Flowdock
...
@@ -43,29 +40,14 @@ module Flowdock
...
@@ -43,29 +40,14 @@ module Flowdock
end
end
end
end
# Create and post notification in background process. Avoid blocking the push notification.
def
background_post
pid
=
Process
.
fork
if
pid
.
nil?
Grit
::
Git
.
with_timeout
(
600
)
do
post
end
else
Process
.
detach
(
pid
)
# Parent
end
end
def
repo
def
repo
@repo
||=
Grit
::
Repo
.
new
(
@options
[
:repo
]
@options
[
:repo
]
||
Dir
.
pwd
,
is_bare:
@options
[
:is_bare
]
||
false
)
end
end
private
private
def
messages
def
messages
Git
::
Builder
.
new
(
repo:
@
repo
,
Git
::
Builder
.
new
(
repo:
repo
,
ref:
@ref
,
ref:
@ref
,
before:
@from
,
before:
@from
,
after:
@to
,
after:
@to
,
...
@@ -81,18 +63,7 @@ module Flowdock
...
@@ -81,18 +63,7 @@ module Flowdock
# Flowdock tags attached to the push notification
# Flowdock tags attached to the push notification
def
tags
def
tags
tags
=
Array
(
@options
[
:tags
]).
map
{
|
tag
|
CGI
.
escape
(
tag
)
}
if
@options
[
:tags
]
@options
[
:tags
]
else
config
[
"flowdock.tags"
].
to_s
.
split
(
","
).
map
(
&
:strip
)
end
tags
.
map
{
|
t
|
CGI
.
escape
(
t
)
}
end
def
config
@config
||=
Grit
::
Config
.
new
(
repo
)
end
end
end
end
end
end
lib/flowdock/git/builder.rb
View file @
27e9ed7a
# frozen_string_literal: true
# frozen_string_literal: true
require
"grit"
require
'cgi'
require
'cgi'
require
"securerandom"
require
'securerandom'
module
Flowdock
module
Flowdock
class
Git
class
Git
...
@@ -93,12 +92,12 @@ module Flowdock
...
@@ -93,12 +92,12 @@ module Flowdock
def
commits
def
commits
@repo
.
commits_between
(
@before
,
@after
).
map
do
|
commit
|
@repo
.
commits_between
(
@before
,
@after
).
map
do
|
commit
|
{
{
url:
if
@opts
[
:commit_url
]
then
@opts
[
:commit_url
]
%
[
commit
.
sha
]
end
,
url:
@opts
[
:commit_url
]
?
@opts
[
:commit_url
]
%
[
commit
.
sha
]
:
nil
,
id:
commit
.
sha
,
id:
commit
.
sha
,
message:
commit
.
message
,
message:
commit
.
message
,
author:
{
author:
{
name:
commit
.
author
.
name
,
name:
commit
.
author
_
name
,
email:
commit
.
author
.
email
email:
commit
.
author
_
email
}
}
}
}
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