Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LIBTRACK-121 Add jobber_data_platform to Library Tracking #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions exe/analyze
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
#!/usr/bin/env ruby

require "library_version_analysis"
require "optparse"

options = {}
parser = OptionParser.new do |opts|
opts.banner = "Usage: analyze [options] <spreadsheet_id> [repository] [source]"

opts.on("-c", "--config PATH", "Path to config file") do |path|
options[:config_path] = path
end
end

parser.parse!

# Set config path if provided
LibraryVersionAnalysis::Configuration.config_file_path = options[:config_path] if options[:config_path]

# Configure the library
LibraryVersionAnalysis::Configuration.configure

if ARGV.count == 1
spreadsheet_id = ARGV[0]
Expand All @@ -11,9 +29,12 @@ elsif ARGV.count == 2
spreadsheet_id = ""
repository = ARGV[0]
source = ARGV[1]
elsif ARGV.count == 3
spreadsheet_id = ARGV[0]
repository = ARGV[1]
source = ARGV[2]
else
puts "Usage: analyze <spreadsheet_id> <repository> <source>"

puts parser
Kernel.exit(1)
end

Expand Down
1 change: 1 addition & 0 deletions lib/library_version_analysis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require "library_version_analysis/github"
require "library_version_analysis/gemfile"
require "library_version_analysis/npm"
require "library_version_analysis/poetry"
require "library_version_analysis/version"
require "library_version_analysis/slack_notify"
require "pry-byebug"
Expand Down
14 changes: 13 additions & 1 deletion lib/library_version_analysis/check_version_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ def self.run(spreadsheet_id: "", repository: "", source: "")
end

def initialize
LibraryVersionAnalysis::Configuration.configure
# Only configure if not already configured
LibraryVersionAnalysis::Configuration.configure unless LibraryVersionAnalysis::Configuration.keys.any?

if OBFUSCATE_WORDS # rubocop:disable Style/GuardClause
@word_list = []
Expand Down Expand Up @@ -113,6 +114,8 @@ def go(spreadsheet_id:, repository:, source:) # rubocop:disable Metrics/AbcSize,
meta_data, mode = go_npm(spreadsheet_id, repository, source)
when "gemfile"
meta_data, mode = go_gemfile(spreadsheet_id, repository, source)
when "poetry"
meta_data, mode = go_poetry(spreadsheet_id, repository, source)
else
puts "Don't recognize source #{source}"
exit(-1)
Expand All @@ -127,6 +130,15 @@ def go(spreadsheet_id:, repository:, source:) # rubocop:disable Metrics/AbcSize,
}
end

def go_poetry(spreadsheet_id, repository, source)
puts " poetry" if LibraryVersionAnalysis.dev_output?
poetry = Poetry.new(repository)

meta_data, mode = get_version_summary(poetry, "", nil, repository, source)

return meta_data, mode
end

def go_gemfile(spreadsheet_id, repository, source)
puts " gemfile" if LibraryVersionAnalysis.dev_output?
gemfile = Gemfile.new(repository)
Expand Down
17 changes: 12 additions & 5 deletions lib/library_version_analysis/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
module LibraryVersionAnalysis
module Configuration
@config = {}
@config_file_path = File.join(Dir.pwd, '/config/library_version_analysis.yml')

def self.set(key, value)
@config[key] = value
Expand All @@ -15,14 +16,20 @@ def self.keys
@config.keys
end

def self.configure
config_file_path = File.join(Dir.pwd, '/config/library_version_analysis.yml')
def self.config_file_path=(path)
@config_file_path = path
end

if File.exist?(config_file_path)
yaml_config = YAML.load_file(config_file_path)
def self.config_file_path
@config_file_path
end

def self.configure
if File.exist?(@config_file_path)
yaml_config = YAML.load_file(@config_file_path)
else
yaml_config = {}
puts "No config file found! Using defaults." if LibraryVersionAnalysis.dev_output?
puts "No config file found at #{@config_file_path}! Using defaults." if LibraryVersionAnalysis.dev_output?
end

@config[:default_owner_name] = yaml_config.fetch("default_owner_name", :unknown).to_sym
Expand Down
1 change: 1 addition & 0 deletions lib/library_version_analysis/github.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Github
SOURCES = {
"npm": "NPM",
"gemfile": "RUBYGEMS",
"poetry": "PIP",
}.freeze

HTTP_ADAPTER = GraphQL::Client::HTTP.new(URL) do
Expand Down
29 changes: 29 additions & 0 deletions lib/library_version_analysis/poetry.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require "library_version_analysis/ownership"
require "library_version_analysis/configuration"
require "code_ownership"

module LibraryVersionAnalysis
class Poetry
include LibraryVersionAnalysis::Ownership

def initialize(github_repo)
@github_repo = github_repo
end

def get_versions(source) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
parsed_results = {}
meta_data = MetaData.new

puts("\Poetry dependabot") if LibraryVersionAnalysis.dev_output?
add_dependabot_findings(parsed_results, meta_data, @github_repo, source)

puts("Poetry done") if LibraryVersionAnalysis.dev_output?

return parsed_results, meta_data
end

def add_dependabot_findings(parsed_results, meta_data, github_repo, source)
LibraryVersionAnalysis::Github.new.get_dependabot_findings(parsed_results, meta_data, github_repo, source)
end
end
end
49 changes: 49 additions & 0 deletions spec/library_version_analysis/poetry_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
require "spec_helper"

RSpec.describe LibraryVersionAnalysis::Poetry do
let(:github_repo) { "test-repo" }
subject(:poetry) { described_class.new(github_repo) }

describe "#initialize" do
it "initializes with a github repo" do
expect(poetry.instance_variable_get(:@github_repo)).to eq(github_repo)
end
end

describe "#get_versions" do
let(:source) { "test-source" }
let(:github) { instance_double(LibraryVersionAnalysis::Github) }

before do
allow(LibraryVersionAnalysis::Github).to receive(:new).and_return(github)
end

it "returns parsed results and metadata" do
expect(github).to receive(:get_dependabot_findings)
.with({}, kind_of(LibraryVersionAnalysis::MetaData), github_repo, source)

parsed_results, meta_data = poetry.get_versions(source)

expect(parsed_results).to be_a(Hash)
expect(meta_data).to be_a(LibraryVersionAnalysis::MetaData)
end
end

describe "#add_dependabot_findings" do
let(:parsed_results) { {} }
let(:meta_data) { LibraryVersionAnalysis::MetaData.new }
let(:source) { "test-source" }
let(:github) { instance_double(LibraryVersionAnalysis::Github) }

before do
allow(LibraryVersionAnalysis::Github).to receive(:new).and_return(github)
end

it "calls get_dependabot_findings on github instance" do
expect(github).to receive(:get_dependabot_findings)
.with(parsed_results, meta_data, github_repo, source)

poetry.add_dependabot_findings(parsed_results, meta_data, github_repo, source)
end
end
end