Skip to content

Commit df02785

Browse files
committed
feat: add action outputs, draft PR, and PR reviewers/assignees support
- Add 6 action outputs (commit_sha, pr_number, pr_url, tag_name, skipped, changed_files) - Add pr_draft input for creating draft pull requests - Add pr_reviewers and pr_assignees inputs for PR reviewer/assignee assignment - Add output verification steps and dry-run tests in CI workflows
1 parent ed0e977 commit df02785

13 files changed

Lines changed: 691 additions & 19 deletions

File tree

.github/workflows/ci.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ jobs:
194194
token: ${{ secrets.PAT_TOKEN }}
195195

196196
- name: Test Skip If Empty (should skip - no changes)
197+
id: skip-test
197198
uses: ./
198199
with:
199200
user_email: actions@github.com
@@ -211,12 +212,23 @@ jobs:
211212
github_token: ${{ secrets.PAT_TOKEN }}
212213
pr_closed: true
213214

215+
- name: Verify Skip Output
216+
run: |
217+
echo "skipped=${{ steps.skip-test.outputs.skipped }}"
218+
echo "changed_files=${{ steps.skip-test.outputs.changed_files }}"
219+
if [ "${{ steps.skip-test.outputs.skipped }}" != "true" ]; then
220+
echo "FAIL: expected skipped=true"
221+
exit 1
222+
fi
223+
echo "PASS: skip output verified"
224+
214225
# Verify skip does not happen when changes exist
215226
- name: Create Test File
216227
run: |
217228
echo "$(date +%s)-$RANDOM" > test/skip-test.txt
218229
219230
- name: Test Skip If Empty (should not skip - with changes)
231+
id: no-skip-test
220232
uses: ./
221233
with:
222234
user_email: actions@github.com
@@ -234,6 +246,18 @@ jobs:
234246
github_token: ${{ secrets.PAT_TOKEN }}
235247
pr_closed: true
236248

249+
- name: Verify No-Skip Output
250+
run: |
251+
echo "skipped=${{ steps.no-skip-test.outputs.skipped }}"
252+
echo "changed_files=${{ steps.no-skip-test.outputs.changed_files }}"
253+
echo "pr_number=${{ steps.no-skip-test.outputs.pr_number }}"
254+
echo "pr_url=${{ steps.no-skip-test.outputs.pr_url }}"
255+
if [ "${{ steps.no-skip-test.outputs.skipped }}" = "true" ]; then
256+
echo "FAIL: expected skipped!=true"
257+
exit 1
258+
fi
259+
echo "PASS: no-skip output verified"
260+
237261
test-pr-auto-close-pr-body:
238262
name: Test PR Auto Close
239263
runs-on: ubuntu-latest
@@ -297,6 +321,43 @@ jobs:
297321
github_token: ${{ secrets.PAT_TOKEN }}
298322
pr_dry_run: true
299323

324+
- name: Test PR Dry Run with Draft
325+
uses: ./
326+
with:
327+
user_email: actions@github.com
328+
user_name: GitHub Actions
329+
branch: main
330+
create_pr: true
331+
auto_branch: false
332+
pr_title: "Test PR Dry Run (Draft)"
333+
pr_base: test
334+
pr_branch: main
335+
pr_labels: "test,automated,draft-pr-test"
336+
repository_path: "test"
337+
file_pattern: "pr-dry-run-test.txt"
338+
github_token: ${{ secrets.PAT_TOKEN }}
339+
pr_draft: true
340+
pr_dry_run: true
341+
342+
- name: Test PR Dry Run with Reviewers and Assignees
343+
uses: ./
344+
with:
345+
user_email: actions@github.com
346+
user_name: GitHub Actions
347+
branch: main
348+
create_pr: true
349+
auto_branch: false
350+
pr_title: "Test PR Dry Run (Reviewers/Assignees)"
351+
pr_base: test
352+
pr_branch: main
353+
pr_labels: "test,automated,reviewers-test"
354+
pr_reviewers: "somaz94"
355+
pr_assignees: "somaz94"
356+
repository_path: "test"
357+
file_pattern: "pr-dry-run-test.txt"
358+
github_token: ${{ secrets.PAT_TOKEN }}
359+
pr_dry_run: true
360+
300361
ci-result:
301362
name: CI Result
302363
if: always()

.github/workflows/use-action.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ jobs:
129129
token: ${{ secrets.PAT_TOKEN }}
130130

