Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add Cake support #958

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Dockerfile.ci
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ COPY nuget/Gemfile \
/home/dependabot/dependabot-core/nuget/
RUN cd nuget && bundle install

RUN mkdir -p /home/dependabot/dependabot-core/cake
COPY cake/Gemfile \
cake/dependabot-cake.gemspec \
/home/dependabot/dependabot-core/cake/
RUN cd cake && bundle install

RUN mkdir -p /home/dependabot/dependabot-core/composer
COPY composer/Gemfile \
composer/dependabot-composer.gemspec \
Expand Down
4 changes: 4 additions & 0 deletions Dockerfile.development
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ RUN mkdir -p /home/dependabot/dependabot-core/nuget
COPY nuget/Gemfile nuget/dependabot-nuget.gemspec /home/dependabot/dependabot-core/nuget/
RUN cd nuget && bundle install

RUN mkdir -p /home/dependabot/dependabot-core/cake
COPY cake/Gemfile cake/dependabot-cake.gemspec /home/dependabot/dependabot-core/cake/
RUN cd cake && bundle install

RUN mkdir -p /home/dependabot/dependabot-core/maven
COPY maven/Gemfile maven/dependabot-maven.gemspec /home/dependabot/dependabot-core/maven/
RUN cd maven && bundle install
Expand Down
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ GEMSPECS = %w(
docker/dependabot-docker.gemspec
git_submodules/dependabot-git_submodules.gemspec
nuget/dependabot-nuget.gemspec
cake/dependabot-cake.gemspec
gradle/dependabot-gradle.gemspec
maven/dependabot-maven.gemspec
npm_and_yarn/dependabot-npm_and_yarn.gemspec
Expand Down
4 changes: 4 additions & 0 deletions bin/docker-dev-shell
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ docker run --rm -ti \
-v "$(pwd)/nuget/dependabot-nuget.gemspec:$CODE_DIR/nuget/dependabot-core.gemspec" \
-v "$(pwd)/nuget/lib:$CODE_DIR/nuget/lib" \
-v "$(pwd)/nuget/spec:$CODE_DIR/nuget/spec" \
-v "$(pwd)/cake/Gemfile:$CODE_DIR/cake/Gemfile" \
-v "$(pwd)/cake/dependabot-cake.gemspec:$CODE_DIR/cake/dependabot-core.gemspec" \
-v "$(pwd)/cake/lib:$CODE_DIR/cake/lib" \
-v "$(pwd)/cake/spec:$CODE_DIR/cake/spec" \
-v "$(pwd)/maven/Gemfile:$CODE_DIR/maven/Gemfile" \
-v "$(pwd)/maven/dependabot-maven.gemspec:$CODE_DIR/maven/dependabot-core.gemspec" \
-v "$(pwd)/maven/lib:$CODE_DIR/maven/lib" \
Expand Down
3 changes: 3 additions & 0 deletions bin/dry-run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
# - hex
# - composer
# - nuget
# - cake
# - dep
# - go_modules
# - elm
Expand All @@ -37,6 +38,7 @@
$LOAD_PATH << "./docker/lib"
$LOAD_PATH << "./git_submodules/lib"
$LOAD_PATH << "./nuget/lib"
$LOAD_PATH << "./cake/lib"
$LOAD_PATH << "./cargo/lib"
$LOAD_PATH << "./gradle/lib"
$LOAD_PATH << "./maven/lib"
Expand All @@ -57,6 +59,7 @@
require "dependabot/docker"
require "dependabot/git_submodules"
require "dependabot/nuget"
require "dependabot/cake"
require "dependabot/gradle"
require "dependabot/maven"
require "dependabot/hex"
Expand Down
5 changes: 5 additions & 0 deletions cake/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/.bundle/
/.env
/tmp
/dependabot-*.gem
Gemfile.lock
1 change: 1 addition & 0 deletions cake/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
inherit_from: ../config/rubocop-default.yml
7 changes: 7 additions & 0 deletions cake/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

source "https://rubygems.org"

gem "dependabot-core", path: "../"

gemspec
17 changes: 17 additions & 0 deletions cake/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## `dependabot-cake`

Cake support for [`dependabot-core`][core-repo].

### Running locally

1. Install Ruby dependencies
```
$ bundle install
```

2. Run tests
```
$ bundle exec rspec spec
```

[core-repo]: https://github.com/dependabot/dependabot-core
27 changes: 27 additions & 0 deletions cake/dependabot-cake.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

Gem::Specification.new do |spec|
core_gemspec = Bundler.load_gemspec_uncached("../dependabot-core.gemspec")

spec.name = "dependabot-cake"
spec.summary = ".NET (Cake) support for dependabot-core"
spec.version = core_gemspec.version
spec.description = core_gemspec.description

spec.author = core_gemspec.author
spec.email = core_gemspec.email
spec.homepage = core_gemspec.homepage
spec.license = core_gemspec.license

spec.require_path = "lib"
spec.files = Dir["lib/**/*"]

spec.required_ruby_version = core_gemspec.required_ruby_version
spec.required_rubygems_version = core_gemspec.required_ruby_version

spec.add_dependency "dependabot-core", Dependabot::VERSION

core_gemspec.development_dependencies.each do |dep|
spec.add_development_dependency dep.name, dep.requirement.to_s
end
end
7 changes: 7 additions & 0 deletions cake/lib/dependabot/cake.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

# These all need to be required so the various classes can be registered in a
# lookup table of package manager names to concrete classes.
require "dependabot/cake/file_fetcher"
require "dependabot/cake/file_parser"
require "dependabot/cake/file_updater"
41 changes: 41 additions & 0 deletions cake/lib/dependabot/cake/file_fetcher.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# frozen_string_literal: true

require "dependabot/file_fetchers"
require "dependabot/file_fetchers/base"

module Dependabot
module Cake
class FileFetcher < Dependabot::FileFetchers::Base
def self.required_files_in?(filenames)
filenames.any? { |f| f.end_with?(".cake") }
end

def self.required_files_message
"Repo must contain a Cake file."
end

private

def fetch_files
fetched_files = []
fetched_files += cakefiles

return fetched_files if fetched_files.any?

raise(
Dependabot::DependencyFileNotFound,
File.join(directory, "<anything>.cake")
)
end

def cakefiles
@cakefiles ||=
repo_contents(raise_errors: false).
select { |f| f.type == "file" && f.name.end_with?(".cake") }.
map { |f| fetch_file_from_host(f.name) }
end
end
end
end

Dependabot::FileFetchers.register("cake", Dependabot::Cake::FileFetcher)
80 changes: 80 additions & 0 deletions cake/lib/dependabot/cake/file_parser.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# frozen_string_literal: true

require "dependabot/dependency"
require "dependabot/file_parsers"
require "dependabot/file_parsers/base"

module Dependabot
module Cake
class FileParser < Dependabot::FileParsers::Base
require "dependabot/file_parsers/base/dependency_set"

# Details of Cake preprocessor directives is at
# https://cakebuild.net/docs/fundamentals/preprocessor-directives
DIRECTIVE = /#(?<directive>addin|l|load|module|tool)/i.freeze
SCHEME = /(?<scheme>choco|dotnet|local|nuget):/i.freeze
SOURCE = /(?<source>[^?&"]+)/.freeze
PACKAGE = /[?&]package=([^?&"]+)/i.freeze
VERSION = /[?&]version=([^?&"]+)/i.freeze
DIRECTIVE_LINE = /(?:^|")#{DIRECTIVE}\s+"?#{SCHEME}?#{SOURCE}?/.freeze

def parse
dependency_set = DependencySet.new

cakefiles.each do |cakefile|
cakefile.content.each_line do |line|
next unless DIRECTIVE_LINE.match?(line)

directive, scheme, _source, package, version = parse_line(line)
next if scheme.nil? && %w(l load).include?(directive) ||
%w(choco local).include?(scheme) ||
package.nil? || version.nil?

dependency_set << Dependency.new(
name: package,
version: version,
package_manager: "nuget",
requirements: [{
requirement: version,
file: cakefile.name,
groups: [],
source: nil
}]
)
end
end

dependency_set.dependencies
end

private

def parse_line(line)
parsed_line = DIRECTIVE_LINE.match(line).named_captures

[
parsed_line.fetch("directive"),
parsed_line.fetch("scheme"),
parsed_line.fetch("source"),
PACKAGE.match(line).captures.first,
VERSION.match(line).captures.first
]
end

def cakefiles
# The Cake file fetcher only fetches Cake files, so no need to
# filter here
dependency_files
end

def check_required_files
# Just check if there are any files at all.
return if dependency_files.any?

raise "No Cake file!"
end
end
end
end

Dependabot::FileParsers.register("cake", Dependabot::Cake::FileParser)
30 changes: 30 additions & 0 deletions cake/lib/dependabot/cake/file_updater.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# frozen_string_literal: true

require "dependabot/file_updaters"
require "dependabot/file_updaters/base"

module Dependabot
module Cake
class FileUpdater < Dependabot::FileUpdaters::Base
def self.updated_files_regex
[/.*\.cake$/]
end

def updated_dependency_files
# TODO
raise NotImplementedError
end

private

def check_required_files
# Just check if there are any files at all.
return if dependency_files.any?

raise "No Cake file!"
end
end
end
end

Dependabot::FileUpdaters.register("cake", Dependabot::Cake::FileUpdater)
1 change: 1 addition & 0 deletions config/rubocop-top-level.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ AllCops:
- 'docker/**/*'
- 'git_submodules/**/*'
- 'nuget/**/*'
- 'cake/**/*'
- 'gradle/**/*'
- 'maven/**/*'
- 'python/**/*'
Expand Down
1 change: 1 addition & 0 deletions lib/dependabot/pull_request_creator/labeler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Labeler
"docker" => { name: "docker", colour: "21ceff" },
"terraform" => { name: "terraform", colour: "5C4EE5" },
"nuget" => { name: ".NET", colour: "7121c6" },
"cake" => { name: ".NET", colour: "7121c6" },
"maven" => { name: "java", colour: "ffa221" },
"gradle" => { name: "java", colour: "ffa221" },
"npm_and_yarn" => { name: "javascript", colour: "168700" },
Expand Down
1 change: 1 addition & 0 deletions omnibus/dependabot-omnibus.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
spec.require_path = "lib"
spec.files = ["lib/dependabot/omnibus.rb"]

spec.add_dependency "dependabot-cake", Dependabot::VERSION
spec.add_dependency "dependabot-cargo", Dependabot::VERSION
spec.add_dependency "dependabot-composer", Dependabot::VERSION
spec.add_dependency "dependabot-core", Dependabot::VERSION
Expand Down
1 change: 1 addition & 0 deletions omnibus/lib/dependabot/omnibus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
require "dependabot/git_submodules"
require "dependabot/composer"
require "dependabot/nuget"
require "dependabot/cake"
require "dependabot/gradle"
require "dependabot/maven"
require "dependabot/hex"
Expand Down