Skip to content

Commit

Permalink
update print
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaxyi committed Mar 7, 2023
1 parent 29fa4e1 commit 7a766bc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
7 changes: 5 additions & 2 deletions cmd/searchIssueCmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ var CmdGetIssueOnTimeRange = &cobra.Command{
tokenClient := oauth2.NewClient(ctx, ts)
ghClient := github.NewClient(tokenClient)
ghClient.BaseURL, _ = url.Parse("https://api.github.com/")

toFile := false
if csvFileLocation != "" {
toFile = true
}
searchConditionOnTimeOnly := model.Conditions{
RepoOwner: repoOwner,
RepoName: repoName,
Expand All @@ -39,7 +42,7 @@ var CmdGetIssueOnTimeRange = &cobra.Command{
// return fmt.Errorf("connection to Github repo error: %+v", err)
//}

if err := searches.GetIssueOnCreationTimeRange(ctx, ghClient, searchConditionOnTimeOnly, csvFileLocation, appendOption); err != nil {
if err := searches.GetIssueOnCreationTimeRange(ctx, ghClient, searchConditionOnTimeOnly, csvFileLocation, appendOption, toFile); err != nil {
return err
}
return nil
Expand Down
24 changes: 16 additions & 8 deletions searches/TimeRangeIssueSearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/google/go-github/v47/github"
)

func GetIssueOnCreationTimeRange(ctx context.Context, ghClient *github.Client, condition model.Conditions, desFile string, appendOption string) error {
func GetIssueOnCreationTimeRange(ctx context.Context, ghClient *github.Client, condition model.Conditions, desFile string, appendOption string, toFile bool) error {
filter := fmt.Sprintf("repo:%s/%s is:issue created:%s..%s", condition.RepoOwner, condition.RepoName, condition.CreatedTimeStart, condition.CreatedTimeEnd)
totalIssueSet, _, err := ghClient.Search.Issues(ctx, filter, &github.SearchOptions{Order: "desc", ListOptions: github.ListOptions{PerPage: 100}})
if totalIssueSet == nil {
Expand All @@ -39,36 +39,42 @@ func GetIssueOnCreationTimeRange(ctx context.Context, ghClient *github.Client, c
if err != nil {
return fmt.Errorf("retrieving issues error: %+v", err)
}
AddIssueToList(issueResult, issueList)
AddIssueToList(issueResult, issueList, toFile)
}
}

if desFile != "" {
ExportResultToLocalCsv(issueList, desFile, appendOption)
fmt.Printf("data exported to csv: %s", desFile)
}
return nil
}

func GetIssueBasedOnKeyWordListAndTimeRange(ctx context.Context, ghClient *github.Client, condition model.Conditions, keyWordsList []string, desFile string, appendOption string) error {
issueList := map[int]interface{}{}
toFile := false
if desFile != "" {
toFile = true
}
for _, kw := range keyWordsList {
filter := fmt.Sprintf("repo:%s/%s is:issue in:title %s created:%s..%s", condition.RepoOwner, condition.RepoName, kw, condition.CreatedTimeStart, condition.CreatedTimeEnd)
err := KeyWordAndTimeRangeBasedIssueQueries(ctx, ghClient, filter, issueList)
err := KeyWordAndTimeRangeBasedIssueQueries(ctx, ghClient, filter, issueList, toFile)
if err != nil {
log.Printf("querying issue error:%+v", err)
return err
}
}
if desFile != "" {
ExportResultToLocalCsv(issueList, desFile, appendOption)
fmt.Printf("data exported to csv: %s", desFile)
}
return nil
}

func KeyWordAndTimeRangeBasedIssueQueries(ctx context.Context, ghClient *github.Client, filter string, issueList map[int]interface{}) error {
func KeyWordAndTimeRangeBasedIssueQueries(ctx context.Context, ghClient *github.Client, filter string, issueList map[int]interface{}, toFile bool) error {
totalIssueSet, _, err := ghClient.Search.Issues(ctx, filter, &github.SearchOptions{Order: "asc", ListOptions: github.ListOptions{PerPage: 100}})
if totalIssueSet == nil {
return fmt.Errorf("no issue Found by consition: %s, suggested to check your github token", filter)
return fmt.Errorf("no issue Found by condition: %s, suggested to check your github token", filter)
}
var totalIssueCount int
if totalIssueSet.Total != nil {
Expand All @@ -83,7 +89,7 @@ func KeyWordAndTimeRangeBasedIssueQueries(ctx context.Context, ghClient *github.
if err != nil {
return fmt.Errorf("retrieving issues error: %+v", err)
}
AddIssueToList(issueResult, issueList)
AddIssueToList(issueResult, issueList, toFile)
}
}
if err != nil {
Expand All @@ -93,7 +99,7 @@ func KeyWordAndTimeRangeBasedIssueQueries(ctx context.Context, ghClient *github.
return nil
}

func AddIssueToList(ghResult *github.IssuesSearchResult, issueList map[int]interface{}) {
func AddIssueToList(ghResult *github.IssuesSearchResult, issueList map[int]interface{}, toFile bool) {
var issueNum int

for _, issue := range ghResult.Issues {
Expand Down Expand Up @@ -165,7 +171,9 @@ func AddIssueToList(ghResult *github.IssuesSearchResult, issueList map[int]inter
dataInBuffer = append(dataInBuffer, issueType)
dataInBuffer = append(dataInBuffer, item["serviceLabel"].(string))
dataInBuffer = append(dataInBuffer, item["labeledBug"].(string))
fmt.Println(dataInBuffer)
if !toFile {
fmt.Println(dataInBuffer)
}
issueList[issueNum] = dataInBuffer
}
}
Expand Down

0 comments on commit 7a766bc

Please sign in to comment.