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

add action to check project changes and provide feedback on each PR #1693

Merged
merged 13 commits into from
Nov 14, 2019
Prev Previous commit
Next Next commit
can we query for PR comments?
  • Loading branch information
shiftkey committed Nov 14, 2019
commit 2b1b3522e853876cc249dbb71908234f203fffee
67 changes: 48 additions & 19 deletions .github/actions/project-analyzer/project_analyzer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
require 'up_for_grabs_tooling'

root = ENV['GITHUB_WORKSPACE']
repo = ENV['GITHUB_REPOSITORY']

schema = Pathname.new("#{root}/schema.json")
schemer = JSONSchemer.schema(schema)
Expand Down Expand Up @@ -133,25 +134,51 @@ def validate_project(project, schemer)
Project.new(f, full_path)
end

# TODO: delete earlier issue comment if made by same author (login == "github-actions" && __typename == "Bot")
# and starts with the magic preamble <!-- PULL REQUEST ANALYZER GITHUB ACTION -->

# query ($owner: String!, $name: String!, $number: Int!) {
# repository(owner: $owner, name: $name) {
# pullRequest(number: $number) {
# comments(first: 50) {
# nodes {
# id
# body
# author {
# login
# __typename
# }
# }
# }
# }
# }
# }
http = GraphQL::Client::HTTP.new('https://api.github.com/graphql') do
def headers(_context)
# Optionally set any HTTP headers
{
"User-Agent": 'up-for-grabs-graphql-label-queries',
"Authorization": "bearer #{ENV['GITHUB_TOKEN']}"
}
end
end

schema = GraphQL::Client.load_schema(http)

client = GraphQL::Client.new(schema: schema, execute: http)

PullRequestComments = client.parse <<-'GRAPHQL'
query ($owner: String!, $name: String!, $number: Int!) {
repository(owner: $owner, name: $name) {
pullRequest(number: $number) {
comments(first: 50) {
nodes {
id
body
author {
login
__typename
}
}
}
}
}
}
GRAPHQL

owner, name = repo.split('/')

variables = { owner: owner, name: name, number: pull_request_number }

result = client.query(PullRequestComments, variables: variables)

comments = result.data.repository.pull_request.comments

if comments.nodes.any?
# TODO: delete earlier issue comment if made by same author (login == "github-actions" && __typename == "Bot")
# and starts with the magic preamble <!-- PULL REQUEST ANALYZER GITHUB ACTION -->
end

markdown_body = "<!-- PULL REQUEST ANALYZER GITHUB ACTION -->

Expand All @@ -176,4 +203,6 @@ def validate_project(project, schemer)

markdown_body += messages.join("\n\n")

# add comment to PR

puts markdown_body