dependanot 0.1.5 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 76575ad77b236ed9f2b0c556c057e519aaeb95724be3b1ac2ab8207a6183950c
4
- data.tar.gz: e96055f60fcd2f9af0c2989a95b273147043560492446f8b51a05ca817692525
3
+ metadata.gz: e34d7bc44fc32487ee5bf6d9c7582282fd2af8c365b9a8e02bf3a00c82587218
4
+ data.tar.gz: 4c3af4d15049a52d8767f3d9a204b7ce3e54ab507d8cf735749a9c6c234a2528
5
5
  SHA512:
6
- metadata.gz: 9c3c3eea1d0389ab02b1bc847cd6411d0d8fbf0a7a9b15d0b1a38f546a199f7598100dbda8a83b1af6a3028e70acf23a3726c29d45cc6c84106f1c65b61d1612
7
- data.tar.gz: 9b5b19f79b7c7be095747d20a9e5b260587193c75a5adfd963b4aa5d1e4b8f3790d685defc13956cc56b11e010458689613ccd17d1026f609b794bb1b217b603
6
+ metadata.gz: 1914dc7d10d63356e17d7ee4ab551b219d3c482107a3c072b94dad414129ab5d3adec217f88d810419d3320dd3d087198fa122c89212fd74e93c3ad56aff65fa
7
+ data.tar.gz: 034c3507b26657718121ab7ebf3049408c65d96ca94696031f248e5b80996ab2ffaa736f75bad4012cd9ca762c63a50d202c8ae6fb2fe1f40d72883c699cfd5f
data/dependabot.gemspec CHANGED
@@ -23,4 +23,5 @@ Gem::Specification.new do |spec|
23
23
  spec.add_dependency "rugged", "~> 1.2"
24
24
  spec.add_dependency "spandx", ">= 0.18.3"
25
25
  spec.add_dependency "thor", "~> 1.1"
26
+ spec.add_development_dependency "debug", "~> 1.4"
26
27
  end
@@ -8,7 +8,7 @@ module Dependabot
8
8
 
9
9
  Dir.chdir(dependency.path.parent) do
10
10
  ::Bundler.with_unbundled_env do
11
- system "bundle update #{dependency.name} --conservative --quiet"
11
+ system({ "RUBYOPT" => "-W0" }, "bundle update #{dependency.name} --conservative --quiet")
12
12
  end
13
13
  end
14
14
  end
@@ -3,7 +3,7 @@
3
3
  module Dependabot
4
4
  module CLI
5
5
  class Scan
6
- attr_reader :path
6
+ attr_reader :path, :options
7
7
 
8
8
  def initialize(path, options)
9
9
  @path = ::Pathname.new(path)
@@ -12,7 +12,7 @@ module Dependabot
12
12
 
13
13
  def run
14
14
  each_dependency do |dependency|
15
- update!(dependency)
15
+ update(dependency) if match?(dependency)
16
16
  end
17
17
  end
18
18
 
@@ -20,7 +20,7 @@ module Dependabot
20
20
 
21
21
  def each_file(&block)
22
22
  ::Spandx::Core::PathTraversal
23
- .new(path, recursive: false)
23
+ .new(path, recursive: options[:recursive])
24
24
  .each(&block)
25
25
  end
26
26
 
@@ -30,27 +30,16 @@ module Dependabot
30
30
  end
31
31
  end
32
32
 
33
- def update!(dependency)
34
- puts "Updating #{dependency.name}..."
35
- git_for(dependency) do |git|
36
- ::Spandx::Core::Plugin.enhance(dependency)
37
- puts git.patch
38
- git.commit(all: true, message: "Updating #{dependency.name}")
39
- end
40
- end
41
-
42
- def branch_name_for(dependency)
43
- "dependanot/#{dependency.package_manager}/#{dependency.name}"
33
+ def update(dependency)
34
+ ::Dependabot.logger.info("Updating #{dependency.name}")
35
+ ::Dependabot::Publish.new(dependency).update!(push: options[:push])
36
+ rescue StandardError => boom
37
+ Dependabot.logger.error(boom)
38
+ boom.backtrace.each { |x| Dependabot.logger.debug(x) }
44
39
  end
45
40
 
46
- def git_for(dependency, branch_name: branch_name_for(dependency))
47
- git = ::Dependabot::Git.new(dependency.path.parent)
48
- default_branch = git.repo.head.name
49
- git.checkout(branch: branch_name)
50
- yield git
51
- ensure
52
- git.repo.checkout_head(strategy: :force)
53
- git.repo.checkout(default_branch)
41
+ def match?(dependency)
42
+ options[:dependency].nil? || options[:dependency] == dependency.name
54
43
  end
55
44
  end
56
45
  end
@@ -7,7 +7,10 @@ require "dependabot/cli/scan"
7
7
  module Dependabot
8
8
  module CLI
9
9
  class Application < Thor
10
- desc "scan [DIRECTORY]", "Scan a directory"
10
+ desc "scan [OPTION]... [FILE]", "Scan a directory or file for dependencies to update"
11
+ method_option :dependency, aliases: "-d", type: :string, desc: "Update a specific dependency", default: nil
12
+ method_option :push, aliases: "-p", type: :boolean, desc: "Push the update as a pull request. Default: --no-push", default: false
13
+ method_option :recursive, aliases: "-r", type: :boolean, desc: "Perform a recursive. Default: --no-recursive", default: false
11
14
  def scan(path = Pathname.pwd)
12
15
  ::Dependabot::CLI::Scan.new(path, options).run
13
16
  end
@@ -5,7 +5,6 @@ module Dependabot
5
5
  attr_reader :repo
6
6
 
7
7
  def initialize(path)
