-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: update cli to retrieve promotion commits for product release steps #758
Changes from 3 commits
008f9f7
12984db
851e9e0
9078e86
43060b8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
VERSION=v0.1.65 | ||
VERSION=v0.1.66 | ||
|
||
OUT_DIR=dist | ||
YEAR?=$(shell date +"%Y") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ import ( | |
|
||
"github.com/codefresh-io/cli-v2/pkg/util" | ||
|
||
"github.com/codefresh-io/cli-v2/pkg/log" | ||
"github.com/codefresh-io/go-sdk/pkg/client" | ||
platmodel "github.com/codefresh-io/go-sdk/pkg/model/promotion-orchestrator" | ||
"github.com/spf13/cobra" | ||
|
@@ -37,6 +38,55 @@ type ( | |
} | ||
) | ||
|
||
const latest_query = ` | ||
query getProductReleasesList( | ||
$productName: String! | ||
$filters: ProductReleaseFiltersArgs! | ||
$pagination: SlicePaginationArgs | ||
) { | ||
productReleases(productName: $productName, filters: $filters, pagination: $pagination) { | ||
edges { | ||
node { | ||
releaseId | ||
steps { | ||
environmentName | ||
status | ||
promotionCommits { | ||
applicationId { | ||
runtime | ||
namespace | ||
name | ||
} | ||
commitSha | ||
} | ||
} | ||
status | ||
} | ||
} | ||
} | ||
} | ||
` | ||
|
||
const v0_13_4_query = ` | ||
query getProductReleasesList( | ||
$productName: String! | ||
$filters: ProductReleaseFiltersArgs! | ||
$pagination: SlicePaginationArgs | ||
) { | ||
productReleases(productName: $productName, filters: $filters, pagination: $pagination) { | ||
edges { | ||
node { | ||
releaseId | ||
steps { | ||
environmentName | ||
status | ||
} | ||
status | ||
} | ||
} | ||
} | ||
}` | ||
|
||
func NewProductReleaseCommand() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "product-release", | ||
|
@@ -98,25 +148,7 @@ func newProductReleaseListCommand() *cobra.Command { | |
|
||
// client here is for mock testings usage | ||
func runProductReleaseList(ctx context.Context, filterArgs platmodel.ProductReleaseFiltersArgs, productName string, pageLimit int) error { | ||
query := ` | ||
query getProductReleasesList( | ||
$productName: String! | ||
$filters: ProductReleaseFiltersArgs! | ||
$pagination: SlicePaginationArgs | ||
) { | ||
productReleases(productName: $productName, filters: $filters, pagination: $pagination) { | ||
edges { | ||
node { | ||
releaseId | ||
steps { | ||
environmentName | ||
status | ||
} | ||
status | ||
} | ||
} | ||
} | ||
}` | ||
|
||
// add pagination - default for now is last 20 | ||
variables := map[string]any{ | ||
"filters": filterArgs, | ||
|
@@ -126,9 +158,15 @@ query getProductReleasesList( | |
}, | ||
} | ||
|
||
productReleasesPage, err := client.GraphqlAPI[productReleaseSlice](ctx, cfConfig.NewClient().InternalClient(), query, variables) | ||
productReleasesPage, err := client.GraphqlAPI[productReleaseSlice](ctx, cfConfig.NewClient().InternalClient(), latest_query, variables) | ||
if err != nil { | ||
return fmt.Errorf("failed to get product releases: %w", err) | ||
if strings.Contains(err.Error(), "Cannot query field \\\"promotionCommits\\\" on type \\\"ProductReleaseStep\\\".") { | ||
log.G().Warn("codefresh version v0.13.4 or older detected. Using v0.13.4 query which excludes promotionCommits.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added this warning, but now I'm not sure as if there are customers/internal users using this cli command in automation the extra log line of output would make it fail. I can also just make it fallback silently? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think that should be ok, showing a warning, but falling back to previous query. |
||
productReleasesPage, err = client.GraphqlAPI[productReleaseSlice](ctx, cfConfig.NewClient().InternalClient(), v0_13_4_query, variables) | ||
} | ||
if err != nil { | ||
return fmt.Errorf("failed to get product releases: %s", err.Error()) | ||
} | ||
} | ||
|
||
if len(productReleasesPage.Edges) == 0 { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll update the specific version references once I've merged the argo-platform changes.