Skip to content

Commit

Permalink
add aggegate option (#6)
Browse files Browse the repository at this point in the history
fix #4
  • Loading branch information
guilhem authored Jul 2, 2020
1 parent 7634d79 commit e910ad1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
31 changes: 23 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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, ","))
}

0 comments on commit e910ad1

Please sign in to comment.