Module: ActiveProject::Adapters::GithubRepo::Projects

Included in:
ActiveProject::Adapters::GithubRepoAdapter
Defined in:
lib/active_project/adapters/github_repo/projects.rb

Instance Method Summary collapse

Instance Method Details

#create_project(attributes) ⇒ ActiveProject::Resources::Project

Creates a new repository (project). Note: In most cases users will already have repositories set up.

Parameters:

  • Repository attributes (name, description, etc.)

Returns:

  • The created repository as a project



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/active_project/adapters/github_repo/projects.rb', line 57

def create_project(attributes)
  # Create in organization or user account based on config
  owner = @config.options[:owner]

  # Determine if creating in org or personal account
  begin
    make_request(:get, "orgs/#{owner}")
    path = "orgs/#{owner}/repos"
  rescue NotFoundError
    path = "user/repos"
  end

  data = {
    name: attributes[:name],
    description: attributes[:description],
    private: attributes[:private] || false,
    has_issues: attributes[:has_issues] || true
  }

  repo_data = make_request(:post, path, data)
  map_repository_to_project(repo_data)
end

#delete_project(repo_id) ⇒ Boolean

Deletes a repository. Note: This is a destructive operation and generally not recommended.

Parameters:

  • The ID or full_name of the repository

Returns:

  • True if successfully deleted



84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/active_project/adapters/github_repo/projects.rb', line 84

def delete_project(repo_id)
  # Find the repository first to get its full path
  repo = find_project(repo_id)
  raise NotFoundError, "Repository not found" unless repo

  # Delete requires the full path in "owner/repo" format
  full_path = repo.name # We store full_name in the name field
  make_request(:delete, "repos/#{full_path}")
  true
rescue NotFoundError
  false
end

#find_project(id) ⇒ ActiveProject::Resources::Project?

Finds a specific project by its ID or name. In GitHub’s context, this finds a repository.

Parameters:

  • The ID or full_name of the repository

Returns:

  • The repository as a project



20
21
22
23
24
25
26
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
# File 'lib/active_project/adapters/github_repo/projects.rb', line 20

def find_project(id)
  # If id is nil or empty, use the configured repo
  if id.nil? || id.to_s.empty?
    id = @config.options[:repo]
  end

  # If id matches our configured repo, return that
  if id.to_s == @config.options[:repo] || id.to_s == "#{@config.options[:owner]}/#{@config.options[:repo]}"
    repo_data = make_request(:get, @repo_path)
    return map_repository_to_project(repo_data)
  end

  # Otherwise, try to find by ID or full name
  begin
    repo_data = make_request(:get, "repositories/#{id}")
    map_repository_to_project(repo_data)
  rescue NotFoundError
    # Try with full name path format (owner/repo)
    if id.to_s.include?("/")
      repo_data = make_request(:get, "repos/#{id}")
      map_repository_to_project(repo_data)
    else
      # Try with owner + repo name
      begin
        repo_data = make_request(:get, "repos/#{@config.options[:owner]}/#{id}")
        map_repository_to_project(repo_data)
      rescue NotFoundError
        raise NotFoundError, "GitHub repository with ID or name '#{id}' not found"
      end
    end
  end
end

#list_projectsArray<ActiveProject::Resources::Project>

Lists projects accessible by the configured credentials. In GitHub’s context, this returns the configured repository as a “project”.

Returns:

  • Array containing the repository as a project



10
11
12
13
14
# File 'lib/active_project/adapters/github_repo/projects.rb', line 10

def list_projects
  # Get the configured repository
  repo_data = make_request(:get, @repo_path)
  [ map_repository_to_project(repo_data) ]
end