Repository navigation
factory(78): #50 Document core package role (close #51 as dup) #131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
shadetheory
wants to merge
2
commits into
master
Choose a base branch
from
factory/78
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,183 @@ | ||
| # 3-Way CLI Pattern | ||
|
|
||
| This package implements a **3-Way CLI Pattern** that provides three complementary ways to interact with the GitHub API: | ||
|
|
||
| ``` | ||
| ┌─────────────────────────────────────────────────────────────────────────────┐ | ||
| │ 3-Way CLI Pattern │ | ||
| ├─────────────────────────────────────────────────────────────────────────────┤ | ||
| │ 1. Facade (Github::) 2. Resources (repos(), issues()) 3. CLI Command │ | ||
| │ Static Access Method Grouping Artisan Command │ | ||
| └─────────────────────────────────────────────────────────────────────────────┘ | ||
| │ | ||
| ▼ | ||
| ┌─────────────────────────────────────────────────────────────────────────────┐ | ||
| │ Core Package Role │ | ||
| │ The Github Class │ | ||
| │ Orchestrates all three access patterns through a single, consistent API │ | ||
| └─────────────────────────────────────────────────────────────────────────────┘ | ||
| ``` | ||
|
|
||
| ## The Three Ways | ||
|
|
||
| ### Way 1: Facade Access (`Github::`) | ||
|
|
||
| Use the `Github` facade for static, convenient access to the API: | ||
|
|
||
| ```php | ||
| use JordanPartridge\GithubClient\Facades\Github; | ||
|
|
||
| // List repositories | ||
| $repos = Github::repos()->all()->dto(); | ||
|
|
||
| // Get a specific repository | ||
| $repo = Github::getRepo('laravel/framework'); | ||
| ``` | ||
|
|
||
| **Use when**: You want the simplest, most direct access to the API without dependency injection. | ||
|
|
||
| ### Way 2: Resource Methods (`repos()`, `issues()`) | ||
|
|
||
| Access the API through resource-specific methods that group related functionality: | ||
|
|
||
| ```php | ||
| use JordanPartridge\GithubClient\Facades\Github; | ||
| use JordanPartridge\GithubClient\ValueObjects\Repo; | ||
|
|
||
| // Repository resource | ||
| $repos = Github::repos()->all()->dto(); | ||
| $name = Repo::fromFullName('laravel/framework'); | ||
| $repo = Github::repos()->get($name); | ||
| Github::repos()->delete($name); | ||
|
|
||
| // Issue resource | ||
| $issue = Github::issues()->create($owner, $repo, $title, $body); | ||
|
|
||
| // Pull request resource | ||
| $pullRequests = Github::pullRequests()->all($owner, $repo); | ||
| ``` | ||
|
|
||
| **Use when**: You want organized access to related API endpoints, or when injecting the client for testability. | ||
|
|
||
| ### Way 3: CLI Command (`php artisan github-client`) | ||
|
|
||
| Use Artisan commands for quick inspections and testing from the command line: | ||
|
|
||
| ```bash | ||
| # Test the GitHub API connection | ||
| php artisan github-client test | ||
|
|
||
| # Show repository information | ||
| php artisan github-client repo --repo=laravel/framework | ||
|
|
||
| # Show recent commits | ||
| php artisan github-client commits --repo=laravel/framework --limit=10 | ||
| ``` | ||
|
|
||
| **Use when**: You need quick access to GitHub data without writing PHP code, or for debugging. | ||
|
|
||
| ## The Core Package Role | ||
|
|
||
| The `Github` class is the **core package** that ties all three access methods together: | ||
|
|
||
| ```php | ||
| namespace JordanPartridge\GithubClient; | ||
|
|
||
| use JordanPartridge\GithubClient\Connectors\GithubConnector; | ||
| use JordanPartridge\GithubClient\Resources\RepoResource; | ||
| use JordanPartridge\GithubClient\Resources\IssuesResource; | ||
| use JordanPartridge\GithubClient\Resources\PullRequestResource; | ||
| // ... all other resources | ||
|
|
||
| class Github | ||
| { | ||
| public function __construct( | ||
| protected GithubConnector $connector, | ||
| ) {} | ||
|
|
||
| // Resource methods - connect to resources | ||
| public function repos(): RepoResource | ||
| { | ||
| return new RepoResource($this); | ||
| } | ||
|
|
||
| public function issues(): IssuesResource | ||
| { | ||
| return new IssuesResource($this); | ||
| } | ||
|
|
||
| public function pullRequests(): PullRequestResource | ||
| { | ||
| return new PullRequestResource($this); | ||
| } | ||
|
|
||
| // ... all other resource methods | ||
| } | ||
| ``` | ||
|
|
||
| ### Core Responsibilities | ||
|
|
||
| 1. **Resource Factory**: Creates resource instances (`repos()`, `issues()`, etc.) | ||
|
|
||
| 2. **Connector Holder**: Maintains a single `GithubConnector` instance for HTTP requests | ||
|
|
||
| 3. **Authentication Gateway**: Routes authentication through `GithubConnector` | ||
|
|
||
| 4. **Rate Limit Tracking**: Provides rate limit information via `getRateLimitStatus()` | ||
|
|
||
| 5. **GitHub App Support**: Handles installation-based authentication via `forInstallation()` and `withApp()` | ||
|
|
||
| ### How the Core Ties Everything Together | ||
|
|
||
| ``` | ||
| ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ | ||
| │ Facade │ │ Resources │ │ CLI │ | ||
| │ Github:: │ │ repos(), │ │ artisan │ | ||
| │ static calls │────▶│ issues() │────▶│ github-client│ | ||
| └──────────────┘ │ pullRequests()│ └──────────────┘ | ||
| └──────────────┘ | ||
| │ | ||
| ▼ | ||
| ┌──────────────┐ | ||
| │ Core │ | ||
| │ Github │ | ||
| │ class │ | ||
| └──────────────┘ | ||
| │ | ||
| ▼ | ||
| ┌──────────────┐ | ||
| │ Connector │ | ||
| │ (HTTP) │ | ||
| └──────────────┘ | ||
| │ | ||
| ▼ | ||
| ┌──────────────┐ | ||
| │ GitHub API │ | ||
| └──────────────┘ | ||
| ``` | ||
|
|
||
| ## Choosing the Right Pattern | ||
|
|
||
| | Scenario | Recommended Pattern | | ||
| |----------|---------------------| | ||
| | Quick script or quick test |_facade (`Github::`) | | ||
| | Class-based architecture |_Inject `Github` class | | ||
| | Related endpoint group | Use resource (`repos()`) | | ||
| | CI/CD scripts or shell automation | CLI command | | ||
| | Debugging | CLI command | | ||
|
|
||
| ## Example: All Three Ways to List Repositories | ||
|
|
||
| ```php | ||
| // Way 1: Facade | ||
| use JordanPartridge\GithubClient\Facades\Github; | ||
| $repos = Github::repos()->all()->dto(); | ||
|
|
||
| // Way 2: Resource | ||
| $repos = Github::repos()->all()->dto(); | ||
|
|
||
| // Way 3: CLI | ||
| // php artisan github-client list-repos | ||
| ``` | ||
|
|
||
| All three ways use the same underlying core package and return the same results. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Example uses undefined
$repoon RHS:$repo = Github::repos()->get($repo);. Should be a literal likeget('owner/repo')or introduce a prior assignment.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 3819b15: the example now builds a Repo with Repo::fromFullName('laravel/framework') and passes it to get() and delete(). pint, phpstan and pest pass locally.