gfp

package module
v0.0.0-...-ca1c4c4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 27, 2019 License: MIT Imports: 5 Imported by: 0

README

gfp (GitHub follower path)

Find a path of followers between two GitHub users.

Contents

Demo

Coming soon.

Installation

You should have Go installed and configured.

Install with go get:

$ go get -u -v github.com/kshvmdn/gfp/...
$ which gfp
$GOPATH/bin/gfp

Or, install directly via source:

$ git clone https://github.com/kshvmdn/gfp.git $GOPATH/src/github.com/kshvmdn/gfp
$ cd $_
$ make install && make
$ ./gfp

Setup

gfp uses the GitHub API, so you'll be required to register an application.

Head over to this page and generate a new token. Give it a name (anything works) and hit Generate token (no scope required).

Copy the token and export it as an environment variable.

$ export GITHUB_ACCESS_TOKEN=<access token>

Usage

gfp takes two GitHub usernames: an origin and a target.

The program starts at the origin user and recursively builds a directed graph based on who this user is following. This process is repeated until the target is reached (or the API rate limit is exceeded).

You can generally expect a different path each run (particularly for popular accounts), this is because the traversal order is unpredicatable (we're running everything concurrently, so it's not possible to control order).

gfp is built on top of a concurrent job queue with 6 workers by default. You can change this number with the -workers flag.

Log output is redirected to /dev/null, use the -show-log flag to disable this.

View the usage dialogue with the -help flag.

$ gfp -help
usage: gfp [options] origin target
  -show-log
        show log output
  -version
        print version and exit
  -workers int
        number of workers (default 6)
Examples
$ gfp kshvmdn torvalds
kshvmdn -> ... -> torvalds
$ gfp -show-log kshvmdn torvalds
2017/05/28 05:53:09 worker 1: kshvmdn
2017/05/28 05:53:10 worker 4: ...
2017/05/28 05:53:10 worker 5: ...
2017/05/28 05:53:10 worker 2: ...
2017/05/28 05:53:10 worker 6: ...
...
kshvmdn -> ... -> torvalds

Contribute

gfp is completely open source. Feel free to open an issue or a pull request.

Prior to submitting work, please ensure your changes comply with Golint, test this with make lint.

Todo
  • Find shortest path, might be impossible to find the shortest path (due to rate limits), but it is possible to do something like: run until we find x paths and return the shortest of those x.
  • I think we can do some cool stuff with the resultant graph. Perhaps add a flag to export it once the computation is complete (maybe do something with awalterschulze/gographviz?).
  • Better-handle rate limit (perhaps it's possible to pause execution and wait until more requests are available?).
  • Handle the case where we run out of users to traverse and haven't found the target (also, similar: origin user is following 0 people).

Credits

License

gfp source code is released under the MIT license.

Documentation

Index

Constants

View Source
const TokenName = "GITHUB_ACCESS_TOKEN"

TokenName holds the environment variable name for the GitHub access token.

View Source
const Version = "0.1.0"

Version holds the current application version.

Variables

This section is empty.

Functions

func GetClient

func GetClient(accessToken string) *github.Client

GetClient creates and returns a new *github.Client. Expects accessToken to be a valid GitHub personal access token.

Types

type UserNode

type UserNode struct {
	Login  string
	Parent *UserNode
	Page   int
}

UserNode represents a single node in the follower graph. The Parent field holds the user that discovered this node.

func Run

func Run(start, end string, nWorkers int, c *github.Client) *UserNode

Run starts the dispatcher and pushes a new request for the root user onto the queue. Returns the *UserNode that is received on the done channel.

func (*UserNode) String

func (node *UserNode) String() string

Directories

Path Synopsis
cmd
gfp command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL