Skip to content

Commit f9989cb

Browse files
committed
resource/gitlab_service_jira: support jira_issue_transition_id for GitLab 15.2
1 parent 18006de commit f9989cb

File tree

3 files changed

+13
-20
lines changed

3 files changed

+13
-20
lines changed

docs/resources/service_jira.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ resource "gitlab_service_jira" "jira" {
4646
- `comment_on_event_enabled` (Boolean) Enable comments inside Jira issues on each GitLab event (commit / merge request)
4747
- `commit_events` (Boolean) Enable notifications for commit events
4848
- `issues_events` (Boolean) Enable notifications for issues events.
49-
- `jira_issue_transition_id` (String) The ID of a transition that moves issues to a closed state. You can find this number under the JIRA workflow administration (Administration > Issues > Workflows) by selecting View under Operations of the desired workflow of your project. By default, this ID is set to 2. **Note**: importing this field is currently not supported.
49+
- `jira_issue_transition_id` (String) The ID of a transition that moves issues to a closed state. You can find this number under the JIRA workflow administration (Administration > Issues > Workflows) by selecting View under Operations of the desired workflow of your project. By default, this ID is set to 2. *Note**: importing this field is only supported since GitLab 15.2.
5050
- `job_events` (Boolean) Enable notifications for job events.
5151
- `merge_requests_events` (Boolean) Enable notifications for merge request events
5252
- `note_events` (Boolean) Enable notifications for note events.

internal/provider/resource_gitlab_service_jira.go

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ var _ = registerResource("gitlab_service_jira", func() *schema.Resource {
8181
Sensitive: true,
8282
},
8383
"jira_issue_transition_id": {
84-
Description: "The ID of a transition that moves issues to a closed state. You can find this number under the JIRA workflow administration (Administration > Issues > Workflows) by selecting View under Operations of the desired workflow of your project. By default, this ID is set to 2. **Note**: importing this field is currently not supported.",
84+
Description: "The ID of a transition that moves issues to a closed state. You can find this number under the JIRA workflow administration (Administration > Issues > Workflows) by selecting View under Operations of the desired workflow of your project. By default, this ID is set to 2. *Note**: importing this field is only supported since GitLab 15.2.",
8585
Type: schema.TypeString,
8686
Optional: true,
8787
},
@@ -185,10 +185,12 @@ func resourceGitlabServiceJiraRead(ctx context.Context, d *schema.ResourceData,
185185
d.Set("api_url", jiraService.Properties.APIURL)
186186
d.Set("username", jiraService.Properties.Username)
187187
d.Set("project_key", jiraService.Properties.ProjectKey)
188-
// FIXME: The API or go-gitlab doesn't return `jira_issue_transition_id` properly,
189-
// therefore we don't overwrite the value set in the config, in case it's not set in the API
190-
// response. This currently impacts the import of this attribute.
191-
if jiraService.Properties.JiraIssueTransitionID != "" {
188+
189+
hasJiraIssueTransitionIDFixed, err := isGitLabVersionAtLeast(ctx, client, "15.2")()
190+
if err != nil {
191+
return diag.Errorf("failed to check if `jira_issue_transition_id` is properly supported in GitLab version: %v", err)
192+
}
193+
if hasJiraIssueTransitionIDFixed || jiraService.Properties.JiraIssueTransitionID != "" {
192194
d.Set("jira_issue_transition_id", jiraService.Properties.JiraIssueTransitionID)
193195
}
194196
d.Set("title", jiraService.Title)
@@ -238,14 +240,8 @@ func expandJiraOptions(d *schema.ResourceData) (*gitlab.SetJiraServiceOptions, e
238240
setJiraServiceOptions.CommitEvents = gitlab.Bool(d.Get("commit_events").(bool))
239241
setJiraServiceOptions.MergeRequestsEvents = gitlab.Bool(d.Get("merge_requests_events").(bool))
240242
setJiraServiceOptions.CommentOnEventEnabled = gitlab.Bool(d.Get("comment_on_event_enabled").(bool))
241-
242-
// Set optional properties
243-
if val, ok := d.GetOk("api_url"); ok {
244-
setJiraServiceOptions.APIURL = gitlab.String(val.(string))
245-
}
246-
if val, ok := d.GetOk("jira_issue_transition_id"); ok {
247-
setJiraServiceOptions.JiraIssueTransitionID = gitlab.String(val.(string))
248-
}
243+
setJiraServiceOptions.APIURL = gitlab.String(d.Get("api_url").(string))
244+
setJiraServiceOptions.JiraIssueTransitionID = gitlab.String(d.Get("jira_issue_transition_id").(string))
249245

250246
return &setJiraServiceOptions, nil
251247
}

internal/provider/resource_gitlab_service_jira_test.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ func TestAccGitlabServiceJira_basic(t *testing.T) {
4040
ResourceName: jiraResourceName,
4141
ImportState: true,
4242
ImportStateVerify: true,
43-
// FIXME: there is a bug in the GitLab API which causes the `jira_issue_transition_id` field
44-
// to be empty in the response. Therefore, we ignore it for now in the import.
43+
// TODO: as soon as we remove support for GitLab < 15.2 we can remove ignoring `jira_issue_transition_id`.
4544
// See https://gitlab.com/gitlab-org/gitlab/-/issues/362437
4645
ImportStateVerifyIgnore: []string{"password", "jira_issue_transition_id"},
4746
},
@@ -65,8 +64,7 @@ func TestAccGitlabServiceJira_basic(t *testing.T) {
6564
ResourceName: jiraResourceName,
6665
ImportState: true,
6766
ImportStateVerify: true,
68-
// FIXME: there is a bug in the GitLab API which causes the `jira_issue_transition_id` field
69-
// to be empty in the response. Therefore, we ignore it for now in the import.
67+
// TODO: as soon as we remove support for GitLab < 15.2 we can remove ignoring `jira_issue_transition_id`.
7068
// See https://gitlab.com/gitlab-org/gitlab/-/issues/362437
7169
ImportStateVerifyIgnore: []string{"password", "jira_issue_transition_id"},
7270
},
@@ -89,8 +87,7 @@ func TestAccGitlabServiceJira_basic(t *testing.T) {
8987
ResourceName: jiraResourceName,
9088
ImportState: true,
9189
ImportStateVerify: true,
92-
// FIXME: there is a bug in the GitLab API which causes the `jira_issue_transition_id` field
93-
// to be empty in the response. Therefore, we ignore it for now in the import.
90+
// TODO: as soon as we remove support for GitLab < 15.2 we can remove ignoring `jira_issue_transition_id`.
9491
// See https://gitlab.com/gitlab-org/gitlab/-/issues/362437
9592
ImportStateVerifyIgnore: []string{"password", "jira_issue_transition_id"},
9693
},

0 commit comments

Comments
 (0)