Skip to content

Commit 57527c4

Browse files
authored
Merge branch 'main' into feat/github-app-for-users
2 parents 7016173 + ebd358f commit 57527c4

21 files changed

Lines changed: 477 additions & 53 deletions

.github/labeler.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Configuration for labeler - https://github.com/actions/labeler
2+
"Type: Breaking change":
3+
- head-branch:
4+
- '^breaking/'
5+
- '^breaking-'
6+
7+
"Type: Feature":
8+
- head-branch:
9+
- '^feat/'
10+
- '^feat-'
11+
- '^feature/'
12+
- '^feature-'
13+
14+
"Type: Bug":
15+
- head-branch:
16+
- '^fix/'
17+
- '^fix-'
18+
- '^bugfix/'
19+
- '^bugfix-'
20+
- '^bug/'
21+
- '^bug-'
22+
23+
"Deprecation":
24+
- head-branch:
25+
- '^deprecate/'
26+
- '^deprecate-'
27+
- '^deprecation/'
28+
- '^deprecation-'
29+
30+
"Type: Maintenance":
31+
- head-branch:
32+
- '^chore/'
33+
- '^chore-'
34+
- '^maintenance/'
35+
- '^maintenance-'
36+
- '^maint/'
37+
- '^maint-'
38+
- '^deps/'
39+
- '^deps-'
40+
- '^dependencies/'
41+
- '^dependencies-'
42+
- changed-files:
43+
- any-glob-to-any-file:
44+
- .github/workflows/**
45+
- .github/labeler.yml
46+
- .github/dependabot.yml
47+
- .github/release.yml
48+
49+
"Type: Documentation":
50+
- head-branch:
51+
- '^docs/'
52+
- '^docs-'
53+
- '^doc/'
54+
- '^doc-'
55+
- changed-files:
56+
- any-glob-to-any-file: 'website/**'

.github/workflows/codeql.yml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ on:
1111

1212
jobs:
1313
analyze:
14-
name: Analyze
14+
name: Analyze (${{ matrix.language }})
1515
runs-on: ubuntu-latest
1616
permissions:
1717
actions: read
@@ -21,27 +21,36 @@ jobs:
2121
strategy:
2222
fail-fast: false
2323
matrix:
24-
language: [ 'go' ]
24+
include:
25+
- language: actions
26+
build-mode: none
27+
queries: security-extended # can be 'default' (use empty for 'default'), 'security-and-quality', 'security-extended'
28+
- language: go
29+
build-mode: autobuild
30+
queries: '' # will be used 'default' queries
2531

2632
steps:
2733
- name: Checkout repository
2834
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
2935

3036
- uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0
37+
if: matrix.language == 'go'
3138
with:
3239
go-version-file: 'go.mod'
3340
cache: true
3441

3542
# Initializes the CodeQL tools for scanning.
3643
- name: Initialize CodeQL
37-
uses: github/codeql-action/init@4e94bd11f71e507f7f87df81788dff88d1dacbfb # v4.31.0
44+
uses: github/codeql-action/init@0499de31b99561a6d14a36a5f662c2a54f91beee # v4.31.2
3845
with:
3946
languages: ${{ matrix.language }}
47+
build-mode: ${{ matrix['build-mode'] }}
48+
queries: ${{ matrix.queries }}
4049

4150
- name: Autobuild
42-
uses: github/codeql-action/autobuild@4e94bd11f71e507f7f87df81788dff88d1dacbfb # v4.31.0
51+
uses: github/codeql-action/autobuild@0499de31b99561a6d14a36a5f662c2a54f91beee # v4.31.2
4352

4453
- name: Perform CodeQL Analysis
45-
uses: github/codeql-action/analyze@4e94bd11f71e507f7f87df81788dff88d1dacbfb # v4.31.0
54+
uses: github/codeql-action/analyze@0499de31b99561a6d14a36a5f662c2a54f91beee # v4.31.2
4655
with:
4756
category: "/language:${{matrix.language}}"

.github/workflows/immediate-response.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ on:
1111
- opened
1212
jobs:
1313
respond-to-issue:
14-
if: ${{ github.actor != 'dependabot[bot]' && github.actor != 'renovate[bot]' && github.actor != 'githubactions[bot]' && github.actor != 'octokitbot' }}
14+
if: ${{ github.actor != 'dependabot[bot]' && github.actor != 'renovate[bot]' &&
15+
github.actor != 'githubactions[bot]' && github.actor != 'octokitbot' &&
16+
github.repository == 'integrations/terraform-provider-github' }}
1517
runs-on: ubuntu-latest
1618
steps:
1719
- name: Determine issue or PR number

.github/workflows/labeler.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Pull Request Labeler
2+
3+
on:
4+
pull_request_target:
5+
types: [opened, synchronize, reopened]
6+
7+
permissions:
8+
contents: read
9+
pull-requests: write # Use this if all labels already exist in the repository (i.e., pre-defined in .github/labeler.yml).
10+
11+
jobs:
12+
labeler:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Run Labeler
16+
uses: actions/labeler@634933edcd8ababfe52f92936142cc22ac488b1b # v6.0.1
17+
with:
18+
sync-labels: true # Whether or not to remove labels when matching files are reverted or no longer changed by the PR

github/resource_github_branch_default.go

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ func resourceGithubBranchDefault() *schema.Resource {
5050
}
5151
}
5252

53-
func resourceGithubBranchDefaultCreate(d *schema.ResourceData, meta interface{}) error {
54-
53+
func resourceGithubBranchDefaultCreate(d *schema.ResourceData, meta any) error {
5554
client := meta.(*Owner).v3client
5655
owner := meta.(*Owner).name
5756
repoName := d.Get("repository").(string)
@@ -60,21 +59,24 @@ func resourceGithubBranchDefaultCreate(d *schema.ResourceData, meta interface{})
6059

6160
ctx := context.Background()
6261

63-
if rename {
64-
repository, _, err := client.Repositories.Get(ctx, owner, repoName)
65-
if err != nil {
66-
return err
67-
}
68-
if _, _, err := client.Repositories.RenameBranch(ctx, owner, repoName, *repository.DefaultBranch, defaultBranch); err != nil {
69-
return err
70-
}
71-
} else {
72-
repository := &github.Repository{
73-
DefaultBranch: &defaultBranch,
74-
}
62+
repository, _, err := client.Repositories.Get(ctx, owner, repoName)
63+
if err != nil {
64+
return err
65+
}
7566

76-
if _, _, err := client.Repositories.Edit(ctx, owner, repoName, repository); err != nil {
77-
return err
67+
if *repository.DefaultBranch != defaultBranch {
68+
if rename {
69+
if _, _, err := client.Repositories.RenameBranch(ctx, owner, repoName, *repository.DefaultBranch, defaultBranch); err != nil {
70+
return err
71+
}
72+
} else {
73+
repository := &github.Repository{
74+
DefaultBranch: &defaultBranch,
75+
}
76+
77+
if _, _, err := client.Repositories.Edit(ctx, owner, repoName, repository); err != nil {
78+
return err
79+
}
7880
}
7981
}
8082

@@ -83,8 +85,7 @@ func resourceGithubBranchDefaultCreate(d *schema.ResourceData, meta interface{})
8385
return resourceGithubBranchDefaultRead(d, meta)
8486
}
8587

86-
func resourceGithubBranchDefaultRead(d *schema.ResourceData, meta interface{}) error {
87-
88+
func resourceGithubBranchDefaultRead(d *schema.ResourceData, meta any) error {
8889
client := meta.(*Owner).v3client
8990
owner := meta.(*Owner).name
9091
repoName := d.Id()
@@ -121,8 +122,7 @@ func resourceGithubBranchDefaultRead(d *schema.ResourceData, meta interface{}) e
121122
return nil
122123
}
123124

124-
func resourceGithubBranchDefaultDelete(d *schema.ResourceData, meta interface{}) error {
125-
125+
func resourceGithubBranchDefaultDelete(d *schema.ResourceData, meta any) error {
126126
client := meta.(*Owner).v3client
127127
owner := meta.(*Owner).name
128128
repoName := d.Id()
@@ -137,8 +137,7 @@ func resourceGithubBranchDefaultDelete(d *schema.ResourceData, meta interface{})
137137
return err
138138
}
139139

140-
func resourceGithubBranchDefaultUpdate(d *schema.ResourceData, meta interface{}) error {
141-
140+
func resourceGithubBranchDefaultUpdate(d *schema.ResourceData, meta any) error {
142141
client := meta.(*Owner).v3client
143142
owner := meta.(*Owner).name
144143
repoName := d.Id()

github/resource_github_branch_default_test.go

Lines changed: 54 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@ import (
99
)
1010

1111
func TestAccGithubBranchDefault(t *testing.T) {
12-
1312
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
1413

1514
t.Run("creates and manages branch defaults", func(t *testing.T) {
16-
1715
config := fmt.Sprintf(`
1816
1917
resource "github_repository" "test" {
@@ -62,22 +60,20 @@ func TestAccGithubBranchDefault(t *testing.T) {
6260
t.Run("with an organization account", func(t *testing.T) {
6361
testCase(t, organization)
6462
})
65-
6663
})
6764

6865
t.Run("replaces the default_branch of a repository", func(t *testing.T) {
69-
7066
config := fmt.Sprintf(`
7167
resource "github_repository" "test" {
7268
name = "tf-acc-test-%s"
7369
auto_init = true
7470
}
75-
71+
7672
resource "github_branch" "test" {
7773
repository = github_repository.test.name
7874
branch = "test"
7975
}
80-
76+
8177
resource "github_branch_default" "test"{
8278
repository = github_repository.test.name
8379
branch = github_branch.test.branch
@@ -116,17 +112,67 @@ func TestAccGithubBranchDefault(t *testing.T) {
116112
t.Run("with an organization account", func(t *testing.T) {
117113
testCase(t, organization)
118114
})
115+
})
116+
117+
t.Run("creates and manages branch defaults even if rename is set", func(t *testing.T) {
118+
config := fmt.Sprintf(`
119+
120+
resource "github_repository" "test" {
121+
name = "tf-acc-test-%s"
122+
auto_init = true
123+
}
124+
125+
resource "github_branch_default" "test" {
126+
repository = github_repository.test.name
127+
branch = "main"
128+
rename = true
129+
}
130+
`, randomID)
131+
132+
check := resource.ComposeTestCheckFunc(
133+
resource.TestCheckResourceAttr(
134+
"github_branch_default.test", "branch",
135+
"main",
136+
),
137+
resource.TestCheckResourceAttr(
138+
"github_branch_default.test", "repository",
139+
fmt.Sprintf("tf-acc-test-%s", randomID),
140+
),
141+
)
142+
143+
testCase := func(t *testing.T, mode string) {
144+
resource.Test(t, resource.TestCase{
145+
PreCheck: func() { skipUnlessMode(t, mode) },
146+
Providers: testAccProviders,
147+
Steps: []resource.TestStep{
148+
{
149+
Config: config,
150+
Check: check,
151+
},
152+
},
153+
})
154+
}
155+
156+
t.Run("with an anonymous account", func(t *testing.T) {
157+
t.Skip("anonymous account not supported for this operation")
158+
})
159+
160+
t.Run("with an individual account", func(t *testing.T) {
161+
testCase(t, individual)
162+
})
119163

164+
t.Run("with an organization account", func(t *testing.T) {
165+
testCase(t, organization)
166+
})
120167
})
121168

122169
t.Run("replaces the default_branch of a repository without creating a branch resource prior to", func(t *testing.T) {
123-
124170
config := fmt.Sprintf(`
125171
resource "github_repository" "test" {
126172
name = "tf-acc-test-%s"
127173
auto_init = true
128174
}
129-
175+
130176
resource "github_branch_default" "test"{
131177
repository = github_repository.test.name
132178
branch = "development"
@@ -166,6 +212,5 @@ func TestAccGithubBranchDefault(t *testing.T) {
166212
t.Run("with an organization account", func(t *testing.T) {
167213
testCase(t, organization)
168214
})
169-
170215
})
171216
}

github/resource_github_repository_collaborator.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,14 @@ func resourceGithubRepositoryCollaboratorDelete(d *schema.ResourceData, meta int
196196
// Delete any pending invitations
197197
invitation, err := findRepoInvitation(client, ctx, owner, repoNameWithoutOwner, username)
198198
if err != nil {
199-
return err
199+
return handleArchivedRepoDelete(err, "repository collaborator invitation", username, owner, repoNameWithoutOwner)
200200
} else if invitation != nil {
201201
_, err = client.Repositories.DeleteInvitation(ctx, owner, repoNameWithoutOwner, invitation.GetID())
202-
return err
202+
return handleArchivedRepoDelete(err, "repository collaborator invitation", username, owner, repoNameWithoutOwner)
203203
}
204204

205205
_, err = client.Repositories.RemoveCollaborator(ctx, owner, repoNameWithoutOwner, username)
206-
return err
206+
return handleArchivedRepoDelete(err, "repository collaborator", username, owner, repoNameWithoutOwner)
207207
}
208208

209209
func findRepoInvitation(client *github.Client, ctx context.Context, owner, repo, collaborator string) (*github.RepositoryInvitation, error) {

0 commit comments

Comments
 (0)