Skip to content

Commit 95dafb2

Browse files
authored
Merge branch 'main' into fix/1864-handle-manually-deleted-github-release-state
2 parents 9b21b7e + 6e507a6 commit 95dafb2

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

github/data_source_github_rest_api.go

+15-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package github
22

33
import (
44
"context"
5+
"encoding/json"
56

67
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
78
)
@@ -25,11 +26,11 @@ func dataSourceGithubRestApi() *schema.Resource {
2526
Computed: true,
2627
},
2728
"headers": {
28-
Type: schema.TypeMap,
29+
Type: schema.TypeString,
2930
Computed: true,
3031
},
3132
"body": {
32-
Type: schema.TypeMap,
33+
Type: schema.TypeString,
3334
Computed: true,
3435
},
3536
},
@@ -51,11 +52,21 @@ func dataSourceGithubRestApiRead(d *schema.ResourceData, meta interface{}) error
5152

5253
resp, _ := client.Do(ctx, req, &body)
5354

55+
h, err := json.Marshal(resp.Header)
56+
if err != nil {
57+
return err
58+
}
59+
60+
b, err := json.Marshal(body)
61+
if err != nil {
62+
return err
63+
}
64+
5465
d.SetId(resp.Header.Get("x-github-request-id"))
5566
d.Set("code", resp.StatusCode)
5667
d.Set("status", resp.Status)
57-
d.Set("headers", resp.Header)
58-
d.Set("body", body)
68+
d.Set("headers", string(h))
69+
d.Set("body", string(b))
5970

6071
return nil
6172
}

github/data_source_github_rest_api_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ func TestAccGithubRestApiDataSource(t *testing.T) {
3030
resource.TestMatchResourceAttr(
3131
"data.github_rest_api.test", "code", regexp.MustCompile("200"),
3232
),
33+
resource.TestMatchResourceAttr(
34+
"data.github_rest_api.test", "status", regexp.MustCompile("200 OK"),
35+
),
36+
resource.TestCheckResourceAttrSet("data.github_rest_api.test", "body"),
37+
resource.TestCheckResourceAttrSet("data.github_rest_api.test", "headers"),
3338
)
3439

3540
testCase := func(t *testing.T, mode string) {
@@ -76,6 +81,11 @@ func TestAccGithubRestApiDataSource(t *testing.T) {
7681
resource.TestMatchResourceAttr(
7782
"data.github_rest_api.test", "code", regexp.MustCompile("404"),
7883
),
84+
resource.TestMatchResourceAttr(
85+
"data.github_rest_api.test", "status", regexp.MustCompile("404 Not Found"),
86+
),
87+
resource.TestCheckResourceAttrSet("data.github_rest_api.test", "body"),
88+
resource.TestCheckResourceAttrSet("data.github_rest_api.test", "headers"),
7989
)
8090

8191
testCase := func(t *testing.T, mode string) {

website/docs/d/rest_api.html.markdown

+3-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ data "github_rest_api" "example" {
2323

2424
## Attributes Reference
2525

26+
* `id` - The GitHub API Request ID
2627
* `code` - A response status code.
2728
* `status` - A response status string.
28-
* `headers` - A map of response headers.
29-
* `body` - A map of response body.
29+
* `headers` - A JSON string containing response headers.
30+
* `body` - A JSON string containing response body.

0 commit comments

Comments
 (0)