Skip to content

Commit 8600531

Browse files
authored
option to create issue with label (#1)
1 parent dd1555b commit 8600531

File tree

6 files changed

+34
-5
lines changed

6 files changed

+34
-5
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
IMAGE_REPO=ghcr.io/trstringer/manual-approval
1+
IMAGE_REPO=us-west1-docker.pkg.dev/dl-dapper/dev/github/manual-approval
22

33
.PHONY: build
44
build:

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ steps:
3636
exclude-workflow-initiator-as-approver: false
3737
additional-approved-words: ''
3838
additional-denied-words: ''
39+
labels: ''
3940
```
4041
4142
- `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*)

action.yaml

+4-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ inputs:
2828
additional-denied-words:
2929
description: Comma separated list of words that can be used to deny beyond the defaults.
3030
default: ''
31+
labels:
32+
description: Comma separated issue labels
33+
required: false
3134
runs:
3235
using: docker
33-
image: docker://ghcr.io/trstringer/manual-approval:1.9.0
36+
image: docker://us-west1-docker.pkg.dev/dl-dapper/dev/github/manual-approval:1.10.0

approval.go

+14-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,18 @@ type approvalEnvironment struct {
2121
issueBody string
2222
issueApprovers []string
2323
minimumApprovals int
24+
labels []string
2425
}
2526

26-
func newApprovalEnvironment(client *github.Client, repoFullName, repoOwner string, runID int, approvers []string, minimumApprovals int, issueTitle, issueBody string) (*approvalEnvironment, error) {
27+
func newApprovalEnvironment(
28+
client *github.Client,
29+
repoFullName, repoOwner string,
30+
runID int,
31+
approvers []string,
32+
minimumApprovals int,
33+
issueTitle, issueBody string,
34+
labels []string,
35+
) (*approvalEnvironment, error) {
2736
repoOwnerAndName := strings.Split(repoFullName, "/")
2837
if len(repoOwnerAndName) != 2 {
2938
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
4049
minimumApprovals: minimumApprovals,
4150
issueTitle: issueTitle,
4251
issueBody: issueBody,
52+
labels: labels,
4353
}, nil
4454
}
4555

@@ -72,17 +82,19 @@ Respond %s to continue workflow or %s to cancel.`,
7282

7383
var err error
7484
fmt.Printf(
75-
"Creating issue in repo %s/%s with the following content:\nTitle: %s\nApprovers: %s\nBody:\n%s\n",
85+
"Creating issue in repo %s/%s with the following content:\nTitle: %s\nApprovers: %s\nLabels: %s\nBody:\n%s\n",
7686
a.repoOwner,
7787
a.repo,
7888
issueTitle,
7989
a.issueApprovers,
90+
a.labels,
8091
issueBody,
8192
)
8293
a.approvalIssue, _, err = a.client.Issues.Create(ctx, a.repoOwner, a.repo, &github.IssueRequest{
8394
Title: &issueTitle,
8495
Body: &issueBody,
8596
Assignees: &a.issueApprovers,
97+
Labels: &a.labels,
8698
})
8799
if err != nil {
88100
return err

constants.go

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const (
2121
envVarExcludeWorkflowInitiatorAsApprover string = "INPUT_EXCLUDE-WORKFLOW-INITIATOR-AS-APPROVER"
2222
envVarAdditionalApprovedWords string = "INPUT_ADDITIONAL-APPROVED-WORDS"
2323
envVarAdditionalDeniedWords string = "INPUT_ADDITIONAL-DENIED-WORDS"
24+
envVarIssueLabels string = "INPUT_LABELS"
2425
)
2526

2627
var (

main.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"os"
77
"os/signal"
88
"strconv"
9+
"strings"
910
"time"
1011

1112
"github.com/google/go-github/v43/github"
@@ -181,7 +182,18 @@ func main() {
181182
os.Exit(1)
182183
}
183184
}
184-
apprv, err := newApprovalEnvironment(client, repoFullName, repoOwner, runID, approvers, minimumApprovals, issueTitle, issueBody)
185+
issueLabels := strings.Split(os.Getenv(envVarIssueLabels), ",")
186+
apprv, err := newApprovalEnvironment(
187+
client,
188+
repoFullName,
189+
repoOwner,
190+
runID,
191+
approvers,
192+
minimumApprovals,
193+
issueTitle,
194+
issueBody,
195+
issueLabels,
196+
)
185197
if err != nil {
186198
fmt.Printf("error creating approval environment: %v\n", err)
187199
os.Exit(1)

0 commit comments

Comments
 (0)