From 84a7e97cd0847da7aa1c2cdc43ee438765a4c462 Mon Sep 17 00:00:00 2001 From: Steven Quan <70890758+stevenquanheycar@users.noreply.github.com> Date: Fri, 22 Mar 2024 09:48:57 +0000 Subject: [PATCH] fix(TECH): ecr scan results fix (#2) * fix(TECH): ecr scan results fix * missing curl * fixing whitespace * Update Dockerfile * Update Dockerfile * fix: fixed some issues with script and dependencies --------- Co-authored-by: Abdalaziz Mohamed <89922655+amohamedhey@users.noreply.github.com> Co-authored-by: Youssef Dhraief --- Dockerfile | 4 +++- scripts/gh-utils.sh | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 9705431..c9472f3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,12 +6,14 @@ ARG BASH_VERSION="5" ARG AWS_CLI_VERSION="2" ARG JQ_VERSION="1" ARG CURL_VERSION="8" +ARG GIT_VERSION="2" +ARG GITHUB_CLI_VERSION="2" WORKDIR /scripts RUN apk update --no-cache; \ apk upgrade --no-cache; \ - apk add --no-cache bash~=${BASH_VERSION} aws-cli~=${AWS_CLI_VERSION} jq~=${JQ_VERSION} curl~=${CURL_VERSION} ; \ + apk add --no-cache bash~=${BASH_VERSION} aws-cli~=${AWS_CLI_VERSION} jq~=${JQ_VERSION} curl~=${CURL_VERSION} git~=${GIT_VERSION} github-cli~=${GITHUB_CLI_VERSION}; \ rm -rf /var/cache/apk/* ENV LOG_LEVEL "INFO" diff --git a/scripts/gh-utils.sh b/scripts/gh-utils.sh index 036ff1e..d30eff8 100644 --- a/scripts/gh-utils.sh +++ b/scripts/gh-utils.sh @@ -1,5 +1,31 @@ #!/usr/bin/env bash +function get_formatted_comment_id() { + _comment_id="${1}" + echo "" +} + +# 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}"