Skip to content

Commit

Permalink
Merge pull request #65 from RodrigoMNardi/github/rerun/partial_comment
Browse files Browse the repository at this point in the history
New command - ci:retry
  • Loading branch information
RodrigoMNardi authored May 18, 2024
2 parents ef38182 + cd372a0 commit 13204c6
Show file tree
Hide file tree
Showing 18 changed files with 498 additions and 159 deletions.
16 changes: 12 additions & 4 deletions app/github_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,23 @@ def sinatra_logger_level

halt 200, 'OK' unless %w[rerequested].include? payload['action'].downcase

re_run = Github::Retry.new(payload, logger_level: GithubApp.sinatra_logger_level)
re_run = Github::Retry::Command.new(payload, logger_level: GithubApp.sinatra_logger_level)
halt re_run.start
when 'installation'
logger.debug '>>> Received a new installation policy'
halt 202, 'Updated'
when 'issue_comment'
logger.debug '>>> Received a new issue comment'

halt Github::ReRun::Comment.new(payload, logger_level: GithubApp.sinatra_logger_level).start
halt 404, 'Action not found' if payload.nil? or payload['comment'].nil?

case payload.dig('comment', 'body')
when /ci:retry/
halt Github::Retry::Comment.new(payload, logger_level: GithubApp.sinatra_logger_level).start
when /ci:rerun/
halt Github::ReRun::Comment.new(payload, logger_level: GithubApp.sinatra_logger_level).start
else
logger.debug '>>> Just a comment'
halt 200, 'Just a comment'
end
when 'check_suite'
logger.debug '>>> Received a new check_suite command'
halt 200, 'OK' unless payload['action'].downcase.match?('rerequested')
Expand Down
1 change: 1 addition & 0 deletions lib/github/build/retry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def enqueued_stages

stage = Stage.find_by(check_suite: @check_suite, name: bamboo_stage.github_check_run_name)

next if stage.nil?
next if stage.success?

url = "https://ci1.netdef.org/browse/#{stage.check_suite.bamboo_ci_ref}"
Expand Down
11 changes: 10 additions & 1 deletion lib/github/build/summary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def initialize(job, logger_level: Logger::INFO, agent: 'Github')
@loggers << GithubLogger.instance.create(filename, logger_level)
end

@loggers << GithubLogger.instance.create("pr#{@check_suite.pull_request.github_pr_id}.log", logger_level)
@pr_log = GithubLogger.instance.create("pr#{@check_suite.pull_request.github_pr_id}.log", logger_level)
end

def build_summary
Expand All @@ -36,6 +36,8 @@ def build_summary
check_and_update_github_ref(current_stage)

logger(Logger::INFO, "build_summary: #{current_stage.inspect}")
msg = "Github::Build::Summary - #{@job.inspect}, #{current_stage.inspect}, bamboo info: #{bamboo_info}"
@pr_log.info(msg)

# Update current stage
update_summary(current_stage)
Expand All @@ -52,6 +54,11 @@ def build_summary

private

def bamboo_info
finish = Github::PlanExecution::Finished.new({ 'bamboo_ref' => @check_suite.bamboo_ci_ref })
finish.fetch_build_status
end

def check_and_update_github_ref(current_stage)
current_refs = @github.fetch_check_runs

Expand All @@ -73,6 +80,8 @@ def must_update_previous_stage(current_stage)

return if previous_stage.nil? or !(previous_stage.in_progress? or previous_stage.queued?)

logger(Logger::INFO, "must_update_previous_stage: #{previous_stage.inspect}")

finished_stage_summary(previous_stage)
end

Expand Down
4 changes: 4 additions & 0 deletions lib/github/check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ def comment_reaction_thumb_up(repo, comment_id)
@app.create_issue_comment_reaction(repo, comment_id, '+1')
end

def comment_reaction_thumb_down(repo, comment_id)
@app.create_issue_comment_reaction(repo, comment_id, '-1')
end

def create(name)
@app.create_check_run(
@check_suite.pull_request.repository,
Expand Down
28 changes: 14 additions & 14 deletions lib/github/plan_execution/finished.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,8 @@ def finished
[200, 'Finished']
end

private

# This method will move all tests that no longer exist in BambooCI to the skipped state,
# because there are no executions for them.
def clear_deleted_jobs
github_check = Github::Check.new(@check_suite)

@check_suite.ci_jobs.where(status: %w[queued in_progress]).each do |ci_job|
ci_job.skipped(github_check)
end
def fetch_build_status
get_request(URI("https://127.0.0.1/rest/api/latest/result/status/#{@check_suite.bamboo_ci_ref}"))
end

# Checks if CI still running
Expand All @@ -63,6 +55,18 @@ def in_progress?(build_status)
true
end

private

# This method will move all tests that no longer exist in BambooCI to the skipped state,
# because there are no executions for them.
def clear_deleted_jobs
github_check = Github::Check.new(@check_suite)

@check_suite.ci_jobs.where(status: %w[queued in_progress]).each do |ci_job|
ci_job.skipped(github_check)
end
end

def ci_stopped?(build_status)
build_status.key?('message') and !build_status.key?('finished')
end
Expand Down Expand Up @@ -151,10 +155,6 @@ def check_stages
def fetch_ci_execution
@result = get_status(@check_suite.bamboo_ci_ref)
end

def fetch_build_status
get_request(URI("https://127.0.0.1/rest/api/latest/result/status/#{@check_suite.bamboo_ci_ref}"))
end
end
end
end
4 changes: 1 addition & 3 deletions lib/github/re_run/comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,7 @@ def sha256
end

def action?
return false if action.nil?

action.downcase.match? 'ci:rerun' and @payload['action'] == 'created'
action.to_s.downcase.match? 'ci:rerun' and @payload['action'] == 'created'
end
end
end
Expand Down
122 changes: 0 additions & 122 deletions lib/github/retry.rb

This file was deleted.

Loading

0 comments on commit 13204c6

Please sign in to comment.