Skip to content

Commit

Permalink
Now calls PR API
Browse files Browse the repository at this point in the history
Always work with latest information.
Also, we are now dependent on the token, to be provided as action input.
  • Loading branch information
ParanoidBeing committed Apr 3, 2020
1 parent a0a595f commit a1f6f1b
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,39 @@

set -e

#Making sure we have the token
if [[ -z "$GITHUB_TOKEN" ]]; then
echo "Set the GITHUB_TOKEN env variable."
exit 1
fi

# skip if not a PR
echo "Checking if a PR command..."
(jq -r ".pull_request.url" "$GITHUB_EVENT_PATH") || exit 78

title=$(jq -r ".pull_request.title" "$GITHUB_EVENT_PATH")
labels=$(jq -r ".pull_request.labels" "$GITHUB_EVENT_PATH")
#Setting Required Headers
API_HEADER="Accept: application/vnd.github.v3+json; application/vnd.github.antiope-preview+json"
AUTH_HEADER="Authorization: token ${GITHUB_TOKEN}"

#Extracting pull request number
number=$(jq -r ".pull_request.number" "$GITHUB_EVENT_PATH")

#Calling the PR API to fetch latest info
#If the action had intially failed due to addition of a label or editing the title, it should pass if manually re-triggered
#later on, so we need to always work on the latest information.
RESPONSE=$(curl -s \
-H "Content-Type: application/json" \
-H "${AUTH_HEADER}" \
-H "${API_HEADER}" \
"https://api.github.com/repos/${GITHUB_REPOSITORY}/pulls/${number}")


#Extracting Title & Lables
title=$(jq ".title" <<< "$RESPONSE")
labels=$(jq ".labels" <<< "$RESPONSE")

#Block if suspect words are found.
#Todo - words to be provided as action input.
checkForBlockingWords(){
if echo "${1} ${2}" | grep -iE 'WIP|do not merge|backend not live'
then
Expand Down

0 comments on commit a1f6f1b

Please sign in to comment.