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 1 commit
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
approval-issue-title: "title"
DameonSmith marked this conversation as resolved.
Show resolved Hide resolved
```

- `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.
- `approval-issue-title` is a string that will be appened to the title of the issue.
DameonSmith marked this conversation as resolved.
Show resolved Hide resolved
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
approval-issue-title:
description: The custom subtitle for the issue.
DameonSmith marked this conversation as resolved.
Show resolved Hide resolved
DameonSmith marked this conversation as resolved.
Show resolved Hide resolved
required: false
runs:
using: docker
image: docker://ghcr.io/trstringer/manual-approval:1.4.0
23 changes: 15 additions & 8 deletions approval.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,25 @@ type approvalEnvironment struct {
minimumApprovals int
approvalIssue *github.Issue
approvalIssueNumber int
approvalIssueTitle 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, approvalIssueTitle string) (*approvalEnvironment, error) {
repoOwnerAndName := strings.Split(repoFullName, "/")
if len(repoOwnerAndName) != 2 {
return nil, fmt.Errorf("repo owner and name in unexpected format: %s", repoFullName)
}
repo := repoOwnerAndName[1]

return &approvalEnvironment{
client: client,
repoFullName: repoFullName,
repo: repo,
repoOwner: repoOwner,
runID: runID,
approvers: approvers,
minimumApprovals: minimumApprovals,
client: client,
repoFullName: repoFullName,
repo: repo,
repoOwner: repoOwner,
runID: runID,
approvers: approvers,
minimumApprovals: minimumApprovals,
approvalIssueTitle: approvalIssueTitle,
}, 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.approvalIssueTitle != "" {
issueTitle = fmt.Sprintf("%s: %s", issueTitle, a.approvalIssueTitle)
}

issueBody := fmt.Sprintf(`Workflow is pending manual review.
URL: %s

Expand Down
13 changes: 7 additions & 6 deletions constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import "time"
const (
pollingInterval time.Duration = 10 * time.Second

envVarRepoFullName string = "GITHUB_REPOSITORY"
envVarRunID string = "GITHUB_RUN_ID"
envVarRepoOwner string = "GITHUB_REPOSITORY_OWNER"
envVarToken string = "INPUT_SECRET"
envVarApprovers string = "INPUT_APPROVERS"
envVarMinimumApprovals string = "INPUT_MINIMUM-APPROVALS"
envVarRepoFullName string = "GITHUB_REPOSITORY"
envVarRunID string = "GITHUB_RUN_ID"
envVarRepoOwner string = "GITHUB_REPOSITORY_OWNER"
envVarToken string = "INPUT_SECRET"
envVarApprovers string = "INPUT_APPROVERS"
envVarMinimumApprovals string = "INPUT_MINIMUM-APPROVALS"
envVarApprovalIssueTitle string = "INPUT_APPROVAL-ISSUE-TITLE"
trstringer marked this conversation as resolved.
Show resolved Hide resolved
)

var (
Expand Down
5 changes: 4 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,10 @@ func main() {
os.Exit(1)
}

apprv, err := newApprovalEnvironment(client, repoFullName, repoOwner, runID, approvers, minimumApprovals)
approvalIssueTitle := os.Getenv(envVarApprovalIssueTitle)

apprv, err := newApprovalEnvironment(client, repoFullName, repoOwner, runID, approvers, minimumApprovals, approvalIssueTitle)

trstringer marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
fmt.Printf("error creating approval environment: %v\n", err)
os.Exit(1)
Expand Down