Skip to content

Commit

Permalink
Adding support for custom titles. (#18)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
DameonSmith and trstringer committed Jun 9, 2022
1 parent 3f2b3dd commit 3ecbcf2
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
3 changes: 3 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 8 additions & 1 deletion approval.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -36,6 +37,7 @@ func newApprovalEnvironment(client *github.Client, repoFullName, repoOwner strin
runID: runID,
approvers: approvers,
minimumApprovals: minimumApprovals,
issueTitle: issueTitle,
}, nil
}

Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const (
envVarToken string = "INPUT_SECRET"
envVarApprovers string = "INPUT_APPROVERS"
envVarMinimumApprovals string = "INPUT_MINIMUM-APPROVALS"
envVarIssueTitle string = "INPUT_ISSUE-TITLE"
)

var (
Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3ecbcf2

Please sign in to comment.