Skip to content

Commit e919cdb

Browse files
committed
Review 2
1 parent f390fa2 commit e919cdb

10 files changed

+73
-61
lines changed

docs/data-sources/project_milestone.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ data "gitlab_project_milestone" "example" {
3535
### Required
3636

3737
- `milestone_id` (Number) The instance-wide ID of the project’s milestone.
38-
- `project_id` (String) The ID or URL-encoded path of the project owned by the authenticated user.
38+
- `project_id` (Number) The project ID of milestone.
3939

4040
### Read-Only
4141

@@ -45,6 +45,7 @@ data "gitlab_project_milestone" "example" {
4545
- `expired` (Boolean) Bool, true if milestore expired.
4646
- `id` (String) The ID of this resource.
4747
- `iid` (Number) The ID of the project's milestone.
48+
- `project` (String) The ID or URL-encoded path of the project owned by the authenticated user.
4849
- `start_date` (String) The start date of the milestone. Date time string in the format YYYY-MM-DD, for example 2016-03-11.
4950
- `state` (String) The state of the milestone. Valid values are: `active`, `closed`.
5051
- `title` (String) The title of a milestone.

docs/data-sources/project_milestones.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ data "gitlab_project_milestones" "example" {
3232

3333
### Required
3434

35-
- `project_id` (String) The ID or URL-encoded path of the project owned by the authenticated user.
35+
- `project` (String) The ID or URL-encoded path of the project owned by the authenticated user.
3636

3737
### Optional
3838

@@ -58,7 +58,8 @@ Read-Only:
5858
- `expired` (Boolean)
5959
- `iid` (Number)
6060
- `milestone_id` (Number)
61-
- `project_id` (String)
61+
- `project` (String)
62+
- `project_id` (Number)
6263
- `start_date` (String)
6364
- `state` (String)
6465
- `title` (String)

docs/resources/project_milestone.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ resource "gitlab_project_milestone" "example" {
3434

3535
### Required
3636

37-
- `project_id` (String) The ID or URL-encoded path of the project owned by the authenticated user.
37+
- `project` (String) The ID or URL-encoded path of the project owned by the authenticated user.
3838
- `title` (String) The title of a milestone.
3939

4040
### Optional
@@ -52,6 +52,7 @@ resource "gitlab_project_milestone" "example" {
5252
- `id` (String) The ID of this resource.
5353
- `iid` (Number) The ID of the project's milestone.
5454
- `milestone_id` (Number) The instance-wide ID of the project’s milestone.
55+
- `project_id` (Number) The project ID of milestone.
5556
- `web_url` (String) The web URL of the milestone.
5657

5758
## Import

internal/provider/data_source_gitlab_project_milestone.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ var _ = registerDataSource("gitlab_project_milestone", func() *schema.Resource {
2121

2222
func dataSourceGitlabProjectMilestoneRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
2323
client := meta.(*gitlab.Client)
24-
project := d.Get("project_id").(string)
24+
project := d.Get("project").(string)
2525
milestoneID := d.Get("milestone_id").(int)
2626

2727
milestone, _, err := client.Milestones.GetMilestone(project, milestoneID, gitlab.WithContext(ctx))
2828
if err != nil {
2929
return diag.FromErr(err)
3030
}
31-
d.SetId(resourceGitLabProjectMilestoneBuildId(project, milestoneID))
32-
stateMap := gitlabProjectMilestoneToStateMap(milestone)
31+
d.SetId(resourceGitLabProjectMilestoneBuildId(project, milestone.ID))
32+
stateMap := gitlabProjectMilestoneToStateMap(project, milestone)
3333

3434
if err := setStateMapInResourceData(stateMap, d); err != nil {
3535
return diag.FromErr(err)

internal/provider/data_source_gitlab_project_milestone_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//go:build acceptance
2+
// +build acceptance
3+
14
package provider
25

36
import (
@@ -8,19 +11,17 @@ import (
811
)
912

1013
func TestAccDataSourceGitlabProjectMilestone_basic(t *testing.T) {
11-
testAccCheck(t)
1214

1315
testProject := testAccCreateProject(t)
1416
testMilestone := testAccAddProjectMilestones(t, testProject, 1)[0]
1517

1618
resource.Test(t, resource.TestCase{
17-
PreCheck: func() { testAccPreCheck(t) },
1819
ProviderFactories: providerFactories,
1920
Steps: []resource.TestStep{
2021
{
2122
Config: fmt.Sprintf(`
2223
data "gitlab_project_milestone" "this" {
23-
project_id = "%d"
24+
project = "%d"
2425
milestone_id = "%d"
2526
}`, testProject.ID, testMilestone.ID),
2627
Check: resource.ComposeTestCheckFunc(

internal/provider/data_source_gitlab_project_milestones.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ var _ = registerDataSource("gitlab_project_milestones", func() *schema.Resource
2222

2323
ReadContext: dataSourceGitlabProjectMilestonesRead,
2424
Schema: map[string]*schema.Schema{
25-
"project_id": {
25+
"project": {
2626
Description: "The ID or URL-encoded path of the project owned by the authenticated user.",
2727
Type: schema.TypeString,
2828
Required: true,
@@ -69,7 +69,7 @@ var _ = registerDataSource("gitlab_project_milestones", func() *schema.Resource
6969
func dataSourceGitlabProjectMilestonesRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
7070
client := meta.(*gitlab.Client)
7171

72-
project := d.Get("project_id").(string)
72+
project := d.Get("project").(string)
7373
options := gitlab.ListMilestonesOptions{
7474
ListOptions: gitlab.ListOptions{
7575
PerPage: 20,
@@ -115,16 +115,16 @@ func dataSourceGitlabProjectMilestonesRead(ctx context.Context, d *schema.Resour
115115

116116
log.Printf("[DEBUG] get gitlab milestones from project: %s", project)
117117
d.SetId(fmt.Sprintf("%s:%d", project, optionsHash))
118-
if err = d.Set("milestones", flattenGitlabProjectMilestones(milestones)); err != nil {
118+
if err = d.Set("milestones", flattenGitlabProjectMilestones(project, milestones)); err != nil {
119119
return diag.Errorf("Failed to set milestones to state: %v", err)
120120
}
121121

122122
return nil
123123
}
124124

125-
func flattenGitlabProjectMilestones(milestones []*gitlab.Milestone) (values []map[string]interface{}) {
125+
func flattenGitlabProjectMilestones(project string, milestones []*gitlab.Milestone) (values []map[string]interface{}) {
126126
for _, milestone := range milestones {
127-
values = append(values, gitlabProjectMilestoneToStateMap(milestone))
127+
values = append(values, gitlabProjectMilestoneToStateMap(project, milestone))
128128
}
129129
return values
130130
}

internal/provider/data_source_gitlab_project_milestones_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//go:build acceptance
2+
// +build acceptance
3+
14
package provider
25

36
import (
@@ -8,13 +11,11 @@ import (
811
)
912

1013
func TestAccDataGitlabProjectMilestones_basic(t *testing.T) {
11-
testAccCheck(t)
1214

1315
testProject := testAccCreateProject(t)
1416
testMilestones := testAccAddProjectMilestones(t, testProject, 2)
1517

1618
resource.Test(t, resource.TestCase{
17-
PreCheck: func() { testAccPreCheck(t) },
1819
ProviderFactories: providerFactories,
1920
Steps: []resource.TestStep{
2021
{

internal/provider/resource_gitlab_project_milestone.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ var _ = registerResource("gitlab_project_milestone", func() *schema.Resource {
3535

3636
func resourceGitlabProjectMilestoneCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
3737
client := meta.(*gitlab.Client)
38-
project := d.Get("project_id").(string)
38+
project := d.Get("project").(string)
3939
title := d.Get("title").(string)
4040

4141
options := &gitlab.CreateMilestoneOptions{
@@ -100,7 +100,7 @@ func resourceGitlabProjectMilestoneRead(ctx context.Context, d *schema.ResourceD
100100
return diag.FromErr(err)
101101
}
102102

103-
stateMap := gitlabProjectMilestoneToStateMap(milestone)
103+
stateMap := gitlabProjectMilestoneToStateMap(project, milestone)
104104
if err = setStateMapInResourceData(stateMap, d); err != nil {
105105
return diag.FromErr(err)
106106
}
@@ -158,10 +158,10 @@ func resourceGitlabProjectMilestoneDelete(ctx context.Context, d *schema.Resourc
158158
return diag.FromErr(err)
159159
}
160160

161-
log.Printf("[debug] delete gitlab milestone in project %s with ID %d", project, milestoneID)
161+
log.Printf("[DEBUG] delete gitlab milestone in project %s with ID %d", project, milestoneID)
162162
resp, err := client.Milestones.DeleteMilestone(project, milestoneID, gitlab.WithContext(ctx))
163163
if err != nil {
164-
log.Printf("[debug] failed to delete gitlab milestone in project %s with ID %d. Response %v", project, milestoneID, resp)
164+
log.Printf("[DEBUG] failed to delete gitlab milestone in project %s with ID %d. Response %v", project, milestoneID, resp)
165165
return diag.FromErr(err)
166166
}
167167
return nil

internal/provider/resource_gitlab_project_milestone_test.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//go:build acceptance
2+
// +build acceptance
3+
14
package provider
25

36
import (
@@ -11,23 +14,21 @@ import (
1114
)
1215

1316
func TestAccGitlabProjectMilestone_basic(t *testing.T) {
14-
testAccCheck(t)
1517

1618
rInt1, rInt2 := acctest.RandInt(), acctest.RandInt()
1719
project := testAccCreateProject(t)
1820

1921
resource.Test(t, resource.TestCase{
20-
PreCheck: func() { testAccPreCheck(t) },
2122
ProviderFactories: providerFactories,
2223
CheckDestroy: testAccCheckGitlabProjectMilestoneDestroy,
2324
Steps: []resource.TestStep{
2425
{
2526
// create Milestone with required values only
2627
Config: fmt.Sprintf(`
2728
resource "gitlab_project_milestone" "this" {
28-
project_id = "%d"
29-
title = "test-%d"
30-
}`, project.ID, rInt1),
29+
project = "%v"
30+
title = "test-%d"
31+
}`, project.PathWithNamespace, rInt1),
3132
Check: resource.ComposeTestCheckFunc(
3233
resource.TestCheckResourceAttrSet("gitlab_project_milestone.this", "iid"),
3334
resource.TestCheckResourceAttrSet("gitlab_project_milestone.this", "milestone_id"),
@@ -47,8 +48,8 @@ func TestAccGitlabProjectMilestone_basic(t *testing.T) {
4748
// update some Milestone attributes
4849
Config: fmt.Sprintf(`
4950
resource "gitlab_project_milestone" "this" {
50-
project_id = "%[1]d"
51-
title = "test-%[2]d"
51+
project = "%[1]d"
52+
title = "test-%[2]d"
5253
description = "test-%[2]d"
5354
start_date = "2022-04-10"
5455
due_date = "2022-04-15"
@@ -78,12 +79,12 @@ func testAccCheckGitlabProjectMilestoneDestroy(s *terraform.State) error {
7879
if rs.Type != "gitlab_project_milestone" {
7980
continue
8081
}
81-
project, milestoneID, err := resourceGitLabProjectMilestoneParseId(rs.Primary.ID)
82+
projectID, milestoneID, err := resourceGitLabProjectMilestoneParseId(rs.Primary.ID)
8283
if err != nil {
8384
return err
8485
}
8586

86-
milestone, _, err := testGitlabClient.Milestones.GetMilestone(project, milestoneID)
87+
milestone, _, err := testGitlabClient.Milestones.GetMilestone(projectID, milestoneID)
8788
if err == nil && milestone != nil {
8889
return errors.New("Milestone still exists")
8990
}

internal/provider/schema_gitlab_project_milestone.go

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,7 @@ func gitlabProjectMilestoneGetSchema() map[string]*schema.Schema {
1313
validMilestoneStates := []string{"active", "closed"}
1414

1515
return map[string]*schema.Schema{
16-
"iid": {
17-
Description: "The ID of the project's milestone.",
18-
Type: schema.TypeInt,
19-
Computed: true,
20-
},
21-
"milestone_id": {
22-
Description: "The instance-wide ID of the project’s milestone.",
23-
Type: schema.TypeInt,
24-
Computed: true,
25-
},
26-
"project_id": {
16+
"project": {
2717
Description: "The ID or URL-encoded path of the project owned by the authenticated user.",
2818
Type: schema.TypeString,
2919
ForceNew: true,
@@ -51,50 +41,66 @@ func gitlabProjectMilestoneGetSchema() map[string]*schema.Schema {
5141
Optional: true,
5242
ValidateDiagFunc: isISO6801Date,
5343
},
54-
"updated_at": {
55-
Description: "The last update time of the milestone. Date time string, ISO 8601 formatted, for example 2016-03-11T03:45:40Z.",
44+
// NOTE: not part of `CREATE`, but part of `UPDATE` with the `state_event` field.
45+
"state": {
46+
Description: fmt.Sprintf("The state of the milestone. Valid values are: %s.", renderValueListForDocs(validMilestoneStates)),
47+
Type: schema.TypeString,
48+
Optional: true,
49+
Default: "active",
50+
ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice(validMilestoneStates, false)),
51+
},
52+
"created_at": {
53+
Description: "The time of creation of the milestone. Date time string, ISO 8601 formatted, for example 2016-03-11T03:45:40Z.",
5654
Type: schema.TypeString,
57-
Computed: true,
5855
Optional: true,
56+
Computed: true,
5957
// NOTE: since RFC3339 is pretty much a subset of ISO8601 and actually expected by GitLab,
6058
// we use it here to avoid having to parse the string ourselves.
6159
ValidateDiagFunc: validation.ToDiagFunc(validation.IsRFC3339Time),
6260
},
63-
"created_at": {
64-
Description: "The time of creation of the milestone. Date time string, ISO 8601 formatted, for example 2016-03-11T03:45:40Z.",
61+
"updated_at": {
62+
Description: "The last update time of the milestone. Date time string, ISO 8601 formatted, for example 2016-03-11T03:45:40Z.",
6563
Type: schema.TypeString,
66-
Computed: true,
6764
Optional: true,
65+
Computed: true,
6866
// NOTE: since RFC3339 is pretty much a subset of ISO8601 and actually expected by GitLab,
6967
// we use it here to avoid having to parse the string ourselves.
7068
ValidateDiagFunc: validation.ToDiagFunc(validation.IsRFC3339Time),
7169
},
72-
// NOTE: not part of `CREATE`, but part of `UPDATE` with the `state_event` field.
73-
"state": {
74-
Description: fmt.Sprintf("The state of the milestone. Valid values are: %s.", renderValueListForDocs(validMilestoneStates)),
75-
Type: schema.TypeString,
76-
Optional: true,
77-
Default: "active",
78-
ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice(validMilestoneStates, false)),
70+
"expired": {
71+
Description: "Bool, true if milestore expired.",
72+
Type: schema.TypeBool,
73+
Computed: true,
74+
},
75+
"iid": {
76+
Description: "The ID of the project's milestone.",
77+
Type: schema.TypeInt,
78+
Computed: true,
79+
},
80+
"milestone_id": {
81+
Description: "The instance-wide ID of the project’s milestone.",
82+
Type: schema.TypeInt,
83+
Computed: true,
84+
},
85+
"project_id": {
86+
Description: "The project ID of milestone.",
87+
Type: schema.TypeInt,
88+
Computed: true,
7989
},
8090
"web_url": {
8191
Description: "The web URL of the milestone.",
8292
Type: schema.TypeString,
8393
Computed: true,
8494
},
85-
"expired": {
86-
Description: "Bool, true if milestore expired.",
87-
Type: schema.TypeBool,
88-
Computed: true,
89-
},
9095
}
9196
}
9297

93-
func gitlabProjectMilestoneToStateMap(milestone *gitlab.Milestone) map[string]interface{} {
98+
func gitlabProjectMilestoneToStateMap(project string, milestone *gitlab.Milestone) map[string]interface{} {
9499
stateMap := make(map[string]interface{})
95100
stateMap["iid"] = milestone.IID
96101
stateMap["milestone_id"] = milestone.ID
97-
stateMap["project_id"] = fmt.Sprintf("%d", milestone.ProjectID)
102+
stateMap["project"] = project
103+
stateMap["project_id"] = milestone.ProjectID
98104
stateMap["title"] = milestone.Title
99105
stateMap["description"] = milestone.Description
100106
if milestone.DueDate != nil {

0 commit comments

Comments
 (0)