Skip to content

Commit

Permalink
Merge pull request #1 from rikonor/master
Browse files Browse the repository at this point in the history
Pretty formatting
  • Loading branch information
jrmullins authored Sep 19, 2016
2 parents b99a5fb + 31a0f2f commit f246f5b
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/lita/github_pr_list/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Lita
module GithubPrList
VERSION = "0.3.3"
VERSION = "0.3.4"
end
end
95 changes: 95 additions & 0 deletions lib/lita/handlers/github_pr_list.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
require "lita"
require "json"
require "octokit"
require 'action_view'
include ActionView::Helpers::DateHelper

module Lita
module Handlers
Expand All @@ -22,6 +25,14 @@ def self.default_config(config)
help: { "pr list" => "List open pull requests for an organization." }
)

route(/^prs repo\s+(.+)/i, :list_repo_prs, command: true,
help: { "prs repo REPO" => "List open pull requests for a repo." }
)

route(/prs list/i, :list_org_prs, command: true,
help: { "prs list" => "List open pull requests for an organization." }
)

route(/pr add hooks/i, :add_pr_hooks, command: true,
help: { "pr add hooks" => "Add a pr web hook to every repo in your organization." }
)
Expand Down Expand Up @@ -51,6 +62,90 @@ def list_org_pr(response)
response.reply("#{message}#{requests.join("\n\n")}")
end

def list_repo_prs(response)
client = Octokit::Client.new(access_token: github_token, auto_paginate: true)

# Get a repo
org_name = github_organization
repo_name = response.args[1]
begin
repo = client.repo "#{org_name}/#{repo_name}"
rescue Octokit::NotFound
response.reply("Can't find #{repo_name}")
return
end

# Get the Issues/PRs
issues = client.issues(repo.id)

# it's a pull request if it has a pull_request field
pull_requests = issues.select do |issue|
issue.pull_request != nil
end

if pull_requests.length == 0
response.reply("No pull requests found for #{repo_name}")
return
end

# Build a msg
msgs = ["#{org_name}/#{repo_name} - #{repo.html_url}"]

msgs += pull_requests.map do |pr|
pr_title = pr.title
pr_owner = pr.user.login
pr_how_old = time_ago_in_words(pr.created_at) + ' ago'
"##{pr.number} #{pr.title} - (#{pr.user.login} - #{pr_how_old})"
end

msg = msgs.join "\n"

response.reply(msg)
end

def list_org_prs(response)
client = Octokit::Client.new(access_token: github_token, auto_paginate: true)

org_name = github_organization
team_id = team_id

repos = client.team_repositories team_id
if repos.length == 0
response.reply("No repos found for team #{team_id}")
return
end

repo_msgs = []

repos.each do |repo|
issues = client.issues(repo.id)

# it's a pull request if it has a pull_request field
pull_requests = issues.select do |issue|
issue.pull_request != nil
end

if pull_requests.length == 0
next
end

msgs = ["#{repo.name} - #{repo.html_url}"]

msgs += pull_requests.map do |pr|
pr_title = pr.title
pr_owner = pr.user.login
pr_how_old = time_ago_in_words(pr.created_at) + ' ago'
"##{pr.number} #{pr.title} - (#{pr.user.login} - #{pr_how_old})"
end

msg = msgs.join "\n"
repo_msgs << msg
end

outputMsg = repo_msgs.join "\n- - - - - - - - - -\n"
response.reply(outputMsg)
end

def alias_user(response)
Lita::GithubPrList::AliasUser.new({ response:response, redis: redis }).create_alias
end
Expand Down
1 change: 1 addition & 0 deletions lita-github_pr_list.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Gem::Specification.new do |spec|

spec.add_runtime_dependency "lita"
spec.add_runtime_dependency "octokit", "~> 4.0"
spec.add_runtime_dependency "actionview"

spec.add_development_dependency "bundler", "~> 1.6"
spec.add_development_dependency "rake"
Expand Down

0 comments on commit f246f5b

Please sign in to comment.