reconquest / atlassian-external-hooks

External Hooks plugin for Atlassian Bitbucket
https://external-hooks.reconquest.io
Other
44 stars 37 forks source link

how to verify commit message during push ? #28

Closed z00m1n closed 6 years ago

z00m1n commented 8 years ago

I have a commit-msg hook that works fine when used with a 'raw' git repo and I'm trying to use your plugin to use it in a Stash git repo, so commit message are verified whenever anything is pushed to the repo.

I can't seem to figure out what positional parameters I need to specify in order to pass the commit message to the script.

Can you help me ?

seletskiy commented 8 years ago

@z00m1n: You can obtain commit message by directly invoking git log with correct parameters and SHA hash of commit you are looking for. SHA hash can be obtained from stdin of the script.

deseven commented 6 years ago

Sorry, but how exactly you can do that?
When it's a pre-recieve hook, apparently it happens before the repo is actually updated. This test script doesn't work as intended, git show always returns Invalid revision range because it doesn't have commits that are being pushed.
Post-receive hook is obviously useless in that case, since we've already accepted incoming push.

seletskiy commented 6 years ago

@deseven: which version of BitBucket do you use?

deseven commented 6 years ago

It's 5.9.0.

seletskiy commented 6 years ago

@deseven: I just tested it in 5.9.0 and example script works for me:

remote: Push rejected by External Hook
remote: Script name: /tmp/test.sh
remote: Positional arguments:
remote: STASH_USER_NAME: admin
remote: STASH_USER_EMAIL: admin@example.com
remote: STASH_REPO_NAME: rep_1
remote: STASH_IS_ADMIN: true
remote: Ref update:
remote:  Old value: 0a943a29376f2336b78312d99e65da17048951db
remote:  New value: c1eb3baac452e78cda2c1e209dcbf4685d84924e
remote:  Ref name:  refs/heads/master
remote:  Diff:
remote:   commit c1eb3baac452e78cda2c1e209dcbf4685d84924e
remote:   Author: Stanislav Seletskiy <...>
remote:   Date:   Fri Aug 3 11:29:28 2018 +0300
remote:
remote:       yyy
remote:
remote:   diff --git a/yyy b/yyy
remote:   new file mode 100644
remote:   index 0000000..0cfbf08
remote:   --- /dev/null
remote:   +++ b/yyy
remote:   @@ -0,0 +1 @@
remote:   +2
remote:
remote:   commit ec20450ca7b4d913f553fddb784fee8d143610ec
remote:   Author: Stanislav Seletskiy <...>
remote:   Date:   Fri Aug 3 11:17:42 2018 +0300
remote:
remote:       test
remote:
remote:   diff --git a/xxx b/xxx
remote:   new file mode 100644
remote:   index 0000000..d00491f
remote:   --- /dev/null
remote:   +++ b/xxx
remote:   @@ -0,0 +1 @@
remote:   +1
deseven commented 6 years ago

Thanks for your time! What am i doing wrong then? I created a test repo in bitbucket and cloned it to my local PC. Then i put test script contents into /var/atlassian/application-data/bitbucket/external-hooks/test and enabled it like that:

When i try to push to that repo i get this:

Authenticated to example.com ([1.1.1.1]:7999).
Counting objects: 6, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (6/6), 467 bytes | 467.00 KiB/s, done.
Total 6 (delta 0), reused 0 (delta 0)
remote: Script name: /var/atlassian/application-data/bitbucket/external-hooks/test
remote: Positional arguments:
remote: STASH_USER_NAME: deseven
remote: STASH_USER_EMAIL: de7@deseven.info
remote: STASH_REPO_NAME: test-repo
remote: STASH_IS_ADMIN: true
remote: Ref update:
remote:  Old value: f0ead277ec3035f134c236de7aa7ee42fc9237e3
remote:  New value: 4932439801089864c7b54f8223a21dc70db66616
remote:  Ref name:  refs/heads/master
remote:  Diff:
remote: fatal: Invalid revision range f0ead277ec3035f134c236de7aa7ee42fc9237e3..4932439801089864c7b54f8223a21dc70db66616
remote:
Transferred: sent 3552, received 2552 bytes, in 1.3 seconds
Bytes per second: sent 2660.0, received 1911.1
To ssh://example.com:7999/tool/test-repo.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'ssh://git@example.com:7999/tool/test-repo.git'

I also tried to simply output git log and there are really no new commits.

seletskiy commented 6 years ago

@deseven: which version of plugin are you using?

deseven commented 6 years ago

Updating to the latest version (4.4) worked. Sorry, i had no idea that it has new updates. Previous installed version was 3-something.
Thank you very much for your help.

seletskiy commented 6 years ago

@deseven: no problems.