Gitea 集成 Webhook 操作

集成 钉钉(Dingtalk)

进入项目, 点击 Settings - Add Webhook - Dingtalk.

填入钉钉机器人的链接地址, 选择合适的触发规则, 我选择的是在有 PR 请求和 Push 推送的时候, 发送钉钉消息.

添加完成后, 点击测试推送, 验证消息是否可以正确发送.

需要注意的是, 注册钉钉链接的时候, 要添加一些自定义关键字, 我们发送的消息中必定含有自建 Gitea 的域名 git.DOMAIN.com, 所以可以作为关键字添加进去.

集成 电报群(Telegram)

创建 Telegram 机器人

打开 BotFather 与之对话, 选择 /newbot - create a new bot

回答问题 Bot NameBot Username, 其中 username 必须以 bot 或者 Bot 结尾.

之后机器人就创建成功了.

打开 IdBot 与之对话, 选择 /getid 获取自己的 User ID. 当日也可以获取 Group ID.

配置机器人到 WebHook

进入项目, 点击 Settings - Add Webhook - Telegram.

填写 Token 和 Chat ID, 选择合适的触发规则, 我选择的是在有 PR 请求和 Push 推送的时候, 发送钉钉消息.

添加完成后, 点击测试推送, 验证消息是否可以正确发送.

集成第三方通知 API

我们有时候使用第三方 API 接收 git 的 Webhook 消息, 消息结构为.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
{
"secret": "SECRET",
"ref": "refs/heads/master",
"before": "a3f2d00884370429ee54051e80c8384a99b9be5c",
"after": "a3f2d00884370429ee54051e80c8384a99b9be5c",
"compare_url": "",
"commits": [
{
"id": "a3f2d00884370429ee54051e80c8384a99b9be5c",
"message": "message\n",
"url": "http://PROJECT_ADDR/commit/a3f2d00884370429ee54051e80c8384a99b9be5c",
"author": {
"name": "USERNAME",
"email": "EMAIL",
"username": ""
},
"committer": {
"name": "USERNAME",
"email": "EMAIL",
"username": ""
},
"verification": null,
"timestamp": "0001-01-01T00:00:00Z",
"added": null,
"removed": null,
"modified": null
}
],
"head_commit": null,
"repository": {
"id": 8,
"owner": {
"id": 1,
"login": "LOGIN_NAME",
"full_name": "FULL NAME",
"email": "EMAIL",
"avatar_url": "http://.../-1",
"language": "en-US",
"is_admin": true,
"last_login": "2019-12-20T05:06:48Z",
"created": "2019-12-09T12:33:45Z",
"username": "USERNAME"
},
"name": "PROJECT_NAME",
"full_name": "USERNAME/PROJECT_NAME",
"description": "使用 Gitea 集成 Jenkins,CI/CD,Docker 等进行自动集成部署",
"empty": false,
"private": false,
"fork": false,
"template": false,
"parent": null,
"mirror": false,
"size": 17,
"html_url": "http://PROJECT_ADDR",
"ssh_url": "git@PROJECT_ADDR.git",
"clone_url": "http://PROJECT_ADDR.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": "master",
"archived": false,
"created_at": "2019-12-20T04:53:03Z",
"updated_at": "2019-12-20T04:55:14Z",
"permissions": {
"admin": false,
"push": false,
"pull": false
},
"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,
"ignore_whitespace_conflicts": false,
"allow_merge_commits": true,
"allow_rebase": true,
"allow_rebase_explicit": true,
"allow_squash_merge": true,
"avatar_url": ""
},
"pusher": {
"id": 1,
"login": "USERNAME",
"full_name": "FULLNAME",
"email": "EMAIL",
"avatar_url": "http://.../-1",
"language": "en-US",
"is_admin": true,
"last_login": "2019-12-20T05:06:48Z",
"created": "2019-12-09T12:33:45Z",
"username": "USERNAME"
},
"sender": {
"id": 1,
"login": "USERNAME",
"full_name": "FULLNAME",
"email": "EMAIL",
"avatar_url": "http://.../-1",
"language": "en-US",
"is_admin": true,
"last_login": "2019-12-20T05:06:48Z",
"created": "2019-12-09T12:33:45Z",
"username": "USERNAME"
}
}

可以在 Jenkins 进行集成, 一遍进一步实现 CI/CD 功能. 选择此模式, 可以在 WebHook 中选择 Gitea 或者 Gogs 模式, 目测发送的数据是相同类型的.

Donate - Support to make this site better.
捐助 - 支持我让我做得更好.