Class: PlanMyStuff::AttachmentUploader
- Inherits:
-
Object
- Object
- PlanMyStuff::AttachmentUploader
- Defined in:
- lib/plan_my_stuff/attachment_uploader.rb
Overview
Uploads attachment files to a shared attachment repo (config.attachment_repo under config.organization) using GitHub’s Git Data API, returning SHA-pinned raw.githubusercontent.com permalinks wrapped in PlanMyStuff::Attachment instances.
One commit per batch (atomic): all files in a single upload_all! call land in the same tree/commit so partial failures cannot leave config.main_branch in an inconsistent state.
The attachment repo is assumed to exist; the uploader does not create it. Per-source-repo attachments are namespaced under <repo_key>/issue-<number>/<uuid>.<ext>, where repo_key falls back to repo.name for repos resolved without a config.repos entry.
Class Method Summary collapse
-
.upload_all!(repo:, issue_number:, files:) ⇒ Array<PlanMyStuff::Attachment>
Uploads each entry in
filesto the attachment repo and returns the resultingAttachmentinstances.
Class Method Details
.upload_all!(repo:, issue_number:, files:) ⇒ Array<PlanMyStuff::Attachment>
Uploads each entry in files to the attachment repo and returns the resulting Attachment instances. Order is not preserved: passthrough Attachment entries are returned before newly-uploaded ones. Attachment entries are passed through untouched (no upload), supporting round-trip through Comment#save! without double-uploading.
Empty / nil files short-circuits with no API calls.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/plan_my_stuff/attachment_uploader.rb', line 38 def upload_all!(repo:, issue_number:, files:) entries = Array.wrap(files) return [] if entries.empty? slots = entries.map { |entry| classify(entry) } = slots.grep(PlanMyStuff::Attachment) pending = slots.grep(Hash) return if pending.blank? commit_sha = create_commit!(repo: repo, issue_number: issue_number, pending: pending) pending.each do |slot| slot[:attachment] = (commit_sha: commit_sha, slot: slot) end publish_commit!(commit_sha) + pending.pluck(:attachment) end |