Class: PlanMyStuff::Project

Inherits:
BaseProject show all
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.list` return persisted instances

  • ‘ProjectItem.add_item` / `ProjectItem.add_draft_item` for adding items

  • ‘ProjectItem.move_item` / `ProjectItem.assign` for item mutations

Constant Summary

Constants inherited from BaseProject

BaseProject::ITEMS_PER_PAGE, BaseProject::MAX_AUTO_PAGINATE_ITEMS

Instance Attribute Summary

Attributes inherited from ApplicationRecord

#github_response

Class Method Summary collapse

Methods inherited from BaseProject

clone!, #closed, #description, #fields, #has_next_page, #id, #items, #metadata, #next_cursor, #number, #pms_project?, #raw_readme, #readme, #reload, resolve_default_project_number, #save!, #status_field, #statuses, #title, update!, #update!, #updated_at, #url

Methods inherited from ApplicationRecord

#destroyed?, #initialize, #new_record?, #persisted?, read_field

Constructor Details

This class inherits a constructor from PlanMyStuff::ApplicationRecord

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.

Parameters:

  • title (String)
  • user (Object, Integer, nil) (defaults to: nil)

    user object or user_id

  • visibility (String) (defaults to: 'internal')

    “public” or “internal”

  • custom_fields (Hash) (defaults to: {})

    app-defined field values

  • readme (String) (defaults to: '')

    user-visible readme content

  • description (String, nil) (defaults to: nil)

    project short description

Returns:



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.

Parameters:

  • number (Integer)
  • paginate (Symbol) (defaults to: :auto)

    :auto (default) or :cursor

  • cursor (String, nil) (defaults to: nil)

    pagination cursor for :cursor mode

Returns:

Raises:

  • (ArgumentError)

    if the project is a testing project



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

.listArray<PlanMyStuff::Project>

Lists all regular projects in the configured organization. Testing projects are excluded; use TestingProject.list or BaseProject.list to reach them.

Returns:



87
88
89
# File 'lib/plan_my_stuff/project.rb', line 87

def list
  super.select { |p| p.is_a?(self) }
end