Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ on:

jobs:
call-workflow-from-shared-config:
permissions:
contents: write
uses: rubyatscale/shared-config/.github/workflows/cd.yml@main
secrets: inherit
3 changes: 3 additions & 0 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ on:
- cron: '0 0 * * *'
jobs:
call-workflow-from-shared-config:
permissions:
issues: write
pull-requests: write
uses: rubyatscale/shared-config/.github/workflows/stale.yml@main
2 changes: 2 additions & 0 deletions .github/workflows/triage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ on:
- opened
jobs:
call-workflow-from-shared-config:
permissions:
issues: write
uses: rubyatscale/shared-config/.github/workflows/triage.yml@main
11 changes: 9 additions & 2 deletions lib/packwerk/privacy/checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Checker

VIOLATION_TYPE = 'privacy'
PUBLICIZED_SIGIL = 'pack_public: true'
PUBLICIZED_SIGIL_REGEX = /#.*pack_public:\s*true/
PUBLICIZED_SIGIL_REGEX = /pack_public:\s*true/
@publicized_locations = {} #: Hash[String, bool]

class << self
Expand All @@ -35,7 +35,14 @@ def check_for_publicized_sigil(location)

#: (Array[String] lines) -> bool
def content_contains_sigil?(lines)
lines.first(5).any? { |l| l =~ PUBLICIZED_SIGIL_REGEX }
lines.first(5).any? do |l|
# Only the sigil's existence matters, so it is enough to look for it after the
# line's first `#`. Searching from there keeps the scan linear in the length of
# the line, where matching `/#.*pack_public:\s*true/` would retry the `.*` scan
# once per `#` in the line.
comment_start = l.index('#')
!comment_start.nil? && PUBLICIZED_SIGIL_REGEX.match?(l, comment_start + 1)
end
end
end

Expand Down
3 changes: 3 additions & 0 deletions test/unit/privacy/checker_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,16 @@ class CheckerTest < Minitest::Test
['line 1', 'line 2', 'line 3', 'line 4', '# pack_public: true'],
['#pack_public:true', 'line 2', 'line 3'],
['line 1', '# pack_public: true'],
['# typed: strict # pack_public: true'],
]
content_with_invalid_or_missing_sigils = [
['line 1', 'line 2', 'line 3', 'line 4', 'line 5', '# pack_public: true'],
['#pulic_api:', 'line 2', 'line 3'],
['line 1', '# pack_public: false'],
['# pack_public: false', 'line 2', 'line 3'],
['line 1', 'EOF'],
['pack_public: true'],
['pack_public: true # not the sigil'],
]
assert(content_with_valid_sigils.all? { |content| Privacy::Checker.content_contains_sigil?(content) })
assert(content_with_invalid_or_missing_sigils.none? { |content| Privacy::Checker.content_contains_sigil?(content) })
Expand Down