Add Support For Labels

This commit is contained in:
Matt Petersen 2024-07-15 12:09:16 -06:00
parent b55b06bc42
commit aba70161cf
8 changed files with 18 additions and 22 deletions

View file

@ -4,7 +4,7 @@ WORKDIR /var/app
RUN CGO_ENABLED=0 go build -o app .
FROM alpine:3.14
LABEL org.opencontainers.image.source https://github.com/radicldefense/manual-approval
LABEL org.opencontainers.image.source https://github.com/trstringer/manual-approval
RUN apk update && apk add ca-certificates
COPY --from=builder /var/app/app /var/app/app
CMD ["/var/app/app"]

View file

@ -1,4 +1,4 @@
IMAGE_REPO=ghcr.io/radicldefense/rad-manual-approval
IMAGE_REPO=ghcr.io/trstringer/manual-approval
.PHONY: build
build:

View file

@ -33,6 +33,7 @@ steps:
minimum-approvals: 1
issue-title: "Deploying v1.3.5 to prod from staging"
issue-body: "Please approve or deny the deployment of version v1.3.5."
issue-labels: "deployment"
exclude-workflow-initiator-as-approver: false
additional-approved-words: ''
additional-denied-words: ''
@ -42,6 +43,7 @@ steps:
- `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 appended to the title of the issue.
- `issue-body` is a string that will be prepended to the body of the issue.
- `issue-labels` is a comma separated list of strings that will be added as labels to the issue.
- `exclude-workflow-initiator-as-approver` is a boolean that indicates if the workflow initiator (determined by the `GITHUB_ACTOR` environment variable) should be filtered from the final list of approvers. This is optional and defaults to `false`. Set this to `true` to prevent users in the `approvers` list from being able to self-approve workflows.
- `additional-approved-words` is a comma separated list of strings to expand the dictionary of words that indicate approval. This is optional and defaults to an empty string.
- `additional-denied-words` is a comma separated list of strings to expand the dictionary of words that indicate denial. This is optional and defaults to an empty string.

View file

@ -1,4 +1,4 @@
name: RADICL Manual Workflow Approval
name: Manual Workflow Approval
description: Pause a workflow and get user approval to continue
branding:
icon: pause
@ -22,12 +22,12 @@ inputs:
issue-body:
description: The custom body for the issue
required: false
issue-labels:
description: Labels to add to the issue
required: false
exclude-workflow-initiator-as-approver:
description: Whether or not to filter out the user who initiated the workflow as an approver if they are in the approvers list
default: false
labels:
description: Labels to add to the issue
required: false
additional-approved-words:
description: Comma separated list of words that can be used to approve beyond the defaults.
default: ''
@ -36,4 +36,4 @@ inputs:
default: ''
runs:
using: docker
image: docker://ghcr.io/radicldefense/rad-manual-approval:1.10
image: docker://ghcr.io/trstringer/manual-approval:1.9.1

View file

@ -19,12 +19,12 @@ type approvalEnvironment struct {
approvalIssueNumber int
issueTitle string
issueBody string
issueLabels []string
issueApprovers []string
minimumApprovals int
labels []string
}
func newApprovalEnvironment(client *github.Client, repoFullName, repoOwner string, runID int, approvers []string, minimumApprovals int, issueTitle, issueBody string, labels []string) (*approvalEnvironment, error) {
func newApprovalEnvironment(client *github.Client, repoFullName, repoOwner string, runID int, approvers []string, minimumApprovals int, issueTitle, issueBody string, issueLabels []string) (*approvalEnvironment, error) {
repoOwnerAndName := strings.Split(repoFullName, "/")
if len(repoOwnerAndName) != 2 {
return nil, fmt.Errorf("repo owner and name in unexpected format: %s", repoFullName)
@ -41,7 +41,7 @@ func newApprovalEnvironment(client *github.Client, repoFullName, repoOwner strin
minimumApprovals: minimumApprovals,
issueTitle: issueTitle,
issueBody: issueBody,
labels: labels,
issueLabels: issueLabels,
}, nil
}
@ -85,12 +85,11 @@ Respond %s to continue workflow or %s to cancel.`,
a.issueApprovers,
issueBody,
)
a.approvalIssue, _, err = a.client.Issues.Create(ctx, a.repoOwner, a.repo, &github.IssueRequest{
Title: &issueTitle,
Body: &issueBody,
Assignees: &a.issueApprovers,
Labels: &a.labels,
Labels: &a.issueLabels,
})
if err != nil {
return err

View file

@ -18,10 +18,10 @@ const (
envVarMinimumApprovals string = "INPUT_MINIMUM-APPROVALS"
envVarIssueTitle string = "INPUT_ISSUE-TITLE"
envVarIssueBody string = "INPUT_ISSUE-BODY"
envVarIssueLabels string = "INPUT_ISSUE-LABELS"
envVarExcludeWorkflowInitiatorAsApprover string = "INPUT_EXCLUDE-WORKFLOW-INITIATOR-AS-APPROVER"
envVarAdditionalApprovedWords string = "INPUT_ADDITIONAL-APPROVED-WORDS"
envVarAdditionalDeniedWords string = "INPUT_ADDITIONAL-DENIED-WORDS"
envVarLabels string = "INPUT_LABELS"
)
var (

2
go.mod
View file

@ -1,4 +1,4 @@
module github.com/radicldefense/rad-manual-approval
module github.com/trstringer/manual-approval
go 1.17

11
main.go
View file

@ -173,6 +173,8 @@ func main() {
issueTitle := os.Getenv(envVarIssueTitle)
issueBody := os.Getenv(envVarIssueBody)
issueLabels := strings.Split(strings.ReplaceAll(os.Getenv(envVarIssueLabels), " ", ""), ",")
minimumApprovalsRaw := os.Getenv(envVarMinimumApprovals)
minimumApprovals := 0
if minimumApprovalsRaw != "" {
@ -182,14 +184,7 @@ func main() {
os.Exit(1)
}
}
labelsRaw := os.Getenv(envVarLabels)
labels := []string{}
if labelsRaw != "" {
labels = strings.Split(labelsRaw, ",")
}
apprv, err := newApprovalEnvironment(client, repoFullName, repoOwner, runID, approvers, minimumApprovals, issueTitle, issueBody, labels)
apprv, err := newApprovalEnvironment(client, repoFullName, repoOwner, runID, approvers, minimumApprovals, issueTitle, issueBody, issueLabels)
if err != nil {
fmt.Printf("error creating approval environment: %v\n", err)
os.Exit(1)