From c454b4f2718aa79d798342dd0121e0cda259d720 Mon Sep 17 00:00:00 2001 From: Matt Petersen Date: Mon, 15 Jul 2024 08:50:38 -0600 Subject: [PATCH 1/5] Add Labels --- Makefile | 2 +- action.yaml | 5 ++++- approval.go | 6 +++++- constants.go | 1 + main.go | 10 +++++++++- 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 3ec553a..99a7490 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -IMAGE_REPO=ghcr.io/trstringer/manual-approval +IMAGE_REPO=ghcr.io/radicldefense/manual-approval .PHONY: build build: diff --git a/action.yaml b/action.yaml index 7866c0b..da5f5fd 100644 --- a/action.yaml +++ b/action.yaml @@ -25,6 +25,9 @@ inputs: 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 + lables: + 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: '' @@ -33,4 +36,4 @@ inputs: default: '' runs: using: docker - image: docker://ghcr.io/trstringer/manual-approval:1.9.1 + image: docker://ghcr.io/radicldefense/manual-approval:1.10 diff --git a/approval.go b/approval.go index e2bb13f..c5acd7a 100644 --- a/approval.go +++ b/approval.go @@ -21,9 +21,10 @@ type approvalEnvironment struct { issueBody string issueApprovers []string minimumApprovals int + labels []string } -func newApprovalEnvironment(client *github.Client, repoFullName, repoOwner string, runID int, approvers []string, minimumApprovals int, issueTitle, issueBody string) (*approvalEnvironment, error) { +func newApprovalEnvironment(client *github.Client, repoFullName, repoOwner string, runID int, approvers []string, minimumApprovals int, issueTitle, issueBody string, labels []string) (*approvalEnvironment, error) { repoOwnerAndName := strings.Split(repoFullName, "/") if len(repoOwnerAndName) != 2 { return nil, fmt.Errorf("repo owner and name in unexpected format: %s", repoFullName) @@ -40,6 +41,7 @@ func newApprovalEnvironment(client *github.Client, repoFullName, repoOwner strin minimumApprovals: minimumApprovals, issueTitle: issueTitle, issueBody: issueBody, + labels: labels, }, nil } @@ -83,10 +85,12 @@ 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, }) if err != nil { return err diff --git a/constants.go b/constants.go index 03e4b4e..4de36c0 100644 --- a/constants.go +++ b/constants.go @@ -21,6 +21,7 @@ const ( 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 ( diff --git a/main.go b/main.go index 5aad15e..3d7822f 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ import ( "os" "os/signal" "strconv" + "strings" "time" "github.com/google/go-github/v43/github" @@ -181,7 +182,14 @@ func main() { os.Exit(1) } } - apprv, err := newApprovalEnvironment(client, repoFullName, repoOwner, runID, approvers, minimumApprovals, issueTitle, issueBody) + + labelsRaw := os.Getenv(envVarLabels) + labels := []string{} + if labelsRaw != "" { + labels = strings.Split(labelsRaw, ",") + } + + apprv, err := newApprovalEnvironment(client, repoFullName, repoOwner, runID, approvers, minimumApprovals, issueTitle, issueBody, labels) if err != nil { fmt.Printf("error creating approval environment: %v\n", err) os.Exit(1) From 366066d5052f0f7e691786b215e2334c367099f0 Mon Sep 17 00:00:00 2001 From: Matt Petersen Date: Mon, 15 Jul 2024 09:02:39 -0600 Subject: [PATCH 2/5] Add Labels --- Dockerfile | 2 +- go.mod | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6ec73aa..33817da 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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/trstringer/manual-approval +LABEL org.opencontainers.image.source https://github.com/radicldefense/manual-approval RUN apk update && apk add ca-certificates COPY --from=builder /var/app/app /var/app/app CMD ["/var/app/app"] diff --git a/go.mod b/go.mod index 413e6d2..f7a2e06 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/trstringer/manual-approval +module github.com/radicldefense/manual-approval go 1.17 From 50e5c5e02bab2393dbbf4ce421b693fcbd0c3c49 Mon Sep 17 00:00:00 2001 From: Matt Petersen Date: Mon, 15 Jul 2024 09:23:14 -0600 Subject: [PATCH 3/5] RAD-Manual approval --- Makefile | 2 +- action.yaml | 4 ++-- go.mod | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 99a7490..082569a 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -IMAGE_REPO=ghcr.io/radicldefense/manual-approval +IMAGE_REPO=ghcr.io/radicldefense/rad-manual-approval .PHONY: build build: diff --git a/action.yaml b/action.yaml index da5f5fd..9247c35 100644 --- a/action.yaml +++ b/action.yaml @@ -1,4 +1,4 @@ -name: Manual Workflow Approval +name: RADICL Manual Workflow Approval description: Pause a workflow and get user approval to continue branding: icon: pause @@ -36,4 +36,4 @@ inputs: default: '' runs: using: docker - image: docker://ghcr.io/radicldefense/manual-approval:1.10 + image: docker://ghcr.io/radicldefense/rad-manual-approval:1.10 diff --git a/go.mod b/go.mod index f7a2e06..dbfb8e3 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/radicldefense/manual-approval +module github.com/radicldefense/rad-manual-approval go 1.17 From b55b06bc42c123f9ce9a92084639cc381ac5757d Mon Sep 17 00:00:00 2001 From: Matt Petersen Date: Mon, 15 Jul 2024 09:37:45 -0600 Subject: [PATCH 4/5] Fix name --- action.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yaml b/action.yaml index 9247c35..525649e 100644 --- a/action.yaml +++ b/action.yaml @@ -25,7 +25,7 @@ inputs: 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 - lables: + labels: description: Labels to add to the issue required: false additional-approved-words: From aba70161cf1e9440ea6d41546249eeccb407a741 Mon Sep 17 00:00:00 2001 From: Matt Petersen Date: Mon, 15 Jul 2024 12:09:16 -0600 Subject: [PATCH 5/5] Add Support For Labels --- Dockerfile | 2 +- Makefile | 2 +- README.md | 2 ++ action.yaml | 10 +++++----- approval.go | 9 ++++----- constants.go | 2 +- go.mod | 2 +- main.go | 11 +++-------- 8 files changed, 18 insertions(+), 22 deletions(-) diff --git a/Dockerfile b/Dockerfile index 33817da..6ec73aa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] diff --git a/Makefile b/Makefile index 082569a..3ec553a 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -IMAGE_REPO=ghcr.io/radicldefense/rad-manual-approval +IMAGE_REPO=ghcr.io/trstringer/manual-approval .PHONY: build build: diff --git a/README.md b/README.md index 25218e9..8340e53 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/action.yaml b/action.yaml index 525649e..d96c75a 100644 --- a/action.yaml +++ b/action.yaml @@ -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 diff --git a/approval.go b/approval.go index c5acd7a..e4a3d64 100644 --- a/approval.go +++ b/approval.go @@ -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 diff --git a/constants.go b/constants.go index 4de36c0..19a118f 100644 --- a/constants.go +++ b/constants.go @@ -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 ( diff --git a/go.mod b/go.mod index dbfb8e3..413e6d2 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/radicldefense/rad-manual-approval +module github.com/trstringer/manual-approval go 1.17 diff --git a/main.go b/main.go index 3d7822f..8fcc1e1 100644 --- a/main.go +++ b/main.go @@ -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)