mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-09 07:33:58 -06:00
5ddf83907c
``` === RUN TestProvider --- PASS: TestProvider (0.00s) === RUN TestProvider_impl --- PASS: TestProvider_impl (0.00s) === RUN TestAccGithubIssueLabel_basic --- PASS: TestAccGithubIssueLabel_basic (0.91s) === RUN TestAccGithubIssueLabel_importBasic --- PASS: TestAccGithubIssueLabel_importBasic (0.41s) === RUN TestAccGithubMembership_basic --- PASS: TestAccGithubMembership_basic (0.84s) === RUN TestAccGithubMembership_importBasic --- PASS: TestAccGithubMembership_importBasic (0.53s) === RUN TestAccGithubRepositoryCollaborator_basic --- PASS: TestAccGithubRepositoryCollaborator_basic (0.64s) === RUN TestAccGithubRepositoryCollaborator_importBasic --- PASS: TestAccGithubRepositoryCollaborator_importBasic (0.74s) === RUN TestAccGithubRepository_basic --- PASS: TestAccGithubRepository_basic (1.54s) === RUN TestAccGithubRepository_importBasic --- PASS: TestAccGithubRepository_importBasic (0.77s) === RUN TestAccGithubTeamMembership_basic --- PASS: TestAccGithubTeamMembership_basic (1.59s) === RUN TestAccGithubTeamMembership_importBasic --- PASS: TestAccGithubTeamMembership_importBasic (0.95s) === RUN TestAccGithubTeamRepository_basic --- PASS: TestAccGithubTeamRepository_basic (1.45s) === RUN TestAccGithubTeamRepository_importBasic --- PASS: TestAccGithubTeamRepository_importBasic (0.75s) === RUN TestAccCheckGetPermissions --- PASS: TestAccCheckGetPermissions (0.00s) === RUN TestAccGithubTeam_basic --- PASS: TestAccGithubTeam_basic (0.79s) === RUN TestAccGithubTeam_importBasic --- PASS: TestAccGithubTeam_importBasic (0.54s) === RUN TestAccGithubUtilRole_validation --- PASS: TestAccGithubUtilRole_validation (0.00s) === RUN TestAccGithubUtilTwoPartID --- PASS: TestAccGithubUtilTwoPartID (0.00s) PASS ok github.com/hashicorp/terraform/builtin/providers/github 12.455s ```
105 lines
2.4 KiB
Go
105 lines
2.4 KiB
Go
package github
|
|
|
|
import (
|
|
"github.com/google/go-github/github"
|
|
"github.com/hashicorp/terraform/helper/schema"
|
|
)
|
|
|
|
func resourceGithubIssueLabel() *schema.Resource {
|
|
return &schema.Resource{
|
|
Create: resourceGithubIssueLabelCreate,
|
|
Read: resourceGithubIssueLabelRead,
|
|
Update: resourceGithubIssueLabelUpdate,
|
|
Delete: resourceGithubIssueLabelDelete,
|
|
Importer: &schema.ResourceImporter{
|
|
State: schema.ImportStatePassthrough,
|
|
},
|
|
|
|
Schema: map[string]*schema.Schema{
|
|
"repository": &schema.Schema{
|
|
Type: schema.TypeString,
|
|
Required: true,
|
|
ForceNew: true,
|
|
},
|
|
"name": &schema.Schema{
|
|
Type: schema.TypeString,
|
|
Required: true,
|
|
},
|
|
"color": &schema.Schema{
|
|
Type: schema.TypeString,
|
|
Required: true,
|
|
},
|
|
"url": &schema.Schema{
|
|
Type: schema.TypeString,
|
|
Computed: true,
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
func resourceGithubIssueLabelCreate(d *schema.ResourceData, meta interface{}) error {
|
|
client := meta.(*Organization).client
|
|
r := d.Get("repository").(string)
|
|
n := d.Get("name").(string)
|
|
c := d.Get("color").(string)
|
|
|
|
_, _, err := client.Issues.CreateLabel(meta.(*Organization).name, r, &github.Label{
|
|
Name: &n,
|
|
Color: &c,
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
d.SetId(buildTwoPartID(&r, &n))
|
|
|
|
return resourceGithubIssueLabelRead(d, meta)
|
|
}
|
|
|
|
func resourceGithubIssueLabelRead(d *schema.ResourceData, meta interface{}) error {
|
|
client := meta.(*Organization).client
|
|
r, n := parseTwoPartID(d.Id())
|
|
|
|
githubLabel, _, err := client.Issues.GetLabel(meta.(*Organization).name, r, n)
|
|
if err != nil {
|
|
d.SetId("")
|
|
return nil
|
|
}
|
|
|
|
d.Set("repository", r)
|
|
d.Set("name", n)
|
|
d.Set("color", githubLabel.Color)
|
|
d.Set("url", githubLabel.URL)
|
|
|
|
return nil
|
|
}
|
|
|
|
func resourceGithubIssueLabelUpdate(d *schema.ResourceData, meta interface{}) error {
|
|
client := meta.(*Organization).client
|
|
r := d.Get("repository").(string)
|
|
n := d.Get("name").(string)
|
|
c := d.Get("color").(string)
|
|
|
|
_, originalName := parseTwoPartID(d.Id())
|
|
_, _, err := client.Issues.EditLabel(meta.(*Organization).name, r, originalName, &github.Label{
|
|
Name: &n,
|
|
Color: &c,
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
d.SetId(buildTwoPartID(&r, &n))
|
|
|
|
return resourceGithubIssueLabelRead(d, meta)
|
|
}
|
|
|
|
func resourceGithubIssueLabelDelete(d *schema.ResourceData, meta interface{}) error {
|
|
client := meta.(*Organization).client
|
|
r := d.Get("repository").(string)
|
|
n := d.Get("name").(string)
|
|
|
|
_, err := client.Issues.DeleteLabel(meta.(*Organization).name, r, n)
|
|
return err
|
|
}
|