Commit c12c77eb authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'feature/improve_wiki_page_events' into 'master'

Include Wiki attributes in Wiki page events webhook

The hook data we are sending is not 100% correct (we send details of the project, but should also send details of the "ProjectWiki" attributes like URLs and repositories relative to the wiki itself).

This is a follow up to #17506

Fixes #17507

See merge request !4138
parents e87149a1 6d16feef
...@@ -2,6 +2,7 @@ Please view this file on the master branch, on stable branches it's out of date. ...@@ -2,6 +2,7 @@ Please view this file on the master branch, on stable branches it's out of date.
v 8.9.0 (unreleased) v 8.9.0 (unreleased)
- Allow enabling wiki page events from Webhook management UI - Allow enabling wiki page events from Webhook management UI
- Fix wiki page events' webhook to point to the wiki repository
- Allow forking projects with restricted visibility level - Allow forking projects with restricted visibility level
- Improve note validation to prevent errors when creating invalid note via API - Improve note validation to prevent errors when creating invalid note via API
- Remove project notification settings associated with deleted projects - Remove project notification settings associated with deleted projects
......
...@@ -27,6 +27,10 @@ class ProjectWiki ...@@ -27,6 +27,10 @@ class ProjectWiki
@project.path_with_namespace + ".wiki" @project.path_with_namespace + ".wiki"
end end
def web_url
Gitlab::Routing.url_helpers.namespace_project_wiki_url(@project.namespace, @project, :home)
end
def url_to_repo def url_to_repo
gitlab_shell.url_to_repo(path_with_namespace) gitlab_shell.url_to_repo(path_with_namespace)
end end
...@@ -142,6 +146,16 @@ class ProjectWiki ...@@ -142,6 +146,16 @@ class ProjectWiki
wiki wiki
end end
def hook_attrs
{
web_url: web_url,
git_ssh_url: ssh_url_to_repo,
git_http_url: http_url_to_repo,
path_with_namespace: path_with_namespace,
default_branch: default_branch
}
end
private private
def init_repo(path_with_namespace) def init_repo(path_with_namespace)
......
...@@ -6,9 +6,8 @@ module WikiPages ...@@ -6,9 +6,8 @@ module WikiPages
object_kind: page.class.name.underscore, object_kind: page.class.name.underscore,
user: current_user.hook_attrs, user: current_user.hook_attrs,
project: @project.hook_attrs, project: @project.hook_attrs,
object_attributes: page.hook_attrs, wiki: @project.wiki.hook_attrs,
# DEPRECATED object_attributes: page.hook_attrs
repository: @project.hook_attrs.slice(:name, :url, :description, :homepage)
} }
page_url = Gitlab::UrlBuilder.build(page) page_url = Gitlab::UrlBuilder.build(page)
......
...@@ -720,7 +720,7 @@ X-Gitlab-Event: Wiki Page Hook ...@@ -720,7 +720,7 @@ X-Gitlab-Event: Wiki Page Hook
"description": "This is awesome", "description": "This is awesome",
"web_url": "http://example.com/root/awesome-project", "web_url": "http://example.com/root/awesome-project",
"avatar_url": null, "avatar_url": null,
"git_ssh_url": "git@example.com:root/test-project.git", "git_ssh_url": "git@example.com:root/awesome-project.git",
"git_http_url": "http://example.com/root/awesome-project.git", "git_http_url": "http://example.com/root/awesome-project.git",
"namespace": "root", "namespace": "root",
"visibility_level": 0, "visibility_level": 0,
...@@ -731,6 +731,13 @@ X-Gitlab-Event: Wiki Page Hook ...@@ -731,6 +731,13 @@ X-Gitlab-Event: Wiki Page Hook
"ssh_url": "git@example.com:root/awesome-project.git", "ssh_url": "git@example.com:root/awesome-project.git",
"http_url": "http://example.com/root/awesome-project.git" "http_url": "http://example.com/root/awesome-project.git"
}, },
"wiki": {
"web_url": "http://example.com/root/awesome-project/wikis/home",
"git_ssh_url": "git@example.com:root/awesome-project.wiki.git",
"git_http_url": "http://example.com/root/awesome-project.wiki.git",
"path_with_namespace": "root/awesome-project.wiki",
"default_branch": "master"
},
"object_attributes": { "object_attributes": {
"title": "Awesome", "title": "Awesome",
"content": "awesome content goes here", "content": "awesome content goes here",
...@@ -739,12 +746,6 @@ X-Gitlab-Event: Wiki Page Hook ...@@ -739,12 +746,6 @@ X-Gitlab-Event: Wiki Page Hook
"slug": "awesome", "slug": "awesome",
"url": "http://example.com/root/awesome-project/wikis/awesome", "url": "http://example.com/root/awesome-project/wikis/awesome",
"action": "create" "action": "create"
},
"repository": {
"name": "awesome-project",
"url": "git@example.com:root/awesome-project.git",
"description": "test",
"homepage": "http://example.com/root/awesome-project"
} }
} }
``` ```
......
...@@ -16,6 +16,12 @@ describe ProjectWiki, models: true do ...@@ -16,6 +16,12 @@ describe ProjectWiki, models: true do
end end
end end
describe '#web_url' do
it 'returns the full web URL to the wiki' do
expect(subject.web_url).to eq("#{Gitlab.config.gitlab.url}/#{project.path_with_namespace}/wikis/home")
end
end
describe "#url_to_repo" do describe "#url_to_repo" do
it "returns the correct ssh url to the repo" do it "returns the correct ssh url to the repo" do
expect(subject.url_to_repo).to eq(gitlab_shell.url_to_repo(subject.path_with_namespace)) expect(subject.url_to_repo).to eq(gitlab_shell.url_to_repo(subject.path_with_namespace))
...@@ -257,6 +263,13 @@ describe ProjectWiki, models: true do ...@@ -257,6 +263,13 @@ describe ProjectWiki, models: true do
end end
end end
describe '#hook_attrs' do
it 'returns a hash with values' do
expect(subject.hook_attrs).to be_a Hash
expect(subject.hook_attrs.keys).to contain_exactly(:web_url, :git_ssh_url, :git_http_url, :path_with_namespace, :default_branch)
end
end
private private
def create_temp_repo(path) def create_temp_repo(path)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment