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 <thomas@trstringer.com>

* Remove period in action doc.

Co-authored-by: Thomas Stringer <thomas@trstringer.com>

Co-authored-by: Thomas Stringer <thomas@trstringer.com>
This commit is contained in:
Dameon Smith 2022-06-09 07:09:09 -06:00 committed by GitHub
parent 3f2b3dd866
commit 3ecbcf2753
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 2 deletions

View file

@ -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.

View file

@ -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

View file

@ -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

View file

@ -11,6 +11,7 @@ const (
envVarToken string = "INPUT_SECRET"
envVarApprovers string = "INPUT_APPROVERS"
envVarMinimumApprovals string = "INPUT_MINIMUM-APPROVALS"
envVarIssueTitle string = "INPUT_ISSUE-TITLE"
)
var (

View file

@ -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)