-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP using buildplanner ImpactReport endpoint to show change summary.
It currently has issues because the afterCommitId is not yet published as part of the project history. A buildexpression is needed.
- Loading branch information
1 parent
16b5648
commit c7d90d6
Showing
7 changed files
with
237 additions
and
3 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
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,56 @@ | ||
package request | ||
|
||
import ( | ||
"github.com/go-openapi/strfmt" | ||
) | ||
|
||
func ImpactReport(organization, project string, beforeCommitId, afterCommitId strfmt.UUID) *impactReport { | ||
bp := &impactReport{map[string]interface{}{ | ||
"organization": organization, | ||
"project": project, | ||
"beforeCommitId": beforeCommitId.String(), | ||
"afterCommitId": afterCommitId.String(), | ||
}} | ||
|
||
return bp | ||
} | ||
|
||
type impactReport struct { | ||
vars map[string]interface{} | ||
} | ||
|
||
func (b *impactReport) Query() string { | ||
return ` | ||
query ($organization: String!, $project: String!, $beforeCommitId: ID!, $afterCommitId: ID!) { | ||
impactReport( | ||
before: {organization: $organization, project: $project, buildExprOrCommit: {commitId: $beforeCommitId}} | ||
after: {organization: $organization, project: $project, buildExprOrCommit: {commitId: $afterCommitId}} | ||
) { | ||
__typename | ||
... on ImpactReport { | ||
ingredients { | ||
namespace | ||
name | ||
before { | ||
ingredientID | ||
version | ||
isRequirement | ||
} | ||
after { | ||
ingredientID | ||
version | ||
isRequirement | ||
} | ||
} | ||
} | ||
... on ImpactReportError { | ||
message | ||
} | ||
} | ||
} | ||
` | ||
} | ||
|
||
func (b *impactReport) Vars() (map[string]interface{}, error) { | ||
return b.vars, nil | ||
} |
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,43 @@ | ||
package response | ||
|
||
import ( | ||
"github.com/ActiveState/cli/internal/errs" | ||
) | ||
|
||
type ImpactReportIngredientState struct { | ||
IngredientID string `json:"ingredientID"` | ||
Version string `json:"version"` | ||
IsRequirement bool `json:"isRequirement"` | ||
} | ||
|
||
type ImpactReportIngredient struct { | ||
Namespace string `json:"namespace"` | ||
Name string `json:"name"` | ||
Before *ImpactReportIngredientState `json:"before"` | ||
After *ImpactReportIngredientState `json:"after"` | ||
} | ||
|
||
type ImpactReportResult struct { | ||
Type string `json:"__typename"` | ||
Ingredients []ImpactReportIngredient `json:"ingredients"` | ||
*Error | ||
} | ||
|
||
type ImpactReportResponse struct { | ||
*ImpactReportResult `json:"impactReport"` | ||
} | ||
|
||
type ImpactReportError struct { | ||
Type string | ||
Message string | ||
} | ||
|
||
func (e ImpactReportError) Error() string { return e.Message } | ||
|
||
func ProcessImpactReportError(err *ImpactReportResult, fallbackMessage string) error { | ||
if err.Error == nil { | ||
return errs.New(fallbackMessage) | ||
} | ||
|
||
return &ImpactReportError{err.Type, err.Message} | ||
} |
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,35 @@ | ||
package buildplanner | ||
|
||
import ( | ||
"github.com/go-openapi/strfmt" | ||
|
||
"github.com/ActiveState/cli/internal/errs" | ||
"github.com/ActiveState/cli/pkg/platform/api/buildplanner/request" | ||
"github.com/ActiveState/cli/pkg/platform/api/buildplanner/response" | ||
) | ||
|
||
type ImpactReportParams struct { | ||
Owner string | ||
Project string | ||
BeforeCommitId strfmt.UUID | ||
AfterCommitId strfmt.UUID | ||
} | ||
|
||
func (b *BuildPlanner) ImpactReport(params *ImpactReportParams) (*response.ImpactReportResult, error) { | ||
request := request.ImpactReport(params.Owner, params.Project, params.BeforeCommitId, params.AfterCommitId) | ||
resp := &response.ImpactReportResponse{} | ||
err := b.client.Run(request, resp) | ||
if err != nil { | ||
return nil, processBuildPlannerError(err, "failed to get impact report") | ||
} | ||
|
||
if resp.ImpactReportResult == nil { | ||
return nil, errs.New("ImpactReport is nil") | ||
} | ||
|
||
if response.IsErrorResponse(resp.ImpactReportResult.Type) { | ||
return nil, response.ProcessImpactReportError(resp.ImpactReportResult, "Could not get impact report") | ||
} | ||
|
||
return resp.ImpactReportResult, nil | ||
} |