|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# This script generates a collaborator list for every module repository listed |
| 4 | +# as `West project` in the Zephyr MAINTAINERS.yml file. |
| 5 | + |
| 6 | +set -e |
| 7 | + |
| 8 | +usage() |
| 9 | +{ |
| 10 | + echo "Usage $(basename $0) maintainers_file manifest_path" |
| 11 | +} |
| 12 | + |
| 13 | +# Validate and prase arguments |
| 14 | +if [ "$1" == "" ]; then |
| 15 | + usage |
| 16 | + echo |
| 17 | + echo "maintainers_file must be specified." |
| 18 | + exit 1 |
| 19 | +elif [ "$2" == "" ]; then |
| 20 | + usage |
| 21 | + echo |
| 22 | + echo "manifest_path must be specified." |
| 23 | + exit 1 |
| 24 | +fi |
| 25 | + |
| 26 | +maintainers_file=$1 |
| 27 | +manifest_path=$2 |
| 28 | + |
| 29 | +if [ ! -f "${maintainers_file}" ]; then |
| 30 | + echo "'${maintainers_file}' does not exist." |
| 31 | + exit 2 |
| 32 | +fi |
| 33 | + |
| 34 | +if [ ! -d "${manifest_path}" ]; then |
| 35 | + echo "'${manifest_path}' is not a valid directory." |
| 36 | +fi |
| 37 | + |
| 38 | +# Read and validate maintainers file. |
| 39 | +maintainers_data=$(<${maintainers_file}) |
| 40 | + |
| 41 | +echo "${maintainers_data}" | yq &> /dev/null || ( |
| 42 | + echo "'${maintainers_file}' is not a valid YAML file." |
| 43 | + exit 10 |
| 44 | +) |
| 45 | + |
| 46 | +# Get the maintainer data for modules (aka. west projects) |
| 47 | +readarray module_maintainer_entries < <(echo "${maintainers_data}" | |
| 48 | + yq -r -o=j -I=0 'with_entries(select(.key == "West project: *")) | to_entries()[]') |
| 49 | + |
| 50 | +for module_maintainer_entry in "${module_maintainer_entries[@]}"; do |
| 51 | + # Get entry data |
| 52 | + name=$(echo "${module_maintainer_entry}" | |
| 53 | + jq -r '.key | sub("West project: "; "")') |
| 54 | + maintainers=$(echo "${module_maintainer_entry}" | |
| 55 | + jq -r 'try .value.maintainers[]') |
| 56 | + collaborators=$(echo "${module_maintainer_entry}" | |
| 57 | + jq -r 'try .value.collaborators[]') |
| 58 | + |
| 59 | + echo "Processing ${name}" |
| 60 | + |
| 61 | + # Write repositoy member list |
| 62 | + collab_list_file="${manifest_path}/repository/repository-members/${name}.csv" |
| 63 | + |
| 64 | + ## Write CSV header |
| 65 | + echo "type,id,permission" > ${collab_list_file} |
| 66 | + |
| 67 | + ## Write team entries |
| 68 | + echo "team,maintainers,triage" >> ${collab_list_file} |
| 69 | + echo "team,release,push" >> ${collab_list_file} |
| 70 | + |
| 71 | + ## Write maintainer entries |
| 72 | + for maintainer in ${maintainers}; do |
| 73 | + echo "user,${maintainer},maintain" >> ${collab_list_file} |
| 74 | + done |
| 75 | + |
| 76 | + ## Write collaborator entries |
| 77 | + for collaborator in ${collaborators}; do |
| 78 | + echo "user,${collaborator},push" >> ${collab_list_file} |
| 79 | + done |
| 80 | +done |
0 commit comments