statamic / spock

Automatically perform git commits, pushes, and other cli actions when Statamic content changes
95 stars 16 forks source link

Add author to commits #28

Open knut-forkalsrud opened 6 years ago

knut-forkalsrud commented 6 years ago

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: spock@domain.com

And a user (username "bob", first name "Bob", last name "Author", email "bob@example.com"). The log will look something like:

git log --pretty=full
Author: Bob Author <bob@example.com>
Commit: Spock <spock@domain.com>

    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.

bluetidepro commented 5 years ago

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;
}