deleteOldComments.sh 1.0 KB

12345678910111213141516171819202122232425262728
  1. #!/usr/bin/env bash
  2. #1: LOG_USERNAME
  3. #2: LOG_PASSWORD
  4. #3: DRONE_BUILD_NUMBER
  5. #4: BRANCH (stable or master)
  6. #5: TYPE (IT or Unit)
  7. #6: DRONE_PULL_REQUEST
  8. #7: GITHUB_TOKEN
  9. BRANCH=$1
  10. TYPE=$2
  11. PR=$3
  12. GITHUB_USER=$4
  13. GITHUB_PASSWORD=$5
  14. BRANCH_TYPE=$BRANCH-$TYPE
  15. # delete all old comments, matching this type
  16. echo "Deleting old comments for $BRANCH_TYPE"
  17. 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") | tostring) + "|" + (.body | test([$TYPE]) | tostring)'| grep "true|true" | tr -d "\"" | cut -f1 -d"|")
  18. count=$(echo $oldComments | grep true | wc -l)
  19. echo "Found $count old comments"
  20. echo $oldComments | while read comment ; do
  21. echo "Deleting comment: $comment"
  22. curl 2>/dev/null --header "authorization: Bearer $GITHUB_TOKEN" -X DELETE https://api.github.com/repos/nextcloud/android/issues/comments/$comment
  23. done
  24. exit 0