Skip to content

Commit

Permalink
Merge pull request #168 from samvera/thor-audit-teams
Browse files Browse the repository at this point in the history
Extending the Thor CLI to manage team membership
  • Loading branch information
jrgriffiniii authored Oct 17, 2024
2 parents b4ee2c4 + bb24de0 commit 945e67c
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions cli.thor
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Samvera < Thor
option :updated, type: :string, default: "2021-01-01"
option :created, type: :string, default: "2021-01-01"
option :label, type: :string, default: "stale"
option :project_id, type: :numeric, default: 28
def audit_issues

repo = options[:repo]
Expand Down Expand Up @@ -61,6 +62,10 @@ class Samvera < Thor
else
say("No milestone to remove from Issue ##{issue.number}", :yellow)
end

project_url = "https://github.com/orgs/samvera/projects/#{project_id}"
project_card = client.create_project_card(project_url, content_id: issue.id, content_type: 'Issue')
say("Added Issue ##{issue.number} to Project '#{project_name}'", :green)
rescue Octokit::Error => e
say("Failed to audit Issue ##{issue.number}: #{e.message}", :red)
end
Expand All @@ -70,5 +75,59 @@ class Samvera < Thor
say("-" * 40, :green)
end
end

desc "add_team_member", "Adds a GitHub user to a Samvera Organization Team"
option :user, required: true, type: :string
option :team, type: :string, default: "maintenance"
option :org, type: :string, default: "samvera"
def add_team_member

team_slug = options[:team]
user_login = options[:user]
org = options[:org]

client = Octokit::Client.new(access_token: ENV['GH_TOKEN'])

begin
team = client.team_by_name(org, team_slug)
team_id = team[:id]
client.add_team_membership(team_id, user_login)

say("#{user_login} has been successfully added to the team #{team_slug} in the organization #{org}.", :green)
rescue Octokit::NotFound => not_found_error
say("The team or organization was not found, or the user does not exist: #{not_found_error}", :red)
rescue Octokit::Unauthorized
say("Authentication failed. Please check your personal access token.", :red)
rescue Octokit::UnprocessableEntity
say("The user is already a member of the team.", :yellow)
end
end

desc "remove_team_member", "Remove a GitHub user from a Samvera Organization Team"
option :user, required: true, type: :string
option :team, required: true, type: :string
option :org, type: :string, default: "samvera"
def remove_team_member

team_slug = options[:team]
user_login = options[:user]
org = options[:org]

client = Octokit::Client.new(access_token: ENV['GH_TOKEN'])

begin
team = client.team_by_name(org, team_slug)
team_id = team[:id]
client.remove_team_membership(team_id, user_login)

say("#{user_login} has been successfully removed from the team #{team_slug} in the organization #{org}.", :green)
rescue Octokit::NotFound
say("The team or organization was not found, or the user does not exist.", :red)
rescue Octokit::Unauthorized
say("Authentication failed. Please check your personal access token.", :red)
rescue Octokit::UnprocessableEntity
say("The user is not a member of the team.", :yellow)
end
end
end

0 comments on commit 945e67c

Please sign in to comment.