Coder Social home page Coder Social logo

Comments (10)

sebastianfeldmann avatar sebastianfeldmann commented on August 30, 2024 1

Fixed and released with version 5.18.3

Thanks for reporting it :)

from captainhook.

cegento avatar cegento commented on August 30, 2024 1

Thank you for the quick fix

from captainhook.

cegento avatar cegento commented on August 30, 2024 1

I found the issue, it was actually my fault, i have put it under "commit-msg" instead of "prepare-commit-msg". Somehow the application did not throw any errors + even recognized it as a valid action under "commit-msg" and even composed the correct message :D

from captainhook.

sebastianfeldmann avatar sebastianfeldmann commented on August 30, 2024

I will have a look and see if I can reproduce the issue.

from captainhook.

sebastianfeldmann avatar sebastianfeldmann commented on August 30, 2024

Ok I found the issue.
The default commit message templates includes a lot of comment lines.
Within those comment lines the branch name is present.

The action checks if the issue key is already in the prepared commit messages and if so it does nothing.
The problem being that I'm not making a difference between comment lins and actual message text.

In the new version I'll release in a bit (still thinking about some edge cases) this should be fixed.

from captainhook.

cegento avatar cegento commented on August 30, 2024

I have looked it up again, either the error is now from my side or there are still issues.

For debug: i did this in the InjectIssueKEyFromranch.php file:

echo var_dump($this->createNewCommitMessage($options, $msg, $issueID));

and output was again correct but somehow again githu did not recognize

from captainhook.

sebastianfeldmann avatar sebastianfeldmann commented on August 30, 2024

Are you committing via an external tool like PHPStorm or Kraken, or on the terminal?

from captainhook.

sebastianfeldmann avatar sebastianfeldmann commented on August 30, 2024

How it should work.

  • The captain prepare commit message hook is triggered.
  • In case you provide a message via -m or use for example PHPStorm to commit. The message you provided will be used.
  • In case no message is provided git will load a default commit message from a template.
  • A file with your commit message is created .git/COMMIT_EDITMSG
  • The Cap'n reads that file and appends the issue key and writes the new version back to disk
  • Only if you are on the terminal and you did not provide a -m option the .git/COMMIT_EDITMSG file is loaded into your default editor (vi vim nano...)
  • If you close the editor git uses the file to create the final commit message

If you use PHPStorm or the -m option you will never see the added issue number while committing. You should see it using git log though.
If you run git commit in your terminal you should see the added issueID in your editor.

from captainhook.

cegento avatar cegento commented on August 30, 2024

I tested it via git commit now (without -m) and got exactly the same results as i have done with -m.

  • The echo var dump at line 80 i wrote printed the wanted commit message but github still somehow did not adapt (got git log)

from captainhook.

sebastianfeldmann avatar sebastianfeldmann commented on August 30, 2024

It works on my machine :/
Here is my prepare-commit-msg config

    "prepare-commit-msg": {
        "enabled": true,
        "actions": [
            {
                "action": "\\CaptainHook\\App\\Hook\\Message\\Action\\InjectIssueKeyFromBranch",
                "options": {
                    "regex": "#([A-Z]+\\-[0-9]+)#i",
                    "into": "body",
                    "mode": "append",
                    "prefix": "\nissue: ",
                    "force": false
                }
            }
        ]
    }

I'm on branch feature/captain-12345

git commit -m"My Commit Message"
pre-commit: 
 - \CaptainHook\App\Hook\PHP\Action\Linting                          : done
 - \CaptainHook\App\Hook\File\Action\DoesNotContainRegex             : done
 - \CaptainHook\App\Hook\File\Action\IsNotEmpty                      : done
 - Max size check                                                    : done
 - tools/phpunit --no-coverage --testsuite UnitTests                 : done
 - tools/phpcs --colors --standard=psr12 {$STAGED_FILES|of-type:p... : skipped
 - \CaptainHook\App\Hook\Composer\Action\CheckLockFile               : done
prepare-commit-msg: 
 - \CaptainHook\App\Hook\Message\Action\InjectIssueKeyFromBranch     : done
 - \CaptainHook\App\Hook\Message\Action\PrepareFromFile              : done
commit-msg: 
 - Verify commit message format                                      : done
 - Fake regex validation                                             : done
 - Store commit message on failure                                   : done
post-commit: 
 - hook is disabled
[feature/captain-12345 038612e] My Commit Message
 1 file changed, 2 insertions(+)

Then my git log looks like this

git log HEAD^..HEAD
commit 038612e1cce66898fd544f0da09667446a4ed900 (HEAD -> feature/captain-12345)
Author: Sebastian Feldmann <[email protected]>
Date:   Sat Nov 11 17:33:53 2023 +0100

    My Commit Message
    
    issue: captain-12345

How do you execute the Captain? Locally installed PHP or a Docker container?

from captainhook.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.