@@ -2,10 +2,8 @@ package provider
2
2
3
3
import (
4
4
"context"
5
- "errors"
6
5
"fmt"
7
6
"log"
8
- "net/http"
9
7
"strconv"
10
8
"time"
11
9
@@ -565,12 +563,11 @@ func resourceGitlabProjectCreate(ctx context.Context, d *schema.ResourceData, me
565
563
566
564
if _ , ok := d .GetOk ("push_rules" ); ok {
567
565
err := editOrAddPushRules (ctx , client , d .Id (), d )
568
- var httpError * gitlab.ErrorResponse
569
- if errors .As (err , & httpError ) && httpError .Response .StatusCode == http .StatusNotFound {
570
- log .Printf ("[DEBUG] Failed to edit push rules for project %q: %v" , d .Id (), err )
571
- return diag .Errorf ("Project push rules are not supported in your version of GitLab" )
572
- }
573
566
if err != nil {
567
+ if is404 (err ) {
568
+ log .Printf ("[DEBUG] Failed to edit push rules for project %q: %v" , d .Id (), err )
569
+ return diag .Errorf ("Project push rules are not supported in your version of GitLab" )
570
+ }
574
571
return diag .Errorf ("Failed to edit push rules for project %q: %s" , d .Id (), err )
575
572
}
576
573
}
@@ -629,9 +626,9 @@ func resourceGitlabProjectCreate(ctx context.Context, d *schema.ResourceData, me
629
626
Target : []string {"true" },
630
627
Timeout : 2 * time .Minute , //The async action usually completes very quickly, within seconds. Don't wait too long.
631
628
Refresh : func () (interface {}, string , error ) {
632
- branch , response , err := client .Branches .GetBranch (project .ID , project .DefaultBranch , gitlab .WithContext (ctx ))
629
+ branch , _ , err := client .Branches .GetBranch (project .ID , project .DefaultBranch , gitlab .WithContext (ctx ))
633
630
if err != nil {
634
- if response . StatusCode == 404 {
631
+ if is404 ( err ) {
635
632
// When we hit a 404 here, it means the default branch wasn't created at all as part of the project
636
633
// this will happen when "default_branch" isn't set, or "initialize_with_readme" is set to false.
637
634
// We don't need to wait anymore, so return "true" to exist the wait loop.
@@ -700,8 +697,7 @@ func resourceGitlabProjectRead(ctx context.Context, d *schema.ResourceData, meta
700
697
log .Printf ("[DEBUG] read gitlab project %q push rules" , d .Id ())
701
698
702
699
pushRules , _ , err := client .Projects .GetProjectPushRules (d .Id (), gitlab .WithContext (ctx ))
703
- var httpError * gitlab.ErrorResponse
704
- if errors .As (err , & httpError ) && httpError .Response .StatusCode == http .StatusNotFound {
700
+ if is404 (err ) {
705
701
log .Printf ("[DEBUG] Failed to get push rules for project %q: %v" , d .Id (), err )
706
702
} else if err != nil {
707
703
return diag .Errorf ("Failed to get push rules for project %q: %s" , d .Id (), err )
@@ -889,12 +885,11 @@ func resourceGitlabProjectUpdate(ctx context.Context, d *schema.ResourceData, me
889
885
890
886
if d .HasChange ("push_rules" ) {
891
887
err := editOrAddPushRules (ctx , client , d .Id (), d )
892
- var httpError * gitlab.ErrorResponse
893
- if errors .As (err , & httpError ) && httpError .Response .StatusCode == http .StatusNotFound {
894
- log .Printf ("[DEBUG] Failed to get push rules for project %q: %v" , d .Id (), err )
895
- return diag .Errorf ("Project push rules are not supported in your version of GitLab" )
896
- }
897
888
if err != nil {
889
+ if is404 (err ) {
890
+ log .Printf ("[DEBUG] Failed to get push rules for project %q: %v" , d .Id (), err )
891
+ return diag .Errorf ("Project push rules are not supported in your version of GitLab" )
892
+ }
898
893
return diag .Errorf ("Failed to edit push rules for project %q: %s" , d .Id (), err )
899
894
}
900
895
}
@@ -918,9 +913,9 @@ func resourceGitlabProjectDelete(ctx context.Context, d *schema.ResourceData, me
918
913
Pending : []string {"Deleting" },
919
914
Target : []string {"Deleted" },
920
915
Refresh : func () (interface {}, string , error ) {
921
- out , response , err := client .Projects .GetProject (d .Id (), nil , gitlab .WithContext (ctx ))
916
+ out , _ , err := client .Projects .GetProject (d .Id (), nil , gitlab .WithContext (ctx ))
922
917
if err != nil {
923
- if response . StatusCode == 404 {
918
+ if is404 ( err ) {
924
919
return out , "Deleted" , nil
925
920
}
926
921
log .Printf ("[ERROR] Received error: %#v" , err )
0 commit comments