Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: github_rest_api data source always returns header and body as null #2110

Merged

Conversation

srgustafson8
Copy link
Contributor

Resolves #2109


Before the change?

  • The GitHub REST API data source would always return null or incomplete map values for body and headers attributes.

After the change?

  • The GitHub REST API data source now returns the body and headers attributes as a JSON string, allowing users to decode them and use them.

Pull request checklist

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)

Does this introduce a breaking change?

Please see our docs on breaking changes to help!

  • Yes
  • No

This is technically a breaking change as it changes the type of the attributes involved to strings rather than maps - however, as this would have almost never worked properly, i'm not sure how much breaking it would do.


@srgustafson8
Copy link
Contributor Author

srgustafson8 commented Jan 19, 2024

Tests:

--- PASS: TestAccGithubRestApiDataSource (32.38s)
    --- PASS: TestAccGithubRestApiDataSource/queries_an_existing_branch_without_error (16.16s)
        --- SKIP: TestAccGithubRestApiDataSource/queries_an_existing_branch_without_error/with_an_anonymous_account (0.00s)
        --- PASS: TestAccGithubRestApiDataSource/queries_an_existing_branch_without_error/with_an_individual_account (8.15s)
        --- PASS: TestAccGithubRestApiDataSource/queries_an_existing_branch_without_error/with_an_organization_account (8.02s)
    --- PASS: TestAccGithubRestApiDataSource/queries_an_invalid_branch_without_error (16.22s)
        --- SKIP: TestAccGithubRestApiDataSource/queries_an_invalid_branch_without_error/with_an_anonymous_account (0.00s)
        --- PASS: TestAccGithubRestApiDataSource/queries_an_invalid_branch_without_error/with_an_individual_account (8.26s)
        --- PASS: TestAccGithubRestApiDataSource/queries_an_invalid_branch_without_error/with_an_organization_account (7.95s)
PASS
ok      github.com/integrations/terraform-provider-github/v5/github     33.171s

Copy link
Member

@kfcampbell kfcampbell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirming integration tests are passing for me as well. I'm comfortable releasing this as a minor change given the broken nature of the behavior before. We will be releasing #2091 soon though, so stay tuned!

@kfcampbell kfcampbell merged commit 6e507a6 into integrations:main Jan 22, 2024
3 checks passed
@srgustafson8 srgustafson8 deleted the 2109-fix-restapi-datasource branch January 29, 2024 14:46
avidspartan1 pushed a commit to avidspartan1/terraform-provider-github that referenced this pull request Feb 5, 2024
…ll (integrations#2110)

* Enhance tests

* Marshal body and headers to JSON string

* Update documentation to reference JSON string

---------

Co-authored-by: Keegan Campbell <[email protected]>
@riezebosch
Copy link
Contributor

riezebosch commented Feb 16, 2024

Trying out this new behaviour and I do see the headers having value in my state file but the body is still always null? I think, when working, this would also solve #1776 and #1953.

I think I solved it: #2152

@srgustafson8
Copy link
Contributor Author

srgustafson8 commented Feb 18, 2024

EDIT: I took a look at your original issue 1776 and I see what you mean now, while my implementation works for the calls that return a map, it doesn't for calls that return an array. Good catch.


hi @riezebosch - can you give some more info on what you're trying and seeing? If i try to use it, I get body populated correctly (on calls that don't fail with 404 or other things where body would be null).

e.g.

terraform {
  required_providers {
    github = {
      source  = "integrations/github"
      version = "6.0.0"
    }
  }
}

provider "github" {}

data "github_rest_api" "test" {
  endpoint = "repos/integrations/terraform-provider-github/git/refs/heads/main"
}

gives me in state, trimmed for brevity:

  "resources": [
    {
      "mode": "data",
      "type": "github_rest_api",
      "name": "test",
      "provider": "provider[\"registry.terraform.io/integrations/github\"]",
      "instances": [
        {
          "schema_version": 0,
          "attributes": {
            "body": "{\"node_id\":\"MDM6UmVmOTM0NDYwOTk6cmVmcy9oZWFkcy9tYWlu\",\"object\":{\"sha\":\"16872b724254fdddc3441c713b087cb4d7005f83\",\"type\":\"commit\",\"url\":\"https://api.github.com/repos/integrations/terraform-provider-github/git/commits/16872b724254fdddc3441c713b087cb4d7005f83\"},\"ref\":\"refs/heads/main\",\"url\":\"https://api.github.com/repos/integrations/terraform-provider-github/git/refs/heads/main\"}",
            "code": 200,
            "headers": "{\"Access-Control-Allow-Origin\":[\"*\"],\"Access-Control-Expose-Headers\" etc etc....",
            "status": "200 OK"
          },
          "sensitive_attributes": []
        }
      ]
    }
  ],

@riezebosch
Copy link
Contributor

See my pr #2152

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG]: github_rest_api Data Source returns null values for body and headers
3 participants