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

src/list_command.sh: Populate REPOS array when listing all contributions #12

Closed
wants to merge 1 commit into from
Closed
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
75 changes: 33 additions & 42 deletions contribution-stats
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
# This script was generated by bashly 1.1.10 (https://bashly.dannyb.co)
# This script was generated by bashly 1.2.2 (https://bashly.dannyb.co)
# Modifying it manually is not recommended

# :wrapper.bash3_bouncer
@@ -17,15 +17,7 @@ version_command() {

# :command.usage
contribution_stats_usage() {
if [[ -n $long_usage ]]; then
printf "contribution-stats - Script gathering contribution stats from upstream projects\n"
echo

else
printf "contribution-stats - Script gathering contribution stats from upstream projects\n"
echo

fi
printf "contribution-stats - Script gathering contribution stats from upstream projects\n\n"

printf "%s\n" "Usage:"
printf " contribution-stats COMMAND\n"
@@ -39,7 +31,7 @@ contribution_stats_usage() {
echo

# :command.long_usage
if [[ -n $long_usage ]]; then
if [[ -n "$long_usage" ]]; then
printf "%s\n" "Options:"

# :command.usage_fixed_flags
@@ -55,16 +47,7 @@ contribution_stats_usage() {

# :command.usage
contribution_stats_sync_usage() {
if [[ -n $long_usage ]]; then
printf "contribution-stats sync - Clone and/or all tracked upstream repositories\n"
echo

else
printf "contribution-stats sync - Clone and/or all tracked upstream repositories\n"
echo

fi

printf "contribution-stats sync - Clone and/or all tracked upstream repositories\n\n"
printf "Alias: s\n"
echo

@@ -74,7 +57,7 @@ contribution_stats_sync_usage() {
echo

# :command.long_usage
if [[ -n $long_usage ]]; then
if [[ -n "$long_usage" ]]; then
printf "%s\n" "Options:"

# :command.usage_flags
@@ -98,16 +81,7 @@ contribution_stats_sync_usage() {

# :command.usage
contribution_stats_list_usage() {
if [[ -n $long_usage ]]; then
printf "contribution-stats list - List contribution stats\n"
echo

else
printf "contribution-stats list - List contribution stats\n"
echo

fi

printf "contribution-stats list - List contribution stats\n\n"
printf "Alias: l\n"
echo

@@ -117,7 +91,7 @@ contribution_stats_list_usage() {
echo

# :command.long_usage
if [[ -n $long_usage ]]; then
if [[ -n "$long_usage" ]]; then
printf "%s\n" "Options:"

# :command.usage_flags
@@ -129,19 +103,19 @@ contribution_stats_list_usage() {
# :flag.usage
printf " %s\n" "--start-date, -s DATE"
printf " Start date for analyze - only commits older than this date will be listed.\n Defaults to 01/01/2013.\n"
printf " Default: 01/01/2013\n"
printf " %s\n" "Default: 01/01/2013"
echo

# :flag.usage
printf " %s\n" "--end-date, -e DATE"
printf " End date for analyze - only commits younger than this date will be listed.\n Defaults to 31/12/2050.\n"
printf " Default: 31/12/2050\n"
printf " %s\n" "Default: 31/12/2050"
echo

# :flag.usage
printf " %s\n" "--out, -o OUTPUT"
printf " Path to the output CSV file\n"
printf " Default: list.csv\n"
printf " %s\n" "Default: list.csv"
echo

# :command.usage_fixed_flags
@@ -164,7 +138,7 @@ contribution_stats_list_usage() {
# :command.normalize_input
# :command.normalize_input_function
normalize_input() {
local arg flags passthru
local arg passthru flags
passthru=false

while [[ $# -gt 0 ]]; do
@@ -388,13 +362,30 @@ contribution_stats_list_command() {
fi
}

# Function to load repository definitions from a YAML file
load_repos_from_yamls() {
local repo_directory="repo-def"

# Declare the global associative array
declare -g -A REPOS

# Use yq to parse the YAML file and populate the REPOS array
# Make sure to use correct quotes and verify the command based on your yq version
for file in $(find "$repo_directory" -type f -name "*.yaml" ); do
while IFS=" " read -r key value; do
REPOS["$key"]="$value"
done < <(yq -r '. | to_entries[] | "\(.key) \(.value)"' "$file")
done
}

list_all_repos() {
for repo in "${!REPOS[@]}"; do
_dir="$repo"
_url="${REPOS[$repo]}"
load_repos_from_yamls
for repo in "${!REPOS[@]}"; do
_dir="$repo"
_url="${REPOS[$repo]}"

list_single_repo "${_dir}"
done
list_single_repo "${_dir}"
done
}

rm -f "${OUTPUT_FILE}"
27 changes: 22 additions & 5 deletions src/list_command.sh
Original file line number Diff line number Diff line change
@@ -81,13 +81,30 @@ list_single_repo() {
fi
}

# Function to load repository definitions from a YAML file
load_repos_from_yamls() {
local repo_directory="repo-def"

# Declare the global associative array
declare -g -A REPOS

# Use yq to parse the YAML file and populate the REPOS array
# Make sure to use correct quotes and verify the command based on your yq version
for file in $(find "$repo_directory" -type f -name "*.yaml" ); do
while IFS=" " read -r key value; do
REPOS["$key"]="$value"
done < <(yq -r '. | to_entries[] | "\(.key) \(.value)"' "$file")
done
}

list_all_repos() {
for repo in "${!REPOS[@]}"; do
_dir="$repo"
_url="${REPOS[$repo]}"
load_repos_from_yamls
for repo in "${!REPOS[@]}"; do
_dir="$repo"
_url="${REPOS[$repo]}"

list_single_repo "${_dir}"
done
list_single_repo "${_dir}"
done
}

rm -f "${OUTPUT_FILE}"