Skip to content

Commit

Permalink
Expose DangerfileGitLabPlugin#mr_changes
Browse files Browse the repository at this point in the history
Signed-off-by: Rémy Coutable <remy@rymai.me>
  • Loading branch information
rymai committed Jul 1, 2021
1 parent 327aaae commit a95e5b7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/danger/danger_core/plugins/dangerfile_gitlab_plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@ def mr_diff
@gitlab.mr_diff
end

# @!group MR Changes
# The array of changes
# @return [Array<Gitlab::ObjectifiedHash>]
#
def mr_changes
@gitlab.mr_changes.changes
end

# @!group MR Commit Metadata
# The branch to which the MR is going to be merged into
# @deprecated Please use {#branch_for_base} instead
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,25 @@
end
end

describe "#mr_changes" do
before do
stub_merge_request_changes(
"merge_request_1_changes_response",
"k0nserv\%2Fdanger-test",
1
)
end

it "sets the mr_changes" do
with_git_repo(origin: "git@gitlab.com:k0nserv/danger-test.git") do
expect(plugin.mr_changes).to all(be_an_instance_of(Gitlab::ObjectifiedHash))
expect(plugin.mr_changes[0].to_h).to match(hash_including("old_path"=>"Dangerfile", "new_path"=>"Dangerfile", "a_mode"=>"100644", "b_mode"=>"100644", "new_file"=>false, "renamed_file"=>false, "deleted_file"=>false, "diff"=>an_instance_of(String)))
expect(plugin.mr_changes[1].to_h).to match(hash_including("old_path"=>"a", "new_path"=>"a", "a_mode"=>"0", "b_mode"=>"100644", "new_file"=>true, "renamed_file"=>false, "deleted_file"=>false, "diff"=>"--- /dev/null\n+++ b/a\n@@ -0,0 +1 @@\n+Danger rocks!\n"))
expect(plugin.mr_changes[2].to_h).to match(hash_including("old_path"=>"b", "new_path"=>"b", "a_mode"=>"0", "b_mode"=>"100644", "new_file"=>true, "renamed_file"=>false, "deleted_file"=>false, "diff"=>"--- /dev/null\n+++ b/b\n@@ -0,0 +1 @@\n+Test message please ignore\n"))
end
end
end

describe "#mr_json" do
it "is set" do
with_git_repo(origin: "git@gitlab.com:k0nserv/danger-test.git") do
Expand Down

0 comments on commit a95e5b7

Please sign in to comment.