Skip to content

Instantly share code, notes, and snippets.

@mohtada-h
Last active January 5, 2025 17:58
Show Gist options
  • Save mohtada-h/6f93e9199b3d361c304c25bd25ac68bd to your computer and use it in GitHub Desktop.
Save mohtada-h/6f93e9199b3d361c304c25bd25ac68bd to your computer and use it in GitHub Desktop.
To calculate the change failure rate, you need to determine the percentage of changes that resulted in a failure, typically indicated by revert commits. Here's how you can calculate it using Git
# Count all commits in the last month
total_commits=$(git log --since='1 month ago' --oneline | wc -l)
# Count revert commits in the last month
revert_commits=$(git log --since='1 month ago' --grep='^Revert' -i --oneline | wc -l)
# Calculate the percentage of revert commits
percentage=$(echo "scale=2; ($revert_commits / $total_commits) * 100" | bc)
echo "Change Failure Rate: $percentage%"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment