Adding more functionality
This commit is contained in:
136
tests/webhook-samples.md
Normal file
136
tests/webhook-samples.md
Normal file
@@ -0,0 +1,136 @@
|
||||
# Gitea Webhook Integration Test Samples
|
||||
|
||||
The corrected webhook implementation now properly receives and processes webhook notifications FROM Git platforms like Gitea when new releases are published.
|
||||
|
||||
## Sample Gitea Release Webhook Payload
|
||||
|
||||
When a release is published in Gitea, it sends a webhook payload like this:
|
||||
|
||||
```json
|
||||
{
|
||||
"action": "published",
|
||||
"release": {
|
||||
"id": 123,
|
||||
"tag_name": "v1.2.0",
|
||||
"target_commitish": "main",
|
||||
"name": "Version 1.2.0",
|
||||
"body": "## What's New\n- Added new feature X\n- Fixed bug Y\n- Improved performance\n\n## Breaking Changes\n- None",
|
||||
"url": "https://git.example.com/user/repo/releases/tag/v1.2.0",
|
||||
"html_url": "https://git.example.com/user/repo/releases/tag/v1.2.0",
|
||||
"tarball_url": "https://git.example.com/user/repo/archive/v1.2.0.tar.gz",
|
||||
"zipball_url": "https://git.example.com/user/repo/archive/v1.2.0.zip",
|
||||
"draft": false,
|
||||
"prerelease": false,
|
||||
"created_at": "2025-01-15T10:30:00Z",
|
||||
"published_at": "2025-01-15T10:30:00Z",
|
||||
"author": {
|
||||
"id": 1,
|
||||
"login": "developer",
|
||||
"full_name": "Developer Name"
|
||||
}
|
||||
},
|
||||
"repository": {
|
||||
"id": 456,
|
||||
"name": "my-wordpress-plugin",
|
||||
"full_name": "user/my-wordpress-plugin",
|
||||
"html_url": "https://git.example.com/user/my-wordpress-plugin",
|
||||
"clone_url": "https://git.example.com/user/my-wordpress-plugin.git"
|
||||
},
|
||||
"sender": {
|
||||
"id": 1,
|
||||
"login": "developer"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## How the Webhook Handler Processes This
|
||||
|
||||
1. **Authentication**: Validates the passcode in the URL path
|
||||
2. **Event Detection**: Identifies this as a Gitea release event (`action: "published"`)
|
||||
3. **Version Extraction**: Extracts version "1.2.0" from `tag_name: "v1.2.0"`
|
||||
4. **Changelog Processing**: Uses the release `body` field for changelog
|
||||
5. **Package Creation**: Clones the repository at tag `v1.2.0` and creates distribution package
|
||||
6. **Database Storage**: Stores the new version in `wpdd_software_versions` table
|
||||
7. **Customer Updates**: Customers with valid licenses can now receive the update
|
||||
|
||||
## Sample GitHub Release Webhook Payload
|
||||
|
||||
GitHub uses a similar but slightly different structure:
|
||||
|
||||
```json
|
||||
{
|
||||
"action": "published",
|
||||
"release": {
|
||||
"tag_name": "v1.2.0",
|
||||
"target_commitish": "main",
|
||||
"name": "Version 1.2.0",
|
||||
"body": "Release notes here...",
|
||||
"draft": false,
|
||||
"prerelease": false
|
||||
},
|
||||
"repository": {
|
||||
"name": "my-plugin",
|
||||
"clone_url": "https://github.com/user/my-plugin.git"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Sample Git Push with Tag Webhook
|
||||
|
||||
For platforms that send tag push events instead of release events:
|
||||
|
||||
```json
|
||||
{
|
||||
"ref": "refs/tags/v1.2.0",
|
||||
"repository": {
|
||||
"clone_url": "https://git.example.com/user/repo.git"
|
||||
},
|
||||
"commits": [
|
||||
{
|
||||
"id": "abc123",
|
||||
"message": "Release version 1.2.0"
|
||||
}
|
||||
],
|
||||
"head_commit": {
|
||||
"id": "abc123",
|
||||
"message": "Release version 1.2.0"
|
||||
},
|
||||
"after": "abc123"
|
||||
}
|
||||
```
|
||||
|
||||
## Webhook URL Format
|
||||
|
||||
The webhook URLs generated for each software product follow this format:
|
||||
|
||||
```
|
||||
https://streamers.channel/wp-json/wpdd/v1/webhook/{product_id}/{passcode}
|
||||
```
|
||||
|
||||
Example:
|
||||
```
|
||||
https://streamers.channel/wp-json/wpdd/v1/webhook/123/a1b2c3d4e5f6
|
||||
```
|
||||
|
||||
Where:
|
||||
- `123` is the WordPress post ID of the software product
|
||||
- `a1b2c3d4e5f6` is the randomly generated passcode for security
|
||||
|
||||
## Testing the Integration
|
||||
|
||||
To test this webhook integration:
|
||||
|
||||
1. Create a software product in WordPress admin
|
||||
2. Set the product type to "Software License"
|
||||
3. Configure the Git repository URL and credentials
|
||||
4. Copy the generated webhook URL from the metabox
|
||||
5. Add the webhook URL to your Gitea repository settings:
|
||||
- Go to Settings → Webhooks
|
||||
- Add new webhook with the WPDD URL
|
||||
- Select "Release events" as the trigger
|
||||
- Set Content-Type to "application/json"
|
||||
6. Create and publish a new release in Gitea
|
||||
7. Check the `wpdd_webhook_events` table to see the received payload
|
||||
8. Check the `wpdd_software_versions` table to see the processed release
|
||||
|
||||
This corrected implementation properly receives release notifications FROM Git platforms like Gitea, rather than attempting to push to them.
|
Reference in New Issue
Block a user