From 0d973127c732cc967e33b82c69a18b8379da786c Mon Sep 17 00:00:00 2001 From: Gregory Eremin Date: Thu, 5 Mar 2015 02:14:11 +0700 Subject: [PATCH] Cleanup old code --- config.example.json | 4 -- db/common.go | 2 + steward/backend/mysql/storage.go | 85 ----------------------- steward/config.go | 8 --- steward/contribution.go | 12 ---- steward/github/github.go | 113 ------------------------------- 6 files changed, 2 insertions(+), 222 deletions(-) delete mode 100644 config.example.json delete mode 100644 steward/backend/mysql/storage.go delete mode 100644 steward/config.go delete mode 100644 steward/contribution.go delete mode 100644 steward/github/github.go diff --git a/config.example.json b/config.example.json deleted file mode 100644 index fc9c150..0000000 --- a/config.example.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "github_client_id": "XXXXXXXXXXXXXXXXXXXX", - "github_secret": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" -} diff --git a/db/common.go b/db/common.go index 742ee70..d0312a4 100644 --- a/db/common.go +++ b/db/common.go @@ -2,6 +2,8 @@ package db import ( "database/sql" + + _ "github.com/go-sql-driver/mysql" ) var ( diff --git a/steward/backend/mysql/storage.go b/steward/backend/mysql/storage.go deleted file mode 100644 index b5e54af..0000000 --- a/steward/backend/mysql/storage.go +++ /dev/null @@ -1,85 +0,0 @@ -package mysql - -import ( - "database/sql" - "strconv" - - _ "github.com/go-sql-driver/mysql" - "github.com/localhots/steward/steward" -) - -type ( - Config struct { - Hostname string - Port int - Username string - Password string - Database string - } - Storage struct { - db *sql.DB - importStmt *sql.Stmt - } -) - -const ( - importQuery = "" + - "replace into contributions (author, repo, week, commits, additions, deletions) " + - "values (?, ?, ?, ?, ?, ?)" -) - -func New(c *Config) *Storage { - var ( - s = &Storage{} - err error - ) - - if s.db, err = sql.Open("mysql", c.URI()); err != nil { - panic(err) - } - if s.importStmt, err = s.db.Prepare(importQuery); err != nil { - panic(err) - } - - return s -} - -func (s *Storage) ImportContributions(contrib []*steward.Contribution) { - for _, c := range contrib { - if _, err := s.importStmt.Exec( - c.Author, - c.Repo, - c.Week, - c.Commits, - c.Additions, - c.Deletions, - ); err != nil { - panic(err) - } - } -} - -func (c *Config) URI() (uri string) { - if c.Username == "" && c.Password != "" { - panic("Password is set but no username specified") - } - - if c.Username != "" { - uri += c.Username - } - if c.Password != "" { - uri += ":" + c.Password - } - if c.Username != "" { - uri += "@" - } - if c.Hostname != "" { - uri += c.Hostname - } - if c.Port != 0 { - uri += ":" + strconv.Itoa(c.Port) - } - uri += "/" + c.Database + "?parseTime=true" - - return -} diff --git a/steward/config.go b/steward/config.go deleted file mode 100644 index 4eab40d..0000000 --- a/steward/config.go +++ /dev/null @@ -1,8 +0,0 @@ -package steward - -type ( - Config struct { - GithubClientID string - GithubSecret string - } -) diff --git a/steward/contribution.go b/steward/contribution.go deleted file mode 100644 index 2cff8cf..0000000 --- a/steward/contribution.go +++ /dev/null @@ -1,12 +0,0 @@ -package steward - -type ( - Contribution struct { - Author string - Repo string - Week int64 - Commits int - Additions int - Deletions int - } -) diff --git a/steward/github/github.go b/steward/github/github.go deleted file mode 100644 index 4a1b8e0..0000000 --- a/steward/github/github.go +++ /dev/null @@ -1,113 +0,0 @@ -package github - -import ( - "fmt" - "time" - - "code.google.com/p/goauth2/oauth" - gh "github.com/google/go-github/github" - "github.com/localhots/steward/steward" -) - -const ( - DefaultPerPage = 30 -) - -type ( - GithubClient struct { - owner string - client *gh.Client - limit int - remaining int - limitEnds time.Time - } -) - -func New(clientID, clientSecret, owner string) *GithubClient { - // Auth here - return nil -} - -// Temp method -func NewClient(token, owner string) *GithubClient { - trans := &oauth.Transport{ - Token: &oauth.Token{AccessToken: token}, - } - - return &GithubClient{ - owner: owner, - client: gh.NewClient(trans.Client()), - } -} - -func (c *GithubClient) ListRepos() []string { - var ( - names = []string{} - opt = &gh.RepositoryListByOrgOptions{ - ListOptions: gh.ListOptions{}, - } - ) - - for { - opt.Page++ - repos, resp, err := c.client.Repositories.ListByOrg(c.owner, opt) - c.saveResponseMeta(resp) - if err != nil { - panic(err) - } - - for _, repo := range repos { - names = append(names, *repo.Name) - } - - if len(repos) < DefaultPerPage { - break - } - } - - return names -} - -func (c *GithubClient) ListContributors(repo string) []*steward.Contribution { - var ( - contrib = []*steward.Contribution{} - ) - - cslist, resp, err := c.client.Repositories.ListContributorsStats(c.owner, repo) - c.saveResponseMeta(resp) - if err != nil { - if err.Error() == "EOF" { - // Empty repository, not an actual error - return contrib - } - - fmt.Println("Error loading contributors stats for repo", repo) - fmt.Println(err.Error()) - return contrib - } - - for _, cs := range cslist { - for _, week := range cs.Weeks { - if *week.Commits == 0 { - continue - } - - contrib = append(contrib, &steward.Contribution{ - Author: *cs.Author.Login, - Repo: repo, - Week: week.Week.Time.Unix(), - Commits: *week.Commits, - Additions: *week.Additions, - Deletions: *week.Deletions, - }) - } - } - - return contrib -} - -func (c *GithubClient) saveResponseMeta(res *gh.Response) { - c.limit = res.Limit - c.remaining = res.Remaining - c.limitEnds = res.Reset.Time -}