dependanot 0.1.7 → 0.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2107d2fc9ef2ce61680a0a62bbb248548e91dea25ac4c05e2c426197fb0aebc6
4
- data.tar.gz: 965595379cb72610d767afcbab36a51891aa1f0a4be7ae83b9e6437a802f36b4
3
+ metadata.gz: e5badfc35fefa1a5209ee7e9495d8051990d5c64c379a1653aeb4e1075c3bce6
4
+ data.tar.gz: 85c462d293de42633139a913aa28e73e13460745ccd421cd0ba02898749b2be7
5
5
  SHA512:
6
- metadata.gz: 2ea7a9dac327b8ff470db6392f6734bef39e71b41665d1f1d350bcdb0adb3093627ed0ad1d5e1cc16fd08745ab088fe9e2f7f9b7098e825ac7abc47dbfba2c5d
7
- data.tar.gz: 6a29693a707725fcec357cc453a9f33bf9a329ec9947e23ba893f87f0acd8aad5ca41221a805d83b8f957393129ef33e0a4c0db38d84a9d26f6e245361cf2de3
6
+ metadata.gz: a9189f9292c94bac7e08ab53c6039e7a305d03f4fe631f13558807ec27703446e3c55b636c5e97f9e34a10b1cb0de83abeabd0576c49f2ddcac6e33257f3f9f1
7
+ data.tar.gz: b172ac7a995ad36e83c480db71d5046a95e97b2f66aa872046bf3b5045f77d0de62b9aa6490c32dafead65530aee7a200d1cb7e245742bd8fe233316323381f2
data/README.md CHANGED
@@ -1,28 +1,41 @@
1
- # Dependabot
1
+ # Dependanot
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/dependabot`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ Dependanot is definitely not [Dependabot](https://github.com/dependabot).
6
4
 
7
5
  ## Installation
8
6
 
9
- Add this line to your application's Gemfile:
10
-
11
- ```ruby
12
- gem 'dependabot'
13
- ```
14
-
15
- And then execute:
16
-
17
- $ bundle install
7
+ Install `dependanot` from https://rubygems.org.
18
8
 
19
- Or install it yourself as:
20
-
21
- $ gem install dependabot
9
+ $ gem install dependanot
22
10
 
23
11
  ## Usage
24
12
 
25
- TODO: Write usage instructions here
13
+ `dependanot` is a CLI that can be invoked via `$ dependabot`. However, it's
14
+ meant to be used from a GitHub Action.
15
+
16
+ This following example can be added to your repo as `.github/workflows/dependanot.yml`.
17
+
18
+ ```yaml
19
+ name: dependanot
20
+ on:
21
+ schedule:
22
+ - cron: '42 * * * *'
23
+ jobs:
24
+ bundler:
25
+ runs-on: ubuntu-latest
26
+ steps:
27
+ - uses: actions/checkout@v2
28
+ - uses: ruby/setup-ruby@v1
29
+ with:
30
+ ruby-version: 3.0
31
+ - run: gem install dependanot
32
+ - run: dependabot scan --recursive --push $GITHUB_WORKSPACE
33
+ env:
34
+ GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
35
+ ```
36
+
37
+ That's it! Consult the [GitHub Actions Documentation][1] to customize the
38
+ workflow or check out the [Examples repo][2].
26
39
 
27
40
  ## Development
28
41
 
@@ -37,3 +50,6 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/depend
37
50
  ## License
38
51
 
39
52
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
53
+
54
+ [1]: https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions
55
+ [2]: https://github.com/dependanot/examples
data/dependabot.gemspec CHANGED
@@ -5,10 +5,17 @@ require_relative "lib/dependabot/version"
5
5
  Gem::Specification.new do |spec|
6
6
  spec.authors = ["mo khan"]
7
7
  spec.bindir = "exe"
8
- spec.description = "The Dependabot CLI"
8
+ spec.description = "Definitely not Dependabot"
9
9
  spec.email = ["xlgmokha@github.com"]
10
10
  spec.executables = ["dependabot"]
11
- spec.files = Dir.glob("lib/**/*.rb") + Dir.glob("exe/*") + Dir.glob("*.gemspec") + ["LICENSE.txt", "README.md"]
11
+ spec.files = Dir.glob([
12
+ "*.gemspec",
13
+ "LICENSE.txt",
14
+ "README.md",
15
+ "exe/*",
16
+ "lib/**/*.erb",
17
+ "lib/**/*.rb",
18
+ ])
12
19
  spec.homepage = "https://github.com/dependanot/cli"
13
20
  spec.license = "MIT"
14
21
  spec.metadata["homepage_uri"] = spec.homepage
@@ -16,12 +23,12 @@ Gem::Specification.new do |spec|
16
23
  spec.name = "dependanot"
17
24
  spec.require_paths = ["lib"]
18
25
  spec.required_ruby_version = ">= 3.0.0"
19
- spec.summary = "The Dependabot CLI"
26
+ spec.summary = "Definitely not Dependabot"
20
27
  spec.version = Dependabot::VERSION
21
28
  spec.add_dependency "bundler", "~> 2.0"
22
29
  spec.add_dependency "octokit", "~> 4.0"
23
30
  spec.add_dependency "rugged", "~> 1.2"
24
31
  spec.add_dependency "spandx", ">= 0.18.3"
32
+ spec.add_dependency "straw", "~> 0.1"
25
33
  spec.add_dependency "thor", "~> 1.1"
26
- spec.add_development_dependency "debug", "~> 1.4"
27
34
  end
@@ -3,14 +3,19 @@
3
3
  module Dependabot
4
4
  module Bundler
5
5
  class Update < ::Spandx::Core::Plugin
6
+ def match?(dependency)
7
+ dependency.package_manager == :rubygems
8
+ end
9
+
6
10
  def enhance(dependency)
7
- return unless dependency.package_manager == :rubygems
11
+ return dependency unless match?(dependency)
8
12
 
9
13
  Dir.chdir(dependency.path.parent) do
10
14
  ::Bundler.with_unbundled_env do
11
15
  system({ "RUBYOPT" => "-W0" }, "bundle update #{dependency.name} --conservative --quiet")
12
16
  end
13
17
  end
18
+ dependency
14
19
  end
15
20
  end
16
21
  end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dependabot
4
+ class Callback
5
+ def initialize(&block)
6
+ @block = block
7
+ end
8
+
9
+ def call
10
+ @block.call
11
+ end
12
+ end
13
+ end
@@ -31,8 +31,11 @@ module Dependabot
31
31
  end
32
32
 
33
33
  def update(dependency)
34
- ::Dependabot.logger.debug("Updating #{dependency.name}…")
34
+ ::Dependabot.logger.info("Updating #{dependency.name}…")
35
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) }
36
39
  end
37
40
 
38
41
  def match?(dependency)
@@ -11,7 +11,9 @@ module Dependabot
11
11
  method_option :dependency, aliases: "-d", type: :string, desc: "Update a specific dependency", default: nil
12
12
  method_option :push, aliases: "-p", type: :boolean, desc: "Push the update as a pull request. Default: --no-push", default: false
13
13
  method_option :recursive, aliases: "-r", type: :boolean, desc: "Perform a recursive. Default: --no-recursive", default: false
14
+ method_option :verbose, aliases: "-v", type: :boolean, desc: "Increase verbosity. Default: --no-verbose", default: false
14
15
  def scan(path = Pathname.pwd)
16
+ Dependabot.logger.level = :debug if options[:verbose]
15
17
  ::Dependabot::CLI::Scan.new(path, options).run
16
18
  end
17
19
 
@@ -5,17 +5,24 @@ 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
 
11
+ def self.for(dependency)
12
+ new(dependency.path.parent)
13
+ end
14
+
12
15
  def checkout(branch:)
13
- repo.create_branch(branch, repo.head.name)
16
+ repo.create_branch(branch, repo.head.name) unless repo.branches[branch]
14
17
  repo.checkout(branch)
15
18
  end
16
19
 
17
20
  def push(remote: "origin", branch: "HEAD")
18
21
  repo.push(remote, ["refs/heads/#{branch}"], credentials: credentials_for(remote))
22
+ rescue StandardError
23
+ Dir.chdir(File.dirname(repo.path)) do
24
+ system("git push #{remote} #{branch}", exception: true)
25
+ end
19
26
  end
20
27
 
21
28
  def patch
@@ -42,6 +49,7 @@ module Dependabot
42
49
  end
43
50
 
44
51
  def credentials_for(remote)
52
+ Dependabot.logger.debug(repo.remotes[remote].url)
45
53
  if ssh?(repo.remotes[remote].url)
46
54
  Rugged::Credentials::SshKeyFromAgent.new(username: "git")
47
55
  else
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dependabot
4
+ module Npm
5
+ class Update < ::Spandx::Core::Plugin
6
+ def match?(dependency)
7
+ dependency.package_manager == :npm
8
+ end
9
+
10
+ def enhance(dependency)
11
+ return dependency unless match?(dependency)
12
+
13
+ Dir.chdir(dependency.path.parent) do
14
+ system("rm -fr node_modules/#{dependency.name}")
15
+ system("npm update #{dependency.name}")
16
+ end
17
+ dependency
18
+ end
19
+ end
20
+ end
21
+ end
@@ -2,62 +2,52 @@
2
2
 
3
3
  module Dependabot
4
4
  class Publish
5
- attr_reader :dependency
5
+ attr_reader :dependency, :git, :pull_request
6
6
 
7
- def initialize(dependency)
7
+ def initialize(dependency, git: Dependabot::Git.for(dependency))
8
8
  @dependency = dependency
9
+ @git = git
10
+ @pull_request = PullRequest.new(
11
+ nwo: GitHub.name_with_owner_from(git.repo.remotes["origin"].url),
12
+ base: git.repo.head.name,
13
+ head: "dependanot/#{dependency.package_manager}/#{dependency.name}",
14
+ dependency: dependency
15
+ )
9
16
  end
10
17
 
11
18
  def update!(push: false)
12
- git_for(dependency, push: push) do |git|
19
+ transaction(push: push) do |after_commit|
13
20
  ::Spandx::Core::Plugin.enhance(dependency)
14
- Dependabot.logger.debug(git.patch) unless git.patch.empty?
21
+ after_commit.new do
22
+ Dependabot.logger.debug(git.patch)
23
+ Dependabot.github.create(pull_request)
24
+ end
15
25
  end
16
26
  end
17
27
 
18
28
  private
19
29
 
20
- def branch_name_for(dependency)
21
- "dependanot/#{dependency.package_manager}/#{dependency.name}"
22
- end
30
+ def transaction(push:)
31
+ git.checkout(branch: pull_request.head)
32
+ callback = yield Callback
33
+ return if no_changes?
34
+
35
+ git.commit(all: true, message: pull_request.commit_message)
36
+ return unless push
23
37
 
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?
38
+ git.push(remote: "origin", branch: pull_request.head)
39
+ callback.call
30
40
  ensure
31
- git.repo.checkout_head(strategy: :force)
32
- git.repo.checkout(default_branch)
41
+ reset
33
42
  end
34
43
 
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
44
+ def reset
45
+ git.repo.checkout_head(strategy: :force)
46
+ git.repo.checkout(pull_request.base)
47
47
  end
48
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}",
59
- description_for(dependency)
60
- )
49
+ def no_changes?
50
+ git.patch.empty?
61
51
  end
62
52
  end
63
53
  end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dependabot
4
+ class PullRequest
5
+ include ::Straw::Memoizable
6
+
7
+ attr_reader :base, :head
8
+
9
+ def initialize(nwo:, base:, head:, dependency:)
10
+ @nwo = nwo
11
+ @base = base
12
+ @head = head
13
+ @dependency = dependency
14
+ end
15
+
16
+ def commit_message
17
+ memoize(:commit_message) do
18
+ <<~COMMIT
19
+ #{title}
20
+
21
+ #{description}
22
+ COMMIT
23
+ end
24
+ end
25
+
26
+ def run_against(api)
27
+ api.create_pull_request(nwo, base, head, title, description)
28
+ end
29
+
30
+ private
31
+
32
+ attr_reader :nwo, :dependency
33
+
34
+ def title
35
+ memoize(:title) do
36
+ "chore(deps): bump #{dependency.name} from #{dependency.version}"
37
+ end
38
+ end
39
+
40
+ def description
41
+ memoize(:description) do
42
+ ERB
43
+ .new(File.read(File.join(__dir__, "templates/pull.md.erb")))
44
+ .result(binding)
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,9 @@
1
+ Bumps [<%= dependency.name %>](#) to <%= dependency.version %>
2
+
3
+ <details>
4
+ <summary>Changelog</summary>
5
+ </details>
6
+
7
+ <details>
8
+ <summary>Commits</summary>
9
+ </details>
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dependabot
4
- VERSION = "0.1.7"
4
+ VERSION = "0.1.11"
5
5
  end
data/lib/dependabot.rb CHANGED
@@ -1,31 +1,26 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "bundler"
4
+ require "erb"
4
5
  require "github"
5
- require "logger"
6
6
  require "octokit"
7
7
  require "rugged"
8
8
  require "spandx"
9
+ require "straw"
9
10
 
10
11
  require_relative "dependabot/bundler/update"
12
+ require_relative "dependabot/npm/update"
13
+ require_relative "dependabot/callback"
11
14
  require_relative "dependabot/git"
12
15
  require_relative "dependabot/publish"
13
- require_relative "dependabot/tracer"
16
+ require_relative "dependabot/pull_request"
14
17
  require_relative "dependabot/version"
15
18
 
16
19
  module Dependabot
17
20
  class Error < StandardError; end
18
21
 
19
22
  def self.logger
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
25
- end
26
-
27
- def self.tracer
28
- @tracer ||= Tracer.new(logger)
23
+ ::Straw.logger
29
24
  end
30
25
 
31
26
  def self.octokit
@@ -42,3 +37,13 @@ module Dependabot
42
37
  @github ||= GitHub.new
43
38
  end
44
39
  end
40
+
41
+ module Spandx
42
+ module Core
43
+ class LicensePlugin
44
+ def enhance(dependency)
45
+ dependency
46
+ end
47
+ end
48
+ end
49
+ end
data/lib/github.rb CHANGED
@@ -18,6 +18,10 @@ class GitHub
18
18
  @workspace = workspace
19
19
  end
20
20
 
21
+ def create(action)
22
+ action.run_against(Dependabot.octokit)
23
+ end
24
+
21
25
  class << self
22
26
  def name_with_owner_from(url)
23
27
  regex = %r{(?<x>(?<scheme>https|ssh)://)?(?<username>git@)?github.com[:|/](?<nwo>\w+/\w+)(?<extension>\.git)?}
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.7
4
+ version: 0.1.11
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-21 00:00:00.000000000 Z
11
+ date: 2021-12-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -67,34 +67,34 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: 0.18.3
69
69
  - !ruby/object:Gem::Dependency
70
- name: thor
70
+ name: straw
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '1.1'
75
+ version: '0.1'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '1.1'
82
+ version: '0.1'
83
83
  - !ruby/object:Gem::Dependency
84
- name: debug
84
+ name: thor
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '1.4'
90
- type: :development
89
+ version: '1.1'
90
+ type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '1.4'
97
- description: The Dependabot CLI
96
+ version: '1.1'
97
+ description: Definitely not Dependabot
98
98
  email:
99
99
  - xlgmokha@github.com
100
100
  executables:
@@ -108,11 +108,14 @@ files:
108
108
  - exe/dependabot
109
109
  - lib/dependabot.rb
110
110
  - lib/dependabot/bundler/update.rb
111
+ - lib/dependabot/callback.rb
111
112
  - lib/dependabot/cli.rb
112
113
  - lib/dependabot/cli/scan.rb
113
114
  - lib/dependabot/git.rb
115
+ - lib/dependabot/npm/update.rb
114
116
  - lib/dependabot/publish.rb
115
- - lib/dependabot/tracer.rb
117
+ - lib/dependabot/pull_request.rb
118
+ - lib/dependabot/templates/pull.md.erb
116
119
  - lib/dependabot/version.rb
117
120
  - lib/github.rb
118
121
  homepage: https://github.com/dependanot/cli
@@ -136,8 +139,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
139
  - !ruby/object:Gem::Version
137
140
  version: '0'
138
141
  requirements: []
139
- rubygems_version: 3.2.32
142
+ rubygems_version: 3.2.33
140
143
  signing_key:
141
144
  specification_version: 4
142
- summary: The Dependabot CLI
145
+ summary: Definitely not Dependabot
143
146
  test_files: []
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Dependabot
4
- class Tracer
5
- def initialize(logger)
6
- @logger = logger
7
- end
8
-
9
- def trace(defaults = {})
10
- tracer = TracePoint.new(:call) do |x|
11
- @logger.debug(defaults.merge({ path: x.path, lineno: x.lineno, clazz: x.defined_class, method: x.method_id, args: args_from(x), locals: locals_from(x) }))
12
- rescue StandardError => boom
13
- @logger.error(defaults.merge({ message: boom.message, stacktrace: boom.backtrace }))
14
- end
15
- tracer.enable
16
- yield
17
- ensure
18
- tracer.disable
19
- end
20
-
21
- private
22
-
23
- def args_from(trace)
24
- trace.parameters.map(&:last).map { |x| [x, trace.binding.eval(x.to_s)] }.to_h
25
- end
26
-
27
- def locals_from(trace)
28
- trace.binding.local_variables.map { |x| [x, trace.binding.local_variable_get(x)] }.to_h
29
- end
30
- end
31
- end