Commit 03db4f11 authored by Douwe Maan's avatar Douwe Maan

Autolink package names in Podfile

parent fbec6dbd
......@@ -5,6 +5,7 @@ module Gitlab
GemspecLinker,
PackageJsonLinker,
ComposerJsonLinker,
PodfileLinker,
].freeze
def self.linker(blob_name)
......
module Gitlab
module DependencyLinker
module Cocoapods
def package_url(name)
package = name.split("/", 2).first
"https://cocoapods.org/pods/#{package}"
end
end
end
end
module Gitlab
module DependencyLinker
class PodfileLinker < GemfileLinker
include Cocoapods
self.file_type = :podfile
private
def link_packages
link_method_call('pod', &method(:package_url))
end
end
end
end
require 'rails_helper'
describe Gitlab::DependencyLinker::PodfileLinker, lib: true do
describe '.support?' do
it 'supports Podfile' do
expect(described_class.support?('Podfile')).to be_truthy
end
it 'does not support other files' do
expect(described_class.support?('Podfile.lock')).to be_falsey
end
end
describe '#link' do
let(:file_name) { "Podfile" }
let(:file_content) do
<<-CONTENT.strip_heredoc
source 'https://github.com/artsy/Specs.git'
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!
inhibit_all_warnings!
target 'Artsy' do
pod 'AFNetworking', "~> 2.5"
pod 'Interstellar/Core', git: 'https://github.com/ashfurrow/Interstellar.git', branch: 'observable-unsubscribe'
end
CONTENT
end
subject { Gitlab::Highlight.highlight(file_name, file_content) }
def link(name, url)
%{<a href="#{url}" rel="nofollow noreferrer noopener" target="_blank">#{name}</a>}
end
it 'links sources' do
expect(subject).to include(link('https://github.com/artsy/Specs.git', 'https://github.com/artsy/Specs.git'))
expect(subject).to include(link('https://github.com/CocoaPods/Specs.git', 'https://github.com/CocoaPods/Specs.git'))
end
it 'links packages' do
expect(subject).to include(link('AFNetworking', 'https://cocoapods.org/pods/AFNetworking'))
expect(subject).to include(link('Interstellar/Core', 'https://cocoapods.org/pods/Interstellar'))
end
it 'links Git repos' do
expect(subject).to include(link('https://github.com/ashfurrow/Interstellar.git', 'https://github.com/ashfurrow/Interstellar.git'))
end
end
end
......@@ -33,5 +33,13 @@ describe Gitlab::DependencyLinker, lib: true do
described_class.link(blob_name, nil, nil)
end
it 'links using PodfileLinker' do
blob_name = 'Podfile'
expect(described_class::PodfileLinker).to receive(:link)
described_class.link(blob_name, nil, nil)
end
end
end
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