Skip to content

Commit

Permalink
fix security code scanning notes
Browse files Browse the repository at this point in the history
Change-Id: I2c594c6ee498de1969c5fc9fdd52270550016351
Signed-off-by: AbdAlMoniem AlHifnawy <[email protected]>
  • Loading branch information
abdalmoniem committed Dec 8, 2024
1 parent ae8199c commit 604abdc
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 31 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,4 +287,4 @@ size of the subtext and move it to the left until it is inside the radius.

### 3. Finally, I draw the subtext on the canvas.

</details>
</details>
50 changes: 25 additions & 25 deletions git_hooks/get_changelog.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
gitTopLevel="$(git rev-parse --show-toplevel)"
versionCodeFilter="\(versionCode\s\+=\s\+\)\([[:digit:]]\+\)"
previousTag=$(git tag | sort | tail -n 2 | head -n 1)
latestTag=$(git describe --tags $(git rev-list --tags --max-count=1))
commitHashesBetweenTags=$(git log $previousTag..$latestTag --pretty=format:"%H")
latestTag=$(git describe --tags "$(git rev-list --tags --max-count=1)")
commitHashesBetweenTags=$(git log "$previousTag".."$latestTag" --pretty=format:"%H")
commitHashCount=$(echo "$commitHashesBetweenTags" | wc -l)
previousVersionCode=$(git show "$previousTag:app/build.gradle.kts" | grep versionCode | sed -e "s/$versionCodeFilter/\2/" | xargs)
latestVersionCode=$(git show "$tag:app/build.gradle.kts" | grep versionCode | sed -e "s/$versionCodeFilter/\2/" | xargs)
latestVersionCode=$(git show "$latestTag:app/build.gradle.kts" | grep versionCode | sed -e "s/$versionCodeFilter/\2/" | xargs)
changelogsPath="$gitTopLevel/changelogs"
changelogs=0
subjects=()
Expand All @@ -27,22 +27,22 @@ if [ ! -d "$changelogsPath" ]; then
mkdir -p "$changelogsPath"
fi

if [ $commitHashCount -gt 0 ] && [ -f "$changelogsPath/$latestVersionCode.txt" ]; then
if [ "$commitHashCount" -gt 0 ] && [ -f "$changelogsPath/$latestVersionCode.txt" ]; then
echo "'$changelogsPath/$latestVersionCode.txt' already exists, deleting..."
rm "$changelogsPath/$latestVersionCode.txt"
fi

echo "Generating Changelog between $previousTag and $latestTag..."
for commitHash in $commitHashesBetweenTags
do
subject=$(git log --format=%s -n 1 $commitHash | sed -e 's/Change-Id:\s*.*//' | sed -e 's/Signed-off-by:\s*.*//' | sed -e 's/^[^a-zA-Z0-9]*//')
body=$(git log --format=%b -n 1 $commitHash | sed -e 's/Change-Id:\s*.*//' | sed -e 's/Signed-off-by:\s*.*//' | sed -e 's/^[^a-zA-Z0-9]*//')
subject=$(git log --format=%s -n 1 "$commitHash" | sed -e 's/Change-Id:\s*.*//' -e 's/Signed-off-by:\s*.*//' -e 's/^[^a-zA-Z0-9]*//')
body=$(git log --format=%b -n 1 "$commitHash" | sed -e 's/Change-Id:\s*.*//' -e 's/Signed-off-by:\s*.*//' -e 's/^[^a-zA-Z0-9]*//')

