Skip to content

Commit

Permalink
commit-json.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
danking committed Dec 11, 2024
1 parent 932d671 commit 34de678
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions scripts/commit-json.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

author_email=$(git log -1 --pretty=format:'%ae')
author_name=$(git log -1 --pretty=format:'%an')

committer_email=$(git log -1 --pretty=format:'%ce')
committer_name=$(git log -1 --pretty=format:'%cn')

commit_id=$(git rev-parse HEAD)
commit_title=$(git log -1 --pretty=%B | head -n 1)
commit_timestamp=$(git log -1 --format=%cd --date=iso-strict)
tree_id=$(git rev-parse --verify HEAD^{tree})
repo_url=$(git config --get remote.origin.url | sed 's/[email protected]:/https:\/\/github.com\//' | sed 's/.git$//') # Convert to HTTPS format

jq -c '.' > commit.json <<EOF
{
"author": {
"email": "$author_email",
"name": "$author_name"
},
"committer": {
"email": "$committer_email",
"name": "$committer_name"
},
"id": "$commit_id",
"message": "$commit_title",
"timestamp": "$commit_timestamp",
"tree_id": "$tree_id",
"url": "$repo_url/commit/$commit_id"
}
EOF

0 comments on commit 34de678

Please sign in to comment.