I am trying to filter the Pull Requests in Github If particular PR is there we don't need to create PR for that I have included below code but its saying error line 61: syntax error: unexpected end of file
Usual PR name should be like = Checking drift in the resource: $RESOURCE
echo "Checking if a pull request for '$RESOURCE' already exists"
existing_pr=$(curl -s -H "Authorization: Bearer $(pat-token)" \
https://github.mytab.com/api/v3/repos/rep/rep-infra/pulls?state=open&head=drift-rep-${RESOURCE} \
| jq '.[] | select(.title | test("Checking drift in the resource: '"$RESOURCE"'"))')
if [ -n "$existing_pr" ]; then
echo "Pull request already exists for '$RESOURCE'. Skipping PR creation."
else
echo "Creating Pull Request now"
Is any wrong with logic ?
Possibly fatal bugs:
fi
after an if
.&
in an unquoted string."$RESOURCE"
in the jq
command is not going to appear in double quotes to jq.Other considerations:
jq
has an --exit-status
flag that is probably more suitable than [ -n "$existing_pr" ]
.RESOURCE
into jq
as a variable.gh
for this?Perhaps:
echo "Checking if a pull request for '$RESOURCE' already exists"
gh_token=$(pat-token)
url="https://github.mytab.com/api/v3/repos/rep/rep-infra/pulls?state=open&head=drift-rep-${RESOURCE}"
jq='.[] |
select(.title |
test("Checking drift in the resource: $resource"))'
json=$(curl -sfH "Authorization: Bearer $gh_token" "$url")
if jq --exit-status --arg resource "$RESOURCE" "$jq"; then
echo "Pull request already exists for '$RESOURCE'. Skipping PR creation."
else
echo 'Creating Pull Request now'
fi