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
iv
gitlab-ce
Commits
5c1b49f4
Commit
5c1b49f4
authored
Dec 04, 2015
by
Valery Sizov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add added, modified and removed properties to commit object in webhook
parent
4de7f32c
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
51 additions
and
42 deletions
+51
-42
CHANGELOG
CHANGELOG
+3
-0
app/models/commit.rb
app/models/commit.rb
+23
-1
doc/web_hooks/web_hooks.md
doc/web_hooks/web_hooks.md
+9
-5
lib/gitlab/push_data_builder.rb
lib/gitlab/push_data_builder.rb
+2
-30
spec/lib/gitlab/push_data_builder_spec.rb
spec/lib/gitlab/push_data_builder_spec.rb
+3
-6
spec/models/commit_spec.rb
spec/models/commit_spec.rb
+11
-0
No files found.
CHANGELOG
View file @
5c1b49f4
...
...
@@ -10,6 +10,9 @@ v 8.3.0 (unreleased)
- Add API endpoint to fetch merge request commits list
- Expose events API with comment information and author info
v 8.2.3
- Webhook payload has an added, modified and removed properties for each commit
v 8.2.2
- Fix 404 in redirection after removing a project (Stan Hu)
- Ensure cached application settings are refreshed at startup (Stan Hu)
...
...
app/models/commit.rb
View file @
5c1b49f4
...
...
@@ -146,7 +146,10 @@ class Commit
author:
{
name:
author_name
,
email:
author_email
}
},
added:
repo_changes
[
:added
],
modified:
repo_changes
[
:modified
],
removed:
repo_changes
[
:removed
]
}
end
...
...
@@ -196,4 +199,23 @@ class Commit
def
status
ci_commit
.
try
(
:status
)
||
:not_found
end
private
def
repo_changes
changes
=
{
added:
[],
modified:
[],
removed:
[]
}
diffs
.
each
do
|
diff
|
case
true
when
diff
.
deleted_file
changes
[
:removed
]
<<
diff
.
old_path
when
diff
.
renamed_file
,
diff
.
new_file
changes
[
:added
]
<<
diff
.
new_path
else
changes
[
:modified
]
<<
diff
.
new_path
end
end
changes
end
end
doc/web_hooks/web_hooks.md
View file @
5c1b49f4
...
...
@@ -57,6 +57,9 @@ X-Gitlab-Event: Push Hook
"name"
:
"Jordi Mallach"
,
"email"
:
"jordi@softcatala.org"
}
"added"
:
[
"CHANGELOG"
],
"modified"
:
[
"app/controller/application.rb"
],
"removed"
:
[]
},
{
"id"
:
"da1560886d4f094c3e6c9ef40349f7d38b5d27d7"
,
...
...
@@ -66,13 +69,14 @@ X-Gitlab-Event: Push Hook
"author"
:
{
"name"
:
"GitLab dev user"
,
"email"
:
"gitlabdev@dv6700.(none)"
}
},
"added"
:
[
"CHANGELOG"
],
"modified"
:
[
"app/controller/application.rb"
],
"removed"
:
[]
}
],
"total_commits_count"
:
4
,
"added"
:
[
"CHANGELOG"
],
"modified"
:
[
"app/controller/application.rb"
],
"removed"
:
[]
"total_commits_count"
:
4
}
```
...
...
lib/gitlab/push_data_builder.rb
View file @
5c1b49f4
...
...
@@ -18,10 +18,7 @@ module Gitlab
# homepage: String,
# },
# commits: Array,
# total_commits_count: Fixnum,
# added: ["CHANGELOG"],
# modified: [],
# removed: ["tmp/file.txt"]
# total_commits_count: Fixnum
# }
#
def
build
(
project
,
user
,
oldrev
,
newrev
,
ref
,
commits
=
[],
message
=
nil
)
...
...
@@ -37,7 +34,6 @@ module Gitlab
type
=
Gitlab
::
Git
.
tag_ref?
(
ref
)
?
"tag_push"
:
"push"
repo_changes
=
repo_changes
(
project
,
newrev
,
oldrev
)
# Hash to be passed as post_receive_data
data
=
{
object_kind:
type
,
...
...
@@ -60,10 +56,7 @@ module Gitlab
visibility_level:
project
.
visibility_level
},
commits:
commit_attrs
,
total_commits_count:
commits_count
,
added:
repo_changes
[
:added
],
modified:
repo_changes
[
:modified
],
removed:
repo_changes
[
:removed
]
total_commits_count:
commits_count
}
data
...
...
@@ -94,27 +87,6 @@ module Gitlab
newrev
end
end
def
repo_changes
(
project
,
newrev
,
oldrev
)
changes
=
{
added:
[],
modified:
[],
removed:
[]
}
compare_result
=
CompareService
.
new
.
execute
(
project
,
newrev
,
project
,
oldrev
)
if
compare_result
compare_result
.
diffs
.
each
do
|
diff
|
case
true
when
diff
.
deleted_file
changes
[
:removed
]
<<
diff
.
old_path
when
diff
.
renamed_file
,
diff
.
new_file
changes
[
:added
]
<<
diff
.
new_path
else
changes
[
:modified
]
<<
diff
.
new_path
end
end
end
changes
end
end
end
end
spec/lib/gitlab/push_data_builder_spec.rb
View file @
5c1b49f4
...
...
@@ -17,9 +17,9 @@ describe 'Gitlab::PushDataBuilder' do
it
{
expect
(
data
[
:repository
][
:git_ssh_url
]).
to
eq
(
project
.
ssh_url_to_repo
)
}
it
{
expect
(
data
[
:repository
][
:visibility_level
]).
to
eq
(
project
.
visibility_level
)
}
it
{
expect
(
data
[
:total_commits_count
]).
to
eq
(
3
)
}
it
{
expect
(
data
[
:added
]).
to
eq
([
"gitlab-grack"
])
}
it
{
expect
(
data
[
:
modified
]).
to
eq
([
".gitmodules"
,
"files/ruby/popen.rb"
,
"files/ruby/regex.rb
"
])
}
it
{
expect
(
data
[
:removed
]).
to
eq
([])
}
it
{
expect
(
data
[
:
commits
].
first
[
:
added
]).
to
eq
([
"gitlab-grack"
])
}
it
{
expect
(
data
[
:
commits
].
first
[
:modified
]).
to
eq
([
".gitmodules
"
])
}
it
{
expect
(
data
[
:
commits
].
first
[
:
removed
]).
to
eq
([])
}
end
describe
:build
do
...
...
@@ -38,8 +38,5 @@ describe 'Gitlab::PushDataBuilder' do
it
{
expect
(
data
[
:ref
]).
to
eq
(
'refs/tags/v1.1.0'
)
}
it
{
expect
(
data
[
:commits
]).
to
be_empty
}
it
{
expect
(
data
[
:total_commits_count
]).
to
be_zero
}
it
{
expect
(
data
[
:added
]).
to
eq
([])
}
it
{
expect
(
data
[
:modified
]).
to
eq
([])
}
it
{
expect
(
data
[
:removed
]).
to
eq
([])
}
end
end
spec/models/commit_spec.rb
View file @
5c1b49f4
...
...
@@ -100,4 +100,15 @@ eos
# Include the subject in the repository stub.
let
(
:extra_commits
)
{
[
subject
]
}
end
describe
'#hook_attrs'
do
let
(
:data
)
{
commit
.
hook_attrs
}
it
{
expect
(
data
).
to
be_a
(
Hash
)
}
it
{
expect
(
data
[
:message
]).
to
include
(
'Add submodule from gitlab.com'
)
}
it
{
expect
(
data
[
:timestamp
]).
to
eq
(
'2014-02-27T11:01:38+02:00'
)
}
it
{
expect
(
data
[
:added
]).
to
eq
([
"gitlab-grack"
])
}
it
{
expect
(
data
[
:modified
]).
to
eq
([
".gitmodules"
])
}
it
{
expect
(
data
[
:removed
]).
to
eq
([])
}
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