deleteOldComments.sh 844 B

123456789101112131415161718192021222324252627
  1. #!/usr/bin/env bash
  2. #1: BRANCH
  3. #2: TYPE
  4. #3: PR
  5. BRANCH=$1
  6. TYPE=$2
  7. PR=$3
  8. source scripts/lib.sh
  9. BRANCH_TYPE=$BRANCH-$TYPE
  10. # delete all old comments, matching this type
  11. echo "Deleting old comments for $BRANCH_TYPE"
  12. oldComments=$(curl_gh -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"|")
  13. count=$(echo -n "$oldComments" | grep -c '^')
  14. echo "Found $count old comments"
  15. if [ "$count" -gt 0 ]; then
  16. echo "$oldComments" | while read comment ; do
  17. echo "Deleting comment: $comment"
  18. curl_gh -X DELETE https://api.github.com/repos/nextcloud/android/issues/comments/$comment
  19. done
  20. fi
  21. exit 0