mirror of
https://github.com/nextcloud/android.git
synced 2024-11-28 18:28:59 +03:00
scripts: Fix deleteOldComments.sh
* Get comments from github-actions, not only our android bot * Fix count (was broken for 0 comments) and only try to delete if count > 0 Signed-off-by: Álvaro Brey Vilas <alvaro.brey@nextcloud.com>
This commit is contained in:
parent
6c176c4802
commit
ab692d92a7
1 changed files with 12 additions and 13 deletions
|
@ -1,11 +1,8 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
#1: LOG_USERNAME
|
#1: BRANCH
|
||||||
#2: LOG_PASSWORD
|
#2: TYPE
|
||||||
#3: DRONE_BUILD_NUMBER
|
#3: PR
|
||||||
#4: BRANCH (stable or master)
|
#4: GITHUB_TOKEN
|
||||||
#5: TYPE (IT or Unit)
|
|
||||||
#6: DRONE_PULL_REQUEST
|
|
||||||
#7: GITHUB_TOKEN
|
|
||||||
|
|
||||||
BRANCH=$1
|
BRANCH=$1
|
||||||
TYPE=$2
|
TYPE=$2
|
||||||
|
@ -16,13 +13,15 @@ BRANCH_TYPE=$BRANCH-$TYPE
|
||||||
|
|
||||||
# delete all old comments, matching this type
|
# delete all old comments, matching this type
|
||||||
echo "Deleting old comments for $BRANCH_TYPE"
|
echo "Deleting old comments for $BRANCH_TYPE"
|
||||||
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"|")
|
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"|")
|
||||||
count=$(echo $oldComments | grep true | wc -l)
|
count=$(echo -n "$oldComments" | grep -c '^')
|
||||||
echo "Found $count old comments"
|
echo "Found $count old comments"
|
||||||
|
|
||||||
echo $oldComments | while read comment ; do
|
if [ "$count" -gt 0 ]; then
|
||||||
echo "Deleting comment: $comment"
|
echo "$oldComments" | while read comment ; do
|
||||||
curl 2>/dev/null --header "authorization: Bearer $GITHUB_TOKEN" -X DELETE https://api.github.com/repos/nextcloud/android/issues/comments/$comment
|
echo "Deleting comment: $comment"
|
||||||
done
|
curl 2>/dev/null --header "authorization: Bearer $GITHUB_TOKEN" -X DELETE https://api.github.com/repos/nextcloud/android/issues/comments/$comment
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|
Loading…
Reference in a new issue