Skip to content

Commit a2df606

Browse files
authored
add script, remove GHAE references (#38)
1 parent c8e7445 commit a2df606

File tree

2 files changed

+61
-3
lines changed

2 files changed

+61
-3
lines changed

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ Creates a CSV file of some `git log` data, useful for exporting to audit reports
44

55
[![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/some-natalie/gitlog-to-csv/badge)](https://securityscorecards.dev/viewer/?uri=github.com/some-natalie/gitlog-to-csv)
66

7+
> [!NOTE]
8+
> Only need the shell script? Here you go - [git-history-report.sh](git-history-report.sh)
9+
710
## Inputs and Outputs
811

912
Inputs
@@ -57,17 +60,19 @@ Per the [git documentation](https://git-scm.com/docs/git-log#_pretty_formats), t
5760
| E | Signature cannot be checked (e.g. missing key) |
5861
| N | No signature |
5962
60-
:information_source: The runner that you use to execute this Action might need to be set up with your key management server. This may mean you'll need to chat with your key management / identity management folks to get things set up on a private key server.
63+
> [!NOTE]
64+
> The runner that you use to execute this Action might need to be set up to trust your key management server. This may mean you'll need to chat with your key management / identity management folks to get things set up on a private key server.
6165
6266
## GitHub Enterprise version compatibility
6367
6468
Naturally, this works without any hitch on GitHub.com. As a composite Action that calls other Actions, you'll need to be on at least GitHub Enterprise Server or GitHub AE version 3.3 to use this if you're not in GitHub.com.
6569
66-
:information_source: This references the tag `v3` of [`actions/checkout`](https://github.com/actions/checkout) and [`actions/upload-artifact`](https://github.com/actions/upload-artifact), which is (currently) beyond the version shipped bundled in GHES and GHAE. Your enterprise administrator might need to [update](https://docs.github.com/en/enterprise-server@latest/admin/github-actions/managing-access-to-actions-from-githubcom/using-the-latest-version-of-the-official-bundled-actions) the bundled actions. Alternatively, you can copy this repository to your GHES or GHAE instance and downgrade the versions of these dependencies in that process.
70+
> [!NOTE]
71+
> This references the tag `v4` of [`actions/checkout`](https://github.com/actions/checkout) and [`actions/upload-artifact`](https://github.com/actions/upload-artifact), which may be beyond the version shipped bundled in GHES. Your enterprise administrator might need to [update](https://docs.github.com/en/enterprise-server@latest/admin/github-actions/managing-access-to-actions-from-githubcom/using-the-latest-version-of-the-official-bundled-actions) the bundled actions. Alternatively, you can copy this repository to your GHES instance and downgrade the versions of these dependencies in that process.
6772

6873
## Using it without GitHub Actions
6974

70-
:question: Not using or can't use GitHub Actions? Not a problem - the core logic of this report is a plain [bash script](https://github.com/some-natalie/gitlog-to-csv/blob/main/action.yml#L40-L81) that you can plug into your CI system of choice or run _ad hoc_. To run on an arbitrary machine, you'll need the following:
75+
:question: Not using or can't use GitHub Actions? Not a problem - the core logic of this report is a plain [bash script](git-history-report.sh) that you can plug into your CI system of choice or run _ad hoc_. To run on an arbitrary machine, you'll need the following:
7176

7277
- BASH, of course
7378
- GNU `awk` and `sed`

git-history-report.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/bash
2+
3+
# This script generates a CSV file with the git history of the repository.
4+
# Run from the project's root directory.
5+
6+
# set environment variables
7+
# COMMIT_URL="${{ github.server_url }}/${{ github.repository }}/commit/"
8+
COMMIT_URL="" # makes a nice, clickable link to the commit in the CSV
9+
input_gpg="true" # whether to include GPG signature information
10+
input_diffs="true" # whether to create a diff file for each commit
11+
12+
# git log
13+
if [ $input_gpg = "true" ]; then
14+
git log main --date=local --pretty="%x40%H%x2C%h%x2C%an%x2C%G?%x2C%GS%x2C%GK%x2C%ad%x2C%x22%s%x22%x2C" --shortstat | tr "\n" " " | tr "@" "\n" >> log.csv
15+
else
16+
git log main --date=local --pretty="%x40%H%x2C%h%x2C%an%x2C%ad%x2C%x22%s%x22%x2C" --shortstat | tr "\n" " " | tr "@" "\n" >> log.csv
17+
fi
18+
19+
# sed magic to remove text from number fields
20+
sed -i.bak 's/ files changed//' log.csv
21+
sed -i.bak 's/ file changed//' log.csv
22+
sed -i.bak 's/ insertions(+)//' log.csv
23+
sed -i.bak 's/ insertion(+)//' log.csv
24+
sed -i.bak 's/ deletions(-)//' log.csv
25+
sed -i.bak 's/ deletion(-)//' log.csv
26+
27+
# download diffs if needed
28+
if [ $input_diffs = "true" ]; then
29+
sed -i.bak -e "1d" log.csv # delete blank line at the top
30+
initial_commit_id=$(git rev-list --max-parents=0 HEAD) # get the initial commit id
31+
initial_commit_short_id=$(git rev-list --max-parents=0 HEAD | cut -c 1-7) # get the initial commit short id
32+
git show "$initial_commit_id" > "$initial_commit_short_id".diff # write the first diff to the file
33+
while read -r line; do # loop through the rest of the diffs
34+
commit_id=$(echo "$line" | awk -F"," '{print $1}')
35+
short_commit_id=$(echo "$line" | awk -F"," '{print $2}')
36+
git show "$commit_id" > "$short_commit_id".diff
37+
done < log.csv
38+
fi
39+
40+
# awk to insert the commit url to click and view the diff
41+
awk -F"," 'OFS = ", " {$1 = "'"$COMMIT_URL"'"$1; print}' log.csv > history.csv
42+
43+
# now add that header row
44+
if [ $input_gpg = "true" ]; then
45+
sed -i.bak '1s/.*/url,commit id,author,commit signature status,name of signer,key used to sign,date,comment,changed files,lines added,lines deleted/' history.csv
46+
else
47+
sed -i.bak '1s/.*/url,commit id,author,date,comment,changed files,lines added,lines deleted/' history.csv
48+
fi
49+
50+
# clean up
51+
rm log.csv
52+
rm log.csv.bak
53+
rm history.csv.bak

0 commit comments

Comments
 (0)