forked from Homebrew/homebrew-cask
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchanged_files.rb
31 lines (26 loc) · 1.41 KB
/
changed_files.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# frozen_string_literal: true
module ChangedFiles
def changed_files
commit_range_start = system_command!("git", args: ["rev-parse", "origin"], chdir: path).stdout.chomp
commit_range_end = system_command!("git", args: ["rev-parse", "HEAD"], chdir: path).stdout.chomp
commit_range = "#{commit_range_start}...#{commit_range_end}"
modified_files = system_command!(
"git", args: ["diff", "--name-only", "--diff-filter=AMR", commit_range], chdir: path
).stdout.split("\n").map { |path| Pathname(path) }
added_files = system_command!(
"git", args: ["diff", "--name-only", "--diff-filter=A", commit_range], chdir: path
).stdout.split("\n").map { |path| Pathname(path) }
modified_ruby_files = modified_files.select { |path| path.extname == ".rb" }
modified_command_files = modified_files.select { |path| path.ascend.to_a.last.to_s == "cmd" }
modified_github_actions_files = modified_files.select { |path| path.to_s.start_with?(".github/actions/") }
modified_cask_files = modified_files.select { |path| cask_file?(path) }
{
modified_files: modified_files,
added_files: added_files,
modified_ruby_files: modified_ruby_files,
modified_command_files: modified_command_files,
modified_github_actions_files: modified_github_actions_files,
modified_cask_files: modified_cask_files,
}
end
end