Skip to content

Commit

Permalink
Version 2.13.0 (#100)
Browse files Browse the repository at this point in the history
* feat(#28): count of lines in script (#88)

- Add script to call cloc
- Update dry-run
- Improve README

Signed-off-by: Pierre-Yves Lapersonne <[email protected]>

* doc(#87): add DCO sample (#89)

Signed-off-by: Pierre-Yves Lapersonne <[email protected]>

* doc(#90): add security policy for repository (#91)

Signed-off-by: Pierre-Yves Lapersonne <[email protected]>

* chore(#86): remove data test samples for release archives (#92)

Signed-off-by: Pierre-Yves Lapersonne <[email protected]>

* [#85] [#93] Update README, dry-run files (#94)

* doc(#85): split main README to four

Signed-off-by: Pierre-Yves Lapersonne <[email protected]>

* doc(#85): split REAMDE, update dry-run (#93) and licenses files

Signed-off-by: Pierre-Yves Lapersonne <[email protected]>

---------

Signed-off-by: Pierre-Yves Lapersonne <[email protected]>

* Prepare version 2.12.0

Signed-off-by: Pierre-Yves Lapersonne <[email protected]>

* fix(#96): broken hyperlinks in README menus

Signed-off-by: Pierre-Yves Lapersonne <[email protected]>

* feat(#98): metrics computation from Git URL or directory path (#99)

- Breaking public API
- New options

Signed-off-by: Pierre-Yves Lapersonne <[email protected]>

* Prepare version 2.13.0

Signed-off-by: Pierre-Yves Lapersonne <[email protected]>

---------

Signed-off-by: Pierre-Yves Lapersonne <[email protected]>
  • Loading branch information
pylapp authored Jul 19, 2023
1 parent ae6b0ad commit bebd870
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 34 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# CHANGELOG

## Version 2.13.0

### Features

- [#98](https://github.com/Orange-OpenSource/floss-toolbox/issues/98) Diver - Compute metrics with in parameter URL to clone repo

### Bugs

- [#96](https://github.com/Orange-OpenSource/floss-toolbox/issues/96) Project - Broken links in README

## Version 2.12.0

### Features
Expand Down
4 changes: 2 additions & 2 deletions toolbox/LicensesInventory/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ Table of Contents
=================
* [Licenses inventory](#licenses-inventory)
* [Disclaimer](#disclaimer)
* [Prerequisites](#prerequisites-3)
* [Prerequisites](#prerequisites)
* [Fill the configuration file](#fill-the-configuration-file)
* [Run the tool](#run-the-tool)
* [Run the tests](#run-the-tests)
* [Managed platforms and environments](#managed-platforms)
* [Go with go.mod](#go-language)
* [Gradle with build.gradle(.kts)](#gradle-environment)
* [Rust with Cargo.lock](#rust-environment)
* [JavaScript / Node.js with package.json](#javascriptnodejs-environment)
* [JavaScript / Node.js with package.json](#javascript--nodejs-environment)
* [Swift with Package.swift](#swift--spm-environment)
* [Dart / Flutter with pubspec.yaml](#dart--flutter-environment)
* [Notes](#notes)
Expand Down
7 changes: 6 additions & 1 deletion toolbox/diver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Table of Contents
* [Find credits](#find-credits)
* [List conributors from Git history](#list-contributors-from-git-history)
* [Extract email adress from Git history](#extract-email-address-from-git-history)
* [Count lines of code in a directory](#count-lines-of-code-in-a-directory)

# The "diver" of source code and commits

Expand Down Expand Up @@ -206,5 +207,9 @@ You can use one script to compute lines of code thanks to [cloc](https://github.
It will generate a report with all the metrics you may need.

```shell
bash lines-count.sh --target "absolute/path/to/target"
# To compute metrics in some folder
bash lines-count.sh --folder "absolute/path/to/target"

# To compute metrics for a remote repository to clone at given URL
bash lines-count.sh --url "HTTP-or-SSH-URL-of-Git-repository"
```
85 changes: 62 additions & 23 deletions toolbox/diver/lines-count.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,22 @@
#
# Author: Pierre-Yves LAPERSONNE <pierreyves(dot)lapersonne(at)orange(dot)com> et al.

# Version.............: 1.0.0
# Version.............: 2.0.0
# Since...............: 18/07/2023
# Description.........: Counts liens of cound for a target directory
#
# Usage: bash lines-count.sh --target TARGET
#
# Exit codes:
# 0 - normal exit
# 1 - problem with given parameters
#
# Description.........: Counts lines of code for a target directory or Git repo URL

set -euo pipefail # set -euxo pipefail

VERSION="1.0.0"
SCRIPT_NAME="lines-count.sh"
VERSION="2.0.0"
SCRIPT_NAME=$(basename "$0")

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

NORMAL_EXIT_CODE=0
BAD_ARGUMENTS_EXIT_CODE=1
BAD_PRECONDITIONS_EXIT_CODE=2

# Folder fo generated files
TEMP_FOLDER="./data"
Expand All @@ -39,6 +33,9 @@ GENERATED_FILES_PREFIX="$$-lines-count"
# Report file with metrics
REPORT_METRIC_FILE="$TEMP_FOLDER/$GENERATED_FILES_PREFIX-report.txt"

# Name of clone repository if done
REPO_CLONE_NAME="$TEMP_FOLDER/repo-to-scan"

# ---------
# Functions
# ---------
Expand All @@ -50,8 +47,13 @@ DisplayUsages(){
echo "$SCRIPT_NAME - Version $VERSION"
echo "***********************************************"
echo "USAGE:"
echo "bash $SCRIPT_NAME --target TARGET"
echo -e "\t --target.........: TARGET must point to a directory to scan for lines and count them (recursive)"
echo "bash $SCRIPT_NAME [--folder TARGET | --url URL_OF_GIT_REPO]"
echo -e "\t --folder.........: TARGET must point to a directory to scan for lines and count them (recursive)"
echo -e "\t --url............: Clone repo at URL_OF_GIT_REPO and scan it"
echo "EXIT CODES:"
echo -e "\t$NORMAL_EXIT_CODE: normal exit"
echo -e "\t$BAD_ARGUMENTS_EXIT_CODE: problem with given parameters"
echo -e "\t$BAD_PRECONDITIONS_EXIT_CODE: preconditions issues"
}

# \fn NormalExit
Expand All @@ -69,14 +71,17 @@ BadArgumentsExit(){
# \fn BadPreconditionsExit
# \brief Exits with BAD_PRECONDITION_EXIT_CODE code
BadPreconditionsExit() {
exit $BAD_PRECONDITION_EXIT_CODE
exit $BAD_PRECONDITIONS_EXIT_CODE
}

# \fn CleanFiles
# \brief If existing removes the work files
CleanFiles() {
if [ -f $REPORT_METRIC_FILE ]; then
rm $REPORT_METRIC_FILE
if [ -f "$REPORT_METRIC_FILE" ]; then
rm "$REPORT_METRIC_FILE"
fi
if [ -d "$REPO_CLONE_NAME" ]; then
rm -rf "$REPO_CLONE_NAME"
fi
}

Expand All @@ -98,9 +103,23 @@ if [ "$#" -ne 2 ]; then
fi

# Get target
if [ "$1" = "--target" ]; then
if [ "$1" = "--folder" ]; then
if [ "$2" ]; then
directory_to_scan=$2
repo_to_clone_url=""
# Check if target is directory
if [ ! -d "$directory_to_scan" ]; then
echo "💥 Error: Target is not a directory ($directory_to_scan)."
BadArgumentsExit
fi
else
DisplayUsages
BadArgumentsExit
fi
elif [ "$1" = "--url" ]; then
if [ "$2" ]; then
directory_to_scan=""
repo_to_clone_url=$2
else
DisplayUsages
BadArgumentsExit
Expand All @@ -123,26 +142,46 @@ echo "**************************************************"
echo "$SCRIPT_NAME - Version $VERSION"
echo "**************************************************"

echo -e "\n"

echo "📋 Directory to scan is to analyse is $directory_to_scan"
echo "📋 Prepare logs"
PrepareFiles

echo -e "\n"
# ---------------------------------
# Step 1 - If URL of repo, clone it
# ---------------------------------

if [ ! -z "$repo_to_clone_url" ]; then
echo "📋 Repository to clone is '$repo_to_clone_url'"
git clone "$repo_to_clone_url" "$REPO_CLONE_NAME"
if [ "$(ls -A $REPO_CLONE_NAME)" ]; then
echo "👌 Repository after cloning is not empty, good!"
directory_to_scan="$REPO_CLONE_NAME"
else
echo "💥 Error: After cloning repository is empty, cannot compute metric"
BadPreconditionsExit
fi
else
echo "📋 No repository to clone, check suplied folder"
fi

echo "📋 Directory to scan is $directory_to_scan"

# ------------------------------------------------
# Step 1 - Count lines of target and store results
# Step 2 - Count lines of target and store results
# ------------------------------------------------

echo "🍥 Counting lines and store in $directory_to_scan"

if [ ! "$(ls -A $directory_to_scan)" ]; then
echo "💥 Error: Directory to scan is empty, cannot compute metric"
BadPreconditionsExit
fi

cloc "$directory_to_scan" > "$REPORT_METRIC_FILE"

echo -e "👌 Counting of lines is done\n"

# ------------------------------------------------------------
# Step 2 - Metrics (words and files counts, hits, duration...)
# Step 3 - Metrics (words and files counts, hits, duration...)
# ------------------------------------------------------------

script_duration=$SECONDS
Expand Down
4 changes: 1 addition & 3 deletions toolbox/github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ Table of Contents
* [Project tree](#project-tree)
* [Prerequisites](#prerequisites)
* [Prepare project](#prepare-project)
* [Third party elements](#third-party-elements)
* [Features](#features-1)
* [Features](#features)
* [Display usages](#display-usage)
* [Get all members of organization](#get-all-members-of-organization)
* [Get members of organization with 2FA disabled](#get-members-of-organization-with-2fa-disabled)
Expand All @@ -23,7 +22,6 @@ Table of Contents
* [Play with GitHub CLI (GH)](#play-with-github-cli-gh)
* [Prerequisites](#prerequisites-1)
* [Prepare project](#prepare-project-1)
* [Third party elements](#third-party-elements-1)
* [Features](#features-2)
* [Make a backup of organization repositories](#make-a-backup-of-organization-repositories)
* [Check if there are vulnerabilities alerts in organisation repositories](#check-if-there-are-vulnerabilities-alerts-in-organisation-repositories)
Expand Down
9 changes: 4 additions & 5 deletions toolbox/gitlab/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
Table of Contents
=================
* [Play with GitLab web API](#play-with-gitlab-web-api)
* [Prerequisites](#prerequisites-2)
* [Prepare projects](#prepare-project-2)
* [Features](#features-3)
* [Make a backup of organization repositories](#make-a-backup-of-organization-repositories-1)
* [Check if there are leaks in organisation repositories (using gitleaks)](#check-if-there-are-leaks-in-organisation-repositories-using-gitleaks-1)
* [Prerequisites](#prerequisites)
* [Features](#features)
* [Make a backup of organization repositories](#make-a-backup-of-organization-repositories)
* [Check if there are leaks in organisation repositories (using gitleaks)](#check-if-there-are-leaks-in-organisation-repositories-using-gitleaks)

# Play with GitLab web API

Expand Down

0 comments on commit bebd870

Please sign in to comment.