Skip to content

Commit

Permalink
feat: adds abilty to open pipeline job in browser
Browse files Browse the repository at this point in the history
  • Loading branch information
FredrikMWold committed Jul 16, 2024
1 parent 2a25c6b commit 5495981
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 17 deletions.
11 changes: 6 additions & 5 deletions applicationTable/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ type Application struct {
}

type Job struct {
AppName string `json:"appName"`
Branch string `json:"branch"`
Pipeline string `json:"pipeline"`
Status string `json:"status"`
Created string `json:"created"`
Name string `json:"name"`
TriggeredBy string `json:"triggeredBy"`
Environments []string `json:"environments"`
Pipeline string `json:"pipeline"`
Status string `json:"status"`
Created string `json:"created"`
}

type Environment struct {
Expand Down
1 change: 1 addition & 0 deletions pipelineTable/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func New() Model {
type Model struct {
table table.Model
isLoadingApplication bool
jobs []string
selectedApplication string
spinner spinner.Model
focused bool
Expand Down
44 changes: 32 additions & 12 deletions pipelineTable/pipelineTable.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package pipelineTable

import (
"fmt"
"os/exec"
"time"

"github.com/FredrikMWold/radix-tui/applicationTable"
Expand All @@ -18,10 +19,15 @@ func (m Model) Init() tea.Cmd {
func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
var cmds []tea.Cmd
switch msg := msg.(type) {
case tea.KeyMsg:
switch msg.String() {
case "enter":
m.openJobInBrowser()
}
case tea.WindowSizeMsg:
var columns = []table.Column{
{Title: "name", Width: (msg.Width - 44) / 5},
{Title: "branch", Width: (msg.Width - 44) / 5},
{Title: "Triggered by", Width: (msg.Width - 44) / 5},
{Title: "Environment", Width: (msg.Width - 44) / 5},
{Title: "pipeline", Width: (msg.Width - 44) / 5},
{Title: "status", Width: (msg.Width - 44) / 5},
{Title: "created", Width: (msg.Width - 44) / 5},
Expand All @@ -36,16 +42,8 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {

case applicationTable.Application:
m.isLoadingApplication = false
jobs := make([]table.Row, len(msg.Jobs))
for i, job := range msg.Jobs {
parsedTime, err := time.Parse(time.RFC3339, job.Created)
if err != nil {
fmt.Println(err)
}
job.Created = parsedTime.Format("02.01.2006 15:04:05")
jobs[i] = table.Row([]string{job.AppName, job.Branch, job.Pipeline, job.Status, job.Created})
}
m.table.SetRows(jobs)
m.loadApplication(msg)

}

var tableCmd, spinnerCmd tea.Cmd
Expand Down Expand Up @@ -82,3 +80,25 @@ func (m *Model) Focus() {
func (m *Model) Blur() {
m.focused = false
}

func (m *Model) loadApplication(application applicationTable.Application) {
rows := make([]table.Row, len(application.Jobs))
jobs := make([]string, len(application.Jobs))
for i, job := range application.Jobs {
parsedTime, err := time.Parse(time.RFC3339, job.Created)
if err != nil {
fmt.Println(err)
}
job.Created = parsedTime.Format("02.01.2006 15:04:05")
rows[i] = table.Row([]string{job.TriggeredBy, job.Environments[0], job.Pipeline, job.Status, job.Created})
jobs[i] = job.Name
}
m.table.SetRows(rows)
m.jobs = jobs
}

func (m Model) openJobInBrowser() {
tableCursor := m.table.Cursor()
url := fmt.Sprintf("https://console.radix.equinor.com/applications/%s/jobs/view/%s", m.selectedApplication, m.jobs[tableCursor])
exec.Command("open", url).Start()
}

0 comments on commit 5495981

Please sign in to comment.