From aaaed331ba06d14f0e071e0933a250c61caabf94 Mon Sep 17 00:00:00 2001 From: Gabriel Mazetto Date: Fri, 13 May 2016 04:21:01 -0300 Subject: Fix hook data for Wiki Page event Added "wiki" section and removed "repository" --- app/models/project_wiki.rb | 14 ++++++++++++++ app/services/wiki_pages/base_service.rb | 5 ++--- doc/web_hooks/web_hooks.md | 15 ++++++++------- spec/models/project_wiki_spec.rb | 13 +++++++++++++ 4 files changed, 37 insertions(+), 10 deletions(-) diff --git a/app/models/project_wiki.rb b/app/models/project_wiki.rb index 339fb0b9f9d..415393d7368 100644 --- a/app/models/project_wiki.rb +++ b/app/models/project_wiki.rb @@ -27,6 +27,10 @@ class ProjectWiki @project.path_with_namespace + ".wiki" end + def web_url + Gitlab::Routing.url_helpers.namespace_project_wiki_url(@project.namespace, @project, :home) + end + def url_to_repo gitlab_shell.url_to_repo(path_with_namespace) end @@ -141,6 +145,16 @@ class ProjectWiki wiki 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 diff --git a/app/services/wiki_pages/base_service.rb b/app/services/wiki_pages/base_service.rb index 9162f128602..4c0a2c6b4d8 100644 --- a/app/services/wiki_pages/base_service.rb +++ b/app/services/wiki_pages/base_service.rb @@ -6,9 +6,8 @@ module WikiPages object_kind: page.class.name.underscore, user: current_user.hook_attrs, project: @project.hook_attrs, - object_attributes: page.hook_attrs, - # DEPRECATED - repository: @project.hook_attrs.slice(:name, :url, :description, :homepage) + wiki: @project.wiki.hook_attrs, + object_attributes: page.hook_attrs } page_url = Gitlab::UrlBuilder.build(page) diff --git a/doc/web_hooks/web_hooks.md b/doc/web_hooks/web_hooks.md index 0777463def5..8559b67af04 100644 --- a/doc/web_hooks/web_hooks.md +++ b/doc/web_hooks/web_hooks.md @@ -720,7 +720,7 @@ X-Gitlab-Event: Wiki Page Hook "description": "This is awesome", "web_url": "http://example.com/root/awesome-project", "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", "namespace": "root", "visibility_level": 0, @@ -731,6 +731,13 @@ X-Gitlab-Event: Wiki Page Hook "ssh_url": "git@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": { "title": "Awesome", "content": "awesome content goes here", @@ -739,12 +746,6 @@ X-Gitlab-Event: Wiki Page Hook "slug": "awesome", "url": "http://example.com/root/awesome-project/wikis/awesome", "action": "create" - }, - "repository": { - "name": "awesome-project", - "url": "git@example.com:root/awesome-project.git", - "description": "test", - "homepage": "http://example.com/root/awesome-project" } } ``` diff --git a/spec/models/project_wiki_spec.rb b/spec/models/project_wiki_spec.rb index 91ebb612baa..58b57bd4fef 100644 --- a/spec/models/project_wiki_spec.rb +++ b/spec/models/project_wiki_spec.rb @@ -16,6 +16,12 @@ describe ProjectWiki, models: true do 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 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)) @@ -257,6 +263,13 @@ describe ProjectWiki, models: true do 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 def create_temp_repo(path) -- cgit v1.2.1 From 04084996e5f18b67abaf0d9aa54d9d51a31ecd7c Mon Sep 17 00:00:00 2001 From: Gabriel Mazetto Date: Fri, 27 May 2016 20:31:03 -0300 Subject: Codestyle changes --- app/models/project_wiki.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/project_wiki.rb b/app/models/project_wiki.rb index 415393d7368..25d82929c0b 100644 --- a/app/models/project_wiki.rb +++ b/app/models/project_wiki.rb @@ -145,14 +145,14 @@ class ProjectWiki wiki 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, + default_branch: default_branch } end -- cgit v1.2.1 From 6d16feef053cc453552803885add0a2755e58399 Mon Sep 17 00:00:00 2001 From: Gabriel Mazetto Date: Tue, 31 May 2016 12:07:01 -0300 Subject: Add wiki page events fix to the Changelog --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index 98e24dc63b1..3dc7214cad9 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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) - 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 - Improve note validation to prevent errors when creating invalid note via API - Redesign navigation for project pages -- cgit v1.2.1