codeinventory-github 0.1.1 → 0.1.3
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 +4 -4
- data/README.md +19 -1
- data/bin/console +1 -1
- data/lib/codeinventory/github.rb +18 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c44f83f0f75fe961775c818fbfab9619e2cff06b
|
4
|
+
data.tar.gz: d382f89f51c4352e459dee4973b4586dd9463a1d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a65202527e863c5ba035c37a3fe882db75499b29332a78d3975f9d08717bf2be6aabdc51fd9e393f5282303b1967ec45442ebe4d2b1924a7b013fbc8b875f92
|
7
|
+
data.tar.gz: 6cd71f3db07c98ca99f051434fe5d1bea2ea4a0846344dc6ccf767a9e3a0aacc060d5ce569a69a727415491072c564584a4afb971e05df24fd62dae693be051e
|
data/README.md
CHANGED
@@ -8,6 +8,20 @@ The `codeinventory-github` gem is a [CodeInventory](https://github.com/GSA/codei
|
|
8
8
|
* GitHub metadata
|
9
9
|
* Manually specified overrides
|
10
10
|
|
11
|
+
This tool currently supports the following code.json fields:
|
12
|
+
|
13
|
+
* name
|
14
|
+
* description
|
15
|
+
* license
|
16
|
+
* openSourceProject
|
17
|
+
* governmentWideReuseProject
|
18
|
+
* tags
|
19
|
+
* contact > email
|
20
|
+
* repository
|
21
|
+
* organization
|
22
|
+
|
23
|
+
Most of these are fields required by [Code.gov](https://code.gov/). The plan is to gradually add in the rest of the optional fields.
|
24
|
+
|
11
25
|
## Installation
|
12
26
|
|
13
27
|
Add this line to your application's Gemfile:
|
@@ -58,6 +72,8 @@ tags:
|
|
58
72
|
- usa
|
59
73
|
contact:
|
60
74
|
email: example@example.com
|
75
|
+
repository: https://github.com/octocat/Spoon-Knife
|
76
|
+
organization: ABC Bureau
|
61
77
|
```
|
62
78
|
|
63
79
|
#### JSON Format (.codeinventory.json)
|
@@ -74,7 +90,9 @@ contact:
|
|
74
90
|
],
|
75
91
|
"contact": {
|
76
92
|
"email": "example@example.com"
|
77
|
-
}
|
93
|
+
},
|
94
|
+
"repository": "https://github.com/octocat/Spoon-Knife",
|
95
|
+
"organization": "ABC Bureau"
|
78
96
|
}
|
79
97
|
```
|
80
98
|
|
data/bin/console
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require "bundler/setup"
|
4
4
|
require "codeinventory"
|
5
|
-
require "codeinventory
|
5
|
+
require "codeinventory/github"
|
6
6
|
|
7
7
|
# You can add fixtures and/or initialization code here to make experimenting
|
8
8
|
# with your gem easier. You can also use a different console, if you like.
|
data/lib/codeinventory/github.rb
CHANGED
@@ -4,7 +4,7 @@ require "base64"
|
|
4
4
|
|
5
5
|
module CodeInventory
|
6
6
|
class GitHub
|
7
|
-
VERSION = "0.1.
|
7
|
+
VERSION = "0.1.3"
|
8
8
|
attr_accessor :org, :overrides, :exclude
|
9
9
|
|
10
10
|
def initialize(access_token:, org:, overrides: {}, exclude: [])
|
@@ -30,6 +30,8 @@ module CodeInventory
|
|
30
30
|
repo_metadata["tags"] = tags(repo, inventory_file_metadata)
|
31
31
|
repo_metadata["contact"] = { "email" => contact_email(repo, inventory_file_metadata) }
|
32
32
|
repo_metadata["repository"] = repository(repo, inventory_file_metadata)
|
33
|
+
organization = organization(repo, inventory_file_metadata)
|
34
|
+
repo_metadata["organization"] = organization(repo, inventory_file_metadata) unless organization.nil?
|
33
35
|
projects << repo_metadata
|
34
36
|
end
|
35
37
|
projects
|
@@ -43,6 +45,8 @@ module CodeInventory
|
|
43
45
|
unless inventory_file.nil?
|
44
46
|
file_content = client.contents(repo[:full_name], path: inventory_file[:path])
|
45
47
|
raw_content = Base64.decode64(file_content[:content])
|
48
|
+
# Remove UTF-8 BOM if there is one; it throws off JSON.parse
|
49
|
+
raw_content.sub!("\xEF\xBB\xBF".force_encoding("ASCII-8BIT"), "")
|
46
50
|
if inventory_file[:name].end_with? ".yml"
|
47
51
|
metadata = YAML.load(raw_content).to_hash
|
48
52
|
elsif inventory_file[:name].end_with? ".json"
|
@@ -141,11 +145,22 @@ module CodeInventory
|
|
141
145
|
# Order of precedence:
|
142
146
|
# 1. List of overrides
|
143
147
|
# 2. CodeInventory metadata file
|
144
|
-
# 3. GitHub repository URL
|
148
|
+
# 3. If repo is public, GitHub repository URL, otherwise nil
|
145
149
|
def repository(repo, inventory_file_metadata)
|
146
150
|
return @overrides[:repository] if @overrides[:repository]
|
147
151
|
return inventory_file_metadata["repository"] if inventory_file_metadata["repository"]
|
148
|
-
repo[:html_url]
|
152
|
+
repo[:private] ? nil : repo[:html_url]
|
153
|
+
end
|
154
|
+
|
155
|
+
# Provies a value for the organization field (optional).
|
156
|
+
# Order of precedence:
|
157
|
+
# 1. List of overrides
|
158
|
+
# 2. CodeInventory metadata file
|
159
|
+
# 3. No organization field
|
160
|
+
def organization(repo, inventory_file_metadata)
|
161
|
+
return @overrides[:organization] if @overrides[:organization]
|
162
|
+
return inventory_file_metadata["organization"] if inventory_file_metadata["organization"]
|
163
|
+
nil
|
149
164
|
end
|
150
165
|
|
151
166
|
def client
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: codeinventory-github
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Fredrickson
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|