Repository: google/go-github
Pull request #1421 (2020-02-10 14:04:34)

Implement support for actions workflow jobs
This PR adds support for managing the most recent update of Action Workflow Jobs.

Relates to: #1399

By the way, there are several things that I am still not sure of:
- The action in the original GitHub documentation is "List workflow job logs" thus I name the function `ListWorkflowJobLogs` but since it basically retrieve a URL to download a text file that contain the logs I think it would be better to name it `GetLogsFileURL`.
- I am still not sure of perhaps how `go-github` would implement this particular function since the URL of the file is in the header of the response. Do you have any example of other functions that implement this kind of response? 

Thank you very much beforehand :slightly_smiling_face: 

joshuabezaleel: Apparently I pasted the wrong test, I am sorry.
gmlewis: Thanks, @joshuabezaleel!

> By the way, there are several things that I am still not sure of:

Yes, I think this one should probably be treated like we treat [GetArchiveLink](https://github.com/google/go-github/blob/master/github/repos_contents.go#L242-L288) where the client can either get the URL or get the actual text file using the `followRedirects bool` parameter.

Does that make sense?
joshuabezaleel: Yes, the function that you mentioned was really helpful, thank you very much @gmlewis !! Looking forward to your review :slightly_smiling_face:  
joshuabezaleel: I tried to use the `ActionsService` from a constructed client to try it but I couldn't find it. Do you have any idea why? .... :confused: 
![imageedit_3_3260833938](https://user-images.githubusercontent.com/7043511/74212636-ba898900-4cc7-11ea-9bdd-2dbc8fce43f8.png)

marcofranssen: @joshuabezaleel 

probably you need to do

```bash
go get github.com/google/go-github@thebranch-containing-the-code
```

or you should add a replace in your go.mod

```mod
replace github.com/google/go-github => ./the-path-to-your-checkout-of-the-repo-branch
```
joshuabezaleel: @marcofranssen The `main.go` that I wrote to try the `ActionsService` is in the `go-github` folder itself. And I already fetch the latest commits that contains the updates of including `ActionsService` when initiating a new Client so that should already be included though. :confused: 
gmlewis: Can you please start with a super-simple example like this: https://github.com/google/go-github/issues/1176#issuecomment-495996087
and tweak it to call `client.Actions.YourMethodYouWantToTest` and share it here, and we can help you debug it?

I'm betting that you are trying to call `client.ActionsService` instead of `client.Actions` and that is the problem.
gmlewis: Thank you, @joshuabezaleel.
Please run `go generate ./...` again and then the tests should pass.
joshuabezaleel: Hi @gmlewis , I ran the `go generate ./...` command but I think it still yield error on the `go test` and `go vet` command :confused: 
joshuabezaleel: Truly sorry for the hassle and thank you for fixing it up for me, @gmlewis ! Truly appreciate it :slightly_smiling_face: 

Patch:
diff --git a/github/actions_artifacts.go b/github/actions_artifacts.go
new file mode 100644
index 00000000..17358495
--- /dev/null
+++ b/github/actions_artifacts.go
@@ -0,0 +1,140 @@
+// Copyright 2020 The go-github AUTHORS. All rights reserved.
+//
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package github
+
+import (
+	"context"
+	"fmt"
+	"net/http"
+	"net/url"
+)
+
+// Artifact reprents a GitHub artifact.  Artifacts allow sharing
+// data between jobs in a workflow and provide storage for data
+// once a workflow is complete.
+//
+// GitHub API docs: https://developer.github.com/v3/actions/artifacts/
+type Artifact struct {
+	ID                 *int64     `json:"id,omitempty"`
+	NodeID             *string    `json:"node_id,omitempty"`
+	Name               *string    `json:"name,omitempty"`
+	SizeInBytes        *int64     `json:"size_in_bytes,omitempty"`
+	ArchiveDownloadURL *string    `json:"archive_download_url,omitempty"`
+	Expired            *bool      `json:"expired,omitempty"`
+	CreatedAt          *Timestamp `json:"created_at,omitempty"`
+	ExpiresAt          *Timestamp `json:"expires_at,omitempty"`
+}
+
+// ArtifactList represents a list of GitHub artifacts.
+//
+// GitHub API docs: https://developer.github.com/v3/actions/artifacts/
+type ArtifactList struct {
+	TotalCount *int64      `json:"total_count,omitempty"`
+	Artifacts  []*Artifact `json:"artifacts,omitempty"`
+}
+
+// ListWorkflowRunArtifacts lists all artifacts that belong to a workflow run.
+//
+// GitHub API docs: https://developer.github.com/v3/actions/artifacts/#list-workflow-run-artifacts
+func (s *ActionsService) ListWorkflowRunArtifacts(ctx context.Context, owner, repo string, runID int64, opts *ListOptions) (*ArtifactList, *Response, error) {
+	u := fmt.Sprintf("repos/%v/%v/actions/runs/%v/artifacts", owner, repo, runID)
+	u, err := addOptions(u, opts)
+	if err != nil {
+		return nil, nil, err
+	}
+
+	req, err := s.client.NewRequest("GET", u, nil)
+	if err != nil {
+		return nil, nil, err
+	}
+
+	artifactList := new(ArtifactList)
+	resp, err := s.client.Do(ctx, req, artifactList)
+	if err != nil {
+		return nil, resp, err
+	}
+
+	return artifactList, resp, nil
+}
+
+// GetArtifact gets a specific artifact for a workflow run.
+//
+// GitHub API docs: https://developer.github.com/v3/actions/artifacts/#get-an-artifact
+func (s *ActionsService) GetArtifact(ctx context.Context, owner, repo string, artifactID int64) (*Artifact, *Response, error) {
+	u := fmt.Sprintf("repos/%v/%v/actions/artifacts/%v", owner, repo, artifactID)
+
+	req, err := s.client.NewRequest("GET", u, nil)
+	if err != nil {
+		return nil, nil, err
+	}
+
+	artifact := new(Artifact)
+	resp, err := s.client.Do(ctx, req, artifact)
+	if err != nil {
+		return nil, resp, err
+	}
+
+	return artifact, resp, nil
+}
+
+// DownloadArtifact gets a redirect URL to download an archive for a repository.
+//
+// GitHub API docs: https://developer.github.com/v3/actions/artifacts/#download-an-artifact
+func (s *ActionsService) DownloadArtifact(ctx context.Context, owner, repo string, artifactID int64, followRedirects bool) (*url.URL, *Response, error) {
+	u := fmt.Sprintf("repos/%v/%v/actions/artifacts/%v/zip", owner, repo, artifactID)
+
+	resp, err := s.getDownloadArtifactFromURL(ctx, u, followRedirects)
+	if err != nil {
+		return nil, nil, err
+	}
+
+	if resp.StatusCode != http.StatusFound {
+		return nil, newResponse(resp), fmt.Errorf("unexpected status code: %s", resp.Status)
+	}
+	parsedURL, err := url.Parse(resp.Header.Get("Location"))
+	return parsedURL, newResponse(resp), nil
+}
+
+func (s *ActionsService) getDownloadArtifactFromURL(ctx context.Context, u string, followRedirects bool) (*http.Response, error) {
+	req, err := s.client.NewRequest("GET", u, nil)
+	if err != nil {
+		return nil, err
+	}
+
+	var resp *http.Response
+	// Use http.DefaultTransport if no custom Transport is configured
+	req = withContext(ctx, req)
+	if s.client.client.Transport == nil {
+		resp, err = http.DefaultTransport.RoundTrip(req)
+	} else {
+		resp, err = s.client.client.Transport.RoundTrip(req)
+	}
+	if err != nil {
+		return nil, err
+	}
+	resp.Body.Close()
+
+	// If redirect response is returned, follow it
+	if followRedirects && resp.StatusCode == http.StatusMovedPermanently {
+		u = resp.Header.Get("Location")
+		resp, err = s.getDownloadArtifactFromURL(ctx, u, false)
+	}
+	return resp, err
+}
+
+// DeleteArtifact deletes a workflow run artifact.
+//
+// GitHub API docs: https://developer.github.com/v3/actions/artifacts/#delete-an-artifact
+func (s *ActionsService) DeleteArtifact(ctx context.Context, owner, repo string, artifactID int64) (*Response, error) {
+	u := fmt.Sprintf("repos/%v/%v/actions/artifacts/%v", owner, repo, artifactID)
+
+	req, err := s.client.NewRequest("DELETE", u, nil)
+	if err != nil {
+		return nil, err
+	}
+
+	return s.client.Do(ctx, req, nil)
+}
diff --git a/github/actions_workflow_jobs.go b/github/actions_workflow_jobs.go
new file mode 100644
index 00000000..d9adad7d
--- /dev/null
+++ b/github/actions_workflow_jobs.go
@@ -0,0 +1,137 @@
+// Copyright 2020 The go-github AUTHORS. All rights reserved.
+//
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package github
+
+import (
+	"context"
+	"fmt"
+	"net/http"
+	"net/url"
+)
+
+// TaskStep represents a single task step from a sequence of tasks of a job.
+type TaskStep struct {
+	Name        *string    `json:"name,omitempty"`
+	Status      *string    `json:"status,omitempty"`
+	Conclusion  *string    `json:"conclusion,omitempty"`
+	Number      *int64     `json:"number,omitempty"`
+	StartedAt   *Timestamp `json:"started_at,omitempty"`
+	CompletedAt *Timestamp `json:"completed_at,omitempty"`
+}
+
+// WorkflowJob represents a repository action workflow job.
+type WorkflowJob struct {
+	ID          *int64      `json:"id,omitempty"`
+	RunID       *int64      `json:"run_id,omitempty"`
+	RunURL      *string     `json:"run_url,omitempty"`
+	NodeID      *string     `json:"node_id,omitempty"`
+	HeadSHA     *string     `json:"head_sha,omitempty"`
+	URL         *string     `json:"url,omitempty"`
+	HTMLURL     *string     `json:"html_url,omitempty"`
+	Status      *string     `json:"status,omitempty"`
+	Conclusion  *string     `json:"conclusion,omitempty"`
+	StartedAt   *Timestamp  `json:"started_at,omitempty"`
+	CompletedAt *Timestamp  `json:"completed_at,omitempty"`
+	Name        *string     `json:"name,omitempty"`
+	Steps       []*TaskStep `json:"steps,omitempty"`
+	CheckRunURL *string     `json:"check_run_url,omitempty"`
+}
+
+// Jobs represents a slice of repository action workflow job.
+type Jobs struct {
+	TotalCount *int           `json:"total_count,omitempty"`
+	Jobs       []*WorkflowJob `json:"jobs,omitempty"`
+}
+
+// ListWorkflowJobs lists all jobs for a workflow run.
+//
+// GitHub API docs: https://developer.github.com/v3/actions/workflow_jobs/#list-jobs-for-a-workflow-run
+func (s *ActionsService) ListWorkflowJobs(ctx context.Context, owner, repo string, runID int64, opts *ListOptions) (*Jobs, *Response, error) {
+	u := fmt.Sprintf("repos/%s/%s/actions/runs/%v/jobs", owner, repo, runID)
+	u, err := addOptions(u, opts)
+	if err != nil {
+		return nil, nil, err
+	}
+
+	req, err := s.client.NewRequest("GET", u, nil)
+	if err != nil {
+		return nil, nil, err
+	}
+
+	jobs := new(Jobs)
+	resp, err := s.client.Do(ctx, req, &jobs)
+	if err != nil {
+		return nil, resp, err
+	}
+
+	return jobs, resp, nil
+}
+
+// GetWorkflowJobByID gets a specific job in a workflow run by ID.
+//
+// GitHub API docs: https://developer.github.com/v3/actions/workflow_jobs/#list-jobs-for-a-workflow-run
+func (s *ActionsService) GetWorkflowJobByID(ctx context.Context, owner, repo string, jobID int64) (*WorkflowJob, *Response, error) {
+	u := fmt.Sprintf("repos/%v/%v/actions/jobs/%v", owner, repo, jobID)
+
+	req, err := s.client.NewRequest("GET", u, nil)
+	if err != nil {
+		return nil, nil, err
+	}
+
+	job := new(WorkflowJob)
+	resp, err := s.client.Do(ctx, req, job)
+	if err != nil {
+		return nil, resp, err
+	}
+
+	return job, resp, nil
+}
+
+// GetWorkflowJobLogs gets a redirect URL to download a plain text file of logs for a workflow job.
+//
+// GitHub API docs: https://developer.github.com/v3/actions/workflow_jobs/#list-workflow-job-logs
+func (s *ActionsService) GetWorkflowJobLogs(ctx context.Context, owner, repo string, jobID int64, followRedirects bool) (*url.URL, *Response, error) {
+	u := fmt.Sprintf("repos/%v/%v/actions/jobs/%v/logs", owner, repo, jobID)
+
+	resp, err := s.getWorkflowJobLogsFromURL(ctx, u, followRedirects)
+	if err != nil {
+		return nil, nil, err
+	}
+
+	if resp.StatusCode != http.StatusFound {
+		return nil, newResponse(resp), fmt.Errorf("unexpected status code: %s", resp.Status)
+	}
+	parsedURL, err := url.Parse(resp.Header.Get("Location"))
+	return parsedURL, newResponse(resp), err
+}
+
+func (s *ActionsService) getWorkflowJobLogsFromURL(ctx context.Context, u string, followRedirects bool) (*http.Response, error) {
+	req, err := s.client.NewRequest("GET", u, nil)
+	if err != nil {
+		return nil, err
+	}
+
+	var resp *http.Response
+	// Use http.DefaultTransport if no custom Transport is configured
+	req = withContext(ctx, req)
+	if s.client.client.Transport == nil {
+		resp, err = http.DefaultTransport.RoundTrip(req)
+	} else {
+		resp, err = s.client.client.Transport.RoundTrip(req)
+	}
+	if err != nil {
+		return nil, err
+	}
+	resp.Body.Close()
+
+	// If redirect response is returned, follow it
+	if followRedirects && resp.StatusCode == http.StatusMovedPermanently {
+		u = resp.Header.Get("Location")
+		resp, err = s.getWorkflowJobLogsFromURL(ctx, u, false)
+	}
+	return resp, err
+
+}
diff --git a/github/github-accessors.go b/github/github-accessors.go
index a1f3e0c1..2ad2af18 100644
--- a/github/github-accessors.go
+++ b/github/github-accessors.go
@@ -308,6 +308,78 @@ func (a *AppConfig) GetWebhookSecret() string {
 	return *a.WebhookSecret
 }
 
+// GetArchiveDownloadURL returns the ArchiveDownloadURL field if it's non-nil, zero value otherwise.
+func (a *Artifact) GetArchiveDownloadURL() string {
+	if a == nil || a.ArchiveDownloadURL == nil {
+		return ""
+	}
+	return *a.ArchiveDownloadURL
+}
+
+// GetCreatedAt returns the CreatedAt field if it's non-nil, zero value otherwise.
+func (a *Artifact) GetCreatedAt() Timestamp {
+	if a == nil || a.CreatedAt == nil {
+		return Timestamp{}
+	}
+	return *a.CreatedAt
+}
+
+// GetExpired returns the Expired field if it's non-nil, zero value otherwise.
+func (a *Artifact) GetExpired() bool {
+	if a == nil || a.Expired == nil {
+		return false
+	}
+	return *a.Expired
+}
+
+// GetExpiresAt returns the ExpiresAt field if it's non-nil, zero value otherwise.
+func (a *Artifact) GetExpiresAt() Timestamp {
+	if a == nil || a.ExpiresAt == nil {
+		return Timestamp{}
+	}
+	return *a.ExpiresAt
+}
+
+// GetID returns the ID field if it's non-nil, zero value otherwise.
+func (a *Artifact) GetID() int64 {
+	if a == nil || a.ID == nil {
+		return 0
+	}
+	return *a.ID
+}
+
+// GetName returns the Name field if it's non-nil, zero value otherwise.
+func (a *Artifact) GetName() string {
+	if a == nil || a.Name == nil {
+		return ""
+	}
+	return *a.Name
+}
+
+// GetNodeID returns the NodeID field if it's non-nil, zero value otherwise.
+func (a *Artifact) GetNodeID() string {
+	if a == nil || a.NodeID == nil {
+		return ""
+	}
+	return *a.NodeID
+}
+
+// GetSizeInBytes returns the SizeInBytes field if it's non-nil, zero value otherwise.
+func (a *Artifact) GetSizeInBytes() int64 {
+	if a == nil || a.SizeInBytes == nil {
+		return 0
+	}
+	return *a.SizeInBytes
+}
+
+// GetTotalCount returns the TotalCount field if it's non-nil, zero value otherwise.
+func (a *ArtifactList) GetTotalCount() int64 {
+	if a == nil || a.TotalCount == nil {
+		return 0
+	}
+	return *a.TotalCount
+}
+
 // GetBody returns the Body field if it's non-nil, zero value otherwise.
 func (a *Attachment) GetBody() string {
 	if a == nil || a.Body == nil {
@@ -4972,6 +5044,14 @@ func (i *IssueStats) GetTotalIssues() int {
 	return *i.TotalIssues
 }
 
+// GetTotalCount returns the TotalCount field if it's non-nil, zero value otherwise.
+func (j *Jobs) GetTotalCount() int {
+	if j == nil || j.TotalCount == nil {
+		return 0
+	}
+	return *j.TotalCount
+}
+
 // GetCreatedAt returns the CreatedAt field if it's non-nil, zero value otherwise.
 func (k *Key) GetCreatedAt() Timestamp {
 	if k == nil || k.CreatedAt == nil {
@@ -11916,6 +11996,54 @@ func (t *Tag) GetVerification() *SignatureVerification {
 	return t.Verification
 }
 
+// GetCompletedAt returns the CompletedAt field if it's non-nil, zero value otherwise.
+func (t *TaskStep) GetCompletedAt() Timestamp {
+	if t == nil || t.CompletedAt == nil {
+		return Timestamp{}
+	}
+	return *t.CompletedAt
+}
+
+// GetConclusion returns the Conclusion field if it's non-nil, zero value otherwise.
+func (t *TaskStep) GetConclusion() string {
+	if t == nil || t.Conclusion == nil {
+		return ""
+	}
+	return *t.Conclusion
+}
+
+// GetName returns the Name field if it's non-nil, zero value otherwise.
+func (t *TaskStep) GetName() string {
+	if t == nil || t.Name == nil {
+		return ""
+	}
+	return *t.Name
+}
+
+// GetNumber returns the Number field if it's non-nil, zero value otherwise.
+func (t *TaskStep) GetNumber() int64 {
+	if t == nil || t.Number == nil {
+		return 0
+	}
+	return *t.Number
+}
+
+// GetStartedAt returns the StartedAt field if it's non-nil, zero value otherwise.
+func (t *TaskStep) GetStartedAt() Timestamp {
+	if t == nil || t.StartedAt == nil {
+		return Timestamp{}
+	}
+	return *t.StartedAt
+}
+
+// GetStatus returns the Status field if it's non-nil, zero value otherwise.
+func (t *TaskStep) GetStatus() string {
+	if t == nil || t.Status == nil {
+		return ""
+	}
+	return *t.Status
+}
+
 // GetDescription returns the Description field if it's non-nil, zero value otherwise.
 func (t *Team) GetDescription() string {
 	if t == nil || t.Description == nil {
@@ -13932,6 +14060,110 @@ func (w *Workflow) GetURL() string {
 	return *w.URL
 }
 
+// GetCheckRunURL returns the CheckRunURL field if it's non-nil, zero value otherwise.
+func (w *WorkflowJob) GetCheckRunURL() string {
+	if w == nil || w.CheckRunURL == nil {
+		return ""
+	}
+	return *w.CheckRunURL
+}
+
+// GetCompletedAt returns the CompletedAt field if it's non-nil, zero value otherwise.
+func (w *WorkflowJob) GetCompletedAt() Timestamp {
+	if w == nil || w.CompletedAt == nil {
+		return Timestamp{}
+	}
+	return *w.CompletedAt
+}
+
+// GetConclusion returns the Conclusion field if it's non-nil, zero value otherwise.
+func (w *WorkflowJob) GetConclusion() string {
+	if w == nil || w.Conclusion == nil {
+		return ""
+	}
+	return *w.Conclusion
+}
+
+// GetHeadSHA returns the HeadSHA field if it's non-nil, zero value otherwise.
+func (w *WorkflowJob) GetHeadSHA() string {
+	if w == nil || w.HeadSHA == nil {
+		return ""
+	}
+	return *w.HeadSHA
+}
+
+// GetHTMLURL returns the HTMLURL field if it's non-nil, zero value otherwise.
+func (w *WorkflowJob) GetHTMLURL() string {
+	if w == nil || w.HTMLURL == nil {
+		return ""
+	}
+	return *w.HTMLURL
+}
+
+// GetID returns the ID field if it's non-nil, zero value otherwise.
+func (w *WorkflowJob) GetID() int64 {
+	if w == nil || w.ID == nil {
+		return 0
+	}
+	return *w.ID
+}
+
+// GetName returns the Name field if it's non-nil, zero value otherwise.
+func (w *WorkflowJob) GetName() string {
+	if w == nil || w.Name == nil {
+		return ""
+	}
+	return *w.Name
+}
+
+// GetNodeID returns the NodeID field if it's non-nil, zero value otherwise.
+func (w *WorkflowJob) GetNodeID() string {
+	if w == nil || w.NodeID == nil {
+		return ""
+	}
+	return *w.NodeID
+}
+
+// GetRunID returns the RunID field if it's non-nil, zero value otherwise.
+func (w *WorkflowJob) GetRunID() int64 {
+	if w == nil || w.RunID == nil {
+		return 0
+	}
+	return *w.RunID
+}
+
+// GetRunURL returns the RunURL field if it's non-nil, zero value otherwise.
+func (w *WorkflowJob) GetRunURL() string {
+	if w == nil || w.RunURL == nil {
+		return ""
+	}
+	return *w.RunURL
+}
+
+// GetStartedAt returns the StartedAt field if it's non-nil, zero value otherwise.
+func (w *WorkflowJob) GetStartedAt() Timestamp {
+	if w == nil || w.StartedAt == nil {
+		return Timestamp{}
+	}
+	return *w.StartedAt
+}
+
+// GetStatus returns the Status field if it's non-nil, zero value otherwise.
+func (w *WorkflowJob) GetStatus() string {
+	if w == nil || w.Status == nil {
+		return ""
+	}
+	return *w.Status
+}
+
+// GetURL returns the URL field if it's non-nil, zero value otherwise.
+func (w *WorkflowJob) GetURL() string {
+	if w == nil || w.URL == nil {
+		return ""
+	}
+	return *w.URL
+}
+
 // GetTotalCount returns the TotalCount field if it's non-nil, zero value otherwise.
 func (w *Workflows) GetTotalCount() int {
 	if w == nil || w.TotalCount == nil {


Test patch:
diff --git a/github/actions_artifacts_test.go b/github/actions_artifacts_test.go
new file mode 100644
index 00000000..2d478e45
--- /dev/null
+++ b/github/actions_artifacts_test.go
@@ -0,0 +1,277 @@
+// Copyright 2020 The go-github AUTHORS. All rights reserved.
+//
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package github
+
+import (
+	"context"
+	"fmt"
+	"net/http"
+	"net/url"
+	"reflect"
+	"testing"
+)
+
+func TestActionsService_ListWorkflowRunArtifacts(t *testing.T) {
+	client, mux, _, teardown := setup()
+	defer teardown()
+
+	mux.HandleFunc("/repos/o/r/actions/runs/1/artifacts", func(w http.ResponseWriter, r *http.Request) {
+		testMethod(t, r, "GET")
+		testFormValues(t, r, values{"page": "2"})
+		fmt.Fprint(w,
+			`{
+				"total_count":1, 
+				"artifacts":[{"id":1}]
+			}`,
+		)
+	})
+
+	opts := &ListOptions{Page: 2}
+	artifacts, _, err := client.Actions.ListWorkflowRunArtifacts(context.Background(), "o", "r", 1, opts)
+	if err != nil {
+		t.Errorf("Actions.ListWorkflowRunArtifacts returned error: %v", err)
+	}
+
+	want := &ArtifactList{TotalCount: Int64(1), Artifacts: []*Artifact{{ID: Int64(1)}}}
+	if !reflect.DeepEqual(artifacts, want) {
+		t.Errorf("Actions.ListWorkflowRunArtifacts returned %+v, want %+v", artifacts, want)
+	}
+}
+
+func TestActionsService_ListWorkflowRunArtifacts_invalidOwner(t *testing.T) {
+	client, _, _, teardown := setup()
+	defer teardown()
+
+	_, _, err := client.Actions.ListWorkflowRunArtifacts(context.Background(), "%", "r", 1, nil)
+	testURLParseError(t, err)
+}
+
+func TestActionsService_ListWorkflowRunArtifacts_invalidRepo(t *testing.T) {
+	client, _, _, teardown := setup()
+	defer teardown()
+
+	_, _, err := client.Actions.ListWorkflowRunArtifacts(context.Background(), "o", "%", 1, nil)
+	testURLParseError(t, err)
+}
+
+func TestActionsService_ListWorkflowRunArtifacts_notFound(t *testing.T) {
+	client, mux, _, teardown := setup()
+	defer teardown()
+
+	mux.HandleFunc("/repos/o/r/actions/runs/1/artifacts", func(w http.ResponseWriter, r *http.Request) {
+		testMethod(t, r, "GET")
+		w.WriteHeader(http.StatusNotFound)
+	})
+
+	artifacts, resp, err := client.Actions.ListWorkflowRunArtifacts(context.Background(), "o", "r", 1, nil)
+	if err == nil {
+		t.Errorf("Expected HTTP 404 response")
+	}
+	if got, want := resp.Response.StatusCode, http.StatusNotFound; got != want {
+		t.Errorf("Actions.ListWorkflowRunArtifacts return status %d, want %d", got, want)
+	}
+	if artifacts != nil {
+		t.Errorf("Actions.ListWorkflowRunArtifacts return %+v, want nil", artifacts)
+	}
+}
+
+func TestActionsService_GetArtifact(t *testing.T) {
+	client, mux, _, teardown := setup()
+	defer teardown()
+
+	mux.HandleFunc("/repos/o/r/actions/artifacts/1", func(w http.ResponseWriter, r *http.Request) {
+		testMethod(t, r, "GET")
+		fmt.Fprint(w, `{
+			"id":1,
+			"node_id":"xyz",
+			"name":"a",
+			"size_in_bytes":5,
+			"archive_download_url":"u"
+		}`)
+	})
+
+	artifact, _, err := client.Actions.GetArtifact(context.Background(), "o", "r", 1)
+	if err != nil {
+		t.Errorf("Actions.GetArtifact returned error: %v", err)
+	}
+
+	want := &Artifact{
+		ID:                 Int64(1),
+		NodeID:             String("xyz"),
+		Name:               String("a"),
+		SizeInBytes:        Int64(5),
+		ArchiveDownloadURL: String("u"),
+	}
+	if !reflect.DeepEqual(artifact, want) {
+		t.Errorf("Actions.GetArtifact returned %+v, want %+v", artifact, want)
+	}
+}
+
+func TestActionsService_GetArtifact_invalidOwner(t *testing.T) {
+	client, _, _, teardown := setup()
+	defer teardown()
+
+	_, _, err := client.Actions.GetArtifact(context.Background(), "%", "r", 1)
+	testURLParseError(t, err)
+}
+
+func TestActionsService_GetArtifact_invalidRepo(t *testing.T) {
+	client, _, _, teardown := setup()
+	defer teardown()
+
+	_, _, err := client.Actions.GetArtifact(context.Background(), "o", "%", 1)
+	testURLParseError(t, err)
+}
+
+func TestActionsService_GetArtifact_notFound(t *testing.T) {
+	client, mux, _, teardown := setup()
+	defer teardown()
+
+	mux.HandleFunc("/repos/o/r/actions/artifacts/1", func(w http.ResponseWriter, r *http.Request) {
+		testMethod(t, r, "GET")
+		w.WriteHeader(http.StatusNotFound)
+	})
+
+	artifact, resp, err := client.Actions.GetArtifact(context.Background(), "o", "r", 1)
+	if err == nil {
+		t.Errorf("Expected HTTP 404 response")
+	}
+	if got, want := resp.Response.StatusCode, http.StatusNotFound; got != want {
+		t.Errorf("Actions.GetArtifact return status %d, want %d", got, want)
+	}
+	if artifact != nil {
+		t.Errorf("Actions.GetArtifact return %+v, want nil", artifact)
+	}
+}
+
+func TestActionsSerivice_DownloadArtifact(t *testing.T) {
+	client, mux, _, teardown := setup()
+	defer teardown()
+
+	mux.HandleFunc("/repos/o/r/actions/artifacts/1/zip", func(w http.ResponseWriter, r *http.Request) {
+		testMethod(t, r, "GET")
+		http.Redirect(w, r, "https://github.com/artifact", http.StatusFound)
+	})
+
+	url, resp, err := client.Actions.DownloadArtifact(context.Background(), "o", "r", 1, true)
+	if err != nil {
+		t.Errorf("Actions.DownloadArtifact returned error: %v", err)
+	}
+	if resp.StatusCode != http.StatusFound {
+		t.Errorf("Actions.DownloadArtifact returned status: %d, want %d", resp.StatusCode, http.StatusFound)
+	}
+
+	want := "https://github.com/artifact"
+	if url.String() != want {
+		t.Errorf("Actions.DownloadArtifact returned %+v, want %+v", url.String(), want)
+	}
+}
+
+func TestActionsService_DownloadArtifact_invalidOwner(t *testing.T) {
+	client, _, _, teardown := setup()
+	defer teardown()
+
+	_, _, err := client.Actions.DownloadArtifact(context.Background(), "%", "r", 1, true)
+	testURLParseError(t, err)
+}
+
+func TestActionsService_DownloadArtifact_invalidRepo(t *testing.T) {
+	client, _, _, teardown := setup()
+	defer teardown()
+
+	_, _, err := client.Actions.DownloadArtifact(context.Background(), "o", "%", 1, true)
+	testURLParseError(t, err)
+}
+
+func TestActionsService_DownloadArtifact_StatusMovedPermanently_dontFollowRedirects(t *testing.T) {
+	client, mux, _, teardown := setup()
+	defer teardown()
+
+	mux.HandleFunc("/repos/o/r/actions/artifacts/1/zip", func(w http.ResponseWriter, r *http.Request) {
+		testMethod(t, r, "GET")
+		http.Redirect(w, r, "https://github.com/artifact", http.StatusMovedPermanently)
+	})
+
+	_, resp, _ := client.Actions.DownloadArtifact(context.Background(), "o", "r", 1, false)
+	if resp.StatusCode != http.StatusMovedPermanently {
+		t.Errorf("Actions.DownloadArtifact return status %d, want %d", resp.StatusCode, http.StatusMovedPermanently)
+	}
+}
+
+func TestActionsService_DownloadArtifact_StatusMovedPermanently_followRedirects(t *testing.T) {
+	client, mux, serverURL, teardown := setup()
+	defer teardown()
+
+	mux.HandleFunc("/repos/o/r/actions/artifacts/1/zip", func(w http.ResponseWriter, r *http.Request) {
+		testMethod(t, r, "GET")
+		redirectURL, _ := url.Parse(serverURL + baseURLPath + "/redirect")
+		http.Redirect(w, r, redirectURL.String(), http.StatusMovedPermanently)
+	})
+	mux.HandleFunc("/redirect", func(w http.ResponseWriter, r *http.Request) {
+		testMethod(t, r, "GET")
+		http.Redirect(w, r, "http://github.com/artifact", http.StatusFound)
+	})
+
+	url, resp, err := client.Actions.DownloadArtifact(context.Background(), "o", "r", 1, true)
+	if err != nil {
+		t.Errorf("Actions.DownloadArtifact return error: %v", err)
+	}
+	if resp.StatusCode != http.StatusFound {
+		t.Errorf("Actions.DownloadArtifact return status %d, want %d", resp.StatusCode, http.StatusFound)
+	}
+	want := "http://github.com/artifact"
+	if url.String() != want {
+		t.Errorf("Actions.DownloadArtifact returned %+v, want %+v", url.String(), want)
+	}
+}
+
+func TestActionsService_DeleteArtifact(t *testing.T) {
+	client, mux, _, teardown := setup()
+	defer teardown()
+
+	mux.HandleFunc("/repos/o/r/actions/artifacts/1", func(w http.ResponseWriter, r *http.Request) {
+		testMethod(t, r, "DELETE")
+	})
+
+	_, err := client.Actions.DeleteArtifact(context.Background(), "o", "r", 1)
+	if err != nil {
+		t.Errorf("Actions.DeleteArtifact return error: %v", err)
+	}
+}
+
+func TestActionsService_DeleteArtifact_invalidOwner(t *testing.T) {
+	client, _, _, teardown := setup()
+	defer teardown()
+
+	_, err := client.Actions.DeleteArtifact(context.Background(), "%", "r", 1)
+	testURLParseError(t, err)
+}
+
+func TestActionsService_DeleteArtifact_invalidRepo(t *testing.T) {
+	client, _, _, teardown := setup()
+	defer teardown()
+
+	_, err := client.Actions.DeleteArtifact(context.Background(), "o", "%", 1)
+	testURLParseError(t, err)
+}
+
+func TestActionsService_DeleteArtifact_notFound(t *testing.T) {
+	client, mux, _, teardown := setup()
+	defer teardown()
+
+	mux.HandleFunc("/repos/o/r/actions/artifacts/1", func(w http.ResponseWriter, r *http.Request) {
+		testMethod(t, r, "DELETE")
+		w.WriteHeader(http.StatusNotFound)
+	})
+
+	resp, err := client.Actions.DeleteArtifact(context.Background(), "o", "r", 1)
+	if err == nil {
+		t.Errorf("Expected HTTP 404 response")
+	}
+	if got, want := resp.Response.StatusCode, http.StatusNotFound; got != want {
+		t.Errorf("Actions.DeleteArtifact return status %d, want %d", got, want)
+	}
+}
diff --git a/github/actions_workflow_jobs_test.go b/github/actions_workflow_jobs_test.go
new file mode 100644
index 00000000..36cf7a82
--- /dev/null
+++ b/github/actions_workflow_jobs_test.go
@@ -0,0 +1,136 @@
+// Copyright 2020 The go-github AUTHORS. All rights reserved.
+//
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package github
+
+import (
+	"context"
+	"fmt"
+	"net/http"
+	"net/url"
+	"reflect"
+	"testing"
+	"time"
+)
+
+func TestActionsService_ListWorkflowJobs(t *testing.T) {
+	client, mux, _, teardown := setup()
+	defer teardown()
+
+	mux.HandleFunc("/repos/o/r/actions/runs/29679449/jobs", func(w http.ResponseWriter, r *http.Request) {
+		testMethod(t, r, "GET")
+		testFormValues(t, r, values{"per_page": "2", "page": "2"})
+		fmt.Fprint(w, `{"total_count":4,"jobs":[{"id":399444496,"run_id":29679449,"started_at":"2019-01-02T15:04:05Z","completed_at":"2020-01-02T15:04:05Z"},{"id":399444497,"run_id":29679449,"started_at":"2019-01-02T15:04:05Z","completed_at":"2020-01-02T15:04:05Z"}]}`)
+	})
+
+	opts := &ListOptions{Page: 2, PerPage: 2}
+	jobs, _, err := client.Actions.ListWorkflowJobs(context.Background(), "o", "r", 29679449, opts)
+	if err != nil {
+		t.Errorf("Actions.ListWorkflowJobs returned error: %v", err)
+	}
+
+	want := &Jobs{
+		TotalCount: Int(4),
+		Jobs: []*WorkflowJob{
+			{ID: Int64(399444496), RunID: Int64(29679449), StartedAt: &Timestamp{time.Date(2019, time.January, 02, 15, 04, 05, 0, time.UTC)}, CompletedAt: &Timestamp{time.Date(2020, time.January, 02, 15, 04, 05, 0, time.UTC)}},
+			{ID: Int64(399444497), RunID: Int64(29679449), StartedAt: &Timestamp{time.Date(2019, time.January, 02, 15, 04, 05, 0, time.UTC)}, CompletedAt: &Timestamp{time.Date(2020, time.January, 02, 15, 04, 05, 0, time.UTC)}},
+		},
+	}
+	if !reflect.DeepEqual(jobs, want) {
+		t.Errorf("Actions.ListWorkflowJobs returned %+v, want %+v", jobs, want)
+	}
+}
+
+func TestActionsService_GetWorkflowJobByID(t *testing.T) {
+	client, mux, _, teardown := setup()
+	defer teardown()
+
+	mux.HandleFunc("/repos/o/r/actions/jobs/399444496", func(w http.ResponseWriter, r *http.Request) {
+		testMethod(t, r, "GET")
+		fmt.Fprint(w, `{"id":399444496,"started_at":"2019-01-02T15:04:05Z","completed_at":"2020-01-02T15:04:05Z"}`)
+	})
+
+	job, _, err := client.Actions.GetWorkflowJobByID(context.Background(), "o", "r", 399444496)
+	if err != nil {
+		t.Errorf("Actions.GetWorkflowJobByID returned error: %v", err)
+	}
+
+	want := &WorkflowJob{
+		ID:          Int64(399444496),
+		StartedAt:   &Timestamp{time.Date(2019, time.January, 02, 15, 04, 05, 0, time.UTC)},
+		CompletedAt: &Timestamp{time.Date(2020, time.January, 02, 15, 04, 05, 0, time.UTC)},
+	}
+	if !reflect.DeepEqual(job, want) {
+		t.Errorf("Actions.GetWorkflowJobByID returned %+v, want %+v", job, want)
+	}
+}
+
+func TestActionsService_GetWorkflowJobLogs(t *testing.T) {
+	client, mux, _, teardown := setup()
+	defer teardown()
+
+	mux.HandleFunc("/repos/o/r/actions/jobs/399444496/logs", func(w http.ResponseWriter, r *http.Request) {
+		testMethod(t, r, "GET")
+		http.Redirect(w, r, "http://github.com/a", http.StatusFound)
+	})
+
+	url, resp, err := client.Actions.GetWorkflowJobLogs(context.Background(), "o", "r", 399444496, true)
+	if err != nil {
+		t.Errorf("Actions.GetWorkflowJobLogs returned error: %v", err)
+	}
+	if resp.StatusCode != http.StatusFound {
+		t.Errorf("Actions.GetWorkflowJobLogs returned status: %d, want %d", resp.StatusCode, http.StatusFound)
+	}
+	want := "http://github.com/a"
+	if url.String() != want {
+		t.Errorf("Actions.GetWorkflowJobLogs returned %+v, want %+v", url.String(), want)
+	}
+}
+
+func TestActionsService_GetWorkflowJobLogs_StatusMovedPermanently_dontFollowRedirects(t *testing.T) {
+	client, mux, _, teardown := setup()
+	defer teardown()
+
+	mux.HandleFunc("/repos/o/r/actions/jobs/399444496/logs", func(w http.ResponseWriter, r *http.Request) {
+		testMethod(t, r, "GET")
+		http.Redirect(w, r, "http://github.com/a", http.StatusMovedPermanently)
+	})
+
+	_, resp, _ := client.Actions.GetWorkflowJobLogs(context.Background(), "o", "r", 399444496, false)
+	if resp.StatusCode != http.StatusMovedPermanently {
+		t.Errorf("Actions.GetWorkflowJobLogs returned status: %d, want %d", resp.StatusCode, http.StatusMovedPermanently)
+	}
+}
+
+func TestActionsService_GetWorkflowJobLogs_StatusMovedPermanently_followRedirects(t *testing.T) {
+	client, mux, serverURL, teardown := setup()
+	defer teardown()
+
+	// Mock a redirect link, which leads to an archive link
+	mux.HandleFunc("/repos/o/r/actions/jobs/399444496/logs", func(w http.ResponseWriter, r *http.Request) {
+		testMethod(t, r, "GET")
+		redirectURL, _ := url.Parse(serverURL + baseURLPath + "/redirect")
+		http.Redirect(w, r, redirectURL.String(), http.StatusMovedPermanently)
+	})
+
+	mux.HandleFunc("/redirect", func(w http.ResponseWriter, r *http.Request) {
+		testMethod(t, r, "GET")
+		http.Redirect(w, r, "http://github.com/a", http.StatusFound)
+	})
+
+	url, resp, err := client.Actions.GetWorkflowJobLogs(context.Background(), "o", "r", 399444496, true)
+	if err != nil {
+		t.Errorf("Actions.GetWorkflowJobLogs returned error: %v", err)
+	}
+
+	if resp.StatusCode != http.StatusFound {
+		t.Errorf("Actions.GetWorkflowJobLogs returned status: %d, want %d", resp.StatusCode, http.StatusFound)
+	}
+
+	want := "http://github.com/a"
+	if url.String() != want {
+		t.Errorf("Actions.GetWorkflowJobLogs returned %+v, want %+v", url.String(), want)
+	}
+}