Skip to content

Instantly share code, notes, and snippets.

@jonico
Last active April 16, 2024 19:20
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jonico/f002e0ae5cb37ad2019242b02b7b15fb to your computer and use it in GitHub Desktop.
Save jonico/f002e0ae5cb37ad2019242b02b7b15fb to your computer and use it in GitHub Desktop.
Count all unique committers in the last 90 days on GitHub Enterprise Server
ghe-console -y <<'ENDSCRIPT'
ActiveRecord::Base.connected_to(role: :reading) do
puts "Version 0.2.0"
emails = Set.new
start_time = 90.days.ago.beginning_of_day
Repository.where(active: true).find_each do |repo|
Push
.where(repository: repo)
.where("created_at >= ?", start_time)
.find_each do |push|
push.commits_pushed.each do |commit|
commit.author_emails.each do |email|
emails << email unless UserEmail.belongs_to_a_bot?(email)
end
end
end
end
users = Set.new
emails.each_slice(1000) do |batch|
emails_to_users_hash = User.find_by_emails(batch)
active_users = emails_to_users_hash.values.select do |user|
!(user.disabled? || user.suspended?)
end
users.merge(active_users)
end
puts "Committers in the past 90d: #{users.size}"
end
ENDSCRIPT
@stoe
Copy link

stoe commented Nov 4, 2020

@jonico, what's your thought on changing L6 to git --git-dir=#{path} shortlog -sne --all --since "90 days ago" >> /tmp/committers

Example from this Gist:

$ git shortlog -sne --all --since "90 days ago"
     2  Johannes Nicolai <jonico@github.com>

https://git-scm.com/docs/git-shortlog

@jonico
Copy link
Author

jonico commented Nov 4, 2020

@stoe: have you tested your change? For some reason, the above script did not work any more once I used shortlog

@jonico
Copy link
Author

jonico commented Nov 4, 2020

@stoe: I would love to have a solution where the output is just the e-mail address (neither name nor count), so that we can deduplicate based on e-mail later - could you do that for me :octocat: ❤️ ?

@stoe
Copy link

stoe commented Nov 5, 2020

I can look into it, @jonico

@jonico
Copy link
Author

jonico commented Nov 24, 2020

@stoe: I changed the logic to get closer to the actual GHAS license check in GitHub Enterprise Server

@stoe
Copy link

stoe commented Nov 24, 2020

I changed the logic to get closer to the actual GHAS license check in GitHub Enterprise Server

ghe-console script looks promising, but Ruby-fu is not strong enough to really say if this works.
What could be cool is to wrap that into the way we use in out toolbox: https://github.com/github/services-toolbox/tree/master/scripts/ghes-v2

@cbraynor
Copy link

cbraynor commented Feb 2, 2021

This script is now outdated - we've made improvements (and continue to do so) as customer issues have come up

I've been keeping this comment up to date as we've made changes

Edit: I have permissions to edit so I updated it too

@issc29
Copy link

issc29 commented Feb 2, 2021

I also just created a script from this one that gets the committers from specific orgs based off of organization_id. I would love to do it based off of org name but couldn't figure out how.

[REDACTED] - please don't use

@cbraynor
Copy link

cbraynor commented Feb 2, 2021

https://github.com/github/code-scanning/issues/2537 is trying to solve that, Simon is working on it now

Trying to be really careful how code is distributed - seeing lots of stale / adapted versions of this script around and ideally there's one source of truth so we can keep it updated and consistent and fix issues for all customers

@issc29
Copy link

issc29 commented Feb 2, 2021

@cbraynor great! let me know when its done and then I can put the official ones to use in the SE repo (or a link to the official ones)!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment