-
-
Notifications
You must be signed in to change notification settings - Fork 247
Allow custom field values to be specified as JSON #661
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
Open
octachrome
wants to merge
8
commits into
ankitpokhrel:main
Choose a base branch
from
octachrome:custom-fields-json
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0a2bed0
feat: Allow custom field values to be specified as JSON #ankitpokhrel…
octachrome 3ac8220
fix: linting
octachrome 299d08a
feat: Configure JSON custom fields in config file instead of using --…
octachrome fccd6ed
feat: Handle unknown custom field types as JSON, and support arrays o…
octachrome 155f3f9
Merge branch 'main' into custom-fields-json
ankitpokhrel 1288518
Merge branch 'main' into custom-fields-json
ankitpokhrel c51ba28
Fixed bug when setting array type custom fields
octachrome 0477062
Merge branch 'main' into custom-fields-json
ankitpokhrel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,88 @@ | ||
package jira | ||
|
||
import ( | ||
"encoding/json" | ||
"strconv" | ||
"strings" | ||
) | ||
|
||
const ( | ||
customFieldFormatAny = "any" | ||
customFieldFormatOption = "option" | ||
customFieldFormatArray = "array" | ||
customFieldFormatNumber = "number" | ||
customFieldFormatString = "string" | ||
customFieldFormatProject = "project" | ||
customFieldFormatJson = "json" | ||
) | ||
|
||
type customField map[string]interface{} | ||
|
||
type customFieldTypeNumber float64 | ||
|
||
type customFieldTypeNumberSet struct { | ||
Set customFieldTypeNumber `json:"set"` | ||
type customFieldTypeString string | ||
|
||
type customFieldTypeOption struct { | ||
Value string `json:"value"` | ||
} | ||
|
||
type customFieldTypeStringSet struct { | ||
Set string `json:"set"` | ||
type customFieldTypeProject struct { | ||
Value string `json:"key"` | ||
} | ||
|
||
type customFieldTypeOption struct { | ||
Value string `json:"value"` | ||
type customFieldTypeJson struct { | ||
Json string | ||
} | ||
|
||
type customFieldTypeOptionSet struct { | ||
Set customFieldTypeOption `json:"set"` | ||
func (field customFieldTypeJson) MarshalJSON() ([]byte, error) { | ||
return []byte(field.Json), nil | ||
} | ||
|
||
type customFieldTypeOptionAddRemove struct { | ||
Add *customFieldTypeOption `json:"add,omitempty"` | ||
Remove *customFieldTypeOption `json:"remove,omitempty"` | ||
type customFieldEditTypeSet struct { | ||
Set any `json:"set"` | ||
} | ||
|
||
type customFieldTypeProject struct { | ||
Value string `json:"key"` | ||
type customFieldEditTypeAddRemove struct { | ||
Add *any `json:"add,omitempty"` | ||
Remove *any `json:"remove,omitempty"` | ||
} | ||
|
||
type customFieldTypeProjectSet struct { | ||
Set customFieldTypeProject `json:"set"` | ||
func constructCustomField(dataType string, itemType string, value string) any { | ||
switch dataType { | ||
case customFieldFormatOption: | ||
return customFieldTypeOption{Value: value} | ||
case customFieldFormatProject: | ||
return customFieldTypeProject{Value: value} | ||
case customFieldFormatArray: | ||
pieces := strings.Split(strings.TrimSpace(value), ",") | ||
items := make([]any, len(pieces)) | ||
for idx, piece := range pieces { | ||
items[idx] = constructCustomField(itemType, piece, "") | ||
} | ||
return items | ||
case customFieldFormatNumber: | ||
num, err := strconv.ParseFloat(value, 64) //nolint:gomnd | ||
if err != nil { | ||
// Let Jira API handle data type error for now. | ||
return value | ||
} else { | ||
return customFieldTypeNumber(num) | ||
} | ||
case customFieldFormatAny: | ||
fallthrough | ||
case customFieldFormatString: | ||
return customFieldTypeString(value) | ||
case customFieldFormatJson: | ||
return customFieldTypeJson{Json: value} | ||
default: | ||
// An unknown type like "version" or "user". Try parsing as JSON, | ||
// and if that doesn't work, just send as a string | ||
var unused any | ||
err := json.Unmarshal([]byte(value), &unused) | ||
if err == nil { | ||
return customFieldTypeJson{Json: value} | ||
} else { | ||
return value | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.