-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support apps in non-root locations (#40)
* Allow passing in a filename transformer * attempt to pull out git wrapper * Easy PR comments (rename, types, comments) * comment * add some tests * Fix sorbet, increment version * Fix the last cop Ended up pulling some functions private to get around the max 100 lines cop.
- Loading branch information
1 parent
9c1b404
commit 1513888
Showing
11 changed files
with
353 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# typed: strict | ||
|
||
require 'code_ownership' | ||
require 'packs' | ||
|
||
# In order to support running danger-packwerk from a non-root filepath, we need | ||
# to wrap some git functions in filesystem wrappers: packwerk runs relative to | ||
# the rails app root, whereas git returns paths on the actual filesystem. | ||
module DangerPackwerk | ||
module Private | ||
class GitFilesystem < T::Struct | ||
extend T::Sig | ||
|
||
const :git, Danger::DangerfileGitPlugin | ||
const :root, String | ||
|
||
sig { returns(T::Array[{ after: String, before: String }]) } | ||
def renamed_files | ||
@git.renamed_files.map do |f| | ||
{ | ||
after: convert_file_from_filesystem(f[:after]), | ||
before: convert_file_from_filesystem(f[:before]) | ||
} | ||
end | ||
end | ||
|
||
sig { returns(T::Array[String]) } | ||
def modified_files | ||
convert_from_filesystem(@git.modified_files.to_a) | ||
end | ||
|
||
sig { returns(T::Array[String]) } | ||
def deleted_files | ||
convert_from_filesystem(@git.deleted_files.to_a) | ||
end | ||
|
||
sig { returns(T::Array[String]) } | ||
def added_files | ||
convert_from_filesystem(@git.added_files.to_a) | ||
end | ||
|
||
sig { params(filename_on_disk: String).returns(::Git::Diff::DiffFile) } | ||
def diff(filename_on_disk) | ||
@git.diff[filename_on_disk] | ||
end | ||
|
||
sig { params(path: String).returns(String) } | ||
def convert_to_filesystem(path) | ||
Pathname(@root).join(path).to_s | ||
end | ||
|
||
private | ||
|
||
sig { params(files: T::Array[String]).returns(T::Array[String]) } | ||
def convert_from_filesystem(files) | ||
files.map { |f| convert_file_from_filesystem(f) } | ||
end | ||
|
||
sig { params(file: String).returns(String) } | ||
def convert_file_from_filesystem(file) | ||
Pathname(file).relative_path_from(@root).to_s | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.