forked from ksol/stations-human-diff
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathentrypoint.sh
More file actions
executable file
·47 lines (36 loc) · 1.35 KB
/
entrypoint.sh
File metadata and controls
executable file
·47 lines (36 loc) · 1.35 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env ruby
lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require_relative "./lib/stations_human_diff"
SHD::Logger.info "Veryfing pull requests..."
SHD::EnvironmentChecker.check!
client = SHD::GithubClient.generate
repository = ENV.fetch("GITHUB_REPOSITORY")
pull_requests = client.pull_requests(repository, state: 'open')
pull_requests.each do |pull_request|
SHD::Logger.info "Veryfing pull request ##{pull_request['number']}..."
own_comments = SHD::GithubClient.own_comments(client: client, pull: pull_request)
last_comment = own_comments.last
commits = SHD::GithubClient.commits(client: client, pull: pull_request)
last_commit = commits.last
if last_comment.nil? || last_commit.commit.committer.date > last_comment.updated_at
SHD::GithubClient.remove_old_comments!(
client: client,
pull: pull_request,
comments: own_comments,
)
## Diffing stations..
report = SHD::DiffAnalyzer.new(
base: pull_request["base"],
head: pull_request["head"],
).run
formatted_report = SHD::ReportFormatter.run(report)
formatted_report = formatted_report.empty? ? 'No changes' : formatted_report
SHD::GithubClient.post_comment!(
client: client,
pull: pull_request,
body: formatted_report,
)
end
end
SHD::Logger.info "Done."