-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented Heroku apps, dynos & builds
- Loading branch information
Showing
14 changed files
with
268 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package heroku | ||
|
||
import ( | ||
"context" | ||
// "errors" | ||
|
||
"github.com/mrusme/planor/nori/models" | ||
|
||
herokugo "github.com/heroku/heroku-go/v5" | ||
) | ||
|
||
func (cloud *Heroku) ListApps() ([]models.App, error) { | ||
input := herokugo.ListRange{ | ||
Field: "id", | ||
Max: 100, | ||
Descending: false, | ||
} | ||
|
||
ret, err := cloud.heroku.AppList(context.Background(), &input) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var apps []models.App | ||
for _, app := range ret { | ||
newApp := models.App{ | ||
ID: app.ID, | ||
Name: app.Name, | ||
} | ||
|
||
apps = append(apps, newApp) | ||
} | ||
|
||
return apps, nil | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package heroku | ||
|
||
import ( | ||
"context" | ||
// "errors" | ||
|
||
"github.com/mrusme/planor/nori/models" | ||
|
||
herokugo "github.com/heroku/heroku-go/v5" | ||
) | ||
|
||
func (cloud *Heroku) ListPipelines() ([]models.Pipeline, error) { | ||
apps, err := cloud.ListApps() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var pipelines []models.Pipeline | ||
input := herokugo.ListRange{ | ||
Field: "id", | ||
Max: 1, | ||
Descending: true, | ||
} | ||
for _, app := range apps { | ||
ret, err := cloud.heroku.BuildList(context.Background(), app.ID, &input) | ||
if err != nil { | ||
return pipelines, err | ||
} | ||
|
||
for _, build := range ret { | ||
newPipelineStage := models.PipelineStage { | ||
ID: build.ID, | ||
Name: build.Release.ID, | ||
Status: build.Status, | ||
} | ||
|
||
var stages []models.PipelineStage | ||
stages = append(stages, newPipelineStage) | ||
newPipeline := models.Pipeline{ | ||
ID: app.ID, | ||
Name: app.Name, | ||
Stages: stages, | ||
} | ||
|
||
pipelines = append(pipelines, newPipeline) | ||
} | ||
} | ||
|
||
return pipelines, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package heroku | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/mrusme/planor/nori/adapter" | ||
|
||
herokugo "github.com/heroku/heroku-go/v5" | ||
) | ||
|
||
type Heroku struct { | ||
apiKey string | ||
heroku *herokugo.Service | ||
} | ||
|
||
func (cloud *Heroku) LoadProfile(profile *string) (error) { | ||
cloud.apiKey = os.Getenv(*profile) | ||
|
||
return nil | ||
} | ||
|
||
func (cloud *Heroku) LoadClients() (error) { | ||
herokugo.DefaultTransport.BearerToken = cloud.apiKey | ||
|
||
cloud.heroku = herokugo.NewService(herokugo.DefaultClient) | ||
|
||
return nil | ||
} | ||
|
||
func (cloud *Heroku) GetCapabilities() ([]adapter.Capability) { | ||
var caps []adapter.Capability | ||
|
||
caps = append(caps, adapter.Capability{ | ||
ID: "instances", | ||
Name: "Dynos", | ||
}) | ||
caps = append(caps, adapter.Capability{ | ||
ID: "ci", | ||
Name: "Builds", | ||
}) | ||
|
||
return caps | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package heroku | ||
|
||
import ( | ||
"context" | ||
// "errors" | ||
|
||
"github.com/mrusme/planor/nori/models" | ||
|
||
herokugo "github.com/heroku/heroku-go/v5" | ||
) | ||
|
||
func (cloud *Heroku) ListInstances() ([]models.Instance, error) { | ||
apps, err := cloud.ListApps() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var dynos []models.Instance | ||
input := herokugo.ListRange{ | ||
Field: "id", | ||
Max: 100, | ||
Descending: false, | ||
} | ||
for _, app := range apps { | ||
ret, err := cloud.heroku.DynoList(context.Background(), app.ID, &input) | ||
if err != nil { | ||
return dynos, err | ||
} | ||
|
||
for _, dyno := range ret { | ||
newDyno := models.Instance{ | ||
ID: dyno.ID, | ||
Name: dyno.Name, | ||
|
||
Type: dyno.Size, | ||
Image: dyno.Command, | ||
|
||
Status: dyno.State, | ||
} | ||
|
||
dynos = append(dynos, newDyno) | ||
} | ||
} | ||
|
||
return dynos, nil | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package heroku | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/mrusme/planor/nori/models" | ||
) | ||
|
||
|
||
func (cloud *Heroku) ListLogGroups(updateStreams bool, updateEvents bool) ([]models.LogGroup, error) { | ||
return nil, errors.New("Unsupported") | ||
} | ||
|
||
func (cloud *Heroku) UpdateLogStreams(logGroup *models.LogGroup, updateEvents bool) (error) { | ||
return errors.New("Unsupported") | ||
} | ||
|
||
func (cloud *Heroku) UpdateLogEvents(logStream *models.LogStream) (error) { | ||
return errors.New("Unsupported") | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package models | ||
|
||
import ( | ||
// "fmt" | ||
) | ||
|
||
type App struct { | ||
ID string | ||
Name string | ||
} | ||
|
||
func (app App) FilterValue() (string) { | ||
return app.Name | ||
} | ||
|
||
func (app App) Title() (string) { | ||
return app.Name | ||
} | ||
|
||
func (app App) Description() (string) { | ||
return app.ID | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.