diff --git a/lib/orgbots.rb b/lib/orgbots.rb index 0c4badd..4cb8b1b 100644 --- a/lib/orgbots.rb +++ b/lib/orgbots.rb @@ -4,12 +4,16 @@ require_relative 'tasks/schedule' require_relative 'config' -# Run through the setup checklist before proceeding -Config.new.checklist +puts TaskManager.new.shuffle_file -# Clear the screen and show a welcome message -system 'clear' -Reporter.new.welcome +# Query.new.authed_ratelimit -# Prompt the user to select which mode to run Orgbots in -Config.new.mode_config +# # Run through the setup checklist before proceeding +# Config.new.checklist + +# # Clear the screen and show a welcome message +# system 'clear' +# Reporter.new.welcome + +# # Prompt the user to select which mode to run Orgbots in +# Config.new.mode_config diff --git a/lib/tasks/random_commit.rb b/lib/tasks/random_commit.rb index 9ff72c3..57c9753 100644 --- a/lib/tasks/random_commit.rb +++ b/lib/tasks/random_commit.rb @@ -12,7 +12,7 @@ def initialize(r, t) def commit content = genword - randombranch = BranchBot.new(@repo, @token).list_branches.sample + randombranch = BranchBot.new(@repo, @token).rand_branch file = pick_file(randombranch) file = genword.to_s + txt_ext if maybe CommitBot.new(@repo, randombranch, @token).commit(file, content, genword) diff --git a/lib/tasks/tasks.rb b/lib/tasks/tasks.rb index f170c76..6ccee16 100644 --- a/lib/tasks/tasks.rb +++ b/lib/tasks/tasks.rb @@ -13,15 +13,11 @@ def initialize @t = ENV['TOKEN'] end - def rand_file_content + def shuffle_rand_file + @message = 'shufflin' @branch = BranchBot.new(@r, @t).list_branches.sample @file = FileBot.new(@r, @t).list_files(@branch).collect { |f| f[:path] }.sample - FileBot.new(@r, @t).get_contents(@file, @branch)[:content] - end - - # Find a branch, find a file on that branch - def shuffle_file - @message = 'shufflin' - RandCommit.new(@r, @t).shuffle_file(@branch, @file, rand_file_content, @message) + @content = FileBot.new(@r, @t).get_contents(@file, @branch)[:content] + RandCommit.new(@r, @t).shuffle_file(@branch, @file, @content, @message) end end diff --git a/lib/utils/brancher.rb b/lib/utils/brancher.rb index 74e7b88..b78c83f 100644 --- a/lib/utils/brancher.rb +++ b/lib/utils/brancher.rb @@ -5,6 +5,7 @@ class BranchBot def initialize(r, t) @c = Octokit::Client.new(access_token: t) @repo = r + @token = t end def list_branches @@ -26,4 +27,8 @@ def delete_branch(branch) @c.delete_ref(@repo, 'heads/' + branch) if list_branches.include?(branch) puts "Deleting #{branch} from #{@repo}" end + + def rand_branch + BranchBot.new(@repo, @token).list_branches.sample.to_s + end end diff --git a/lib/utils/reacter.rb b/lib/utils/reacter.rb index 7b8f2bf..bd3d3df 100644 --- a/lib/utils/reacter.rb +++ b/lib/utils/reacter.rb @@ -17,7 +17,7 @@ def issue_react(issue_id, reaction) end def randemoji(multiple) - moji = Octokit.emojis.to_a.sample(multiple) + moji = @c.emojis.to_a.sample(multiple) str = '' moji.each { |a| str += ":#{a[0]}: " } str diff --git a/test/suppress_output.rb b/test/suppress_output.rb new file mode 100644 index 0000000..4084a09 --- /dev/null +++ b/test/suppress_output.rb @@ -0,0 +1,22 @@ +# Temporarily redirects STDOUT and STDERR to /dev/null +# but does print exceptions should there occur any. +# Call as: +# suppress_output { puts 'never printed' } +# +def suppress_output + begin + original_stderr = $stderr.clone + original_stdout = $stdout.clone + $stderr.reopen(File.new('/dev/null', 'w')) + $stdout.reopen(File.new('/dev/null', 'w')) + retval = yield + rescue Exception => e + $stdout.reopen(original_stdout) + $stderr.reopen(original_stderr) + raise e + ensure + $stdout.reopen(original_stdout) + $stderr.reopen(original_stderr) + end + retval +end \ No newline at end of file diff --git a/test/test_pull_requests.rb b/test/test_pull_requests.rb index f68ce92..9c17472 100644 --- a/test/test_pull_requests.rb +++ b/test/test_pull_requests.rb @@ -1,5 +1,6 @@ require 'test/unit' require 'dotenv/load' +require_relative 'suppress_output' require_relative '../lib/utils/pullrequest' Dotenv.load('orgbot.env') @@ -8,14 +9,14 @@ class TestPullRequest < Test::Unit::TestCase def test_open_prs pr = PRBot.new(ENV['REPO'], ENV['TOKEN']) assert_nothing_raised do - pr.open_prs + suppress_output { pr.open_prs } end end def test_all_pr_comments pr = PRBot.new(ENV['REPO'], ENV['TOKEN']) assert_nothing_raised do - pr.all_pr_comments + suppress_output { pr.all_pr_comments } end end end diff --git a/test/test_reporter.rb b/test/test_reporter.rb index 4f1388b..66c8254 100644 --- a/test/test_reporter.rb +++ b/test/test_reporter.rb @@ -1,11 +1,12 @@ require 'test/unit' +require_relative 'suppress_output' require_relative '../lib/utils/reporter' class TestReporter < Test::Unit::TestCase def test_welcome rep = Reporter.new assert_nothing_raised do - rep.welcome + suppress_output { rep.welcome } end end end