You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Refactor: Remove models, use array-based API interaction
This commit completes a major refactoring to remove data model objects for API requests and responses. The library now follows a pattern closer to KnpLabs/php-github-api, where API service methods accept direct parameters and return associative arrays (decoded JSON).
Key changes include:
1. **Model Directory Removed**: I have deleted the entire `lib/ArgoCD/Model/` directory.
2. **Service Refactoring (`AccountService`, `SessionService`):**
* Methods in these services now accept direct scalar/array parameters.
* Request bodies are constructed internally as associative arrays.
* Responses are returned directly as associative arrays.
3. **`Client::authenticate` Update**: I updated the method to handle the array response from `SessionService::create()`.
4. **`ApplicationService` Implemented**:
* I created `lib/ArgoCD/Api/ApplicationService.php`.
* Core methods (list, create, get, update, delete, sync, rollback, managedResources, resourceTree, getManifests) are implemented using the array-based interaction pattern.
5. **Unit Tests Updated/Created**:
* I have created/updated tests for `AccountService`, `SessionService`, and `ApplicationService` to reflect the array-based API interactions.
6. **Documentation (`AI.md`) Updated**: `AI.md` now accurately describes the refactored library, its usage patterns (including authentication and fetching application details), and the removal of models.
7. **Test Cleanup**: I removed obsolete organization-related tests.
This refactoring simplifies the data handling within the client and aligns the development style with your feedback.
Copy file name to clipboardExpand all lines: AI.md
+92-12Lines changed: 92 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -4,27 +4,107 @@ This document provides context on the development process of this PHP client for
4
4
5
5
## Project Goal
6
6
7
-
The primary goal of this project was to refactor an existing PHP client library originally designed for the GitHub API (KnpLabs/php-github-api) and adapt it to become a fully functional client for the ArgoCD REST API.
7
+
The primary goal of this project was to refactor an existing PHP client library (originally forked from a GitHub API client) and adapt it to become a fully functional client for the ArgoCD REST API. A key aspect of the refactoring was to move away from a model-based approach for requests and responses to a more direct, array-based interaction style, similar to the KnpLabs/php-github-api library.
8
8
9
9
## Development Process
10
10
11
11
The development process involved a collaborative effort between a human developer and the AI agent, Jules. Key aspects of this process include:
12
12
13
-
***Initial Request:** The human developer provided an issue statement outlining the need to fork the GitHub library, study its structure, and then refactor it to implement ArgoCD's OpenAPI specification (`https://raw.githubusercontent.com/argoproj/argo-cd/master/assets/swagger.json`).
13
+
***Initial Request:** The human developer provided an issue statement outlining the need to fork the GitHub library, study its structure, and then refactor it to implement ArgoCD's OpenAPI specification (`reference/argocd_swagger.json`).
14
14
***Codebase Analysis:** Jules explored the existing GitHub client's codebase using tools to list files and read their content to understand its architecture and patterns.
15
15
***OpenAPI Analysis:** Jules fetched and analyzed the ArgoCD OpenAPI specification to understand its endpoints, data structures, and service organization.
16
-
***Planning:** Based on the analysis, Jules created a detailed, multi-step plan to execute the refactoring. This plan was reviewed and approved by the human developer.
16
+
***Planning & Refactoring Strategy:** Based on the analysis, Jules created a detailed, multi-step plan. A significant decision during this phase was to refactor the library to **remove dedicated Model classes** for API requests and responses.
17
+
* API methods now accept direct parameters (strings, arrays, booleans, etc.).
18
+
* Request bodies are constructed internally as associative arrays.
19
+
* API methods return associative arrays directly, representing the decoded JSON responses from the ArgoCD API.
20
+
* This array-based approach for request/response handling aligns more closely with the interaction style of the KnpLabs/php-github-api library.
17
21
***Iterative Implementation:** Jules executed the plan step-by-step by delegating specific, actionable tasks to a "Worker" agent. These tasks included:
18
-
* Creating new directory structures.
19
-
* Adapting core classes that are derived from the fork, to work with the constraints of ArgoCD.
22
+
* Creating new directory structures and removing old Model directories (e.g., `lib/ArgoCD/Model/`).
23
+
* Adapting core classes derived from the fork to work with the constraints of ArgoCD and the new array-based data handling.
20
24
* Implementing exception handling.
21
-
* Implementing API classes (e.g., `Sessions.php`, `Accounts.php`) with methods corresponding to ArgoCD API operations.
22
-
* Interaction with these methods should be like [KnpLabs/php-github-api](https://github.com/KnpLabs/php-github-api).
23
-
* Any other validation is done through the parameter resolver like in [KnpLabs/php-github-api](https://github.com/KnpLabs/php-github-api).
24
-
***Feedback Incorporation:** The human developer provided feedback at various stages (e.g., on directory structure, PHP version constraints), and Jules updated the plan and execution accordingly.
25
+
* Implementing API service classes (e.g., `SessionService.php`, `AccountService.php`, `ApplicationService.php`) with methods corresponding to ArgoCD API operations. These methods were designed to accept direct parameters and return associative arrays.
26
+
* Generating unit tests for the service classes, ensuring they correctly handle array-based inputs and outputs.
27
+
***Feedback Incorporation:** The human developer provided feedback at various stages (e.g., on directory structure, PHP version constraints, refactoring strategy), and Jules updated the plan and execution accordingly.
28
+
29
+
## Library Usage Examples
30
+
31
+
### Authentication
32
+
33
+
To use the client, first instantiate it and then authenticate.
34
+
35
+
**Username/Password Authentication:**
36
+
```php
37
+
<?php
38
+
require_once __DIR__ . '/vendor/autoload.php'; // Adjust path as needed
39
+
40
+
$client = new \ArgoCD\Client('https://your-argocd-server.com');
print_r($appsList); // $appsList is an associative array
90
+
91
+
// Get details for a specific application
92
+
$appName = 'my-sample-app';
93
+
$appDetails = $applicationApi->get($appName);
94
+
echo "\nDetails for application '$appName':\n";
95
+
print_r($appDetails); // $appDetails is an associative array
96
+
97
+
} catch (\ArgoCD\Exception\RuntimeException $e) {
98
+
echo "API Error: " . $e->getMessage() . "\n";
99
+
}
100
+
```
101
+
Methods like `list()` and `get()` return associative arrays containing the application data directly decoded from the API's JSON response.
102
+
103
+
## Library Status
104
+
105
+
The refactoring to an array-based interaction style for the `AccountService`, `SessionService`, and `ApplicationService` is complete. These services now accept direct parameters for requests and return associative arrays for responses, simplifying their usage.
25
106
26
107
## Acknowledgements
27
108
28
-
* The initial structure and patterns were derived from the excellent [KnpLabs/php-github-api](https://github.com/KnpLabs/php-github-api) library.
29
-
* The target API is [ArgoCD](https://argo-cd.readthedocs.io/en/stable/), and its OpenAPI specification was used as the blueprint for API implementation.
30
-
* You can find the OpenAPI spec in `reference/argocd_swagger.json`.
109
+
* The initial structure and patterns were derived from the excellent [KnpLabs/php-github-api](https://github.com/KnpLabs/php-github-api) library. The refactoring aimed to bring the request/response handling closer to this style.
110
+
* The target API is [ArgoCD](https://argo-cd.readthedocs.io/en/stable/), and its OpenAPI specification (available in `reference/argocd_swagger.json` in this repository) was used as the blueprint for API implementation.
0 commit comments