Skip to content

Commit

Permalink
Merge branch 'main' into issue-782
Browse files Browse the repository at this point in the history
  • Loading branch information
marceloboeira authored Feb 12, 2022
2 parents ef08e4b + 2dea817 commit 0b73948
Show file tree
Hide file tree
Showing 28 changed files with 1,052 additions and 79 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/issue-comment-created.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,19 @@ permissions:
jobs:
remove-labels:
runs-on: ubuntu-latest
# This job contains steps which are expected to fail.
continue-on-error: true
steps:
- name: Is comment from a collaborator?
uses: octokit/[email protected]
with:
route: GET /repos/${{ github.repository }}/collaborators/${{ github.event.sender.login }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Only remove labels if they are NOT a collaborator.
# Reason being, a collaborator may post a comment and add a waiting-response label.
- uses: actions-ecosystem/action-remove-labels@v1
if: ${{ failure() }}
with:
labels: |
stale
Expand Down
12 changes: 12 additions & 0 deletions .github/workflows/issue-opened.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,21 @@ permissions:
jobs:
add-labels:
runs-on: ubuntu-latest
# This job contains steps which are expected to fail.
continue-on-error: true
steps:
- name: Is opened by a collaborator?
uses: octokit/[email protected]
with:
route: GET /repos/${{ github.repository }}/collaborators/${{ github.event.sender.login }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Only add triage labels if they are NOT a collaborator.
# This prevents the needs-triage label from being added.
- uses: actions/checkout@v2
if: ${{ failure() }}
- uses: github/[email protected]
if: ${{ failure() }}
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
configuration-path: .github/labeler-issue-triage.yml
Expand Down
1 change: 1 addition & 0 deletions docs/data-sources/projects.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ Read-Only:
- **avatar_url** (String)
- **build_coverage_regex** (String)
- **ci_config_path** (String)
- **ci_forward_deployment_enabled** (Boolean)
- **container_registry_enabled** (Boolean)
- **created_at** (String)
- **creator_id** (Number)
Expand Down
64 changes: 64 additions & 0 deletions docs/resources/group_access_token.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "gitlab_group_access_token Resource - terraform-provider-gitlab"
subcategory: ""
description: |-
This resource allows you to create and manage Group Access Token for your GitLab Groups. (Introduced in GitLab 14.7)
---

# gitlab_group_access_token (Resource)

This resource allows you to create and manage Group Access Token for your GitLab Groups. (Introduced in GitLab 14.7)

## Example Usage

```terraform
resource "gitlab_group_access_token" "example" {
group = "25"
name = "Example project access token"
expires_at = "2020-03-14"
access_level = "developer"
scopes = ["api"]
}
resource "gitlab_group_variable" "example" {
group = "25"
key = "gat"
value = gitlab_group_access_token.example.token
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- **group** (String) The ID or path of the group to add the group access token to.
- **name** (String) The name of the group access token.
- **scopes** (Set of String) The scope for the group access token. It determines the actions which can be performed when authenticating with this token. Valid values are: `api`, `read_api`, `read_registry`, `write_registry`, `read_repository`, `write_repository`.

### Optional

- **access_level** (String) The access level for the group access token. Valid values are: `guest`, `reporter`, `developer`, `maintainer`.
- **expires_at** (String) The token expires at midnight UTC on that date. The date must be in the format YYYY-MM-DD. Default is never.
- **id** (String) The ID of this resource.

### Read-Only

- **active** (Boolean) True if the token is active.
- **created_at** (String) Time the token has been created, RFC3339 format.
- **revoked** (Boolean) True if the token is revoked.
- **token** (String, Sensitive) The group access token. This is only populated when creating a new group access token. This attribute is not available for imported resources.
- **user_id** (Number) The user id associated to the token.

## Import

Import is supported using the following syntax:

```shell
# A GitLab Group Access Token can be imported using a key composed of `<group-id>:<token-id>`, e.g.
terraform import gitlab_group_access_token.example "12345:1"

# ATTENTION: the `token` resource attribute is not available for imported resources as this information cannot be read from the GitLab API.
```
1 change: 1 addition & 0 deletions docs/resources/project.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ resource "gitlab_project" "example-two" {
- **archived** (Boolean) Whether the project is in read-only mode (archived). Repositories can be archived/unarchived by toggling this parameter.
- **build_coverage_regex** (String) Test coverage parsing for the project.
- **ci_config_path** (String) Custom Path to CI config file.
- **ci_forward_deployment_enabled** (Boolean) When a new deployment job starts, skip older deployment jobs that are still pending.
- **container_registry_enabled** (Boolean) Enable container registry for the project.
- **default_branch** (String) The default branch for the project.
- **description** (String) A description of the project.
Expand Down
1 change: 1 addition & 0 deletions docs/resources/user.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ resource "gitlab_user" "example" {
- **projects_limit** (Number) Integer, defaults to 0. Number of projects user can create.
- **reset_password** (Boolean) Boolean, defaults to false. Send user password reset link.
- **skip_confirmation** (Boolean) Boolean, defaults to true. Whether to skip confirmation.
- **state** (String) String, defaults to 'active'. The state of the user account. Valid values are either 'active' or 'blocked'

## Import

Expand Down
4 changes: 4 additions & 0 deletions examples/resources/gitlab_group_access_token/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# A GitLab Group Access Token can be imported using a key composed of `<group-id>:<token-id>`, e.g.
terraform import gitlab_group_access_token.example "12345:1"

# ATTENTION: the `token` resource attribute is not available for imported resources as this information cannot be read from the GitLab API.
14 changes: 14 additions & 0 deletions examples/resources/gitlab_group_access_token/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
resource "gitlab_group_access_token" "example" {
group = "25"
name = "Example project access token"
expires_at = "2020-03-14"
access_level = "developer"

scopes = ["api"]
}

resource "gitlab_group_variable" "example" {
group = "25"
key = "gat"
value = gitlab_group_access_token.example.token
}
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ go 1.16
require (
github.com/apparentlymart/go-cidr v1.1.0 // indirect
github.com/aws/aws-sdk-go v1.37.0 // indirect
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
github.com/hashicorp/go-retryablehttp v0.7.0
github.com/hashicorp/hcl/v2 v2.8.2 // indirect
github.com/hashicorp/terraform-plugin-sdk/v2 v2.10.1
github.com/mitchellh/hashstructure v1.1.0
github.com/onsi/gomega v1.18.1
github.com/xanzy/go-gitlab v0.54.4
github.com/xanzy/go-gitlab v0.55.0
google.golang.org/api v0.34.0 // indirect
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,8 @@ github.com/vmihailenco/msgpack v4.0.4+incompatible h1:dSLoQfGFAo3F6OoNhwUmLwVgaU
github.com/vmihailenco/msgpack v4.0.4+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
github.com/vmihailenco/msgpack/v4 v4.3.12/go.mod h1:gborTTJjAo/GWTqqRjrLCn9pgNN+NXzzngzBKDPIqw4=
github.com/vmihailenco/tagparser v0.1.1/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI=
github.com/xanzy/go-gitlab v0.54.4 h1:3CFEdQ9O+bFx3BsyuOK0gqgLPwnT2rwnPOjudV07wTw=
github.com/xanzy/go-gitlab v0.54.4/go.mod h1:F0QEXwmqiBUxCgJm8fE9S+1veX4XC9Z4cfaAbqwk4YM=
github.com/xanzy/go-gitlab v0.55.0 h1:klg5EgPYtsF6QlnVFpOpv/FmhqQxCUUG7zLJIL1NKz8=
github.com/xanzy/go-gitlab v0.55.0/go.mod h1:F0QEXwmqiBUxCgJm8fE9S+1veX4XC9Z4cfaAbqwk4YM=
github.com/xanzy/ssh-agent v0.3.0 h1:wUMzuKtKilRgBAD1sUb8gOwwRr2FGoBVumcjoOACClI=
github.com/xanzy/ssh-agent v0.3.0/go.mod h1:3s9xbODqPuuhK9JV1R321M/FlMZSBvE5aY6eAcqrDh0=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down
26 changes: 21 additions & 5 deletions internal/provider/data_source_gitlab_group_membership.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ var _ = registerDataSource("gitlab_group_membership", func() *schema.Resource {
func dataSourceGitlabGroupMembershipRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(*gitlab.Client)

var gm []*gitlab.GroupMember
var group *gitlab.Group
var err error

Expand Down Expand Up @@ -129,15 +128,32 @@ func dataSourceGitlabGroupMembershipRead(ctx context.Context, d *schema.Resource
log.Printf("[INFO] Reading Gitlab group memberships")

// Get group memberships
gm, _, err = client.Groups.ListGroupMembers(group.ID, &gitlab.ListGroupMembersOptions{}, gitlab.WithContext(ctx))
if err != nil {
return diag.FromErr(err)
listOptions := &gitlab.ListGroupMembersOptions{
ListOptions: gitlab.ListOptions{
PerPage: 20,
Page: 1,
},
}

var allGms []*gitlab.GroupMember
for {
gms, resp, err := client.Groups.ListGroupMembers(group.ID, listOptions, gitlab.WithContext(ctx))
if err != nil {
return diag.FromErr(err)
}

allGms = append(allGms, gms...)

if resp.NextPage == 0 {
break
}
listOptions.Page = resp.NextPage
}

d.Set("group_id", group.ID)
d.Set("full_path", group.FullPath)

d.Set("members", flattenGitlabMembers(d, gm)) // lintignore: XR004 // TODO: Resolve this tfproviderlint issue
d.Set("members", flattenGitlabMembers(d, allGms)) // lintignore: XR004 // TODO: Resolve this tfproviderlint issue

var optionsHash strings.Builder
optionsHash.WriteString(strconv.Itoa(group.ID))
Expand Down
29 changes: 29 additions & 0 deletions internal/provider/data_source_gitlab_group_membership_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,27 @@ func TestAccDataSourceGitlabMembership_basic(t *testing.T) {
})
}

func TestAccDataSourceGitlabMembership_pagination(t *testing.T) {
testAccCheck(t)

userCount := 21

group := testAccCreateGroups(t, 1)[0]
users := testAccCreateUsers(t, userCount)
testAccAddGroupMembers(t, group.ID, users)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: testAccDataSourceGitlabGroupMembershipPagination(group.ID),
Check: resource.TestCheckResourceAttr("data.gitlab_group_membership.this", "members.#", fmt.Sprintf("%d", userCount)),
},
},
})
}

func testAccDataSourceGitlabGroupMembershipConfig(rInt int) string {
return fmt.Sprintf(`
resource "gitlab_group" "foo" {
Expand Down Expand Up @@ -89,3 +110,11 @@ data "gitlab_group_membership" "foomaintainers" {
access_level = "maintainer"
}`, rInt, rInt)
}

func testAccDataSourceGitlabGroupMembershipPagination(groupId int) string {
return fmt.Sprintf(`
data "gitlab_group_membership" "this" {
group_id = "%d"
access_level = "developer"
}`, groupId)
}
53 changes: 42 additions & 11 deletions internal/provider/data_source_gitlab_projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ func flattenProjects(projects []*gitlab.Project) (values []map[string]interface{
"custom_attributes": project.CustomAttributes,
"packages_enabled": project.PackagesEnabled,
"build_coverage_regex": project.BuildCoverageRegex,
"ci_forward_deployment_enabled": project.CIForwardDeploymentEnabled,
}
values = append(values, v)
}
Expand Down Expand Up @@ -771,6 +772,11 @@ var _ = registerDataSource("gitlab_projects", func() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"ci_forward_deployment_enabled": {
Description: "When a new deployment job starts, skip older deployment jobs that are still pending.",
Type: schema.TypeBool,
Computed: true,
},
},
},
},
Expand Down Expand Up @@ -811,15 +817,24 @@ func dataSourceGitlabProjectsRead(ctx context.Context, d *schema.ResourceData, m
var withProgrammingLanguagePtr *string
var withSharedPtr *bool

if data, ok := d.GetOk("archived"); ok {
// NOTE: `GetOkExists()` is deprecated, but until there is a replacement we need to use it.
// see https://github.com/hashicorp/terraform-plugin-sdk/pull/350#issuecomment-597888969

// nolint:staticcheck // SA1019 ignore deprecated GetOkExists
// lintignore: XR001 // TODO: replace with alternative for GetOkExists
if data, ok := d.GetOkExists("archived"); ok {
d := data.(bool)
archivedPtr = &d
}
if data, ok := d.GetOk("include_subgroups"); ok {
// nolint:staticcheck // SA1019 ignore deprecated GetOkExists
// lintignore: XR001 // TODO: replace with alternative for GetOkExists
if data, ok := d.GetOkExists("include_subgroups"); ok {
d := data.(bool)
includeSubGroupsPtr = &d
}
if data, ok := d.GetOk("membership"); ok {
// nolint:staticcheck // SA1019 ignore deprecated GetOkExists
// lintignore: XR001 // TODO: replace with alternative for GetOkExists
if data, ok := d.GetOkExists("membership"); ok {
d := data.(bool)
membershipPtr = &d
}
Expand All @@ -830,50 +845,66 @@ func dataSourceGitlabProjectsRead(ctx context.Context, d *schema.ResourceData, m
d := data.(string)
orderByPtr = &d
}
if data, ok := d.GetOk("owned"); ok {
// nolint:staticcheck // SA1019 ignore deprecated GetOkExists
// lintignore: XR001 // TODO: replace with alternative for GetOkExists
if data, ok := d.GetOkExists("owned"); ok {
d := data.(bool)
ownedPtr = &d
}
if data, ok := d.GetOk("search"); ok {
d := data.(string)
searchPtr = &d
}
if data, ok := d.GetOk("simple"); ok {
// nolint:staticcheck // SA1019 ignore deprecated GetOkExists
// lintignore: XR001 // TODO: replace with alternative for GetOkExists
if data, ok := d.GetOkExists("simple"); ok {
d := data.(bool)
simplePtr = &d
}
if data, ok := d.GetOk("sort"); ok {
d := data.(string)
sortPtr = &d
}
if data, ok := d.GetOk("starred"); ok {
// nolint:staticcheck // SA1019 ignore deprecated GetOkExists
// lintignore: XR001 // TODO: replace with alternative for GetOkExists
if data, ok := d.GetOkExists("starred"); ok {
d := data.(bool)
starredPtr = &d
}
if data, ok := d.GetOk("statistics"); ok {
// nolint:staticcheck // SA1019 ignore deprecated GetOkExists
// lintignore: XR001 // TODO: replace with alternative for GetOkExists
if data, ok := d.GetOkExists("statistics"); ok {
d := data.(bool)
statisticsPtr = &d
}
if data, ok := d.GetOk("visibility"); ok {
visibilityPtr = gitlab.Visibility(gitlab.VisibilityValue(data.(string)))
}
if data, ok := d.GetOk("with_custom_attributes"); ok {
// nolint:staticcheck // SA1019 ignore deprecated GetOkExists
// lintignore: XR001 // TODO: replace with alternative for GetOkExists
if data, ok := d.GetOkExists("with_custom_attributes"); ok {
d := data.(bool)
withCustomAttributesPtr = &d
}
if data, ok := d.GetOk("with_issues_enabled"); ok {
// nolint:staticcheck // SA1019 ignore deprecated GetOkExists
// lintignore: XR001 // TODO: replace with alternative for GetOkExists
if data, ok := d.GetOkExists("with_issues_enabled"); ok {
d := data.(bool)
withIssuesEnabledPtr = &d
}
if data, ok := d.GetOk("with_merge_requests_enabled"); ok {
// nolint:staticcheck // SA1019 ignore deprecated GetOkExists
// lintignore: XR001 // TODO: replace with alternative for GetOkExists
if data, ok := d.GetOkExists("with_merge_requests_enabled"); ok {
d := data.(bool)
withMergeRequestsEnabledPtr = &d
}
if data, ok := d.GetOk("with_programming_language"); ok {
d := data.(string)
withProgrammingLanguagePtr = &d
}
if data, ok := d.GetOk("with_shared"); ok {
// nolint:staticcheck // SA1019 ignore deprecated GetOkExists
// lintignore: XR001 // TODO: replace with alternative for GetOkExists
if data, ok := d.GetOkExists("with_shared"); ok {
d := data.(bool)
withSharedPtr = &d
}
Expand Down
Loading

0 comments on commit 0b73948

Please sign in to comment.