2018-10-16 21:28:15 +02:00
#!/bin/bash
PR_NR = $TRAVIS_PULL_REQUEST
function performQuery( ) {
NEW_QUERY_STR = " {\"query\":\" $1 \"} "
2018-10-16 21:41:47 +02:00
echo $NEW_QUERY_STR
curl -s -H " Authorization: bearer $COMMENT_TOKEN " -X POST -d " $NEW_QUERY_STR " https://api.github.com/graphql
2018-10-16 21:28:15 +02:00
}
RESULT = $( performQuery " {repository(owner:\\\"ZeusWPI\\\",name:\\\"zeus.ugent.be\\\"){pullRequest(number: $PR_NR ){id,comments(first:10){nodes{author{login}}}}}} " )
if [ $? -ne 0 ] ; then
echo " QUERY FAILED, RESULT: $RESULT "
exit 1
fi
# Get the GraphQL ID
PR_ID = $( echo $RESULT | sed 's/.*"id":"\([^"]*\)".*/\1/' )
2019-03-08 02:46:06 +01:00
if [ [ $RESULT = = *"zeuswpi-bot" * ] ] ; then
2018-10-16 21:28:15 +02:00
echo "User has already commented"
else
ADD_COMMENT_STR = " mutation{addComment(input:{subjectId:\\\" $PR_ID \\\",body:\\\"Check out the preview on https:// $PR_NR .pr.zeus.gent/\\\"}){clientMutationId}} "
2018-10-16 21:41:47 +02:00
performQuery " $ADD_COMMENT_STR "
2018-10-16 21:28:15 +02:00
fi