From 4cb1e9bb57a8de36f2cdfd1982ea4a6bedcedff0 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Tue, 9 Jan 2018 09:47:47 -0500 Subject: [PATCH] writing github issues! --- Gopkg.lock | 57 +++++++++++++++++++++------- Gopkg.toml | 12 ++++++ cmd/version-scraper/main.go | 76 +++++++++++++++++++++++-------------- herald.go | 2 +- 4 files changed, 105 insertions(+), 42 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index 0556301..66c5ad1 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -110,6 +110,24 @@ revision = "32e4c1e6bc4e7d0d8451aa6b75200d19e37a536a" version = "v1.32.0" +[[projects]] + branch = "master" + name = "github.com/golang/protobuf" + packages = ["proto"] + revision = "1e59b77b52bf8e4b449a57e6f79f21226d571845" + +[[projects]] + branch = "master" + name = "github.com/google/go-github" + packages = ["github"] + revision = "218ecc238cf77bbaa2e16a54cada252ec87e7d6e" + +[[projects]] + branch = "master" + name = "github.com/google/go-querystring" + packages = ["query"] + revision = "53e6ce116135b80d037921a7fdd5138cf32d7a8a" + [[projects]] branch = "master" name = "github.com/hashicorp/go-cleanhttp" @@ -242,12 +260,6 @@ revision = "cb6bfca970f6908083f26f39a79009d608efd5cd" version = "v1.1" -[[projects]] - name = "github.com/mailgun/mailgun-go" - packages = ["."] - revision = "a4002e2df2e8ca2da6a6fbb4a72871b504e49f50" - version = "v1.1.0" - [[projects]] name = "github.com/mattn/go-colorable" packages = ["."] @@ -284,12 +296,6 @@ packages = ["."] revision = "a61a99592b77c9ba629d254a693acffaeb4b7e28" -[[projects]] - name = "github.com/pkg/errors" - packages = ["."] - revision = "645ef00459ed84a119197bfb8d8205042c6df63d" - version = "v0.8.0" - [[projects]] name = "github.com/russross/blackfriday" packages = ["."] @@ -344,17 +350,42 @@ branch = "master" name = "golang.org/x/net" packages = [ + "context", + "context/ctxhttp", "html", "html/atom" ] revision = "d866cfc389cec985d6fda2859936a575a55a3ab6" +[[projects]] + branch = "master" + name = "golang.org/x/oauth2" + packages = [ + ".", + "internal" + ] + revision = "30785a2c434e431ef7c507b54617d6a951d5f2b4" + [[projects]] branch = "master" name = "golang.org/x/sys" packages = ["unix"] revision = "b8f5ef32195cae6470b728e8ca677f0dbed1a004" +[[projects]] + name = "google.golang.org/appengine" + packages = [ + "internal", + "internal/base", + "internal/datastore", + "internal/log", + "internal/remote_api", + "internal/urlfetch", + "urlfetch" + ] + revision = "150dc57a1b433e64154302bdc40b6bb8aefa313a" + version = "v1.0.0" + [[projects]] branch = "v2" name = "gopkg.in/yaml.v2" @@ -364,6 +395,6 @@ [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "6e5a8becd6ad2bd1d88a01d4d74fe47f2ae22e490f78d3255b55ebd096004a39" + inputs-digest = "02581f9c20f3fa1daf2dacb89e71feb62298f452a06db6d3757799727700c73f" solver-name = "gps-cdcl" solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml index 494afe7..0f760aa 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -41,3 +41,15 @@ [[constraint]] name = "github.com/urfave/cli" version = "1.20.0" + +[[constraint]] + branch = "master" + name = "github.com/shurcooL/githubql" + +[[constraint]] + branch = "master" + name = "github.com/google/go-github" + +[[constraint]] + branch = "master" + name = "golang.org/x/oauth2" diff --git a/cmd/version-scraper/main.go b/cmd/version-scraper/main.go index 729d6b2..a932186 100644 --- a/cmd/version-scraper/main.go +++ b/cmd/version-scraper/main.go @@ -1,31 +1,49 @@ package main -import "github.com/heroku/herald" -import "github.com/fatih/color" -import "github.com/mailgun/mailgun-go" -import "time" -import "log" -import "fmt" -import "os" +import ( + "github.com/heroku/herald"; + "github.com/fatih/color"; + "github.com/google/go-github/github"; + "golang.org/x/oauth2" +) +import ( + "time"; + "log"; + "fmt"; + "os"; + "context" +) -var MAILGUN_DOMAIN = os.Getenv("MAILGUN_DOMAIN") -var MAILGUN_API_KEY = os.Getenv("MAILGUN_API_KEY") -var MAILGUN_PUBLIC_KEY = os.Getenv("MAILGUN_PUBLIC_KEY") +func open_issue(bp herald.Buildpack, target string) { + ctx := context.Background() + ts := oauth2.StaticTokenSource( + &oauth2.Token{AccessToken: os.Getenv("GITHUB_TOKEN")}, + ) + tc := oauth2.NewClient(ctx, ts) + client := github.NewClient(tc) -func send_email(to string, version string) { - - mg := mailgun.NewMailgun(MAILGUN_DOMAIN, MAILGUN_API_KEY, MAILGUN_PUBLIC_KEY) - message := mg.NewMessage( - to, - "Fancy subject!", - "Hello from Mailgun Go!", - "me@sandbox13d17507cb14496a9d97fe500600ac68.mailgun.org") - resp, id, err := mg.Send(message) - if err != nil { - log.Fatal(err) - } - fmt.Printf("ID: %s Resp: %s\n", id, resp) + title := fmt.Sprintf("New release (%s) available! (Herald System)", target) + body := fmt.Sprintf("This issue created programmatically and automatically by Heroku, on behalf of %s, the owner of the %s buildpack.", bp.Owner, bp.Name) + + newIssue := github.IssueRequest{ + Title: &title, + Body: &body, +// Labels: ["New Build Target"], + Assignee: &bp.Owner, + } + // list all repositories for the authenticated user + bp_name := fmt.Sprintf("heroku-buildpack-%s", bp.Name) + fmt.Println(bp_name) + + issue, _, err := client.Issues.Create(ctx, "heroku", bp_name, &newIssue) + if err != nil { + // do something + } +// _ = issue + fmt.Println(issue) + + fmt.Println(fmt.Sprintf("New issue created on %s buildpack on GitHub.", bp.Name)) } @@ -78,11 +96,13 @@ func main() { // Store the results in Redis. result, err := redis.Connection.Do("SETNX", key, value) - // The insert was successful (e.g. it didn't exist already) - if result.(int64) != int64(0) { - // TODO: Send a notification to the buildpack owner. - fmt.Println("Notifying %s about %s.", blue(bp.Owner), red(key)) -// send_email(bp.Owner, key) + // The insert was successful (e.g. it didn't exist already) + if result.(int64) != int64(0) { + // TODO: Send a notification to the buildpack owner. + fmt.Println("Notifying", blue(bp.Owner), "about", red(key), ".") + + // Open an issue on GitHub (work in progress). + open_issue(bp, key) } if err != nil { diff --git a/herald.go b/herald.go index 6269719..a926f2b 100644 --- a/herald.go +++ b/herald.go @@ -23,7 +23,7 @@ type OwnedBuildpack struct { } var BUILDPACKS = []OwnedBuildpack{ - {Name: "python", Owner: "kreitz@salesforce.com"}, + {Name: "python", Owner: "kennethreitz"}, {Name: "php", Owner: "kreitz@salesforce.com"}, {Name: "nodejs", Owner: "kreitz@salesforce.com"}, {Name: "ruby", Owner: "kreitz@salesforce.com"},