From 8600531d96bf240ab7985e30b171623211e25ea2 Mon Sep 17 00:00:00 2001 From: Eric Ren Date: Wed, 5 Jul 2023 15:22:26 -0700 Subject: [PATCH] option to create issue with label (#1) --- Makefile | 2 +- README.md | 1 + action.yaml | 5 ++++- approval.go | 16 ++++++++++++++-- constants.go | 1 + main.go | 14 +++++++++++++- 6 files changed, 34 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 3ec553a..bf59bd7 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -IMAGE_REPO=ghcr.io/trstringer/manual-approval +IMAGE_REPO=us-west1-docker.pkg.dev/dl-dapper/dev/github/manual-approval .PHONY: build build: diff --git a/README.md b/README.md index 25218e9..6a7e9f7 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ steps: exclude-workflow-initiator-as-approver: false additional-approved-words: '' additional-denied-words: '' + labels: '' ``` - `approvers` is a comma-delimited list of all required approvers. An approver can either be a user or an org team. (*Note: Required approvers must have the ability to be set as approvers in the repository. If you add an approver that doesn't have this permission then you would receive an HTTP/402 Validation Failed error when running this action*) diff --git a/action.yaml b/action.yaml index cbd28ce..ad473b0 100644 --- a/action.yaml +++ b/action.yaml @@ -28,6 +28,9 @@ inputs: additional-denied-words: description: Comma separated list of words that can be used to deny beyond the defaults. default: '' + labels: + description: Comma separated issue labels + required: false runs: using: docker - image: docker://ghcr.io/trstringer/manual-approval:1.9.0 + image: docker://us-west1-docker.pkg.dev/dl-dapper/dev/github/manual-approval:1.10.0 diff --git a/approval.go b/approval.go index a34c647..5349bf1 100644 --- a/approval.go +++ b/approval.go @@ -21,9 +21,18 @@ 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 +49,7 @@ func newApprovalEnvironment(client *github.Client, repoFullName, repoOwner strin minimumApprovals: minimumApprovals, issueTitle: issueTitle, issueBody: issueBody, + labels: labels, }, nil } @@ -72,17 +82,19 @@ Respond %s to continue workflow or %s to cancel.`, var err error fmt.Printf( - "Creating issue in repo %s/%s with the following content:\nTitle: %s\nApprovers: %s\nBody:\n%s\n", + "Creating issue in repo %s/%s with the following content:\nTitle: %s\nApprovers: %s\nLabels: %s\nBody:\n%s\n", a.repoOwner, a.repo, issueTitle, a.issueApprovers, + a.labels, 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..96fec60 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" + envVarIssueLabels string = "INPUT_LABELS" ) var ( diff --git a/main.go b/main.go index 5aad15e..633c664 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,18 @@ func main() { os.Exit(1) } } - apprv, err := newApprovalEnvironment(client, repoFullName, repoOwner, runID, approvers, minimumApprovals, issueTitle, issueBody) + issueLabels := strings.Split(os.Getenv(envVarIssueLabels), ",") + 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)