Skip to content

Commit 98a4351

Browse files
authored
Merge pull request #1038 from timofurrer/feature/executable-flag-repository-files
resource/gitlab_repository_file: Add execute_filemode attribute
2 parents be313f1 + 582de52 commit 98a4351

File tree

8 files changed

+23
-2
lines changed

8 files changed

+23
-2
lines changed

docs/data-sources/repository_file.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ data "gitlab_repository_file" "example" {
4343
- `content` (String) File content. If the content is not yet base64 encoded, it will be encoded automatically. No other encoding is currently supported, because of a [GitLab API bug](https://gitlab.com/gitlab-org/gitlab/-/issues/342430).
4444
- `content_sha256` (String) File content sha256 digest.
4545
- `encoding` (String) The file content encoding.
46+
- `execute_filemode` (Boolean) Enables or disables the execute flag on the file. **Note**: requires GitLab 14.10 or newer.
4647
- `file_name` (String) The filename.
4748
- `last_commit_id` (String) The last known commit id.
4849
- `size` (Number) The file size.

docs/resources/repository_file.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ resource "gitlab_repository_file" "readme" {
7575

7676
- `author_email` (String) Email of the commit author.
7777
- `author_name` (String) Name of the commit author.
78+
- `execute_filemode` (Boolean) Enables or disables the execute flag on the file. **Note**: requires GitLab 14.10 or newer.
7879
- `id` (String) The ID of this resource.
7980
- `start_branch` (String) Name of the branch to start the new commit from.
8081
- `timeouts` (Block, Optional) (see [below for nested schema](#nestedblock--timeouts))

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ require (
88
github.com/hashicorp/terraform-plugin-sdk/v2 v2.14.0
99
github.com/mitchellh/hashstructure v1.1.0
1010
github.com/onsi/gomega v1.19.0
11-
github.com/xanzy/go-gitlab v0.63.0
11+
github.com/xanzy/go-gitlab v0.64.0
1212
golang.org/x/crypto v0.0.0-20220214200702-86341886e292 // indirect
13-
golang.org/x/net v0.0.0-20220412020605-290c469a71a5 // indirect
13+
golang.org/x/net v0.0.0-20220421235706-1d1ef9303861 // indirect
1414
golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5 // indirect
1515
golang.org/x/time v0.0.0-20220411224347-583f2d630306 // indirect
1616
google.golang.org/appengine v1.6.7 // indirect

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,8 @@ github.com/vmihailenco/tagparser v0.1.1 h1:quXMXlA39OCbd2wAdTsGDlK9RkOk6Wuw+x37w
311311
github.com/vmihailenco/tagparser v0.1.1/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI=
312312
github.com/xanzy/go-gitlab v0.63.0 h1:a9fXpKWykUS6dowapFej/2Wjf4aOAEFC1q2ZIcz4IpI=
313313
github.com/xanzy/go-gitlab v0.63.0/go.mod h1:F0QEXwmqiBUxCgJm8fE9S+1veX4XC9Z4cfaAbqwk4YM=
314+
github.com/xanzy/go-gitlab v0.64.0 h1:rMgQdW9S1w3qvNAH2LYpFd2xh7KNLk+JWJd7sorNuTc=
315+
github.com/xanzy/go-gitlab v0.64.0/go.mod h1:F0QEXwmqiBUxCgJm8fE9S+1veX4XC9Z4cfaAbqwk4YM=
314316
github.com/xanzy/ssh-agent v0.3.0 h1:wUMzuKtKilRgBAD1sUb8gOwwRr2FGoBVumcjoOACClI=
315317
github.com/xanzy/ssh-agent v0.3.0/go.mod h1:3s9xbODqPuuhK9JV1R321M/FlMZSBvE5aY6eAcqrDh0=
316318
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
@@ -413,6 +415,8 @@ golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su
413415
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
414416
golang.org/x/net v0.0.0-20220412020605-290c469a71a5 h1:bRb386wvrE+oBNdF1d/Xh9mQrfQ4ecYhW5qJ5GvTGT4=
415417
golang.org/x/net v0.0.0-20220412020605-290c469a71a5/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
418+
golang.org/x/net v0.0.0-20220421235706-1d1ef9303861 h1:yssD99+7tqHWO5Gwh81phT+67hg+KttniBr6UnEXOY8=
419+
golang.org/x/net v0.0.0-20220421235706-1d1ef9303861/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
416420
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
417421
golang.org/x/oauth2 v0.0.0-20181106182150-f42d05182288/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
418422
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=

internal/provider/data_source_gitlab_repository_file_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ func testAccDataSourceGitlabRepositoryFile(src, n string) resource.TestCheckFunc
4040
"size",
4141
"encoding",
4242
"content",
43+
"execute_filemode",
4344
"ref",
4445
"blob_id",
4546
"commit_id",
@@ -64,6 +65,7 @@ resource "gitlab_repository_file" "foo" {
6465
branch = "main"
6566
content = base64encode("Meow goes the cat")
6667
commit_message = "feat: Meow"
68+
execute_filemode = true
6769
}
6870
6971
data "gitlab_repository_file" "foo" {

internal/provider/resource_gitlab_repository_file.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ func resourceGitlabRepositoryFileCreate(ctx context.Context, d *schema.ResourceD
126126
if startBranch, ok := d.GetOk("start_branch"); ok {
127127
options.StartBranch = gitlab.String(startBranch.(string))
128128
}
129+
if executeFilemode, ok := d.GetOk("execute_filemode"); ok {
130+
options.ExecuteFilemode = gitlab.Bool(executeFilemode.(bool))
131+
}
129132

130133
err := resource.RetryContext(ctx, d.Timeout(schema.TimeoutCreate), func() *resource.RetryError {
131134
repositoryFile, _, err := client.RepositoryFiles.CreateFile(project, filePath, options, gitlab.WithContext(ctx))
@@ -227,6 +230,9 @@ func resourceGitlabRepositoryFileUpdate(ctx context.Context, d *schema.ResourceD
227230
if startBranch, ok := d.GetOk("start_branch"); ok {
228231
updateOptions.StartBranch = gitlab.String(startBranch.(string))
229232
}
233+
if executeFilemode, ok := d.GetOk("execute_filemode"); ok {
234+
updateOptions.ExecuteFilemode = gitlab.Bool(executeFilemode.(bool))
235+
}
230236

231237
err = resource.RetryContext(ctx, d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError {
232238
// NOTE: we also re-read the file to obtain an eventually changed `LastCommitID` for which we needed the refresh

internal/provider/resource_gitlab_repository_file_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ resource "gitlab_repository_file" "this" {
366366
author_email = "[email protected]"
367367
author_name = "Meow Meowington"
368368
commit_message = "feature: change launch codes"
369+
execute_filemode = true
369370
}
370371
`, projectID)
371372
}

internal/provider/schema_gitlab_repository_file.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ func gitlabRepositoryFileGetSchema() map[string]*schema.Schema {
4949
Type: schema.TypeString,
5050
Computed: true,
5151
},
52+
"execute_filemode": {
53+
Description: "Enables or disables the execute flag on the file. **Note**: requires GitLab 14.10 or newer.",
54+
Type: schema.TypeBool,
55+
Optional: true,
56+
},
5257
"blob_id": {
5358
Description: "The blob id.",
5459
Type: schema.TypeString,
@@ -76,6 +81,7 @@ func gitlabRepositoryFileToStateMap(project string, repositoryFile *gitlab.File)
7681
stateMap["encoding"] = repositoryFile.Encoding
7782
stateMap["content"] = repositoryFile.Content
7883
stateMap["content_sha256"] = repositoryFile.SHA256
84+
stateMap["execute_filemode"] = repositoryFile.ExecuteFilemode
7985
stateMap["ref"] = repositoryFile.Ref
8086
stateMap["blob_id"] = repositoryFile.BlobID
8187
stateMap["commit_id"] = repositoryFile.CommitID

0 commit comments

Comments
 (0)