本页介绍了 Secure Source Manager Webhook。如需设置 Webhook,请按照设置 Webhook 中的说明操作。
Webhook 是由 Secure Source Manager 代码库中的事件触发的 HTTP 请求,然后发送到用户指定的网址。
网络钩子设置
Webhook 只能在 Secure Source Manager 网页界面中配置。以下字段可配置:
- 钩子 ID
- Webhook 的人类可读名称。钩子 ID 必须遵循资源命名惯例。它们只能包含小写字母、数字或短划线,必须以字母开头,并且在创建 Webhook 后无法更改。
- 目标网址
- 网络钩子目标网址。webhook 目标是一个开放的公共网址。
- 敏感查询字符串
敏感查询字符串会以
TARGET_URL?SENSITIVE_QUERY_STRING格式附加到目标网址的末尾。大多数服务都会提供令牌或密钥,以确保传入请求来自已获授权的服务。为了验证请求,您可以将所需的令牌或密钥存储在敏感的查询字符串中。
- 触发对象
触发 webhook 请求的事件。选项包括:推送(在向代码库推送时触发)或拉取请求状态已更改(在拉取请求打开、关闭、重新打开或修改时触发)。
- 推送事件的 Git 引用过滤条件
一个过滤条件,用于指定要针对推送事件报告哪些分支(以 glob 模式指定)。如需了解语法,请参阅 glob 文档。
- 有效
如果选择此选项,Webhook 会在触发事件时发送请求。如果未选中,则不发送任何请求。
测试 Webhook
配置网络钩子后,您可以使用网络钩子标签页中的测试传送按钮来测试网络钩子。
活动信息示例
以下示例展示了 Secure Source Manager 针对不同 webhook 事件发送到目标网址的事件信息。
推送事件载荷
推送事件载荷的内容类似于以下内容:
标题
Request URL: https://example.com?{sensitive_query_string_placeholder}
Request method: POST
Content-Type: application/json
X-SecureSourceManager-Delivery: 6546af81-25c6-46d9-aa41-70c00dc67752
X-SecureSourceManager-Event: push
X-SecureSourceManager-Signature:
正文
{
"secret": "",
"ref": "refs/heads/main",
"before": "f22fe95d6097bc18ba2ace7c5808ef53c0211a2e",
"after": "85c7e78e6dfb63bcad4a0bb0953c0b3554ed0e93",
"compare_url": "https://my-instance-123456789.us-central1.sourcemanager.dev/my-project/my-repo/compare/f22fe95d6097bc18ba2ace7c5808ef53c0211a2e...85c7e78e6dfb63bcad4a0bb0953c0b3554ed0e93",
"commits": [
{
"id": "85c7e78e6dfb63bcad4a0bb0953c0b3554ed0e93",
"message": "Push Event'\n",
"url": "https://my-instance-123456789.us-central1.sourcemanager.dev/my-project/my-repo/commit/85c7e78e6dfb63bcad4a0bb0953c0b3554ed0e93",
"author": {
"name": "user",
"email": "user@example.com",
"username": "user@example.com"
},
"committer": {
"name": "user",
"email": "user@example.com",
"username": "user@example.com"
},
"verification": null,
"timestamp": "2024-07-03T18:27:38Z",
"added": [],
"removed": [],
"modified": [
"README.md"
]
}
],
"head_commit": null,
"repository": {
"id": 4,
"owner": {"id":2,"login":"my-project","full_name":"","email":"email-address@example.com","avatar_url":"b2653dbf52c7e078e04b8b20020eaadeafe0337787cc0e19b976efc8d594aefb","language":"","is_admin":false,"last_login":"1970-01-01T00:00:00Z","created":"2023-06-02T14:18:40Z","restricted":false,"username":"my-project"},
"name": "my-repo",
"full_name": "my-project/my-repo",
"description": "",
"empty": false,
"private": false,
"fork": false,
"template": false,
"parent": null,
"mirror": false,
"size": 4,
"html_url": "https://my-instance-123456789.us-central1.sourcemanager.dev/my-project/my-repo",
"ssh_url": "git@my-instance-123456789-ssh.us-central1.sourcemanager.dev:my-project/my-repo.git",
"clone_url": "https://my-instance-123456789-git.us-central1.sourcemanager.dev/my-project/my-repo.git",
"original_url": "",
"website": "",
"stars_count": 0,
"forks_count": 0,
"watchers_count": 1,
"open_issues_count": 0,
"open_pr_counter": 1,
"release_counter": 1,
"default_branch": "main",
"archived": false,
"created_at": "2023-06-06T20:34:36Z",
"updated_at": "2024-04-04T18:19:14Z",
"permissions": {
"admin": true,
"push": true,
"pull": true
},
"has_issues": true,
"internal_tracker": {
"enable_time_tracker": false,
"allow_only_contributors_to_track_time": true,
"enable_issue_dependencies": true
},
"has_wiki": true,
"has_pull_requests": true,
"has_projects": true,
"ignore_whitespace_conflicts": false,
"allow_merge_commits": true,
"allow_rebase": true,
"allow_rebase_explicit": true,
"allow_squash_merge": true,
"avatar_url": "",
"internal": false,
"mirror_interval": "",
"uris": {
"api": "https://my-instance-123456789-api.us-central1.sourcemanager.dev/v1/projects/my-project/locations/us-central1/repositories/my-repo",
"html": "https://my-instance-123456789.us-central1.sourcemanager.dev/my-project/my-repo",
"git_https": "https://my-instance-123456789-git.us-central1.sourcemanager.dev/my-project/my-repo.git"
}
},
"pusher": {"id":4,"login":"user@example.com","full_name":"user","email":"user@example.com","avatar_url":"https://this-is-avatar.com","language":"","is_admin":false,"last_login":"0001-01-01T00:00:00Z","created":"2023-06-02T20:53:58Z","restricted":false,"username":"user@example.com"},
"sender": {"id":4,"login":"user@example.com","full_name":"user","email":"user@example.com","avatar_url":"https://this-is-avatar.com","language":"","is_admin":false,"last_login":"0001-01-01T00:00:00Z","created":"2023-06-02T20:53:58Z","restricted":false,"username":"user@example.com"}
}
拉取事件载荷
拉取事件载荷的内容类似于以下内容。
标题
Request URL: https://example.com?{sensitive_query_string_placeholder}
Request method: POST
Content-Type: application/json
X-SecureSourceManager-Delivery: d7bb9273-17cf-431d-835c-b334c9702eee
X-SecureSourceManager-Event: pull_request
X-SecureSourceManager-Signature:
正文
{
"secret": "",
"action": "opened",
"number": 4,
"pull_request": {
"id": 18,
"url": "https://my-instance-123456789.us-central1.sourcemanager.dev/my-project/my-repo/pulls/4",
"number": 4,
"user": {"id":4,"login":"user@example.com","full_name":"user","email":"user@example.com","avatar_url":"https://page-address.com","language":"","is_admin":false,"last_login":"0001-01-01T00:00:00Z","created":"2023-06-02T20:53:58Z","restricted":false,"username":"user@example.com"},
"title": "Open a Pull Request'",
"body": "",
"labels": [],
"milestone": null,
"assignee": null,
"assignees": null,
"state": "open",
"is_locked": false,
"comments": 0,
"html_url": "https://my-instance-123456789.us-central1.sourcemanager.dev/cloud-git-test-pso-instance/test2/pulls/4",
"diff_url": "https://my-instance-123456789.us-central1.sourcemanager.dev/my-project/my-repo/pulls/4.diff",
"patch_url": "https://my-instance-123456789.us-central1.sourcemanager.dev/my-project/my-repo/pulls/4.patch",
"mergeable": false,
"merged": false,
"merged_at": null,
"merge_commit_sha": null,
"merged_by": null,
"base": {
"label": "main",
"ref": "main",
"sha": "85c7e78e6dfb63bcad4a0bb0953c0b3554ed0e93",
"repo_id": 4,
"repo": {
"id": 4,
"owner": {"id":2,"login":"my-project","full_name":"","email":"email-address@example.com","avatar_url":"b2653dbf52c7e078e04b8b20020eaadeafe0337787cc0e19b976efc8d594aefb","language":"","is_admin":false,"last_login":"0001-01-01T00:00:00Z","created":"2023-06-02T14:18:40Z","restricted":false,"username":"my-project"},
"name": "my-repo",
"full_name": "my-project/my-repo",
"description": "",
"empty": false,
"private": false,
"fork": false,
"template": false,
"parent": null,
"mirror": false,
"size": 4,
"html_url": "https://my-instance-123456789.us-central1.sourcemanager.dev/my-project/my-repo",
"ssh_url": "git@my-instance-123456789-ssh.us-central1.sourcemanager.dev:my-project/my-repo.git",
"clone_url": "https://my-instance-123456789-git.us-central1.sourcemanager.dev/my-project/my-repo.git",
"original_url": "",
"website": "",
"stars_count": 0,
"forks_count": 0,
"watchers_count": 1,
"open_issues_count": 0,
"open_pr_counter": 0,
"release_counter": 1,
"default_branch": "main",
"archived": false,
"created_at": "2023-06-06T20:34:36Z",
"updated_at": "2024-07-03T18:27:42Z",
"permissions": {
"admin": false,
"push": false,
"pull": false
},
"has_issues": true,
"internal_tracker": {
"enable_time_tracker": false,
"allow_only_contributors_to_track_time": true,
"enable_issue_dependencies": true
},
"has_wiki": true,
"has_pull_requests": true,
"has_projects": true,
"ignore_whitespace_conflicts": false,
"allow_merge_commits": true,
"allow_rebase": true,
"allow_rebase_explicit": true,
"allow_squash_merge": true,
"avatar_url": "",
"internal": false,
"mirror_interval": "",
"uris": {
"api": "https://my-instance-123456789-api.us-central1.sourcemanager.dev/v1/projects/my-project/locations/us-central1/repositories/my-repo",
"html": "https://my-instance-123456789.us-central1.sourcemanager.dev/my-project/my-repo",
"git_https": "https://my-instance-123456789-git.us-central1.sourcemanager.dev/my-project/my-repo.git"
}
}
},
"head": {
"label": "dev",
"ref": "dev",
"sha": "06aa2c971d8e06e5271ce04248ef1920341ce208",
"repo_id": 4,
"repo": {
"id": 4,
"owner": {"id":2,"login":"my-project","full_name":"","email":"email-address@example.com","avatar_url":"b2653dbf52c7e078e04b8b20020eaadeafe0337787cc0e19b976efc8d594aefb","language":"","is_admin":false,"last_login":"0001-01-01T00:00:00Z","created":"2023-06-02T14:18:40Z","restricted":false,"username":"my-project"},
"name": "my-repo",
"full_name": "my-project/my-repo",
"description": "",
"empty": false,
"private": false,
"fork": false,
"template": false,
"parent": null,
"mirror": false,
"size": 4,
"html_url": "https://my-instance-123456789.us-central1.sourcemanager.dev/my-project/my-repo",
"ssh_url": "git@my-instance-123456789-ssh.us-central1.sourcemanager.dev:my-project/my-repo.git",
"clone_url": "https://my-instance-123456789-git.us-central1.sourcemanager.dev/my-project/my-repo.git",
"original_url": "",
"website": "",
"stars_count": 0,
"forks_count": 0,
"watchers_count": 1,
"open_issues_count": 0,
"open_pr_counter": 0,
"release_counter": 1,
"default_branch": "main",
"archived": false,
"created_at": "2023-06-06T20:34:36Z",
"updated_at": "2024-07-03T18:27:42Z",
"permissions": {
"admin": false,
"push": false,
"pull": false
},
"has_issues": true,
"internal_tracker": {
"enable_time_tracker": false,
"allow_only_contributors_to_track_time": true,
"enable_issue_dependencies": true
},
"has_wiki": true,
"has_pull_requests": true,
"has_projects": true,
"ignore_whitespace_conflicts": false,
"allow_merge_commits": true,
"allow_rebase": true,
"allow_rebase_explicit": true,
"allow_squash_merge": true,
"avatar_url": "",
"internal": false,
"mirror_interval": "",
"uris": {
"api": "https://my-instance-123456789-api.us-central1.sourcemanager.dev/v1/projects/my-project/locations/us-central1/repositories/my-repo",
"html": "https://my-instance-123456789.us-central1.sourcemanager.dev/my-project/my-repo",
"git_https": "https://my-instance-123456789-git.us-central1.sourcemanager.dev/my-project/my-repo.git"
}
}
},
"merge_base": "af065efa8d3d7549154c560da5cb3ec236ad3002",
"due_date": null,
"created_at": "2024-07-03T18:40:21Z",
"updated_at": "2024-07-03T18:40:21Z",
"closed_at": null
},
"repository": {
"id": 4,
"owner": {"id":2,"login":"my-project","full_name":"","email":"email-address@example.com","avatar_url":"b2653dbf52c7e078e04b8b20020eaadeafe0337787cc0e19b976efc8d594aefb","language":"","is_admin":false,"last_login":"0001-01-01T00:00:00Z","created":"2023-06-02T14:18:40Z","restricted":false,"username":"my-project"},
"name": "my-repo",
"full_name": "my-project/my-repo",
"description": "",
"empty": false,
"private": false,
"fork": false,
"template": false,
"parent": null,
"mirror": false,
"size": 4,
"html_url": "https://my-instance-123456789.us-central1.sourcemanager.dev/my-project/my-repo",
"ssh_url": "git@my-instance-123456789-ssh.us-central1.sourcemanager.dev:my-project/my-repo.git",
"clone_url": "https://my-instance-123456789-git.us-central1.sourcemanager.dev/my-project/my-repo.git",
"original_url": "",
"website": "",
"stars_count": 0,
"forks_count": 0,
"watchers_count": 1,
"open_issues_count": 0,
"open_pr_counter": 1,
"release_counter": 1,
"default_branch": "main",
"archived": false,
"created_at": "2023-06-06T20:34:36Z",
"updated_at": "2024-07-03T18:27:42Z",
"permissions": {
"admin": false,
"push": false,
"pull": true
},
"has_issues": true,
"internal_tracker": {
"enable_time_tracker": false,
"allow_only_contributors_to_track_time": true,
"enable_issue_dependencies": true
},
"has_wiki": true,
"has_pull_requests": true,
"has_projects": true,
"ignore_whitespace_conflicts": false,
"allow_merge_commits": true,
"allow_rebase": true,
"allow_rebase_explicit": true,
"allow_squash_merge": true,
"avatar_url": "",
"internal": false,
"mirror_interval": "",
"uris": {
"api": "https://my-instance-123456789-api.us-central1.sourcemanager.dev/v1/projects/my-project/locations/us-central1/repositories/my-repo",
"html": "https://my-instance-123456789.us-central1.sourcemanager.dev/my-project/my-repo",
"git_https": "https://my-instance-123456789-git.us-central1.sourcemanager.dev/my-project/my-repo.git"
}
},
"sender": {"id":4,"login":"user@example.com","full_name":"user","email":"user@example.com","avatar_url":"https://this-is-avatar.com","language":"","is_admin":false,"last_login":"0001-01-01T00:00:00Z","created":"2023-06-02T20:53:58Z","restricted":false,"username":"user@example.com"},
"review": null
}
后续步骤
- 使用 Webhook 连接到 Jenkins。
- 设置 webhook。