Skip to content

Commit bebd870

Browse files
authored
Version 2.13.0 (#100)
* feat(#28): count of lines in script (#88) - Add script to call cloc - Update dry-run - Improve README Signed-off-by: Pierre-Yves Lapersonne <pierreyves.lapersonne@orange.com> * doc(#87): add DCO sample (#89) Signed-off-by: Pierre-Yves Lapersonne <pierreyves.lapersonne@orange.com> * doc(#90): add security policy for repository (#91) Signed-off-by: Pierre-Yves Lapersonne <pierreyves.lapersonne@orange.com> * chore(#86): remove data test samples for release archives (#92) Signed-off-by: Pierre-Yves Lapersonne <pierreyves.lapersonne@orange.com> * [#85] [#93] Update README, dry-run files (#94) * doc(#85): split main README to four Signed-off-by: Pierre-Yves Lapersonne <pierreyves.lapersonne@orange.com> * doc(#85): split REAMDE, update dry-run (#93) and licenses files Signed-off-by: Pierre-Yves Lapersonne <pierreyves.lapersonne@orange.com> --------- Signed-off-by: Pierre-Yves Lapersonne <pierreyves.lapersonne@orange.com> * Prepare version 2.12.0 Signed-off-by: Pierre-Yves Lapersonne <pierreyves.lapersonne@orange.com> * fix(#96): broken hyperlinks in README menus Signed-off-by: Pierre-Yves Lapersonne <pierreyves.lapersonne@orange.com> * feat(#98): metrics computation from Git URL or directory path (#99) - Breaking public API - New options Signed-off-by: Pierre-Yves Lapersonne <pierreyves.lapersonne@orange.com> * Prepare version 2.13.0 Signed-off-by: Pierre-Yves Lapersonne <pierreyves.lapersonne@orange.com> --------- Signed-off-by: Pierre-Yves Lapersonne <pierreyves.lapersonne@orange.com>
1 parent ae6b0ad commit bebd870

File tree

6 files changed

+85
-34
lines changed

6 files changed

+85
-34
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# CHANGELOG
22

3+
## Version 2.13.0
4+
5+
### Features
6+
7+
- [#98](https://github.com/Orange-OpenSource/floss-toolbox/issues/98) Diver - Compute metrics with in parameter URL to clone repo
8+
9+
### Bugs
10+
11+
- [#96](https://github.com/Orange-OpenSource/floss-toolbox/issues/96) Project - Broken links in README
12+
313
## Version 2.12.0
414

515
### Features

toolbox/LicensesInventory/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ Table of Contents
44
=================
55
* [Licenses inventory](#licenses-inventory)
66
* [Disclaimer](#disclaimer)
7-
* [Prerequisites](#prerequisites-3)
7+
* [Prerequisites](#prerequisites)
88
* [Fill the configuration file](#fill-the-configuration-file)
99
* [Run the tool](#run-the-tool)
1010
* [Run the tests](#run-the-tests)
1111
* [Managed platforms and environments](#managed-platforms)
1212
* [Go with go.mod](#go-language)
1313
* [Gradle with build.gradle(.kts)](#gradle-environment)
1414
* [Rust with Cargo.lock](#rust-environment)
15-
* [JavaScript / Node.js with package.json](#javascriptnodejs-environment)
15+
* [JavaScript / Node.js with package.json](#javascript--nodejs-environment)
1616
* [Swift with Package.swift](#swift--spm-environment)
1717
* [Dart / Flutter with pubspec.yaml](#dart--flutter-environment)
1818
* [Notes](#notes)

toolbox/diver/README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Table of Contents
1414
* [Find credits](#find-credits)
1515
* [List conributors from Git history](#list-contributors-from-git-history)
1616
* [Extract email adress from Git history](#extract-email-address-from-git-history)
17+
* [Count lines of code in a directory](#count-lines-of-code-in-a-directory)
1718

1819
# The "diver" of source code and commits
1920

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

208209
```shell
209-
bash lines-count.sh --target "absolute/path/to/target"
210+
# To compute metrics in some folder
211+
bash lines-count.sh --folder "absolute/path/to/target"
212+
213+
# To compute metrics for a remote repository to clone at given URL
214+
bash lines-count.sh --url "HTTP-or-SSH-URL-of-Git-repository"
210215
```

toolbox/diver/lines-count.sh

Lines changed: 62 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,22 @@
77
#
88
# Author: Pierre-Yves LAPERSONNE <pierreyves(dot)lapersonne(at)orange(dot)com> et al.
99

10-
# Version.............: 1.0.0
10+
# Version.............: 2.0.0
1111
# Since...............: 18/07/2023
12-
# Description.........: Counts liens of cound for a target directory
13-
#
14-
# Usage: bash lines-count.sh --target TARGET
15-
#
16-
# Exit codes:
17-
# 0 - normal exit
18-
# 1 - problem with given parameters
19-
#
12+
# Description.........: Counts lines of code for a target directory or Git repo URL
2013

2114
set -euo pipefail # set -euxo pipefail
2215

23-
VERSION="1.0.0"
24-
SCRIPT_NAME="lines-count.sh"
16+
VERSION="2.0.0"
17+
SCRIPT_NAME=$(basename "$0")
2518

2619
# -------------
2720
# Configuration
2821
# -------------
2922

3023
NORMAL_EXIT_CODE=0
3124
BAD_ARGUMENTS_EXIT_CODE=1
25+
BAD_PRECONDITIONS_EXIT_CODE=2
3226

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

36+
# Name of clone repository if done
37+
REPO_CLONE_NAME="$TEMP_FOLDER/repo-to-scan"
38+
4239
# ---------
4340
# Functions
4441
# ---------
@@ -50,8 +47,13 @@ DisplayUsages(){
5047
echo "$SCRIPT_NAME - Version $VERSION"
5148
echo "***********************************************"
5249
echo "USAGE:"
53-
echo "bash $SCRIPT_NAME --target TARGET"
54-
echo -e "\t --target.........: TARGET must point to a directory to scan for lines and count them (recursive)"
50+
echo "bash $SCRIPT_NAME [--folder TARGET | --url URL_OF_GIT_REPO]"
51+
echo -e "\t --folder.........: TARGET must point to a directory to scan for lines and count them (recursive)"
52+
echo -e "\t --url............: Clone repo at URL_OF_GIT_REPO and scan it"
53+
echo "EXIT CODES:"
54+
echo -e "\t$NORMAL_EXIT_CODE: normal exit"
55+
echo -e "\t$BAD_ARGUMENTS_EXIT_CODE: problem with given parameters"
56+
echo -e "\t$BAD_PRECONDITIONS_EXIT_CODE: preconditions issues"
5557
}
5658

5759
# \fn NormalExit
@@ -69,14 +71,17 @@ BadArgumentsExit(){
6971
# \fn BadPreconditionsExit
7072
# \brief Exits with BAD_PRECONDITION_EXIT_CODE code
7173
BadPreconditionsExit() {
72-
exit $BAD_PRECONDITION_EXIT_CODE
74+
exit $BAD_PRECONDITIONS_EXIT_CODE
7375
}
7476

7577
# \fn CleanFiles
7678
# \brief If existing removes the work files
7779
CleanFiles() {
78-
if [ -f $REPORT_METRIC_FILE ]; then
79-
rm $REPORT_METRIC_FILE
80+
if [ -f "$REPORT_METRIC_FILE" ]; then
81+
rm "$REPORT_METRIC_FILE"
82+
fi
83+
if [ -d "$REPO_CLONE_NAME" ]; then
84+
rm -rf "$REPO_CLONE_NAME"
8085
fi
8186
}
8287

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

100105
# Get target
101-
if [ "$1" = "--target" ]; then
106+
if [ "$1" = "--folder" ]; then
102107
if [ "$2" ]; then
103108
directory_to_scan=$2
109+
repo_to_clone_url=""
110+
# Check if target is directory
111+
if [ ! -d "$directory_to_scan" ]; then
112+
echo "💥 Error: Target is not a directory ($directory_to_scan)."
113+
BadArgumentsExit
114+
fi
115+
else
116+
DisplayUsages
117+
BadArgumentsExit
118+
fi
119+
elif [ "$1" = "--url" ]; then
120+
if [ "$2" ]; then
121+
directory_to_scan=""
122+
repo_to_clone_url=$2
104123
else
105124
DisplayUsages
106125
BadArgumentsExit
@@ -123,26 +142,46 @@ echo "**************************************************"
123142
echo "$SCRIPT_NAME - Version $VERSION"
124143
echo "**************************************************"
125144

126-
echo -e "\n"
127-
128-
echo "📋 Directory to scan is to analyse is $directory_to_scan"
129145
echo "📋 Prepare logs"
130146
PrepareFiles
131147

132-
echo -e "\n"
148+
# ---------------------------------
149+
# Step 1 - If URL of repo, clone it
150+
# ---------------------------------
151+
152+
if [ ! -z "$repo_to_clone_url" ]; then
153+
echo "📋 Repository to clone is '$repo_to_clone_url'"
154+
git clone "$repo_to_clone_url" "$REPO_CLONE_NAME"
155+
if [ "$(ls -A $REPO_CLONE_NAME)" ]; then
156+
echo "👌 Repository after cloning is not empty, good!"
157+
directory_to_scan="$REPO_CLONE_NAME"
158+
else
159+
echo "💥 Error: After cloning repository is empty, cannot compute metric"
160+
BadPreconditionsExit
161+
fi
162+
else
163+
echo "📋 No repository to clone, check suplied folder"
164+
fi
165+
166+
echo "📋 Directory to scan is $directory_to_scan"
133167

134168
# ------------------------------------------------
135-
# Step 1 - Count lines of target and store results
169+
# Step 2 - Count lines of target and store results
136170
# ------------------------------------------------
137171

138172
echo "🍥 Counting lines and store in $directory_to_scan"
139173

174+
if [ ! "$(ls -A $directory_to_scan)" ]; then
175+
echo "💥 Error: Directory to scan is empty, cannot compute metric"
176+
BadPreconditionsExit
177+
fi
178+
140179
cloc "$directory_to_scan" > "$REPORT_METRIC_FILE"
141180

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

144183
# ------------------------------------------------------------
145-
# Step 2 - Metrics (words and files counts, hits, duration...)
184+
# Step 3 - Metrics (words and files counts, hits, duration...)
146185
# ------------------------------------------------------------
147186

148187
script_duration=$SECONDS

toolbox/github/README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ Table of Contents
66
* [Project tree](#project-tree)
77
* [Prerequisites](#prerequisites)
88
* [Prepare project](#prepare-project)
9-
* [Third party elements](#third-party-elements)
10-
* [Features](#features-1)
9+
* [Features](#features)
1110
* [Display usages](#display-usage)
1211
* [Get all members of organization](#get-all-members-of-organization)
1312
* [Get members of organization with 2FA disabled](#get-members-of-organization-with-2fa-disabled)
@@ -23,7 +22,6 @@ Table of Contents
2322
* [Play with GitHub CLI (GH)](#play-with-github-cli-gh)
2423
* [Prerequisites](#prerequisites-1)
2524
* [Prepare project](#prepare-project-1)
26-
* [Third party elements](#third-party-elements-1)
2725
* [Features](#features-2)
2826
* [Make a backup of organization repositories](#make-a-backup-of-organization-repositories)
2927
* [Check if there are vulnerabilities alerts in organisation repositories](#check-if-there-are-vulnerabilities-alerts-in-organisation-repositories)

toolbox/gitlab/README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
Table of Contents
44
=================
55
* [Play with GitLab web API](#play-with-gitlab-web-api)
6-
* [Prerequisites](#prerequisites-2)
7-
* [Prepare projects](#prepare-project-2)
8-
* [Features](#features-3)
9-
* [Make a backup of organization repositories](#make-a-backup-of-organization-repositories-1)
10-
* [Check if there are leaks in organisation repositories (using gitleaks)](#check-if-there-are-leaks-in-organisation-repositories-using-gitleaks-1)
6+
* [Prerequisites](#prerequisites)
7+
* [Features](#features)
8+
* [Make a backup of organization repositories](#make-a-backup-of-organization-repositories)
9+
* [Check if there are leaks in organisation repositories (using gitleaks)](#check-if-there-are-leaks-in-organisation-repositories-using-gitleaks)
1110

1211
# Play with GitLab web API
1312

0 commit comments

Comments
 (0)