-
Notifications
You must be signed in to change notification settings - Fork 1
/
data_source_jira_issue_type.go
107 lines (92 loc) · 3.3 KB
/
data_source_jira_issue_type.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package atlassian
import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/provider"
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
"github.com/hashicorp/terraform-plugin-framework/types"
)
var _ provider.DataSourceType = jiraIssueTypeDataSourceType{}
var _ datasource.DataSource = jiraIssueTypeDataSource{}
type jiraIssueTypeDataSourceType struct{}
type jiraIssueTypeDataSourceData struct {
ID types.String `tfsdk:"id"`
Name types.String `tfsdk:"name"`
Description types.String `tfsdk:"description"`
HierarchyLevel types.Int64 `tfsdk:"hierarchy_level"`
IconURL types.String `tfsdk:"icon_url"`
AvatarID types.Int64 `tfsdk:"avatar_id"`
}
type jiraIssueTypeDataSource struct {
p atlassianProvider
}
func (t jiraIssueTypeDataSourceType) GetSchema(ctx context.Context) (tfsdk.Schema, diag.Diagnostics) {
return tfsdk.Schema{
MarkdownDescription: "Jira Issue Type Data Source",
Attributes: map[string]tfsdk.Attribute{
"id": {
MarkdownDescription: "The ID of the issue type.",
Type: types.StringType,
Required: true,
},
"name": {
MarkdownDescription: "The name of the issue type.",
Type: types.StringType,
Computed: true,
},
"description": {
MarkdownDescription: "The description of the issue type.",
Type: types.StringType,
Computed: true,
},
"hierarchy_level": {
MarkdownDescription: "The hierarchy level of the issue type.",
Type: types.Int64Type,
Computed: true,
},
"icon_url": {
MarkdownDescription: "The URL of the issue type's avatar.",
Type: types.StringType,
Computed: true,
},
"avatar_id": {
MarkdownDescription: "The ID of the issue type's avatar.",
Type: types.Int64Type,
Computed: true,
},
},
Version: 1,
}, nil
}
func (t jiraIssueTypeDataSourceType) NewDataSource(ctx context.Context, in provider.Provider) (datasource.DataSource, diag.Diagnostics) {
provider, diags := convertProviderType(in)
return jiraIssueTypeDataSource{
p: provider,
}, diags
}
func (d jiraIssueTypeDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var data jiraIssueTypeDataSourceData
diags := req.Config.Get(ctx, &data)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}
returnedIssueType, res, err := d.p.jira.Issue.Type.Get(ctx, data.ID.Value)
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to get issue type, got error: %s\n%s", err.Error(), res.Bytes.String()))
return
}
data.ID = types.String{Value: returnedIssueType.ID}
data.Name = types.String{Value: returnedIssueType.Name}
data.Description = types.String{Value: returnedIssueType.Description}
data.HierarchyLevel = types.Int64{Value: int64(returnedIssueType.HierarchyLevel)}
data.IconURL = types.String{Value: returnedIssueType.IconURL}
data.AvatarID = types.Int64{Value: int64(returnedIssueType.AvatarID)}
diags = resp.State.Set(ctx, &data)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}
}