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

Add Branch Scanning #258

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
13 changes: 11 additions & 2 deletions api/ruby/find-inactive-members/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@
```
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
```

This utility finds users inactive since a configured date, writes those users to a file `inactive_users.csv`.

## 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
Expand All @@ -38,10 +43,14 @@ export OCTOKIT_API_ENDPOINT="https://<your_github_enterprise_instance>/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**:
Expand Down
42 changes: 32 additions & 10 deletions api/ruby/find-inactive-members/find_inactive_members.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def initialize(options={})
@date = options[:date]
@organization = options[:organization]
@email = options[:email]
@branches = options[:branches]
@unrecognized_authors = []

organization_members
Expand Down Expand Up @@ -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|
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JennieOhyoung: looks as if indenting is broken here

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
Expand Down Expand Up @@ -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
Expand Down