drone-hunter 0.1.1 → 0.4.0

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: 861970148bcea4b9401487878b533fb2547945f8f73805442411d0d8400c9530
4
- data.tar.gz: be66196505c7ec0c23a0a510b3f75c991f78bede3cb8f51bf5db4c545183f862
3
+ metadata.gz: eaeb14dc51de2fee5541c680a5a100e6adfaaab2826185f63824aceb0e4039d6
4
+ data.tar.gz: ac3aa67b76d86918e93658123ad05c72ca5be17e86d68a0eeb13e7a7232f9208
5
5
  SHA512:
6
- metadata.gz: f4cc781d6f2385f62c54626e56e31909f28d7aa223a7ed943b10bbb158b4f35f3837e9492089d20da7ee18b19596faf92f602c2a4b9cdb48ac706b33ebecbe35
7
- data.tar.gz: 2d882f2bb9b1b7015f7e57388371e24bdaebfac2b5b3471c8da0f4f395587ba5b7de82cd6dbee57fc4b4df3c24f019b7f75d573734a58d6c9b768ee4d6cc1193
6
+ metadata.gz: 1bce4e1e93f683b9638aa51194c6a853334e425800285d3aafba6243563398522ee54fae9f610945de1ecb1b77a87656ed3891dc8ddc36b134364d7d49e81dcc
7
+ data.tar.gz: d474676013e09f8b3e7dbef82ddd83d4f7ae64ffe8fddb8a6a90c530ee6af71b92600036998fb5ad72c886329da03c07f178f7b2bf29efcd902cece06c595cb3
@@ -0,0 +1,11 @@
1
+ # To get started with Dependabot version updates, you'll need to specify which
2
+ # package ecosystems to update and where the package manifests are located.
3
+ # Please see the documentation for all configuration options:
4
+ # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5
+
6
+ version: 2
7
+ updates:
8
+ - package-ecosystem: "bundler" # See documentation for possible values
9
+ directory: "/" # Location of package manifests
10
+ schedule:
11
+ interval: "weekly"
@@ -0,0 +1,72 @@
1
+ # For most projects, this workflow file will not need changing; you simply need
2
+ # to commit it to your repository.
3
+ #
4
+ # You may wish to alter this file to override the set of languages analyzed,
5
+ # or to provide custom queries or build logic.
6
+ #
7
+ # ******** NOTE ********
8
+ # We have attempted to detect the languages in your repository. Please check
9
+ # the `language` matrix defined below to confirm you have the correct set of
10
+ # supported CodeQL languages.
11
+ #
12
+ name: "CodeQL"
13
+
14
+ on:
15
+ push:
16
+ branches: [ "master" ]
17
+ pull_request:
18
+ # The branches below must be a subset of the branches above
19
+ branches: [ "master" ]
20
+ schedule:
21
+ - cron: '35 6 * * 3'
22
+
23
+ jobs:
24
+ analyze:
25
+ name: Analyze
26
+ runs-on: ubuntu-latest
27
+ permissions:
28
+ actions: read
29
+ contents: read
30
+ security-events: write
31
+
32
+ strategy:
33
+ fail-fast: false
34
+ matrix:
35
+ language: [ 'ruby' ]
36
+ # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
37
+ # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
38
+
39
+ steps:
40
+ - name: Checkout repository
41
+ uses: actions/checkout@v3
42
+
43
+ # Initializes the CodeQL tools for scanning.
44
+ - name: Initialize CodeQL
45
+ uses: github/codeql-action/init@v2
46
+ with:
47
+ languages: ${{ matrix.language }}
48
+ # If you wish to specify custom queries, you can do so here or in a config file.
49
+ # By default, queries listed here will override any specified in a config file.
50
+ # Prefix the list here with "+" to use these queries and those in the config file.
51
+
52
+ # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
53
+ # queries: security-extended,security-and-quality
54
+
55
+
56
+ # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
57
+ # If this step fails, then you should remove it and run the build manually (see below)
58
+ - name: Autobuild
59
+ uses: github/codeql-action/autobuild@v2
60
+
61
+ # ℹ️ Command-line programs to run using the OS shell.
62
+ # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
63
+
64
+ # If the Autobuild fails above, remove it and uncomment the following three lines.
65
+ # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
66
+
67
+ # - run: |
68
+ # echo "Run, Build Application using script"
69
+ # ./location_of_script_within_repo/buildscript.sh
70
+
71
+ - name: Perform CodeQL Analysis
72
+ uses: github/codeql-action/analyze@v2
@@ -0,0 +1,51 @@
1
+ name: Ruby Gem
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - '*'
7
+
8
+ jobs:
9
+ build:
10
+ name: Build + Publish
11
+ runs-on: ubuntu-latest
12
+ permissions:
13
+ contents: read
14
+ packages: write
15
+
16
+ steps:
17
+ - uses: actions/checkout@v3
18
+ - name: Set up Ruby 2.6
19
+ uses: actions/setup-ruby@v1
20
+ with:
21
+ ruby-version: 2.6.x
22
+
23
+ - name: Publish to GPR
24
+ run: |
25
+ mkdir -p $HOME/.gem
26
+ touch $HOME/.gem/credentials
27
+ chmod 0600 $HOME/.gem/credentials
28
+ printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
29
+ gem build *.gemspec
30
+ gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
31
+ env:
32
+ GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}"
33
+ OWNER: ${{ github.repository_owner }}
34
+ - name: Publish to Release Assets
35
+ uses: softprops/action-gh-release@v1
36
+ if: startsWith(github.ref, 'refs/tags/')
37
+ with:
38
+ files: |
39
+ *.gem
40
+ LICENSE.txt
41
+ CHANGELOG.md
42
+ # - name: Publish to RubyGems
43
+ # run: |
44
+ # mkdir -p $HOME/.gem
45
+ # touch $HOME/.gem/credentials
46
+ # chmod 0600 $HOME/.gem/credentials
47
+ # printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
48
+ # gem build *.gemspec
49
+ # gem push *.gem
50
+ # env:
51
+ # GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
data/CHANGELOG.md ADDED
@@ -0,0 +1,23 @@
1
+ # Change Log
2
+
3
+ ## 0.4.0
4
+
5
+ - [feature] added `--match-basename` option to override file basename filter.
6
+ - [feature] added `--match-suffix` option to override file suffix filter.
7
+
8
+ ## 0.3.0
9
+
10
+ - [feature] added `--ignore-archived` option to skip archived repositories.
11
+
12
+ ## 0.2.0
13
+
14
+ - [config] added `--github-auto-paginate` option if you want to turn this off for some reason.
15
+ - [feature] added `--output-normalize` option to remove cosmetic differences from dronefiles.
16
+
17
+ ## 0.1.1
18
+
19
+ - [fix] `--output-format=files` actually works now.
20
+
21
+ ## 0.1.0
22
+
23
+ - initial release
data/README.md CHANGED
@@ -76,6 +76,12 @@ drone-hunter.output/rancherlabs/support-tools/.drone.yml
76
76
 