subjects+=("$subject")
bodies+=("$body")
changelogs=${#subjects[@]}

if [ $changelogs -eq 1 ]; then
if [ "$changelogs" -eq 1 ]; then
echo "saving to '$changelogsPath/$latestVersionCode.txt'..."
fi

Expand All @@ -53,41 +53,41 @@ do
lineCount=${#lines[@]}
for line in "${lines[@]}"; do
if [[ -n "$line" ]]; then
if [ $lineCount -gt 1 ]; then
if [ "$lineCount" -gt 1 ]; then
echo " > - $line" | tee -a "$changelogsPath/$latestVersionCode.txt"
else
echo " > $line" | tee -a "$changelogsPath/$latestVersionCode.txt"
fi
else
if [ $lineCount -eq 1 ]; then
if [ "$lineCount" -eq 1 ]; then
echo " >" | tee -a "$changelogsPath/$latestVersionCode.txt"
fi
fi
done
echo "------------------------------"
done

if [ $changelogs -gt 0 ]; then
if [ "$changelogs" -gt 0 ]; then
echo "$changelogs changelog(s) saved to '$changelogsPath/$latestVersionCode.txt'!"
echo | tee -a "$changelogsPath/$latestVersionCode.txt"
echo "**Full Changelog**: https://github.com/abdalmoniem/CircularDurationView/compare/$previousTag...$latestTag" |\
tee -a "$changelogsPath/$latestVersionCode.txt"

currentCommitHash=$(git rev-parse HEAD)
isCurrentCommitOnRemote=$(git branch -r --contains "$currentCommitHash")
if [ -n "$isCurrentCommitOnRemote" ]; then
echo "commit '$currentCommitHash' is on the remote branch, creating a new change log commit..."
echo

git add "$changelogsPath/"
git commit -sm "updated $changelogs change log(s)"
else
echo "commit '$currentCommitHash' is not on the remote branch, amending..."
echo

git add "$changelogsPath/"
git commit --amend --no-edit
fi
# currentCommitHash=$(git rev-parse HEAD)
# isCurrentCommitOnRemote=$(git branch -r --contains "$currentCommitHash")
# if [ -n "$isCurrentCommitOnRemote" ]; then
# echo "commit '$currentCommitHash' is on the remote branch, creating a new change log commit..."
# echo
#
# git add "$changelogsPath/"
# git commit -sm "updated $changelogs change log(s)"
# else
# echo "commit '$currentCommitHash' is not on the remote branch, amending..."
# echo
#
# git add "$changelogsPath/"
# git commit --amend --no-edit
# fi
else
echo "No / $changelogs change log(s) found between $previousTag and $latestTag"
fi
2 changes: 1 addition & 1 deletion git_hooks/post_tag.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ update_publish_release_yaml_file_and_add_tag() {
fi

scriptDir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd -P)
sh $scriptDir/get_changelog.sh
sh "$scriptDir/get_changelog.sh"

else
echo "ERROR: file $publishReleaseYaml not found"
Expand Down
17 changes: 13 additions & 4 deletions git_hooks/update_changelogs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,19 @@
gitTopLevel="$(git rev-parse --show-toplevel)"
versionCodeFilter="\(versionCode\s\+=\s\+\)\([[:digit:]]\+\)"
changelogsPath="$gitTopLevel/changelogs"
tags=($(git tag))
mapfile -t tags < <(git tag)
changelogs=0

isWriteChanges=false
isCommitChanges=false

help() {
echo "Usage: $0 [--write_changes] [--commit_changes]"
echo "Options:"
echo " --write_changes Write changes to changelogs folder"
echo " --commit_changes Commit changes to changelogs folder"
}

# Parse command-line flags
while [[ $# -gt 0 ]]; do
case "$1" in
Expand All @@ -20,9 +27,13 @@ while [[ $# -gt 0 ]]; do
isCommitChanges=true
shift # Move to the next argument
;;
--help)
help
exit 0
;;
*)
echo "Unknown option: $1"
echo "Usage: $0 [--write_changes] [--commit_changes]"
help
exit 1
;;
esac
Expand Down Expand Up @@ -73,8 +84,6 @@ if [[ $changelogs -gt 0 && "$isCommitChanges" == true ]]; then
echo

if [ -n "$isCurrentCommitOnRemote" ]; then
newVersionName="${newTag#v}"

echo "commit '$currentCommitHash' is on the remote branch, creating a new change log commit..."
echo

Expand Down

0 comments on commit 604abdc

Please sign in to comment.