Skip to content
Merged
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 lib/pyxis/checks/canary_release.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def initialize(build_id_to_promote)
'Canary release',
[
TucanaVersionMatch.new(info),
OpenIssues.new('release blocking', ['blocks-releases'])
OpenIssues.new('release blocking', field: 'Blocker', values: ['Release', 'Release: Canary'])
]
)
end
Expand Down
79 changes: 73 additions & 6 deletions lib/pyxis/checks/open_issues.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@ module Checks
class OpenIssues
include Check

attr_reader :check_context, :labels
Issue = Struct.new(:title, :html_url)

def initialize(check_context, labels)
PAGE_SIZE = 100

attr_reader :check_context, :field, :values

def initialize(check_context, field:, values:)
@check_context = check_context
@labels = labels
@field = field
@values = values
end

def perform_check!
Expand All @@ -31,9 +36,71 @@ def status_message
private

def issues
@issues ||= GithubClient.octokit.search_issues(
"org:#{GithubClient::ORGANIZATION_NAME} is:open is:issue #{labels.map { |l| "label:#{l}" }.join(' ')}"
).items
@issues ||= values
.flat_map { |value| fetch_issues_for(value) }
.uniq(&:html_url)
end

def fetch_issues_for(value)
issues = []
after = nil

loop do
page = fetch_page(value, after)
repositories = page&.dig(:nodes) || []

repositories.each do |repository|
(repository.dig(:issues, :nodes) || []).each do |issue|
issues << Issue.new(issue[:title], issue[:url])
end
end

page_info = page&.dig(:pageInfo) || {}
break unless page_info[:hasNextPage]

after = page_info[:endCursor]
end

issues
end

def fetch_page(value, after)
response = Pyxis::GlobalStatus.with_faraday_dry_run_bypass do
variables = { org: GithubClient::ORGANIZATION_NAME, field: field, value: value, after: after }
GithubClient.octokit.post(
'/graphql',
{ query: issues_query, variables: variables }.to_json
)
end

response.dig(:data, :organization, :repositories)
end

def issues_query
<<~GRAPHQL
query ($org: String!, $field: String!, $value: String!, $after: String) {
organization(login: $org) {
repositories(first: #{PAGE_SIZE}, after: $after) {
pageInfo {
hasNextPage
endCursor
}
nodes {
issues(
first: #{PAGE_SIZE},
states: OPEN,
filterBy: { issueFieldValues: [{ fieldName: $field, multiSelectOptionValues: [$value] }] }
) {
nodes {
title
url
}
}
}
}
}
}
GRAPHQL
end
end
end
Expand Down
3 changes: 2 additions & 1 deletion lib/pyxis/global_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ def dry_run?
end

def with_faraday_dry_run_bypass
previous = @faraday_dry_run_bypass
@faraday_dry_run_bypass = true
yield
ensure
@faraday_dry_run_bypass = false
@faraday_dry_run_bypass = previous
end

def faraday_dry_run_bypass?
Expand Down
Loading