Skip to content

Commit

Permalink
integrationsGH-144 - Added basic release functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
benj-fletch authored and Jeremy Udit committed Feb 18, 2020
1 parent 621a02b commit 4a5a866
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
54 changes: 54 additions & 0 deletions github/data_source_github_release.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package github

import (
"context"
"log"
"strconv"

"github.com/hashicorp/terraform/helper/schema"
)

func dataSourceGithubRelease() *schema.Resource {
return &schema.Resource{
Read: dataSourceGithubReleaseRead,

Schema: map[string]*schema.Schema{
"repository": {
Type: schema.TypeString,
Required: true,
},
"owner": {
Type: schema.TypeString,
Required: true,
},
"release_id": {
Type: schema.TypeInt,
Required: true,
},
"url": {
Type: schema.TypeString,
Computed: true,
},
},
}
}

func dataSourceGithubReleaseRead(d *schema.ResourceData, meta interface{}) error {
repository := d.Get("repository").(string)
owner := d.Get("owner").(string)
releaseID := int64(d.Get("release_id").(int))
log.Printf("[INFO] Refreshing GitHub release %s from repository %s", releaseID, repository)

client := meta.(*Organization).client
ctx := context.Background()

release, _, err := client.Repositories.GetRelease(ctx, owner, repository, releaseID)
if err != nil {
return err
}

d.SetId(strconv.FormatInt(release.GetID(), 10))
d.Set("url", release.GetURL())

return nil
}
1 change: 1 addition & 0 deletions github/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func Provider() terraform.ResourceProvider {
DataSourcesMap: map[string]*schema.Resource{
"github_collaborators": dataSourceGithubCollaborators(),
"github_ip_ranges": dataSourceGithubIpRanges(),
"github_release": dataSourceGithubRelease(),
"github_repositories": dataSourceGithubRepositories(),
"github_repository": dataSourceGithubRepository(),
"github_team": dataSourceGithubTeam(),
Expand Down

0 comments on commit 4a5a866

Please sign in to comment.