Skip to content

Commit

Permalink
Merge pull request #1200 from RonaldPrithiv/master
Browse files Browse the repository at this point in the history
Update RegEx pattern for Bitrise projects
  • Loading branch information
RonaldPrithiv committed Mar 11, 2020
2 parents d06b02e + 9f30c43 commit c51e39c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -9,6 +9,8 @@
-->

## master

* Update RegEx pattern used for URL matching for bitrise projects. [@RonaldPrithiv](https://github.com/RonaldPrithiv)
* Refactor shared code from Violation and Markdown into a base class [@telyn] [#1186](https://github.com/danger/danger/pull/1184)
* Add <=> methods to Violation and Markdown [@telyn] [#1186](https://github.com/danger/danger/pull/1184)
* Add sketch of MessageGroup and a totally unimplemented MessageAggregator, for the coming PR-host-agnostic
Expand Down
15 changes: 9 additions & 6 deletions lib/danger/ci_source/bitrise.rb
Expand Up @@ -48,13 +48,16 @@ def supported_request_sources
def initialize(env)
self.pull_request_id = env["BITRISE_PULL_REQUEST"]
self.repo_url = env["GIT_REPOSITORY_URL"]

if repo_url.include? ".com/"
repo_matches = self.repo_url.match(%r{\.com/(.*)})[1].split(/\.git$|$/)[0]
elsif repo_url.include? ".com:"
repo_matches = self.repo_url.match(%r{\.com:(.*)})[1].split(/\.git$|$/)[0]
end

matcher_url = self.repo_url

#If the URL contains https:// as :// leads to inaccurate matching. So we remove it and proceed to match.
if repo_url.include? "https://"
matcher_url["https://"] = ''
end

repo_matches = matcher_url.match(%r{([\/:])(([^\/]+\/)+[^\/]+?)(\.git$|$)})[2]

self.repo_slug = repo_matches unless repo_matches.nil?

end
Expand Down
5 changes: 5 additions & 0 deletions spec/lib/danger/ci_sources/bitrise_spec.rb
Expand Up @@ -76,6 +76,11 @@
valid_env["GIT_REPOSITORY_URL"] = "https://github.com/artsy/ios/artsy.github.io.git"
expect(source.repo_slug).to eq("artsy/ios/artsy.github.io")
end

it "sets the repo_slug from a repo with .io instead of .com", host: :github do
valid_env["GIT_REPOSITORY_URL"] = "git@github.company.io/artsy/ios/artsy.github.io.git"
expect(source.repo_slug).to eq("artsy/ios/artsy.github.io")
end

it "sets the pull_request_id" do
expect(source.pull_request_id).to eq("4")
Expand Down

0 comments on commit c51e39c

Please sign in to comment.