feat: add issue label

This commit is contained in:
reynandaptr 2023-11-05 22:22:40 +07:00
parent a824dad59a
commit fc93116448
5 changed files with 16 additions and 4 deletions

View file

@ -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*)
@ -45,6 +46,7 @@ steps:
- `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.
- `labels` is a comma separated list of strings to set labels of issue. This is optional and defaults to an empty string.
### Using Custom Words

View file

@ -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: Issue labels
default: ''
runs:
using: docker
image: docker://ghcr.io/trstringer/manual-approval:1.9.0
image: docker://ghcr.io/trstringer/manual-approval:1.10.0

View file

@ -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
}
@ -72,17 +74,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

View file

@ -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 (

View file

@ -6,6 +6,7 @@ import (
"os"
"os/signal"
"strconv"
"strings"
"time"
"github.com/google/go-github/v43/github"
@ -172,6 +173,7 @@ func main() {
issueTitle := os.Getenv(envVarIssueTitle)
issueBody := os.Getenv(envVarIssueBody)
labels := os.Getenv(envVarLabels)
minimumApprovalsRaw := os.Getenv(envVarMinimumApprovals)
minimumApprovals := 0
if minimumApprovalsRaw != "" {
@ -181,7 +183,7 @@ func main() {
os.Exit(1)
}
}
apprv, err := newApprovalEnvironment(client, repoFullName, repoOwner, runID, approvers, minimumApprovals, issueTitle, issueBody)
apprv, err := newApprovalEnvironment(client, repoFullName, repoOwner, runID, approvers, minimumApprovals, issueTitle, issueBody, strings.Split(labels, ","))
if err != nil {
fmt.Printf("error creating approval environment: %v\n", err)
os.Exit(1)