LoginSignup
4
4

More than 5 years have passed since last update.

githubのtrending repositoriesを取得するhubotスクリプト

Last updated at Posted at 2014-11-20

実行例

  • hubot g tr [since] <対象言語> と送信するとtrending repositoriesを一覧表示する
  • 任意パラメータ "since" について
    • d (デフォルト) - "daily"
    • w - "weekly"
    • m - "monthly"
me> hubot g tr go

hubot> https://github.com//bradfitz/http2 - HTTP/2 support for Go (in active development) (120 stars)
hubot> https://github.com//docker/docker - Docker - the open-source application container engine (48 stars)
hubot> https://github.com//syncthing/syncthing - Open Source Continuous File Synchronization (34 stars)
hubot> https://github.com//tylertreat/Comcast - Simulating shitty network connections so you can build better systems. (28 stars)
hubot> https://github.com//progrium/logspout - Log routing for Docker container logs (26 stars)
hubot> https://github.com//GoogleCloudPlatform/kubernetes - Container Cluster Manager (23 stars)
hubot> https://github.com//bitly/nsq - A realtime distributed messaging platform (24 stars)
hubot> https://github.com//cockroachdb/cockroach - A Scalable, Geo-Replicated, Transactional Datastore (21 stars)
hubot> https://github.com//derekparker/delve - Go debugger (18 stars)
hubot> https://github.com//flynn/flynn - A next generation open source platform as a service (PaaS) (14 stars)
hubot> https://github.com//gogits/gogs - Gogs(Go Git Service) is a painless self-hosted Git Service written in Go. (13 stars)
hubot> https://github.com//blevesearch/bleve - A modern text indexing library for go (11 stars)
hubot> https://github.com//smartystreets/mafsa - Package mafsa implements Minimal Acyclic Finite State Automata in Go, essentially a high-speed, memory-efficient, Unicode-friendly set of strings. (13 stars)
hubot> https://github.com//coreos/etcd - A highly-available key value store for shared configuration and service discovery (11 stars)
hubot> https://github.com//zettio/weave - The Docker Network (11 stars)
hubot> https://github.com//deis/deis - Your PaaS. Your Rules. (11 stars)
hubot> https://github.com//spf13/hugo - A Fast and Flexible Static Site Generator built with love by spf13 in GoLang (10 stars)
hubot> https://github.com//github/hub - hub helps you win at git. (11 stars)
hubot> https://github.com//sosedoff/pgweb - Web-based PostgreSQL database browser (11 stars)
hubot> https://github.com//influxdb/influxdb - Scalable datastore for metrics, events, and real-time analytics (9 stars)
hubot> https://github.com//youtube/vitess - vitess provides servers and tools which facilitate scaling of MySQL databases for large scale web services. (9 stars)
hubot> https://github.com//hashicorp/consul - Consul is a tool for service discovery, monitoring and configuration. (8 stars)
hubot> https://github.com//limetext/lime - Open source API-compatible alternative to Sublime Text (7 stars)
hubot> https://github.com//revel/revel - A high productivity, full-stack web framework for the Go language. (8 stars)
hubot> https://github.com//go-martini/martini - Classy web framework for Go (8 stars)

ソース

  • Gistはこちら
  • 依存モジュール×2
    • "request": "^2.42.0"
    • "cheerio": "^0.17.0"
request = require 'request'

module.exports = (robot) ->

  trim = (str) ->
    str.replace(/(^\s+)|(\s+$)/g, '').replace(/\r?\n/g, '')

  robot.respond /g tr(?:\s+)?((m|w|d)\s+)?([^\s]+)?/i, (msg) ->
    since = "daily"
    if msg.match[2]?
      switch msg.match[2]
        when "m"
          since = "monthly"
        when "w"
          since = "weekly"
    l = if msg.match[3]? then "&l=#{msg.match[3]}" else ""
    url = "https://github.com/trending?since=#{since}" + l

    options =
      url: url
      method: "GET"
    request options, (error, response, body) =>
      if error
        console.log "A problem was caused: #{error}"
        return

      status = response.statusCode
      if status == 200
        cheerio = require 'cheerio'
        $ = cheerio.load body
        m = ""
        $('ol.repo-list > li').each (i, e) ->
          $$ = cheerio.load e
          repo = "https://github.com/" + $$('h3.repo-list-name > a').attr('href')
          desc = trim $$('p.repo-list-description').text()
          meta = trim $$('p.repo-list-meta').text()
          star = trim meta.replace(/stars.+/g, '').split('•')[1]
          repoInfo = "#{repo} - #{desc} (#{star} stars)"
          m = m + "\n" + repoInfo
        msg.send m
      else
        console.log "Status(#{status}) is error: #{body}"

(cheerioの使い方に若干自信なし)

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4