-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add approval and rejection support (#82)
- Added the ability to approve and reject runs and tasks. - The approval and rejection mutations accept an optional run ID (if not specified they target the stack blocker). Because of that I've created an extra optional run ID flag and renamed the required one. Issues: #81
- Loading branch information
1 parent
6ce41eb
commit ed0540b
Showing
8 changed files
with
121 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package enums | ||
|
||
// RunReviewDecision represents the API RunReviewDecision enum. | ||
type RunReviewDecision string | ||
|
||
const ( | ||
// RunReviewDecisionApprove represents an approval decision. | ||
RunReviewDecisionApprove = "APPROVE" | ||
|
||
// RunReviewDecisionReject represents a rejection decision. | ||
RunReviewDecisionReject = "REJECT" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package stack | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/shurcooL/graphql" | ||
"github.com/urfave/cli/v2" | ||
|
||
"github.com/spacelift-io/spacectl/client/enums" | ||
"github.com/spacelift-io/spacectl/internal/cmd/authenticated" | ||
) | ||
|
||
type runReviewMutation struct { | ||
Review struct { | ||
ID string `graphql:"id"` | ||
} `graphql:"runReview(stack: $stack, run: $run, decision: $decision, note: $note)"` | ||
} | ||
|
||
var flagRunReviewNote = &cli.StringFlag{ | ||
Name: "note", | ||
Usage: "Description of why the review decision was made.", | ||
Required: false, | ||
} | ||
|
||
func runApprove(cliCtx *cli.Context) error { | ||
stackID := cliCtx.String(flagStackID.Name) | ||
runID := cliCtx.String(flagRequiredRun.Name) | ||
note := cliCtx.String(flagRunReviewNote.Name) | ||
|
||
if nArgs := cliCtx.NArg(); nArgs != 0 { | ||
return fmt.Errorf("expected zero arguments but got %d", nArgs) | ||
} | ||
|
||
return addRunReview(cliCtx.Context, stackID, runID, note, enums.RunReviewDecisionApprove) | ||
} | ||
|
||
func runReject(cliCtx *cli.Context) error { | ||
stackID := cliCtx.String(flagStackID.Name) | ||
runID := cliCtx.String(flagRequiredRun.Name) | ||
note := cliCtx.String(flagRunReviewNote.Name) | ||
|
||
if nArgs := cliCtx.NArg(); nArgs != 0 { | ||
return fmt.Errorf("expected zero arguments but got %d", nArgs) | ||
} | ||
|
||
return addRunReview(cliCtx.Context, stackID, runID, note, enums.RunReviewDecisionReject) | ||
} | ||
|
||
func addRunReview(ctx context.Context, stackID, runID, note string, decision enums.RunReviewDecision) error { | ||
var runIDGQL *graphql.ID | ||
if runID != "" { | ||
runIDGQL = graphql.NewID(runID) | ||
} | ||
|
||
var mutation runReviewMutation | ||
variables := map[string]interface{}{ | ||
"stack": graphql.ID(stackID), | ||
"run": runIDGQL, | ||
"decision": decision, | ||
"note": graphql.String(note), | ||
} | ||
|
||
return authenticated.Client.Mutate(ctx, &mutation, variables) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters