diff --git a/README.md b/README.md index d1303d8..678c3b3 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,7 @@ steps: fail-on-denial: true 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*) @@ -65,6 +66,7 @@ steps: * `fail-on-denial` is a boolean that indicates if the workflow should fail if any approver denies the approval. This is optional and defaults to `true`. Set this to `false` to allow the workflow to continue if any approver denies the approval. * `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. +* `labels` is a comma separated list of strings to set labels of issue. This is optional and defaults to an empty string. > [!Note] > 1. If You are using issue-body-file-path then please make sure the file is reachable, for example, idf the file is in your repo then please checkout to your repo in the same job as the approval issue. diff --git a/action.yaml b/action.yaml index a8b661b..01437d6 100644 --- a/action.yaml +++ b/action.yaml @@ -44,6 +44,9 @@ inputs: description: Whether or not to fail the workflow if the approval is denied required: false default: 'true' + labels: + description: Issue labels + default: '' outputs: issue-number: description: The number of the issue created diff --git a/approval.go b/approval.go index 6391ad2..184b016 100644 --- a/approval.go +++ b/approval.go @@ -22,12 +22,13 @@ type approvalEnvironment struct { issueBody string issueApprovers []string minimumApprovals int + labels []string targetRepoOwner string targetRepoName string failOnDenial bool } -func newApprovalEnvironment(client *github.Client, repoFullName, repoOwner string, runID int, approvers []string, minimumApprovals int, issueTitle, issueBody string, targetRepoOwner string, targetRepoName string, failOnDenial bool) (*approvalEnvironment, error) { +func newApprovalEnvironment(client *github.Client, repoFullName, repoOwner string, runID int, approvers []string, minimumApprovals int, issueTitle, issueBody string, targetRepoOwner string, targetRepoName string, failOnDenial bool, 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) @@ -44,6 +45,7 @@ func newApprovalEnvironment(client *github.Client, repoFullName, repoOwner strin minimumApprovals: minimumApprovals, issueTitle: issueTitle, issueBody: issueBody, + labels: labels, targetRepoOwner: targetRepoOwner, targetRepoName: targetRepoName, failOnDenial: failOnDenial, @@ -89,17 +91,21 @@ func (a *approvalEnvironment) createApprovalIssue(ctx context.Context) error { 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, a.targetRepoOwner, a.targetRepoName, issueTitle, a.issueApprovers, + a.labels, issueBody, ) a.approvalIssue, _, err = a.client.Issues.Create(ctx, a.targetRepoOwner, a.targetRepoName, &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 88867e3..07f330a 100644 --- a/constants.go +++ b/constants.go @@ -22,6 +22,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" envVarFailOnDenial string = "INPUT_FAIL-ON-DENIAL" envVarTargetRepoOwner string = "INPUT_TARGET-REPOSITORY-OWNER" envVarTargetRepo string = "INPUT_TARGET-REPOSITORY" diff --git a/main.go b/main.go index e18a395..2386076 100644 --- a/main.go +++ b/main.go @@ -210,6 +210,9 @@ func main() { } else { issueBody = os.Getenv(envVarIssueBody) } + + labels := os.Getenv(envVarLabels) + minimumApprovalsRaw := os.Getenv(envVarMinimumApprovals) minimumApprovals := 0 if minimumApprovalsRaw != "" { @@ -220,7 +223,8 @@ func main() { } } - apprv, err := newApprovalEnvironment(client, repoFullName, repoOwner, runID, approvers, minimumApprovals, issueTitle, issueBody, targetRepoOwner, targetRepoName, failOnDenial) + apprv, err := newApprovalEnvironment(client, repoFullName, repoOwner, runID, approvers, minimumApprovals, issueTitle, issueBody, targetRepoOwner, targetRepoName, failOnDenial, strings.Split(labels, ",")) + if err != nil { fmt.Printf("error creating approval environment: %v\n", err) os.Exit(1)