Comment on GitHub PR with site changes
This commit is contained in:
1 parent
2380018457
commit
e1063944f6
2 files changed
+35
No files matched your search
@@ -9,6 +9,7 @@ rm -f "$STATE" && touch "$STATE"
|
|||||||
|
|
||||||
if [ -n "$CI_PULL_REQUEST" -a "$CI_PULL_REQUEST" = "$CI_PULL_REQUESTS" ] ; then
|
if [ -n "$CI_PULL_REQUEST" -a "$CI_PULL_REQUEST" = "$CI_PULL_REQUESTS" ] ; then
|
||||||
if PR=$(echo "$CI_PULL_REQUEST" | grep -oP '(?<=^https://github.com/weaveworks/weave/pull/)[0-9]+$') ; then
|
if PR=$(echo "$CI_PULL_REQUEST" | grep -oP '(?<=^https://github.com/weaveworks/weave/pull/)[0-9]+$') ; then
|
||||||
|
echo "GH_PR=$PR" >> "$STATE"
|
||||||
if FILES=$(curl -s https://api.github.com/repos/weaveworks/weave/pulls/$PR/files | jq -r '.[]|.filename') ; then
|
if FILES=$(curl -s https://api.github.com/repos/weaveworks/weave/pulls/$PR/files | jq -r '.[]|.filename') ; then
|
||||||
echo "PR touches [$FILES]"
|
echo "PR touches [$FILES]"
|
||||||
if ! echo "$FILES" | grep -v ^site/ ; then
|
if ! echo "$FILES" | grep -v ^site/ ; then
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
set -o pipefail
|
||||||
|
|
||||||
source "$STATE"
|
source "$STATE"
|
||||||
|
|
||||||
@@ -12,3 +13,36 @@ go get
|
|||||||
|
|
||||||
cd $SRCDIR
|
cd $SRCDIR
|
||||||
bin/publish-site "$WP_DEV_URL" "$WP_DEV_USER" "$WP_DEV_PASSWORD"
|
bin/publish-site "$WP_DEV_URL" "$WP_DEV_USER" "$WP_DEV_PASSWORD"
|
||||||
|
|
||||||
|
site_changes() {
|
||||||
|
curl -s https://api.github.com/repos/weaveworks/weave/pulls/$1/files |
|
||||||
|
jq -r '.[]|.status + " " + .filename' |
|
||||||
|
grep -oP '^(added|modified|removed) site/.*(?=\.md$)'
|
||||||
|
}
|
||||||
|
|
||||||
|
format_comment() {
|
||||||
|
if [ ! -d .git ] || ! BRANCH=$(git symbolic-ref --short HEAD) || [ -z "$BRANCH" ] ; then
|
||||||
|
echo "Could not determine branch" >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "#### Documentation changes:"
|
||||||
|
while read ACTION PAGE; do
|
||||||
|
echo "$ACTION [${PAGE#site/}]($WP_DEV_URL/docs/net/${BRANCH#issues/}/${PAGE#site/}/)"
|
||||||
|
done | sort
|
||||||
|
}
|
||||||
|
|
||||||
|
post_comment() {
|
||||||
|
jq -s -R '. | tostring | { body: . }' |
|
||||||
|
curl -s -d @- \
|
||||||
|
-H "Authorization: Bearer $WP_GH_COMMENT_TOKEN" \
|
||||||
|
-H 'Content-Type: application/json' \
|
||||||
|
https://api.github.com/repos/weaveworks/weave/issues/$GH_PR/comments > /dev/null
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ -n "$WP_GH_COMMENT_TOKEN" -a -n "$GH_PR" ] ; then
|
||||||
|
echo ">>> Adding doc changelog to GitHub PR $GH_PR"
|
||||||
|
if CHANGES=$(site_changes $GH_PR) && [ -n "$CHANGES" ] ; then
|
||||||
|
echo "$CHANGES" | format_comment | post_comment
|
||||||
|
fi
|
||||||
|
fi
|
||||||
Reference in new issue
Block a user