Skip to content

Commit

Permalink
Merge pull request #3335 from mopi3456/new-teams-webhook
Browse files Browse the repository at this point in the history
New teams webhook
  • Loading branch information
robertcheramy authored Feb 10, 2025
2 parents 11693d1 + 0e2ee34 commit 35ddd43
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
- cumulus: remove ANSI Escape codes and fix prompt issues. The prompt is more specific now (@alchemyx, @robertcheramy)
- model unit tests: the tests are automated and simpler to use (@ytti, @robertcheramy)
- device2yaml.rb: moved to extra/, commands can be specified from the command line or from a file (no cmdsets provided anymore) (@robertcheramy)
- extra/gitdiff-msteams.sh: honor the 28KB size limit and add an optional link to GitHub (@mopi3456)

### Fixed
- tplink: send 'enable' before the enable password. Fixes #3271 (@robertcheramy)
Expand Down
37 changes: 32 additions & 5 deletions extra/gitdiff-msteams.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,31 @@
# timeout: 120
#
# Add webhook to your MS Teams channel and set the next variable to the full url
# If INCLUDE_GITHUB_LINK is set to true, there will be a button that links to GITURL in the bottom of each teams post. the commit id is added at the end of the url.
# MAXSIZE is set to respect the 28 KB limit for teams webhooks, but you might need to change it if you modify the Adaptive Card

weburl="https://contoso.webhook.office.com/webhookb2/etc etc etc"
GITURL="https://github.example.com/My-org/oxidized/commit/"
INCLUDE_GITHUB_LINK=false
# Max size for summary text.
MAXSIZE=24500

if [ "$INCLUDE_GITHUB_LINK" = true ]; then
github_action=",
{ \"type\": \"ActionSet\",
\"actions\":
[
{
\"type\": \"Action.OpenUrl\",
\"title\": \"Click to see diff in github\",
\"url\": \"${GITURL}${OX_REPO_COMMITREF}\"
}
]
}"
fi

postdata()
{
COMMIT=$(git --bare --git-dir="${OX_REPO_NAME}" show --pretty='' --no-color "${OX_REPO_COMMITREF}" | jq --raw-input --slurp --compact-output)
cat <<EOF
{
"type":"message",
Expand Down Expand Up @@ -77,7 +96,7 @@ postdata()
"size": "small"
}
]
}
}${github_action}
]
}
}
Expand All @@ -86,6 +105,14 @@ postdata()
EOF
}

curl -i \
-H "Content-Type: application/json" \
-X POST --data "$(postdata)" "${weburl}"
COMMIT=$(git --bare --git-dir="${OX_REPO_NAME}" show --pretty='' --no-color "${OX_REPO_COMMITREF}" | jq --raw-input --slurp --compact-output)
URL=""

size=$(postdata | wc -c)
if [ "$size" -gt "$MAXSIZE" ]; then
COMMIT=$(git --bare --git-dir="${OX_REPO_NAME}" show --pretty='' --no-color "${OX_REPO_COMMITREF}" | head -c $MAXSIZE)
COMMIT+="$NEWLINE...$NEWLINE Shortened because of length"
COMMIT=$(echo "${COMMIT}" | jq --raw-input --slurp --compact-output )
fi

curl -i -H "Content-Type: application/json" -X POST --data "$(postdata)" "${weburl}"

0 comments on commit 35ddd43

Please sign in to comment.