Skip to content

Instantly share code, notes, and snippets.

@manekinekko
Created November 13, 2018 13:15
Show Gist options
  • Save manekinekko/10e361b9839237ad7887917f4ac7a41c to your computer and use it in GitHub Desktop.
Save manekinekko/10e361b9839237ad7887917f4ac7a41c to your computer and use it in GitHub Desktop.
Create a comment on the xlayers/xlayers GitHub project, using the GraphQL API
#!/bin/bash
set -u
access_token=$GITHUB_ACCESS_TOKEN
subject_json=$(curl --url "https://api.github.com/graphql?access_token=$access_token" \
--header 'content-type: application/json' \
--data "{ \"query\": \"{ search(first: 1, type: ISSUE, query: \\\"type:pr repo:xlayers/xlayers $COMMIT_SHA\\\") { nodes { ... on PullRequest { id, number, title } } } }\" }")
# extract the subject ID from the JSON string using Python's JSON module
subject_id=`echo $subject_json | python -c 'import sys, json; print json.load(sys.stdin)["data"]["search"]["nodes"][0]["id"]'`
if [ $? -eq 1 ]; then
echo "Could not get Subject ID. Abort."
exit 0;
fi
body="☸️ Build auto-deployed at: $PREVIEW_BUILD_URL"
curl --url "https://api.github.com/graphql?access_token=$access_token" \
--header 'content-type: application/json' \
--data "{ \"query\": \"mutation AddCommentToIssue { addComment(input: {subjectId: \\\"$subject_id\\\", body: \\\"$body\\\"}) { clientMutationId } }\" }"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment