* use forked yaml.v2 so as to not lose line terminations present in jira fields

* adding a |~ literal yaml syntax to just chomp a single newline (again to preserve
existing formatting in jira fields)
* for indent/comment allow for unicode line termination characters that yaml will use for parsing
This commit is contained in:
Cory Bennett
2015-09-15 19:31:38 -07:00
parent 4265913001
commit f84e77fd84
4 changed files with 23 additions and 14 deletions
+3 -5
View File
@@ -6,7 +6,7 @@ import (
"fmt"
"github.com/kballard/go-shellquote"
"github.com/op/go-logging"
"gopkg.in/yaml.v2"
"gopkg.in/coryb/yaml.v2"
"io/ioutil"
"net/http"
"net/http/cookiejar"
@@ -250,10 +250,7 @@ func (c *Cli) editTemplate(template string, tmpFilePrefix string, templateData m
}
}
editing := true
if val, ok := c.opts["edit"].(bool); ok && !val {
editing = false
}
editing := c.getOptBool("edit", true)
tmpFileNameOrig := fmt.Sprintf("%s.orig", tmpFileName)
copyFile(tmpFileName, tmpFileNameOrig)
@@ -275,6 +272,7 @@ func (c *Cli) editTemplate(template string, tmpFilePrefix string, templateData m
}
return err
}
diff := exec.Command("diff", "-q", tmpFileNameOrig, tmpFileName)
// if err == nil then diff found no changes
if err := diff.Run(); err == nil {
+5 -5
View File
@@ -54,7 +54,7 @@ const default_edit_template = `# issue: {{ .key }}
update:
comment:
- add:
body: |
body: |~
{{ or .overrides.comment "" | indent 10 }}
fields:
summary: {{ or .overrides.summary .fields.summary }}
@@ -71,7 +71,7 @@ fields:
- name: {{ .overrides.watcher}}{{end}}
priority: # Values: {{ range .meta.fields.priority.allowedValues }}{{.name}}, {{end}}
name: {{ or .overrides.priority .fields.priority.name }}
description: |
description: |~
{{ or .overrides.description (or .fields.description "") | indent 4 }}
# comments:
# {{ range .fields.comment.comments }} - | # {{.author.name}} at {{.created}}
@@ -94,7 +94,7 @@ const default_create_template = `fields:
name: {{ or .overrides.priority "unassigned" }}
components: # Values: {{ range .meta.fields.components.allowedValues }}{{.name}}, {{end}}{{ range split "," (or .overrides.components "")}}
- name: {{ . }}{{end}}
description: |
description: |~
{{ or .overrides.description "" | indent 4 }}
assignee:
name: {{ or .overrides.assignee "" }}
@@ -106,14 +106,14 @@ const default_create_template = `fields:
- name:
`
const default_comment_template = `body: |
const default_comment_template = `body: |~
{{ or .overrides.comment "" | indent 2 }}
`
const default_transition_template = `update:
comment:
- add:
body: |
body: |~
{{ or .overrides.comment "" | indent 10 }}
fields:{{if .meta.fields.assignee}}
assignee:
+14 -3
View File
@@ -125,15 +125,26 @@ func runTemplate(templateContent string, data interface{}, out io.Writer) error
}
},
"indent": func(spaces int, content string) string {
indent := make([]byte, spaces+1, spaces+1)
indent := make([]rune, spaces+1, spaces+1)
indent[0] = '\n'
for i := 1; i < spaces+1; i += 1 {
indent[i] = ' '
}
return strings.Replace(content, "\n", string(indent), -1)
lineSeps := []rune{'\n', '\u0085', '\u2028', '\u2029'}
for _, sep := range lineSeps {
indent[0] = sep
content = strings.Replace(content, string(sep), string(indent), -1)
}
return content
},
"comment": func(content string) string {
return strings.Replace(content, "\n", "\n# ", -1)
lineSeps := []rune{'\n', '\u0085', '\u2028', '\u2029'}
for _, sep := range lineSeps {
content = strings.Replace(content, string(sep), string([]rune{sep, '#', ' '}), -1)
}
return content
},
"color": func(color string) string {
return ansi.ColorCode(color)
+1 -1
View File
@@ -6,7 +6,7 @@ import (
"github.com/Netflix-Skunkworks/go-jira/jira/cli"
"github.com/coryb/optigo"
"github.com/op/go-logging"
"gopkg.in/yaml.v2"
"gopkg.in/coryb/yaml.v2"
"io/ioutil"
"os"
"os/exec"