Class: PlanMyStuff::Project
- Inherits:
-
BaseProject
- Object
- BaseProject
- PlanMyStuff::Project
- Defined in:
- lib/plan_my_stuff/project.rb
Overview
Wraps a regular (non-testing) GitHub Projects V2 project.
Inherits all shared find/list/update/hydrate behavior from BaseProject.
Adds create! for regular project creation, and overrides +find+/+list+
to exclude testing projects. For testing projects use TestingProject;
for either type use +BaseProject.find+/+list+.
Follows an ActiveRecord-style pattern:
Project.find/Project.listreturn persisted instancesProjectItem.add_item/ProjectItem.add_draft_itemfor adding itemsProjectItem.move_item/ProjectItem.assignfor item mutations
Class Method Summary collapse
-
.create!(title:, user: nil, visibility: 'internal', custom_fields: {}, readme: '', description: nil) ⇒ PlanMyStuff::Project
Creates a new regular project in the configured organization with PMS metadata.
-
.find(number, paginate: :auto, cursor: nil) ⇒ PlanMyStuff::Project
Finds a regular project by number.
-
.list ⇒ Array<PlanMyStuff::Project>
Lists all regular projects in the configured organization.
Class Method Details
.create!(title:, user: nil, visibility: 'internal', custom_fields: {}, readme: '', description: nil) ⇒ PlanMyStuff::Project
Creates a new regular project in the configured organization with PMS metadata.
27 28 29 30 31 32 33 34 35 36 37 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/project.rb', line 27 def create!(title:, user: nil, visibility: 'internal', custom_fields: {}, readme: '', description: nil) org = PlanMyStuff.configuration.organization = PlanMyStuff::ProjectMetadata.build( user: user, visibility: visibility, custom_fields: custom_fields, ) .validate_custom_fields! org_id = resolve_org_id(org) data = PlanMyStuff.client.graphql( PlanMyStuff::GraphQL::Queries::CREATE_PROJECT, variables: { input: { ownerId: org_id, title: title } }, ) new_project = data.dig(:createProjectV2, :projectV2) || {} project_id = new_project[:id] project_number = new_project[:number] serialized_readme = PlanMyStuff::MetadataParser.serialize!(.to_h, readme) update_input = { projectId: project_id, readme: serialized_readme } update_input[:shortDescription] = description if description.present? PlanMyStuff.client.graphql( PlanMyStuff::GraphQL::Queries::UPDATE_PROJECT, variables: { input: update_input }, ) find(project_number) end |
.find(number, paginate: :auto, cursor: nil) ⇒ PlanMyStuff::Project
Finds a regular project by number. Raises if the project is a testing
project - call TestingProject.find for those, or BaseProject.find
if you want either type.
71 72 73 74 75 76 77 78 79 |
# File 'lib/plan_my_stuff/project.rb', line 71 def find(number, paginate: :auto, cursor: nil) project = super unless project.is_a?(self) raise(ArgumentError, "Project ##{number} is a testing project; use PlanMyStuff::TestingProject.find") end project end |
.list ⇒ Array<PlanMyStuff::Project>
Lists all regular projects in the configured organization.
Testing projects are excluded; use TestingProject.list or
BaseProject.list to reach them.
87 88 89 |
# File 'lib/plan_my_stuff/project.rb', line 87 def list super.select { |p| p.is_a?(self) } end |