-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ability to fetch_repositories by web hook from bitbucket
- Loading branch information
1 parent
1416b46
commit 901d852
Showing
6 changed files
with
105 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
module RedmineUndevGit::Services | ||
class BitbucketRepo < ExtRepo | ||
attr_reader :repo_owner | ||
def initialize(absolute_url, canon_url, repo_owner) | ||
if m = /\Ahttps?:\/\/(?<host>.+?)\z/.match(canon_url) | ||
@host = m[:host] | ||
else | ||
raise RedmineUndevGit::Services::WrongRepoUrl | ||
end | ||
if m = /\A\/(?<path_to_repo>.+)\/\z/.match(absolute_url) | ||
@path_to_repo = m[:path_to_repo] | ||
else | ||
raise RedmineUndevGit::Services::WrongRepoUrl | ||
end | ||
@user = 'git' | ||
@repo_owner = repo_owner | ||
end | ||
|
||
def git_urls | ||
[ssh_url, https_url, https_with_owner_url] | ||
end | ||
|
||
def https_with_owner_url | ||
"https://#{repo_owner}@#{host}/#{path_to_repo}.git" | ||
end | ||
end | ||
|
||
class Bitbucket | ||
class << self | ||
def git_urls_from_request(request) | ||
web_hook = web_hook_from_request(request) | ||
repo = RedmineUndevGit::Services::BitbucketRepo.new( | ||
web_hook['repository']['absolute_url'], web_hook['canon_url'], web_hook['user']) | ||
repo.git_urls | ||
end | ||
|
||
def web_hook_from_request(request) | ||
JSON.parse(request.params[:payload]) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,14 @@ def test_success_on_github_ping_hook_when_login_requred | |
assert_response :success | ||
end | ||
|
||
def test_fetch_after_bitbucket_push_hook | ||
repository = create_test_repository(:project => @project, :url => 'https://bitbucket.org/test/dt_fetch.git') | ||
assert repository | ||
Workers::RepositoryFetcher.expects(:defer).with(repository.id).at_least_once | ||
post '/bitbucket_hooks', :payload => bitbucket_payload.to_json | ||
assert_response :success | ||
end | ||
|
||
def gitlab_payload | ||
{ | ||
before: '95790bf891e76fee5e1747ab589903a6a1f80f22', | ||
|
@@ -259,4 +267,40 @@ def github_ping_headers | |
'HTTP_X_GITHUB_EVENT' => 'ping' | ||
} | ||
end | ||
|
||
def bitbucket_payload | ||
{ | ||
repository: { | ||
website: '', | ||
fork: false, | ||
name: 'dt_fetch', | ||
scm: 'git', | ||
owner: 'test', | ||
absolute_url: '/test/dt_fetch/', | ||
slug: 'dt_fetch', | ||
is_private: false | ||
}, | ||
truncated: false, | ||
commits: [ | ||
{ | ||
node: '81c83664d120', | ||
files: [ | ||
{type: 'added', file: 'update5.txt'} | ||
], | ||
raw_author: 'Test <[email protected]>', | ||
utctimestamp: '2014-06-06 07:04:38+00:00', | ||
author: 'test', | ||
timestamp: '2014-06-06 09:04:38', | ||
raw_node: '81c83664d120ce05c91b7259b70c02ebc64edd52', | ||
parents: ['75d5e5aef45a'], | ||
branch: 'master', | ||
message: 'update 5', | ||
revision: nil, | ||
size: -1 | ||
} | ||
], | ||
canon_url: 'https://bitbucket.org', | ||
user: 'test' | ||
} | ||
end | ||
end |