deleteOldComments.sh 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. #!/usr/bin/env bash
  2. #1: BRANCH
  3. #2: TYPE
  4. #3: PR
  5. # SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  6. # SPDX-FileCopyrightText: 2016 Tobias Kaminsky <tobias@kaminsky.me>
  7. # SPDX-License-Identifier: AGPL-3.0-or-later OR GPL-2.0-only
  8. BRANCH=$1
  9. TYPE=$2
  10. PR=$3
  11. source scripts/lib.sh
  12. BRANCH_TYPE=$BRANCH-$TYPE
  13. # delete all old comments, matching this type
  14. echo "Deleting old comments for $BRANCH_TYPE"
  15. 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"|")
  16. count=$(echo -n "$oldComments" | grep -c '^')
  17. echo "Found $count old comments"
  18. if [ "$count" -gt 0 ]; then
  19. echo "$oldComments" | while read comment ; do
  20. echo "Deleting comment: $comment"
  21. curl_gh -X DELETE https://api.github.com/repos/nextcloud/android/issues/comments/$comment
  22. done
  23. fi
  24. exit 0