codeinventory-github 0.3.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 +4 -4
- data/README.md +21 -16
- data/lib/codeinventory/github/source.rb +70 -55
- data/lib/codeinventory/github/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4adb87edfb54ee9c5f57ffd5c6ce26ccf6d45c5f
|
4
|
+
data.tar.gz: 933c2da647c7ce18b46f19b64002f422a157e65a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e4a5c71fe105acb609f3809066ade8d38543b4ce7b14bb8483e3fb53963ae530c0149a38d2c9a66400c03707f9b808db29731a1e3902ed43b7e4a1b4fc1a087
|
7
|
+
data.tar.gz: b75771c365399b238ea77d6c6bad20bb3a181c22f2b24ae59b8ede6dba3505d727c77b11a46de812bb7ca1c448c6e9b44db714ff83fbced2e6e05fc2ff82172d
|
data/README.md
CHANGED
@@ -8,16 +8,16 @@ 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:
|
11
|
+
This tool currently supports the following code.json fields, based on Code.gov metadata 2.0.0:
|
12
12
|
|
13
13
|
* name
|
14
14
|
* description
|
15
|
-
*
|
16
|
-
*
|
17
|
-
*
|
15
|
+
* permissions > licenses
|
16
|
+
* permissions > usageType
|
17
|
+
* permissions > exemptionTexzt
|
18
18
|
* tags
|
19
19
|
* contact > email
|
20
|
-
*
|
20
|
+
* repositoryURL
|
21
21
|
* organization
|
22
22
|
|
23
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.
|
@@ -70,14 +70,16 @@ If you want more fine-grained control over project metadata beyond what is in th
|
|
70
70
|
```yaml
|
71
71
|
name: Product One
|
72
72
|
description: An awesome product.
|
73
|
-
|
74
|
-
|
75
|
-
|
73
|
+
permissions:
|
74
|
+
licenses:
|
75
|
+
- URL: http://www.usa.gov/publicdomain/label/1.0/
|
76
|
+
name: PD
|
77
|
+
usageType: openSource
|
76
78
|
tags:
|
77
79
|
- usa
|
78
80
|
contact:
|
79
81
|
email: example@example.com
|
80
|
-
|
82
|
+
repositoryURL: https://github.com/octocat/Spoon-Knife
|
81
83
|
organization: ABC Bureau
|
82
84
|
```
|
83
85
|
|
@@ -87,16 +89,19 @@ organization: ABC Bureau
|
|
87
89
|
{
|
88
90
|
"name": "Product One",
|
89
91
|
"description": "An awesome product.",
|
90
|
-
"
|
91
|
-
|
92
|
-
|
92
|
+
"permissions": {
|
93
|
+
"licenses": [
|
94
|
+
{ "URL": "http://www.usa.gov/publicdomain/label/1.0/", name: "PD" }
|
95
|
+
],
|
96
|
+
"usageType": "openSource"
|
97
|
+
}
|
93
98
|
"tags": [
|
94
99
|
"usa"
|
95
100
|
],
|
96
101
|
"contact": {
|
97
102
|
"email": "example@example.com"
|
98
103
|
},
|
99
|
-
"
|
104
|
+
"repositoryURL": "https://github.com/octocat/Spoon-Knife",
|
100
105
|
"organization": "ABC Bureau"
|
101
106
|
}
|
102
107
|
```
|
@@ -144,11 +149,11 @@ If the metadata file does not exist or does not contain a field, and there are n
|
|
144
149
|
|
145
150
|
* name - GitHub repository name
|
146
151
|
* description - GitHub repository description
|
147
|
-
* license - GitHub repository license
|
148
|
-
*
|
152
|
+
* permissions > license - GitHub repository license
|
153
|
+
* permissions > usageType - `openSource` if the repository is public, `governmentWideReuse` if it is private
|
149
154
|
* tags - GitHub repository topics
|
150
155
|
* contact > email - GitHub organization email address
|
151
|
-
*
|
156
|
+
* repositoryURL - GitHub repository URL
|
152
157
|
|
153
158
|
If you already specify any of the above items in your GitHub repository, there is no need to specify them in a metadata file.
|
154
159
|
|
@@ -16,51 +16,56 @@ module CodeInventory
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def project(repo_name)
|
19
|
-
|
19
|
+
# mercy = GitHub topics preview
|
20
|
+
# drax = GitHub license preview
|
21
|
+
headers = {
|
22
|
+
accept: [ "application/vnd.github.mercy-preview+json", "application/vnd.github.drax-preview+json" ]
|
23
|
+
}
|
20
24
|
repo = client.repository(repo_name, headers)
|
21
25
|
inventory_file_metadata = inventory_file(repo)
|
22
26
|
unless inventory_file_metadata.dig("codeinventory", "exclude")
|
23
|
-
|
24
|
-
repo_metadata["name"] = name(repo, inventory_file_metadata)
|
25
|
-
repo_metadata["description"] = description(repo, inventory_file_metadata)
|
26
|
-
repo_metadata["license"] = license(repo, inventory_file_metadata)
|
27
|
-
repo_metadata["openSourceProject"] = open_source_project(repo, inventory_file_metadata)
|
28
|
-
repo_metadata["governmentWideReuseProject"] = government_wide_reuse_project(repo, inventory_file_metadata)
|
29
|
-
repo_metadata["tags"] = tags(repo, inventory_file_metadata)
|
30
|
-
repo_metadata["contact"] = { "email" => contact_email(repo, inventory_file_metadata) }
|
31
|
-
repo_metadata["repository"] = repository(repo, inventory_file_metadata)
|
32
|
-
organization = organization(repo, inventory_file_metadata)
|
33
|
-
repo_metadata["organization"] = organization(repo, inventory_file_metadata) unless organization.nil?
|
34
|
-
repo_metadata
|
27
|
+
build_metadata(repo, inventory_file_metadata)
|
35
28
|
end
|
36
29
|
end
|
37
30
|
|
38
31
|
def projects
|
39
|
-
|
32
|
+
# mercy = GitHub topics preview
|
33
|
+
# drax = GitHub license preview
|
34
|
+
headers = {
|
35
|
+
accept: [ "application/vnd.github.mercy-preview+json", "application/vnd.github.drax-preview+json" ]
|
36
|
+
}
|
40
37
|
repos = client.organization_repositories(@org, headers)
|
41
38
|
repos.delete_if { |repo| exclude.include? repo[:name] }
|
42
39
|
projects = []
|
43
40
|
repos.each do |repo|
|
44
41
|
inventory_file_metadata = inventory_file(repo)
|
45
42
|
unless inventory_file_metadata.dig("codeinventory", "exclude")
|
46
|
-
|
47
|
-
repo_metadata["name"] = name(repo, inventory_file_metadata)
|
48
|
-
repo_metadata["description"] = description(repo, inventory_file_metadata)
|
49
|
-
repo_metadata["license"] = license(repo, inventory_file_metadata)
|
50
|
-
repo_metadata["openSourceProject"] = open_source_project(repo, inventory_file_metadata)
|
51
|
-
repo_metadata["governmentWideReuseProject"] = government_wide_reuse_project(repo, inventory_file_metadata)
|
52
|
-
repo_metadata["tags"] = tags(repo, inventory_file_metadata)
|
53
|
-
repo_metadata["contact"] = { "email" => contact_email(repo, inventory_file_metadata) }
|
54
|
-
repo_metadata["repository"] = repository(repo, inventory_file_metadata)
|
55
|
-
organization = organization(repo, inventory_file_metadata)
|
56
|
-
repo_metadata["organization"] = organization(repo, inventory_file_metadata) unless organization.nil?
|
57
|
-
projects << repo_metadata
|
43
|
+
projects << build_metadata(repo, inventory_file_metadata)
|
58
44
|
yield repo_metadata if block_given?
|
59
45
|
end
|
60
46
|
end
|
61
47
|
projects
|
62
48
|
end
|
63
49
|
|
50
|
+
def build_metadata(repo, inventory_file_metadata)
|
51
|
+
repo_metadata = {}
|
52
|
+
repo_metadata["name"] = name(repo, inventory_file_metadata)
|
53
|
+
repo_metadata["description"] = description(repo, inventory_file_metadata)
|
54
|
+
usage_type = usage_type(repo, inventory_file_metadata)
|
55
|
+
repo_metadata["permissions"] = {
|
56
|
+
"licenses" => licenses(repo, inventory_file_metadata),
|
57
|
+
"usageType" => usage_type,
|
58
|
+
"exemptionText" => exemption_text(repo, inventory_file_metadata)
|
59
|
+
}
|
60
|
+
repo_metadata["tags"] = tags(repo, inventory_file_metadata)
|
61
|
+
repo_metadata["contact"] = { "email" => contact_email(repo, inventory_file_metadata) }
|
62
|
+
repo_metadata["repositoryURL"] = repository(repo, inventory_file_metadata)
|
63
|
+
repo_metadata["laborHours"] = labor_hours(repo, inventory_file_metadata)
|
64
|
+
organization = organization(repo, inventory_file_metadata)
|
65
|
+
repo_metadata["organization"] = organization unless organization.nil?
|
66
|
+
repo_metadata
|
67
|
+
end
|
68
|
+
|
64
69
|
# Checks if the repo has an inventory file. If so, loads its metadata.
|
65
70
|
def inventory_file(repo)
|
66
71
|
metadata = {}
|
@@ -104,44 +109,43 @@ module CodeInventory
|
|
104
109
|
repo[:name]
|
105
110
|
end
|
106
111
|
|
107
|
-
# Provides a value for the
|
112
|
+
# Provides a value for the permissions.licenses field.
|
108
113
|
# Order of precedence:
|
109
114
|
# 1. List of overrides
|
110
115
|
# 2. CodeInventory metadata file
|
111
|
-
# 3.
|
116
|
+
# 3. GitHub repository license
|
112
117
|
# 4. nil
|
113
|
-
def
|
114
|
-
return @overrides[:
|
115
|
-
return inventory_file_metadata["
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
# Provides a value for the openSourceProject field.
|
118
|
+
def licenses(repo, inventory_file_metadata)
|
119
|
+
return @overrides[:permissions][:licenses] if @overrides.dig(:permissions, :licenses)
|
120
|
+
return inventory_file_metadata["permissions"]["licenses"] if inventory_file_metadata.dig("permissions", "licenses")
|
121
|
+
require 'pp'
|
122
|
+
if repo[:license] && repo[:license][:url] && repo[:license][:spdx_id]
|
123
|
+
return [ { "URL": repo[:license][:url], "name": repo[:license][:spdx_id] } ]
|
124
|
+
end
|
125
|
+
nil
|
126
|
+
end
|
127
|
+
|
128
|
+
# Provides a value for the permissions.usageType field.
|
126
129
|
# Order of precedence:
|
127
130
|
# 1. List of overrides
|
128
131
|
# 2. CodeInventory metadata file
|
129
|
-
# 3. GitHub repository public/private status (public=
|
130
|
-
|
131
|
-
|
132
|
-
return
|
133
|
-
|
132
|
+
# 3. GitHub repository public/private status (public=openSource; private=governmentWideReuse)
|
133
|
+
# Note: exempt* values must be set either in overrides or the metadata file.
|
134
|
+
def usage_type(repo, inventory_file_metadata)
|
135
|
+
return @overrides[:permissions][:usageType] if @overrides.dig(:permissions, :usageType)
|
136
|
+
return inventory_file_metadata["permissions"]["usageType"] if inventory_file_metadata.dig("permissions", "usageType")
|
137
|
+
repo[:private] ? "governmentWideReuse" : "openSource"
|
134
138
|
end
|
135
139
|
|
136
|
-
# Provides a value for the
|
140
|
+
# Provides a value for the permissions.exemptionText field.
|
137
141
|
# Order of precedence:
|
138
142
|
# 1. List of overrides
|
139
143
|
# 2. CodeInventory metadata file
|
140
|
-
# 3.
|
141
|
-
def
|
142
|
-
return @overrides[:
|
143
|
-
return inventory_file_metadata["
|
144
|
-
|
144
|
+
# 3. nil
|
145
|
+
def exemption_text(repo, inventory_file_metadata)
|
146
|
+
return @overrides[:permissions][:exemptionText] if @overrides.dig(:permissions, :exemptionText)
|
147
|
+
return inventory_file_metadata["permissions"]["exemptionText"] if inventory_file_metadata.dig("permissions", "exemptionText")
|
148
|
+
nil
|
145
149
|
end
|
146
150
|
|
147
151
|
# Provides a value for the tags field.
|
@@ -169,17 +173,28 @@ module CodeInventory
|
|
169
173
|
org[:email]
|
170
174
|
end
|
171
175
|
|
172
|
-
# Provies a value for the
|
176
|
+
# Provies a value for the repositoryURL field.
|
173
177
|
# Order of precedence:
|
174
178
|
# 1. List of overrides
|
175
179
|
# 2. CodeInventory metadata file
|
176
180
|
# 3. If repo is public, GitHub repository URL, otherwise nil
|
177
181
|
def repository(repo, inventory_file_metadata)
|
178
|
-
return @overrides[:
|
179
|
-
return inventory_file_metadata["
|
182
|
+
return @overrides[:repositoryURL] if @overrides[:repositoryURL]
|
183
|
+
return inventory_file_metadata["repositoryURL"] if inventory_file_metadata["repositoryURL"]
|
180
184
|
repo[:private] ? nil : repo[:html_url]
|
181
185
|
end
|
182
186
|
|
187
|
+
# Provies a value for the laborHours field.
|
188
|
+
# Order of precedence:
|
189
|
+
# 1. List of overrides
|
190
|
+
# 2. CodeInventory metadata file
|
191
|
+
# 3. 0
|
192
|
+
def labor_hours(repo, inventory_file_metadata)
|
193
|
+
return @overrides[:laborHours] if @overrides[:laborHours]
|
194
|
+
return inventory_file_metadata["laborHours"] if inventory_file_metadata["laborHours"]
|
195
|
+
0
|
196
|
+
end
|
197
|
+
|
183
198
|
# Provies a value for the organization field (optional).
|
184
199
|
# Order of precedence:
|
185
200
|
# 1. List of overrides
|