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

Add author to commits #28

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 36 additions & 7 deletions addons/Spock/Git.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,50 @@ protected function commitCommand()
$parts = ['git'];

if ($username = array_get($this->config, 'git_username')) {
$parts[] = sprintf('-c "user.name=%s"', $username);
$parts[] = '-c';
$parts[] = escapeshellarg('user.name=' . $username);
}

if ($email = array_get($this->config, 'git_email')) {
$parts[] = sprintf('-c "user.email=%s"', $email);
$parts[] = '-c';
$parts[] = escapeshellarg('user.email=' . $email);
}

$message = 'commit -m "' . $this->label();
$message .= $this->user ? ' by ' . $this->user->username() : '';
$message .= '"';
$parts[] = $message;

$parts[] = 'commit';
if ($this->user) {
$parts[] = escapeshellarg($this->author());
}
$parts[] = '-m';
$parts[] = escapeshellarg($this->commitMessage());
return join(' ', $parts);
}



/**
* Create a Git author parameter from the user's name and email address,
* i.e, "--author=A U Thor <[email protected]>"
*/
protected function author() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method could be private

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed it could be private, however all the other similar methods are protected, so I'd rather follow suit on that.

$user = $this->user->toArray();
return sprintf("--author=%s <%s>", $user['name'], $user['email']);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use the getter methods on the User object?
Like $this->user->email()

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I can't get $this->user->email() to work... Maybe I'm being dense, but PHP claim there is no such function. I'll go back to the toArray() approach.

}


/**
* Generate the commit message
*
* @return string
*/
protected function commitMessage() {
$msg = $this->label();
if ($this->user) {
$msg .= ' by ' . $this->user->username();
}
return $msg;
}


/**
* Get the label of the class, which is the action name.
*
Expand Down