#!/bin/sh

url() {
  local mrId="$1"
  echo "https://lily-is.land/kazv/libkazv/-/merge_requests/$mrId"
}

collectType() {
    local suffix="$1"
    local header="$2"
    local printed=0
    local mrId=
    for file in changelogs/*."$suffix"; do
        if [ '!' -f "$file" ]; then
            continue
        fi
        if [ "$printed" = 0 ]; then
            echo
            echo "### $header"
            printed=1
        fi
        # Normalize any trailing newlines/spaces, etc.
        mrId="$(basename "$file" ".$suffix")"
        echo "- $(cat "$file"). $(url "$mrId")"
    done
}

collectType security Security
collectType add Added
collectType fix Fixed
collectType remove Removed

rm changelogs/*
