Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose DangerfileGitLabPlugin#mr_changes #1309

Merged
merged 1 commit into from
Jul 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<!-- Your comment below here -->
* Handle GitLab URL containing /-/ scope on Jenkins - [@adamprice](https://github.com/adamprice)
* Add `pr_draft?` method to GitHub DSL. - [@connorshea](https://github.com/connorshea)
* Expose `DangerfileGitLabPlugin#mr_changes`. - [@rymai](https://github.com/rymai) [#1309](https://github.com/danger/danger/pull/1309)
<!-- Your comment above here -->

## 8.3.0
Expand Down
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,24 @@
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[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