@@ -436,7 +436,7 @@ func resourceGitlabProjectCreate(ctx context.Context, d *schema.ResourceData, me
436
436
437
437
log .Printf ("[DEBUG] create gitlab project %q" , * options .Name )
438
438
439
- project , _ , err := client .Projects .CreateProject (options )
439
+ project , _ , err := client .Projects .CreateProject (options , gitlab . WithContext ( ctx ) )
440
440
if err != nil {
441
441
return diag .FromErr (err )
442
442
}
@@ -454,7 +454,7 @@ func resourceGitlabProjectCreate(ctx context.Context, d *schema.ResourceData, me
454
454
Target : []string {"finished" },
455
455
Timeout : 10 * time .Minute ,
456
456
Refresh : func () (interface {}, string , error ) {
457
- status , _ , err := client .ProjectImportExport .ImportStatus (d .Id ())
457
+ status , _ , err := client .ProjectImportExport .ImportStatus (d .Id (), gitlab . WithContext ( ctx ) )
458
458
if err != nil {
459
459
return nil , "" , err
460
460
}
@@ -468,21 +468,21 @@ func resourceGitlabProjectCreate(ctx context.Context, d *schema.ResourceData, me
468
468
}
469
469
470
470
// Read the project again, so that we can detect the default branch.
471
- project , _ , err = client .Projects .GetProject (project .ID , nil )
471
+ project , _ , err = client .Projects .GetProject (project .ID , nil , gitlab . WithContext ( ctx ) )
472
472
if err != nil {
473
473
return diag .Errorf ("Failed to get project %q after completing import: %s" , d .Id (), err )
474
474
}
475
475
}
476
476
477
477
if d .Get ("archived" ).(bool ) {
478
478
// strange as it may seem, this project is created in archived state...
479
- if _ , _ , err := client .Projects .ArchiveProject (d .Id ()); err != nil {
479
+ if _ , _ , err := client .Projects .ArchiveProject (d .Id (), gitlab . WithContext ( ctx ) ); err != nil {
480
480
return diag .Errorf ("new project %q could not be archived: %s" , d .Id (), err )
481
481
}
482
482
}
483
483
484
484
if _ , ok := d .GetOk ("push_rules" ); ok {
485
- err := editOrAddPushRules (client , d .Id (), d )
485
+ err := editOrAddPushRules (ctx , client , d .Id (), d )
486
486
var httpError * gitlab.ErrorResponse
487
487
if errors .As (err , & httpError ) && httpError .Response .StatusCode == http .StatusNotFound {
488
488
log .Printf ("[DEBUG] Failed to edit push rules for project %q: %v" , d .Id (), err )
@@ -505,35 +505,35 @@ func resourceGitlabProjectCreate(ctx context.Context, d *schema.ResourceData, me
505
505
_ , _ , err := client .Branches .CreateBranch (project .ID , & gitlab.CreateBranchOptions {
506
506
Branch : gitlab .String (newDefaultBranch ),
507
507
Ref : gitlab .String (oldDefaultBranch ),
508
- })
508
+ }, gitlab . WithContext ( ctx ) )
509
509
if err != nil {
510
510
return diag .Errorf ("Failed to create branch %q for project %q: %s" , newDefaultBranch , d .Id (), err )
511
511
}
512
512
513
513
log .Printf ("[DEBUG] set new default branch to %q for project %q" , newDefaultBranch , d .Id ())
514
514
_ , _ , err = client .Projects .EditProject (project .ID , & gitlab.EditProjectOptions {
515
515
DefaultBranch : gitlab .String (newDefaultBranch ),
516
- })
516
+ }, gitlab . WithContext ( ctx ) )
517
517
if err != nil {
518
518
return diag .Errorf ("Failed to set default branch to %q for project %q: %s" , newDefaultBranch , d .Id (), err )
519
519
}
520
520
521
521
log .Printf ("[DEBUG] protect new default branch %q for project %q" , newDefaultBranch , d .Id ())
522
522
_ , _ , err = client .ProtectedBranches .ProtectRepositoryBranches (project .ID , & gitlab.ProtectRepositoryBranchesOptions {
523
523
Name : gitlab .String (newDefaultBranch ),
524
- })
524
+ }, gitlab . WithContext ( ctx ) )
525
525
if err != nil {
526
526
return diag .Errorf ("Failed to protect default branch %q for project %q: %s" , newDefaultBranch , d .Id (), err )
527
527
}
528
528
529
529
log .Printf ("[DEBUG] unprotect old default branch %q for project %q" , oldDefaultBranch , d .Id ())
530
- _ , err = client .ProtectedBranches .UnprotectRepositoryBranches (project .ID , oldDefaultBranch )
530
+ _ , err = client .ProtectedBranches .UnprotectRepositoryBranches (project .ID , oldDefaultBranch , gitlab . WithContext ( ctx ) )
531
531
if err != nil {
532
532
return diag .Errorf ("Failed to unprotect undesired default branch %q for project %q: %s" , oldDefaultBranch , d .Id (), err )
533
533
}
534
534
535
535
log .Printf ("[DEBUG] delete old default branch %q for project %q" , oldDefaultBranch , d .Id ())
536
- _ , err = client .Branches .DeleteBranch (project .ID , oldDefaultBranch )
536
+ _ , err = client .Branches .DeleteBranch (project .ID , oldDefaultBranch , gitlab . WithContext ( ctx ) )
537
537
if err != nil {
538
538
return diag .Errorf ("Failed to clean up undesired default branch %q for project %q: %s" , oldDefaultBranch , d .Id (), err )
539
539
}
@@ -552,7 +552,7 @@ func resourceGitlabProjectCreate(ctx context.Context, d *schema.ResourceData, me
552
552
}
553
553
554
554
if (editProjectOptions != gitlab.EditProjectOptions {}) {
555
- if _ , _ , err := client .Projects .EditProject (d .Id (), & editProjectOptions ); err != nil {
555
+ if _ , _ , err := client .Projects .EditProject (d .Id (), & editProjectOptions , gitlab . WithContext ( ctx ) ); err != nil {
556
556
return diag .Errorf ("Could not update project %q: %s" , d .Id (), err )
557
557
}
558
558
}
@@ -564,7 +564,7 @@ func resourceGitlabProjectRead(ctx context.Context, d *schema.ResourceData, meta
564
564
client := meta .(* gitlab.Client )
565
565
log .Printf ("[DEBUG] read gitlab project %s" , d .Id ())
566
566
567
- project , _ , err := client .Projects .GetProject (d .Id (), nil )
567
+ project , _ , err := client .Projects .GetProject (d .Id (), nil , gitlab . WithContext ( ctx ) )
568
568
if err != nil {
569
569
return diag .FromErr (err )
570
570
}
@@ -580,7 +580,7 @@ func resourceGitlabProjectRead(ctx context.Context, d *schema.ResourceData, meta
580
580
581
581
log .Printf ("[DEBUG] read gitlab project %q push rules" , d .Id ())
582
582
583
- pushRules , _ , err := client .Projects .GetProjectPushRules (d .Id ())
583
+ pushRules , _ , err := client .Projects .GetProjectPushRules (d .Id (), gitlab . WithContext ( ctx ) )
584
584
var httpError * gitlab.ErrorResponse
585
585
if errors .As (err , & httpError ) && httpError .Response .StatusCode == http .StatusNotFound {
586
586
log .Printf ("[DEBUG] Failed to get push rules for project %q: %v" , d .Id (), err )
@@ -730,34 +730,34 @@ func resourceGitlabProjectUpdate(ctx context.Context, d *schema.ResourceData, me
730
730
731
731
if * options != (gitlab.EditProjectOptions {}) {
732
732
log .Printf ("[DEBUG] update gitlab project %s" , d .Id ())
733
- _ , _ , err := client .Projects .EditProject (d .Id (), options )
733
+ _ , _ , err := client .Projects .EditProject (d .Id (), options , gitlab . WithContext ( ctx ) )
734
734
if err != nil {
735
735
return diag .FromErr (err )
736
736
}
737
737
}
738
738
739
739
if * transferOptions != (gitlab.TransferProjectOptions {}) {
740
740
log .Printf ("[DEBUG] transferring project %s to namespace %d" , d .Id (), transferOptions .Namespace )
741
- _ , _ , err := client .Projects .TransferProject (d .Id (), transferOptions )
741
+ _ , _ , err := client .Projects .TransferProject (d .Id (), transferOptions , gitlab . WithContext ( ctx ) )
742
742
if err != nil {
743
743
return diag .FromErr (err )
744
744
}
745
745
}
746
746
747
747
if d .HasChange ("archived" ) {
748
748
if d .Get ("archived" ).(bool ) {
749
- if _ , _ , err := client .Projects .ArchiveProject (d .Id ()); err != nil {
749
+ if _ , _ , err := client .Projects .ArchiveProject (d .Id (), gitlab . WithContext ( ctx ) ); err != nil {
750
750
return diag .Errorf ("project %q could not be archived: %s" , d .Id (), err )
751
751
}
752
752
} else {
753
- if _ , _ , err := client .Projects .UnarchiveProject (d .Id ()); err != nil {
753
+ if _ , _ , err := client .Projects .UnarchiveProject (d .Id (), gitlab . WithContext ( ctx ) ); err != nil {
754
754
return diag .Errorf ("project %q could not be unarchived: %s" , d .Id (), err )
755
755
}
756
756
}
757
757
}
758
758
759
759
if d .HasChange ("push_rules" ) {
760
- err := editOrAddPushRules (client , d .Id (), d )
760
+ err := editOrAddPushRules (ctx , client , d .Id (), d )
761
761
var httpError * gitlab.ErrorResponse
762
762
if errors .As (err , & httpError ) && httpError .Response .StatusCode == http .StatusNotFound {
763
763
log .Printf ("[DEBUG] Failed to get push rules for project %q: %v" , d .Id (), err )
@@ -775,7 +775,7 @@ func resourceGitlabProjectDelete(ctx context.Context, d *schema.ResourceData, me
775
775
client := meta .(* gitlab.Client )
776
776
log .Printf ("[DEBUG] Delete gitlab project %s" , d .Id ())
777
777
778
- _ , err := client .Projects .DeleteProject (d .Id ())
778
+ _ , err := client .Projects .DeleteProject (d .Id (), gitlab . WithContext ( ctx ) )
779
779
if err != nil {
780
780
return diag .FromErr (err )
781
781
}
@@ -786,7 +786,7 @@ func resourceGitlabProjectDelete(ctx context.Context, d *schema.ResourceData, me
786
786
Pending : []string {"Deleting" },
787
787
Target : []string {"Deleted" },
788
788
Refresh : func () (interface {}, string , error ) {
789
- out , response , err := client .Projects .GetProject (d .Id (), nil )
789
+ out , response , err := client .Projects .GetProject (d .Id (), nil , gitlab . WithContext ( ctx ) )
790
790
if err != nil {
791
791
if response .StatusCode == 404 {
792
792
return out , "Deleted" , nil
@@ -813,11 +813,11 @@ func resourceGitlabProjectDelete(ctx context.Context, d *schema.ResourceData, me
813
813
return nil
814
814
}
815
815
816
- func editOrAddPushRules (client * gitlab.Client , projectID string , d * schema.ResourceData ) error {
816
+ func editOrAddPushRules (ctx context. Context , client * gitlab.Client , projectID string , d * schema.ResourceData ) error {
817
817
log .Printf ("[DEBUG] Editing push rules for project %q" , projectID )
818
818
819
819
editOptions := expandEditProjectPushRuleOptions (d )
820
- _ , _ , err := client .Projects .EditProjectPushRule (projectID , editOptions )
820
+ _ , _ , err := client .Projects .EditProjectPushRule (projectID , editOptions , gitlab . WithContext ( ctx ) )
821
821
if err == nil {
822
822
return nil
823
823
}
@@ -833,7 +833,7 @@ func editOrAddPushRules(client *gitlab.Client, projectID string, d *schema.Resou
833
833
log .Printf ("[DEBUG] Creating new push rules for project %q" , projectID )
834
834
835
835
addOptions := expandAddProjectPushRuleOptions (d )
836
- _ , _ , err = client .Projects .AddProjectPushRule (projectID , addOptions )
836
+ _ , _ , err = client .Projects .AddProjectPushRule (projectID , addOptions , gitlab . WithContext ( ctx ) )
837
837
if err != nil {
838
838
return err
839
839
}
0 commit comments