Skip to content

Commit 615eca2

Browse files
dafyddcrosbyfacebook-github-bot
authored andcommitted
rule+report to cross-reference cookbook to maintainer
Summary: A common problem is cross-referencing cookbooks to maintainers, this rule to scrape out the cookbook name and the maintainer email makes this process easy. Differential Revision: D65182550 fbshipit-source-id: af538f7caa60c0b16e0f0e1f97aa83b2d2e28f3f
1 parent 27faf84 commit 615eca2

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright (c) 2022-present, Meta, Inc.
2+
# All rights reserved.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
description 'Cross-reference the cookbook name to the maintainer_email in a CSV fashion'
16+
needs_rules ['MetadatarbAttributeLiterals']
17+
18+
def to_a
19+
buffer = Set.new
20+
@kb.metadatarbs.each do |_, metadata|
21+
cb = metadata['MetadatarbAttributeLiterals']
22+
buffer << "#{cb[:name]},#{cb[:maintainer_email]}"
23+
end
24+
buffer.sort.to_a
25+
end
26+
27+
def output
28+
to_a
29+
end
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright (c) 2022-present, Meta, Inc.
2+
# All rights reserved.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
description 'Scrapes metadata attribute string literals'
16+
keys ['metadatarb']
17+
18+
# TODO Search *all* possible attributes
19+
20+
def_node_search :attribute_literals, '`(send nil? ${:name :maintainer :maintainer_email} (str $_))'
21+
22+
def output
23+
attribute_literals(@metadata['ast'])&.to_h
24+
end
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Copyright (c) 2022-present, Meta, Inc.
2+
# All rights reserved.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
require_relative './helper'
16+
17+
describe Bookworm::InferRules::MetadatarbAttributeLiterals do
18+
let(:ast) do
19+
generate_ast(<<~RUBY)
20+
name "fb_example"
21+
maintainer "Dave"
22+
maintainer_email "dave@example.org"
23+
RUBY
24+
end
25+
it 'captures the metadata literals' do
26+
rule = described_class.new({ 'ast' => ast })
27+
expect(rule.output).to eq(
28+
{
29+
:name => 'fb_example',
30+
:maintainer => 'Dave',
31+
:maintainer_email => 'dave@example.org',
32+
},
33+
)
34+
end
35+
end

0 commit comments

Comments
 (0)