Skip to content

Commit c8ebe3a

Browse files
ahumegmlewis
authored andcommitted
Add method for getting single deployment status
Also add link to newly documented endpoint. Fixes #482. Closes #494. Change-Id: I6cf322efd925f6eafb949d3d8f4e4cc0c75c4fd4
1 parent 4b026b3 commit c8ebe3a

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

github/repos_deployments.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ func (s *RepositoriesService) ListDeployments(owner, repo string, opt *Deploymen
8484

8585
// GetDeployment returns a single deployment of a repository.
8686
//
87-
// GitHub API docs: https://developer.github.com/v3/repos/deployments/
88-
// Note: GetDeployment uses the undocumented GitHub API endpoint /repos/:owner/:repo/deployments/:id.
87+
// GitHub API docs: https://developer.github.com/v3/repos/deployments/#get-a-single-deployment
8988
func (s *RepositoriesService) GetDeployment(owner, repo string, deploymentID int) (*Deployment, *Response, error) {
9089
u := fmt.Sprintf("repos/%v/%v/deployments/%v", owner, repo, deploymentID)
9190

@@ -176,6 +175,29 @@ func (s *RepositoriesService) ListDeploymentStatuses(owner, repo string, deploym
176175
return *statuses, resp, err
177176
}
178177

178+
// GetDeploymentStatus returns a single deployment status of a repository.
179+
//
180+
// GitHub API docs: https://developer.github.com/v3/repos/deployments/#get-a-single-deployment-status
181+
func (s *RepositoriesService) GetDeploymentStatus(owner, repo string, deploymentID, deploymentStatusID int) (*DeploymentStatus, *Response, error) {
182+
u := fmt.Sprintf("repos/%v/%v/deployments/%v/statuses/%v", owner, repo, deploymentID, deploymentStatusID)
183+
184+
req, err := s.client.NewRequest("GET", u, nil)
185+
if err != nil {
186+
return nil, nil, err
187+
}
188+
189+
// TODO: remove custom Accept header when deployment support fully launches
190+
req.Header.Set("Accept", mediaTypeDeploymentStatusPreview)
191+
192+
d := new(DeploymentStatus)
193+
resp, err := s.client.Do(req, d)
194+
if err != nil {
195+
return nil, resp, err
196+
}
197+
198+
return d, resp, err
199+
}
200+
179201
// CreateDeploymentStatus creates a new status for a deployment.
180202
//
181203
// GitHub API docs: https://developer.github.com/v3/repos/deployments/#create-a-deployment-status

github/repos_deployments_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,27 @@ func TestRepositoriesService_ListDeploymentStatuses(t *testing.T) {
108108
}
109109
}
110110

111+
func TestRepositoriesService_GetDeploymentStatus(t *testing.T) {
112+
setup()
113+
defer teardown()
114+
115+
mux.HandleFunc("/repos/o/r/deployments/3/statuses/4", func(w http.ResponseWriter, r *http.Request) {
116+
testMethod(t, r, "GET")
117+
testHeader(t, r, "Accept", mediaTypeDeploymentStatusPreview)
118+
fmt.Fprint(w, `{"id":4}`)
119+
})
120+
121+
deploymentStatus, _, err := client.Repositories.GetDeploymentStatus("o", "r", 3, 4)
122+
if err != nil {
123+
t.Errorf("Repositories.GetDeploymentStatus returned error: %v", err)
124+
}
125+
126+
want := &DeploymentStatus{ID: Int(4)}
127+
if !reflect.DeepEqual(deploymentStatus, want) {
128+
t.Errorf("Repositories.GetDeploymentStatus returned %+v, want %+v", deploymentStatus, want)
129+
}
130+
}
131+
111132
func TestRepositoriesService_CreateDeploymentStatus(t *testing.T) {
112133
setup()
113134
defer teardown()

0 commit comments

Comments
 (0)