Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(TECH): ecr scan results fix #2

Merged
merged 6 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
amohamedhey marked this conversation as resolved.
Show resolved Hide resolved
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"
Expand Down
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