mirror of
https://github.com/ysoftdevs/terraform-provider-bitbucketserver.git
synced 2026-04-17 22:39:38 +02:00
Remove scm not configurable; Fix issue with import repositories/projects
This commit is contained in:
@@ -4,9 +4,8 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
|
"io/ioutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Project struct {
|
type Project struct {
|
||||||
@@ -150,8 +149,15 @@ func resourceProjectRead(d *schema.ResourceData, m interface{}) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func resourceProjectExists(d *schema.ResourceData, m interface{}) (bool, error) {
|
func resourceProjectExists(d *schema.ResourceData, m interface{}) (bool, error) {
|
||||||
|
var project = ""
|
||||||
|
id := d.Id()
|
||||||
|
if id != "" {
|
||||||
|
project = id
|
||||||
|
} else {
|
||||||
|
project = d.Get("key").(string)
|
||||||
|
}
|
||||||
|
|
||||||
client := m.(*BitbucketClient)
|
client := m.(*BitbucketClient)
|
||||||
project := d.Get("key").(string)
|
|
||||||
repo_req, err := client.Get(fmt.Sprintf("/rest/api/1.0/projects/%s",
|
repo_req, err := client.Get(fmt.Sprintf("/rest/api/1.0/projects/%s",
|
||||||
project,
|
project,
|
||||||
))
|
))
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ type CloneUrl struct {
|
|||||||
type Repository struct {
|
type Repository struct {
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
Slug string `json:"slug,omitempty"`
|
Slug string `json:"slug,omitempty"`
|
||||||
SCM string `json:"scmId,omitempty"`
|
|
||||||
Description string `json:"description,omitempty"`
|
Description string `json:"description,omitempty"`
|
||||||
Forkable bool `json:"forkable,omitempty"`
|
Forkable bool `json:"forkable,omitempty"`
|
||||||
Public bool `json:"public,omitempty"`
|
Public bool `json:"public,omitempty"`
|
||||||
@@ -52,11 +51,6 @@ func resourceRepository() *schema.Resource {
|
|||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
},
|
},
|
||||||
"scm": {
|
|
||||||
Type: schema.TypeString,
|
|
||||||
Optional: true,
|
|
||||||
Default: "git",
|
|
||||||
},
|
|
||||||
"description": {
|
"description": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
@@ -87,7 +81,6 @@ func newRepositoryFromResource(d *schema.ResourceData) (Repo *Repository, Projec
|
|||||||
repo := &Repository{
|
repo := &Repository{
|
||||||
Name: d.Get("name").(string),
|
Name: d.Get("name").(string),
|
||||||
Slug: d.Get("slug").(string),
|
Slug: d.Get("slug").(string),
|
||||||
SCM: d.Get("scm").(string),
|
|
||||||
Description: d.Get("description").(string),
|
Description: d.Get("description").(string),
|
||||||
Forkable: d.Get("forkable").(bool),
|
Forkable: d.Get("forkable").(bool),
|
||||||
Public: d.Get("public").(bool),
|
Public: d.Get("public").(bool),
|
||||||
@@ -186,7 +179,6 @@ func resourceRepositoryRead(d *schema.ResourceData, m interface{}) error {
|
|||||||
if repo.Slug != "" && repo.Name != repo.Slug {
|
if repo.Slug != "" && repo.Name != repo.Slug {
|
||||||
d.Set("slug", repo.Slug)
|
d.Set("slug", repo.Slug)
|
||||||
}
|
}
|
||||||
d.Set("scmId", repo.SCM)
|
|
||||||
d.Set("description", repo.Description)
|
d.Set("description", repo.Description)
|
||||||
d.Set("forkable", repo.Forkable)
|
d.Set("forkable", repo.Forkable)
|
||||||
d.Set("public", repo.Public)
|
d.Set("public", repo.Public)
|
||||||
@@ -204,9 +196,21 @@ func resourceRepositoryRead(d *schema.ResourceData, m interface{}) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func resourceRepositoryExists(d *schema.ResourceData, m interface{}) (bool, error) {
|
func resourceRepositoryExists(d *schema.ResourceData, m interface{}) (bool, error) {
|
||||||
|
|
||||||
|
var project = ""
|
||||||
|
var repoSlug = ""
|
||||||
|
id := d.Id()
|
||||||
|
if id != "" {
|
||||||
|
idparts := strings.Split(id, "/")
|
||||||
|
if len(idparts) == 2 {
|
||||||
|
project = idparts[0]
|
||||||
|
repoSlug = idparts[1]
|
||||||
|
} else {
|
||||||
|
return false, fmt.Errorf("incorrect ID format, should match `project/slug`")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
client := m.(*BitbucketClient)
|
client := m.(*BitbucketClient)
|
||||||
repoSlug := determineSlug(d)
|
|
||||||
project := d.Get("project").(string)
|
|
||||||
repo_req, err := client.Get(fmt.Sprintf("/rest/api/1.0/projects/%s/repos/%s",
|
repo_req, err := client.Get(fmt.Sprintf("/rest/api/1.0/projects/%s/repos/%s",
|
||||||
project,
|
project,
|
||||||
repoSlug,
|
repoSlug,
|
||||||
|
|||||||
Reference in New Issue
Block a user