Microsoft Teams Git Push Notifier
source link: https://www.tuicool.com/articles/hit/7jIjUzi
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Microsoft Teams Git Push Notifier
This small Git hook notifies a Microsoft Teams channel as soon as a push is done to a certain remote branch. It can be used to cover the common scenario where a particular remmote branch is used to trigger a project build/deployment using a CI/CD platform such as TeamCity or Jenkins. We chose to provide this feature as a pre-push
hook instead of a post-update
or similar because not all Git services support server side hooks. Of course, the CI scenario is optional. You can use this hook just to notify your team whenever changes get pushed to a remote branch so that e.g. other team members can simply pull them.
Setting Up
First of all, you will need to set up an Incoming Webhook connector on your Microsoft Teams channel. You can choose to use a single channel for all such updates, or have a separate channel per project. In any case you will need to set up a custom incoming webhook on your channel(s). As soon as you have done this, for each of your Git repositories you wish to monitor, you will need to:
-
Copy the contents of the
src
directory into your.git/hooks
directory (make sure you don't already have apre-push
hook in place); -
Make sure the
.git/hooks/pre-push
file has execute permissions (you canchmod 774 .git/hooks/pre-push
frombash
to make sure of this); -
In folder
.git/hooks/pre-push.d
create aconfig.js
file using theconfig.js.sample
file as an example; -
In folder
.git/hooks/pre-push.d
runnpm install
.
Configuring
The config.js
file has the following options:
-
projectName
(string): you should put the name of your project here, as it will appear on the Teams message card -
hardFail
(boolean): iftrue
, push will fail if the Teams channel cannot be notified -
themeColor
(hex color): the theme color of the Teams message card (the colored stripe appearing on its left) -
activityImageUrl
(url, optional): the URL to an image that gets displayed to the left of the Teams message card title -
webHookUrl
(url): the webhook URL obtained when you created the connector on your Teams channel -
triggers
(array): a list of triggers (described below) - when any one of them fires, the Teams channel is notified
Each trigger can have three fields:
remote branchName detailsUrl
The trigger fires whenever a push is done to its remote
for branch branchName
.
License
The project is licensed under the MIT license. See the LICENSE file for details.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK