diff --git a/api/ruby/find-inactive-members/README.md b/api/ruby/find-inactive-members/README.md index cd85238b7..ac537b133 100644 --- a/api/ruby/find-inactive-members/README.md +++ b/api/ruby/find-inactive-members/README.md @@ -3,10 +3,11 @@ ``` find_inactive_members.rb - Find and output inactive members in an organization -c, --check Check connectivity and scope - -d, --date MANDATORY Date from which to start looking for activity + -d, --date MANDATORY Date from which to start looking for activity. The format is DD-MM-YYYY -e, --email Fetch the user email (can make the script take longer -o, --organization MANDATORY Organization to scan for inactive users -v, --verbose More output to STDERR + -b, --branches Iterate through all branches instead of only checking the default branch -h, --help Display this help ``` @@ -14,6 +15,10 @@ This utility finds users inactive since a configured date, writes those users to ## Installation +### Generate a token + +[Generate new GitHub token](https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line) with scopes `repo` and `admin:org` + ### Clone this repository ```shell @@ -38,10 +43,14 @@ export OCTOKIT_API_ENDPOINT="https:///api/v3" # ## Usage + ``` -ruby find_inactive_members.rb [-cehv] -o ORGANIZATION -d DATE +ruby find_inactive_members.rb [-bcehv] -o ORGANIZATION -d DATE ``` + + + ## How Inactivity is Defined Members are defined as inactive if they **have not performed** any of the following actions in any repository in the specified **ORGANIZATION** since the specified **DATE**: diff --git a/api/ruby/find-inactive-members/find_inactive_members.rb b/api/ruby/find-inactive-members/find_inactive_members.rb index 4bc249f3e..da6b58226 100644 --- a/api/ruby/find-inactive-members/find_inactive_members.rb +++ b/api/ruby/find-inactive-members/find_inactive_members.rb @@ -25,6 +25,7 @@ def initialize(options={}) @date = options[:date] @organization = options[:organization] @email = options[:email] + @branches = options[:branches] @unrecognized_authors = [] organization_members @@ -115,16 +116,33 @@ def commit_activity(repo) # get all commits after specified date and iterate info "...commits" begin - @client.commits_since(repo, @date).each do |commit| - # if commmitter is a member of the org and not active, make active - if commit["author"].nil? - add_unrecognized_author(commit[:commit][:author]) - next - end - if t = @members.find {|member| member[:login] == commit["author"]["login"] && member[:active] == false } - make_active(t[:login]) - end - end + # Get all the branches so we can loop through them + if @branches + @client.branches(repo).each do |branch| + info "... branch = " + branch["name"] + @client.commits_since(repo, @date, {:sha => branch["name"]}).each do |commit| + # if commmitter is a member of the org and not active, make active + if commit["author"].nil? + add_unrecognized_author(commit[:commit][:author]) + next + end + if t = @members.find {|member| member[:login] == commit["author"]["login"] && member[:active] == false } + make_active(t[:login]) + end + end + end + else + @client.commits_since(repo, @date).each do |commit| + # if commmitter is a member of the org and not active, make active + if commit["author"].nil? + add_unrecognized_author(commit[:commit][:author]) + next + end + if t = @members.find {|member| member[:login] == commit["author"]["login"] && member[:active] == false } + make_active(t[:login]) + end + end + end rescue Octokit::Conflict info "...no commits" rescue Octokit::NotFound @@ -261,6 +279,10 @@ def member_activity options[:verbose] = v end + opts.on('-b', '--branches', "Iterate through all branches instead of default") do |b| + options[:branches] = b + end + opts.on('-h', '--help', "Display this help") do |h| puts opts exit 0