summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2018-05-28 09:52:08 +0000
committerDouwe Maan <douwe@gitlab.com>2018-05-28 09:52:08 +0000
commit4bc16881347b53709c0f28a3ac2ed3a96d7051b9 (patch)
tree80f88831eb64c8b4c4439d8759afb53c30df3929
parentaa1a39a927b2810c07d23920d5035c6143d8c9cc (diff)
parent4ba4275632351518a4b65e432914a60747ce3e52 (diff)
downloadgitlab-shell-4bc16881347b53709c0f28a3ac2ed3a96d7051b9.tar.gz
Merge branch 'bvl-display-username-instead-of-fullname' into 'master'v7.1.3
Display the username instead of fullname Closes #131 See merge request gitlab-org/gitlab-shell!204
-rw-r--r--CHANGELOG3
-rw-r--r--VERSION2
-rw-r--r--lib/gitlab_shell.rb10
-rw-r--r--spec/gitlab_shell_spec.rb12
4 files changed, 18 insertions, 9 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 388c478..af2bcb5 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,6 @@
+v7.1.3
+ - Use username instead of full name for identifying users (!204)
+
v7.1.2
- Add missing GitlabLogger#error method (!200)
diff --git a/VERSION b/VERSION
index a8a1887..1996c50 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-7.1.2
+7.1.3
diff --git a/lib/gitlab_shell.rb b/lib/gitlab_shell.rb
index b38fefe..9644cf4 100644
--- a/lib/gitlab_shell.rb
+++ b/lib/gitlab_shell.rb
@@ -18,7 +18,7 @@ class GitlabShell # rubocop:disable Metrics/ClassLength
API_COMMANDS = %w(2fa_recovery_codes).freeze
GL_PROTOCOL = 'ssh'.freeze
- attr_accessor :key_id, :gl_repository, :repo_name, :command, :git_access, :username
+ attr_accessor :key_id, :gl_repository, :repo_name, :command, :git_access
attr_reader :repo_path
def initialize(key_id)
@@ -196,8 +196,14 @@ class GitlabShell # rubocop:disable Metrics/ClassLength
end
end
+ def username_from_discover
+ return nil unless user && user['username']
+
+ "@#{user['username']}"
+ end
+
def username
- user && user['name'] || 'Anonymous'
+ @username ||= username_from_discover || 'Anonymous'
end
# User identifier to be used in log messages.
diff --git a/spec/gitlab_shell_spec.rb b/spec/gitlab_shell_spec.rb
index c3d4466..eef0caf 100644
--- a/spec/gitlab_shell_spec.rb
+++ b/spec/gitlab_shell_spec.rb
@@ -31,7 +31,7 @@ describe GitlabShell do
let(:api) do
double(GitlabNet).tap do |api|
- api.stub(discover: { 'name' => 'John Doe' })
+ api.stub(discover: { 'name' => 'John Doe', 'username' => 'testuser' })
api.stub(check_access: GitAccessStatus.new(
true,
'ok',
@@ -167,7 +167,7 @@ describe GitlabShell do
it "should use usernames if configured to do so" do
GitlabConfig.any_instance.stub(audit_usernames: true)
- $logger.should_receive(:info).with("executing git command", hash_including(user: 'John Doe'))
+ $logger.should_receive(:info).with("executing git command", hash_including(user: 'testuser'))
end
end
@@ -202,7 +202,7 @@ describe GitlabShell do
it "should use usernames if configured to do so" do
GitlabConfig.any_instance.stub(audit_usernames: true)
- $logger.should_receive(:info).with("executing git command", hash_including(user: 'John Doe'))
+ $logger.should_receive(:info).with("executing git command", hash_including(user: 'testuser'))
end
end
@@ -248,7 +248,7 @@ describe GitlabShell do
it "should use usernames if configured to do so" do
GitlabConfig.any_instance.stub(audit_usernames: true)
- $logger.should_receive(:info).with("executing git command", hash_including(user: 'John Doe'))
+ $logger.should_receive(:info).with("executing git command", hash_including(user: 'testuser'))
end
end
@@ -275,7 +275,7 @@ describe GitlabShell do
it "should use usernames if configured to do so" do
GitlabConfig.any_instance.stub(audit_usernames: true)
- $logger.should_receive(:info).with("executing git command", hash_including(user: 'John Doe'))
+ $logger.should_receive(:info).with("executing git command", hash_including(user: 'testuser'))
end
end
@@ -452,7 +452,7 @@ describe GitlabShell do
before do
Kernel.stub(:exec)
shell.gl_repository = gl_repository
- shell.username = gl_username
+ shell.instance_variable_set(:@username, gl_username)
end
it "uses Kernel::exec method" do