From c454b4f2718aa79d798342dd0121e0cda259d720 Mon Sep 17 00:00:00 2001 From: Matt Petersen Date: Mon, 15 Jul 2024 08:50:38 -0600 Subject: [PATCH] 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)