spock icon indicating copy to clipboard operation
spock copied to clipboard

Add author to commits

Open knut-forkalsrud opened this issue 5 years ago • 1 comments

Git distinguishes between author and committer. The configured committer details in site/settings/addons/spock.yaml are fine, but the Statamic user who is logged in should be credited with the authorship. The log show both. For example with spock.yaml like the example:

git_username: Spock
git_email: [email protected]

And a user (username "bob", first name "Bob", last name "Author", email "[email protected]"). The log will look something like:

git log --pretty=full
Author: Bob Author <[email protected]>
Commit: Spock <[email protected]>

    Entry deleted by bob

This is somewhat opposite to the desires expressed in issue #25, having the commit message itself include something like "[spock]" to distinguish it from typical developer commits. However there is no conflict between this and that. We can do both.

My apologies for breaking all the tests. I'm not really a PHP developer, and my feeble attempt at running the test is greeted with a definite error message:

php addons/Spock/tests/GitTest.php 

Fatal error: Class 'PHPUnit_Framework_TestCase' not found in /Users/knut/opensource/spock/addons/Spock/tests/GitTest.php on line 10

I may need a pointer to how to run the tests effectively.

Also part of the pull request is a change from looking at "affected paths", and instead commit all outstanding changes. There seems to be an issue with some changes (draft blog entries) not being accurately reflected in "affected paths". Maybe this aspect should have ben a different pull request altogether.

Finally I'm using the standard escapeshellarg to escape any potential malicious input to the shell command. I notice commit b4a89a4c7cff3ef5ff6da35471d6507182f65076 is opposite in some ways, but I suspect that is just a workaround for a different culprit.

knut-forkalsrud avatar Nov 06 '18 21:11 knut-forkalsrud

Would love to see this added! Is it also possible to have the commitMessage be something you can append or change via the config? Maybe something like this:

protected function commitMessage() {
    $msg = $this->label();
    if ($this->user) {
        $msg .= ' by ' . $this->user->username();
    }
    // Append commit if in config
    if ($commitAppend = array_get($this->config, 'git_commit_append')) {
        $msg .= ' ' . $commitAppend;
    }
    return $msg;
}

bluetidepro avatar Jan 10 '19 19:01 bluetidepro