mirror of
https://github.com/zulip/zulip.git
synced 2025-11-01 20:44:04 +00:00
gogs: Add webhook integration.
- Add push, create and pull request event. - Handle 'opened', 'closed' and 'merged' in 'pull request' event. - Include tests for all the above events including 'push' with commits more than limits.
This commit is contained in:
committed by
Tim Abbott
parent
9c5f1d2239
commit
9e45f32275
BIN
static/images/integrations/gogs/001.png
Normal file
BIN
static/images/integrations/gogs/001.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 14 KiB |
BIN
static/images/integrations/gogs/002.png
Normal file
BIN
static/images/integrations/gogs/002.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.8 KiB |
BIN
static/images/integrations/gogs/003.png
Normal file
BIN
static/images/integrations/gogs/003.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 21 KiB |
BIN
static/images/integrations/gogs/004.png
Normal file
BIN
static/images/integrations/gogs/004.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 59 KiB |
BIN
static/images/integrations/gogs/005.png
Normal file
BIN
static/images/integrations/gogs/005.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 13 KiB |
BIN
static/images/integrations/logos/gogs.png
Normal file
BIN
static/images/integrations/logos/gogs.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.7 KiB |
40
zerver/fixtures/gogs/gogs_branch.json
Normal file
40
zerver/fixtures/gogs/gogs_branch.json
Normal file
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"secret": "",
|
||||
"ref": "my_feature",
|
||||
"ref_type": "branch",
|
||||
"repository": {
|
||||
"id": 1,
|
||||
"owner": {
|
||||
"id": 1,
|
||||
"login": "john",
|
||||
"full_name": "",
|
||||
"email": "john@example.com",
|
||||
"avatar_url": "https://secure.gravatar.com/avatar/715cb4680284423d81d2e75e94f812a1",
|
||||
"username": "john"
|
||||
},
|
||||
"name": "try-git",
|
||||
"full_name": "john/try-git",
|
||||
"description": "",
|
||||
"private": false,
|
||||
"fork": false,
|
||||
"html_url": "http://localhost:3000/john/try-git",
|
||||
"ssh_url": "john@localhost:john/try-git.git",
|
||||
"clone_url": "http://localhost:3000/john/try-git.git",
|
||||
"website": "",
|
||||
"stars_count": 0,
|
||||
"forks_count": 0,
|
||||
"watchers_count": 1,
|
||||
"open_issues_count": 0,
|
||||
"default_branch": "master",
|
||||
"created_at": "2017-02-19T13:23:39-05:00",
|
||||
"updated_at": "2017-02-19T13:57:06-05:00"
|
||||
},
|
||||
"sender": {
|
||||
"id": 1,
|
||||
"login": "john",
|
||||
"full_name": "",
|
||||
"email": "john@example.com",
|
||||
"avatar_url": "https://secure.gravatar.com/avatar/715cb4680284423d81d2e75e94f812a1",
|
||||
"username": "john"
|
||||
}
|
||||
}
|
121
zerver/fixtures/gogs/gogs_pull_request_closed.json
Normal file
121
zerver/fixtures/gogs/gogs_pull_request_closed.json
Normal file
@@ -0,0 +1,121 @@
|
||||
{
|
||||
"secret": "",
|
||||
"action": "closed",
|
||||
"number": 1,
|
||||
"pull_request": {
|
||||
"id": 1,
|
||||
"number": 1,
|
||||
"user": {
|
||||
"id": 2,
|
||||
"login": "john",
|
||||
"full_name": "",
|
||||
"email": "john@example.com",
|
||||
"avatar_url": "https://secure.gravatar.com/avatar/3e55b4d0f779dd3b7ab3be7960dc157a",
|
||||
"username": "john"
|
||||
},
|
||||
"title": "Title Text for Pull Request",
|
||||
"body": "Description Text",
|
||||
"labels": [],
|
||||
"milestone": null,
|
||||
"assignee": null,
|
||||
"state": "closed",
|
||||
"comments": 0,
|
||||
"head_branch": "feature",
|
||||
"head_repo": {
|
||||
"id": 2,
|
||||
"owner": {
|
||||
"id": 2,
|
||||
"login": "john",
|
||||
"full_name": "",
|
||||
"email": "john@example.com",
|
||||
"avatar_url": "https://secure.gravatar.com/avatar/3e55b4d0f779dd3b7ab3be7960dc157a",
|
||||
"username": "john"
|
||||
},
|
||||
"name": "try-git",
|
||||
"full_name": "john/try-git",
|
||||
"description": "",
|
||||
"private": false,
|
||||
"fork": true,
|
||||
"html_url": "http://localhost:3000/john/try-git",
|
||||
"ssh_url": "john@localhost:john/try-git.git",
|
||||
"clone_url": "http://localhost:3000/john/try-git.git",
|
||||
"website": "",
|
||||
"stars_count": 0,
|
||||
"forks_count": 0,
|
||||
"watchers_count": 1,
|
||||
"open_issues_count": 0,
|
||||
"default_branch": "master",
|
||||
"created_at": "2017-02-19T18:10:53-05:00",
|
||||
"updated_at": "2017-02-19T18:13:08-05:00"
|
||||
},
|
||||
"base_branch": "master",
|
||||
"base_repo": {
|
||||
"id": 1,
|
||||
"owner": {
|
||||
"id": 1,
|
||||
"login": "john",
|
||||
"full_name": "",
|
||||
"email": "john@example.com",
|
||||
"avatar_url": "https://secure.gravatar.com/avatar/715cb4680284423d81d2e75e94f812a1",
|
||||
"username": "john"
|
||||
},
|
||||
"name": "try-git",
|
||||
"full_name": "john/try-git",
|
||||
"description": "",
|
||||
"private": false,
|
||||
"fork": false,
|
||||
"html_url": "http://localhost:3000/john/try-git",
|
||||
"ssh_url": "john@localhost:john/try-git.git",
|
||||
"clone_url": "http://localhost:3000/john/try-git.git",
|
||||
"website": "",
|
||||
"stars_count": 0,
|
||||
"forks_count": 1,
|
||||
"watchers_count": 1,
|
||||
"open_issues_count": 0,
|
||||
"default_branch": "master",
|
||||
"created_at": "2017-02-19T13:23:39-05:00",
|
||||
"updated_at": "2017-02-19T17:56:41-05:00"
|
||||
},
|
||||
"html_url": "http://localhost:3000/john/try-git/pulls/1",
|
||||
"mergeable": true,
|
||||
"merged": false,
|
||||
"merged_at": null,
|
||||
"merge_commit_sha": null,
|
||||
"merged_by": null
|
||||
},
|
||||
"repository": {
|
||||
"id": 1,
|
||||
"owner": {
|
||||
"id": 1,
|
||||
"login": "john",
|
||||
"full_name": "",
|
||||
"email": "john@example.com",
|
||||
"avatar_url": "https://secure.gravatar.com/avatar/715cb4680284423d81d2e75e94f812a1",
|
||||
"username": "john"
|
||||
},
|
||||
"name": "try-git",
|
||||
"full_name": "john/try-git",
|
||||
"description": "",
|
||||
"private": false,
|
||||
"fork": false,
|
||||
"html_url": "http://localhost:3000/john/try-git",
|
||||
"ssh_url": "john@localhost:john/try-git.git",
|
||||
"clone_url": "http://localhost:3000/john/try-git.git",
|
||||
"website": "",
|
||||
"stars_count": 0,
|
||||
"forks_count": 1,
|
||||
"watchers_count": 1,
|
||||
"open_issues_count": 0,
|
||||
"default_branch": "master",
|
||||
"created_at": "2017-02-19T13:23:39-05:00",
|
||||
"updated_at": "2017-02-19T17:56:41-05:00"
|
||||
},
|
||||
"sender": {
|
||||
"id": 1,
|
||||
"login": "john",
|
||||
"full_name": "",
|
||||
"email": "john@example.com",
|
||||
"avatar_url": "https://secure.gravatar.com/avatar/715cb4680284423d81d2e75e94f812a1",
|
||||
"username": "john"
|
||||
}
|
||||
}
|
128
zerver/fixtures/gogs/gogs_pull_request_merged.json
Normal file
128
zerver/fixtures/gogs/gogs_pull_request_merged.json
Normal file
@@ -0,0 +1,128 @@
|
||||
{
|
||||
"secret": "",
|
||||
"action": "closed",
|
||||
"number": 2,
|
||||
"pull_request": {
|
||||
"id": 2,
|
||||
"number": 2,
|
||||
"user": {
|
||||
"id": 2,
|
||||
"login": "john",
|
||||
"full_name": "",
|
||||
"email": "john@example.com",
|
||||
"avatar_url": "https://secure.gravatar.com/avatar/3e55b4d0f779dd3b7ab3be7960dc157a",
|
||||
"username": "john"
|
||||
},
|
||||
"title": "Title Text for Pull Request",
|
||||
"body": "Description Text",
|
||||
"labels": [],
|
||||
"milestone": null,
|
||||
"assignee": null,
|
||||
"state": "closed",
|
||||
"comments": 0,
|
||||
"head_branch": "feature",
|
||||
"head_repo": {
|
||||
"id": 2,
|
||||
"owner": {
|
||||
"id": 2,
|
||||
"login": "john",
|
||||
"full_name": "",
|
||||
"email": "john@example.com",
|
||||
"avatar_url": "https://secure.gravatar.com/avatar/3e55b4d0f779dd3b7ab3be7960dc157a",
|
||||
"username": "john"
|
||||
},
|
||||
"name": "try-git",
|
||||
"full_name": "john/try-git",
|
||||
"description": "",
|
||||
"private": false,
|
||||
"fork": true,
|
||||
"html_url": "http://localhost:3000/john/try-git",
|
||||
"ssh_url": "john@localhost:john/try-git.git",
|
||||
"clone_url": "http://localhost:3000/john/try-git.git",
|
||||
"website": "",
|
||||
"stars_count": 0,
|
||||
"forks_count": 0,
|
||||
"watchers_count": 1,
|
||||
"open_issues_count": 0,
|
||||
"default_branch": "master",
|
||||
"created_at": "2017-02-19T18:10:53-05:00",
|
||||
"updated_at": "2017-02-19T18:19:27-05:00"
|
||||
},
|
||||
"base_branch": "master",
|
||||
"base_repo": {
|
||||
"id": 1,
|
||||
"owner": {
|
||||
"id": 1,
|
||||
"login": "john",
|
||||
"full_name": "",
|
||||
"email": "john@example.com",
|
||||
"avatar_url": "https://secure.gravatar.com/avatar/715cb4680284423d81d2e75e94f812a1",
|
||||
"username": "john"
|
||||
},
|
||||
"name": "try-git",
|
||||
"full_name": "john/try-git",
|
||||
"description": "",
|
||||
"private": false,
|
||||
"fork": false,
|
||||
"html_url": "http://localhost:3000/john/try-git",
|
||||
"ssh_url": "john@localhost:john/try-git.git",
|
||||
"clone_url": "http://localhost:3000/john/try-git.git",
|
||||
"website": "",
|
||||
"stars_count": 0,
|
||||
"forks_count": 1,
|
||||
"watchers_count": 1,
|
||||
"open_issues_count": 0,
|
||||
"default_branch": "master",
|
||||
"created_at": "2017-02-19T13:23:39-05:00",
|
||||
"updated_at": "2017-02-19T17:56:41-05:00"
|
||||
},
|
||||
"html_url": "http://localhost:3000/john/try-git/pulls/2",
|
||||
"mergeable": true,
|
||||
"merged": true,
|
||||
"merged_at": "2017-02-19T18:20:24.851356231-05:00",
|
||||
"merge_commit_sha": "9c65fc6e0a3a7487ad70a3711c8c478aa6e94c69",
|
||||
"merged_by": {
|
||||
"id": 1,
|
||||
"login": "john",
|
||||
"full_name": "",
|
||||
"email": "john@example.com",
|
||||
"avatar_url": "https://secure.gravatar.com/avatar/715cb4680284423d81d2e75e94f812a1",
|
||||
"username": "john"
|
||||
}
|
||||
},
|
||||
"repository": {
|
||||
"id": 1,
|
||||
"owner": {
|
||||
"id": 1,
|
||||
"login": "john",
|
||||
"full_name": "",
|
||||
"email": "john@example.com",
|
||||
"avatar_url": "https://secure.gravatar.com/avatar/715cb4680284423d81d2e75e94f812a1",
|
||||
"username": "john"
|
||||
},
|
||||
"name": "try-git",
|
||||
"full_name": "john/try-git",
|
||||
"description": "",
|
||||
"private": false,
|
||||
"fork": false,
|
||||
"html_url": "http://localhost:3000/john/try-git",
|
||||
"ssh_url": "john@localhost:john/try-git.git",
|
||||
"clone_url": "http://localhost:3000/john/try-git.git",
|
||||
"website": "",
|
||||
"stars_count": 0,
|
||||
"forks_count": 1,
|
||||
"watchers_count": 1,
|
||||
"open_issues_count": 0,
|
||||
"default_branch": "master",
|
||||
"created_at": "2017-02-19T13:23:39-05:00",
|
||||
"updated_at": "2017-02-19T17:56:41-05:00"
|
||||
},
|
||||
"sender": {
|
||||
"id": 1,
|
||||
"login": "john",
|
||||
"full_name": "",
|
||||
"email": "john@example.com",
|
||||
"avatar_url": "https://secure.gravatar.com/avatar/715cb4680284423d81d2e75e94f812a1",
|
||||
"username": "john"
|
||||
}
|
||||
}
|
121
zerver/fixtures/gogs/gogs_pull_request_opened.json
Normal file
121
zerver/fixtures/gogs/gogs_pull_request_opened.json
Normal file
@@ -0,0 +1,121 @@
|
||||
{
|
||||
"secret": "",
|
||||
"action": "opened",
|
||||
"number": 1,
|
||||
"pull_request": {
|
||||
"id": 1,
|
||||
"number": 1,
|
||||
"user": {
|
||||
"id": 2,
|
||||
"login": "john",
|
||||
"full_name": "",
|
||||
"email": "john@example.com",
|
||||
"avatar_url": "https://secure.gravatar.com/avatar/3e55b4d0f779dd3b7ab3be7960dc157a",
|
||||
"username": "john"
|
||||
},
|
||||
"title": "Title Text for Pull Request",
|
||||
"body": "Description Text",
|
||||
"labels": [],
|
||||
"milestone": null,
|
||||
"assignee": null,
|
||||
"state": "open",
|
||||
"comments": 0,
|
||||
"head_branch": "feature",
|
||||
"head_repo": {
|
||||
"id": 2,
|
||||
"owner": {
|
||||
"id": 2,
|
||||
"login": "john",
|
||||
"full_name": "",
|
||||
"email": "john@example.com",
|
||||
"avatar_url": "https://secure.gravatar.com/avatar/3e55b4d0f779dd3b7ab3be7960dc157a",
|
||||
"username": "john"
|
||||
},
|
||||
"name": "try-git",
|
||||
"full_name": "john/try-git",
|
||||
"description": "",
|
||||
"private": false,
|
||||
"fork": true,
|
||||
"html_url": "http://localhost:3000/john/try-git",
|
||||
"ssh_url": "john@localhost:john/try-git.git",
|
||||
"clone_url": "http://localhost:3000/john/try-git.git",
|
||||
"website": "",
|
||||
"stars_count": 0,
|
||||
"forks_count": 0,
|
||||
"watchers_count": 1,
|
||||
"open_issues_count": 0,
|
||||
"default_branch": "master",
|
||||
"created_at": "2017-02-19T18:10:53-05:00",
|
||||
"updated_at": "2017-02-19T18:13:08-05:00"
|
||||
},
|
||||
"base_branch": "master",
|
||||
"base_repo": {
|
||||
"id": 1,
|
||||
"owner": {
|
||||
"id": 1,
|
||||
"login": "john",
|
||||
"full_name": "",
|
||||
"email": "john@example.com",
|
||||
"avatar_url": "https://secure.gravatar.com/avatar/715cb4680284423d81d2e75e94f812a1",
|
||||
"username": "john"
|
||||
},
|
||||
"name": "try-git",
|
||||
"full_name": "john/try-git",
|
||||
"description": "",
|
||||
"private": false,
|
||||
"fork": false,
|
||||
"html_url": "http://localhost:3000/john/try-git",
|
||||
"ssh_url": "john@localhost:john/try-git.git",
|
||||
"clone_url": "http://localhost:3000/john/try-git.git",
|
||||
"website": "",
|
||||
"stars_count": 0,
|
||||
"forks_count": 1,
|
||||
"watchers_count": 1,
|
||||
"open_issues_count": 0,
|
||||
"default_branch": "master",
|
||||
"created_at": "2017-02-19T13:23:39-05:00",
|
||||
"updated_at": "2017-02-19T17:56:41-05:00"
|
||||
},
|
||||
"html_url": "http://localhost:3000/john/try-git/pulls/1",
|
||||
"mergeable": true,
|
||||
"merged": false,
|
||||
"merged_at": null,
|
||||
"merge_commit_sha": null,
|
||||
"merged_by": null
|
||||
},
|
||||
"repository": {
|
||||
"id": 1,
|
||||
"owner": {
|
||||
"id": 1,
|
||||
"login": "john",
|
||||
"full_name": "",
|
||||
"email": "john@example.com",
|
||||
"avatar_url": "https://secure.gravatar.com/avatar/715cb4680284423d81d2e75e94f812a1",
|
||||
"username": "john"
|
||||
},
|
||||
"name": "try-git",
|
||||
"full_name": "john/try-git",
|
||||
"description": "",
|
||||
"private": false,
|
||||
"fork": false,
|
||||
"html_url": "http://localhost:3000/john/try-git",
|
||||
"ssh_url": "john@localhost:john/try-git.git",
|
||||
"clone_url": "http://localhost:3000/john/try-git.git",
|
||||
"website": "",
|
||||
"stars_count": 0,
|
||||
"forks_count": 1,
|
||||
"watchers_count": 1,
|
||||
"open_issues_count": 0,
|
||||
"default_branch": "master",
|
||||
"created_at": "2017-02-19T13:23:39-05:00",
|
||||
"updated_at": "2017-02-19T17:56:41-05:00"
|
||||
},
|
||||
"sender": {
|
||||
"id": 2,
|
||||
"login": "john",
|
||||
"full_name": "",
|
||||
"email": "john@example.com",
|
||||
"avatar_url": "https://secure.gravatar.com/avatar/3e55b4d0f779dd3b7ab3be7960dc157a",
|
||||
"username": "john"
|
||||
}
|
||||
}
|
68
zerver/fixtures/gogs/gogs_push.json
Normal file
68
zerver/fixtures/gogs/gogs_push.json
Normal file
@@ -0,0 +1,68 @@
|
||||
{
|
||||
"secret": "",
|
||||
"ref": "refs/heads/master",
|
||||
"before": "479e6b772b7fba19412457483f50b201286d0103",
|
||||
"after": "d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"compare_url": "http://localhost:3000/john/try-git/compare/479e6b772b7fba19412457483f50b201286d0103...d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"commits": [
|
||||
{
|
||||
"id": "d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"message": "Webhook Test\n",
|
||||
"url": "http://localhost:3000/john/try-git/commit/d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"author": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"committer": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"timestamp": "2017-01-28T08:54:49-05:00"
|
||||
}
|
||||
],
|
||||
"repository": {
|
||||
"id": 1,
|
||||
"owner": {
|
||||
"id": 1,
|
||||
"login": "john",
|
||||
"full_name": "",
|
||||
"email": "john@example.com",
|
||||
"avatar_url": "https://secure.gravatar.com/avatar/ab4e102452ed53394cba1eb306de04c4",
|
||||
"username": "john"
|
||||
},
|
||||
"name": "try-git",
|
||||
"full_name": "john/try-git",
|
||||
"description": "",
|
||||
"private": false,
|
||||
"fork": false,
|
||||
"html_url": "http://localhost:3000/john/try-git",
|
||||
"ssh_url": "john@localhost:john/try-git.git",
|
||||
"clone_url": "http://localhost:3000/john/try-git.git",
|
||||
"website": "",
|
||||
"stars_count": 0,
|
||||
"forks_count": 0,
|
||||
"watchers_count": 1,
|
||||
"open_issues_count": 0,
|
||||
"default_branch": "master",
|
||||
"created_at": "2017-01-27T17:21:00-05:00",
|
||||
"updated_at": "2017-01-27T17:22:47-05:00"
|
||||
},
|
||||
"pusher": {
|
||||
"id": 1,
|
||||
"login": "john",
|
||||
"full_name": "",
|
||||
"email": "john@example.com",
|
||||
"avatar_url": "https://secure.gravatar.com/avatar/ab4e102452ed53394cba1eb306de04c4",
|
||||
"username": "john"
|
||||
},
|
||||
"sender": {
|
||||
"id": 1,
|
||||
"login": "john",
|
||||
"full_name": "",
|
||||
"email": "john@example.com",
|
||||
"avatar_url": "https://secure.gravatar.com/avatar/ab4e102452ed53394cba1eb306de04c4",
|
||||
"username": "john"
|
||||
}
|
||||
}
|
532
zerver/fixtures/gogs/gogs_push_commits_more_than_limits.json
Normal file
532
zerver/fixtures/gogs/gogs_push_commits_more_than_limits.json
Normal file
@@ -0,0 +1,532 @@
|
||||
{
|
||||
"secret": "",
|
||||
"ref": "refs/heads/master",
|
||||
"before": "479e6b772b7fba19412457483f50b201286d0103",
|
||||
"after": "d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"compare_url": "http://localhost:3000/john/try-git/compare/479e6b772b7fba19412457483f50b201286d0103...d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"commits": [
|
||||
{
|
||||
"id": "d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"message": "Webhook Test\n",
|
||||
"url": "http://localhost:3000/john/try-git/commit/d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"author": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"committer": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"timestamp": "2017-01-28T08:54:49-05:00"
|
||||
},
|
||||
{
|
||||
"id": "d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"message": "Webhook Test\n",
|
||||
"url": "http://localhost:3000/john/try-git/commit/d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"author": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"committer": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"timestamp": "2017-01-28T08:54:49-05:00"
|
||||
},
|
||||
{
|
||||
"id": "d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"message": "Webhook Test\n",
|
||||
"url": "http://localhost:3000/john/try-git/commit/d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"author": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"committer": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"timestamp": "2017-01-28T08:54:49-05:00"
|
||||
},
|
||||
{
|
||||
"id": "d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"message": "Webhook Test\n",
|
||||
"url": "http://localhost:3000/john/try-git/commit/d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"author": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"committer": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"timestamp": "2017-01-28T08:54:49-05:00"
|
||||
},
|
||||
{
|
||||
"id": "d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"message": "Webhook Test\n",
|
||||
"url": "http://localhost:3000/john/try-git/commit/d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"author": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"committer": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"timestamp": "2017-01-28T08:54:49-05:00"
|
||||
},
|
||||
{
|
||||
"id": "d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"message": "Webhook Test\n",
|
||||
"url": "http://localhost:3000/john/try-git/commit/d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"author": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"committer": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"timestamp": "2017-01-28T08:54:49-05:00"
|
||||
},
|
||||
{
|
||||
"id": "d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"message": "Webhook Test\n",
|
||||
"url": "http://localhost:3000/john/try-git/commit/d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"author": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"committer": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"timestamp": "2017-01-28T08:54:49-05:00"
|
||||
},
|
||||
{
|
||||
"id": "d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"message": "Webhook Test\n",
|
||||
"url": "http://localhost:3000/john/try-git/commit/d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"author": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"committer": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"timestamp": "2017-01-28T08:54:49-05:00"
|
||||
},
|
||||
{
|
||||
"id": "d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"message": "Webhook Test\n",
|
||||
"url": "http://localhost:3000/john/try-git/commit/d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"author": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"committer": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"timestamp": "2017-01-28T08:54:49-05:00"
|
||||
},
|
||||
{
|
||||
"id": "d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"message": "Webhook Test\n",
|
||||
"url": "http://localhost:3000/john/try-git/commit/d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"author": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"committer": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"timestamp": "2017-01-28T08:54:49-05:00"
|
||||
},
|
||||
{
|
||||
"id": "d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"message": "Webhook Test\n",
|
||||
"url": "http://localhost:3000/john/try-git/commit/d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"author": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"committer": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"timestamp": "2017-01-28T08:54:49-05:00"
|
||||
},
|
||||
{
|
||||
"id": "d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"message": "Webhook Test\n",
|
||||
"url": "http://localhost:3000/john/try-git/commit/d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"author": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"committer": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"timestamp": "2017-01-28T08:54:49-05:00"
|
||||
},
|
||||
{
|
||||
"id": "d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"message": "Webhook Test\n",
|
||||
"url": "http://localhost:3000/john/try-git/commit/d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"author": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"committer": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"timestamp": "2017-01-28T08:54:49-05:00"
|
||||
},
|
||||
{
|
||||
"id": "d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"message": "Webhook Test\n",
|
||||
"url": "http://localhost:3000/john/try-git/commit/d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"author": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"committer": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"timestamp": "2017-01-28T08:54:49-05:00"
|
||||
},
|
||||
{
|
||||
"id": "d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"message": "Webhook Test\n",
|
||||
"url": "http://localhost:3000/john/try-git/commit/d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"author": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"committer": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"timestamp": "2017-01-28T08:54:49-05:00"
|
||||
},
|
||||
{
|
||||
"id": "d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"message": "Webhook Test\n",
|
||||
"url": "http://localhost:3000/john/try-git/commit/d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"author": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"committer": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"timestamp": "2017-01-28T08:54:49-05:00"
|
||||
},
|
||||
{
|
||||
"id": "d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"message": "Webhook Test\n",
|
||||
"url": "http://localhost:3000/john/try-git/commit/d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"author": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"committer": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"timestamp": "2017-01-28T08:54:49-05:00"
|
||||
},
|
||||
{
|
||||
"id": "d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"message": "Webhook Test\n",
|
||||
"url": "http://localhost:3000/john/try-git/commit/d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"author": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"committer": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"timestamp": "2017-01-28T08:54:49-05:00"
|
||||
},
|
||||
{
|
||||
"id": "d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"message": "Webhook Test\n",
|
||||
"url": "http://localhost:3000/john/try-git/commit/d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"author": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"committer": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"timestamp": "2017-01-28T08:54:49-05:00"
|
||||
},
|
||||
{
|
||||
"id": "d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"message": "Webhook Test\n",
|
||||
"url": "http://localhost:3000/john/try-git/commit/d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"author": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"committer": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"timestamp": "2017-01-28T08:54:49-05:00"
|
||||
},
|
||||
{
|
||||
"id": "d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"message": "Webhook Test\n",
|
||||
"url": "http://localhost:3000/john/try-git/commit/d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"author": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"committer": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"timestamp": "2017-01-28T08:54:49-05:00"
|
||||
},
|
||||
{
|
||||
"id": "d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"message": "Webhook Test\n",
|
||||
"url": "http://localhost:3000/john/try-git/commit/d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"author": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"committer": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"timestamp": "2017-01-28T08:54:49-05:00"
|
||||
},
|
||||
{
|
||||
"id": "d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"message": "Webhook Test\n",
|
||||
"url": "http://localhost:3000/john/try-git/commit/d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"author": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"committer": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"timestamp": "2017-01-28T08:54:49-05:00"
|
||||
},
|
||||
{
|
||||
"id": "d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"message": "Webhook Test\n",
|
||||
"url": "http://localhost:3000/john/try-git/commit/d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"author": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"committer": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"timestamp": "2017-01-28T08:54:49-05:00"
|
||||
},
|
||||
{
|
||||
"id": "d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"message": "Webhook Test\n",
|
||||
"url": "http://localhost:3000/john/try-git/commit/d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"author": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"committer": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"timestamp": "2017-01-28T08:54:49-05:00"
|
||||
},
|
||||
{
|
||||
"id": "d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"message": "Webhook Test\n",
|
||||
"url": "http://localhost:3000/john/try-git/commit/d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"author": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"committer": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"timestamp": "2017-01-28T08:54:49-05:00"
|
||||
},
|
||||
{
|
||||
"id": "d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"message": "Webhook Test\n",
|
||||
"url": "http://localhost:3000/john/try-git/commit/d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"author": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"committer": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"timestamp": "2017-01-28T08:54:49-05:00"
|
||||
},
|
||||
{
|
||||
"id": "d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"message": "Webhook Test\n",
|
||||
"url": "http://localhost:3000/john/try-git/commit/d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"author": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"committer": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"timestamp": "2017-01-28T08:54:49-05:00"
|
||||
},
|
||||
{
|
||||
"id": "d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"message": "Webhook Test\n",
|
||||
"url": "http://localhost:3000/john/try-git/commit/d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"author": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"committer": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"timestamp": "2017-01-28T08:54:49-05:00"
|
||||
},
|
||||
{
|
||||
"id": "d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"message": "Webhook Test\n",
|
||||
"url": "http://localhost:3000/john/try-git/commit/d8fce16c72a2ff56a5afc8a08645a6ce45491794",
|
||||
"author": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"committer": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com",
|
||||
"username": ""
|
||||
},
|
||||
"timestamp": "2017-01-28T08:54:49-05:00"
|
||||
}
|
||||
],
|
||||
"repository": {
|
||||
"id": 1,
|
||||
"owner": {
|
||||
"id": 1,
|
||||
"login": "john",
|
||||
"full_name": "",
|
||||
"email": "john@example.com",
|
||||
"avatar_url": "https://secure.gravatar.com/avatar/ab4e102452ed53394cba1eb306de04c4",
|
||||
"username": "john"
|
||||
},
|
||||
"name": "try-git",
|
||||
"full_name": "john/try-git",
|
||||
"description": "",
|
||||
"private": false,
|
||||
"fork": false,
|
||||
"html_url": "http://localhost:3000/john/try-git",
|
||||
"ssh_url": "john@localhost:john/try-git.git",
|
||||
"clone_url": "http://localhost:3000/john/try-git.git",
|
||||
"website": "",
|
||||
"stars_count": 0,
|
||||
"forks_count": 0,
|
||||
"watchers_count": 1,
|
||||
"open_issues_count": 0,
|
||||
"default_branch": "master",
|
||||
"created_at": "2017-01-27T17:21:00-05:00",
|
||||
"updated_at": "2017-01-27T17:22:47-05:00"
|
||||
},
|
||||
"pusher": {
|
||||
"id": 1,
|
||||
"login": "john",
|
||||
"full_name": "",
|
||||
"email": "john@example.com",
|
||||
"avatar_url": "https://secure.gravatar.com/avatar/ab4e102452ed53394cba1eb306de04c4",
|
||||
"username": "john"
|
||||
},
|
||||
"sender": {
|
||||
"id": 1,
|
||||
"login": "john",
|
||||
"full_name": "",
|
||||
"email": "john@example.com",
|
||||
"avatar_url": "https://secure.gravatar.com/avatar/ab4e102452ed53394cba1eb306de04c4",
|
||||
"username": "john"
|
||||
}
|
||||
}
|
@@ -132,6 +132,7 @@ WEBHOOK_INTEGRATIONS = [
|
||||
function='zerver.webhooks.github_webhook.view.api_github_webhook'
|
||||
),
|
||||
WebhookIntegration('gitlab', display_name='GitLab'),
|
||||
WebhookIntegration('gogs'),
|
||||
WebhookIntegration('gosquared', display_name='GoSquared'),
|
||||
WebhookIntegration('greenhouse', display_name='Greenhouse'),
|
||||
WebhookIntegration('hellosign', display_name='HelloSign'),
|
||||
|
0
zerver/webhooks/gogs/__init__.py
Normal file
0
zerver/webhooks/gogs/__init__.py
Normal file
48
zerver/webhooks/gogs/doc.html
Normal file
48
zerver/webhooks/gogs/doc.html
Normal file
@@ -0,0 +1,48 @@
|
||||
<p>
|
||||
First, create the stream you'd like to use for Gogs notifications, and then
|
||||
subscribe all interested parties to this stream. The integration will use
|
||||
the default stream <code>commits</code> if no stream is supplied in the
|
||||
hook; you still need to
|
||||
<a target="_blank" href="../help/create-a-stream">create the stream</a>
|
||||
even if you are using this default.
|
||||
</p>
|
||||
|
||||
<p>Next, go to your repository page and click <b>Settings</b>:</p>
|
||||
<p><img src="/static/images/integrations/gogs/001.png"/></p>
|
||||
|
||||
<p>
|
||||
On the <b>Settings</b> page, select the <b>Webhooks</b> link on the left
|
||||
sidebar:
|
||||
</p>
|
||||
<p><img src="/static/images/integrations/gogs/002.png"/></p>
|
||||
|
||||
<p>
|
||||
Click the <b>Add Webhook</b> button and then select the <b>Gogs</b> option
|
||||
from the dropdown that appears.
|
||||
</p>
|
||||
<p><img class="screenshot" src="/static/images/integrations/gogs/003.png"/></p>
|
||||
|
||||
<p>Authorize yourself and configure your webhook.</p>
|
||||
|
||||
<p>In the <b>Payload URL</b> field, enter a URL in the format of:</p>
|
||||
|
||||
<p><code>{{ external_api_uri_subdomain }}/v1/external/gogs?api_key=abcdefgh&stream=gogs</code></p>
|
||||
|
||||
<p>where <code>api_key</code> is the API key of your Zulip bot.</p>
|
||||
|
||||
<p>Then, set <b>Content type</b> to <code>application/json</code>.</p>
|
||||
|
||||
<p>
|
||||
Next, select the events that you want to trigger Zulip notifications. After
|
||||
you have selected all the desired events, click the <b>Add Webhook</b>
|
||||
button.
|
||||
</p>
|
||||
|
||||
<p><img class="screenshot" src="/static/images/integrations/gogs/004.png"/></p>
|
||||
|
||||
<p>
|
||||
<b>Congratulations! You're done!</b><br/>
|
||||
Your messages will look like this:
|
||||
</p>
|
||||
|
||||
<p><img class="screenshot" src="/static/images/integrations/gogs/005.png"/></p>
|
55
zerver/webhooks/gogs/tests.py
Normal file
55
zerver/webhooks/gogs/tests.py
Normal file
@@ -0,0 +1,55 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from typing import Text
|
||||
from zerver.lib.webhooks.git import COMMITS_LIMIT
|
||||
from zerver.lib.test_classes import WebhookTestCase
|
||||
|
||||
|
||||
class GogsHookTests(WebhookTestCase):
|
||||
STREAM_NAME = 'commits'
|
||||
URL_TEMPLATE = "/api/v1/external/gogs?&api_key={api_key}"
|
||||
FIXTURE_DIR_NAME = 'gogs'
|
||||
|
||||
def test_push(self):
|
||||
# type: () -> None
|
||||
expected_subject = u"try-git / master"
|
||||
expected_message = u"""john [pushed](http://localhost:3000/john/try-git/compare/479e6b772b7fba19412457483f50b201286d0103...d8fce16c72a2ff56a5afc8a08645a6ce45491794) to branch master
|
||||
|
||||
* Webhook Test ([d8fce16](http://localhost:3000/john/try-git/commit/d8fce16c72a2ff56a5afc8a08645a6ce45491794))"""
|
||||
self.send_and_test_stream_message('push', expected_subject, expected_message, HTTP_X_GOGS_EVENT='push')
|
||||
|
||||
def test_push_commits_more_than_limits(self):
|
||||
# type: () -> None
|
||||
expected_subject = u"try-git / master"
|
||||
commits_info = "* Webhook Test ([d8fce16](http://localhost:3000/john/try-git/commit/d8fce16c72a2ff56a5afc8a08645a6ce45491794))\n"
|
||||
expected_message = u"john [pushed](http://localhost:3000/john/try-git/compare/479e6b772b7fba19412457483f50b201286d0103...d8fce16c72a2ff56a5afc8a08645a6ce45491794) to branch master\n\n{}[and {} more commit(s)]".format(
|
||||
commits_info * COMMITS_LIMIT,
|
||||
30 - COMMITS_LIMIT
|
||||
)
|
||||
self.send_and_test_stream_message('push_commits_more_than_limits', expected_subject, expected_message, HTTP_X_GOGS_EVENT='push')
|
||||
|
||||
def test_new_branch(self):
|
||||
# type: () -> None
|
||||
expected_subject = u"try-git / my_feature"
|
||||
expected_message = u"john created [my_feature](http://localhost:3000/john/try-git/src/my_feature) branch"
|
||||
self.send_and_test_stream_message('branch', expected_subject, expected_message, HTTP_X_GOGS_EVENT='create')
|
||||
|
||||
def test_pull_request_opened(self):
|
||||
# type: () -> None
|
||||
expected_subject = u"try-git / PR #1 Title Text for Pull Request"
|
||||
expected_message = u"""john opened [PR #1](http://localhost:3000/john/try-git/pulls/1)
|
||||
from `feature` to `master`"""
|
||||
self.send_and_test_stream_message('pull_request_opened', expected_subject, expected_message, HTTP_X_GOGS_EVENT='pull_request')
|
||||
|
||||
def test_pull_request_closed(self):
|
||||
# type: () -> None
|
||||
expected_subject = u"try-git / PR #1 Title Text for Pull Request"
|
||||
expected_message = u"""john closed [PR #1](http://localhost:3000/john/try-git/pulls/1)
|
||||
from `feature` to `master`"""
|
||||
self.send_and_test_stream_message('pull_request_closed', expected_subject, expected_message, HTTP_X_GOGS_EVENT='pull_request')
|
||||
|
||||
def test_pull_request_merged(self):
|
||||
# type: () -> None
|
||||
expected_subject = u"try-git / PR #2 Title Text for Pull Request"
|
||||
expected_message = u"""john merged [PR #2](http://localhost:3000/john/try-git/pulls/2)
|
||||
from `feature` to `master`"""
|
||||
self.send_and_test_stream_message('pull_request_merged', expected_subject, expected_message, HTTP_X_GOGS_EVENT='pull_request')
|
99
zerver/webhooks/gogs/view.py
Normal file
99
zerver/webhooks/gogs/view.py
Normal file
@@ -0,0 +1,99 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# vim:fenc=utf-8
|
||||
from __future__ import absolute_import
|
||||
from django.utils.translation import ugettext as _
|
||||
from zerver.lib.actions import check_send_message
|
||||
from zerver.lib.response import json_success, json_error
|
||||
from zerver.decorator import REQ, has_request_variables, api_key_only_webhook_view
|
||||
from zerver.models import Client, UserProfile
|
||||
from zerver.lib.webhooks.git import get_push_commits_event_message, \
|
||||
get_pull_request_event_message, get_create_branch_event_message, \
|
||||
SUBJECT_WITH_BRANCH_TEMPLATE, SUBJECT_WITH_PR_OR_ISSUE_INFO_TEMPLATE
|
||||
|
||||
from django.http import HttpRequest, HttpResponse
|
||||
from typing import Dict, Any, Iterable, Optional, Text
|
||||
|
||||
def format_push_event(payload):
|
||||
# type: (Dict[str, Any]) -> Text
|
||||
|
||||
for commit in payload['commits']:
|
||||
commit['sha'] = commit['id']
|
||||
|
||||
data = {
|
||||
'user_name': payload['sender']['username'],
|
||||
'compare_url': payload['compare_url'],
|
||||
'branch_name': payload['ref'].replace('refs/heads/', ''),
|
||||
'commits_data': payload['commits']
|
||||
}
|
||||
|
||||
return get_push_commits_event_message(**data)
|
||||
|
||||
def format_new_branch_event(payload):
|
||||
# type: (Dict[str, Any]) -> Text
|
||||
|
||||
branch_name = payload['ref']
|
||||
url = '{}/src/{}'.format(payload['repository']['html_url'], branch_name)
|
||||
|
||||
data = {
|
||||
'user_name': payload['sender']['username'],
|
||||
'url': url,
|
||||
'branch_name': branch_name
|
||||
}
|
||||
return get_create_branch_event_message(**data)
|
||||
|
||||
def format_pull_request_event(payload):
|
||||
# type: (Dict[str, Any]) -> Text
|
||||
|
||||
data = {
|
||||
'user_name': payload['pull_request']['user']['username'],
|
||||
'action': payload['action'],
|
||||
'url': payload['pull_request']['html_url'],
|
||||
'number': payload['pull_request']['number'],
|
||||
'target_branch': payload['pull_request']['head_branch'],
|
||||
'base_branch': payload['pull_request']['base_branch'],
|
||||
}
|
||||
|
||||
if payload['pull_request']['merged']:
|
||||
data['user_name'] = payload['pull_request']['merged_by']['username']
|
||||
data['action'] = 'merged'
|
||||
|
||||
return get_pull_request_event_message(**data)
|
||||
|
||||
@api_key_only_webhook_view('Gogs')
|
||||
@has_request_variables
|
||||
def api_gogs_webhook(request, user_profile, client,
|
||||
payload=REQ(argument_type='body'),
|
||||
stream=REQ(default='commits')):
|
||||
# type: (HttpRequest, UserProfile, Client, Dict[str, Any], Text) -> HttpResponse
|
||||
|
||||
repo = payload['repository']['name']
|
||||
event = request.META['HTTP_X_GOGS_EVENT']
|
||||
|
||||
try:
|
||||
if event == 'push':
|
||||
body = format_push_event(payload)
|
||||
topic = SUBJECT_WITH_BRANCH_TEMPLATE.format(
|
||||
repo=repo,
|
||||
branch=payload['ref'].replace('refs/heads/', '')
|
||||
)
|
||||
elif event == 'create':
|
||||
body = format_new_branch_event(payload)
|
||||
topic = SUBJECT_WITH_BRANCH_TEMPLATE.format(
|
||||
repo=repo,
|
||||
branch=payload['ref']
|
||||
)
|
||||
elif event == 'pull_request':
|
||||
body = format_pull_request_event(payload)
|
||||
topic = SUBJECT_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format(
|
||||
repo=repo,
|
||||
type='PR',
|
||||
id=payload['pull_request']['id'],
|
||||
title=payload['pull_request']['title']
|
||||
)
|
||||
else:
|
||||
return json_error(_('Invalid event "{}" in request headers').format(event))
|
||||
except KeyError as e:
|
||||
return json_error(_('Missing key {} in JSON').format(str(e)))
|
||||
|
||||
check_send_message(user_profile, client, 'stream', [stream], topic, body)
|
||||
return json_success()
|
Reference in New Issue
Block a user