Skip to content

Commit

Permalink
refactor: update wait-for-pr step for improved consistency with other…
Browse files Browse the repository at this point in the history
… built-ins (akuity#2609)

Signed-off-by: Kent Rancourt <kent.rancourt@gmail.com>
  • Loading branch information
krancour authored Sep 30, 2024
1 parent e8f433f commit 5135af2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
12 changes: 6 additions & 6 deletions internal/directives/git_pr_waiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,28 +131,28 @@ func (g *gitPRWaiter) runPromotionStep(
}

func getPRNumber(sharedState State, cfg GitWaitForPRConfig) (int64, error) {
if cfg.PRNumberFromOpen == "" {
if cfg.PRNumberFromStep == "" {
return cfg.PRNumber, nil
}
stepOutput, exists := sharedState.Get(cfg.PRNumberFromOpen)
stepOutput, exists := sharedState.Get(cfg.PRNumberFromStep)
if !exists {
return 0, fmt.Errorf(
"no output found from step with alias %q",
cfg.PRNumberFromOpen,
cfg.PRNumberFromStep,
)
}
stepOutputMap, ok := stepOutput.(map[string]any)
if !ok {
return 0, fmt.Errorf(
"output from step with alias %q is not a map[string]any",
cfg.PRNumberFromOpen,
cfg.PRNumberFromStep,
)
}
prNumberAny, exists := stepOutputMap[prNumberKey]
if !exists {
return 0, fmt.Errorf(
"no PR number found in output from step with alias %q",
cfg.PRNumberFromOpen,
cfg.PRNumberFromStep,
)
}
// If the state was rehydrated from PromotionStatus, which makes use of
Expand All @@ -166,7 +166,7 @@ func getPRNumber(sharedState State, cfg GitWaitForPRConfig) (int64, error) {
default:
return 0, fmt.Errorf(
"PR number in output from step with alias %q is not an int64",
cfg.PRNumberFromOpen,
cfg.PRNumberFromStep,
)
}
}
6 changes: 3 additions & 3 deletions internal/directives/git_pr_waiter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ func Test_gitPRWaiter_validate(t *testing.T) {
},
},
{
name: "neither prNumber nor prNumberFromOpen specified",
name: "neither prNumber nor prNumberFromStep specified",
config: Config{},
expectedProblems: []string{
"(root): Must validate one and only one schema",
},
},
{
name: "both prNumber and prNumberFromOpen specified",
name: "both prNumber and prNumberFromStep specified",
config: Config{
"prNumber": 42,
"prNumberFromOpen": "fake-step",
"prNumberFromStep": "fake-step",
},
expectedProblems: []string{
"(root): Must validate one and only one schema",
Expand Down
8 changes: 4 additions & 4 deletions internal/directives/schemas/git-wait-for-pr-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
"type": "number",
"description": "The number of the pull request to wait for."
},
"prNumberFromOpen": {
"prNumberFromStep": {
"type": "string",
"description": "References a previous open step by alias and will use the PR number opened by that step.",
"description": "This field references the 'prNumber' output from a previous step and uses it as the number of the pull request to wait for.",
"minLength": 1
},
"repoURL": {
Expand All @@ -34,11 +34,11 @@
{
"required": ["prNumber"],
"properties": {
"prNumberFromOpen": { "enum": ["", null] }
"prNumberFromStep": { "enum": ["", null] }
}
},
{
"required": ["prNumberFromOpen"],
"required": ["prNumberFromStep"],
"properties": {
"prNumber": { "enum": [0, null] }
}
Expand Down
5 changes: 3 additions & 2 deletions internal/directives/zz_config_types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5135af2

Please sign in to comment.