Skip to content

Commit 3ec2652

Browse files
authored
Run hooks on av pr command (#548)
1 parent 96777f3 commit 3ec2652

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

cmd/av/pr.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/aviator-co/av/internal/avgql"
1313
"github.com/aviator-co/av/internal/config"
1414
"github.com/aviator-co/av/internal/gh"
15+
"github.com/aviator-co/av/internal/git"
1516
"github.com/aviator-co/av/internal/meta"
1617
"github.com/aviator-co/av/internal/utils/cleanup"
1718
"github.com/aviator-co/av/internal/utils/colors"
@@ -95,6 +96,11 @@ Examples:
9596
if err != nil {
9697
return errors.WrapIf(err, "failed to determine current branch")
9798
}
99+
100+
if err := runPRHook(repo, "single"); err != nil {
101+
return err
102+
}
103+
98104
client, err := getGitHubClient()
99105
if err != nil {
100106
return err
@@ -204,6 +210,10 @@ func submitAll(current bool, draft bool) error {
204210
branchesToSubmit = append(branchesToSubmit, subsequentBranches...)
205211
}
206212

213+
if err := runPRHook(repo, "all"); err != nil {
214+
return err
215+
}
216+
207217
// ensure pull requests for each branch in the stack
208218
createdPullRequestPermalinks := []string{}
209219
ctx := context.Background()
@@ -291,6 +301,10 @@ func queue() error {
291301
)
292302
}
293303

304+
if err := runPRHook(repo, "queue"); err != nil {
305+
return err
306+
}
307+
294308
prNumber := branch.PullRequest.Number
295309
repository := tx.Repository()
296310

@@ -332,6 +346,27 @@ func queue() error {
332346
return nil
333347
}
334348

349+
func runPRHook(repo *git.Repo, hookType string) error {
350+
output, err := repo.Run(&git.RunOpts{
351+
Args: []string{"hook", "run", "--ignore-missing", "pre-av-pr"},
352+
Env: []string{"AV_PR_HOOK_TYPE=" + hookType},
353+
})
354+
var messages []string
355+
if len(output.Stdout) != 0 {
356+
messages = append(messages, string(output.Stdout))
357+
}
358+
if len(output.Stderr) != 0 {
359+
messages = append(messages, string(output.Stderr))
360+
}
361+
if len(messages) != 0 {
362+
fmt.Fprint(os.Stderr, strings.Join(messages, "\n"))
363+
}
364+
if err != nil {
365+
return errors.Errorf("pre-av-pr hook failed: %v", err)
366+
}
367+
return nil
368+
}
369+
335370
func init() {
336371
prCmd.Flags().BoolVar(
337372
&prFlags.Draft, "draft", false,

0 commit comments

Comments
 (0)