<commit_before>package phases

import (
    _ "github.com/Everlane/evan/heroku"
)<commit_msg>Start setting up ability to create Heroku builds<commit_after>package phases

import (
    "fmt"
    "net/http"

    "github.com/Everlane/evan/common"
    "github.com/Everlane/evan/heroku"
)

type HerokuBuildPhase struct {
    Client *heroku.Client
    AppId string
}

func (hbp *HerokuBuildPhase) CanPreload() bool {
    return false
}

func (hbp *HerokuBuildPhase) Execute(deployment common.Deployment) error {
    err := hbp.createBuild(deployment)
    if err != nil {
        return err
    }

    return nil
}

func (hbp *HerokuBuildPhase) createBuild(deployment common.Deployment) error {
    githubRepo := common.NewGithubRepositoryFromDeployment(deployment)
    tarballUrl, err := githubRepo.GetArchiveLink(common.Tarball)
    if err != nil {
        return err
    }

    resp, err := hbp.Client.BuildCreate(hbp.AppId, &heroku.SourceBlob{
        Url: tarballUrl,
        Version: deployment.Ref(),
    })
    if err != nil {
        return err
    }
    if resp.StatusCode != http.StatusCreated {
        return fmt.Errorf("Non-creation status code (expected %v, got %v)", http.StatusCreated, resp.StatusCode)
    }

    return nil
}
{'fraction_non_alphanumeric': 0.10517799352750809, 'fraction_numerical': 0.0, 'mean_word_length': 3.1096345514950166, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '2832162', 'n_tokens_mistral': 406, 'n_tokens_neox': 396, 'n_words': 91}