-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 = {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
|
||
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") | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
@@ -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? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) } | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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')) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
There was a problem hiding this comment.
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.