From e910ad1171d9b3ca3e55c3c08862aae06ce35697 Mon Sep 17 00:00:00 2001 From: Guilhem Lettron Date: Thu, 2 Jul 2020 09:47:17 +0200 Subject: [PATCH] add aggegate option (#6) fix #4 --- README.md | 4 ++++ action.yml | 2 ++ main.go | 31 +++++++++++++++++++++++-------- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 522aa18..b2aeec6 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,10 @@ Labels to add, comma separated. Log issue creation but do nothing +### `aggregate` + +Aggregate all items in a single issue + ### `characterLimit` Limit size of issue content diff --git a/action.yml b/action.yml index 02c0cdd..01a8fac 100644 --- a/action.yml +++ b/action.yml @@ -17,6 +17,8 @@ inputs: description: "Labels to add, comma separated" dry-run: description: "Log issue creation but do nothing" + aggregate: + description: "Aggregate all items in a single issue" characterLimit: description: "Limit size of issue content" outputs: diff --git a/main.go b/main.go index 45c4dc2..0cc0942 100644 --- a/main.go +++ b/main.go @@ -84,7 +84,7 @@ func main() { } gha.Debug(fmt.Sprintf("%d issues", len(issues)), ghaLogOption) - var createdIssues []string + var createdIssues []*github.IssueRequest // Iterate for _, item := range feed.Items { @@ -148,25 +148,40 @@ func main() { body := tpl.String() - // Create Issue + // Default to creating an issue per item + // Create first issue if aggregate + if aggregate, err := strconv.ParseBool(gha.GetInput("aggregate")); err != nil || !aggregate || len(createdIssues) == 0 { + // Create Issue - issueRequest := &github.IssueRequest{ - Title: &title, - Body: &body, - Labels: &labels, + issueRequest := &github.IssueRequest{ + Title: &title, + Body: &body, + Labels: &labels, + } + createdIssues = append(createdIssues, issueRequest) + } else { + title = strings.Join([]string{gha.GetInput("prefix"), time.Now().Format(time.RFC822)}, " ") + createdIssues[0].Title = &title + + body = fmt.Sprintf("%s\n\n%s", *createdIssues[0].Body, body) + createdIssues[0].Body = &body } + } + + for _, issueRequest := range createdIssues { if dr, err := strconv.ParseBool(gha.GetInput("dry-run")); err != nil || !dr { + _, _, err := client.Issues.Create(ctx, repo[0], repo[1], issueRequest) if err != nil { gha.Warning(fmt.Sprintf("Fail create issue %s: %s", *issueRequest.Title, err), ghaLogOption) continue } + } else { gha.Debug(fmt.Sprintf("Creating Issue '%s' with content '%s'", *issueRequest.Title, *issueRequest.Body), ghaLogOption) } - createdIssues = append(createdIssues, *issueRequest.Title) } - gha.SetOutput("issues", strings.Join(createdIssues, ",")) + // gha.SetOutput("issues", strings.Join(createdIssues, ",")) }