features_types=(chore feat style)
changes_types=(refactor perf)
fix_types=(fix revert)
file="CHANGELOG.md"
file_tmp="temp_log.txt"
file_current_tmp="temp_current_log.txt"

setType(){
    echo "### $1" >> $file_tmp
    arr=("$@")
    echo "" > $file_current_tmp
    for i in "${arr[@]}"
    do
        git log --grep="$i" --oneline --no-merges --format="- %s %d by:%an" master..test >> $file_current_tmp
    done
    # remove duplicates
    sort -o $file_current_tmp -u $file_current_tmp
    cat $file_current_tmp >> $file_tmp
    echo "" >> $file_tmp
    # remove tmp current file
    [ -e $file_current_tmp ] && rm $file_current_tmp
}

echo "# Version XX.XX - XXXX-XX-XX" >> $file_tmp
echo "" >> $file_tmp

setType "Added 🆕" "${features_types[@]}"
setType "Changed 📦" "${changes_types[@]}"
setType "Fixed 🛠️" "${fix_types[@]}"

cat $file >> $file_tmp
mv $file_tmp $file


