Add Labels

This commit is contained in:
Matt Petersen 2024-07-15 08:50:38 -06:00
parent d2e412d840
commit c454b4f271
5 changed files with 20 additions and 4 deletions

View file

@ -1,4 +1,4 @@
IMAGE_REPO=ghcr.io/trstringer/manual-approval
IMAGE_REPO=ghcr.io/radicldefense/manual-approval
.PHONY: build
build:

View file

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

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

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 (

10
main.go
View file

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