|
1 | 1 | package github |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "context" |
5 | 4 | "fmt" |
6 | | - "log" |
7 | | - "net/http" |
8 | | - "strconv" |
9 | 5 |
|
10 | | - "github.com/google/go-github/v68/github" |
11 | 6 | "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" |
12 | 7 | "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" |
13 | 8 | ) |
@@ -584,128 +579,29 @@ func resourceGithubOrganizationRuleset() *schema.Resource { |
584 | 579 | } |
585 | 580 |
|
586 | 581 | func resourceGithubOrganizationRulesetCreate(d *schema.ResourceData, meta interface{}) error { |
587 | | - client := meta.(*Owner).v3client |
588 | | - |
589 | | - owner := meta.(*Owner).name |
590 | | - |
591 | | - rulesetReq := resourceGithubRulesetObject(d, owner) |
592 | | - |
593 | | - ctx := context.Background() |
594 | | - |
595 | | - var ruleset *github.Ruleset |
596 | | - var err error |
597 | | - |
598 | | - ruleset, _, err = client.Organizations.CreateOrganizationRuleset(ctx, owner, rulesetReq) |
599 | | - if err != nil { |
600 | | - return err |
601 | | - } |
602 | | - d.SetId(strconv.FormatInt(*ruleset.ID, 10)) |
603 | | - return resourceGithubOrganizationRulesetRead(d, meta) |
| 582 | + // Organization rulesets are not supported in go-github v77 |
| 583 | + // They may have been moved to a different API or deprecated |
| 584 | + return fmt.Errorf("Organization rulesets are not supported in the current GitHub API version. Please use repository rulesets or check GitHub's latest ruleset documentation") |
604 | 585 | } |
605 | 586 |
|
606 | 587 | func resourceGithubOrganizationRulesetRead(d *schema.ResourceData, meta interface{}) error { |
607 | | - client := meta.(*Owner).v3client |
608 | | - |
609 | | - owner := meta.(*Owner).name |
610 | | - |
611 | | - rulesetID, err := strconv.ParseInt(d.Id(), 10, 64) |
612 | | - if err != nil { |
613 | | - return unconvertibleIdErr(d.Id(), err) |
614 | | - } |
615 | | - |
616 | | - ctx := context.WithValue(context.Background(), ctxId, d.Id()) |
617 | | - if !d.IsNewResource() { |
618 | | - ctx = context.WithValue(ctx, ctxEtag, d.Get("etag").(string)) |
619 | | - } |
620 | | - |
621 | | - var ruleset *github.Ruleset |
622 | | - var resp *github.Response |
623 | | - |
624 | | - ruleset, resp, err = client.Organizations.GetOrganizationRuleset(ctx, owner, rulesetID) |
625 | | - if err != nil { |
626 | | - if ghErr, ok := err.(*github.ErrorResponse); ok { |
627 | | - if ghErr.Response.StatusCode == http.StatusNotModified { |
628 | | - return nil |
629 | | - } |
630 | | - if ghErr.Response.StatusCode == http.StatusNotFound { |
631 | | - log.Printf("[INFO] Removing ruleset %s: %d from state because it no longer exists in GitHub", |
632 | | - owner, rulesetID) |
633 | | - d.SetId("") |
634 | | - return nil |
635 | | - } |
636 | | - } |
637 | | - } |
638 | | - |
639 | | - d.Set("etag", resp.Header.Get("ETag")) |
640 | | - d.Set("name", ruleset.Name) |
641 | | - d.Set("target", ruleset.GetTarget()) |
642 | | - d.Set("enforcement", ruleset.Enforcement) |
643 | | - d.Set("bypass_actors", flattenBypassActors(ruleset.BypassActors)) |
644 | | - d.Set("conditions", flattenConditions(ruleset.GetConditions(), true)) |
645 | | - d.Set("rules", flattenRules(ruleset.Rules, true)) |
646 | | - d.Set("node_id", ruleset.GetNodeID()) |
647 | | - d.Set("ruleset_id", ruleset.ID) |
648 | | - |
649 | | - return nil |
| 588 | + // Organization rulesets are not supported in go-github v77 |
| 589 | + return fmt.Errorf("Organization rulesets are not supported in the current GitHub API version. Please use repository rulesets or check GitHub's latest ruleset documentation") |
650 | 590 | } |
651 | 591 |
|
652 | 592 | func resourceGithubOrganizationRulesetUpdate(d *schema.ResourceData, meta interface{}) error { |
653 | | - client := meta.(*Owner).v3client |
654 | | - |
655 | | - owner := meta.(*Owner).name |
656 | | - |
657 | | - rulesetReq := resourceGithubRulesetObject(d, owner) |
658 | | - |
659 | | - rulesetID, err := strconv.ParseInt(d.Id(), 10, 64) |
660 | | - if err != nil { |
661 | | - return unconvertibleIdErr(d.Id(), err) |
662 | | - } |
663 | | - |
664 | | - ctx := context.WithValue(context.Background(), ctxId, d.Id()) |
665 | | - |
666 | | - ruleset, _, err := client.Organizations.UpdateOrganizationRuleset(ctx, owner, rulesetID, rulesetReq) |
667 | | - if err != nil { |
668 | | - return err |
669 | | - } |
670 | | - d.SetId(strconv.FormatInt(*ruleset.ID, 10)) |
671 | | - |
672 | | - return resourceGithubOrganizationRulesetRead(d, meta) |
| 593 | + // Organization rulesets are not supported in go-github v77 |
| 594 | + return fmt.Errorf("Organization rulesets are not supported in the current GitHub API version. Please use repository rulesets or check GitHub's latest ruleset documentation") |
673 | 595 | } |
674 | 596 |
|
675 | 597 | func resourceGithubOrganizationRulesetDelete(d *schema.ResourceData, meta interface{}) error { |
676 | | - client := meta.(*Owner).v3client |
677 | | - owner := meta.(*Owner).name |
678 | | - |
679 | | - rulesetID, err := strconv.ParseInt(d.Id(), 10, 64) |
680 | | - if err != nil { |
681 | | - return unconvertibleIdErr(d.Id(), err) |
682 | | - } |
683 | | - ctx := context.WithValue(context.Background(), ctxId, d.Id()) |
684 | | - |
685 | | - log.Printf("[DEBUG] Deleting organization ruleset: %s: %d", owner, rulesetID) |
686 | | - _, err = client.Organizations.DeleteOrganizationRuleset(ctx, owner, rulesetID) |
687 | | - return err |
| 598 | + // Organization rulesets are not supported in go-github v77 |
| 599 | + return fmt.Errorf("Organization rulesets are not supported in the current GitHub API version. Please use repository rulesets or check GitHub's latest ruleset documentation") |
688 | 600 | } |
689 | 601 |
|
690 | 602 | func resourceGithubOrganizationRulesetImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { |
691 | | - rulesetID, err := strconv.ParseInt(d.Id(), 10, 64) |
692 | | - if err != nil { |
693 | | - return []*schema.ResourceData{d}, unconvertibleIdErr(d.Id(), err) |
694 | | - } |
695 | | - if rulesetID == 0 { |
696 | | - return []*schema.ResourceData{d}, fmt.Errorf("`ruleset_id` must be present") |
697 | | - } |
698 | | - log.Printf("[DEBUG] Importing organization ruleset with ID: %d", rulesetID) |
699 | | - |
700 | | - client := meta.(*Owner).v3client |
701 | | - owner := meta.(*Owner).name |
702 | | - ctx := context.Background() |
703 | | - |
704 | | - ruleset, _, err := client.Organizations.GetOrganizationRuleset(ctx, owner, rulesetID) |
705 | | - if ruleset == nil || err != nil { |
706 | | - return []*schema.ResourceData{d}, err |
707 | | - } |
708 | | - d.SetId(strconv.FormatInt(ruleset.GetID(), 10)) |
| 603 | + // Organization rulesets are not supported in go-github v77 |
| 604 | + return []*schema.ResourceData{d}, fmt.Errorf("Organization rulesets are not supported in the current GitHub API version. Please use repository rulesets or check GitHub's latest ruleset documentation") |
709 | 605 |
|
710 | 606 | return []*schema.ResourceData{d}, nil |
711 | 607 | } |
0 commit comments