Skip to content

Commit

Permalink
test: jira test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
hielfx committed May 28, 2024
1 parent b233f6a commit 7eacabb
Show file tree
Hide file tree
Showing 5 changed files with 365 additions and 346 deletions.
3 changes: 0 additions & 3 deletions internal/issue_trackers/github/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ func Test_CheckConfiguration(t *testing.T) {
}
}

// TODO: MOVE THIS TEST WHERE IS NEEDED
func TestGetIssueType(t *testing.T) {

createIssue := func(labelNames ...string) domain.Issue {
Expand Down Expand Up @@ -226,8 +225,6 @@ func TestGithub_FormatIssueId(t *testing.T) {
}
}

//TODO: MOVE THIS TEST WHERE IS NEDED

func TestGetIssueTypeLabel(t *testing.T) {

createIssue := func(labelNames ...string) domain.Issue {
Expand Down
92 changes: 21 additions & 71 deletions internal/issue_trackers/issue_trackers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ import (
"github.com/InditexTech/gh-sherpa/internal/config"
"github.com/InditexTech/gh-sherpa/internal/domain"
"github.com/InditexTech/gh-sherpa/internal/issue_trackers/github"
"github.com/InditexTech/gh-sherpa/internal/issue_trackers/jira"
"github.com/InditexTech/gh-sherpa/internal/logging"
)

type Configuration struct {
//TODO: UNCOMMENT JIRA
// Jira jira.Configuration
Jira jira.Configuration
Github github.Configuration
}
type Provider struct {
cfg Configuration
github github.Github
// jira jira.Jira
jira jira.Jira
}

var _ domain.IssueTrackerProvider = (*Provider)(nil)
Expand All @@ -29,27 +29,25 @@ func New(cfg Configuration) (*Provider, error) {
return nil, err
}

//TODO: UNCOMMENT JIRA
// j, err := jira.New(cfg.Jira)
// if err != nil {
// return nil, err
// }
j, err := jira.New(cfg.Jira)
if err != nil {
return nil, err
}

return &Provider{
cfg: cfg,
github: *g,
// jira: *j,
jira: *j,
}, nil
}

// NewConfiguration returns a new configuration from the given global configuration
func NewFromConfiguration(globalConfig config.Configuration) (*Provider, error) {
return New(Configuration{
//TODO: UNCOMMENT JIRA
// Jira: jira.Configuration{
// Jira: globalConfig.Jira,
// IssueTypeLabels: globalConfig.Github.IssueLabels,
// },
Jira: jira.Configuration{
Jira: globalConfig.Jira,
IssueTypeLabels: globalConfig.Github.IssueLabels,
},
Github: github.Configuration{
Github: globalConfig.Github,
},
Expand All @@ -63,13 +61,11 @@ func (p Provider) GetIssue(identifier string) (domain.Issue, error) {
return p.github.GetIssue(identifier)
}

//TODO: UNCOMMENT JIRA
// if p.jira.IdentifyIssue(identifier) {
// logging.Debugf("Issue %s identified as a Jira issue", identifier)
// // return &p.jira, nil
// return p.jira.GetIssue(identifier)

// }
if p.jira.IdentifyIssue(identifier) {
logging.Debugf("Issue %s identified as a Jira issue", identifier)
// return &p.jira, nil
return p.jira.GetIssue(identifier)
}

return nil, fmt.Errorf("could not identify issue %s", identifier)
}
Expand All @@ -80,56 +76,10 @@ func (p Provider) ParseIssueId(identifier string) (issueId string) {
return p.github.ParseRawIssueId(identifier)
}

//TODO: UNCOMMENT JIRA

// if p.jira.IdentifyIssue(identifier) {
// logging.Debugf("Issue %s identified as a Jira issue", identifier)
// return p.jira.ParseRawIssueId(identifier)
// }
if p.jira.IdentifyIssue(identifier) {
logging.Debugf("Issue %s identified as a Jira issue", identifier)
return p.jira.ParseRawIssueId(identifier)
}

return
}

//TODO: MOVE THIS TO THE CORRESPONDING PLACE
// GetIssueTitle returns the issue title
// func (p *Provider) GetIssueTitle(issue domain.Issue) (title string, err error) {
// switch issue.IssueTracker {
// case domain.IssueTrackerTypeGithub:
// title = issue.Title
// case domain.IssueTrackerTypeJira:
// title = fmt.Sprintf("[%s] %s", issue.ID, issue.Title)
// default:
// err = fmt.Errorf("issue tracker %s is not supported", issue.IssueTracker)
// }

// return
// }

//TODO: MOVE THIS TO THE CORRESPONDING PLACE
// GetIssueBody returns the issue body
// func (p *Provider) GetIssueBody(issue domain.Issue, noCloseIssue bool) (body string, err error) {
// switch issue.IssueTracker {
// case domain.IssueTrackerTypeGithub:
// keyword := "Closes"
// if noCloseIssue {
// keyword = "Related to"
// }

// body = fmt.Sprintf("%s #%s", keyword, issue.ID)

// case domain.IssueTrackerTypeJira:
// jiraHost := p.cfg.Jira.Auth.Host
// jiraUrlBrowseIssue := jiraHost
// if !strings.HasSuffix(jiraHost, "/") {
// jiraUrlBrowseIssue += "/"
// }

// jiraUrlBrowseIssue += "browse/" + issue.ID

// body = fmt.Sprintf("Relates to [%s](%s)", issue.ID, jiraUrlBrowseIssue)
// default:
// err = fmt.Errorf("issue tracker %s is not supported", issue.IssueTracker)
// }

// return
// }
81 changes: 81 additions & 0 deletions internal/issue_trackers/jira/issue.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package jira

import (
"github.com/InditexTech/gh-sherpa/internal/config"
"github.com/InditexTech/gh-sherpa/internal/domain"
"github.com/InditexTech/gh-sherpa/internal/domain/issue_types"
)

type Issue struct {
id string
title string
body string
url string
issueType IssueType
issueTypesConfig config.JiraIssueTypes
labelsConfig map[issue_types.IssueType][]string
}

var _ domain.Issue = (*Issue)(nil)

type IssueType struct {
Id string
Name string
Description string
}

// Body implements domain.Issue.
func (i Issue) Body() string {
panic("unimplemented")
}

// FormatID implements domain.Issue.
func (i Issue) FormatID() string {
return i.id
}

// ID implements domain.Issue.
func (i Issue) ID() string {
return i.id
}

// Title implements domain.Issue.
func (i Issue) Title() string {
return i.title
}

// TrackerType implements domain.Issue.
func (i Issue) TrackerType() domain.IssueTrackerType {
return domain.IssueTrackerTypeJira
}

// Type implements domain.Issue.
func (i Issue) Type() issue_types.IssueType {
for issueType, ids := range i.issueTypesConfig {
for _, id := range ids {
if id == i.issueType.Id {
return issueType
}
}
}

return issue_types.Unknown
}

// TypeLabel implements domain.Issue.
func (i Issue) TypeLabel() string {
issueType := i.Type()

for mappedIssueType, labels := range i.labelsConfig {
if issueType == mappedIssueType && len(labels) > 0 {
return labels[0]
}
}

return ""
}

// URL implements domain.Issue.
func (i Issue) URL() string {
return i.url
}
Loading

0 comments on commit 7eacabb

Please sign in to comment.