Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for custom titles. #18

Merged
merged 5 commits into from
Jun 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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