Commit 190b7b45 authored by Douwe Maan's avatar Douwe Maan

Autolink package names in podspec

parent 03db4f11
......@@ -6,6 +6,7 @@ module Gitlab
PackageJsonLinker,
ComposerJsonLinker,
PodfileLinker,
PodspecLinker,
].freeze
def self.linker(blob_name)
......
module Gitlab
module DependencyLinker
class PodspecLinker < MethodLinker
include Cocoapods
STRING_REGEX = /['"](?<name>[^'"]+)['"]/.freeze
self.file_type = :podspec
private
def link_dependencies
link_method_call('homepage', URL_REGEX, &:itself)
link_regex(%r{(git:|:git\s*=>)\s*['"](?<name>#{URL_REGEX})['"]}, &:itself)
link_method_call('license', &method(:license_url))
link_regex(/license\s*=\s*\{\s*(type:|:type\s*=>)\s*#{STRING_REGEX}/, &method(:license_url))
link_method_call(%w[name dependency], &method(:package_url))
end
end
end
end
require 'rails_helper'
describe Gitlab::DependencyLinker::PodspecLinker, lib: true do
describe '.support?' do
it 'supports *.podspec' do
expect(described_class.support?('Reachability.podspec')).to be_truthy
end
it 'does not support other files' do
expect(described_class.support?('.podspec.example')).to be_falsey
end
end
describe '#link' do
let(:file_name) { "Reachability.podspec" }
let(:file_content) do
<<-CONTENT.strip_heredoc
Pod::Spec.new do |spec|
spec.name = 'Reachability'
spec.version = '3.1.0'
spec.license = { :type => 'GPL-3.0' }
spec.license = "MIT"
spec.license = { type: 'Apache-2.0' }
spec.homepage = 'https://github.com/tonymillion/Reachability'
spec.authors = { 'Tony Million' => 'tonymillion@gmail.com' }
spec.summary = 'ARC and GCD Compatible Reachability Class for iOS and OS X.'
spec.source = { :git => 'https://github.com/tonymillion/Reachability.git', :tag => 'v3.1.0' }
spec.source_files = 'Reachability.{h,m}'
spec.framework = 'SystemConfiguration'
spec.dependency 'AFNetworking', '~> 1.0'
spec.dependency 'RestKit/CoreData', '~> 0.20.0'
spec.ios.dependency 'MBProgressHUD', '~> 0.5'
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 the gem name' do
expect(subject).to include(link('Reachability', 'https://cocoapods.org/pods/Reachability'))
end
it 'links the license' do
expect(subject).to include(link('GPL-3.0', 'http://choosealicense.com/licenses/gpl-3.0/'))
expect(subject).to include(link('MIT', 'http://choosealicense.com/licenses/mit/'))
expect(subject).to include(link('Apache-2.0', 'http://choosealicense.com/licenses/apache-2.0/'))
end
it 'links the homepage' do
expect(subject).to include(link('https://github.com/tonymillion/Reachability', 'https://github.com/tonymillion/Reachability'))
end
it 'links the source URL' do
expect(subject).to include(link('https://github.com/tonymillion/Reachability.git', 'https://github.com/tonymillion/Reachability.git'))
end
it 'links dependencies' do
expect(subject).to include(link('AFNetworking', 'https://cocoapods.org/pods/AFNetworking'))
expect(subject).to include(link('RestKit/CoreData', 'https://cocoapods.org/pods/RestKit'))
expect(subject).to include(link('MBProgressHUD', 'https://cocoapods.org/pods/MBProgressHUD'))
end
end
end
......@@ -41,5 +41,13 @@ describe Gitlab::DependencyLinker, lib: true do
described_class.link(blob_name, nil, nil)
end
it 'links using PodspecLinker' do
blob_name = 'Reachability.podspec'
expect(described_class::PodspecLinker).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