Skip to content

Commit 0f84a2a

Browse files
Rate limit (#2345)
* docs: Correct name of docs file * tests: failed on main branch When running the tests prior to making changes 2 issues were seen 1) With a setting to enable vulnerability alerts the tests failed, adding them to be on in these tests doesn't impact the results and allows others in the same position to run the tests. 2) The overwrte tests did not set attributes that were being asserted, adding the attribures allow the test to pass. Not sure how these previously passed. * fix: Files should not be removed on rate limiting --------- Co-authored-by: Keegan Campbell <[email protected]>
1 parent 7e83094 commit 0f84a2a

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

github/resource_github_repository_file.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package github
22

33
import (
44
"context"
5+
"errors"
56
"log"
7+
"net/http"
68
"net/url"
79
"strings"
810

@@ -298,7 +300,13 @@ func resourceGithubRepositoryFileRead(d *schema.ResourceData, meta interface{})
298300
opts.Ref = branch.(string)
299301
}
300302

301-
fc, _, _, _ := client.Repositories.GetContents(ctx, owner, repo, file, opts)
303+
fc, _, _, err := client.Repositories.GetContents(ctx, owner, repo, file, opts)
304+
if err != nil {
305+
var errorResponse *github.ErrorResponse
306+
if errors.As(err, &errorResponse) && errorResponse.Response.StatusCode == http.StatusTooManyRequests {
307+
return err
308+
}
309+
}
302310
if fc == nil {
303311
log.Printf("[INFO] Removing repository path %s/%s/%s from state because it no longer exists in GitHub",
304312
owner, repo, file)

github/resource_github_repository_file_test.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ func TestAccGithubRepositoryFile(t *testing.T) {
1919
config := fmt.Sprintf(`
2020
2121
resource "github_repository" "test" {
22-
name = "tf-acc-test-%s"
23-
auto_init = true
22+
name = "tf-acc-test-%s"
23+
auto_init = true
24+
vulnerability_alerts = true
2425
}
2526
2627
resource "github_repository_file" "test" {
@@ -92,8 +93,9 @@ func TestAccGithubRepositoryFile(t *testing.T) {
9293

9394
config := fmt.Sprintf(`
9495
resource "github_repository" "test" {
95-
name = "tf-acc-test-%s"
96-
auto_init = true
96+
name = "tf-acc-test-%s"
97+
auto_init = true
98+
vulnerability_alerts = true
9799
}
98100
99101
resource "github_repository_file" "test" {
@@ -102,6 +104,9 @@ func TestAccGithubRepositoryFile(t *testing.T) {
102104
file = "README.md"
103105
content = "overwritten"
104106
overwrite_on_create = false
107+
commit_message = "Managed by Terraform"
108+
commit_author = "Terraform User"
109+
commit_email = "[email protected]"
105110
}
106111
107112
`, randomID)
@@ -167,8 +172,9 @@ func TestAccGithubRepositoryFile(t *testing.T) {
167172
config := fmt.Sprintf(`
168173
169174
resource "github_repository" "test" {
170-
name = "tf-acc-test-%s"
171-
auto_init = true
175+
name = "tf-acc-test-%s"
176+
auto_init = true
177+
vulnerability_alerts = true
172178
}
173179
174180
resource "github_branch" "test" {
@@ -251,8 +257,9 @@ func TestAccGithubRepositoryFile(t *testing.T) {
251257

252258
config := fmt.Sprintf(`
253259
resource "github_repository" "test" {
254-
name = "tf-acc-test-%s"
255-
auto_init = true
260+
name = "tf-acc-test-%s"
261+
auto_init = true
262+
vulnerability_alerts = true
256263
}
257264
258265
resource "github_repository_file" "test" {

0 commit comments

Comments
 (0)