ref: 4dbbe5f84485a1507c995683ab98ab6b32b76330
parent: 9be022b54341bef76e62871c352adc6e7a77d9a3
author: Kenny Levinsen <w@kl.wtf>
date: Thu Jun 9 19:18:40 EDT 2016
Change comment details
--- a/README.md
+++ b/README.md
@@ -56,7 +56,13 @@
ABC-1/
assignee
comments/
- 1
+ 1/
+ author
+ updated
+ created
+ comment
+ 2/
+ ...
...
comment
components
@@ -78,10 +84,10 @@
type
worklog/
1/
- comment
author
- time
started
+ time
+ comment
...
ABC-2/
...
--- a/jira.go
+++ b/jira.go
@@ -83,66 +83,119 @@
s = append(s, wr.ID)
}
- return StringsToStats(s, 0555, "jira", "jira"), nil
+ return StringsToStats(s, 0555|qp.DMDIR, "jira", "jira"), nil
}
type CommentView struct {
issueNo string
+ comment string
}
-func (cw *CommentView) Walk(jc *Client, name string) (trees.File, error) {
- switch name {
+func (cw *CommentView) Walk(jc *Client, file string) (trees.File, error) {
+ if !StringExistsInSets(file, []string{"author", "comment", "updated", "created"}) {
+ return nil, nil
+ }
+
+ cmt, err := GetComment(jc, cw.issueNo, cw.comment)
+ if err != nil {
+ return nil, err
+ }
+
+ var cnt []byte
+ writable := false
+ forceTrunc := true
+ switch file {
+ case "author":
+ cnt = []byte(cmt.Author.Name + "\n")
case "comment":
- sf := trees.NewSyntheticFile(name, 0777, "jira", "jira")
- onClose := func() error {
- sf.Lock()
- body := string(sf.Content)
- sf.Unlock()
+ cnt = []byte(cmt.Body)
+ forceTrunc = false
+ writable = true
+ case "updated":
+ cnt = []byte(cmt.Updated + "\n")
+ case "created":
+ cnt = []byte(cmt.Created + "\n")
+ }
+ var perm qp.FileMode
+ if writable {
+ perm = 0777
+ } else {
+ perm = 0555
+ }
+ sf := trees.NewSyntheticFile(file, perm, "jira", "jira")
+ sf.SetContent(cnt)
- return AddComment(jc, cw.issueNo, body)
+ onClose := func() error {
+ sf.RLock()
+ str := string(sf.Content)
+ sf.RUnlock()
+
+ switch file {
+ case "comment":
+ return SetComment(jc, cw.issueNo, cw.comment, str)
}
- return NewCloseSaver(sf, onClose), nil
- default:
- cmt, err := GetComment(jc, cw.issueNo, name)
- if err != nil {
- return nil, err
- }
- if len(cmt.Body) > 0 && cmt.Body[len(cmt.Body)-1] != '\n' {
- cmt.Body += "\n"
- }
+ return nil
+ }
- sf := trees.NewSyntheticFile(name, 0777, cmt.Author.Name, "jira")
- sf.SetContent([]byte(cmt.Body))
+ if writable {
+ cs := NewCloseSaver(sf, onClose)
+ cs.forceTrunc = forceTrunc
+ return cs, nil
+ }
+ return sf, nil
+}
+
+func (cw *CommentView) List(jc *Client) ([]qp.Stat, error) {
+ a := StringsToStats([]string{"comment"}, 0777, "jira", "jira")
+ b := StringsToStats([]string{"author", "updated", "created"}, 0555, "jira", "jira")
+ return append(a, b...), nil
+}
+
+type IssueCommentView struct {
+ issueNo string
+}
+
+func (icv *IssueCommentView) Walk(jc *Client, file string) (trees.File, error) {
+ switch file {
+ case "comment":
+ sf := trees.NewSyntheticFile(file, 0777, "jira", "jira")
onClose := func() error {
sf.Lock()
body := string(sf.Content)
sf.Unlock()
- return SetComment(jc, cw.issueNo, name, body)
+ return AddComment(jc, icv.issueNo, body)
}
-
return NewCloseSaver(sf, onClose), nil
+ default:
+ _, err := GetComment(jc, icv.issueNo, file)
+ if err != nil {
+ return nil, err
+ }
+ cv := &CommentView{issueNo: icv.issueNo, comment: file}
+ return NewJiraDir(file, 0777|qp.DMDIR, "jira", "jira", jc, cv)
}
}
-func (cw *CommentView) List(jc *Client) ([]qp.Stat, error) {
- strs, err := GetCommentsForIssue(jc, cw.issueNo)
+func (icv *IssueCommentView) List(jc *Client) ([]qp.Stat, error) {
+ strs, err := GetCommentsForIssue(jc, icv.issueNo)
if err != nil {
return nil, err
}
- strs = append(strs, "comment")
+ a := StringsToStats(strs, 0777|qp.DMDIR, "jira", "jira")
+ b := StringsToStats([]string{"comment"}, 0777, "jira", "jira")
- return StringsToStats(strs, 0777, "jira", "jira"), nil
+ return append(a, b...), nil
}
-func (cw *CommentView) Remove(jc *Client, name string) error {
+func (icv *IssueCommentView) Remove(jc *Client, name string) error {
switch name {
case "comment":
return trees.ErrPermissionDenied
default:
- return RemoveComment(jc, cw.issueNo, name)
+ return RemoveComment(jc, icv.issueNo, name)
}
}
@@ -378,7 +431,7 @@
"jira",
"jira",
jc,
- &CommentView{issueNo: iw.issueNo})
+ &IssueCommentView{issueNo: iw.issueNo})
case "worklog":
return NewJiraDir(file,
0555|qp.DMDIR,