Skip to content

Commit

Permalink
Display '[DRAFT]' for draft pull requests
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonpenny committed Oct 23, 2019
1 parent f6a049d commit 9f0dc56
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lib/github-graphql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ def self.query(query, variables = nil)
req = Net::HTTP::Post.new(
GITHUB_URI,
"Content-Type" => "application/json",
"Authorization" => "Bearer #{GITHUB_ACCESS_TOKEN}"
"Authorization" => "Bearer #{GITHUB_ACCESS_TOKEN}",
"Accept" => "application/vnd.github.shadow-cat-preview+json", # for isDraft
)
if !variables.nil?
req.body = {query: query, variables: variables}.to_json
Expand Down Expand Up @@ -98,6 +99,7 @@ def self.get_pull_request_by_number(org, repo, pr_number)
headRefName
baseRefName
mergeable
isDraft
commits(last:1){
nodes{
commit{
Expand Down Expand Up @@ -178,6 +180,7 @@ def self.get_pull_requests_for_login(login, extra_filters)
headRefName
baseRefName
mergeable
isDraft
commits(last:1){
nodes{
commit{
Expand Down
5 changes: 4 additions & 1 deletion lib/github.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def self.pull_requests_for_login(login, extra_filters)

def self._pr_data(pr)
result = pr.select do |k, v|
%w(id url number headRefName baseRefName title createdAt).include? k
%w(id url number headRefName baseRefName title createdAt isDraft).include? k
end
result["owner"] = pr["repository"]["owner"]["login"]
result["authorId"] = pr["author"]["id"]
Expand Down Expand Up @@ -73,6 +73,9 @@ def self.request_review_on_pull_request(pr_id, user_ids)
def self.puts_multiple_pull_requests(prs, options = {})
prs.each_with_index do |pr, i|
url = "\e[36m#{pr["url"]}\e[0m"
if pr["isDraft"]
url = "\e[7m[DRAFT]\e[0m #{url}"
end
puts options[:prefix].nil? ? url : options[:prefix] + url
puts_pull_request(pr, options)

Expand Down
3 changes: 3 additions & 0 deletions pr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@
parsed = Github.parse_pull_request_url(ARGV[0])

pr = Github.pull_request_by_number(parsed["org"], parsed["repo"], parsed["pr_number"].to_i)
if pr["isDraft"]
puts "\e[7m[DRAFT]\e[0m"
end
Github.puts_pull_request(pr)
end

0 comments on commit 9f0dc56

Please sign in to comment.