Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimal fixes to try to comment on the PR itself #58

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ci.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ def get_limits(t_options, t_client, t_repo)
test_mode = !(ARGV[0] =~ /false/i)

$logger.info "Querying for updated branches"
b.query_branches
b.query_pull_requests
b.query_branches
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reordered the calls here. Each of these functions just do two independent things, and the order does not appear to matter at all, as they don't really check anything common between them. I moved the PRs check first though because now it collects a list of "internal" PRs with their branch and their PR number. Then when we call for branches next, we have that list ready, and can use that PR number.


did_daily_task = false

Expand Down
10 changes: 9 additions & 1 deletion lib/build.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ def initialize(token, repository, max_age)
@potential_builds = []
@max_age = max_age
github_check_rate_limit(@client.last_response.headers)
# Keep a mapping of branch name -> PR number for PRs which are based on non-fork branches
# This is only used for providing the GitHub status comment, nothing else
@branch_to_pr_number = {}
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just create an empty hash on the build class when it's constructed at the beginning of each CI pass.

end

def query_branches
Expand Down Expand Up @@ -66,7 +69,10 @@ def query_branches
login = branch_details.commit.author.login
end

@potential_builds << PotentialBuild.new(@client, @token, @repository, nil, b.commit.sha, b.name, login, nil, nil, nil, nil, nil)
associated_pr_num = @branch_to_pr_number.fetch(b.name, nil)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR check should have been called first, which would have populated this hash.

These lines simply:

  • Get the PR number for this branch, or nil
  • Create a new PotentialBuild instance as before
  • Call a method to assign the pr number to the potential build instance
  • Add the potential build to the list of potential builds

pb = PotentialBuild.new(@client, @token, @repository, nil, b.commit.sha, b.name, login, nil, nil, nil, nil, nil)
pb.assign_pr_num_for_comment(associated_pr_num)
@potential_builds << pb
$logger.info("Found a branch to add to potential_builds: #{b.name}")
else
$logger.info("Skipping potential build (#{b.name}), it hasn't been updated in #{days} days")
Expand Down Expand Up @@ -118,6 +124,8 @@ def query_pull_requests

if p.head.repo.full_name == p.base.repo.full_name
$logger.info("Skipping pull-request originating from head repo: #{p.number}")
@branch_to_pr_number[p.head.ref] = p.number
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR check should be called before the branch check. This function has always skipped "internal" PRs, where the branch lives inside NREL/EnergyPlus. Now it still does that...but before skipping, it grabs the branch name and PR number to keep them for later.

$logger.info(" ...but matching branch to pr_number: #{p.head.ref} => #{p.number}")
else
$logger.info("Found an external PR to add to potential_builds: #{p.number}")
@potential_builds << pb
Expand Down
9 changes: 8 additions & 1 deletion lib/potentialbuild.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ def initialize(client, token, repository, tag_name, commit_sha, branch_name, aut
@valgrind_counters_results = nil
@perf_counters_results = nil
@file_sizes = nil
@pr_num_for_comment = nil
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creates a nil member variable to store the PR number that should be used ONLY for posting the GitHub comment.

end

def assign_pr_num_for_comment(pr_num)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small worker function to update the member variable.

@pr_num_for_comment = pr_num
end

def set_as_baseline
Expand Down Expand Up @@ -936,7 +941,9 @@ def post_results(compiler, pending)
end

if !pending && @config.post_results_comment
if !@commit_sha.nil? && @repository == @config.repository
if !@pr_num_for_comment.nil?
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, so this section has nothing to do with the CI mechanics, just posting the GitHub comment. If the PR number member variable is present, we should go ahead and use that, otherwise fall back to the normal mode.

github_query(@client) { @client.add_comment(@config.repository, @pr_num_for_comment, github_document) }
elsif !@commit_sha.nil? && @repository == @config.repository
github_query(@client) { @client.create_commit_comment(@config.repository, @commit_sha, github_document) }
elsif !@pull_id.nil?
github_query(@client) { @client.add_comment(@config.repository, @pull_id, github_document) }
Expand Down
5 changes: 4 additions & 1 deletion spec/build_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,16 @@ def configuration
def pull_request?
@pr
end
def assign_pr_num_for_comment(pr_num)
@pr_num_for_comment = pr_num
end
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small worker function for the mock class.

end

describe 'Build Testing' do
context 'when calling query_branches' do
it 'should include branches that are valid and new' do
allow(Octokit::Client).to receive(:new).and_return(DummyClient2.new)
allow(PotentialBuild).to receive(:new).and_return(true)
allow(PotentialBuild).to receive(:new).and_return(DummyPotentialBuild.new('dummy'))
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modified mock return value.

b = Build.new('abcdef', 'spec/resources', 10)
expect(b.client.branches('', 1).length).to eql 8 # this is the absolute total
b.query_branches
Expand Down
Loading