webhook_bridge/test_webhook.bash

227 lines
6.8 KiB
Bash
Executable File

#!/usr/bin/env bash
#
set -euo pipefail
IFS=$'\n\t'
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
function main() {
local payload
payload=$(cat <<EOF
{
"ref": "refs/heads/main",
"before": "2a544017179b6bd125deacb7919566e8b62e73ea",
"after": "7e44e5da4af3fe7e3db39f43d4d7be5b7e92170d",
"compare_url": "https://code.fizz.buzz/talexander/webhook_bridge/compare/2a544017179b6bd125deacb7919566e8b62e73ea...7e44e5da4af3fe7e3db39f43d4d7be5b7e92170d",
"commits": [
{
"id": "7e44e5da4af3fe7e3db39f43d4d7be5b7e92170d",
"message": "Add signature verification middleware.\n",
"url": "https://code.fizz.buzz/talexander/webhook_bridge/commit/7e44e5da4af3fe7e3db39f43d4d7be5b7e92170d",
"author": {
"name": "Tom Alexander",
"email": "tom@fizz.buzz",
"username": ""
},
"committer": {
"name": "Tom Alexander",
"email": "tom@fizz.buzz",
"username": ""
},
"verification": null,
"timestamp": "2024-07-15T21:02:30-04:00",
"added": [],
"removed": [],
"modified": [
"Cargo.lock",
"Cargo.toml",
"src/main.rs",
"src/webhook.rs"
]
}
],
"total_commits": 1,
"head_commit": {
"id": "7e44e5da4af3fe7e3db39f43d4d7be5b7e92170d",
"message": "Add signature verification middleware.\n",
"url": "https://code.fizz.buzz/talexander/webhook_bridge/commit/7e44e5da4af3fe7e3db39f43d4d7be5b7e92170d",
"author": {
"name": "Tom Alexander",
"email": "tom@fizz.buzz",
"username": ""
},
"committer": {
"name": "Tom Alexander",
"email": "tom@fizz.buzz",
"username": ""
},
"verification": null,
"timestamp": "2024-07-15T21:02:30-04:00",
"added": [],
"removed": [],
"modified": [
"Cargo.lock",
"Cargo.toml",
"src/main.rs",
"src/webhook.rs"
]
},
"repository": {
"id": 21,
"owner": {
"id": 1,
"login": "talexander",
"login_name": "",
"full_name": "",
"email": "gitea@local.domain",
"avatar_url": "https://code.fizz.buzz/avatars/9d402a89b5a0786f83c1b8c5486fc7ff3d083a54fe20e55c0a776a1932c30289",
"language": "",
"is_admin": false,
"last_login": "0001-01-01T00:00:00Z",
"created": "2023-07-05T22:03:28Z",
"restricted": false,
"active": false,
"prohibit_login": false,
"location": "",
"website": "",
"description": "",
"visibility": "public",
"followers_count": 0,
"following_count": 0,
"starred_repos_count": 0,
"username": "talexander"
},
"name": "webhook_bridge",
"full_name": "talexander/webhook_bridge",
"description": "A server that receives webhooks from gitea and fires off Tekton jobs in response.",
"empty": false,
"private": false,
"fork": false,
"template": false,
"parent": null,
"mirror": false,
"size": 103,
"language": "",
"languages_url": "https://code.fizz.buzz/api/v1/repos/talexander/webhook_bridge/languages",
"html_url": "https://code.fizz.buzz/talexander/webhook_bridge",
"url": "https://code.fizz.buzz/api/v1/repos/talexander/webhook_bridge",
"link": "",
"ssh_url": "git@code.fizz.buzz:talexander/webhook_bridge.git",
"clone_url": "https://code.fizz.buzz/talexander/webhook_bridge.git",
"original_url": "",
"website": "",
"stars_count": 0,
"forks_count": 0,
"watchers_count": 1,
"open_issues_count": 0,
"open_pr_counter": 0,
"release_counter": 0,
"default_branch": "main",
"archived": false,
"created_at": "2024-07-14T18:48:52Z",
"updated_at": "2024-07-15T03:11:13Z",
"archived_at": "1970-01-01T00:00:00Z",
"permissions": {
"admin": true,
"push": true,
"pull": true
},
"has_issues": true,
"internal_tracker": {
"enable_time_tracker": true,
"allow_only_contributors_to_track_time": true,
"enable_issue_dependencies": true
},
"has_wiki": true,
"has_pull_requests": true,
"has_projects": true,
"has_releases": true,
"has_packages": true,
"has_actions": false,
"ignore_whitespace_conflicts": false,
"allow_merge_commits": true,
"allow_rebase": true,
"allow_rebase_explicit": true,
"allow_squash_merge": true,
"allow_rebase_update": true,
"default_delete_branch_after_merge": false,
"default_merge_style": "merge",
"default_allow_maintainer_edit": false,
"avatar_url": "",
"internal": false,
"mirror_interval": "",
"mirror_updated": "0001-01-01T00:00:00Z",
"repo_transfer": null
},
"pusher": {
"id": 1,
"login": "talexander",
"login_name": "",
"full_name": "",
"email": "talexander@noreply.code.fizz.buzz",
"avatar_url": "https://code.fizz.buzz/avatars/9d402a89b5a0786f83c1b8c5486fc7ff3d083a54fe20e55c0a776a1932c30289",
"language": "",
"is_admin": false,
"last_login": "0001-01-01T00:00:00Z",
"created": "2023-07-05T22:03:28Z",
"restricted": false,
"active": false,
"prohibit_login": false,
"location": "",
"website": "",
"description": "",
"visibility": "public",
"followers_count": 0,
"following_count": 0,
"starred_repos_count": 0,
"username": "talexander"
},
"sender": {
"id": 1,
"login": "talexander",
"login_name": "",
"full_name": "",
"email": "talexander@noreply.code.fizz.buzz",
"avatar_url": "https://code.fizz.buzz/avatars/9d402a89b5a0786f83c1b8c5486fc7ff3d083a54fe20e55c0a776a1932c30289",
"language": "",
"is_admin": false,
"last_login": "0001-01-01T00:00:00Z",
"created": "2023-07-05T22:03:28Z",
"restricted": false,
"active": false,
"prohibit_login": false,
"location": "",
"website": "",
"description": "",
"visibility": "public",
"followers_count": 0,
"following_count": 0,
"starred_repos_count": 0,
"username": "talexander"
}
}
EOF
)
curl -v \
--http2-prior-knowledge \
-X POST \
-H 'Content-Type: application/json' \
-H 'X-GitHub-Delivery: 04036b0e-6660-4761-896e-e2b6a7631a22' \
-H 'X-GitHub-Event: push' \
-H 'X-GitHub-Event-Type: push' \
-H 'X-Gitea-Delivery: 04036b0e-6660-4761-896e-e2b6a7631a22' \
-H 'X-Gitea-Event: push' \
-H 'X-Gitea-Event-Type: push' \
-H 'X-Gitea-Signature: ea67493aae634655aed55474e6df6d075f7d5f48c35542c9d5fa5c56f5ed9e79' \
-H 'X-Gogs-Delivery: 04036b0e-6660-4761-896e-e2b6a7631a22' \
-H 'X-Gogs-Event: push' \
-H 'X-Gogs-Event-Type: push' \
-H 'X-Gogs-Signature: ea67493aae634655aed55474e6df6d075f7d5f48c35542c9d5fa5c56f5ed9e79' \
-H 'X-Hub-Signature: sha1=291432b9e22fe0dbdb8c809e4f5c5557fbdd48d8' \
-H 'X-Hub-Signature-256: sha256=ea67493aae634655aed55474e6df6d075f7d5f48c35542c9d5fa5c56f5ed9e79' \
-d @- \
'http://127.0.0.1:8080/hook' <<<"$payload"
}
main "${@}"