Created
June 9, 2017 15:50
-
-
Save mtsmfm/cadccf69ae823fc00833d9fed14cd0d4 to your computer and use it in GitHub Desktop.
Generate OPML file of your GitHub org members' public activity
This file contains hidden or 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
| # | |
| # Generate OPML file of your GitHub org members' public activity | |
| # You can import OPML file from https://feedly.com/i/cortex | |
| # | |
| # Usage: ruby main.rb $GITHUB_API_TOKEN $GITHUB_ORG_NAME | |
| # | |
| require 'net/http' | |
| require 'uri' | |
| require 'json' | |
| class Client | |
| ENDPOINT = URI.parse("https://api.github.com/graphql") | |
| def initialize(token) | |
| @token = token | |
| end | |
| def post(query, variables) | |
| https = Net::HTTP.new(ENDPOINT.host,ENDPOINT.port) | |
| https.use_ssl = true | |
| req = Net::HTTP::Post.new(ENDPOINT.path, 'Content-Type' =>'application/json', 'Authorization' => "bearer #{@token}") | |
| req.body = {query: query, variables: variables}.to_json | |
| res = https.request(req) | |
| JSON.parse(res.body, symbolize_names: true)[:data] | |
| end | |
| end | |
| query = <<-QUERY | |
| query ($org: String!, $after: String) { | |
| organization(login: $org) { | |
| members(first: 100, after: $after) { | |
| pageInfo { | |
| endCursor, hasNextPage | |
| } | |
| nodes { | |
| login | |
| url | |
| } | |
| } | |
| } | |
| } | |
| QUERY | |
| token, org = ARGV | |
| client = Client.new(token) | |
| result = client.post(query, org: org) | |
| members = result[:organization][:members][:nodes] | |
| while result[:organization][:members][:pageInfo][:hasNextPage] | |
| cursor = result[:organization][:members][:pageInfo][:endCursor] | |
| result = client.post(query, org: org, after: cursor) | |
| members += result[:organization][:members][:nodes] | |
| end | |
| File.open("list.opml", "w") do |file| | |
| file.puts <<-OPML | |
| <opml version="1.0"> | |
| <head> | |
| <title>#{org}</title> | |
| </head> | |
| <body> | |
| <outline text="#{org}" title="#{org}"> | |
| #{ | |
| members.map {|m| | |
| <<-OUTLINE | |
| <outline type="rss" text="#{m[:login]}" title="#{m[:login]}" xmlUrl="#{m[:url] + ".atom"}" htmlUrl="#{m[:url]}"/> | |
| OUTLINE | |
| }.join("\n") | |
| } | |
| </outline> | |
| </body> | |
| </opml> | |
| OPML | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment