From 06e4aaa0a9bb9075f2c10736e78d177c83e316a4 Mon Sep 17 00:00:00 2001 From: Jennie Ohyoung Date: Sun, 21 Jul 2019 22:19:20 -0700 Subject: [PATCH 1/8] add -b tag to iterate through branches --- .../find_inactive_members.rb | 44 ++++++++++++++----- .../find-inactive-members/inactive_users.csv | 1 + .../unrecognized_authors.csv | 0 3 files changed, 34 insertions(+), 11 deletions(-) create mode 100644 api/ruby/find-inactive-members/inactive_users.csv create mode 100644 api/ruby/find-inactive-members/unrecognized_authors.csv diff --git a/api/ruby/find-inactive-members/find_inactive_members.rb b/api/ruby/find-inactive-members/find_inactive_members.rb index 0db91cf06..64bbc42f2 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 @@ -82,7 +83,7 @@ def organization_members # get all organization members and place into an array of hashes info "Finding #{@organization} members " @members = @client.organization_members(@organization).collect do |m| - email = + email = { login: m["login"], email: member_email(m[:login]), @@ -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 @@ -245,6 +263,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 diff --git a/api/ruby/find-inactive-members/inactive_users.csv b/api/ruby/find-inactive-members/inactive_users.csv new file mode 100644 index 000000000..4825862e2 --- /dev/null +++ b/api/ruby/find-inactive-members/inactive_users.csv @@ -0,0 +1 @@ +"JennieOhyoung," diff --git a/api/ruby/find-inactive-members/unrecognized_authors.csv b/api/ruby/find-inactive-members/unrecognized_authors.csv new file mode 100644 index 000000000..e69de29bb From d7168f089698b2c777ee2d876b8b1f182b5fad09 Mon Sep 17 00:00:00 2001 From: Jennie Ohyoung Date: Sun, 21 Jul 2019 22:36:49 -0700 Subject: [PATCH 2/8] updated readme with details around -b --- api/ruby/find-inactive-members/README.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/api/ruby/find-inactive-members/README.md b/api/ruby/find-inactive-members/README.md index 1ed90b0e0..f9e7faa32 100644 --- a/api/ruby/find-inactive-members/README.md +++ b/api/ruby/find-inactive-members/README.md @@ -7,6 +7,7 @@ find_inactive_members.rb - Find and output inactive members in an organization -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 ``` @@ -29,7 +30,7 @@ gem install octokit ### Configure Octokit -The `OCTOKIT_ACCESS_TOKEN` is required in order to see activities on private repositories. However the `OCTOKIT_API_ENDPOINT` isn't required if connecting to GitHub.com, but is required if connecting to a GitHub Enterprise instance. +The `OCTOKIT_ACCESS_TOKEN` is required in order to see activities on private repositories. However the `OCTOKIT_API_ENDPOINT` isn't required if connecting to GitHub.com, but is required if connecting to a GitHub Enterprise Server instance. ```shell export OCTOKIT_ACCESS_TOKEN=00000000000000000000000 # Required if looking for activity in private repositories. @@ -38,9 +39,12 @@ export OCTOKIT_API_ENDPOINT="https:///api/v3" # ## Usage -``` -ruby find_inactive_members.rb [-cehv] -o ORGANIZATION -d DATE -``` +1. 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` +2. Clone this repository `git clone git@github.com:github/platform-samples.git` +3. Navigate to the right directory and set the environment: `export OCTOKIT_ACCESS_TOKEN=[paste token here]` (`OCTOKIT_API_ENDPOINT` is only necessary for GitHub Enterprise Server) +4. Run the report script: `ruby find_inactive_members.rb [-bcehv] -o ORGANIZATION -d DATE` + + ## How Inactivity is Defined From 9cdcf3bb37f9220d7e4b56867c6afec6108b9f22 Mon Sep 17 00:00:00 2001 From: Jennie Ohyoung Date: Sun, 21 Jul 2019 22:41:30 -0700 Subject: [PATCH 3/8] Remove accidentally committed temporary files --- api/ruby/find-inactive-members/inactive_users.csv | 1 - api/ruby/find-inactive-members/unrecognized_authors.csv | 0 2 files changed, 1 deletion(-) delete mode 100644 api/ruby/find-inactive-members/inactive_users.csv delete mode 100644 api/ruby/find-inactive-members/unrecognized_authors.csv diff --git a/api/ruby/find-inactive-members/inactive_users.csv b/api/ruby/find-inactive-members/inactive_users.csv deleted file mode 100644 index 4825862e2..000000000 --- a/api/ruby/find-inactive-members/inactive_users.csv +++ /dev/null @@ -1 +0,0 @@ -"JennieOhyoung," diff --git a/api/ruby/find-inactive-members/unrecognized_authors.csv b/api/ruby/find-inactive-members/unrecognized_authors.csv deleted file mode 100644 index e69de29bb..000000000 From 37a91ad2bd293b2670fb9064e73ed5211c0026bf Mon Sep 17 00:00:00 2001 From: Jennie Ohyoung Date: Sun, 21 Jul 2019 22:45:15 -0700 Subject: [PATCH 4/8] Adding date format --- api/ruby/find-inactive-members/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/api/ruby/find-inactive-members/README.md b/api/ruby/find-inactive-members/README.md index f9e7faa32..349e80217 100644 --- a/api/ruby/find-inactive-members/README.md +++ b/api/ruby/find-inactive-members/README.md @@ -39,10 +39,11 @@ export OCTOKIT_API_ENDPOINT="https:///api/v3" # ## Usage -1. 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` +1. [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` 2. Clone this repository `git clone git@github.com:github/platform-samples.git` 3. Navigate to the right directory and set the environment: `export OCTOKIT_ACCESS_TOKEN=[paste token here]` (`OCTOKIT_API_ENDPOINT` is only necessary for GitHub Enterprise Server) 4. Run the report script: `ruby find_inactive_members.rb [-bcehv] -o ORGANIZATION -d DATE` + * The DATE format is DD-MM-YYYY From f9e5dc26a0da2b1397a1fbf253b8887489c3c6ab Mon Sep 17 00:00:00 2001 From: Jennie Ohyoung Date: Sun, 21 Jul 2019 22:56:46 -0700 Subject: [PATCH 5/8] Reformatting README.md --- api/ruby/find-inactive-members/README.md | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/api/ruby/find-inactive-members/README.md b/api/ruby/find-inactive-members/README.md index 349e80217..c851c09fb 100644 --- a/api/ruby/find-inactive-members/README.md +++ b/api/ruby/find-inactive-members/README.md @@ -3,7 +3,7 @@ ``` 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 @@ -15,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 @@ -39,11 +43,11 @@ export OCTOKIT_API_ENDPOINT="https:///api/v3" # ## Usage -1. [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` -2. Clone this repository `git clone git@github.com:github/platform-samples.git` -3. Navigate to the right directory and set the environment: `export OCTOKIT_ACCESS_TOKEN=[paste token here]` (`OCTOKIT_API_ENDPOINT` is only necessary for GitHub Enterprise Server) -4. Run the report script: `ruby find_inactive_members.rb [-bcehv] -o ORGANIZATION -d DATE` - * The DATE format is DD-MM-YYYY + +``` +ruby find_inactive_members.rb [-bcehv] -o ORGANIZATION -d DATE +``` + From 2bee1bd37e8b0528cf28957cab4b76622901eda3 Mon Sep 17 00:00:00 2001 From: Jennie Ohyoung Date: Mon, 22 Jul 2019 10:46:57 -0700 Subject: [PATCH 6/8] Modified README.md --- api/ruby/find-inactive-members/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/ruby/find-inactive-members/README.md b/api/ruby/find-inactive-members/README.md index c851c09fb..2f953e10d 100644 --- a/api/ruby/find-inactive-members/README.md +++ b/api/ruby/find-inactive-members/README.md @@ -55,6 +55,6 @@ ruby find_inactive_members.rb [-bcehv] -o ORGANIZATION -d DATE Members are defined as inactive if they haven't, since the specified **DATE**, in any repository in the specified **ORGANIZATION**: -* Have not merged or pushed commits into the default branch +* Have not merged or pushed commits into the default branch (all branches with '-b') * Have not opened an Issue or Pull Request * Have not commented on an Issue or Pull Request From 3a0819a23e36347b7900730bdf25f249eaab0a89 Mon Sep 17 00:00:00 2001 From: Jennie Ohyoung Date: Thu, 25 Jul 2019 12:43:09 -0700 Subject: [PATCH 7/8] Update api/ruby/find-inactive-members/find_inactive_members.rb Co-Authored-By: Jared Murrell --- api/ruby/find-inactive-members/find_inactive_members.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/ruby/find-inactive-members/find_inactive_members.rb b/api/ruby/find-inactive-members/find_inactive_members.rb index 64bbc42f2..6f13fd126 100644 --- a/api/ruby/find-inactive-members/find_inactive_members.rb +++ b/api/ruby/find-inactive-members/find_inactive_members.rb @@ -25,7 +25,7 @@ def initialize(options={}) @date = options[:date] @organization = options[:organization] @email = options[:email] - @branches = options[:branches] + @branches = options[:branches] @unrecognized_authors = [] organization_members From 861ff72fcc588a007328b32de634e8757a8ee2eb Mon Sep 17 00:00:00 2001 From: Jared Murrell Date: Fri, 20 Mar 2020 10:19:17 -0400 Subject: [PATCH 8/8] Update api/ruby/find-inactive-members/find_inactive_members.rb --- api/ruby/find-inactive-members/find_inactive_members.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/ruby/find-inactive-members/find_inactive_members.rb b/api/ruby/find-inactive-members/find_inactive_members.rb index 7a4cd0d06..da6b58226 100644 --- a/api/ruby/find-inactive-members/find_inactive_members.rb +++ b/api/ruby/find-inactive-members/find_inactive_members.rb @@ -117,7 +117,7 @@ def commit_activity(repo) info "...commits" begin # Get all the branches so we can loop through them - if @branches + if @branches @client.branches(repo).each do |branch| info "... branch = " + branch["name"] @client.commits_since(repo, @date, {:sha => branch["name"]}).each do |commit|