Skip to content

Commit

Permalink
fix: fixed some issues with script and dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
piximos committed Mar 22, 2024
1 parent 314cd77 commit c3ff65a
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions scripts/gh-utils.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
#!/usr/bin/env bash

function get_formatted_comment_id() {
_comment_id="${1}"
echo "<!-- comment-id:${_comment_id} -->"
}

# The `delete_previous_comments` function deletes comments by their ids from pull requests.
function delete_previous_comments() {
_repo_org="${1}"
_repo_name="${2}"
_pr_number="${3}"

_nextPage="1"
while [[ "${_nextPage}" != "0" ]]; do
_comments="$(gh api "/repos/${_repo_org}/${_repo_name}/issues/${_pr_number}/comments?direction=asc&per_page=20&page=${_nextPage}")"
if [[ "$(echo "${_comments}" | jq '.|length')" == 0 ]]; then
_nextPage="0"
else
_nextPage="$((_nextPage + 1))"
fi
while read -r _previous_comment_id; do
log_out "Deleting previous comment with ID: ${_previous_comment_id}"
gh api "/repos/${_repo_org}/${_repo_name}/issues/comments/${_previous_comment_id}" -X DELETE >/dev/null
done < <(echo "${_comments}" | jq ".[] | select(.body|startswith(\"$(get_formatted_comment_id "${_comment_id}")\")) | .id")
done
}

# The `comment_on_pull_request` function pushes a comment to a pull request.
function comment_on_pull_request() {
_repo_org="${1}"
Expand Down

0 comments on commit c3ff65a

Please sign in to comment.