dependanot 0.1.5 → 0.1.6

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: 17784d154fbeddc3386710cab5b82326ec7e92bc0900afae82616019a58f41ea
4
+ data.tar.gz: 97c7cf19c1db2fca7259bfecf4eebc5aa627a05456b402c5c075f0b9e39b7399
5
5
  SHA512:
6
- metadata.gz: 9c3c3eea1d0389ab02b1bc847cd6411d0d8fbf0a7a9b15d0b1a38f546a199f7598100dbda8a83b1af6a3028e70acf23a3726c29d45cc6c84106f1c65b61d1612
7
- data.tar.gz: 9b5b19f79b7c7be095747d20a9e5b260587193c75a5adfd963b4aa5d1e4b8f3790d685defc13956cc56b11e010458689613ccd17d1026f609b794bb1b217b603
6
+ metadata.gz: f2ef3acea6d7f6109c40095abdf26de5ea6d5f2ee2e2f23275a95391889d40570cb100caec1dc4009d8b274c13f4981f14af614e17d6bdfc16a736e38da3276e
7
+ data.tar.gz: f0767ac6caf6346191384fffa7dca32a160a2dcbd5da5241705b447e4b2bc786132d785ca599a99ab9990d455c0d15f14d71081e49beea1ba455447526ed83ea
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
+ publish_update_for(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,9 @@ 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}"
44
- end
45
-
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)
33
+ def publish_update_for(dependency)
34
+ ::Dependabot.logger.debug("Updating #{dependency.name}")
35
+ ::Dependabot::Publish.new(dependency).update!(push: options[:push])
54
36
  end
55
37
  end
56
38
  end
@@ -7,7 +7,9 @@ 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 [DIRECTORY | FILE]", "Scan a directory or file for dependencies to update"
11
+ method_option :push, aliases: "-p", type: :boolean, desc: "Push the update as a pull request. Default: --no-push", default: false
12
+ method_option :recursive, aliases: "-r", type: :boolean, desc: "Perform a recursive. Default: --no-recursive", default: false
11
13
  def scan(path = Pathname.pwd)
12
14
  ::Dependabot::CLI::Scan.new(path, options).run
13
15
  end
@@ -14,6 +14,10 @@ module Dependabot
14
14
  repo.checkout(branch)
15
15
  end
16
16
 
17
+ def push(remote: "origin", branch: "HEAD")
18
+ repo.push(remote, ["refs/heads/#{branch}"], credentials: credentials)
19
+ end
20
+
17
21
  def patch
18
22
  repo.index.diff.patch
19
23
  end
@@ -36,5 +40,13 @@ module Dependabot
36
40
  def stage(path)
37
41
  repo.index.add(path)
38
42
  end
43
+
44
+ def credentials
45
+ if ENV["CI"]
46
+ Rugged::Credentials::UserPassword.new(username: "x-access-token", password: Dependabot.github.token)
47
+ else
48
+ Rugged::Credentials::SshKeyFromAgent.new(username: "git")
49
+ end
50
+ end
39
51
  end
40
52
  end
@@ -0,0 +1,85 @@
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
+
47
+ <br />
48
+
49
+ Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.
50
+ ---
51
+
52
+ <details>
53
+ <summary>Dependabot commands and options</summary>
54
+ <br />
55
+
56
+ You can trigger Dependabot actions by commenting on this PR:
57
+ - `@dependabot rebase` will rebase this PR
58
+ - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
59
+ - `@dependabot merge` will merge this PR after your CI passes on it
60
+ - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
61
+ - `@dependabot cancel merge` will cancel a previously requested merge and block automerging
62
+ - `@dependabot reopen` will reopen this PR if it is closed
63
+ - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
64
+ - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
65
+ - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
66
+ - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
67
+ </details>
68
+ MARKDOWN
69
+ end
70
+
71
+ def publish_pull_request_for(dependency, default_branch, branch_name, git, push)
72
+ git.commit(all: true, message: "chore: Update #{dependency.name}")
73
+ return unless push
74
+
75
+ git.push(remote: "origin", branch: branch_name)
76
+ Dependabot.octokit.create_pull_request(
77
+ GitHub.name_with_owner_from(git.repo.remotes["origin"].url),
78
+ default_branch,
79
+ branch_name,
80
+ "chore(deps): bump #{dependency}",
81
+ description_for(dependency)
82
+ )
83
+ end
84
+ end
85
+ 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.6"
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::WARN)).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,7 +1,7 @@
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.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - mo khan
@@ -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