From 3ecbcf2753800fa8f521c5ec4c7781fc8a7c4dbc Mon Sep 17 00:00:00 2001 From: Dameon Smith Date: Thu, 9 Jun 2022 07:09:09 -0600 Subject: [PATCH] Adding support for custom titles. (#18) * Adding support for custom titles. * Cleaning up blank lines in main.go * Renaming approvalIssueTitle to IssueTitle in all relavent places. * Fixing period in README Co-authored-by: Thomas Stringer * Remove period in action doc. Co-authored-by: Thomas Stringer Co-authored-by: Thomas Stringer --- README.md | 2 ++ action.yaml | 3 +++ approval.go | 9 ++++++++- constants.go | 1 + main.go | 3 ++- 5 files changed, 16 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4828206..61eaa8b 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,9 @@ steps: secret: ${{ github.TOKEN }} approvers: user1,user2 minimum-approvals: 1 + issue-title: "Deploying v1.3.5 to prod from staging" ``` - `approvers` is a comma-delimited list of all required approvers. - `minimum-approvals` is an integer that sets the minimum number of approvals required to progress the workflow. Defaults to ALL approvers. +- `issue-title` is a string that will be appened to the title of the issue. diff --git a/action.yaml b/action.yaml index b88c45c..5d610d8 100644 --- a/action.yaml +++ b/action.yaml @@ -10,6 +10,9 @@ inputs: minimum-approvals: description: Minimum number of approvals to progress workflow required: false + issue-title: + description: The custom subtitle for the issue + required: false runs: using: docker image: docker://ghcr.io/trstringer/manual-approval:1.4.0 diff --git a/approval.go b/approval.go index 6bb777e..d1bc050 100644 --- a/approval.go +++ b/approval.go @@ -19,9 +19,10 @@ type approvalEnvironment struct { minimumApprovals int approvalIssue *github.Issue approvalIssueNumber int + issueTitle string } -func newApprovalEnvironment(client *github.Client, repoFullName, repoOwner string, runID int, approvers []string, minimumApprovals int) (*approvalEnvironment, error) { +func newApprovalEnvironment(client *github.Client, repoFullName, repoOwner string, runID int, approvers []string, minimumApprovals int, issueTitle string) (*approvalEnvironment, error) { repoOwnerAndName := strings.Split(repoFullName, "/") if len(repoOwnerAndName) != 2 { return nil, fmt.Errorf("repo owner and name in unexpected format: %s", repoFullName) @@ -36,6 +37,7 @@ func newApprovalEnvironment(client *github.Client, repoFullName, repoOwner strin runID: runID, approvers: approvers, minimumApprovals: minimumApprovals, + issueTitle: issueTitle, }, nil } @@ -45,6 +47,11 @@ func (a approvalEnvironment) runURL() string { func (a *approvalEnvironment) createApprovalIssue(ctx context.Context) error { issueTitle := fmt.Sprintf("Manual approval required for workflow run %d", a.runID) + + if a.issueTitle != "" { + issueTitle = fmt.Sprintf("%s: %s", issueTitle, a.issueTitle) + } + issueBody := fmt.Sprintf(`Workflow is pending manual review. URL: %s diff --git a/constants.go b/constants.go index f1ee6e9..2d1b532 100644 --- a/constants.go +++ b/constants.go @@ -11,6 +11,7 @@ const ( envVarToken string = "INPUT_SECRET" envVarApprovers string = "INPUT_APPROVERS" envVarMinimumApprovals string = "INPUT_MINIMUM-APPROVALS" + envVarIssueTitle string = "INPUT_ISSUE-TITLE" ) var ( diff --git a/main.go b/main.go index 09e4516..348bc70 100644 --- a/main.go +++ b/main.go @@ -137,7 +137,8 @@ func main() { os.Exit(1) } - apprv, err := newApprovalEnvironment(client, repoFullName, repoOwner, runID, approvers, minimumApprovals) + issueTitle := os.Getenv(envVarIssueTitle) + apprv, err := newApprovalEnvironment(client, repoFullName, repoOwner, runID, approvers, minimumApprovals, issueTitle) if err != nil { fmt.Printf("error creating approval environment: %v\n", err) os.Exit(1)