-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* #19, #20 - support for using fields and labels in issues. Also added field as a data source so the ID can be looked up by name Co-authored-by: Matthias Bartelmeß <[email protected]>
- Loading branch information
hh-nharward
authored
May 17, 2021
1 parent
ab3ead2
commit 98c70a3
Showing
9 changed files
with
298 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,46 @@ | ||
// This example works for JIRA projects that support epics | ||
data "jira_field" "epic_name" { | ||
name = "Epic Name" | ||
} | ||
|
||
data "jira_field" "epic_link" { | ||
name = "Epic Link" | ||
} | ||
|
||
resource "jira_issue" "example_epic" { | ||
assignee = "anubhavmishra" | ||
reporter = "anubhavmishra" | ||
|
||
issue_type = "Epic" | ||
|
||
// description is optional | ||
description = "This is an epic description" | ||
summary = "This is an epic summary" | ||
|
||
labels = ["one", "two", "buckle-my-shoe"] | ||
|
||
// System and custom fields are optional; see the field data source to reference internal JIRA field IDs by name | ||
fields = { | ||
(data.jira_field.epic_name.id) = "Example epic name" | ||
} | ||
|
||
project_key = "PROJ" | ||
} | ||
|
||
resource "jira_issue" "example" { | ||
assignee = "anubhavmishra" | ||
reporter = "anubhavmishra" | ||
assignee = "anubhavmishra" | ||
reporter = "anubhavmishra" | ||
|
||
issue_type = "Task" | ||
issue_type = "Task" | ||
|
||
// description is optional | ||
description = "This is a test issue" | ||
// description is optional | ||
description = "This is a test issue that's part of an epic" | ||
summary = "Created using Terraform" | ||
labels = ["label1", "label2"] | ||
fields = { | ||
(jira_field.epic_link.id) = jira_issue.example_epic.issue_key | ||
} | ||
|
||
project_key = "PROJ" | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package jira | ||
|
||
import ( | ||
"fmt" | ||
|
||
jira "github.com/andygrunwald/go-jira" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
var ( | ||
fieldsCache []jira.Field | ||
) | ||
|
||
// JIRA field | ||
func resourceField() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: resourceFieldRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"clause_names": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Schema{Type: schema.TypeString}, | ||
}, | ||
"custom": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
"id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"key": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"navigable": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
"searchable": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceFieldRead(d *schema.ResourceData, m interface{}) error { | ||
config := m.(*Config) | ||
name := d.Get("name").(string) | ||
|
||
if fieldsCache == nil || len(fieldsCache) == 0 { | ||
fields, _, err := config.jiraClient.Field.GetList() | ||
if err != nil { | ||
return errors.Wrapf(err, "fetching jira fields failed") | ||
} | ||
fieldsCache = fields | ||
} | ||
|
||
field := findFieldByName(fieldsCache, name) | ||
if field == nil { | ||
return errors.New(fmt.Sprintf("field with name '%s' not found", name)) | ||
} | ||
|
||
d.SetId(field.ID) | ||
d.Set("clause_names", field.ClauseNames) | ||
d.Set("custom", field.Custom) | ||
d.Set("id", field.ID) | ||
d.Set("key", field.Key) | ||
d.Set("navigable", field.Navigable) | ||
d.Set("searchable", field.Searchable) | ||
|
||
return nil | ||
} | ||
|
||
func findFieldByName(fields []jira.Field, name string) *jira.Field { | ||
for _, field := range fields { | ||
if field.Name == name { | ||
return &field | ||
} | ||
} | ||
return nil | ||
} |
Oops, something went wrong.