Skip to content

Commit a444208

Browse files
committed
Merge branch 'dev'
2 parents 242daab + 3acc760 commit a444208

14 files changed

+708
-16
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
toolbox/github/data
22
toolbox/diver/data
3+
toolbox/gitlab/data

CHANGELOG.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
# CHANGELOG
22

3+
## Version 2.5.0
4+
5+
### Features
6+
7+
- [#32](https://github.com/Orange-OpenSource/floss-toolbox/issues/32) GitLab Auto Backup
8+
- [#49](https://github.com/Orange-OpenSource/floss-toolbox/issues/49) Look for leaks (GitLab)
9+
10+
### Bugs
11+
12+
- [#52](https://github.com/Orange-OpenSource/floss-toolbox/issues/52) Failure of git log if no commits
13+
314
## Version 2.4.0
415

516
### Features
617

7-
- [#44](https://github.com/Orange-OpenSource/floss-toolbox/issues/44) Look for leaks
18+
- [#44](https://github.com/Orange-OpenSource/floss-toolbox/issues/44) Look for leaks (GitHub)
819
- [#29](https://github.com/Orange-OpenSource/floss-toolbox/issues/29) Dry run
920

1021
### Refactoring

README.md

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# floss-toolbox (version 2.4.0)
1+
# floss-toolbox (version 2.5.0)
22

33
Toolbox to help developers and open source referents to have cleaner projects in GitHub organizations.
44

@@ -427,4 +427,67 @@ brew install gitleaks
427427

428428
You need to define in the _configuration.rb_ files the Github organisation at **GITHUB_ORGANIZATION_NAME** and also your GitHub personal token at ** GITHUB_PERSONAL_ACCESS_TOKEN**.
429429

430-
**You should also have your _git_ environment ready i.e. add your SSH private key if you clone by SSH for example. _gh_ must be installed, and _python3_ be ready. Obvisously _gitleaks_ must be installed**
430+
**You should also have your _git_ environment ready i.e. add your SSH private key if you clone by SSH for example. _gh_ must be installed, and _python3_ be ready. Obviously _gitleaks_ must be installed**
431+
432+
# Play with GitLab web API
433+
434+
## Prerequisites
435+
436+
- Ruby Gem: `git 1.8.1`
437+
- Python3
438+
439+
- Create a [GitLab personal token](https://gitlab.com/-/profile/personal_access_tokens) and define it in the _configuration.rb_ file for the `GILAB_PERSONAL_ACCESS_TOKEN` variable.
440+
- Define the GitLab organization id in the _configuration.rb_ file for the `GITLAB_ORGANIZATION_ID` variable. It will allow to send requests to query and modify your organization.
441+
442+
## Prepare project
443+
444+
```ruby
445+
gem install git
446+
```
447+
448+
## Features
449+
450+
### Make a backup of organization repositories
451+
452+
_Keywords: #organisation #GitLab #repositories #clones #dump_
453+
454+
This feature allows to clone all repositories of the defined GitLab organization (groups and subgroups incldued) and save them in a specific folder.
455+
456+
Run the following command:
457+
```shell
458+
bash GitLabWizard.sh backup-all-repositories-from-org
459+
```
460+
461+
This script will get configuation details picked from the Ruby configuration file; and triggers another Shell script to make a CURL request to the GitLab endpoint. A Python code will be called so as to extract repositories URLbefoire the cloning operation.
462+
463+
You need to define in the _configuration.rb_ files the GitLab organisation ID at **GITLAB_ORGANIZATION_ID**.
464+
You have to also define the location to store clones at **REPOSITORIES_CLONE_LOCATION_PATH** and the access token at **GILAB_PERSONAL_ACCESS_TOKEN**.
465+
466+
**You should also have your _git_ environment ready, i.e. add your SSH private key if you clone by SSH for example.**
467+
468+
### Check if there are leaks in organisation repositories (using gitleaks)
469+
470+
_Keywords: #organisation #GitLab #repositories #leaks #gitleaks_
471+
472+
**Warning: This operation can take long time because of both Git histories and file trees parsing**
473+
474+
This feature allows to check in all repositories of the GitHub organisation if there are leaks using the _gitleaks_ tool.
475+
476+
Run the following command:
477+
```shell
478+
bash GitLabWizard.sh look-for-leaks
479+
```
480+
481+
This script needs a GitLab personal access otken to make requests to GitLab API and also the GitLab group ID to use to get projects under it.
482+
The wizard Shell script will pick configuration details from the Ruby configuration file ; and triggers another Shell script for the data process. A Python code will be called too to process JSON sent by GItLab API..
483+
484+
The [gitleaks](https://github.com/zricethezav/gitleaks) tool will be used to look inside the repository. To install it:
485+
486+
```shell
487+
brew install gitleaks
488+
```
489+
490+
You need to define in the _configuration.rb_ files the GitLab organisation ID at **GITLAB_ORGANIZATION_ID**.
491+
You have to also define the location to store clones at **REPOSITORIES_CLONE_LOCATION_PATH** and the access token at **GILAB_PERSONAL_ACCESS_TOKEN**.
492+
493+
**You should also have your _git_ environment ready i.e. add your SSH private key if you clone by SSH for example. _gh_ must be installed, and _python3_ be ready. Obviously _gitleaks_ must be installed**

toolbox/diver/extract-emails-from-history.sh

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

10-
# Version.............: 1.0.1
10+
# Version.............: 1.0.2
1111
# Since...............: 06/10/2021
1212
# Description.........: Using the Git history, provide a list of contributors
1313
#
@@ -22,7 +22,7 @@
2222

2323
set -euo pipefail
2424

25-
VERSION="1.0.1"
25+
VERSION="1.0.2"
2626
SCRIPT_NAME="extract-emails-from-history"
2727

2828
# -------------
@@ -216,6 +216,12 @@ fi
216216

217217
touch "$git_log_file"
218218

219+
if [ "$( git log --oneline -5 2>/dev/null | wc -l )" -eq 0 ]; then
220+
echo "Warning: Project '$git_based_project' is a git repository without any commit, that's weird"
221+
CleanFiles
222+
NormalExit
223+
fi
224+
219225
git log --since=$git_log_limit > $git_log_file
220226

221227
if [ ! -s "$git_log_file" ]; then

toolbox/diver/find-contributors-in-git-logs.sh

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

10-
# Version.............: 1.2.0
10+
# Version.............: 1.2.1
1111
# Since...............: 11/05/2020
1212
# Description.........: Looks for words (defined in dedicated file) in git logs
1313
#
@@ -21,7 +21,7 @@
2121
#
2222

2323

24-
VERSION="1.2.0"
24+
VERSION="1.2.1"
2525
SCRIPT_NAME="find-contributors-in-git-logs"
2626

2727
# -------------
@@ -234,6 +234,11 @@ if [ -f $git_log_file ]; then
234234
rm $git_log_file
235235
fi
236236

237+
if [ "$( git log --oneline -5 2>/dev/null | wc -l )" -eq 0 ]; then
238+
echo "Warning: Project '$git_based_project' is a git repository without any commit, that's weird"
239+
NormalExit
240+
fi
241+
237242
git log --since=$git_log_limit > $git_log_file
238243

239244
if [ ! -s "$git_log_file" ]; then

toolbox/diver/find-missing-developers-in-git-commits.sh

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

10-
# Version.............: 1.1.0
10+
# Version.............: 1.1.1
1111
# Since...............: 12/05/2020
1212
# Description.........: Looks in git commits in the DCO has been used, i.e. if commits have been signed off.
1313
# Checks also if commits authors are defined.
@@ -21,7 +21,7 @@
2121
# 3 - problem with a command
2222
#
2323

24-
VERSION="1.1.0"
24+
VERSION="1.1.1"
2525
SCRIPT_NAME="find-missing-developers-in-git-commits"
2626

2727
# -------------
@@ -199,6 +199,11 @@ if [ -f $git_log_file ]; then
199199
rm $git_log_file
200200
fi
201201

202+
if [ "$( git log --oneline -5 2>/dev/null | wc -l )" -eq 0 ]; then
203+
echo "Warning: Project '$git_based_project' is a git repository without any commit, that's weird"
204+
NormalExit
205+
fi
206+
202207
git log --since=$git_log_limit > $git_log_file
203208

204209
if [ ! -s "$git_log_file" ]; then

toolbox/diver/list-contributors-in-history.sh

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

10-
# Version.............: 1.0.0
10+
# Version.............: 1.0.2
1111
# Since...............: 24/02/2022
1212
# Description.........: Using the Git history, provide a list of contributors' email addresses
1313
#
@@ -22,7 +22,7 @@
2222

2323
set -euo pipefail
2424

25-
VERSION="1.0.1"
25+
VERSION="1.0.2"
2626
SCRIPT_NAME="list-contributors-in-history"
2727

2828
# -------------
@@ -197,6 +197,11 @@ fi
197197

198198
touch "$git_log_file"
199199

200+
if [ "$( git log --oneline -5 2>/dev/null | wc -l )" -eq 0 ]; then
201+
echo "Warning: Project '$git_based_project' is a git repository without any commit, that's weird"
202+
NormalExit
203+
fi
204+
200205
git log --since=$git_log_limit > $git_log_file
201206

202207
if [ ! -s "$git_log_file" ]; then

toolbox/dry-run.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
# Since...............: 08/03/2021
1111
# Description.........: Make a dry-run of the project to check if everything is ready to use
12+
# Version.............: 1.1.0
1213

1314
# Couts
1415
# -----
@@ -128,6 +129,24 @@ CheckIfFileExists "github/utils/GitHubWrapper.rb"
128129
CheckIfFileExists "github/utils/GitWrapper.rb"
129130
CheckIfFileExists "github/utils/IO.rb"
130131

132+
# GitLab features
133+
# ---------------
134+
135+
echo -e "\n----------------------------------"
136+
echo "Assertions for the GITLAB features"
137+
echo "----------------------------------"
138+
139+
echo -e "\nCheck if main folder exists..."
140+
CheckIfDirectoryExists "gitlab"
141+
CheckIfDirectoryExists "gitlab/data"
142+
143+
echo -e "\nCheck files..."
144+
CheckIfFileExists "gitlab/configuration.rb"
145+
CheckIfFileExists "gitlab/GitLabWizard.sh"
146+
CheckIfFileExists "gitlab/utils/dump-git-repositories-from-gitlab.sh"
147+
CheckIfFileExists "github/utils/extract-repos-field-from-json.py" # Stored in github folder but used by dump-git-repositories-from-gitlab.sh
148+
CheckIfFileExists "github/utils/count-leaks-nodes.py" # Stored in github folder but used by check-leaks-from-gitlab.sh
149+
131150
# Runtimes and tools
132151
# ------------------
133152

@@ -164,6 +183,7 @@ echo "Assertions for configuration file"
164183
echo "---------------------------------"
165184

166185
echo -e "\nCheck for entries in configuration file..."
186+
167187
CheckIfConfigurationKeyDefined "github/configuration.rb" "GITHUB_PERSONAL_ACCESS_TOKEN"
168188
CheckIfConfigurationKeyDefined "github/configuration.rb" "GITHUB_ORGANIZATION_NAME"
169189
CheckIfConfigurationKeyDefined "github/configuration.rb" "GITHUB_ORGANIZATION_ADMINS"
@@ -183,6 +203,13 @@ CheckIfConfigurationKeyDefined "github/configuration.rb" "FILENAME_PROJECTS_WITH
183203
CheckIfConfigurationKeyDefined "github/configuration.rb" "FILENAME_EMPTY_PROJECTS"
184204
CheckIfConfigurationKeyDefined "github/configuration.rb" "REPOSITORIES_CLONE_LOCATION_PATH"
185205
CheckIfConfigurationKeyDefined "github/configuration.rb" "REPOSITORIES_CLONE_URL_JSON_KEY"
206+
207+
CheckIfConfigurationKeyDefined "gitlab/configuration.rb" "GILAB_PERSONAL_ACCESS_TOKEN"
208+
CheckIfConfigurationKeyDefined "gitlab/configuration.rb" "GITLAB_ORGANIZATION_ID"
209+
CheckIfConfigurationKeyDefined "gitlab/configuration.rb" "RESULTS_PER_PAGE"
210+
CheckIfConfigurationKeyDefined "gitlab/configuration.rb" "REPOSITORIES_CLONE_LOCATION_PATH"
211+
CheckIfConfigurationKeyDefined "gitlab/configuration.rb" "REPOSITORIES_CLONE_URL_JSON_KEY"
212+
186213
echo -e "🔎 I hope configuration entries are - well - defined, be sure of that"
187214

188215
# Conclusion

toolbox/github/configuration.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
# Allow debug message or not
1010
$LOG_DEBUG = false
1111

12-
# API, tokens, GitHub organization
13-
# --------------------------------
12+
# GitHub organization
13+
# -------------------
1414

1515
# You have to create a personal access token on: https://github.com/settings/tokens
1616
$GITHUB_PERSONAL_ACCESS_TOKEN = ""

toolbox/github/utils/check-leaks-from-github.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,14 @@ if [ -z "$organisation_name" -o "$organisation_name" == "" ]; then
7575
fi
7676

7777
cloning_url_key=$2
78-
if [ -z "$cloning_url_key" -o "$organisation_name" == "" ]; then
78+
if [ -z "$cloning_url_key" -o "$cloning_url_key" == "" ]; then
7979
echo "ERROR: No JSON key for URL. Exits now."
8080
UsageAndExit
8181
exit $EXIT_BAD_ARGUMENTS
8282
fi
8383

8484
dump_folder_name=$3
85-
if [ -z "$dump_folder_name" -o "$organisation_name" == "" ]; then
85+
if [ -z "$dump_folder_name" -o "$dump_folder_name" == "" ]; then
8686
echo "ERROR: No dump folder name defined. Exits now."
8787
UsageAndExit
8888
exit $EXIT_BAD_ARGUMENTS
@@ -195,7 +195,7 @@ while read url_line; do
195195

196196
done < "$dir_before_dump/$url_for_cloning"
197197

198-
echo "Looking done!"
198+
echo "Scanning done!"
199199

200200
# Step 6 - Clean up
201201

0 commit comments

Comments
 (0)