// resourceIssueCreate creates a new jira issue using the jira api
resourceIssueCreate creates a new jira issue using the jira api
// resourceIssueCreate creates a new jira issue using the jira api
func resourceIssueCreate(d *schema.ResourceData, m interface{}) error {
	config := m.(*Config)
	assignee := d.Get("assignee")
	reporter := d.Get("reporter")
	fields := d.Get("fields")
	issueType := d.Get("issue_type").(string)
	description := d.Get("description").(string)
	labels := d.Get("labels")
	summary := d.Get("summary").(string)
	projectKey := d.Get("project_key").(string)
	i := jira.Issue{
		Fields: &jira.IssueFields{
			Description: description,
			Type: jira.IssueType{
				Name: issueType,
			},
			Project: jira.Project{
				Key: projectKey,
			},
			Summary: summary,
		},
	}
	if assignee != "" {
		i.Fields.Assignee = &jira.User{
			Name: assignee.(string),
		}
	}
	if reporter != "" {
		i.Fields.Reporter = &jira.User{
			Name: reporter.(string),
		}
	}
	if fields != nil {
		if i.Fields.Unknowns == nil {
			i.Fields.Unknowns = tcontainer.NewMarshalMap()
		}
		for field, value := range fields.(map[string]interface{}) {
			i.Fields.Unknowns.Set(field, fmt.Sprintf("%v", value))
		}
	}
	if labels != nil {
		for _, label := range labels.([]interface{}) {
			i.Fields.Labels = append(i.Fields.Labels, fmt.Sprintf("%v", label))
		}
	}
	issue, res, err := config.jiraClient.Issue.Create(&i)
	if err != nil {
		body, _ := ioutil.ReadAll(res.Body)
		return errors.Wrapf(err, "creating jira issue failed: %s", body)
	}
	issue, res, err = config.jiraClient.Issue.Get(issue.ID, nil)
	if err != nil {
		body, _ := ioutil.ReadAll(res.Body)
		return errors.Wrapf(err, "getting jira issue failed: %s", body)
	}
	if state, ok := d.GetOk("state"); ok {
		if issue.Fields.Status.ID != state.(string) {
			if transition, ok := d.GetOk("state_transition"); ok {
				res, err := config.jiraClient.Issue.DoTransition(issue.ID, transition.(string))
				if err != nil {
					body, _ := ioutil.ReadAll(res.Body)
					return errors.Wrapf(err, "transitioning jira issue failed: %s", body)
				}
			}
		}
	}
	d.SetId(issue.ID)
	return resourceIssueRead(d, m)
}
func resourceIssueCreate ( d * schema . ResourceData , m interface { } ) error { config := m . ( * Config ) assignee := d . Get ( " " ) reporter := d . Get ( " " ) fields := d . Get ( " " ) issueType := d . Get ( " " ) . ( string ) description := d . Get ( " " ) . ( string ) labels := d . Get ( " " ) summary := d . Get ( " " ) . ( string ) projectKey := d . Get ( " " ) . ( string ) i := jira . Issue { Fields : & jira . IssueFields { Description : description , Type : jira . IssueType { Name : issueType , } , Project : jira . Project { Key : projectKey , } , Summary : summary , } , } if assignee != " " { i . Fields . Assignee = & jira . User { Name : assignee . ( string ) , } } if reporter != " " { i . Fields . Reporter = & jira . User { Name : reporter . ( string ) , } } if fields != nil { if i . Fields . Unknowns == nil { i . Fields . Unknowns = tcontainer . NewMarshalMap ( ) } for field , value := range fields . ( map [ string ] interface { } ) { i . Fields . Unknowns . Set ( field , fmt . Sprintf ( " " , value ) ) } } if labels != nil { for _ , label := range labels . ( [ ] interface { } ) { i . Fields . Labels = append ( i . Fields . Labels , fmt . Sprintf ( " " , label ) ) } } issue , res , err := config . jiraClient . Issue . Create ( & i ) if err != nil { body , _ := ioutil . ReadAll ( res . Body ) return errors . Wrapf ( err , " " , body ) } issue , res , err = config . jiraClient . Issue . Get ( issue . ID , nil ) if err != nil { body , _ := ioutil . ReadAll ( res . Body ) return errors . Wrapf ( err , " " , body ) } if state , ok := d . GetOk ( " " ) ; ok { if issue . Fields . Status . ID != state . ( string ) { if transition , ok := d . GetOk ( " " ) ; ok { res , err := config . jiraClient . Issue . DoTransition ( issue . ID , transition . ( string ) ) if err != nil { body , _ := ioutil . ReadAll ( res . Body ) return errors . Wrapf ( err , " " , body ) } } } } d . SetId ( issue . ID ) return resourceIssueRead ( d , m ) }
resourceIssueCreate creates a new jira issue using the jira api
resourceIssueCreate creates a new jira issue using the jira api