Skip to content

Commit

Permalink
Use README contents for description of nfcore workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
fbacall committed Jan 31, 2024
1 parent bc4e97d commit f1221a5
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 23 deletions.
10 changes: 5 additions & 5 deletions app/models/concerns/workflow_extraction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ def extractor_class
workflow_class&.extractor_class || Seek::WorkflowExtractors::Base
end

def extractor
def extractor(opts = {})
if is_git_ro_crate?
Seek::WorkflowExtractors::ROCrate.new(git_version, main_workflow_class: workflow_class)
Seek::WorkflowExtractors::ROCrate.new(git_version, main_workflow_class: workflow_class, **opts)
elsif is_already_ro_crate?
Seek::WorkflowExtractors::ROCrate.new(content_blob, main_workflow_class: workflow_class)
Seek::WorkflowExtractors::ROCrate.new(content_blob, main_workflow_class: workflow_class, **opts)
elsif is_git_versioned?
Seek::WorkflowExtractors::GitRepo.new(git_version, main_workflow_class: workflow_class)
Seek::WorkflowExtractors::GitRepo.new(git_version, main_workflow_class: workflow_class, **opts)
else
extractor_class.new(content_blob)
extractor_class.new(content_blob, **opts)
end
end

Expand Down
4 changes: 2 additions & 2 deletions app/models/git_workflow_wizard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class GitWorkflowWizard

attr_reader :next_step, :git_repository

attr_accessor :params, :workflow, :workflow_class
attr_accessor :params, :workflow, :workflow_class, :use_readme_for_description

def run
if new_version?
Expand Down Expand Up @@ -78,7 +78,7 @@ def run
return workflow
end

extractor = workflow.extractor
extractor = workflow.extractor(use_readme_for_description: @use_readme_for_description)
workflow.provide_metadata(extractor.metadata)

@next_step = :provide_metadata
Expand Down
21 changes: 11 additions & 10 deletions lib/scrapers/nfcore_scraper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@ def main_branch(repo)

def workflow_wizard(repo, tag)
GitWorkflowWizard.new(workflow_class: WorkflowClass.find_by_key('nextflow'),
params: {
git_version_attributes: {
main_workflow_path: 'nextflow.config',
git_repository_id: repo.id,
ref: "refs/tags/#{tag}",
name: tag,
comment: "Updated to #{tag}"
}
})
use_readme_for_description: true,
params: {
git_version_attributes: {
main_workflow_path: 'nextflow.config',
git_repository_id: repo.id,
ref: "refs/tags/#{tag}",
name: tag,
comment: "Updated to #{tag}"
}
})
end
end
end
end
2 changes: 1 addition & 1 deletion lib/seek/workflow_extractors/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Base
"name" => "Unrecognized Workflow Type"
}

def initialize(io)
def initialize(io, opts = {})
@io = io.is_a?(String) ? StringIO.new(io) : io
end

Expand Down
2 changes: 1 addition & 1 deletion lib/seek/workflow_extractors/cff.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module WorkflowExtractors
class CFF
FILENAME = 'CITATION.cff'

def initialize(io)
def initialize(io, opts = {})
if io.respond_to?(:path)
@path = io.path
else
Expand Down
6 changes: 4 additions & 2 deletions lib/seek/workflow_extractors/ro_like.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ module WorkflowExtractors
# Abstract extractor class for a "Research Object-like" structured bundle of files,
# e.g. an RO-Crate or an annotated Git repository.
class ROLike < Base
def initialize(obj, main_workflow_class: nil)
def initialize(obj, main_workflow_class: nil, use_readme_for_description: false)
@obj = obj
@main_workflow_class = main_workflow_class
@use_readme_for_description = use_readme_for_description
end

def can_render_diagram?
Expand Down Expand Up @@ -56,7 +57,8 @@ def metadata
end

if file_exists?('README.md')
m[:description] ||= file('README.md').read.force_encoding('utf-8').gsub(/^(---\s*\n.*?\n?)^(---\s*$\n?)/m,'') # Remove "Front matter"
readme = file('README.md').read.force_encoding('utf-8').gsub(/^(---\s*\n.*?\n?)^(---\s*$\n?)/m,'') # Remove "Front matter"
m[:description] = readme if readme.present? && (m[:description].blank? || @use_readme_for_description)
end

m[:workflow_class_id] ||= main_workflow_class&.id
Expand Down
4 changes: 2 additions & 2 deletions test/integration/nfcore_scraper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class NfcoreScraperTest < ActionDispatch::IntegrationTest
assert_equal bot, wf.contributor
assert_equal [project], wf.projects
assert_equal 'nf-core/rnaseq', wf.title
assert_equal 'Nextflow RNA-Seq analysis pipeline, part of the nf-core community.', wf.description
assert_includes wf.description, '**nf-core/rnaseq** is a bioinformatics analysis pipeline'
assert_equal 'MIT', wf.license
assert_equal 'nextflow.config', wf.main_workflow_path
assert_equal '3.0', wf.git_version.name
Expand Down Expand Up @@ -66,7 +66,7 @@ class NfcoreScraperTest < ActionDispatch::IntegrationTest
assert_equal bot, wf.contributor
assert_equal [project], wf.projects
assert_equal 'nf-core/rnaseq', wf.title
assert_equal 'Nextflow RNA-Seq analysis pipeline, part of the nf-core community.', wf.description
assert_includes wf.description, '**nf-core/rnaseq** is a bioinformatics analysis pipeline'
assert_equal 'MIT', wf.license
assert_equal 'nextflow.config', wf.main_workflow_path
assert_equal '3.0', wf.git_version.name
Expand Down

0 comments on commit f1221a5

Please sign in to comment.