@@ -2,96 +2,83 @@ package phlow
22
33import (
44 "fmt"
5- "os"
65 "github.com/praqma/git-phlow/plugins"
7- "os/exec"
8- "strings"
96 "github.com/praqma/git-phlow/executor"
10- "bytes "
11- "github.com/praqma/git-phlow/ui "
12- "runtime "
7+ "github.com/praqma/git-phlow/setting "
8+ "github.com/praqma/git-phlow/options "
9+ "github.com/praqma/git-phlow/githandler "
1310)
1411
15- func Issues () {
16- ui .PhlowSpinner .Start ("" )
17- issues , err := plugins .GitHub .GetIssues ()
18- if err != nil {
19- fmt .Println (err )
20- os .Exit (0 )
12+ //IssueCaller ...
13+ //prints issue with given target
14+ func IssueCaller () {
15+ conf := setting .NewProjectStg (options .GlobalFlagTarget )
16+
17+ if conf .Service == "github" {
18+ PrintIssues (conf , FetchGH )
2119 }
22- ui .PhlowSpinner .Stop ()
2320
24- //Collection Issues to a string
25- var buffer bytes.Buffer
26- for _ , issue := range issues {
27- buffer .WriteString (issue .ToString ())
21+ if conf .Service == "jira" {
22+ PrintIssues (conf , FetchJ )
2823 }
24+ }
2925
30- pager := GetPager ()
26+ //Fetch ...
27+ //Type for getting issues
28+ type Fetch func (* setting.ProjectSetting ) ([]plugins.Stringer , error )
3129
32- if pager == "" {
33- fmt .Println (buffer .String ())
34- } else {
35- IssuesInPager ("less" , buffer .String ())
30+ //Fetch ...
31+ //Fetch for github
32+ func FetchGH (conf * setting.ProjectSetting ) ([]plugins.Stringer , error ) {
33+ git := githandler.Git {Run : executor .RunGit }
34+ remote , err := git .LSRemote ("--get-url" , conf .Remote )
35+ if err != nil {
36+ return nil , err
3637 }
37- }
3838
39- //GetPager ...
40- //return the pager if set
41- func GetPager () string {
42- pager := os .Getenv ("PAGER" )
43- if pager != "" {
44- return pager
39+ token , err := git .Config ("--get" , "phlow.token" )
40+ if err != nil {
41+ return nil , err
4542 }
4643
47- if runtime .GOOS == "windows" {
48- return "more"
44+ oar := githandler .OrgAndRepo (remote )
45+
46+ list , err := plugins .GetIssuesGitHub (conf .IssueApi , oar .Organisation , oar .Repository , token )
47+ if err != nil {
48+ return nil , err
4949 }
50- return ""
50+ return list , nil
5151}
5252
53- func IssuesInPager ( pager , text string ) error {
54- cmd := exec . Command ( pager )
55- cmd . Stdin = strings . NewReader ( text )
56- cmd . Stdout = os . Stdout
57- err := executor . ExecuteCommander ( cmd )
53+ //FetchJ
54+ //fetch for Jira
55+ func FetchJ ( conf * setting. ProjectSetting ) ([]plugins. Stringer , error ) {
56+ git := githandler. Git { Run : executor . RunGit }
57+ user , err := git . Config ( "--get" , "phlow.jirauser" )
5858 if err != nil {
59- return err
59+ return nil , err
6060 }
61- return nil
61+
62+ token , err := git .Config ("--get" , "phlow.jiratoken" )
63+ if err != nil {
64+ return nil , err
65+ }
66+ list , err := plugins .QueryIssues (conf .IssueApi , user , token )
67+ if err != nil {
68+ return nil , err
69+ }
70+ return list , nil
6271}
6372
64- //IssueList ...
65- //List open issues from GitHub
66- func IssueList () {
73+ func PrintIssues (conf * setting.ProjectSetting , fetch Fetch ) {
74+ list , err := fetch (conf )
75+ if err != nil {
76+ fmt .Println (err )
77+ return
78+ }
6779
68- //ui.PhlowSpinner.Start("")
69- //
70- //ui.PhlowSpinner.Stop()
71- //
72- ////Nested function for finding user issues
73- //var userIssue = func(issue []plugins.AssigneeIssue) bool {
74- // user := githandler.ConfigGet("user", "phlow")
75- // for _, u := range issue {
76- // if u.Login == user {
77- // return true
78- // }
79- // }
80- // return false
81- //}
82- //
83- //fmt.Println(ui.Format.MileStone("# Issue"))
84- //
85- //for _, issue := range issues {
86- // assignees := issue.Assignees
87- // //If mine is true we print on issues assigned to a user
88- // if options.GlobalFlagMine {
89- // if userIssue(assignees) {
90- // printIssue(issue)
91- // }
92- // } else {
93- // printIssue(issue)
94- // }
95- //}
80+ for _ , iss := range list {
81+ fmt .Println (iss .ToString ())
82+ }
9683
9784}
0 commit comments