Last active
April 29, 2020 14:12
-
-
Save jules2689/e19cc1dcb542e5a088945abc9f127d10 to your computer and use it in GitHub Desktop.
Geekbot tracking issue workflow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "optparse" | |
require 'bundler/inline' | |
gemfile do | |
source 'https://rubygems.org' | |
gem 'octokit', '4.18.0' | |
gem 'cli-kit', '3.3.0' | |
end | |
args = { manager: nil, geekbot_schedule: "TODO", geekbot_token: "TODO", github_token: "TODO", repo: "TODO" } | |
# Find our schedule responses and users who should have responded | |
require_relative "1_geekbot" | |
reports = {} | |
scheduled_users = [] | |
CLI::UI::Frame.open("Finding Tracking Issue Responses") do | |
reports = fetch_and_format_weekly_report(args[:geekbot_schedule], args[:geekbot_token]) | |
puts "Found #{reports.size} reports" | |
scheduled_users = fetch_scheduled_users(args[:geekbot_schedule], args[:geekbot_token]) | |
puts "Found #{scheduled_users.join(",")}" | |
end | |
# Format the responses into a GitHub Issue, assign our manager | |
CLI::UI::Frame.open("Opening issue on repo") do | |
client = Octokit::Client.new(access_token: args[:github_token]) | |
options = { labels: ['geekbot_tracking_issue'] } | |
options[:assignees] = [args[:manager]] if args[:manager] | |
body = "**Link**: [See Geekbot](https://geekbot.com/dashboard/standup/#{args[:geekbot_schedule]}/view)" | |
body << "\n\n---\n\n" | |
# Add reports | |
reports.each do |user, answers| | |
body << "### #{user}\n\n" | |
answers.each do |question, answer| | |
body << "**#{question}**\n\n#{answer}\n\n" | |
end | |
body << "\n\n---\n\n" | |
end | |
# Add in missing reports | |
missing = scheduled_users - reports.keys | |
unless missing.empty? | |
body << "### Missing Reports\n\n" | |
body << "- #{missing.join("\n- ")}" | |
end | |
client.create_issue(args[:repo], "[TRACKING ISSUE] Tracking Issue Summary from Geekbot", body, options) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/http' | |
require 'uri' | |
require 'json' | |
def fetch_scheduled_users(id, token) | |
uri = URI.parse("https://api.geekbot.io/v1/standups/#{id.to_i}") | |
request = Net::HTTP::Get.new(uri) | |
request["Authorization"] = token | |
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http| | |
http.request(request) | |
end | |
JSON.parse(response.body)["users"].map { |u| u["username"] } | |
end | |
def fetch_report(id, after, token) | |
query = URI.encode_www_form( | |
"standup_id" => id.to_i, | |
"after" => after | |
) | |
uri = URI.parse("https://api.geekbot.io/v1/reports?#{query}") | |
request = Net::HTTP::Get.new(uri) | |
request["Authorization"] = token | |
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http| | |
http.request(request) | |
end | |
JSON.parse(response.body) | |
end | |
# We want to take the report that we get and re-format to | |
# | |
# { username => { question => answer, question => answer,... } } | |
# | |
def fetch_and_format_weekly_report(id, token) | |
monday = Date.today | |
monday = monday - (monday.wday - 1) % 7 | |
report = fetch_report(id, monday.to_time.to_i, token) | |
report.each_with_object({}) do |user, acc| | |
acc[user["member"]["username"]] = user["questions"].map { |q| [q["question"], q["answer"]] }.to_h | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment