github.com/cli/cli@v1.14.1-0.20210902173923-1af6a669e342/pkg/cmd/workflow/view/http.go (about)

     1  package view
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/cli/cli/api"
     7  	"github.com/cli/cli/internal/ghrepo"
     8  	runShared "github.com/cli/cli/pkg/cmd/run/shared"
     9  	"github.com/cli/cli/pkg/cmd/workflow/shared"
    10  )
    11  
    12  type workflowRuns struct {
    13  	Total int
    14  	Runs  []runShared.Run
    15  }
    16  
    17  func getWorkflowRuns(client *api.Client, repo ghrepo.Interface, workflow *shared.Workflow) (workflowRuns, error) {
    18  	var wr workflowRuns
    19  	var result runShared.RunsPayload
    20  	path := fmt.Sprintf("repos/%s/actions/workflows/%d/runs?per_page=%d&page=%d", ghrepo.FullName(repo), workflow.ID, 5, 1)
    21  
    22  	err := client.REST(repo.RepoHost(), "GET", path, nil, &result)
    23  	if err != nil {
    24  		return wr, err
    25  	}
    26  
    27  	wr.Total = result.TotalCount
    28  	wr.Runs = append(wr.Runs, result.WorkflowRuns...)
    29  
    30  	return wr, nil
    31  }