* Implement first round of support for GitHub Actions This commit adds: gh actions gh run list gh run view gh job view as part of our first round of actions support. These commands are unlisted and considered in beta. * review feedback * tests for exit status on job view * spinner tracks io itself * review feedback * fix PR matching * enable pager for job log viewing * add more colorf functions * add AnnotationSymbol * hide job, run * do not add method to api.Client * remove useless cargo coded copypasta
47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
package view
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"io"
|
|
"net/http"
|
|
|
|
"github.com/cli/cli/api"
|
|
"github.com/cli/cli/internal/ghinstance"
|
|
"github.com/cli/cli/internal/ghrepo"
|
|
"github.com/cli/cli/pkg/cmd/run/shared"
|
|
)
|
|
|
|
func jobLog(httpClient *http.Client, repo ghrepo.Interface, jobID string) (io.ReadCloser, error) {
|
|
url := fmt.Sprintf("%srepos/%s/actions/jobs/%s/logs",
|
|
ghinstance.RESTPrefix(repo.RepoHost()), ghrepo.FullName(repo), jobID)
|
|
req, err := http.NewRequest("GET", url, nil)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
resp, err := httpClient.Do(req)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if resp.StatusCode == 404 {
|
|
return nil, errors.New("job not found")
|
|
} else if resp.StatusCode != 200 {
|
|
return nil, api.HandleHTTPError(resp)
|
|
}
|
|
|
|
return resp.Body, nil
|
|
}
|
|
|
|
func getJob(client *api.Client, repo ghrepo.Interface, jobID string) (*shared.Job, error) {
|
|
path := fmt.Sprintf("repos/%s/actions/jobs/%s", ghrepo.FullName(repo), jobID)
|
|
|
|
var result shared.Job
|
|
err := client.REST(repo.RepoHost(), "GET", path, nil, &result)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &result, nil
|
|
}
|