Skip to content

Commit

Permalink
Old Checks support
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
RodrigoMNardi committed Jul 3, 2024
1 parent 8b9894f commit baff483
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
17 changes: 11 additions & 6 deletions lib/github/build/skip_old_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,33 @@
module Github
module Build
class SkipOldTests
attr_reader :stages

def initialize(check_suite)
@check_suite = check_suite
@github = Github::Check.new(@check_suite)
@stages = StageConfiguration.all.map(&:github_check_run_name)
@stages = StageConfiguration.all.map { |config| "[CI] #{config.github_check_run_name}" }
@logger = GithubLogger.instance.create('github_skip_old_tests.log', Logger::INFO)
end

def skip_old_tests
@github
.check_runs_for_ref(@check_suite.pull_request.repository, @check_suite.commit_sha_ref)[:check_runs]
&.each { |check_run| skipping_old_test(check_run) }
%w[queued in_progress success failure queued].each do |status|
@github
.check_runs_for_ref(@check_suite.pull_request.repository,
@check_suite.commit_sha_ref, status: status)[:check_runs]
&.each { |check_run| skipping_old_test(check_run) }
end
end

private

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

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

message = 'Old test suite, skipping...'
@github.create(check_run[:name])
@github.skipped(check_run[:id], { title: "#{check_run[:name]} summary", summary: message })
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/github/check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ def comment_reaction_thumb_down(repo, comment_id)
accept: Octokit::Preview::PREVIEW_TYPES[:reactions])
end

def check_runs_for_ref(repo, sha)
@app.check_runs_for_ref(repo, sha)
def check_runs_for_ref(repo, sha, status: 'queued')
@app.check_runs_for_ref(repo, sha, status: status, accept: Octokit::Preview::PREVIEW_TYPES[:checks])
end

def create(name)
Expand Down

0 comments on commit baff483

Please sign in to comment.