summaryrefslogtreecommitdiff
path: root/app/models/concerns
diff options
context:
space:
mode:
authorZeger-Jan van de Weg <git@zjvandeweg.nl>2017-09-19 09:14:06 +0200
committerKamil Trzcinski <ayufan@ayufan.eu>2017-12-03 12:04:47 +0100
commit25df666156279e5b392b429519b4f4ba01eefaac (patch)
tree6c1283d937cebb3ee4542e5d7bfc974939eff657 /app/models/concerns
parent8ac7f29726989bc0a20ee32780aa18625159f8b4 (diff)
downloadgitlab-ce-25df666156279e5b392b429519b4f4ba01eefaac.tar.gz
Create Ci::Artifacts
To allow jobs/builds to have multiple artifacts, and to start seperating concerns from Ci::Build a new model is created: Ci::Artifact. Changes include the updating of the ArtifactUploader to adapt to a slightly different interface. The uploader expects to be initialized with a `Ci::Build`. Futher a migration with the minimal fields, the needed foreign keys and an index. Last, the way this works is by prepending a module to Ci::Build so we can basically override behaviour but if needed use `super` to get the original behaviour.
Diffstat (limited to 'app/models/concerns')
-rw-r--r--app/models/concerns/artifact_migratable.rb37
1 files changed, 37 insertions, 0 deletions
diff --git a/app/models/concerns/artifact_migratable.rb b/app/models/concerns/artifact_migratable.rb
new file mode 100644
index 00000000000..a14a278df9f
--- /dev/null
+++ b/app/models/concerns/artifact_migratable.rb
@@ -0,0 +1,37 @@
+# Adapter class to unify the interface between mounted uploaders and the
+# Ci::Artifact model
+# Meant to be prepended so the interface can stay the same
+module ArtifactMigratable
+ def artifacts_file
+ artifacts.archive.first&.file || super
+ end
+
+ def artifacts_metadata
+ artifacts.metadata.first&.file || super
+ end
+
+ def artifacts?
+ byebug
+ !artifacts_expired? && artifacts_file.exists?
+ end
+
+ def artifacts_metadata?
+ artifacts? && artifacts_metadata.exists?
+ end
+
+ def remove_artifacts_file!
+ artifacts_file.remove!
+ end
+
+ def remove_artifacts_metadata!
+ artifacts_metadata.remove!
+ end
+
+ def artifacts_file=(file)
+ artifacts.create(project: project, type: :archive, file: file)
+ end
+
+ def artifacts_metadata=(file)
+ artifacts.create(project: project, type: :metadata, file: file)
+ end
+end