Conversation
- Show custom fields in `atl issue view` (JSON and plain text) - Add `atl issue field-options` to discover allowed values for select/radio fields - Add `--field` flag to `atl issue transition` for transitions requiring fields - Extract shared field parsing utilities (ParseCustomField, coerceFieldValue) - Refactor edit and create commands to use shared helpers
Summary of ChangesHello @Hinne1, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the Jira CLI's capabilities for interacting with custom fields. It empowers users to view comprehensive custom field data within issue details, efficiently discover valid options for various field types, and seamlessly provide necessary custom field values during issue transitions. These improvements streamline workflows that involve complex Jira configurations and broaden the CLI's utility for managing diverse issue types. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request significantly enhances the CLI by introducing custom field support, including a new field-options command and refactoring field parsing logic into a shared field_util.go. These changes are well-integrated across view, create, edit, and transition commands. A critical security vulnerability was identified in the new GetFieldOptions API method: user-supplied parameters are interpolated into a URL path without proper encoding, which could lead to path traversal. This must be addressed by using url.PathEscape. Additionally, there are a couple of suggestions to improve overall performance and robustness.
internal/api/jira.go
Outdated
| path := fmt.Sprintf("%s/issue/createmeta/%s/issuetypes/%s", | ||
| s.client.JiraBaseURL(), projectKey, issueTypeID) |
There was a problem hiding this comment.
The GetFieldOptions function constructs an API URL by directly interpolating the projectKey and issueTypeID parameters into the path string using fmt.Sprintf. Since these parameters are not URL-encoded, an attacker (or a user providing malicious input) could use path traversal sequences (e.g., ../) to cause the application to make requests to unintended API endpoints within the Jira host. While this is a CLI tool, it is a best practice to always encode path components to prevent unintended behavior, especially if the tool is used in automated environments where input might be untrusted.
| path := fmt.Sprintf("%s/issue/createmeta/%s/issuetypes/%s", | |
| s.client.JiraBaseURL(), projectKey, issueTypeID) | |
| path := fmt.Sprintf("%s/issue/createmeta/%s/issuetypes/%s", | |
| s.client.JiraBaseURL(), url.PathEscape(projectKey), url.PathEscape(issueTypeID)) |
| for _, item := range arr { | ||
| var sv struct { | ||
| Value string `json:"value"` | ||
| } | ||
| if err := json.Unmarshal(item, &sv); err == nil && sv.Value != "" { | ||
| values = append(values, sv.Value) | ||
| continue | ||
| } | ||
| var s string | ||
| if err := json.Unmarshal(item, &s); err == nil { | ||
| values = append(values, s) | ||
| continue | ||
| } | ||
| values = append(values, string(item)) | ||
| } |
There was a problem hiding this comment.
The current implementation for handling array items only checks for select-like objects ({ "value": ... }) and plain strings. This is incomplete as an array can contain other complex types that FormatCustomFieldValue can handle, such as user objects ({ "displayName": ... }).
To make this more robust and handle all supported types within an array, you can use a recursive call to FormatCustomFieldValue for each item.
This simplifies the code and correctly formats any nested types that the parent function already knows how to handle.
for _, item := range arr {
// Recursively format each item to handle various nested types like user pickers, etc.
formattedItem := FormatCustomFieldValue(item)
if formattedItem != "" {
values = append(values, formattedItem)
}
}| func ParseCustomField(ctx context.Context, jira *api.JiraService, raw string) (string, interface{}, error) { | ||
| parts := strings.SplitN(raw, "=", 2) | ||
| if len(parts) != 2 { | ||
| return "", nil, fmt.Errorf("invalid field format: %s (expected key=value)", raw) | ||
| } | ||
| key, value := parts[0], parts[1] | ||
|
|
||
| var resolvedField *api.Field | ||
|
|
||
| if strings.HasPrefix(key, "customfield_") { | ||
| resolvedField, _ = jira.GetFieldByID(ctx, key) | ||
| } else if !isSystemField(key) { | ||
| var err error | ||
| resolvedField, err = jira.GetFieldByName(ctx, key) | ||
| if err != nil { | ||
| return "", nil, fmt.Errorf("failed to look up field '%s': %w", key, err) | ||
| } | ||
| if resolvedField == nil { | ||
| return "", nil, fmt.Errorf("field not found: %s\n\nUse 'atl issue fields --search \"%s\"' to find available fields", key, key) | ||
| } | ||
| key = resolvedField.ID | ||
| } | ||
|
|
||
| fieldValue := coerceFieldValue(resolvedField, value) | ||
| return key, fieldValue, nil | ||
| } |
There was a problem hiding this comment.
This function is called in a loop within the create, edit, and transition commands whenever multiple --field flags are used. Inside this function, jira.GetFieldByID or jira.GetFieldByName are called, which in turn call jira.GetFields(). This results in multiple API calls to fetch the same list of all fields, which is inefficient.
To optimize this, you could cache the result of GetFields() within the JiraService instance. The cache would live for the duration of a single command execution, avoiding redundant API calls.
Here's a suggested implementation in internal/api/jira.go:
// In internal/api/jira.go
type JiraService struct {
client *Client
fieldsCache []*Field // Add this cache field
}
func NewJiraService(client *Client) *JiraService {
return &JiraService{client: client}
}
func (s *JiraService) GetFields(ctx context.Context) ([]*Field, error) {
if s.fieldsCache != nil {
return s.fieldsCache, nil
}
path := fmt.Sprintf("%s/field", s.client.JiraBaseURL())
var fields []*Field
if err := s.client.Get(ctx, path, &fields); err != nil {
return nil, err
}
s.fieldsCache = fields
return fields, nil
}With this change, subsequent calls to GetFieldByID and GetFieldByName within the same command execution will use the cached data instead of making new API requests.
…ng, field caching - URL-encode projectKey and issueTypeID in GetFieldOptions path - Use recursive FormatCustomFieldValue for array items (handles user objects, nested types) - Cache GetFields() result on JiraService for the command lifetime
Merging this branch will decrease overall coverage
Coverage by fileChanged files (no unit tests)
Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code. Changed unit test files
|
Summary
atl issue view:IssueFields.UnmarshalJSONnow capturescustomfield_*keys intoExtramap. View output shows custom fields in both JSON (custom_fieldssection) and plain text.atl issue field-optionscommand: Discovers allowed values for select/radio fields via the createmeta API. Supports--project,--type,--fieldfilter.atl issue transition --field: Pass required fields when transitioning (e.g.--field "Resolution=Fixed").field_util.go: ExtractsParseCustomField+coerceFieldValuehelpers with type-aware coercion (select, radio, multiselect, textarea, labels, numbers). Refactorededit.goandcreate.goto use shared helpers.Context
While resolving NX-15169 (Sentry bug), transitioning the bug to "Bereit für Überprüfung" required setting custom fields (Repo, Application, Ursprung, Fehlverhalten) — but the CLI had no way to discover valid values or pass fields during transitions.
Test plan
make checkpasses (tests + lint, 0 issues)atl issue view NX-15169 --jsonshowscustom_fieldssectionatl issue field-options --project NX --type Buglists fields with allowed valuesatl issue transitionwith--fieldflag sets fields during transition