chriseldredge / git-slack-hook Goto Github PK
View Code? Open in Web Editor NEWGit receive hook to notify Slack channels
Git receive hook to notify Slack channels
Can anyone explain for me the changesets and how they work? Maybe provide an example?
#!/bin/bash
is not default interpreter. Better way is to change it to #!/bin/env bash
I cloned your script (excellent script by the way... super helpful!) but it didnt work for me out of the box.
My bash scripting isnt that great, but I did a load of debugging and I came to the conclusion that everything is working up until the curl command.
I replaced:
curl -s
-d "payload=$payload"
"$webhook_url"
>/dev/null
with
curl -X POST
--data-urlencode "payload=$payload"
$webhook_url
>/dev/null
and now it works fine.
Just in case anyone else has a similar problem.
GNU sed is not compatible with BSD sed. Didn't check all expressions, but first problem line is
sed ':a;N;$!ba;s/\n/\\n/g'
.
I would suggest you document which hook should trigger this script!
post-receive or post-update or something else?
Hi, I'm pretty new to git. Can you do a quick run through on how to setup a post-receive hook to use this? I have never setup a hook script before.
my config contains ;
in url:
[hooks "slack"]
webhook-url = https://hooks.slack.com/services/
channel = "#git"
repos-root = /srv/git/
changeset-url-pattern = "https://git.local/cgi-bin/gitweb.cgi?p=%repo_path%;a=commitdiff;h=%rev_hash%"
show-full-commit = true
show-only-last-commit = false
username = git
this looks ok if one commit is pushed,
but shows Author Name;;;;;<https://git.local>
when multiple commits are pushed.
i.e all but last commit is ok with push with multiple commits
probably related to #15 being not tested with multiple commits
Using git config
for parameters is a neat approach but it would also be nice if we could have ENVIRONMENT VARIABLE
s as fallback.
in post-receive
< | sed -e 's/\/\\/g' \
| sed -e 's/\\/\\\\\\\\/g' \
fixes it
I've recently set up git-slack-hook on a machine running Debian squeeze. My config looks like this:
[hooks "slack"]
webhook-url = https://hooks.slack.com/services/...
channel = "#notify"
username = Git
icon-emoji = :twisted_rightwards_arrows:
repo-nice-name = testrepo
show-only-last-commit = false
Messages from the hook appear garbled, with all commit messages but the last one smashed together:
GitBOT [12:35]
3 new commits *pushed* to *master* in testrepo
fog;;;;;test: Fix typo in README fog;;;;;test: Modify README fog
----------------
Add script in Python
On my Mac (running OS X 10.10.3), the same configuration works correctly:
GitBOT [12:35]
3 new commits *pushed* to *master* in testrepo
fog
----------------
test: Fix typo in README
fog
----------------
test: Modify README
fog
----------------
Add script in Python
Closed investigation reveals that a certain call to sed
works differently on my Debian machine and on my Mac.
On the Mac (as intended):
mac:testrepo targi$ git log --pretty=format:"%cN;;;;;%s" 27fac..73e2 | sed ':a;N;$!ba;s/\n/\\n/g'
fog;;;;;test: Fix typo in README
fog;;;;;test: Modify README
fog;;;;;Add script in Python
On the Debian machine (problem):
targi@debian:~/tmp/testrepo.git$ git log --pretty=format:"%cN;;;;;%s" 27fac..73e2 | sed ':a;N;$!ba;s/\n/\\n/g'
fog;;;;;test: Fix typo in README\nfog;;;;;test: Modify README\nfog;;;;;Add script in Python
On the Debian machine, I have GNU sed version 4.2.1.
As I don't need full commit messages in the notification, I replaced the call to sed
with a no-op:
-sed ':a;N;$!ba;s/\n/\\n/g'
+sed ':a;N;$!ba;s/\n/\n/g'
This is obviously a work-around (breaks full commit messages). For reference, it's available at targi/git-slack-hook@2148553.
If it's not set, readlink on the remote host throws an error:
Zähle Objekte: 5, Fertig.
Delta compression using up to 4 threads.
Komprimiere Objekte: 100% (5/5), Fertig.
Schreibe Objekte: 100% (5/5), 440 bytes | 0 bytes/s, Fertig.
Total 5 (delta 4), reused 0 (delta 0)
remote: readlink: fehlender Operand
remote: „readlink --help“ liefert weitere Informationen.
To user@host:/home/user/repo.git
bdcbbab..aedc28e master -> master
(sorry for the German text output, but I guess the error is clear anyways)
Currently new lines are seemingly not converted over to \n. This would be very helpful for end user consumption (especially managers) when the notification hits Slack. Thanks.
Would this work with a git repo that is hosted locally? I have this working on a server that I own but I recently started a new project that I'm working on only locally, any chance this could work that way ?
It appears that double-quotes in the commit message are not escaped, which means commit messages with double-quotes aren't properly formatted and are not sent to slack.
Cant seam to get the script to post multi line commits into slack!
Is it supposed to support this?
In the 'Linking to changesets' section of the README.md file, the parameter for the repo's root is listed with an underscore, but it really should be a dash. This is true in the command code block, and in the example description below it.
I think git config hooks.slack.repos_root '/path/to/repos'
should be git config hooks.slack.repos-root '/path/to/repos'
and the mention of 'repos_root' later in the description should also be changed.
Thanks for this helpful script. Just wish to disable the following:
echo " git config hooks.slack.repos-root '/path/to/repos' #optional"
echo " git config hooks.slack.changeset-url-pattern 'http://yourserver/%repo_path%/changeset/%rev_hash%' #optional"
echo " git config hooks.slack.compare-url-pattern 'http://yourserver/%repo_path%/changeset/%old_rev_hash%..%new_rev_hash%' #optional"
echo " git config hooks.slack.branch-regexp 'regexp' #optional"
But I don't know what to do, should I just get rid of these lines in the code or put false as an argument?
Post failed when '&' is included in commit message.
For example, "Erase user.name & user.email" for commit message.
& should be escaped to '%26'.
I am using git to push webapp changes to a simple HTTP staging server, so I wanted the nice-name in Slack to conveniently link to the new live changes. I tried setting hooks.slack.repo-nice-name
to the URL of my staging server but that broke the app (it wouldn't send anything on post-receive).
But! I just discovered that URL-encoding the nice-name works perfectly, and Slack (or some other step in the API chain) conveniently URL-decodes it as well.
For example:
git config hooks.slack.repo-nice-name 'http://127.0.0.1/path/to/page.html'
does not work.
git config hooks.slack.repo-nice-name 'http%3A%2F%2F127.0.0.1%2Fpath%2Fto%2Fpage.html'
works perfectly.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.