From e89f5c92710ca2193bb4063e1fadf787cafd4df7 Mon Sep 17 00:00:00 2001 From: Sho Mizutani Date: Sun, 16 Feb 2020 01:41:54 +0900 Subject: [PATCH] Add ADD_DATES option --- README.md | 1 + src/issue.go | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7655885..7cebba0 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ This action opens a new issue from an issue template. It parses the template's f ## Environment variables - `IFT_TEMPLATE_NAME` (*required*): The name of the issue template. For example, `report.md`. This action will look for the file in the `.github/ISSUE_TEMPLATE` directory. +- `ADD_DATES` (*optional*): Number of the dates to add. This is useful when you want to run this action to open an issue for the next week, not this week. ## Available template variables diff --git a/src/issue.go b/src/issue.go index 6e956e3..131ad19 100644 --- a/src/issue.go +++ b/src/issue.go @@ -7,6 +7,7 @@ import ( "io/ioutil" "os" "path/filepath" + "strconv" "strings" "text/template" "time" @@ -24,7 +25,15 @@ type issue struct { func NewIssue() *issue { i := &issue{} i.request = NewRequest(201) - i.date = NewDate(time.Now()) + if os.Getenv("ADD_DATES") == "" { + i.date = NewDate(time.Now()) + } else { + dates, err := strconv.Atoi(os.Getenv("ADD_DATES")) + if err != nil { + return nil + } + i.date = NewDate(time.Now().AddDate(0, 0, dates)) + } i.endpoint = "https://api.github.com/repos/" + os.Getenv("GITHUB_REPOSITORY") + "/issues" i.template = filepath.Join(os.Getenv("GITHUB_WORKSPACE"), ".github", "ISSUE_TEMPLATE", os.Getenv("IFT_TEMPLATE_NAME")) return i