Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support active user calculation for self-hosted repos #50

Merged
merged 1 commit into from
Feb 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions billing/Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,23 @@ FROM alpine/git:2.36.3

# Estimates monthly active users of a GIT remote repo, based on past commits
active-users:

RUN mkdir ~/.ssh; \
ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts; \
ssh-keyscan -t rsa gitlab.com >> ~/.ssh/known_hosts
RUN --no-cache --ssh --secret repoUrl git clone --bare --filter=blob:none $repoUrl repo;
RUN apk add --no-cache python3
RUN echo "
from urllib.parse import urlsplit
import sys
p = urlsplit(sys.argv[1])
if p.scheme == 'ssh':
with open('/tmp/.host', 'w') as f:
f.write(p.hostname)
with open('/tmp/.port', 'w') as f:
f.write(str(p.port or 22))
" > parse.py
RUN --no-cache --ssh --secret repoUrl python3 parse.py "$repoUrl" && \
# don't scan if SSH isn't actually used; some environments may actively block it
if [ -f /tmp/.host ]; then \
ssh-keyscan -t rsa -p "$(cat /tmp/.port)" "$(cat /tmp/.host)" > /etc/ssh/ssh_known_hosts; \
fi && \
git clone --bare --filter=blob:none $repoUrl repo;
RUN --no-cache cd repo; \
activeUsers=$(git --no-pager log -s --format="%ae" --since=30.days | grep -v @users.noreply.github.com | sort | uniq -c | awk '$1 >= 3 {print $0}' | wc -l); \
echo ""; \
Expand Down
Loading