8
- @path = path
9
8
  @repo = Rugged::Repository.discover(path)
10
9
  end
11
10
 
@@ -14,6 +13,14 @@ module Dependabot
14
13
  repo.checkout(branch)
15
14
  end
16
15
 
16
+ def push(remote: "origin", branch: "HEAD")
17
+ repo.push(remote, ["refs/heads/#{branch}"], credentials: credentials_for(remote))
18
+ rescue StandardError
19
+ Dir.chdir(File.dirname(repo.path)) do
20
+ system("git push #{remote} #{branch}", exception: true)
21
+ end
22
+ end
23
+
17
24
  def patch
18
25
  repo.index.diff.patch
19
26
  end
@@ -36,5 +43,18 @@ module Dependabot
36
43
  def stage(path)
37
44
  repo.index.add(path)
38
45
  end
46
+
47
+ def credentials_for(remote)
48
+ Dependabot.logger.debug(repo.remotes[remote].url)
49
+ if ssh?(repo.remotes[remote].url)
50
+ Rugged::Credentials::SshKeyFromAgent.new(username: "git")
51
+ else
52
+ Rugged::Credentials::UserPassword.new(username: "x-access-token", password: Dependabot.github.token)
53
+ end
54
+ end
55
+
56
+ def ssh?(url)
57
+ url.include?("git@github.com:")
58
+ end
39
59
  end
40
60
  end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dependabot
4
+ class Publish
5
+ attr_reader :dependency
6
+
7
+ def initialize(dependency)
8
+ @dependency = dependency
9
+ end
10
+
11
+ def update!(push: false)
12
+ git_for(dependency, push: push) do |git|
13
+ ::Spandx::Core::Plugin.enhance(dependency)
14
+ Dependabot.logger.debug(git.patch) unless git.patch.empty?
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def branch_name_for(dependency)
21
+ "dependanot/#{dependency.package_manager}/#{dependency.name}"
22
+ end
23
+
24
+ def git_for(dependency, branch_name: branch_name_for(dependency), push: false)
25
+ git = ::Dependabot::Git.new(dependency.path.parent)
26
+ default_branch = git.repo.head.name
27
+ git.checkout(branch: branch_name)
28
+ yield git
29
+ publish_pull_request_for(dependency, default_branch, branch_name, git, push) unless git.patch.empty?
30
+ ensure
31
+ git.repo.checkout_head(strategy: :force)
32
+ git.repo.checkout(default_branch)
33
+ end
34
+
35
+ def description_for(dependency)
36
+ <<~MARKDOWN
37
+ Bumps [#{dependency.name}](#)
38
+
39
+ <details>
40
+ <summary>Changelog</summary>
41
+ </details>
42
+
43
+ <details>
44
+ <summary>Commits</summary>
45
+ </details>
46
+ MARKDOWN
47
+ end
48
+
49
+ def publish_pull_request_for(dependency, default_branch, branch_name, git, push)
50
+ git.commit(all: true, message: "chore: Update #{dependency.name}")
51
+ return unless push
52
+
53
+ git.push(remote: "origin", branch: branch_name)
54
+ Dependabot.octokit.create_pull_request(
55
+ GitHub.name_with_owner_from(git.repo.remotes["origin"].url),
56
+ default_branch,
57
+ branch_name,
58
+ "chore(deps): bump #{dependency.name} from #{dependency.version}",
59
+ description_for(dependency)
60
+ )
61
+ end
62
+ end
63
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dependabot
4
- VERSION = "0.1.5"
4
+ VERSION = "0.1.9"
5
5
  end
data/lib/dependabot.rb CHANGED
@@ -9,6 +9,7 @@ require "spandx"
9
9
 
10
10
  require_relative "dependabot/bundler/update"
11
11
  require_relative "dependabot/git"
12
+ require_relative "dependabot/publish"
12
13
  require_relative "dependabot/tracer"
13
14
  require_relative "dependabot/version"
14
15
 
@@ -16,7 +17,11 @@ module Dependabot
16
17
  class Error < StandardError; end
17
18
 
18
19
  def self.logger
19
- @logger ||= Logger.new($stderr)
20
+ @logger ||= Logger.new($stderr, level: ENV.fetch("LOG_LEVEL", Logger::INFO)).tap do |x|
21
+ x.formatter = proc do |_severity, _datetime, _progname, message|
22
+ "[v#{VERSION}] #{message}\n"
23
+ end
24
+ end
20
25
  end
21
26
 
22
27
  def self.tracer
data/lib/github.rb CHANGED
@@ -18,6 +18,14 @@ class GitHub
18
18
  @workspace = workspace
19
19
  end
20
20
 
21
+ class << self
22
+ def name_with_owner_from(url)
23
+ regex = %r{(?<x>(?<scheme>https|ssh)://)?(?<username>git@)?github.com[:|/](?<nwo>\w+/\w+)(?<extension>\.git)?}
24
+ match = url.match(regex)
25
+ match && match["nwo"]
26
+ end
27
+ end
28
+
21
29
  private
22
30
 
23
31
  def default_api_url
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dependanot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - mo khan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-12-20 00:00:00.000000000 Z
11
+ date: 2021-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '1.1'
83
+ - !ruby/object:Gem::Dependency
84
+ name: debug
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.4'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.4'
83
97
  description: The Dependabot CLI
84
98
  email:
85
99
  - xlgmokha@github.com
@@ -97,6 +111,7 @@ files:
97
111
  - lib/dependabot/cli.rb
98
112
  - lib/dependabot/cli/scan.rb
99
113
  - lib/dependabot/git.rb
114
+ - lib/dependabot/publish.rb
100
115
  - lib/dependabot/tracer.rb
101
116
  - lib/dependabot/version.rb
102
117
  - lib/github.rb