Skip to content

Commit 5b127d6

Browse files
fix: patch product-release command to use new query depend on platfor… (#798)
…m version ## What <!-- What is changing in this PR? --> ## Why <!-- Why are these changes being made? --> ## Notes <!-- Add any additional notes here -->
1 parent 9d67cdd commit 5b127d6

File tree

6 files changed

+528
-9
lines changed

6 files changed

+528
-9
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION=v0.2.14
1+
VERSION=v0.2.15
22

33
OUT_DIR=dist
44
YEAR?=$(shell date +"%Y")

cmd/commands/product-release.go

Lines changed: 81 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,74 @@ type (
3838
}
3939
)
4040

41+
const pre_v1_3808_0_err_message = "Cannot query field \\\"promotions\\\" on type \\\"Query\\\""
42+
const pre_v1_3728_0_err_message = "Unknown argument \"productNames\""
43+
const pre_v1_3120_1_err_message = "Cannot query field \\\"applications\\\" on type \\\"ProductReleaseStep\\\"."
4144
const latest_query = `
45+
query Promotions($filters: ProductReleaseFiltersArgs, $pagination: SlicePaginationArgs) {
46+
promotions(filters: $filters, pagination: $pagination) {
47+
pageInfo {
48+
hasNextPage
49+
hasPrevPage
50+
startCursor
51+
endCursor
52+
}
53+
edges {
54+
node {
55+
__typename
56+
... on ProductRelease {
57+
releaseId
58+
releaseName
59+
productName
60+
promotionFlowName
61+
error {
62+
message
63+
code
64+
}
65+
status
66+
environmentsStatuses {
67+
__typename
68+
environmentName
69+
status
70+
}
71+
createdAt
72+
triggerCommit {
73+
sha
74+
}
75+
initiator {
76+
name
77+
avatarUrl
78+
}
79+
version
80+
}
81+
... on Promotion {
82+
id
83+
productName
84+
promotionFlowName
85+
status
86+
environments {
87+
__typename
88+
name
89+
status
90+
}
91+
createdAt
92+
triggerCommitInfo {
93+
commitSha
94+
commitAuthor
95+
avatarURL
96+
}
97+
promotionAppVersion
98+
failure {
99+
message
100+
}
101+
}
102+
}
103+
}
104+
}
105+
}
106+
`
107+
108+
const pre_v1_3808_0_query = `
42109
query getProductReleasesList(
43110
$productName: String!
44111
$filters: ProductReleaseFiltersArgs!
@@ -160,19 +227,29 @@ func newProductReleaseListCommand() *cobra.Command {
160227
func runProductReleaseList(ctx context.Context, filterArgs platmodel.ProductReleaseFiltersArgs, productName string, pageLimit int) error {
161228

162229
// add pagination - default for now is last 20
230+
filterArgs.ProductNames = []string{productName}
163231
variables := map[string]any{
164-
"filters": filterArgs,
165-
"productName": productName,
232+
"filters": filterArgs,
166233
"pagination": platmodel.SlicePaginationArgs{
167234
First: &pageLimit,
168235
},
169236
}
170237

171238
productReleasesPage, err := client.GraphqlAPI[productReleaseSlice](ctx, cfConfig.NewClient().InternalClient(), latest_query, variables)
172239
if err != nil {
173-
if strings.Contains(err.Error(), "Cannot query field \\\"applications\\\" on type \\\"ProductReleaseStep\\\".") {
240+
pre_v1_3808_0_variables := map[string]any{
241+
"filters": filterArgs,
242+
"productName": productName,
243+
"pagination": platmodel.SlicePaginationArgs{
244+
First: &pageLimit,
245+
},
246+
}
247+
if strings.Contains(err.Error(), pre_v1_3120_1_err_message) {
174248
log.G().Warn("codefresh version older than v1.3120.1 detected. Using pre v1.3120.1 query which excludes applications.")
175-
productReleasesPage, err = client.GraphqlAPI[productReleaseSlice](ctx, cfConfig.NewClient().InternalClient(), pre_v1_3120_1_query, variables)
249+
productReleasesPage, err = client.GraphqlAPI[productReleaseSlice](ctx, cfConfig.NewClient().InternalClient(), pre_v1_3120_1_query, pre_v1_3808_0_variables)
250+
} else if strings.Contains(err.Error(), pre_v1_3808_0_err_message) || strings.Contains(err.Error(), pre_v1_3728_0_err_message) {
251+
log.G().Warn("codefresh version older than v1.3808.0 detected. Using pre v1.3808.0 for old arch without promotions.")
252+
productReleasesPage, err = client.GraphqlAPI[productReleaseSlice](ctx, cfConfig.NewClient().InternalClient(), pre_v1_3808_0_query, pre_v1_3808_0_variables)
176253
}
177254
if err != nil {
178255
return fmt.Errorf("failed to get product releases: %s", err.Error())

0 commit comments

Comments
 (0)