deleteOldComments.sh 966 B

123456789101112131415161718192021222324252627
  1. #!/usr/bin/env bash
  2. #1: BRANCH
  3. #2: TYPE
  4. #3: PR
  5. #4: GITHUB_TOKEN
  6. BRANCH=$1
  7. TYPE=$2
  8. PR=$3
  9. GITHUB_TOKEN=$4
  10. BRANCH_TYPE=$BRANCH-$TYPE
  11. # delete all old comments, matching this type
  12. echo "Deleting old comments for $BRANCH_TYPE"
  13. oldComments=$(curl 2>/dev/null --header "authorization: Bearer $GITHUB_TOKEN" -X GET https://api.github.com/repos/nextcloud/android/issues/$PR/comments | jq --arg TYPE $BRANCH_TYPE '.[] | (.id |tostring) + "|" + (.user.login | test("(nextcloud-android-bot|github-actions)") | tostring) + "|" + (.body | test([$TYPE]) | tostring)'| grep "true|true" | tr -d "\"" | cut -f1 -d"|")
  14. count=$(echo -n "$oldComments" | grep -c '^')
  15. echo "Found $count old comments"
  16. if [ "$count" -gt 0 ]; then
  17. echo "$oldComments" | while read comment ; do
  18. echo "Deleting comment: $comment"
  19. curl 2>/dev/null --header "authorization: Bearer $GITHUB_TOKEN" -X DELETE https://api.github.com/repos/nextcloud/android/issues/comments/$comment
  20. done
  21. fi
  22. exit 0