codeinventory-github 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 14db941ce2b924355eaffb6c538731d1da65990b
4
+ data.tar.gz: 51069e1abc8f558d31839501a933c9ce3850928a
5
+ SHA512:
6
+ metadata.gz: b490bf919711a73cf0c4a3c6c7f014efe96f6c6628a158138e5dd8e3e55ee6a17e0e114afb1e67ba16bae604bda35c488606c0cfe146c5ebfec59a13f4fa4cc4
7
+ data.tar.gz: 043d08d40d9d9eed3a5382bc5ae354f10541a25231a3b72dd8f0e799659215c3e5f988a654434c2edeb55a9d179a09dae2cad83d25861c32624800cd9ef3bfa8
@@ -0,0 +1,9 @@
1
+ name: CodeInventory GitHub
2
+ description: A plugin for the CodeInventory gem that harvests project metadata from YAML or JSON files in GitHub repositories.
3
+ license: https://github.com/GSA/codeinventory-github/blob/master/LICENSE.md
4
+ openSourceProject: 1
5
+ governmentWideReuseProject: 1
6
+ tags:
7
+ - code.gov
8
+ contact:
9
+ email: jeffrey.fredrickson@gsa.gov
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.gem
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.13.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in codeinventory-github.gemspec
4
+ gemspec
data/LICENSE.md ADDED
@@ -0,0 +1,3 @@
1
+ # License
2
+
3
+ As a work of the United States Government, this project is in the public domain within the United States.
data/README.md ADDED
@@ -0,0 +1,79 @@
1
+ # CodeInventory GitHub
2
+
3
+ *_This is an experimental gem that is currently in an alpha stage. The features and interface are unstable and may change at any time._*
4
+
5
+ The `codeinventory-github` gem is a [CodeInventory](https://github.com/GSA/codeinventory) plugin. This plugin allows CodeInventory to gather metadata from `.codeinventory.yml` or `.codeinventory.json` files in GitHub repositories.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'codeinventory-github'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install codeinventory-github
22
+
23
+ ## Usage
24
+
25
+ Basically:
26
+
27
+ ```ruby
28
+ require "codeinventory"
29
+ require "codeinventory-github"
30
+
31
+ github_source = CodeInventory::GitHub.new(access_token: "GITHUB_ACCESS_TOKEN", org: "github_org_name")
32
+
33
+ inventory = CodeInventory::Inventory.new(github_source)
34
+ inventory.projects # Returns an array of all projects in the GitHub org that have metadata
35
+ ```
36
+
37
+ When using `CodeInventory::GitHub`, provide a [GitHub access token](https://developer.github.com/v3/oauth/) and the GitHub organization name (e.g., "[GSA](https://github.com/GSA/)"). Each repository within the organization that needs to be included in the project listing should have a `.codeinventory.yml` or `.codeinventory.json` file in the repository's root directory.
38
+
39
+ #### YAML Format (.codeinventory.yml)
40
+
41
+ ```yaml
42
+ name: Product One
43
+ description: An awesome product.
44
+ license: http://www.usa.gov/publicdomain/label/1.0/
45
+ openSourceProject: 1
46
+ governmentWideReuseProject: 1
47
+ tags:
48
+ - usa
49
+ contact:
50
+ email: example@example.com
51
+ ```
52
+
53
+ #### JSON Format (.codeinventory.json)
54
+
55
+ ```json
56
+ {
57
+ "name": "Product One",
58
+ "description": "An awesome product.",
59
+ "license": "http://www.usa.gov/publicdomain/label/1.0/",
60
+ "openSourceProject": 1,
61
+ "governmentWideReuseProject": 1,
62
+ "tags": [
63
+ "usa"
64
+ ],
65
+ "contact": {
66
+ "email": "example@example.com"
67
+ }
68
+ }
69
+ ```
70
+
71
+ ## Development
72
+
73
+ 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.
74
+
75
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in [`github.rb`](/lib/codeinventory/github.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).
76
+
77
+ ## Contributing
78
+
79
+ Bug reports and pull requests are welcome on GitHub at https://github.com/GSA/codeinventory-github.
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "spec"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['spec/**/*_spec.rb']
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "codeinventory"
5
+ require "codeinventory-github"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ require "pry"
12
+ Pry.start
13
+
14
+ # require "irb"
15
+ # IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'codeinventory/github'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "codeinventory-github"
8
+ spec.version = CodeInventory::GitHub::VERSION
9
+ spec.authors = ["Jeff Fredrickson"]
10
+ spec.email = ["jeffrey.fredrickson@gsa.gov"]
11
+
12
+ spec.summary = %q{Harvests project metadata from YAML or JSON files in GitHub repositories.}
13
+ spec.description = %q{A plugin for the CodeInventory gem that harvests project metadata from YAML or JSON files in GitHub repositories.}
14
+ spec.homepage = "https://github.com/GSA/codeinventory-github"
15
+ spec.license = "CC0-1.0"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.13"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "minitest", "~> 5.0"
27
+ spec.add_development_dependency "webmock", "~> 2.1"
28
+ spec.add_development_dependency "pry", "~> 0.10"
29
+
30
+ spec.add_runtime_dependency "codeinventory", "~> 0.1.0"
31
+ spec.add_runtime_dependency "octokit", "~> 4.6"
32
+ end
@@ -0,0 +1,46 @@
1
+ require "octokit"
2
+ require "yaml"
3
+ require "base64"
4
+
5
+ module CodeInventory
6
+ class GitHub
7
+ VERSION = "0.1.0"
8
+ attr_accessor :org
9
+
10
+ def initialize(access_token:, org:)
11
+ Octokit.auto_paginate = true
12
+ @access_token = access_token
13
+ @org = org
14
+ end
15
+
16
+ def projects
17
+ repos = client.organization_repositories(@org)
18
+ projects = []
19
+ repos.each do |repo|
20
+ begin
21
+ contents_metadata = client.contents(repo[:full_name], path: ".codeinventory.yml")
22
+ type = :yaml
23
+ raw_content = Base64.decode64(contents_metadata[:content])
24
+ rescue Octokit::NotFound
25
+ begin
26
+ contents_metadata = client.contents(repo[:full_name], path: ".codeinventory.json")
27
+ type = :json
28
+ raw_content = Base64.decode64(contents_metadata[:content])
29
+ rescue Octokit::NotFound
30
+ # Ignore repositories that don't have a CodeInventory metadata file
31
+ end
32
+ end
33
+ if type == :yaml
34
+ projects << YAML.load(raw_content).to_hash
35
+ elsif type == :json
36
+ projects << JSON.parse(raw_content)
37
+ end
38
+ end
39
+ projects
40
+ end
41
+
42
+ def client
43
+ @client ||= Octokit::Client.new(access_token: @access_token)
44
+ end
45
+ end
46
+ end
metadata ADDED
@@ -0,0 +1,154 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: codeinventory-github
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jeff Fredrickson
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-12-06 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: '1.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.1'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.10'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.10'
83
+ - !ruby/object:Gem::Dependency
84
+ name: codeinventory
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.1.0
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.1.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: octokit
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '4.6'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '4.6'
111
+ description: A plugin for the CodeInventory gem that harvests project metadata from
112
+ YAML or JSON files in GitHub repositories.
113
+ email:
114
+ - jeffrey.fredrickson@gsa.gov
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".codeinventory.yml"
120
+ - ".gitignore"
121
+ - ".travis.yml"
122
+ - Gemfile
123
+ - LICENSE.md
124
+ - README.md
125
+ - Rakefile
126
+ - bin/console
127
+ - bin/setup
128
+ - codeinventory-github.gemspec
129
+ - lib/codeinventory/github.rb
130
+ homepage: https://github.com/GSA/codeinventory-github
131
+ licenses:
132
+ - CC0-1.0
133
+ metadata: {}
134
+ post_install_message:
135
+ rdoc_options: []
136
+ require_paths:
137
+ - lib
138
+ required_ruby_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ required_rubygems_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ requirements: []
149
+ rubyforge_project:
150
+ rubygems_version: 2.5.1
151
+ signing_key:
152
+ specification_version: 4
153
+ summary: Harvests project metadata from YAML or JSON files in GitHub repositories.
154
+ test_files: []