find-circle-yml 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +53 -0
- data/exe/find-circle-yml +28 -0
- data/lib/find_circle_yml.rb +13 -0
- data/lib/find_circle_yml/bitbucket/configuration.rb +49 -0
- data/lib/find_circle_yml/bitbucket/service.rb +54 -0
- data/lib/find_circle_yml/configuration_file.rb +5 -0
- data/lib/find_circle_yml/github/configuration.rb +49 -0
- data/lib/find_circle_yml/github/service.rb +40 -0
- data/lib/find_circle_yml/repository.rb +5 -0
- data/lib/find_circle_yml/version.rb +5 -0
- data/test/test_helper.rb +6 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ad3e5216155d142793a5985488898882306bea77
|
4
|
+
data.tar.gz: 77b09f85bcdefff11c3ab35e48446d51cfe801f0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d63eefc0c6a60da841c4c9a588d5dd37efecd324fa915828be9a92d42b9aea811080b88f854d1910770420012ddb5310abc35bc2f73eb632b8e5b836df038e35
|
7
|
+
data.tar.gz: 843965e38d1edf5440fe9dc0890f1d31f45def0ac47e94090462b694134996b352fcf0179be6495c9c2aad87ae6a76f3f9b690783786e1675dd1eb317adad9d3
|
data/README.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# find-circle-yml
|
2
|
+
|
3
|
+
A command-line tool for finding which repositories in your GitHub organization or Bitbucket team have `circle.yml` configuration files.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
$ gem install find-circle-yml
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
**GitHub**
|
12
|
+
|
13
|
+
$ GITHUB_ORGANIZATION=<your github org> GITHUB_USER=<your github user> GITHUB_ACCESS_TOKEN=<your personal access token> find-circle-yml
|
14
|
+
https://github.com/your-org/your-repo/blob/master/circle.yml
|
15
|
+
https://github.com/your-org/another-repo/blob/master/circle.yml
|
16
|
+
|
17
|
+
**Bitbucket**
|
18
|
+
|
19
|
+
$ BITBUCKET_TEAM=<your bitbucket team> BITBUCKET_USER=<your bitbucket user> BITBUCKET_APP_PASSWORD=<your bitbucket password> find-circle-yml
|
20
|
+
https://bitbucket.org/your-team/your-repo/src/bb030e9dcee6218d0ce521b7312e60e5cc5db4a3/circle.yml
|
21
|
+
https://bitbucket.org/your-team/another-repo/src/cf9f1078be258dd902ff49718e5ee5422e2dd08f/circle.yml
|
22
|
+
|
23
|
+
Writes a list of repositories that contain a `circle.yml` to standard out.
|
24
|
+
|
25
|
+
## Authorization
|
26
|
+
|
27
|
+
Authorization requires creating an app-specific password for your platform:
|
28
|
+
|
29
|
+
**GitHub**
|
30
|
+
|
31
|
+
See [the docs for creating a personal access token](https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/). Ensure that the token has the **repo** and **read:org** scope. Use the token as the value of `GITHUB_ACCESS_TOKEN` environment variable.
|
32
|
+
|
33
|
+
**Bitbucket**
|
34
|
+
|
35
|
+
See [the docs for creating an app password](https://confluence.atlassian.com/bitbucket/app-passwords-828781300.html). Ensure that the app password has the **Team membership Read** and **Repositories Read** permissions. Use the app password as the value of `BITBUCKET_APP_PASSWORD` environment variable.
|
36
|
+
|
37
|
+
## Development
|
38
|
+
|
39
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
40
|
+
|
41
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
42
|
+
|
43
|
+
## Contributing
|
44
|
+
|
45
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/circleci/find-circle-yml. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
46
|
+
|
47
|
+
## License
|
48
|
+
|
49
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
50
|
+
|
51
|
+
## Code of Conduct
|
52
|
+
|
53
|
+
Everyone interacting in the circleci-audit project is expected to follow the [code of conduct](https://github.com/CircleCI-Public/find-circle-yml/blob/master/CODE_OF_CONDUCT.md).
|
data/exe/find-circle-yml
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'find_circle_yml'
|
5
|
+
|
6
|
+
provided_configurations = [
|
7
|
+
FindCircleYml::Bitbucket::Configuration.new(ENV),
|
8
|
+
FindCircleYml::GitHub::Configuration.new(ENV)
|
9
|
+
].select(&:provided?)
|
10
|
+
|
11
|
+
if provided_configurations.empty?
|
12
|
+
STDERR.puts 'Provide a Bitbucket or GitHub configuration'
|
13
|
+
exit 1
|
14
|
+
end
|
15
|
+
|
16
|
+
provided_configurations.each do |configuration|
|
17
|
+
if configuration.valid?
|
18
|
+
service = configuration.service
|
19
|
+
service.repositories.each do |repository|
|
20
|
+
if (configuration_file = service.configuration_file(repository))
|
21
|
+
puts configuration_file.url
|
22
|
+
end
|
23
|
+
end
|
24
|
+
else
|
25
|
+
STDERR.puts configuration.error_message
|
26
|
+
exit 1
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'octokit'
|
4
|
+
require 'net/http'
|
5
|
+
require 'uri'
|
6
|
+
require 'json'
|
7
|
+
|
8
|
+
require 'find_circle_yml/repository'
|
9
|
+
require 'find_circle_yml/configuration_file'
|
10
|
+
require 'find_circle_yml/github/service'
|
11
|
+
require 'find_circle_yml/github/configuration'
|
12
|
+
require 'find_circle_yml/bitbucket/configuration'
|
13
|
+
require 'find_circle_yml/bitbucket/service'
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FindCircleYml
|
4
|
+
module Bitbucket
|
5
|
+
class Configuration
|
6
|
+
ENVIRONMENT_VARIABLES = %w[
|
7
|
+
BITBUCKET_USER
|
8
|
+
BITBUCKET_APP_PASSWORD
|
9
|
+
BITBUCKET_TEAM
|
10
|
+
].freeze
|
11
|
+
|
12
|
+
attr_reader :environment
|
13
|
+
|
14
|
+
def initialize(environment)
|
15
|
+
@environment = environment
|
16
|
+
end
|
17
|
+
|
18
|
+
def provided?
|
19
|
+
ENVIRONMENT_VARIABLES.any? do |environment_variable|
|
20
|
+
environment.key?(environment_variable)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def valid?
|
25
|
+
missing.empty?
|
26
|
+
end
|
27
|
+
|
28
|
+
def error_message
|
29
|
+
"Set environment variables: #{missing.join(', ')}"
|
30
|
+
end
|
31
|
+
|
32
|
+
def service
|
33
|
+
Bitbucket::Service.new(
|
34
|
+
environment.fetch('BITBUCKET_USER'),
|
35
|
+
environment.fetch('BITBUCKET_APP_PASSWORD'),
|
36
|
+
environment.fetch('BITBUCKET_TEAM')
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def missing
|
43
|
+
ENVIRONMENT_VARIABLES.reject do |environment_variable|
|
44
|
+
environment.key?(environment_variable)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FindCircleYml
|
4
|
+
module Bitbucket
|
5
|
+
class Service
|
6
|
+
attr_reader :user, :password, :team
|
7
|
+
|
8
|
+
def initialize(user, password, team)
|
9
|
+
@user = user
|
10
|
+
@password = password
|
11
|
+
@team = team
|
12
|
+
end
|
13
|
+
|
14
|
+
def repositories
|
15
|
+
Enumerator.new do |y|
|
16
|
+
url = "/repositories/#{team}"
|
17
|
+
loop do
|
18
|
+
response = request(url)
|
19
|
+
parsed_response = JSON.parse(response.body)
|
20
|
+
parsed_response.fetch('values', []).each do |value|
|
21
|
+
y << Repository.new(
|
22
|
+
value.fetch('full_name'),
|
23
|
+
value.dig('mainbranch', 'branch') || 'master',
|
24
|
+
value.fetch('links').fetch('html').fetch('href')
|
25
|
+
)
|
26
|
+
end
|
27
|
+
break unless parsed_response.key?('next')
|
28
|
+
url = parsed_response.fetch('next')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def configuration_file(repository)
|
34
|
+
response = request("/repositories/#{repository.name}/src/#{repository.main_branch}/circle.yml?format=meta")
|
35
|
+
return unless response.code == '200'
|
36
|
+
parsed_response = JSON.parse(response.body)
|
37
|
+
commit = parsed_response.fetch('commit', {}).fetch('hash', repository.main_branch)
|
38
|
+
path = parsed_response.fetch('path')
|
39
|
+
ConfigurationFile.new("#{repository.url}/src/#{commit}/#{path}")
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def request(path)
|
45
|
+
uri = URI("https://api.bitbucket.org/2.0#{path}")
|
46
|
+
Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
|
47
|
+
request = Net::HTTP::Get.new(uri)
|
48
|
+
request.basic_auth(user, password)
|
49
|
+
http.request request
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FindCircleYml
|
4
|
+
module GitHub
|
5
|
+
class Configuration
|
6
|
+
ENVIRONMENT_VARIABLES = %w[
|
7
|
+
GITHUB_USER
|
8
|
+
GITHUB_ACCESS_TOKEN
|
9
|
+
GITHUB_ORGANIZATION
|
10
|
+
].freeze
|
11
|
+
|
12
|
+
attr_reader :environment
|
13
|
+
|
14
|
+
def initialize(environment)
|
15
|
+
@environment = environment
|
16
|
+
end
|
17
|
+
|
18
|
+
def provided?
|
19
|
+
ENVIRONMENT_VARIABLES.any? do |environment_variable|
|
20
|
+
environment.key?(environment_variable)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def valid?
|
25
|
+
missing.empty?
|
26
|
+
end
|
27
|
+
|
28
|
+
def error_message
|
29
|
+
"Set environment variables: #{missing.join(', ')}"
|
30
|
+
end
|
31
|
+
|
32
|
+
def service
|
33
|
+
GitHub::Service.new(
|
34
|
+
environment.fetch('GITHUB_USER'),
|
35
|
+
environment.fetch('GITHUB_ACCESS_TOKEN'),
|
36
|
+
environment.fetch('GITHUB_ORGANIZATION')
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def missing
|
43
|
+
ENVIRONMENT_VARIABLES.reject do |environment_variable|
|
44
|
+
environment.key?(environment_variable)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FindCircleYml
|
4
|
+
module GitHub
|
5
|
+
class Service
|
6
|
+
attr_reader :user, :access_token, :organization
|
7
|
+
|
8
|
+
def initialize(user, access_token, organization)
|
9
|
+
@user = user
|
10
|
+
@access_token = access_token
|
11
|
+
@organization = organization
|
12
|
+
end
|
13
|
+
|
14
|
+
def repositories
|
15
|
+
client.organization_repositories(organization).map do |response|
|
16
|
+
Repository.new(
|
17
|
+
response[:full_name],
|
18
|
+
response[:default_branch],
|
19
|
+
response[:html_url]
|
20
|
+
)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def configuration_file(repository)
|
25
|
+
ConfigurationFile.new(
|
26
|
+
client.contents(repository.name, path: 'circle.yml')[:html_url]
|
27
|
+
)
|
28
|
+
rescue Octokit::NotFound
|
29
|
+
nil
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def client
|
35
|
+
Octokit.auto_paginate = true
|
36
|
+
Octokit::Client.new(login: user, password: access_token)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: find-circle-yml
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- nwjsmith
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-03-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 5.11.3
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 5.11.3
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 12.3.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 12.3.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: octokit
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: |2
|
70
|
+
A command-line tool for finding which repositories in your GitHub
|
71
|
+
organization or Bitbucket team have circle.yml configuration files.
|
72
|
+
email:
|
73
|
+
- sayhi@circleci.com
|
74
|
+
executables:
|
75
|
+
- find-circle-yml
|
76
|
+
extensions: []
|
77
|
+
extra_rdoc_files: []
|
78
|
+
files:
|
79
|
+
- README.md
|
80
|
+
- exe/find-circle-yml
|
81
|
+
- lib/find_circle_yml.rb
|
82
|
+
- lib/find_circle_yml/bitbucket/configuration.rb
|
83
|
+
- lib/find_circle_yml/bitbucket/service.rb
|
84
|
+
- lib/find_circle_yml/configuration_file.rb
|
85
|
+
- lib/find_circle_yml/github/configuration.rb
|
86
|
+
- lib/find_circle_yml/github/service.rb
|
87
|
+
- lib/find_circle_yml/repository.rb
|
88
|
+
- lib/find_circle_yml/version.rb
|
89
|
+
- test/test_helper.rb
|
90
|
+
homepage: https://github.com/CircleCI-Public/find-circle-yml
|
91
|
+
licenses:
|
92
|
+
- MIT
|
93
|
+
metadata: {}
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: 2.4.0
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 2.6.13
|
111
|
+
signing_key:
|
112
|
+
specification_version: 4
|
113
|
+
summary: Finds circle.yml files
|
114
|
+
test_files:
|
115
|
+
- test/test_helper.rb
|