class Renuo::Cli::Commands::CommitLeaderboardStage
Attributes
Public Instance Methods
Source
# File lib/renuo/cli/commands/commit_leaderboard_stage.rb, line 21 def run(args, options) abort "No author username given." if args[0].nil? abort "No author avatar url given." if args[1].nil? process_params(args, options) check_required_tools check_if_repository_is_present check_if_commit_is_present append_to_queue(build_commit_payload) end
Private Instance Methods
Source
# File lib/renuo/cli/commands/commit_leaderboard_stage.rb, line 77 def append_to_queue(payload) `echo [] > #{@queue_file_path}` unless File.exist?(@queue_file_path) commits = read_commits_from_queue(payload) if @options.verbose puts ">> Adding commit to the queue:" print_queue_item(payload) end File.open(@queue_file_path, "w") do |file| commits << payload file.write(JSON.generate(commits)) end end
Source
# File lib/renuo/cli/commands/commit_leaderboard_stage.rb, line 64 def build_commit_payload { sha: `git rev-parse HEAD`.strip, message: `git log -1 --pretty=%B`.strip, repository: `basename $(git rev-parse --show-toplevel)`.strip, branch: `git rev-parse --abbrev-ref HEAD`.strip, author: { username: @author_username, avatar_url: @author_avatar_url } } end
Source
# File lib/renuo/cli/commands/commit_leaderboard_stage.rb, line 58 def check_if_commit_is_present return if system("git rev-parse --verify HEAD", out: File::NULL) abort(">> No commits found. Please commit your changes first.") end
Source
# File lib/renuo/cli/commands/commit_leaderboard_stage.rb, line 52 def check_if_repository_is_present return if system("git rev-parse --is-inside-work-tree", out: File::NULL) abort(">> Not a git repository. Please run this command in a git repository.") end
Source
# File lib/renuo/cli/commands/commit_leaderboard_stage.rb, line 46 def check_required_tools return if system("git --version", out: File::NULL) abort(">> Git is not installed. Please install it first.") end
Source
# File lib/renuo/cli/commands/commit_leaderboard_stage.rb, line 107 def print_queue_item(payload) sha = payload[:sha] repository = "#{payload[:repository]}##{payload[:branch]}" message = payload[:message] username = payload[:author][:username] avatar_url = payload[:author][:avatar_url] puts "sha: #{sha}" puts "repository: #{repository}" puts "message: #{message}" puts "username: #{username}" puts "avatar_url: #{avatar_url}" end
Source
# File lib/renuo/cli/commands/commit_leaderboard_stage.rb, line 36 def process_params(args, options) @options = options @author_username = args[0] @author_avatar_url = args[1] @queue_file_path = args[2] || "~/.renuo-commit-leaderboard.json" @queue_file_path = File.expand_path(@queue_file_path) end
Source
# File lib/renuo/cli/commands/commit_leaderboard_stage.rb, line 91 def read_commits_from_queue(payload) commits = nil File.open(@queue_file_path, "r") do |file| commits = JSON.parse(file.read) if commits.any? { |commit| commit["sha"] == payload[:sha] } abort(">> Commit has already been added to the queue") end rescue JSON::ParserError abort(">> Invalid JSON format in the queue file.") end commits end
Source
# File lib/renuo/cli/commands/commit_leaderboard_stage.rb, line 121 def truncate_text(text, truncate_length) text[0..truncate_length] end