-
Notifications
You must be signed in to change notification settings - Fork 56
Allow creation of new workflow version via RO-Crate upload (in UI) #2430
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
base: main
Are you sure you want to change the base?
Changes from all commits
0153355
ec991ad
00b902a
45a22d0
dee3448
ec14250
575e628
75b848a
3cd999e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,28 +5,35 @@ | |
| class WorkflowCrateExtractor | ||
| include ActiveModel::Model | ||
|
|
||
| attr_accessor :ro_crate, :workflow_class, :workflow, :git_version, :params, :update_existing | ||
| attr_accessor :ro_crate, :workflow_class, :workflow, :git_version, :params, :detect_workflow | ||
|
|
||
| validate :resolve_crate | ||
| validate :main_workflow_present?, if: -> { @crate.present? } | ||
| validate :source_url_and_version_present?, if: -> { update_existing } | ||
| validate :find_workflows_matching_id, if: -> { update_existing } | ||
| validate :source_url_and_version_present?, if: -> { detect_workflow } | ||
| validate :find_workflows_matching_id, if: -> { detect_workflow } | ||
|
|
||
| def build | ||
| if valid? | ||
| if update_existing && @existing_workflows.length == 1 | ||
| if detect_workflow && @existing_workflows.length == 1 | ||
| self.workflow = @existing_workflows.first | ||
| if self.workflow.git_versions.map(&:name).include?(@crate['version']&.to_s) | ||
| return self.workflow | ||
| else | ||
| self.workflow.latest_git_version.lock if self.workflow.latest_git_version.mutable? | ||
| self.git_version = self.workflow.latest_git_version.next_version(mutable: true) | ||
| end | ||
| end | ||
| self.workflow ||= default_workflow | ||
| self.git_version ||= workflow.git_version.tap do |gv| | ||
| gv.set_default_git_repository | ||
|
|
||
| # If we have an existing workflow, initialise a new version | ||
| if new_version? | ||
| self.workflow.latest_git_version.lock if self.workflow.latest_git_version.mutable? | ||
| self.git_version = self.workflow.git_versions.build(mutable: true) | ||
| # This is a hacky way of ensuring all the default attributes are set (via the before_validation callbacks) | ||
| self.git_version.valid? | ||
| else | ||
| self.workflow = default_workflow | ||
| self.git_version = workflow.git_version.tap do |gv| | ||
| gv.set_default_git_repository | ||
| end | ||
| end | ||
|
|
||
| self.git_version.name = @crate['version'].to_s if @crate['version'] | ||
| git_version.main_workflow_path = URI.decode_www_form_component(@crate.main_workflow.id) if @crate.main_workflow && [email protected]_workflow.remote? | ||
| if @crate.main_workflow&.diagram && [email protected]_workflow.diagram.remote? | ||
|
|
@@ -117,4 +124,8 @@ def resolve_crate | |
|
|
||
| extract_crate | ||
| end | ||
|
|
||
| def new_version? | ||
| workflow.present? && workflow.persisted? | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -278,6 +278,116 @@ class GitWorkflowVersioningTest < ActionDispatch::IntegrationTest | |||
| assert_equal annotation_count + 1, Git::Annotation.count | ||||
| end | ||||
|
|
||||
| test 'handles errors when creating version metadata' do | ||||
| workflow = FactoryBot.create(:local_git_workflow) | ||||
| person = workflow.contributor | ||||
| original_version = workflow.latest_git_version | ||||
|
|
||||
| repo_count = Git::Repository.count | ||||
|
||||
| repo_count = Git::Repository.count |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assignment to workflow_count is useless, since its value is never read.
| workflow_count = Workflow.count |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assignment to version_count is useless, since its value is never read.
| version_count = Git::Version.count |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assignment to annotation_count is useless, since its value is never read.
| annotation_count = Git::Annotation.count |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assignment to original_version is useless, since its value is never read.