Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix when issue type's name has a translation #437

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

xav-jann1
Copy link

Problem :
When an issue type has a translation for its name, it is impossible to create an issue with that issue type (error appears when the original name and its translation are different).

Indeed, in Jira Administation / Issues / Issue types, it is possible to set a translation for each issue type with Translate Action.

For example, when creating a Bug issue with and without translation (tested with an instance of Atlassian Jira v8.18.0) :

## No translation ##

# List issuetypes
$ jira issuetypes
Task:         A task that needs to be done.
Sub-task:     The sub-task of the issue
Story:        Created by Jira Software - do not edit or delete. Issue type for a user story.
Bug:          A problem which impairs or prevents the functions of the product.
Epic:         Created by Jira Software - do not edit or delete. Issue type for a big user story that needs to be broken down.

# Creating an issue
$ jira create --issuetype Bug
OK TEST-24 http://JIRA_DOMAIN/browse/TEST-24


## With translation: 'Bug' -> 'Bogue' ##

# List issuetypes
$ jira issuetypes
Task:         A task that needs to be done.
Sub-task:     The sub-task of the issue
Story:        Created by Jira Software - do not edit or delete. Issue type for a user story.
Bogue:        Bogue Bogue
Epic:         Created by Jira Software - do not edit or delete. Issue type for a big user story that needs to be broken down.

$ jira create --issuetype Bug
ERROR Invalid Usage: project TEST and IssueType Bug not found

$ jira create --issuetype Bogue
ERROR Invalid Usage: project TEST and IssueType Bogue not found

Cause :
This error message comes from the function GetIssueCreateMetaIssueType() in issue.go :

func GetIssueCreateMetaIssueType(ua HttpClient, endpoint string, projectKey, issueTypeName string) (*jiradata.IssueType, error) {
	uri := URLJoin(endpoint, "rest/api/2/issue/createmeta")
	uri += fmt.Sprintf("?projectKeys=%s&issuetypeNames=%s&expand=projects.issuetypes.fields", projectKey, url.QueryEscape(issueTypeName))
	...
	for _, project := range results.Projects {
		if project.Key != projectKey {
			continue
		}
		for _, issueType := range project.IssueTypes {
			if issueType.Name == issueTypeName {
				return issueType, nil
			}
		}
	}
	return nil, fmt.Errorf("project %s and IssueType %s not found", projectKey, issueTypeName)
}

This error happens because when an issue type has a translation on its name, the request GET .../createmeta returns data about the issue type only when issuetypeNames parameter contains the original name ("Bug" in the example), whereas when searching for the issue type in the response, issueType.Name is the translation ("Bogue" in the example when issueTypeName="Bug").
As a result, issuetypeName cannot be found in the response.

Solution :
Removing issuetypeNames parameter to get every issue types from the project :

func GetIssueCreateMetaIssueType(ua HttpClient, endpoint string, projectKey, issueTypeName string) (*jiradata.IssueType, error) {
	uri := URLJoin(endpoint, "rest/api/2/issue/createmeta")
	uri += fmt.Sprintf("?projectKeys=%s&expand=projects.issuetypes.fields", projectKey)
	...
}

However, as it get every issue types with the expand parameter, a lot more useless data is also downloaded.

Another solution would be to keep the original request, but when the issue type is not found, this other request would be used.

I don't know what would be better.
In this fix, I made the easiest but probably not the cleanest solution.

When an issue type has a translation on its name (in 'Jira Administation / Issues / Issue types' - 'Translate' Action),
the request 'GET .../createmeta' returns data about the issue type only when 'issuetypeNames'
contains the original name, whereas in the response 'issueType.Name' includes its translation.
As a result, 'issuetypeName' could not be found in the response.

Solution : removing 'issuetypeNames' parameter to get every issue types from the project.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant