Skip to content

Commit

Permalink
Merge pull request #10 from danger/gitlab_author_fix
Browse files Browse the repository at this point in the history
Add support for gitlab
  • Loading branch information
orta authored Feb 10, 2017
2 parents 883a539 + 8360ab8 commit dea0664
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 7 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ source 'https://rubygems.org'
gemspec

gem 'rspec', '~> 3.4'
gem 'pry'
1 change: 1 addition & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ DEPENDENCIES
danger-mention!
guard (~> 2.14)
guard-rspec (~> 4.7)
pry
rake (~> 10.0)
rspec (~> 3.4)
rubocop (~> 0.41)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Danger Mention

A [Danger](https://github.com/danger/danger) plugin to automatically mention potential reviewers on pull requests.
A [Danger](https://github.com/danger/danger) plugin to automatically mention potential reviewers on pull requests on GitHub and GitLab.

## Installation

Expand Down
20 changes: 18 additions & 2 deletions lib/danger_plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,18 @@ def select_files(file_blacklist)
def compose_urls(files)
host = 'https://' + env.request_source.host
repo_slug = env.ci_source.repo_slug
path = host + '/' + repo_slug + '/' + 'blame' + '/' + github.branch_for_base

path = ""
if defined? @dangerfile.gitlab
# https://gitlab.com/danger-systems/danger.systems/blame/danger_update/.gitlab-ci.yml
path = host + '/' + repo_slug + '/' + 'blame' + '/' + gitlab.branch_for_base

elsif defined? @dangerfile.github
# https://github.com/artsy/emission/blame/master/dangerfile.js
path = host + '/' + repo_slug + '/' + 'blame' + '/' + github.branch_for_base
else
raise "This plugin does not yet support bitbucket, would love PRs: https://github.com/danger/danger-mention/"
end

urls = []
files.each do |file|
Expand Down Expand Up @@ -105,7 +116,12 @@ def parse_blame(url)
end

def find_reviewers(users, user_blacklist, max_reviewers)
user_blacklist << pr_author
if defined? @dangerfile.gitlab
user_blacklist << gitlab.mr_author
elsif defined? @dangerfile.github
user_blacklist << github.pr_author
end

users = users.select { |k, _| !user_blacklist.include? k }
users = users.sort_by { |_, value| value }.reverse

Expand Down
2 changes: 1 addition & 1 deletion lib/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module DangerMention
VERSION = '0.5.0'.freeze
VERSION = '0.6.0'.freeze
DESCRIPTION = 'Danger plugin to automatically mention potential reviewers on pull requests'
end
31 changes: 28 additions & 3 deletions spec/danger_plugin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,22 @@ module Danger

describe :compose_urls do
before do
allow(@mention).to receive_message_chain('env.request_source.host').and_return('host')
github = Danger::RequestSources::GitHub.new({}, testing_env)
allow(@mention).to receive_message_chain('env.request_source').and_return github
allow(@mention).to receive_message_chain('env.ci_source.repo_slug').and_return('slug')
allow(@mention).to receive_message_chain('github.branch_for_base').and_return('branch')
end

it 'composes urls for files' do
files = (1..4).to_a.map { |i| format('M%d', i) }
expected = files.map { |f| format('https://host/slug/blame/branch/%s', f) }
expected = files.map { |f| format('https://github.com/slug/blame/branch/%s', f) }
results = @mention.compose_urls(files)
expect(results).to eq expected
end

describe :compose_urls do
before do
allow(@mention).to receive(:pr_author).and_return('author')
allow(@mention).to receive_message_chain('github.pr_author').and_return('author')
end

it 'finds potential reviewers' do
Expand Down Expand Up @@ -88,7 +89,31 @@ module Danger
expect(output).to include('@user2')
end
end
end


describe :compose_urls_gitlab do

it 'composes gitlab urls for files' do
stub_env = {
"DRONE" => true,
"DRONE_REPO" => "k0nserv/danger-test",
"DRONE_PULL_REQUEST" => "593728",
"DANGER_GITLAB_API_TOKEN" => "a86e56d46ac78b"
}

env = Danger::EnvironmentManager.new(testing_env)
env.request_source = Danger::RequestSources::GitLab.new(Danger::Drone.new(stub_env), testing_env)
danger = Danger::Dangerfile.new(env)
allow(danger.gitlab).to receive(:branch_for_base).and_return("branch_name")

files = (1..4).to_a.map { |i| format('M%d', i) }
expected = files.map { |f| format('https://gitlab.com/artsy/eigen/blame/branch_name/%s', f) }

results = danger.mention.compose_urls(files)
expect(results).to eq expected
end
end
end
end

0 comments on commit dea0664

Please sign in to comment.