Skip to content

Commit

Permalink
[wip] feat: added label and assignee to the create issue
Browse files Browse the repository at this point in the history
  • Loading branch information
sahil9001 committed Oct 2, 2024
1 parent 0ebaad8 commit fd12564
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions pkg/component/application/jira/v0/issues.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ type Issue struct {
Self string `json:"self"`
IssueType string `json:"issue-type"`
Status string `json:"status"`
Labels []string `json:"labels"`
Assignee string `json:"assignee"`
}

type GetIssueInput struct {
Expand All @@ -49,6 +51,22 @@ func extractIssue(issue *Issue) *Issue {
issue.Summary = summary
}
}
if len(issue.Labels) == 0 && issue.Fields["labels"] != nil {
if labels, ok := issue.Fields["labels"].([]interface{}); ok {
for _, label := range labels {
if strLabel, ok := label.(string); ok {
issue.Labels = append(issue.Labels, strLabel)
}
}
}
}
if issue.Assignee == "" && issue.Fields["assignee"] != nil {
if assignee, ok := issue.Fields["assignee"].(map[string]interface{}); ok {
if name, ok := assignee["name"].(string); ok {
issue.Assignee = name
}
}
}
if issue.IssueType == "" && issue.Fields["issuetype"] != nil {
if issueType, ok := issue.Fields["issuetype"]; ok {
if issue.IssueType, ok = issueType.(map[string]interface{})["name"].(string); !ok {
Expand Down Expand Up @@ -305,6 +323,8 @@ type CreateIssueInput struct {
IssueType IssueType `json:"issue-type"`
Summary string `json:"summary"`
Description string `json:"description"`
Labels []string `json:"labels"`
Assignee string `json:"assignee"`
}
type CreateIssueRequset struct {
Fields map[string]interface{} `json:"fields"`
Expand Down Expand Up @@ -340,6 +360,14 @@ func convertCreateIssueRequest(issue *CreateIssueInput) *CreateIssueRequset {
"description": issue.Description,
},
}
if len(issue.Labels) > 0 {
newRequest.Fields["labels"] = issue.Labels
}
if issue.Assignee != "" {
newRequest.Fields["assignee"] = map[string]string{
"name": issue.Assignee,
}
}
if issue.IssueType.ParentKey != "" {
newRequest.Fields["parent"] = map[string]interface{}{
"key": issue.IssueType.ParentKey,
Expand Down

0 comments on commit fd12564

Please sign in to comment.