Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
toolbox/github/data
toolbox/diver/data
toolbox/diver/.floss-toolbox/data
toolbox/gitlab/data
toolbox/utils/text-generator/_templates/new-GitHub-repository-contributors.fr.template.txt.result
toolbox/utils/third-party-generator/components.csv.result
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased](https://github.com/Orange-OpenSource/floss-toolbox/compare/2.19.0..dev)

### Added

- [Diver] List all contributions by contributors ([#153](https://github.com/Orange-OpenSource/floss-toolbox/issues/153))

### Fixed

- [Utils] Fix missing import in configuration.py
Expand Down
10 changes: 10 additions & 0 deletions toolbox/diver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -364,4 +364,14 @@ Maybe a better file after fixes could be (after manual cleaning):
Barry ALLEN <barry.allen@star.labs>
Lex LUTHOR <lex.luthor@lex.corp>
Bruce WAYNE <bruce.wayne@wayneenterprise.com> <batman@gmail.com>
```

### List contributions by contributors

Sometimes we have to check contributions and contributors so as to list who did what, e.g. if subcontractors or interns made commits on some repository.
The *list-contributions-by-contributors.sh* script will extract all authors of commits, and then create file with all contributions for each author.
Thus it will make easier to see who did what.

```shell
bash list-contributions-by-contributors.sh --project /path/to/git/repository
```
1 change: 1 addition & 0 deletions toolbox/diver/dry-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ CheckIfFileExists "./find-missing-developers-in-git-commits.sh"
CheckIfFileExists "./list-contributors-in-history.sh"
CheckIfFileExists "./lines-count.sh"
CheckIfFileExists "./generate-contributors-file.py"
CheckIfFileExists "./list-contributions-by-contributors.sh"

echo -e "\nCheck utilitary scripts..."
CheckIfFileExists "./utils/extract-contributors-lists.rb"
Expand Down
140 changes: 140 additions & 0 deletions toolbox/diver/list-contributions-by-contributors.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
#!/bin/bash
# Software Name: floss-toolbox
# SPDX-FileCopyrightText: Copyright (c) Orange SA
# SPDX-License-Identifier: Apache-2.0
#
# This software is distributed under the Apache 2.0 license,
# the text of which is available at https://opensource.org/license/apache-2-0
# or see the "LICENSE.txt" file for more details.
#
# Authors: See CONTRIBUTORS.txt
# Software description: A toolbox of scripts to help work of forges admins and open source referents

# Version.............: 1.0.0
# Since...............: 04/04/2024
# Description.........: Using the Git history, provide a list of contributors' contributions
#
# Usage: bash list-contributors-in-history-emails-from-history.sh --project path/to/project
#
# Exit codes:
# 0 - normal exit
# 1 - problem with given parameters
# 2 - problem with preconditions (e.g. files to use by the script)
#

#set -euxo pipefail

VERSION="1.0.0"
SCRIPT_NAME=$(basename "$0")

# -------------
# Configuration
# -------------

NORMAL_EXIT_CODE=0
BAD_ARGUMENTS_EXIT_CODE=1
BAD_PRECONDITION_EXIT_CODE=2

# Folder fo generated files
TEMP_FOLDER=".floss-toolbox/data"

# Prefix for generated files
GENERATED_FILES_PREFIX="$$-contributions-of"

# ---------
# Functions
# --------

# \fn DisplayUsages
# \brief Displays an help message and exists
DisplayUsages(){
echo "*****************************************************"
echo "$SCRIPT_NAME - Version $VERSION"
echo "*****************************************************"
echo "USAGE:"
echo "bash $SCRIPT_NAME --project PROJECT"
echo -e "\t --project........: PROJECT must point to a git-based directory whith the commits to scan"
}

# ----------------
# Step 0 - Prepare
# ----------------

# Check the args numbers and display usage if needed
if [ "$#" -ne 2 ]; then
DisplayUsages
exit $NORMAL_EXIT_CODE
fi

# Get target folder
if [ "$1" = "--project" ]; then
if [ "$2" ]; then
git_based_project=$2
else
DisplayUsages
exit $BAD_ARGUMENTS_EXIT_CODE
fi
else
DisplayUsages
exit $BAD_ARGUMENTS_EXIT_CODE
fi

# Run!

echo "*****************************************************"
echo "$SCRIPT_NAME - Version $VERSION"
echo "*****************************************************"

echo "📋 Project to analyse is $git_based_project"
echo "📋 Prepare workspace"

# Prepare workspace

current_folder=`pwd`
workspace="$current_folder/$TEMP_FOLDER"

if [ -d "$workspace" ]; then
yes | rm -rf "$workspace"
fi
mkdir -p "$workspace"

cd "$git_based_project"

# Check if Git repository is not empty

echo "🍥 Checking git project state..."

if [ "$( git log --oneline -5 2>/dev/null | wc -l )" -eq 0 ]; then
echo "Warning: Project '$git_based_project' is a git repository without any commit, that's weird"
exit $BAD_PRECONDITION_EXIT_CODE
fi

# Get all authors

echo "🍥 Retrieving git authors..."
git_authors=$(git log --format='%ae' | sort -u)

for git_author in $git_authors; do
git log --author="$git_author" --pretty=format:"[DATE] %ad [HASH] %h [TITLE] %s" --date=short > "$workspace/$GENERATED_FILES_PREFIX-$git_author.txt"
done

# Finished!

echo "👌 Done!"

cd "$current_folder"
number_files=$(ls -l "$workspace" | grep "^-" | wc -l | tr -d '[:space:]')
echo "📈 There are $number_files generated, i.e. maybe $number_files authors with contributions"
echo "Find results in '$workspace' folder"

echo "Do you want to list all the files? (YES/no)"
read -r response
response=$(echo "$response" | tr '[:upper:]' '[:lower:]')

if [ -z $response ] || [ "$response" = "yes" ] || [ "$response" = "y" ]; then
ls -l "$workspace" | awk '{print $9}'
echo -e "\n"
fi

echo "Bye!"
exit $NORMAL_EXIT_CODE