diff --git a/internal/github/repository/ports.go b/internal/github/repository/ports.go index d051c38..731b4de 100644 --- a/internal/github/repository/ports.go +++ b/internal/github/repository/ports.go @@ -11,12 +11,11 @@ type Repository interface { GetAuthUser(ctx context.Context) (*GithubUser, error) GetRepository(ctx context.Context, repository string) (*GithubRepository, error) ListBranches(ctx context.Context, repository string) ([]GithubBranch, error) - ListWorkflowRuns(ctx context.Context, repository string, branch string) (*WorkflowRuns, error) + ListWorkflowRuns(ctx context.Context, repository string) (*WorkflowRuns, error) TriggerWorkflow(ctx context.Context, repository string, branch string, workflowName string, workflow any) error GetWorkflows(ctx context.Context, repository string) ([]Workflow, error) GetTriggerableWorkflows(ctx context.Context, repository string) ([]Workflow, error) InspectWorkflowContent(ctx context.Context, repository string, branch string, workflowFile string) ([]byte, error) - GetWorkflowRunLogs(ctx context.Context, repository string, runId int64) (GithubWorkflowRunLogs, error) ReRunFailedJobs(ctx context.Context, repository string, runId int64) error ReRunWorkflow(ctx context.Context, repository string, runId int64) error CancelWorkflow(ctx context.Context, repository string, runId int64) error diff --git a/internal/github/repository/repository.go b/internal/github/repository/repository.go index a4d7955..2d718d1 100644 --- a/internal/github/repository/repository.go +++ b/internal/github/repository/repository.go @@ -125,15 +125,12 @@ func (r *Repo) GetRepository(ctx context.Context, repository string) (*GithubRep return &repo, nil } -func (r *Repo) ListWorkflowRuns(ctx context.Context, repository string, branch string) (*WorkflowRuns, error) { +func (r *Repo) ListWorkflowRuns(ctx context.Context, repository string) (*WorkflowRuns, error) { // List workflow runs for the given repository and branch var workflowRuns WorkflowRuns err := r.do(ctx, nil, &workflowRuns, requestOptions{ method: http.MethodGet, paths: []string{"repos", repository, "actions", "runs"}, - queryParams: map[string]string{ - "branch": branch, - }, }) if err != nil { return nil, err @@ -291,20 +288,6 @@ func (r *Repo) getWorkflowFile(ctx context.Context, repository string, path stri return string(decodedContent), nil } -func (r *Repo) GetWorkflowRunLogs(ctx context.Context, repository string, runID int64) (GithubWorkflowRunLogs, error) { - // Get the logs for a given workflow run - var workflowRunLogs GithubWorkflowRunLogs - err := r.do(ctx, nil, &workflowRunLogs, requestOptions{ - method: http.MethodGet, - paths: []string{"repos", repository, "actions", "runs", strconv.FormatInt(runID, 10), "logs"}, - }) - if err != nil { - return GithubWorkflowRunLogs{}, err - } - - return workflowRunLogs, nil -} - func (r *Repo) ReRunFailedJobs(ctx context.Context, repository string, runID int64) error { // Re-run failed jobs for a given workflow run err := r.do(ctx, nil, nil, requestOptions{ diff --git a/internal/github/repository/repository_test.go b/internal/github/repository/repository_test.go index 0712645..7c20bd6 100644 --- a/internal/github/repository/repository_test.go +++ b/internal/github/repository/repository_test.go @@ -45,14 +45,8 @@ func TestRepo_ListWorkflowRuns(t *testing.T) { repo := newRepo(ctx) targetRepositoryName := "canack/tc" - targetRepository, err := repo.GetRepository(ctx, targetRepositoryName) - if err != nil { - t.Error(err) - } - - defaultBranch := targetRepository.DefaultBranch - workflowRuns, err := repo.ListWorkflowRuns(ctx, targetRepositoryName, defaultBranch) + workflowRuns, err := repo.ListWorkflowRuns(ctx, targetRepositoryName) if err != nil { t.Error(err) } diff --git a/internal/github/repository/types.go b/internal/github/repository/types.go index 4185a29..e270d89 100644 --- a/internal/github/repository/types.go +++ b/internal/github/repository/types.go @@ -4,14 +4,6 @@ import ( "time" ) -type GithubConfig struct { - Token string -} - -type InitializeOptions struct { - HTTPTimeout time.Duration -} - type GithubRepository struct { Id int `json:"id"` NodeId string `json:"node_id"` @@ -116,12 +108,6 @@ type Actor struct { AvatarUrl string `json:"avatar_url"` } -type GithubWorkflowRunLogs struct { - TotalSize int `json:"total_size"` - Url string `json:"url"` - Download string `json:"download_url"` -} - type GithubUser struct { Login string `json:"login"` // username ID int `json:"id"` diff --git a/internal/github/usecase/ports.go b/internal/github/usecase/ports.go index b825753..72ff45a 100644 --- a/internal/github/usecase/ports.go +++ b/internal/github/usecase/ports.go @@ -11,8 +11,8 @@ type UseCase interface { GetWorkflowHistory(ctx context.Context, input GetWorkflowHistoryInput) (*GetWorkflowHistoryOutput, error) GetTriggerableWorkflows(ctx context.Context, input GetTriggerableWorkflowsInput) (*GetTriggerableWorkflowsOutput, error) InspectWorkflow(ctx context.Context, input InspectWorkflowInput) (*InspectWorkflowOutput, error) - TriggerWorkflow(ctx context.Context, input TriggerWorkflowInput) (*TriggerWorkflowOutput, error) - ReRunFailedJobs(ctx context.Context, input ReRunFailedJobsInput) (*ReRunFailedJobsOutput, error) - ReRunWorkflow(ctx context.Context, input ReRunWorkflowInput) (*ReRunWorkflowOutput, error) - CancelWorkflow(ctx context.Context, input CancelWorkflowInput) (*CancelWorkflowOutput, error) + TriggerWorkflow(ctx context.Context, input TriggerWorkflowInput) error + ReRunFailedJobs(ctx context.Context, input ReRunFailedJobsInput) error + ReRunWorkflow(ctx context.Context, input ReRunWorkflowInput) error + CancelWorkflow(ctx context.Context, input CancelWorkflowInput) error } diff --git a/internal/github/usecase/types.go b/internal/github/usecase/types.go index b398a8e..b07843d 100644 --- a/internal/github/usecase/types.go +++ b/internal/github/usecase/types.go @@ -114,11 +114,6 @@ type TriggerWorkflowInput struct { Content string // workflow content in json format } -type TriggerWorkflowOutput struct { - // Return workflow information - // Like status url etc. -} - // ------------------------------------------------------------ type GetTriggerableWorkflowsInput struct { @@ -143,9 +138,6 @@ type ReRunFailedJobsInput struct { WorkflowID int64 } -type ReRunFailedJobsOutput struct { -} - // ------------------------------------------------------------ type ReRunWorkflowInput struct { @@ -153,15 +145,9 @@ type ReRunWorkflowInput struct { WorkflowID int64 } -type ReRunWorkflowOutput struct { -} - // ------------------------------------------------------------ type CancelWorkflowInput struct { Repository string WorkflowID int64 } - -type CancelWorkflowOutput struct { -} diff --git a/internal/github/usecase/usecase.go b/internal/github/usecase/usecase.go index f278a7a..508a089 100644 --- a/internal/github/usecase/usecase.go +++ b/internal/github/usecase/usecase.go @@ -137,16 +137,8 @@ func (u useCase) workerListRepositories(ctx context.Context, repository gr.Githu func (u useCase) GetWorkflowHistory(ctx context.Context, input GetWorkflowHistoryInput) (*GetWorkflowHistoryOutput, error) { var targetRepositoryName = input.Repository - var targetBranch = input.Branch - if targetBranch == "" { - repository, err := u.githubRepository.GetRepository(ctx, targetRepositoryName) - if err != nil { - return nil, err - } - targetBranch = repository.DefaultBranch - } - workflowRuns, err := u.githubRepository.ListWorkflowRuns(ctx, targetRepositoryName, targetBranch) + workflowRuns, err := u.githubRepository.ListWorkflowRuns(ctx, targetRepositoryName) if err != nil { return nil, err } @@ -214,34 +206,20 @@ func (u useCase) InspectWorkflow(ctx context.Context, input InspectWorkflowInput }, nil } -func (u useCase) TriggerWorkflow(ctx context.Context, input TriggerWorkflowInput) (*TriggerWorkflowOutput, error) { - err := u.githubRepository.TriggerWorkflow(ctx, input.Repository, input.Branch, input.WorkflowFile, input.Content) - if err != nil { - return nil, err - } - - return &TriggerWorkflowOutput{}, nil +func (u useCase) TriggerWorkflow(ctx context.Context, input TriggerWorkflowInput) error { + return u.githubRepository.TriggerWorkflow(ctx, input.Repository, input.Branch, input.WorkflowFile, input.Content) } -func (u useCase) ReRunFailedJobs(ctx context.Context, input ReRunFailedJobsInput) (*ReRunFailedJobsOutput, error) { - if err := u.githubRepository.ReRunFailedJobs(ctx, input.Repository, input.WorkflowID); err != nil { - return nil, err - } - return &ReRunFailedJobsOutput{}, nil +func (u useCase) ReRunFailedJobs(ctx context.Context, input ReRunFailedJobsInput) error { + return u.githubRepository.ReRunFailedJobs(ctx, input.Repository, input.WorkflowID) } -func (u useCase) ReRunWorkflow(ctx context.Context, input ReRunWorkflowInput) (*ReRunWorkflowOutput, error) { - if err := u.githubRepository.ReRunWorkflow(ctx, input.Repository, input.WorkflowID); err != nil { - return nil, err - } - return &ReRunWorkflowOutput{}, nil +func (u useCase) ReRunWorkflow(ctx context.Context, input ReRunWorkflowInput) error { + return u.githubRepository.ReRunWorkflow(ctx, input.Repository, input.WorkflowID) } -func (u useCase) CancelWorkflow(ctx context.Context, input CancelWorkflowInput) (*CancelWorkflowOutput, error) { - if err := u.githubRepository.CancelWorkflow(ctx, input.Repository, input.WorkflowID); err != nil { - return nil, err - } - return &CancelWorkflowOutput{}, nil +func (u useCase) CancelWorkflow(ctx context.Context, input CancelWorkflowInput) error { + return u.githubRepository.CancelWorkflow(ctx, input.Repository, input.WorkflowID) } func (u useCase) timeToString(t time.Time) string { diff --git a/internal/github/usecase/usecase_test.go b/internal/github/usecase/usecase_test.go index f4d99ab..84ffba7 100644 --- a/internal/github/usecase/usecase_test.go +++ b/internal/github/usecase/usecase_test.go @@ -85,7 +85,7 @@ func TestUseCase_TriggerWorkflow(t *testing.T) { t.Error(err) } - trigger, err := githubUseCase.TriggerWorkflow(ctx, TriggerWorkflowInput{ + err = githubUseCase.TriggerWorkflow(ctx, TriggerWorkflowInput{ WorkflowFile: ".github/workflows/dispatch_test.yaml", Repository: "canack/tc", Branch: "master", @@ -94,5 +94,4 @@ func TestUseCase_TriggerWorkflow(t *testing.T) { if err != nil { t.Error(err) } - t.Log(trigger) } diff --git a/internal/terminal/handler/ghtrigger.go b/internal/terminal/handler/ghtrigger.go index e9d8392..282c180 100644 --- a/internal/terminal/handler/ghtrigger.go +++ b/internal/terminal/handler/ghtrigger.go @@ -511,14 +511,12 @@ func (m *ModelGithubTrigger) triggerWorkflow() { return } - _, err = m.github.TriggerWorkflow(context.Background(), gu.TriggerWorkflowInput{ + if err := m.github.TriggerWorkflow(context.Background(), gu.TriggerWorkflowInput{ Repository: m.selectedRepository.RepositoryName, Branch: m.selectedRepository.BranchName, WorkflowFile: m.selectedWorkflow, Content: content, - }) - - if err != nil { + }); err != nil { m.status.SetError(err) m.status.SetErrorMessage("Workflow cannot be triggered") return diff --git a/internal/terminal/handler/ghworkflowhistory.go b/internal/terminal/handler/ghworkflowhistory.go index 86e649b..bc877c3 100644 --- a/internal/terminal/handler/ghworkflowhistory.go +++ b/internal/terminal/handler/ghworkflowhistory.go @@ -491,12 +491,10 @@ func (m *ModelGithubWorkflowHistory) openInBrowser() { func (m *ModelGithubWorkflowHistory) rerunFailedJobs() { m.status.SetProgressMessage("Re-running failed jobs...") - _, err := m.github.ReRunFailedJobs(context.Background(), gu.ReRunFailedJobsInput{ + if err := m.github.ReRunFailedJobs(context.Background(), gu.ReRunFailedJobsInput{ Repository: m.selectedRepository.RepositoryName, WorkflowID: m.selectedWorkflowID, - }) - - if err != nil { + }); err != nil { m.status.SetError(err) m.status.SetErrorMessage("Failed to re-run failed jobs") return @@ -515,12 +513,10 @@ func (m *ModelGithubWorkflowHistory) rerunWorkflow() { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() - _, err := m.github.ReRunWorkflow(ctx, gu.ReRunWorkflowInput{ + if err := m.github.ReRunWorkflow(ctx, gu.ReRunWorkflowInput{ Repository: m.selectedRepository.RepositoryName, WorkflowID: m.selectedWorkflowID, - }) - - if err != nil { + }); err != nil { if errors.Is(err, context.DeadlineExceeded) { m.status.SetErrorMessage("Workflow re-run request timed out") } else { @@ -541,12 +537,10 @@ func (m *ModelGithubWorkflowHistory) rerunWorkflow() { func (m *ModelGithubWorkflowHistory) cancelWorkflow() { m.status.SetProgressMessage("Canceling workflow...") - _, err := m.github.CancelWorkflow(context.Background(), gu.CancelWorkflowInput{ + if err := m.github.CancelWorkflow(context.Background(), gu.CancelWorkflowInput{ Repository: m.selectedRepository.RepositoryName, WorkflowID: m.selectedWorkflowID, - }) - - if err != nil { + }); err != nil { m.status.SetError(err) m.status.SetErrorMessage("Failed to cancel workflow") return