Skip to content
Merged
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
10 changes: 3 additions & 7 deletions app/jobs/upload_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ class DataNotFoundError < StandardError; end

VALID_LOCALES = Locales.load_locales.freeze

@skip_job = false

ProjectContentQuery = GithubApi::Client.parse <<-GRAPHQL
query($owner: String!, $repository: String!, $expression: String!) {
repository(owner: $owner, name: $repository) {
Expand Down Expand Up @@ -63,7 +61,7 @@ def perform(payload)

projects_data.data.repository.object.entries.each do |project_dir|
project = format_project(project_dir, locale, repository(payload), owner(payload))
if @skip_job
if project[:build] == false
Rails.logger.warn "Build skipped for #{project[:name]}"
next
end
Expand Down Expand Up @@ -107,10 +105,8 @@ def format_project(project_dir, locale, repository, owner)
proj_config_file = data.entries.find { |file| file.name == PROJECT_CONFIG }
proj_config = YAML.safe_load(proj_config_file.object.text, symbolize_names: true)

if proj_config[:build] == false
@skip_job = true
return proj_config
end
# if the build is false, no need to check files, just return the config
return proj_config if proj_config[:build] == false

files = data.entries.reject { |file| file.name == PROJECT_CONFIG }
categorized_files = categorize_files(files, project_dir, locale, repository, owner)
Expand Down
54 changes: 54 additions & 0 deletions spec/jobs/upload_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,60 @@
end
end

context 'with multiple projects where an earlier one has build set to false' do
let(:raw_response) { modifiable_response.deep_dup }

before do
entries = raw_response['data']['repository']['object']['entries']

# Turn the existing project into a build: false project
build_false_dir = entries.find { |entry| entry['name'] == 'dont-collide-starter' }
build_false_config = build_false_dir['object']['entries'].find { |entry| entry['name'] == 'project_config.yml' }
build_false_config['object']['text'] += "build: false\n"

# add second project with build set to true
entries << {
'name' => 'build-me-starter',
'object' => {
'__typename' => 'Tree',
'entries' => [
{
'name' => 'main.py',
'extension' => '.py',
'object' => {
'__typename' => 'Blob',
'text' => "print('hello')\n",
'isBinary' => false
}
},
{
'name' => 'project_config.yml',
'extension' => '.yml',
'object' => {
'__typename' => 'Blob',
'text' => "name: \"Build Me\"\nidentifier: \"build-me-starter\"\ntype: \"python\"\nbuild: true\n",
'isBinary' => true
}
}
]
}
}

allow(GithubApi::Client).to receive(:query).and_return(graphql_response)
allow(ProjectImporter).to receive(:new).and_call_original
end

it 'still imports the later buildable project' do
expect { described_class.perform_now(payload) }.to change(Project, :count).by(1)
expect(Project.find_by(identifier: 'build-me-starter', locale: 'ja-JP')).to be_present
end

it 'does not import the build: false project' do
described_class.perform_now(payload)
expect(Project.find_by(identifier: 'dont-collide-starter', locale: 'ja-JP')).to be_nil
end
end

context 'when GitHub returns nothing for the locale' do
let(:raw_response) { { data: { repository: nil } } }

Expand Down
Loading