77
77
  The only limits are your imagination (and the GitHub API Rate Limit).
78
78
 
79
+ ## Output Normalization
80
+
81
+ As of `0.2.0`, you can pass use the `--output-normalize` option to
82
+ remove formatting differences in the dronefiles. This reduces false
83
+ negatives when trying to identify which files are the same.
84
+
79
85
  ## License
80
86
 
81
87
  `drone-hunter` is available under the [MIT License](https://tldrlegal.com/license/mit-license). See `LICENSE.txt` for the full text.
data/bin/drone-hunter CHANGED
@@ -49,6 +49,15 @@ def log_level_from(input)
49
49
  end
50
50
  end
51
51
 
52
+ # accepts the same values as YAML: https://yaml.org/type/bool.html
53
+ def boolean_from(input)
54
+ case input
55
+ when /1|true|yes|on|enabled?/i then true
56
+ when /0|false|no|off|disabled?/i then false
57
+ else raise NotImplementedError
58
+ end
59
+ end
60
+
52
61
  #########################
53
62
  # Default Configuration #
54
63
  #########################
@@ -58,16 +67,24 @@ config = {
58
67
  cache: {
59
68
  dir: File.expand_path(ENV.fetch("DRONE_HUNTER_CACHE_DIR", './drone-hunter.cache'))
60
69
  },
70
+ match: {
71
+ basename: Regexp.new(ENV.fetch("DRONE_HUNTER_MATCH_BASENAME", "drone")),
72
+ suffix: Regexp.new(ENV.fetch("DRONE_HUNTER_MATCH_SUFFIX", "[.]ya?ml") + "$")
73
+ },
61
74
  github: {
62
- auto_paginate: true,
75
+ auto_paginate: boolean_from(ENV.fetch("DRONE_HUNTER_GITHUB_AUTO_PAGINATE", "true")),
63
76
  access_token: github_access_token_from_environment
64
77
  },
78
+ ignore: {
79
+ archived: boolean_from(ENV.fetch("DRONE_HUNTER_IGNORE_ARCHIVED", "false"))
80
+ },
65
81
  log: {
66
82
  level: log_level_from(ENV.fetch("DRONE_HUNTER_LOG_LEVEL", "info"))
67
83
  },
68
84
  output: {
69
85
  format: output_format_from(ENV.fetch("DRONE_HUNTER_OUTPUT_FORMAT", "json")),
70
86
  path: File.expand_path(ENV.fetch("DRONE_HUNTER_OUTPUT_PATH", "./drone-hunter.output")),
87
+ normalize: boolean_from(ENV.fetch("DRONE_HUNTER_OUTPUT_NORMALIZE", "false")),
71
88
  }
72
89
  }
73
90
 
@@ -76,11 +93,16 @@ config = {
76
93
  ################################
77
94
 
78
95
  OptionParser.new do |options|
79
- options.on("-C", "--cache-dir=DIR", "env: DRONE_HUNTER_CACHE_DIR") { |argument| config[:cache][:dir] = File.expand_path(argument) }
80
- options.on( "--github-access-token=TOKEN", "env: DRONE_HUNTER_GITHUB_ACCESS_TOKEN") { |argument| config[:github][:access_token] = argument }
81
- options.on("-L", "--log-level=LEVEL", "env: DRONE_HUNTER_LOG_LEVEL") { |argument| config[:log][:level] = log_level_from(argument) }
82
- options.on("-o", "--output-format=FORMAT", "env: DRONE_HUNTER_OUTPUT_FORMAT") { |argument| config[:output][:format] = output_format_from(argument) }
83
- options.on("-p", "--output-path=PATH", "env: DRONE_HUNTER_OUTPUT_PATH") { |argument| config[:output][:path] = File.expand_path(argument) }
96
+ options.on("-C", "--cache-dir=DIR", "env: DRONE_HUNTER_CACHE_DIR") { |argument| config[:cache][:dir] = File.expand_path(argument) }
97
+ options.on( "--github-access-token=TOKEN", "env: DRONE_HUNTER_GITHUB_ACCESS_TOKEN") { |argument| config[:github][:access_token] = argument }
98
+ options.on( "--[no-]github-auto-paginate", "env: DRONE_HUNTER_GITHUB_AUTO_PAGINATE") { |argument| config[:github][:auto_paginate] = argument}
99
+ options.on("-L", "--log-level=LEVEL", "env: DRONE_HUNTER_LOG_LEVEL") { |argument| config[:log][:level] = log_level_from(argument) }
100
+ options.on("-o", "--output-format=FORMAT", "env: DRONE_HUNTER_OUTPUT_FORMAT") { |argument| config[:output][:format] = output_format_from(argument) }
101
+ options.on("-p", "--output-path=PATH", "env: DRONE_HUNTER_OUTPUT_PATH") { |argument| config[:output][:path] = File.expand_path(argument) }
102
+ options.on("-N", "--[no-]output-normalize", "env: DRONE_HUNTER_OUTPUT_NORMALIZE") { |argument| config[:output][:normalize] = argument }
103
+ options.on("-A", "--[no-]ignore-archived", "env: DRONE_HUNTER_IGNORE_ARCHIVED") { |argument| config[:ignore][:archived] = argument }
104
+ options.on("-B", "--match-basename=REGEXP", "env: DRONE_HUNTER_MATCH_BASENAME") { |argument| config[:match][:basename] = Regexp.new(argument) }
105
+ options.on("-S", "--match-suffix=REGEXP", "env: DRONE_HUNTER_MATCH_SUFFIX") { |argument| config[:match][:suffix] = Regexp.new(argument + "$") }
84
106
  end.parse!
85
107
 
86
108
  #################
@@ -122,13 +144,20 @@ cache = Moneta.new(:File, dir: config[:cache][:dir])
122
144
  # Main Program #
123
145
  ################
124
146
 
125
- hunt = DroneHunter.new(owners: ARGV, log: log, github: github, cache: cache)
147
+ hunt = DroneHunter.new(owners: ARGV, log: log, github: github, cache: cache, ignore: config[:ignore], match: config[:match])
126
148
 
127
149
  if config[:hacking]
128
150
  require "pry"
129
151
  binding.pry
130
152
  else
131
- hunt.dronefiles.then do |dronefiles|
153
+ hunt.dronefiles.each do |dronefile|
154
+ if config[:output][:normalize]
155
+ require "yaml"
156
+ original = dronefile["content"]
157
+ normalized = YAML.dump(YAML.load(original))
158
+ dronefile["content"] = normalized
159
+ end
160
+ end.then do |dronefiles|
132
161
  case config[:output][:format]
133
162
  when :JSON
134
163
  require "json"
data/drone-hunter.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
- tag = `git describe --tags --abbrev=0`.chomp
3
-
2
+ tag = `git describe --tags --always`.chomp
3
+
4
4
  gem.name = 'drone-hunter'
5
5
  gem.homepage = 'https://github.com/colstrom/drone-hunter'
6
6
  gem.summary = 'Hunts for Drone CI files across many repositories'
data/lib/drone_hunter.rb CHANGED
@@ -7,6 +7,7 @@
7
7
  require "base64"
8
8
  require "logger"
9
9
  require "set"
10
+ require "yaml"
10
11
 
11
12
  #########################
12
13
  # External Dependencies #
@@ -21,12 +22,20 @@ class DroneHunter
21
22
  @github ||= options.fetch(:client) { Octokit::Client.new(auto_paginate: true) }
22
23
  @cache ||= options.fetch(:cache) { Moneta.new(:File, dir: 'drone-hunter.cache') }
23
24
  @owners ||= Set.new(options.fetch(:owners, []))
25
+ @ignoring ||= { archived: false }.merge(options.fetch(:ignore, {}))
26
+ @match ||= { basename: /drone/, suffix: /[.]ya?ml$/ }.merge(options.fetch(:match, {}))
24
27
  end
25
28
 
26
29
  attr_reader :log
27
30
  attr_reader :github
28
31
  attr_reader :cache
29
32
  attr_reader :owners
33
+ attr_reader :ignoring
34
+ attr_reader :match
35
+
36
+ def ignoring_archived?
37
+ ignoring.fetch(:archived, false)
38
+ end
30
39
 
31
40
  def cached(key, *rest, &block)
32
41
  if cache.key?(key)
@@ -41,7 +50,9 @@ class DroneHunter
41
50
  def repositories(owner = nil)
42
51
  case owner
43
52
  when String then cached("repositories/#{owner}") { github.repositories(owner) }
44
- when nil then owners.flat_map { |owner| repositories(owner) }
53
+ when nil then owners.flat_map { |owner| repositories(owner) }.reject do |repo|
54
+ ignoring_archived? && repo.archived
55
+ end
45
56
  else raise TypeError
46
57
  end
47
58
  end
@@ -73,8 +84,8 @@ class DroneHunter
73
84
  def blobs
74
85
  trees.map do |repo, tree|
75
86
  blobs = tree
76
- .select { |entry| entry.path.match?(/ya?ml$/) }
77
- .select { |entry| entry.path.match?(/drone/) }
87
+ .select { |entry| entry.path.match?(match[:suffix]) }
88
+ .select { |entry| entry.path.match?(match[:basename]) }
78
89
  .map do |entry|
79
90
  {
80
91
  entry.path => cached("blob/#{repo}/#{entry.sha}") { github.blob(repo, entry.sha) }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: drone-hunter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Olstrom
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-05 00:00:00.000000000 Z
11
+ date: 2022-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: octokit
@@ -57,6 +57,10 @@ executables:
57
57
  extensions: []
58
58
  extra_rdoc_files: []
59
59
  files:
60
+ - ".github/dependabot.yml"
61
+ - ".github/workflows/codeql-analysis.yml"
62
+ - ".github/workflows/gem-push.yml"
63
+ - CHANGELOG.md
60
64
  - Gemfile
61
65
  - LICENSE.txt
62
66
  - README.md