131131
- name: Test Skip If Empty (should skip - no changes)
132+
id: skip-test
132133
uses: somaz94/go-git-commit-action@v1
133134
with:
134135
user_email: actions@github.com
@@ -146,12 +147,22 @@ jobs:
146147
github_token: ${{ secrets.PAT_TOKEN }}
147148
pr_closed: true
148149

150+
- name: Verify Skip Output
151+
run: |
152+
echo "skipped=${{ steps.skip-test.outputs.skipped }}"
153+
if [ "${{ steps.skip-test.outputs.skipped }}" != "true" ]; then
154+
echo "FAIL: expected skipped=true"
155+
exit 1
156+
fi
157+
echo "PASS: skip output verified"
158+
149159
# Verify skip does not happen when changes exist
150160
- name: Create Test File
151161
run: |
152162
echo "$(date +%s)-$RANDOM" > test/skip-test.txt
153163
154164
- name: Test Skip If Empty (should not skip - with changes)
165+
id: no-skip-test
155166
uses: somaz94/go-git-commit-action@v1
156167
with:
157168
user_email: actions@github.com
@@ -169,6 +180,16 @@ jobs:
169180
github_token: ${{ secrets.PAT_TOKEN }}
170181
pr_closed: true
171182

183+
- name: Verify No-Skip Output
184+
run: |
185+
echo "skipped=${{ steps.no-skip-test.outputs.skipped }}"
186+
echo "pr_number=${{ steps.no-skip-test.outputs.pr_number }}"
187+
if [ "${{ steps.no-skip-test.outputs.skipped }}" = "true" ]; then
188+
echo "FAIL: expected skipped!=true"
189+
exit 1
190+
fi
191+
echo "PASS: no-skip output verified"
192+
172193
smoke-test-pr-auto-close:
173194
name: Smoke Test (PR Auto Close)
174195
runs-on: ubuntu-latest
@@ -226,4 +247,41 @@ jobs:
226247
repository_path: "test"
227248
file_pattern: "pr-dry-run-test.txt"
228249
github_token: ${{ secrets.PAT_TOKEN }}
250+
pr_dry_run: true
251+
252+
- name: Test PR Dry Run with Draft
253+
uses: somaz94/go-git-commit-action@v1
254+
with:
255+
user_email: actions@github.com
256+
user_name: GitHub Actions
257+
branch: main
258+
create_pr: true
259+
auto_branch: false
260+
pr_title: "Test PR Dry Run (Draft)"
261+
pr_base: test
262+
pr_branch: main
263+
pr_labels: "test,automated,draft-pr-test"
264+
repository_path: "test"
265+
file_pattern: "pr-dry-run-test.txt"
266+
github_token: ${{ secrets.PAT_TOKEN }}
267+
pr_draft: true
268+
pr_dry_run: true
269+
270+
- name: Test PR Dry Run with Reviewers and Assignees
271+
uses: somaz94/go-git-commit-action@v1
272+
with:
273+
user_email: actions@github.com
274+
user_name: GitHub Actions
275+
branch: main
276+
create_pr: true
277+
auto_branch: false
278+
pr_title: "Test PR Dry Run (Reviewers/Assignees)"
279+
pr_base: test
280+
pr_branch: main
281+
pr_labels: "test,automated,reviewers-test"
282+
pr_reviewers: "somaz94"
283+
pr_assignees: "somaz94"
284+
repository_path: "test"
285+
file_pattern: "pr-dry-run-test.txt"
286+
github_token: ${{ secrets.PAT_TOKEN }}
229287
pr_dry_run: true

action.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,37 @@ inputs:
8484
description: 'Whether to close the pull request after creation'
8585
required: false
8686
default: 'false'
87+
pr_draft:
88+
description: 'Create pull request as draft'
89+
required: false
90+
default: 'false'
91+
pr_reviewers:
92+
description: 'Reviewers to request for the pull request (comma-separated usernames)'
93+
required: false
94+
default: ''
95+
pr_assignees:
96+
description: 'Assignees for the pull request (comma-separated usernames)'
97+
required: false
98+
default: ''
8799
pr_dry_run:
88100
description: 'Simulate PR creation without actually creating one (for testing)'
89101
required: false
90102
default: 'false'
91103

