mirror of
https://github.com/Threnklyn/jira.git
synced 2026-05-18 20:23:28 +02:00
update all usage of user.name to user.accountId for privacy migration:
https://developer.atlassian.com/cloud/jira/platform/deprecation-notice-user-privacy-api-migration-guide/
This commit is contained in:
+28
-1
@@ -2,6 +2,7 @@ package jiracmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/coryb/figtree"
|
||||
"github.com/coryb/oreo"
|
||||
@@ -48,7 +49,33 @@ func CmdAssignUsage(cmd *kingpin.CmdClause, opts *AssignOptions) error {
|
||||
|
||||
// CmdAssign will assign an issue to a user
|
||||
func CmdAssign(o *oreo.Client, globals *jiracli.GlobalOptions, opts *AssignOptions) error {
|
||||
err := jira.IssueAssign(o, globals.Endpoint.Value, opts.Issue, opts.Assignee)
|
||||
if globals.JiraDeploymentType.Value == "" {
|
||||
serverInfo, err := jira.ServerInfo(o, globals.Endpoint.Value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
globals.JiraDeploymentType.Value = strings.ToLower(serverInfo.DeploymentType)
|
||||
}
|
||||
|
||||
assignFunc := jira.IssueAssign
|
||||
if globals.JiraDeploymentType.Value == jiracli.CloudDeploymentType {
|
||||
if opts.Assignee != "" && opts.Assignee != "-1" {
|
||||
users, err := jira.UserSearch(o, globals.Endpoint.Value, &jira.UserSearchOptions{
|
||||
Username: opts.Assignee,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(users) > 1 {
|
||||
return fmt.Errorf("Found %d accounts for users with username %q", len(users), opts.Assignee)
|
||||
} else if len(users) == 1 {
|
||||
opts.Assignee = users[0].AccountID
|
||||
}
|
||||
}
|
||||
assignFunc = jira.IssueAssignAccountID
|
||||
}
|
||||
|
||||
err := assignFunc(o, globals.Endpoint.Value, opts.Issue, opts.Assignee)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package jiracmd
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/coryb/figtree"
|
||||
"github.com/coryb/oreo"
|
||||
@@ -62,6 +63,14 @@ func CmdCreateUsage(cmd *kingpin.CmdClause, opts *CreateOptions) error {
|
||||
// CmdCreate sends the create-metadata to the "create" template for editing, then
|
||||
// will parse the edited document as YAML and submit the document to jira.
|
||||
func CmdCreate(o *oreo.Client, globals *jiracli.GlobalOptions, opts *CreateOptions) error {
|
||||
if globals.JiraDeploymentType.Value == "" {
|
||||
serverInfo, err := jira.ServerInfo(o, globals.Endpoint.Value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
globals.JiraDeploymentType.Value = strings.ToLower(serverInfo.DeploymentType)
|
||||
}
|
||||
|
||||
type templateInput struct {
|
||||
Meta *jiradata.IssueType `yaml:"meta" json:"meta"`
|
||||
Overrides map[string]string `yaml:"overrides" json:"overrides"`
|
||||
@@ -86,6 +95,12 @@ func CmdCreate(o *oreo.Client, globals *jiracli.GlobalOptions, opts *CreateOptio
|
||||
|
||||
var issueResp *jiradata.IssueCreateResponse
|
||||
err = jiracli.EditLoop(&opts.CommonOptions, &input, &issueUpdate, func() error {
|
||||
if globals.JiraDeploymentType.Value == jiracli.CloudDeploymentType {
|
||||
err := fixGDPRUserFields(o, globals.Endpoint.Value, createMeta.Fields, issueUpdate.Fields)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
issueResp, err = jira.CreateIssue(o, globals.Endpoint.Value, &issueUpdate)
|
||||
return err
|
||||
})
|
||||
|
||||
+108
@@ -2,6 +2,7 @@ package jiracmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/coryb/figtree"
|
||||
"github.com/coryb/oreo"
|
||||
@@ -71,6 +72,14 @@ func CmdEditUsage(cmd *kingpin.CmdClause, opts *EditOptions, fig *figtree.FigTre
|
||||
|
||||
// Edit will get issue data and send to "edit" template
|
||||
func CmdEdit(o *oreo.Client, globals *jiracli.GlobalOptions, opts *EditOptions) error {
|
||||
if globals.JiraDeploymentType.Value == "" {
|
||||
serverInfo, err := jira.ServerInfo(o, globals.Endpoint.Value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
globals.JiraDeploymentType.Value = strings.ToLower(serverInfo.DeploymentType)
|
||||
}
|
||||
|
||||
type templateInput struct {
|
||||
*jiradata.Issue `yaml:",inline"`
|
||||
Meta *jiradata.EditMeta `yaml:"meta" json:"meta"`
|
||||
@@ -93,6 +102,12 @@ func CmdEdit(o *oreo.Client, globals *jiracli.GlobalOptions, opts *EditOptions)
|
||||
Overrides: opts.Overrides,
|
||||
}
|
||||
err = jiracli.EditLoop(&opts.CommonOptions, &input, &issueUpdate, func() error {
|
||||
if globals.JiraDeploymentType.Value == jiracli.CloudDeploymentType {
|
||||
err := fixGDPRUserFields(o, globals.Endpoint.Value, editMeta.Fields, issueUpdate.Fields)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return jira.EditIssue(o, globals.Endpoint.Value, opts.Issue, &issueUpdate)
|
||||
})
|
||||
if err != nil {
|
||||
@@ -123,6 +138,12 @@ func CmdEdit(o *oreo.Client, globals *jiracli.GlobalOptions, opts *EditOptions)
|
||||
Overrides: opts.Overrides,
|
||||
}
|
||||
err = jiracli.EditLoop(&opts.CommonOptions, &input, &issueUpdate, func() error {
|
||||
if globals.JiraDeploymentType.Value == jiracli.CloudDeploymentType {
|
||||
err := fixGDPRUserFields(o, globals.Endpoint.Value, editMeta.Fields, issueUpdate.Fields)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return jira.EditIssue(o, globals.Endpoint.Value, issueData.Key, &issueUpdate)
|
||||
})
|
||||
if err == jiracli.EditLoopAbort && len(results.Issues) > i+1 {
|
||||
@@ -152,3 +173,90 @@ func CmdEdit(o *oreo.Client, globals *jiracli.GlobalOptions, opts *EditOptions)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func fixUserField(ua jira.HttpClient, endpoint string, userField map[string]interface{}) error {
|
||||
if _, ok := userField["accountId"].(string); ok {
|
||||
// this field is already GDPR ready
|
||||
return nil
|
||||
}
|
||||
|
||||
if username, ok := userField["name"].(string); ok {
|
||||
users, err := jira.UserSearch(ua, endpoint, &jira.UserSearchOptions{
|
||||
Username: username,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(users) != 1 {
|
||||
return fmt.Errorf("Found %d accounts for username %q", len(users), username)
|
||||
}
|
||||
userField["accountId"] = users[0].AccountID
|
||||
return nil
|
||||
}
|
||||
|
||||
queryName, ok := userField["displayName"].(string)
|
||||
if !ok {
|
||||
queryName, ok = userField["emailAddress"].(string)
|
||||
if !ok {
|
||||
// no fields to search on, skip user lookup
|
||||
return nil
|
||||
}
|
||||
}
|
||||
users, err := jira.UserSearch(ua, endpoint, &jira.UserSearchOptions{
|
||||
// Query field will search users displayName and emailAddress
|
||||
Query: queryName,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(users) != 1 {
|
||||
return fmt.Errorf("Found %d accounts for users with query %q", len(users), queryName)
|
||||
}
|
||||
userField["accountId"] = users[0].AccountID
|
||||
return nil
|
||||
}
|
||||
|
||||
func fixGDPRUserFields(ua jira.HttpClient, endpoint string, meta jiradata.FieldMetaMap, fields map[string]interface{}) error {
|
||||
for fieldName, fieldMeta := range meta {
|
||||
// check to see if meta-field is in fields data, otherwise skip
|
||||
if _, ok := fields[fieldName]; !ok {
|
||||
continue
|
||||
}
|
||||
if fieldMeta.Schema.Type == "user" {
|
||||
userField, ok := fields[fieldName].(map[string]interface{})
|
||||
if !ok {
|
||||
// for some reason the field seems to be the wrong type in the data
|
||||
// even though the schema is a "user"
|
||||
continue
|
||||
}
|
||||
err := fixUserField(ua, endpoint, userField)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fields[fieldName] = userField
|
||||
}
|
||||
if fieldMeta.Schema.Type == "array" && fieldMeta.Schema.Items == "user" {
|
||||
listUserField, ok := fields[fieldName].([]interface{})
|
||||
if !ok {
|
||||
// for some reason the field seems to be the wrong type in the data
|
||||
// even though the schema is a list of "user"
|
||||
continue
|
||||
}
|
||||
for i, userFieldItem := range listUserField {
|
||||
userField, ok := userFieldItem.(map[string]interface{})
|
||||
if !ok {
|
||||
// for some reason the field seems to be the wrong type in the data
|
||||
// even though the schema is a "user"
|
||||
continue
|
||||
}
|
||||
err := fixUserField(ua, endpoint, userField)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
listUserField[i] = userField
|
||||
}
|
||||
fields[fieldName] = listUserField
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package jiracmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/coryb/figtree"
|
||||
"github.com/coryb/oreo"
|
||||
@@ -63,6 +64,14 @@ func CmdSubtaskUsage(cmd *kingpin.CmdClause, opts *SubtaskOptions) error {
|
||||
// CmdSubtask sends the subtask-metadata to the "subtask" template for editing, then
|
||||
// will parse the edited document as YAML and submit the document to jira.
|
||||
func CmdSubtask(o *oreo.Client, globals *jiracli.GlobalOptions, opts *SubtaskOptions) error {
|
||||
if globals.JiraDeploymentType.Value == "" {
|
||||
serverInfo, err := jira.ServerInfo(o, globals.Endpoint.Value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
globals.JiraDeploymentType.Value = strings.ToLower(serverInfo.DeploymentType)
|
||||
}
|
||||
|
||||
type templateInput struct {
|
||||
Meta *jiradata.IssueType `yaml:"meta" json:"meta"`
|
||||
Overrides map[string]string `yaml:"overrides" json:"overrides"`
|
||||
@@ -101,6 +110,12 @@ func CmdSubtask(o *oreo.Client, globals *jiracli.GlobalOptions, opts *SubtaskOpt
|
||||
|
||||
var issueResp *jiradata.IssueCreateResponse
|
||||
err = jiracli.EditLoop(&opts.CommonOptions, &input, &issueUpdate, func() error {
|
||||
if globals.JiraDeploymentType.Value == jiracli.CloudDeploymentType {
|
||||
err := fixGDPRUserFields(o, globals.Endpoint.Value, createMeta.Fields, issueUpdate.Fields)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
issueResp, err = jira.CreateIssue(o, globals.Endpoint.Value, &issueUpdate)
|
||||
return err
|
||||
})
|
||||
|
||||
@@ -86,6 +86,14 @@ func defaultResolution(transMeta *jiradata.Transition) string {
|
||||
|
||||
// CmdTransition will move state of the given issue to the given transtion
|
||||
func CmdTransition(o *oreo.Client, globals *jiracli.GlobalOptions, opts *TransitionOptions) error {
|
||||
if globals.JiraDeploymentType.Value == "" {
|
||||
serverInfo, err := jira.ServerInfo(o, globals.Endpoint.Value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
globals.JiraDeploymentType.Value = strings.ToLower(serverInfo.DeploymentType)
|
||||
}
|
||||
|
||||
issueData, err := jira.GetIssue(o, globals.Endpoint.Value, opts.Issue, nil)
|
||||
if err != nil {
|
||||
return jiracli.CliError(err)
|
||||
@@ -151,6 +159,12 @@ func CmdTransition(o *oreo.Client, globals *jiracli.GlobalOptions, opts *Transit
|
||||
Overrides: opts.Overrides,
|
||||
}
|
||||
err = jiracli.EditLoop(&opts.CommonOptions, &input, &issueUpdate, func() error {
|
||||
if globals.JiraDeploymentType.Value == jiracli.CloudDeploymentType {
|
||||
err := fixGDPRUserFields(o, globals.Endpoint.Value, transMeta.Fields, issueUpdate.Fields)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return jira.TransitionIssue(o, globals.Endpoint.Value, opts.Issue, &issueUpdate)
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -2,6 +2,7 @@ package jiracmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/coryb/figtree"
|
||||
"github.com/coryb/oreo"
|
||||
@@ -62,6 +63,29 @@ func CmdWatch(o *oreo.Client, globals *jiracli.GlobalOptions, opts *WatchOptions
|
||||
if opts.Watcher == "" {
|
||||
opts.Watcher = globals.User.Value
|
||||
}
|
||||
|
||||
if globals.JiraDeploymentType.Value == "" {
|
||||
serverInfo, err := jira.ServerInfo(o, globals.Endpoint.Value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
globals.JiraDeploymentType.Value = strings.ToLower(serverInfo.DeploymentType)
|
||||
}
|
||||
|
||||
if globals.JiraDeploymentType.Value == jiracli.CloudDeploymentType {
|
||||
users, err := jira.UserSearch(o, globals.Endpoint.Value, &jira.UserSearchOptions{
|
||||
Username: opts.Watcher,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(users) > 1 {
|
||||
return fmt.Errorf("Found %d accounts for users with username %q", len(users), opts.Watcher)
|
||||
} else if len(users) == 1 {
|
||||
opts.Watcher = users[0].AccountID
|
||||
}
|
||||
}
|
||||
|
||||
if opts.Action == WatcherAdd {
|
||||
if err := jira.IssueAddWatcher(o, globals.Endpoint.Value, opts.Issue, opts.Watcher); err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user