@@ -80,50 +80,6 @@ func resourceGithubRepositoryAutolinkReference() *schema.Resource {
8080 }
8181}
8282
83- func resourceGithubRepositoryAutolinkReferenceImport (ctx context.Context , d * schema.ResourceData , m any ) ([]* schema.ResourceData , error ) {
84- parts := strings .Split (d .Id (), "/" )
85- if len (parts ) != 2 {
86- return nil , fmt .Errorf ("invalid ID specified: supplied ID must be written as <repository>/<autolink_reference_id>" )
87- }
88-
89- repository := parts [0 ]
90- id := parts [1 ]
91-
92- meta , _ := m .(* Owner )
93- client := meta .v3client
94- owner := meta .name
95-
96- // If the second part of the provided ID isn't an integer, assume that the
97- // caller provided the key prefix for the autolink reference, and look up
98- // the autolink by the key prefix.
99-
100- _ , err := strconv .Atoi (id )
101- if err != nil {
102- autolink , err := getAutolinkByKeyPrefix (ctx , client , owner , repository , id )
103- if err != nil {
104- return nil , err
105- }
106-
107- id = strconv .FormatInt (* autolink .ID , 10 )
108- }
109-
110- d .SetId (id )
111-
112- repo , _ , err := client .Repositories .Get (ctx , owner , repository )
113- if err != nil {
114- return nil , fmt .Errorf ("failed to retrieve repository %s: %w" , repository , err )
115- }
116-
117- if err = d .Set ("repository" , repository ); err != nil {
118- return nil , err
119- }
120- if err = d .Set ("repository_id" , int (repo .GetID ())); err != nil {
121- return nil , err
122- }
123-
124- return []* schema.ResourceData {d }, nil
125- }
126-
12783func resourceGithubRepositoryAutolinkReferenceCreate (ctx context.Context , d * schema.ResourceData , m any ) diag.Diagnostics {
12884 meta , _ := m .(* Owner )
12985 client := meta .v3client
@@ -246,3 +202,47 @@ func resourceGithubRepositoryAutolinkReferenceDelete(ctx context.Context, d *sch
246202
247203 return nil
248204}
205+
206+ func resourceGithubRepositoryAutolinkReferenceImport (ctx context.Context , d * schema.ResourceData , m any ) ([]* schema.ResourceData , error ) {
207+ parts := strings .Split (d .Id (), "/" )
208+ if len (parts ) != 2 {
209+ return nil , fmt .Errorf ("invalid ID specified: supplied ID must be written as <repository>/<autolink_reference_id>" )
210+ }
211+
212+ repository := parts [0 ]
213+ id := parts [1 ]
214+
215+ meta , _ := m .(* Owner )
216+ client := meta .v3client
217+ owner := meta .name
218+
219+ // If the second part of the provided ID isn't an integer, assume that the
220+ // caller provided the key prefix for the autolink reference, and look up
221+ // the autolink by the key prefix.
222+
223+ _ , err := strconv .Atoi (id )
224+ if err != nil {
225+ autolink , err := getAutolinkByKeyPrefix (ctx , client , owner , repository , id )
226+ if err != nil {
227+ return nil , err
228+ }
229+
230+ id = strconv .FormatInt (* autolink .ID , 10 )
231+ }
232+
233+ d .SetId (id )
234+
235+ repo , _ , err := client .Repositories .Get (ctx , owner , repository )
236+ if err != nil {
237+ return nil , fmt .Errorf ("failed to retrieve repository %s: %w" , repository , err )
238+ }
239+
240+ if err = d .Set ("repository" , repository ); err != nil {
241+ return nil , err
242+ }
243+ if err = d .Set ("repository_id" , int (repo .GetID ())); err != nil {
244+ return nil , err
245+ }
246+
247+ return []* schema.ResourceData {d }, nil
248+ }
0 commit comments