104+
outputs:
105+
commit_sha:
106+
description: 'The SHA of the created commit'
107+
pr_number:
108+
description: 'The number of the created pull request'
109+
pr_url:
110+
description: 'The URL of the created pull request'
111+
tag_name:
112+
description: 'The name of the created tag'
113+
skipped:
114+
description: 'Whether the action was skipped due to no changes (true/false)'
115+
changed_files:
116+
description: 'The number of changed files detected'
117+
92118
runs:
93119
using: 'docker'
94120
image: 'Dockerfile'
@@ -114,6 +140,9 @@ runs:
114140
PR_BODY: ${{ inputs.pr_body }}
115141
SKIP_IF_EMPTY: ${{ inputs.skip_if_empty }}
116142
PR_CLOSED: ${{ inputs.pr_closed }}
143+
PR_DRAFT: ${{ inputs.pr_draft }}
144+
PR_REVIEWERS: ${{ inputs.pr_reviewers }}
145+
PR_ASSIGNEES: ${{ inputs.pr_assignees }}
117146
PR_DRY_RUN: ${{ inputs.pr_dry_run }}
118147
branding:
119148
icon: 'git-commit'

cmd/main.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
"github.com/somaz94/go-git-commit-action/internal/config"
1111
"github.com/somaz94/go-git-commit-action/internal/git"
12+
"github.com/somaz94/go-git-commit-action/internal/output"
1213
)
1314

1415
func main() {
@@ -28,14 +29,22 @@ func main() {
2829
log.Fatalf("Failed to initialize configuration: %v", err)
2930
}
3031

31-
if err := git.RunGitCommit(cfg); err != nil {
32+
// Create result to collect action outputs
33+
result := output.NewResult()
34+
35+
if err := git.RunGitCommit(cfg, result); err != nil {
3236
log.Fatalf("Error executing git commands: %v", err)
3337
}
3438

3539
if cfg.TagName != "" {
3640
tagManager := git.NewTagManager(cfg)
37-
if err := tagManager.HandleGitTag(ctx); err != nil {
41+
if err := tagManager.HandleGitTag(ctx, result); err != nil {
3842
log.Fatalf("Error handling git tag: %v", err)
3943
}
4044
}
45+
46+
// Write all outputs to GITHUB_OUTPUT
47+
if err := result.WriteToGitHubOutput(); err != nil {
48+
log.Printf("[WARN] Failed to write action outputs: %v", err)
49+
}
4150
}

internal/config/config.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ const (
3939
EnvPRLabels = "INPUT_PR_LABELS"
4040
EnvPRBody = "INPUT_PR_BODY"
4141
EnvPRClosed = "INPUT_PR_CLOSED"
42+
EnvPRDraft = "INPUT_PR_DRAFT"
43+
EnvPRReviewers = "INPUT_PR_REVIEWERS"
44+
EnvPRAssignees = "INPUT_PR_ASSIGNEES"
4245
EnvPRDryRun = "INPUT_PR_DRY_RUN"
4346

4447
// Operational settings
@@ -62,6 +65,7 @@ const (
6265
DefaultPRBranch = ""
6366
DefaultDeleteSource = false
6467
DefaultPRClosed = false
68+
DefaultPRDraft = false
6569
DefaultPRDryRun = false
6670
DefaultDebug = false
6771
DefaultTimeout = 30
@@ -100,6 +104,9 @@ type GitConfig struct {
100104
PRLabels []string
101105
PRBody string
102106
PRClosed bool
107+
PRDraft bool
108+
PRReviewers []string
109+
PRAssignees []string
103110
PRDryRun bool
104111

105112
// Operational settings
@@ -166,6 +173,9 @@ func NewGitConfig() (*GitConfig, error) {
166173
PRLabels: parseLabels(os.Getenv(EnvPRLabels)),
167174
PRBody: os.Getenv(EnvPRBody),
168175
PRClosed: getBoolEnv(EnvPRClosed, DefaultPRClosed),
176+
PRDraft: getBoolEnv(EnvPRDraft, DefaultPRDraft),
177+
PRReviewers: parseLabels(os.Getenv(EnvPRReviewers)),
178+
PRAssignees: parseLabels(os.Getenv(EnvPRAssignees)),
169179
PRDryRun: getBoolEnv(EnvPRDryRun, DefaultPRDryRun),
170180

171181
// Operational settings

internal/config/config_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ func TestGitConfig_Defaults(t *testing.T) {
6767
if cfg.SkipIfEmpty != DefaultSkipIfEmpty {
6868
t.Errorf("SkipIfEmpty = %v, want %v", cfg.SkipIfEmpty, DefaultSkipIfEmpty)
6969
}
70+
if cfg.PRDraft != DefaultPRDraft {
71+
t.Errorf("PRDraft = %v, want %v", cfg.PRDraft, DefaultPRDraft)
72+
}
7073
}
7174

7275
func TestGitConfig_ValidatePR(t *testing.T) {

0 commit comments

Comments
 (0)