Skip to content

Commit baff483

Browse files
committed
Old Checks support
It is correcting a small behavior of the GitHub API that does not return all checks and sometimes does not return the queued status in the first request. Signed-off-by: Rodrigo Nardi <rnardi@netdef.org>
1 parent 8b9894f commit baff483

2 files changed

Lines changed: 13 additions & 8 deletions

File tree

lib/github/build/skip_old_tests.rb

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,33 @@
1111
module Github
1212
module Build
1313
class SkipOldTests
14+
attr_reader :stages
15+
1416
def initialize(check_suite)
1517
@check_suite = check_suite
1618
@github = Github::Check.new(@check_suite)
17-
@stages = StageConfiguration.all.map(&:github_check_run_name)
19+
@stages = StageConfiguration.all.map { |config| "[CI] #{config.github_check_run_name}" }
1820
@logger = GithubLogger.instance.create('github_skip_old_tests.log', Logger::INFO)
1921
end
2022

2123
def skip_old_tests
22-
@github
23-
.check_runs_for_ref(@check_suite.pull_request.repository, @check_suite.commit_sha_ref)[:check_runs]
24-
&.each { |check_run| skipping_old_test(check_run) }
24+
%w[queued in_progress success failure queued].each do |status|
25+
@github
26+
.check_runs_for_ref(@check_suite.pull_request.repository,
27+
@check_suite.commit_sha_ref, status: status)[:check_runs]
28+
&.each { |check_run| skipping_old_test(check_run) }
29+
end
2530
end
2631

2732
private
2833

2934
def skipping_old_test(check_run)
30-
return if @stages.include?(check_run[:name]) or check_run[:app][:name] != 'NetDEF CI Hook'
35+
return if check_run[:app][:name] != 'NetDEF CI Hook' or @stages.include?(check_run[:name])
3136

3237
@logger.info("Skipping old test suite: #{check_run[:name]}")
38+
puts("Skipping old test suite: #{check_run[:name]}")
3339

3440
message = 'Old test suite, skipping...'
35-
@github.create(check_run[:name])
3641
@github.skipped(check_run[:id], { title: "#{check_run[:name]} summary", summary: message })
3742
end
3843
end

lib/github/check.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ def comment_reaction_thumb_down(repo, comment_id)
6060
accept: Octokit::Preview::PREVIEW_TYPES[:reactions])
6161
end
6262

63-
def check_runs_for_ref(repo, sha)
64-
@app.check_runs_for_ref(repo, sha)
63+
def check_runs_for_ref(repo, sha, status: 'queued')
64+
@app.check_runs_for_ref(repo, sha, status: status, accept: Octokit::Preview::PREVIEW_TYPES[:checks])
6565
end
6666

6767
def create(name)

0 commit comments

Comments
 (0)