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

Add support for pre-commit package manager #2641

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
43 changes: 43 additions & 0 deletions app/models/package_manager/pre_commit.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
module PackageManager
class PreCommit < Base
HAS_VERSIONS = false
HAS_DEPENDENCIES = false
BIBLIOTHECARY_SUPPORT = true
URL = "https://pre-commit.com/"
COLOR = "#3572A5"

def self.project_names
get("https://pre-commit.com/all-hooks.json")
.values
.flatten
.map { |hook| hook["id"] }
end

def self.project(name)
repo = get("https://pre-commit.com/all-hooks.json")
.find { |repo,hooks| hooks.any? { |hook| hook["id"] == name } }

hook = repo[1]
.find { |hook| hook["id"] == name }

{
repo: repo[0],
id: hook["id"],
language: hook["language"],
description: hook.fetch("description", ""),
}
end

def self.mapping(project)
{
name: project[:id],
description: project[:description],
repository_url: project[:repo],
}
end

def self.formatted_name
"pre-commit"
end
end
end
10 changes: 10 additions & 0 deletions lib/tasks/download.rake
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,16 @@ namespace :download do
PackageManager::PlatformIO.import_async
end

desc "Download new pre-commit packages asynchronously"
task precommit: :environment do
PackageManager::PreCommit.import_new_async
end

desc "Download all pre-commit packages asynchronously"
task precommit_all: :environment do
PackageManager::PreCommit.import_async
end

desc "Download new PureScript packages asynchronously"
task purescript: :environment do
PackageManager::PureScript.import_new_async
Expand Down
98 changes: 98 additions & 0 deletions spec/fixtures/vcr_cassettes/all-hooks.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions spec/models/package_manager/pre_commit_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
require "rails_helper"

describe PackageManager::PreCommit do
describe "#project_names" do
it "resolves projects correctly" do
VCR.use_cassette("all-hooks") do
project_names = described_class.project_names

expect(project_names).to eq ["check-added-large-files", "check-ast", "autopep8"]
end
end
end

describe "#mapping" do
it "maps project data correctly" do
VCR.use_cassette("all-hooks") do
project = described_class.project("check-ast")
mapping = described_class.mapping(project)

expect(mapping[:name]).to eq "check-ast"
expect(mapping[:description]).to eq "Simply check whether the files parse as valid python."
expect(mapping[:repository_url]).to eq "https://github.com/pre-commit/pre-commit-hooks"
end
end

it "uses correct description fallback" do
VCR.use_cassette("all-hooks") do
project = described_class.project("autopep8")
mapping = described_class.mapping(project)

expect(mapping[:name]).to eq "autopep8"
expect(mapping[:description]).to eq ""
expect(mapping[:repository_url]).to eq "https://github.com/pre-commit/mirrors-autopep8"
end
end
end

describe "#formatted_name" do
it 'has a formatted name of "pre-commit"' do
expect(described_class.formatted_name).to eq("pre-commit")
end
end
end