1+ #! /bin/bash
2+ # Software Name: floss-toolbox
3+ # SPDX-FileCopyrightText: Copyright (c) Orange SA
4+ # SPDX-License-Identifier: Apache-2.0
5+ #
6+ # This software is distributed under the Apache 2.0 license,
7+ # the text of which is available at https://opensource.org/license/apache-2-0
8+ # or see the "LICENSE.txt" file for more details.
9+ #
10+ # Authors: See CONTRIBUTORS.txt
11+ # Software description: A toolbox of scripts to help work of forges admins and open source referents
12+
13+ # Version.............: 1.0.0
14+ # Since...............: 04/04/2024
15+ # Description.........: Using the Git history, provide a list of contributors' contributions
16+ #
17+ # Usage: bash list-contributors-in-history-emails-from-history.sh --project path/to/project
18+ #
19+ # Exit codes:
20+ # 0 - normal exit
21+ # 1 - problem with given parameters
22+ # 2 - problem with preconditions (e.g. files to use by the script)
23+ #
24+
25+ # set -euxo pipefail
26+
27+ VERSION=" 1.0.0"
28+ SCRIPT_NAME=$( basename " $0 " )
29+
30+ # -------------
31+ # Configuration
32+ # -------------
33+
34+ NORMAL_EXIT_CODE=0
35+ BAD_ARGUMENTS_EXIT_CODE=1
36+ BAD_PRECONDITION_EXIT_CODE=2
37+
38+ # Folder fo generated files
39+ TEMP_FOLDER=" .floss-toolbox/data"
40+
41+ # Prefix for generated files
42+ GENERATED_FILES_PREFIX=" $$ -contributions-of"
43+
44+ # ---------
45+ # Functions
46+ # --------
47+
48+ # \fn DisplayUsages
49+ # \brief Displays an help message and exists
50+ DisplayUsages (){
51+ echo " *****************************************************"
52+ echo " $SCRIPT_NAME - Version $VERSION "
53+ echo " *****************************************************"
54+ echo " USAGE:"
55+ echo " bash $SCRIPT_NAME --project PROJECT"
56+ echo -e " \t --project........: PROJECT must point to a git-based directory whith the commits to scan"
57+ }
58+
59+ # ----------------
60+ # Step 0 - Prepare
61+ # ----------------
62+
63+ # Check the args numbers and display usage if needed
64+ if [ " $# " -ne 2 ]; then
65+ DisplayUsages
66+ exit $NORMAL_EXIT_CODE
67+ fi
68+
69+ # Get target folder
70+ if [ " $1 " = " --project" ]; then
71+ if [ " $2 " ]; then
72+ git_based_project=$2
73+ else
74+ DisplayUsages
75+ exit $BAD_ARGUMENTS_EXIT_CODE
76+ fi
77+ else
78+ DisplayUsages
79+ exit $BAD_ARGUMENTS_EXIT_CODE
80+ fi
81+
82+ # Run!
83+
84+ echo " *****************************************************"
85+ echo " $SCRIPT_NAME - Version $VERSION "
86+ echo " *****************************************************"
87+
88+ echo " 📋 Project to analyse is $git_based_project "
89+ echo " 📋 Prepare workspace"
90+
91+ # Prepare workspace
92+
93+ current_folder=` pwd`
94+ workspace=" $current_folder /$TEMP_FOLDER "
95+
96+ if [ -d " $workspace " ]; then
97+ yes | rm -rf " $workspace "
98+ fi
99+ mkdir -p " $workspace "
100+
101+ cd " $git_based_project "
102+
103+ # Check if Git repository is not empty
104+
105+ echo " 🍥 Checking git project state..."
106+
107+ if [ " $( git log --oneline -5 2> /dev/null | wc -l ) " -eq 0 ]; then
108+ echo " Warning: Project '$git_based_project ' is a git repository without any commit, that's weird"
109+ exit $BAD_PRECONDITION_EXIT_CODE
110+ fi
111+
112+ # Get all authors
113+
114+ echo " 🍥 Retrieving git authors..."
115+ git_authors=$( git log --format=' %ae' | sort -u)
116+
117+ for git_author in $git_authors ; do
118+ git log --author=" $git_author " --pretty=format:" [DATE] %ad [HASH] %h [TITLE] %s" --date=short > " $workspace /$GENERATED_FILES_PREFIX -$git_author .txt"
119+ done
120+
121+ # Finished!
122+
123+ echo " 👌 Done!"
124+
125+ cd " $current_folder "
126+ number_files=$( ls -l " $workspace " | grep " ^-" | wc -l | tr -d ' [:space:]' )
127+ echo " 📈 There are $number_files generated, i.e. maybe $number_files authors with contributions"
128+ echo " Find results in '$workspace ' folder"
129+
130+ echo " Do you want to list all the files? (YES/no)"
131+ read -r response
132+ response=$( echo " $response " | tr ' [:upper:]' ' [:lower:]' )
133+
134+ if [ -z $response ] || [ " $response " = " yes" ] || [ " $response " = " y" ]; then
135+ ls -l " $workspace " | awk ' {print $9}'
136+ echo -e " \n"
137+ fi
138+
139+ echo " Bye!"
140+ exit $NORMAL_EXIT_CODE
0 commit comments