<commit_before>package heroku

import (
	"encoding/json"
	"fmt"
	"io"
	"net/http"

	"golang.org/x/net/context"

	"github.com/remind101/empire"
	"github.com/remind101/empire/pkg/headerutil"
	"github.com/remind101/empire/pkg/heroku"
	"github.com/remind101/empire/server/auth"
	"github.com/remind101/pkg/httpx"
)

// The Accept header that controls the api version. See
// https://devcenter.heroku.com/articles/platform-api-reference#clients
const AcceptHeader = "application/vnd.heroku+json; version=3"

// New creates the API routes and returns a new http.Handler to serve them.
func New(e *empire.Empire, authenticator auth.Authenticator) httpx.Handler {
	r := httpx.NewRouter()

	// Apps
	r.Handle("/apps", &GetApps{e}).Methods("GET")                  // hk apps
	r.Handle("/apps/{app}", &GetAppInfo{e}).Methods("GET")         // hk info
	r.Handle("/apps/{app}", &DeleteApp{e}).Methods("DELETE")       // hk destroy
	r.Handle("/apps/{app}", &PatchApp{e}).Methods("PATCH")         // hk destroy
	r.Handle("/apps/{app}/deploys", &DeployApp{e}).Methods("POST") // Deploy an image to an app
	r.Handle("/apps", &PostApps{e}).Methods("POST")                // hk create
	r.Handle("/organizations/apps", &PostApps{e}).Methods("POST")  // hk create

	// Domains
	r.Handle("/apps/{app}/domains", &GetDomains{e}).Methods("GET")                 // hk domains
	r.Handle("/apps/{app}/domains", &PostDomains{e}).Methods("POST")               // hk domain-add
	r.Handle("/apps/{app}/domains/{hostname}", &DeleteDomain{e}).Methods("DELETE") // hk domain-remove

	// Deploys
	r.Handle("/deploys", &PostDeploys{e}).Methods("POST") // Deploy an app

	// Releases
	r.Handle("/apps/{app}/releases", &GetReleases{e}).Methods("GET")          // hk releases
	r.Handle("/apps/{app}/releases/{version}", &GetRelease{e}).Methods("GET") // hk release-info
	r.Handle("/apps/{app}/releases", &PostReleases{e}).Methods("POST")        // hk rollback

	// Configs
	r.Handle("/apps/{app}/config-vars", &GetConfigs{e}).Methods("GET")     // hk env, hk get
	r.Handle("/apps/{app}/config-vars", &PatchConfigs{e}).Methods("PATCH") // hk set, hk unset

	// Processes
	r.Handle("/apps/{app}/dynos", &GetProcesses{e}).Methods("GET")                     // hk dynos
	r.Handle("/apps/{app}/dynos", &PostProcess{e}).Methods("POST")                     // hk run
	r.Handle("/apps/{app}/dynos", &DeleteProcesses{e}).Methods("DELETE")               // hk restart
	r.Handle("/apps/{app}/dynos/{ptype}.{pid}", &DeleteProcesses{e}).Methods("DELETE") // hk restart web.1
	r.Handle("/apps/{app}/dynos/{pid}", &DeleteProcesses{e}).Methods("DELETE")         // hk restart web

	// Formations
	r.Handle("/apps/{app}/formation", &GetFormation{e}).Methods("GET")     // hk scale -l
	r.Handle("/apps/{app}/formation", &PatchFormation{e}).Methods("PATCH") // hk scale

	// OAuth
	r.Handle("/oauth/authorizations", &PostAuthorizations{e}).Methods("POST")

	// SSL
	sslRemoved := errHandler(ErrSSLRemoved)
	r.Handle("/apps/{app}/ssl-endpoints", sslRemoved).Methods("GET")           // hk ssl
	r.Handle("/apps/{app}/ssl-endpoints", sslRemoved).Methods("POST")          // hk ssl-cert-add
	r.Handle("/apps/{app}/ssl-endpoints/{cert}", sslRemoved).Methods("PATCH")  // hk ssl-cert-add, hk ssl-cert-rollback
	r.Handle("/apps/{app}/ssl-endpoints/{cert}", sslRemoved).Methods("DELETE") // hk ssl-destroy

	// Logs
	r.Handle("/apps/{app}/log-sessions", &PostLogs{e}).Methods("POST") // hk log

	errorHandler := func(err error, w http.ResponseWriter, r *http.Request) {
		Error(w, err, http.StatusInternalServerError)
	}

	api := Authenticate(r, authenticator)

	return httpx.HandlerFunc(func(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
		err := api.ServeHTTPContext(ctx, w, r)
		if err != nil {
			errorHandler(err, w, r)
		}<commit_msg>Report errors from heroku api.<commit_after>package heroku

import (
	"encoding/json"
	"fmt"
	"io"
	"net/http"

	"golang.org/x/net/context"

	"github.com/remind101/empire"
	"github.com/remind101/empire/pkg/headerutil"
	"github.com/remind101/empire/pkg/heroku"
	"github.com/remind101/empire/server/auth"
	"github.com/remind101/pkg/httpx"
	"github.com/remind101/pkg/reporter"
)

// The Accept header that controls the api version. See
// https://devcenter.heroku.com/articles/platform-api-reference#clients
const AcceptHeader = "application/vnd.heroku+json; version=3"

// New creates the API routes and returns a new http.Handler to serve them.
func New(e *empire.Empire, authenticator auth.Authenticator) httpx.Handler {
	r := httpx.NewRouter()

	// Apps
	r.Handle("/apps", &GetApps{e}).Methods("GET")                  // hk apps
	r.Handle("/apps/{app}", &GetAppInfo{e}).Methods("GET")         // hk info
	r.Handle("/apps/{app}", &DeleteApp{e}).Methods("DELETE")       // hk destroy
	r.Handle("/apps/{app}", &PatchApp{e}).Methods("PATCH")         // hk destroy
	r.Handle("/apps/{app}/deploys", &DeployApp{e}).Methods("POST") // Deploy an image to an app
	r.Handle("/apps", &PostApps{e}).Methods("POST")                // hk create
	r.Handle("/organizations/apps", &PostApps{e}).Methods("POST")  // hk create

	// Domains
	r.Handle("/apps/{app}/domains", &GetDomains{e}).Methods("GET")                 // hk domains
	r.Handle("/apps/{app}/domains", &PostDomains{e}).Methods("POST")               // hk domain-add
	r.Handle("/apps/{app}/domains/{hostname}", &DeleteDomain{e}).Methods("DELETE") // hk domain-remove

	// Deploys
	r.Handle("/deploys", &PostDeploys{e}).Methods("POST") // Deploy an app

	// Releases
	r.Handle("/apps/{app}/releases", &GetReleases{e}).Methods("GET")          // hk releases
	r.Handle("/apps/{app}/releases/{version}", &GetRelease{e}).Methods("GET") // hk release-info
	r.Handle("/apps/{app}/releases", &PostReleases{e}).Methods("POST")        // hk rollback

	// Configs
	r.Handle("/apps/{app}/config-vars", &GetConfigs{e}).Methods("GET")     // hk env, hk get
	r.Handle("/apps/{app}/config-vars", &PatchConfigs{e}).Methods("PATCH") // hk set, hk unset

	// Processes
	r.Handle("/apps/{app}/dynos", &GetProcesses{e}).Methods("GET")                     // hk dynos
	r.Handle("/apps/{app}/dynos", &PostProcess{e}).Methods("POST")                     // hk run
	r.Handle("/apps/{app}/dynos", &DeleteProcesses{e}).Methods("DELETE")               // hk restart
	r.Handle("/apps/{app}/dynos/{ptype}.{pid}", &DeleteProcesses{e}).Methods("DELETE") // hk restart web.1
	r.Handle("/apps/{app}/dynos/{pid}", &DeleteProcesses{e}).Methods("DELETE")         // hk restart web

	// Formations
	r.Handle("/apps/{app}/formation", &GetFormation{e}).Methods("GET")     // hk scale -l
	r.Handle("/apps/{app}/formation", &PatchFormation{e}).Methods("PATCH") // hk scale

	// OAuth
	r.Handle("/oauth/authorizations", &PostAuthorizations{e}).Methods("POST")

	// SSL
	sslRemoved := errHandler(ErrSSLRemoved)
	r.Handle("/apps/{app}/ssl-endpoints", sslRemoved).Methods("GET")           // hk ssl
	r.Handle("/apps/{app}/ssl-endpoints", sslRemoved).Methods("POST")          // hk ssl-cert-add
	r.Handle("/apps/{app}/ssl-endpoints/{cert}", sslRemoved).Methods("PATCH")  // hk ssl-cert-add, hk ssl-cert-rollback
	r.Handle("/apps/{app}/ssl-endpoints/{cert}", sslRemoved).Methods("DELETE") // hk ssl-destroy

	// Logs
	r.Handle("/apps/{app}/log-sessions", &PostLogs{e}).Methods("POST") // hk log

	api := Authenticate(r, authenticator)

	return httpx.HandlerFunc(func(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
		err := api.ServeHTTPContext(ctx, w, r)
		if err != nil {
			Error(w, err, http.StatusInternalServerError)
			reporter.Report(ctx, err)
		}
{'fraction_non_alphanumeric': 0.20586680761099366, 'fraction_numerical': 0.0048890063424947144, 'mean_word_length': 3.4893238434163703, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5181622', 'n_tokens_mistral': 2696, 'n_tokens_neox': 2596, 'n_words': 435}