Top Level Namespace
Defined Under Namespace
Classes: Assistant, Github, Htmlout, Issue, PddIssue, PullRequest, Report, ReportItems, Stdout, Txtout
Instance Method Summary collapse
- #date_one_week_ago(today) ⇒ Object
-
#generate ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity.
- #join(items) ⇒ Object
-
#load_environment_variables ⇒ Object
rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity.
- #week_of_a_year(project, today) ⇒ Object
Instance Method Details
#date_one_week_ago(today) ⇒ Object
76 77 78 79 80 |
# File 'lib/newsman/github.rb', line 76 def date_one_week_ago(today) today = Date.parse(today) unless today.is_a?(Date) one_week_ago = today - 7 one_week_ago.strftime('%Y-%m-%d') end |
#generate ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/newsman.rb', line 39 def generate # Load all options required # Pay attention that some of them have default values. = {} OptionParser.new do |opts| opts. = 'Usage: newsman [options]' opts.on('-n', '--name NAME', 'Reporter name. Human readable name that will be used in a report') do |n| [:name] = n end opts.on('-u', '--username USERNAME', "GitHub username. For example, 'volodya-lombrozo'") do |u| [:username] = u end opts.on('-r', '--repository REPOSITORIES', 'Specify which repositories to include in a report.'\ 'You can specify several repositories using a comma separator,'\ "for example: '-r objectionary/jeo-maven-plugin,objectionary/opeo-maven-plugin'") do |r| [:repositories] = r end opts.on('-p', '--position POSITION', "Reporter position in a company. Default value is a 'Software Developer'.") do |p| [:position] = p end opts.on('-o', '--output OUTPUT', 'Output type. Newsman prints a report to a stdout by default.'\ "You can choose another options like '-o html', '-o txt' or even '-o html'") do |o| [:output] = o end opts.on('-t', '--title TITLE', 'Project Title. Empty by default') { |t| [:title] = t } opts.on('-m', '--model MODEL', 'AI model to use. gpt-3.5-turbo by default') { |m| [:model] = m } end.parse! # Custom method to raise exception with a human-readable message def .require_option(key, ) raise OptionParser::MissingArgument, if self[key].nil? end # Check for required options .require_option(:name, 'Reporter name is required. Please specify using -n or --name.') .require_option(:username, 'GitHub username is required. Please specify using -u or --username.') .require_option(:repositories, 'GitHub repository is required.'\ ' Please specify one or several repositories using -r or --repositories.') [:position] ||= 'Software Developer' [:output] ||= 'stdout' [:title] ||= '' [:model] ||= 'gpt-3.5-turbo' all_params = .map { |key, value| "#{key}: #{value}" }.join(', ') puts "Parsed parameters: #{all_params}" load_environment_variables # Init all required parameters Reporter Info reporter = [:name] reporter_position = [:position] # GitHub github_username = [:username] github_repositories = [:repositories].split(',').map { |repo| "repo:#{repo}" }.join(' ') # Your GitHub personal access token # Make sure it has the 'repo' github_token = ENV['GITHUB_TOKEN'] # Your OpenAI personal access token openai_token = ENV['OPENAI_TOKEN'] # Create a GitHub client instance with your access token github = Github.new(github_token) prs = github.pull_requests(github_username, github_repositories) issues = github.issues(github_username, github_repositories) puts "\nNow lets test some aggregation using OpenAI\n\n" assistant = Assistant.new(openai_token, model: [:model]) # Build previous results answer = '' prs.group_by(&:repository).each do |repository, rprs| puts "Building a results report for the repository: #{repository}" answer = "#{answer}\n#{assistant.prev_results(join(rprs))}" end # Build next plans issues_full_answer = '' issues.group_by(&:repo).each do |repository, rissues| puts "Building a future plans report for the repository: #{repository}" issues_full_answer = "#{issues_full_answer}\n#{assistant.next_plans(join(rissues))}" end # Build report report = Report.new( reporter, reporter_position, [:title], additional: ReportItems.new(prs, issues) ) full_answer = assistant.format(report.build( answer, issues_full_answer, assistant.risks(join(prs)), Date.today )) full_answer = report.append_additional(full_answer) output_mode = [:output] puts "Output mode is '#{output_mode}'" if output_mode.eql? 'txt' puts 'Print result to txy file' output = Txtout.new('.') output.print(full_answer, github_username) elsif output_mode.eql? 'html' puts 'Print result to html file' output = Htmlout.new('.') output.print(full_answer, github_username, [:model]) else puts 'Print result to stdout' output = Stdout.new output.print(full_answer) end end |
#join(items) ⇒ Object
152 153 154 |
# File 'lib/newsman.rb', line 152 def join(items) "[#{items.map(&:to_json).join(',')}]" end |
#load_environment_variables ⇒ Object
rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
147 148 149 150 |
# File 'lib/newsman.rb', line 147 def load_environment_variables Dotenv.load Dotenv.require_keys('GITHUB_TOKEN', 'OPENAI_TOKEN') end |
#week_of_a_year(project, today) ⇒ Object
61 62 63 64 |
# File 'lib/newsman/report.rb', line 61 def week_of_a_year(project, today) number = today.strftime('%U').to_i + 1 "WEEK #{number} #{project}" end |